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