2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET
4 * Copyright (C) 2012 - 2016 - Scilab Enterprises
5 * Copyright (C) 2017, 2018 - Samuel GOUGEON
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
16 #include "checkers/DeprecatedChecker.hxx"
21 std::unordered_map<std::wstring, std::wstring> DeprecatedChecker::deprecated = initDep();
22 std::unordered_map<std::wstring, std::shared_ptr<SLintChecker>> DeprecatedChecker::partiallyDeprecated = initPartDep();
24 void DeprecatedChecker::preCheckNode(const ast::Exp & e, SLintContext & context, SLintResult & result)
26 const ast::CallExp & ce = static_cast<const ast::CallExp &>(e);
27 if (ce.getName().isSimpleVar())
29 const std::wstring & name = static_cast<const ast::SimpleVar &>(ce.getName()).getSymbol().getName();
30 const auto i = deprecated.find(name);
31 if (i != deprecated.end())
33 if (i->second.empty())
35 result.report(context, e.getLocation(), *this, _("Deprecated function: %s."), name);
39 result.report(context, e.getLocation(), *this, _("Deprecated function %s: use %s instead."), name, i->second);
44 const auto i = partiallyDeprecated.find(name);
45 if (i != partiallyDeprecated.end())
47 i->second->preCheckNode(e, context, result);
53 void DeprecatedChecker::postCheckNode(const ast::Exp & e, SLintContext & context, SLintResult & result)
57 const std::string DeprecatedChecker::getName() const
59 return "DeprecatedChecker";
62 void DeprecatedChecker::__Svd::preCheckNode(const ast::Exp & e, SLintContext & context, SLintResult & result)
64 const ast::CallExp & ce = static_cast<const ast::CallExp &>(e);
65 const ast::exps_t args = ce.getArgs();
68 const ast::Exp & second = *args.back();
69 if (second.isDoubleExp() && static_cast<const ast::DoubleExp &>(second).getValue() == 0)
71 result.report(context, e.getLocation(), *this, _("svd(..., 0) is deprecated."));
76 void DeprecatedChecker::__Mfprintf::preCheckNode(const ast::Exp & e, SLintContext & context, SLintResult & result)
78 const ast::CallExp & ce = static_cast<const ast::CallExp &>(e);
79 const ast::exps_t args = ce.getArgs();
82 const ast::Exp & first = *args.front();
83 if (first.isDoubleExp() && static_cast<const ast::DoubleExp &>(first).getValue() == -1)
85 result.report(context, e.getLocation(), *this, _("mfprintf(-1, ...) is deprecated."));
90 std::unordered_map<std::wstring, std::wstring> DeprecatedChecker::initDep()
92 // TODO: get this list from a conf file
93 std::unordered_map<std::wstring, std::wstring> map;
95 // Scilab 6.1.0 => 6.1.x
96 map.emplace(L"setPreferencesValue", L"xmlSetValues");
98 // Scilab 6.0.x => 6.1.0
99 map.emplace(L"champ1", L"champ.colored");
100 map.emplace(L"%sn", L"ellipj");
101 map.emplace(L"dirname", L"fileparts");
102 map.emplace(L"_d", L"_");
103 map.emplace(L"dgettext", L"gettext");
104 map.emplace(L"datatipToggle", L"datatipManagerMode");
105 map.emplace(L"denom", L".den");
106 map.emplace(L"frexp", L"log2");
107 map.emplace(L"eval", L"evstr");
108 map.emplace(L"getPreferencesValue", L"xmlGetValues");
109 map.emplace(L"hypermat", L"zeros|matrix");
110 map.emplace(L"lstsize", L"size");
111 map.emplace(L"nanmin", L"min");
112 map.emplace(L"nanmax", L"max");
113 map.emplace(L"noisegen", L"grand");
114 map.emplace(L"numer", L".num");
115 map.emplace(L"ric_desc", L"riccati");
116 map.emplace(L"square", L"replot");
117 map.emplace(L"sysdiag", L"blockdiag");
118 map.emplace(L"with_tk", L"with_module('tclsci')");
119 map.emplace(L"xgetech", L"gca");
120 map.emplace(L"xinfo", L"gcf().info_message");
122 // Scilab 5.5.2 => 6.0.0
123 map.emplace(L"fort", L"call");
124 map.emplace(L"znaupd", L"eigs");
125 map.emplace(L"zneupd", L"eigs");
126 map.emplace(L"dseupd", L"eigs");
127 map.emplace(L"dneupd", L"eigs");
128 map.emplace(L"dnaupd", L"eigs");
129 map.emplace(L"dsaupd", L"eigs");
131 map.emplace(L"m_circle", L"hallchart");
132 map.emplace(L"plot2d1", L"plot2d");
133 map.emplace(L"xclear", L"clf");
134 map.emplace(L"datatipSetStruct", L"");
135 map.emplace(L"datatipGetStruct", L"");
136 map.emplace(L"fcontour2d", L"contour2d");
137 map.emplace(L"fcontour", L"contour");
138 map.emplace(L"fac3d", L"plot3d");
139 map.emplace(L"eval3d", L"ndgrid");
141 map.emplace(L"gspec", L"spec");
142 map.emplace(L"gschur", L"schur");
143 map.emplace(L"rafiter", L"taucs_chsolve");
144 map.emplace(L"numdiff", L"numderivative");
145 map.emplace(L"derivative", L"numderivative");
146 map.emplace(L"mvvacov", L"cov");
148 map.emplace(L"perl", L"");
149 map.emplace(L"lex_sort", L"gsort");
150 map.emplace(L"strcmpi", L"strcmp");
151 map.emplace(L"jconvMatrixMethod", L"jautoTranspose");
152 map.emplace(L"havewindow", L"getscilabmode");
153 map.emplace(L"xpause", L"sleep");
154 map.emplace(L"curblockc", L"curblock");
155 map.emplace(L"extract_help_examples", L"");
156 map.emplace(L"mtlb_mode", L"oldEmptyBehaviour");
158 map.emplace(L"addf", L"");
159 map.emplace(L"subf", L"");
160 map.emplace(L"mulf", L"");
161 map.emplace(L"ldivf", L"");
162 map.emplace(L"rdivf", L"");
163 map.emplace(L"cmb_lin", L"");
164 map.emplace(L"solve", L"");
165 map.emplace(L"trianfml", L"");
166 map.emplace(L"trisolve", L"");
167 map.emplace(L"bloc2exp", L"");
169 map.emplace(L"comp", L"exec");
170 map.emplace(L"errcatch", L"");
171 map.emplace(L"iserror", L"");
172 map.emplace(L"str2code", L"ascii");
173 map.emplace(L"code2str", L"ascii");
174 map.emplace(L"fun2string", L"string");
175 map.emplace(L"getvariablesonstack", L"who");
176 map.emplace(L"gstacksize", L"");
177 map.emplace(L"stacksize", L"");
178 map.emplace(L"macr2lst", L"");
179 map.emplace(L"readgateway", L"");
181 // Scilab 5.5.1 => 5.5.2
182 map.emplace(L"%asn", L"delip");
183 map.emplace(L"chart", L"nicholschart");
184 map.emplace(L"IsAScalar", L"isscalar");
185 map.emplace(L"jmat", L"flipdim");
186 map.emplace(L"mfft", L"ftt");
187 map.emplace(L"milk_drop", L"");
188 map.emplace(L"msd", L"stdev");
189 map.emplace(L"nfreq", L"tabul");
190 map.emplace(L"pcg", L"conjgrad");
191 map.emplace(L"regress", L"reglin");
192 map.emplace(L"relocate_handle", L"");
193 map.emplace(L"st_deviation", L"stdev");
194 map.emplace(L"xmltochm", L"");
195 map.emplace(L"xsetm", L"");
197 // Scilab 5.5.0 => 5.5.1
198 map.emplace(L"datatipContextMenu", L"");
199 map.emplace(L"datatipEventHandler", L"");
201 // SCilab 5.4.1 => 5.5.0
202 map.emplace(L"dft", L"fft");
203 map.emplace(L"sscanf", L"msscanf");
204 map.emplace(L"fscanf", L"mfscanf");
205 map.emplace(L"printf", L"mprintf");
206 map.emplace(L"fprintf", L"mfprintf");
207 map.emplace(L"sprintf", L"msprintf");
208 map.emplace(L"demo_message", L"");
209 map.emplace(L"demo_mdialog", L"");
210 map.emplace(L"draw", L"");
211 map.emplace(L"clear_pixmap", L"");
212 map.emplace(L"show_pixmap", L"");
213 map.emplace(L"winclose", L"close");
214 map.emplace(L"datatipInitStruct", L"");
215 map.emplace(L"datatipRedraw", L"");
216 map.emplace(L"getfont", L"");
217 map.emplace(L"getmark", L"");
218 map.emplace(L"getlinestyle", L"");
219 map.emplace(L"getsymbol", L"");
220 map.emplace(L"with_embedded_jre", L"");
221 map.emplace(L"fit_dat", L"datafit");
222 map.emplace(L"create_palette", L"");
224 // Scilab 5.4.0 => 5.4.1
225 map.emplace(L"chartoeom", L"");
226 map.emplace(L"eomtochar", L"");
227 map.emplace(L"config", L"preferences");
228 map.emplace(L"createpopup", L"uicontextmenu");
229 map.emplace(L"mtlb_conv", L"conv");
230 map.emplace(L"mtlb_repmat", L"repmat");
231 map.emplace(L"neldermead_display", L"disp");
232 map.emplace(L"nmplot_display", L"disp");
233 map.emplace(L"optimbase_display", L"disp");
234 map.emplace(L"optimsimplex_print", L"disp");
235 map.emplace(L"iptim_simplex_tostring", L"string");
236 map.emplace(L"ricc_old", L"ricc");
237 map.emplace(L"showalluimenushandles", L"set(get(0), \"ShowHiddenHandles\", \"on\")");
238 map.emplace(L"with_pvm", L"getversion");
239 map.emplace(L"with_texmacs", L"");
240 map.emplace(L"xbasr", L"");
241 map.emplace(L"xselect", L"show_window");
243 // Scilab 5.3.3 => 5.4.0
244 map.emplace(L"MSDOS", L"getos");
245 map.emplace(L"sd2sci", L"");
246 map.emplace(L"oldplot", L"");
248 // Scilab 5.3.0 => 5.3.3: nothing removed
250 // Scilab 5.2.X => 5.3.0
251 map.emplace(L"maxi", L"max");
252 map.emplace(L"mini", L"min");
253 map.emplace(L"oldbesseli", L"besseli");
254 map.emplace(L"oldbesselj", L"besselj");
255 map.emplace(L"oldbesselk", L"besselk");
256 map.emplace(L"oldbessely", L"bessely");
257 map.emplace(L"textprint", L"prettyprint");
258 map.emplace(L"pol2tex", L"prettyprint");
259 map.emplace(L"xgetfile", L"uigetfile");
260 map.emplace(L"tk_getfile", L"uigetfile");
261 map.emplace(L"tk_savefile", L"uiputfile");
262 map.emplace(L"tk_getdir", L"uigetdir");
263 map.emplace(L"tk_choose", L"x_choose");
264 map.emplace(L"sci2excel", L"csvWrite");
265 map.emplace(L"excel2sci", L"csvRead");
266 map.emplace(L"x_message_modeless", L"messagebox");
267 map.emplace(L"sethomedirectory", L"SCIHOME,home");
268 map.emplace(L"getcwd", L"pwd");
269 map.emplace(L"xbasc", L"clf");
270 map.emplace(L"getf", L"exec");
271 map.emplace(L"NumTokens", L"tokens");
272 map.emplace(L"sort", L"gsort");
273 map.emplace(L"scilab_demos", L"demo_gui");
274 map.emplace(L"with_gtk", L"getversion");
275 map.emplace(L"readc_", L"input");
277 // Scilab 5.2.1 => 5.2.2
278 map.emplace(L"oldsave", L"save");
279 map.emplace(L"oldload", L"load");
281 // Scilab 5.2.0 => 5.2.1: nothing removed
283 // Scilab 5.1.1 => 5.2.0
284 map.emplace(L"lgfft", L"");
286 // Scilab 5.1.0 => 5.1.1: nothing removed
288 // Scilab 5.0.X => 5.1.0
289 map.emplace(L"mtlb_load", L"loadmatfile");
290 map.emplace(L"mtlb_save", L"savematfile");
291 map.emplace(L"xbasimp", L"toprint,xs2ps");
292 map.emplace(L"xg2ps", L"xs2ps");
293 map.emplace(L"hidetoolbar", L"toolbar(,\'off\')");
294 map.emplace(L"browsehelp", L"helpbrowser");
295 map.emplace(L"quapro", L"qpsolve");
296 map.emplace(L"%sp_eye", L"speye");
297 map.emplace(L"TCL_gcf", L"gcf");
298 map.emplace(L"TCL_scf", L"scf");
299 map.emplace(L"TK_EvalStr", L"TCL_EvalStr");
300 map.emplace(L"TK_GetVar", L"TCL_GetVar");
301 map.emplace(L"TK_SetVar", L"TCL_SetVar");
302 map.emplace(L"sciGUIhelp", L"help");
303 map.emplace(L"demoplay", L"demo_gui");
304 map.emplace(L"buttondialog", L"messagebox");
305 map.emplace(L"tk_getvalue", L"getvalue");
307 // Scilab 5.0.1 => 5.0.3: nothing removed
309 // Scilab 4.1.2 => 5.0
310 map.emplace(L"xclea", L"xfrect");
311 map.emplace(L"xaxis", L"drawaxis");
312 map.emplace(L"loadplots", L"");
313 map.emplace(L"xtape", L"");
314 map.emplace(L"loaddefaultbrowser", L"");
315 map.emplace(L"%browsehelp", L"");
320 std::unordered_map<std::wstring, std::shared_ptr<SLintChecker>> DeprecatedChecker::initPartDep()
322 std::unordered_map<std::wstring, std::shared_ptr<SLintChecker>> map;
323 map.emplace(L"svd", std::shared_ptr<SLintChecker>(new __Svd()));
324 map.emplace(L"mfprintf", std::shared_ptr<SLintChecker>(new __Mfprintf()));