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;
95 // Scilab 6.0.x => 6.1.0
96 map.emplace(L"_d", L"_");
97 map.emplace(L"dgettext", L"gettext");
98 map.emplace(L"datatipToggle", L"datatipManagerMode");
99 map.emplace(L"denom", L".den");
100 map.emplace(L"hypermat", L"zeros|matrix");
101 map.emplace(L"lstsize", L"size");
102 map.emplace(L"nanmin", L"min");
103 map.emplace(L"nanmax", L"max");
104 map.emplace(L"numer", L".num");
105 map.emplace(L"square", L"replot");
106 map.emplace(L"with_tk", L"with_module('tclsci')");
107 map.emplace(L"xgetech", L"gca");
108 map.emplace(L"xinfo", L"gcf().info_message");
110 // Scilab 5.5.2 => 6.0.0
111 map.emplace(L"fort", L"call");
112 map.emplace(L"znaupd", L"eigs");
113 map.emplace(L"zneupd", L"eigs");
114 map.emplace(L"dseupd", L"eigs");
115 map.emplace(L"dneupd", L"eigs");
116 map.emplace(L"dnaupd", L"eigs");
117 map.emplace(L"dsaupd", L"eigs");
119 map.emplace(L"m_circle", L"hallchart");
120 map.emplace(L"plot2d1", L"plot2d");
121 map.emplace(L"xclear", L"clf");
122 map.emplace(L"datatipSetStruct", L"");
123 map.emplace(L"datatipGetStruct", L"");
124 map.emplace(L"fcontour2d", L"contour2d");
125 map.emplace(L"fcontour", L"contour");
126 map.emplace(L"fac3d", L"plot3d");
127 map.emplace(L"eval3d", L"ndgrid");
129 map.emplace(L"gspec", L"spec");
130 map.emplace(L"gschur", L"schur");
131 map.emplace(L"rafiter", L"taucs_chsolve");
132 map.emplace(L"numdiff", L"numderivative");
133 map.emplace(L"derivative", L"numderivative");
134 map.emplace(L"mvvacov", L"cov");
136 map.emplace(L"perl", L"");
137 map.emplace(L"lex_sort", L"gsort");
138 map.emplace(L"strcmpi", L"strcmp");
139 map.emplace(L"jconvMatrixMethod", L"jautoTranspose");
140 map.emplace(L"havewindow", L"getscilabmode");
141 map.emplace(L"xpause", L"sleep");
142 map.emplace(L"curblockc", L"curblock");
143 map.emplace(L"extract_help_examples", L"");
144 map.emplace(L"mtlb_mode", L"oldEmptyBehaviour");
146 map.emplace(L"addf", L"");
147 map.emplace(L"subf", L"");
148 map.emplace(L"mulf", L"");
149 map.emplace(L"ldivf", L"");
150 map.emplace(L"rdivf", L"");
151 map.emplace(L"cmb_lin", L"");
152 map.emplace(L"solve", L"");
153 map.emplace(L"trianfml", L"");
154 map.emplace(L"trisolve", L"");
155 map.emplace(L"bloc2exp", L"");
157 map.emplace(L"comp", L"exec");
158 map.emplace(L"errcatch", L"");
159 map.emplace(L"iserror", L"");
160 map.emplace(L"str2code", L"ascii");
161 map.emplace(L"code2str", L"ascii");
162 map.emplace(L"fun2string", L"string");
163 map.emplace(L"getvariablesonstack", L"who");
164 map.emplace(L"gstacksize", L"");
165 map.emplace(L"stacksize", L"");
166 map.emplace(L"macr2lst", L"");
167 map.emplace(L"readgateway", L"");
169 // Scilab 5.5.1 => 5.5.2
170 map.emplace(L"%asn", L"delip");
171 map.emplace(L"chart", L"nicholschart");
172 map.emplace(L"IsAScalar", L"isscalar");
173 map.emplace(L"jmat", L"flipdim");
174 map.emplace(L"mfft", L"ftt");
175 map.emplace(L"milk_drop", L"");
176 map.emplace(L"msd", L"stdev");
177 map.emplace(L"nfreq", L"tabul");
178 map.emplace(L"pcg", L"conjgrad");
179 map.emplace(L"regress", L"reglin");
180 map.emplace(L"relocate_handle", L"");
181 map.emplace(L"st_deviation", L"stdev");
182 map.emplace(L"xmltochm", L"");
183 map.emplace(L"xsetm", L"");
185 // Scilab 5.5.0 => 5.5.1
186 map.emplace(L"datatipContextMenu", L"");
187 map.emplace(L"datatipEventHandler", L"");
189 // SCilab 5.4.1 => 5.5.0
190 map.emplace(L"dft", L"fft");
191 map.emplace(L"sscanf", L"msscanf");
192 map.emplace(L"fscanf", L"mfscanf");
193 map.emplace(L"printf", L"mprintf");
194 map.emplace(L"fprintf", L"mfprintf");
195 map.emplace(L"sprintf", L"msprintf");
196 map.emplace(L"demo_message", L"");
197 map.emplace(L"demo_mdialog", L"");
198 map.emplace(L"draw", L"");
199 map.emplace(L"clear_pixmap", L"");
200 map.emplace(L"show_pixmap", L"");
201 map.emplace(L"winclose", L"close");
202 map.emplace(L"datatipInitStruct", L"");
203 map.emplace(L"datatipRedraw", L"");
204 map.emplace(L"getfont", L"");
205 map.emplace(L"getmark", L"");
206 map.emplace(L"getlinestyle", L"");
207 map.emplace(L"getsymbol", L"");
208 map.emplace(L"with_embedded_jre", L"");
209 map.emplace(L"fit_dat", L"datafit");
210 map.emplace(L"create_palette", L"");
212 // Scilab 5.4.0 => 5.4.1
213 map.emplace(L"chartoeom", L"");
214 map.emplace(L"eomtochar", L"");
215 map.emplace(L"config", L"preferences");
216 map.emplace(L"createpopup", L"uicontextmenu");
217 map.emplace(L"mtlb_conv", L"conv");
218 map.emplace(L"mtlb_repmat", L"repmat");
219 map.emplace(L"neldermead_display", L"disp");
220 map.emplace(L"nmplot_display", L"disp");
221 map.emplace(L"optimbase_display", L"disp");
222 map.emplace(L"optimsimplex_print", L"disp");
223 map.emplace(L"iptim_simplex_tostring", L"string");
224 map.emplace(L"ricc_old", L"ricc");
225 map.emplace(L"showalluimenushandles", L"set(get(0), \"ShowHiddenHandles\", \"on\")");
226 map.emplace(L"with_pvm", L"getversion");
227 map.emplace(L"with_texmacs", L"");
228 map.emplace(L"xbasr", L"");
229 map.emplace(L"xselect", L"show_window");
231 // Scilab 5.3.3 => 5.4.0
232 map.emplace(L"MSDOS", L"getos");
233 map.emplace(L"sd2sci", L"");
234 map.emplace(L"oldplot", L"");
236 // Scilab 5.3.0 => 5.3.3: nothing removed
238 // Scilab 5.2.X => 5.3.0
239 map.emplace(L"maxi", L"max");
240 map.emplace(L"mini", L"min");
241 map.emplace(L"oldbesseli", L"besseli");
242 map.emplace(L"oldbesselj", L"besselj");
243 map.emplace(L"oldbesselk", L"besselk");
244 map.emplace(L"oldbessely", L"bessely");
245 map.emplace(L"textprint", L"prettyprint");
246 map.emplace(L"pol2tex", L"prettyprint");
247 map.emplace(L"xgetfile", L"uigetfile");
248 map.emplace(L"tk_getfile", L"uigetfile");
249 map.emplace(L"tk_savefile", L"uiputfile");
250 map.emplace(L"tk_getdir", L"uigetdir");
251 map.emplace(L"tk_choose", L"x_choose");
252 map.emplace(L"sci2excel", L"csvWrite");
253 map.emplace(L"excel2sci", L"csvRead");
254 map.emplace(L"x_message_modeless", L"messagebox");
255 map.emplace(L"sethomedirectory", L"SCIHOME,home");
256 map.emplace(L"getcwd", L"pwd");
257 map.emplace(L"xbasc", L"clf");
258 map.emplace(L"getf", L"exec");
259 map.emplace(L"NumTokens", L"tokens");
260 map.emplace(L"sort", L"gsort");
261 map.emplace(L"scilab_demos", L"demo_gui");
262 map.emplace(L"with_gtk", L"getversion");
263 map.emplace(L"readc_", L"input");
265 // Scilab 5.2.1 => 5.2.2
266 map.emplace(L"oldsave", L"save");
267 map.emplace(L"oldload", L"load");
269 // Scilab 5.2.0 => 5.2.1: nothing removed
271 // Scilab 5.1.1 => 5.2.0
272 map.emplace(L"lgfft", L"");
274 // Scilab 5.1.0 => 5.1.1: nothing removed
276 // Scilab 5.0.X => 5.1.0
277 map.emplace(L"mtlb_load", L"loadmatfile");
278 map.emplace(L"mtlb_save", L"savematfile");
279 map.emplace(L"xbasimp", L"toprint,xs2ps");
280 map.emplace(L"xg2ps", L"xs2ps");
281 map.emplace(L"hidetoolbar", L"toolbar(,\'off\')");
282 map.emplace(L"browsehelp", L"helpbrowser");
283 map.emplace(L"quapro", L"qpsolve");
284 map.emplace(L"%sp_eye", L"speye");
285 map.emplace(L"TCL_gcf", L"gcf");
286 map.emplace(L"TCL_scf", L"scf");
287 map.emplace(L"TK_EvalStr", L"TCL_EvalStr");
288 map.emplace(L"TK_GetVar", L"TCL_GetVar");
289 map.emplace(L"TK_SetVar", L"TCL_SetVar");
290 map.emplace(L"sciGUIhelp", L"help");
291 map.emplace(L"demoplay", L"demo_gui");
292 map.emplace(L"buttondialog", L"messagebox");
293 map.emplace(L"tk_getvalue", L"getvalue");
295 // Scilab 5.0.1 => 5.0.3: nothing removed
297 // Scilab 4.1.2 => 5.0
298 map.emplace(L"xclea", L"xfrect");
299 map.emplace(L"xaxis", L"drawaxis");
300 map.emplace(L"loadplots", L"");
301 map.emplace(L"xtape", L"");
302 map.emplace(L"loaddefaultbrowser", L"");
303 map.emplace(L"%browsehelp", L"");
308 std::unordered_map<std::wstring, std::shared_ptr<SLintChecker>> DeprecatedChecker::initPartDep()
310 std::unordered_map<std::wstring, std::shared_ptr<SLintChecker>> map;
311 map.emplace(L"svd", std::shared_ptr<SLintChecker>(new __Svd()));
312 map.emplace(L"mfprintf", std::shared_ptr<SLintChecker>(new __Mfprintf()));