]>
Commit | Line | Data |
---|---|---|
5934cda1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: ifacecheck.cpp | |
3 | // Purpose: Interface headers <=> real headers coherence checker | |
4 | // Author: Francesco Montorsi | |
5 | // Created: 2008/03/17 | |
5934cda1 FM |
6 | // Copyright: (c) 2008 Francesco Montorsi |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx/wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
17 | // for all others, include the necessary headers | |
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/app.h" | |
e7bed112 | 20 | #include "wx/crt.h" |
5934cda1 FM |
21 | #endif |
22 | ||
23 | #include "wx/cmdline.h" | |
24 | #include "wx/textfile.h" | |
d5978709 | 25 | #include "wx/filename.h" |
fdd4a897 | 26 | #include "wx/stopwatch.h" // for wxGetLocalTime |
5934cda1 FM |
27 | #include "xmlparser.h" |
28 | ||
29 | // global verbosity flag | |
30 | bool g_verbose = false; | |
31 | ||
32 | ||
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // IfaceCheckApp | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
5570107a FM |
38 | #define API_DUMP_FILE "dump.api.txt" |
39 | #define INTERFACE_DUMP_FILE "dump.interface.txt" | |
5934cda1 | 40 | |
5570107a FM |
41 | #define PROCESS_ONLY_OPTION "p" |
42 | #define USE_PREPROCESSOR_OPTION "u" | |
43 | ||
44 | #define MODIFY_SWITCH "m" | |
45 | #define DUMP_SWITCH "d" | |
46 | #define HELP_SWITCH "h" | |
47 | #define VERBOSE_SWITCH "v" | |
5934cda1 FM |
48 | |
49 | static const wxCmdLineEntryDesc g_cmdLineDesc[] = | |
50 | { | |
5570107a FM |
51 | { wxCMD_LINE_OPTION, USE_PREPROCESSOR_OPTION, "use-preproc", |
52 | "uses the preprocessor output to increase the checker accuracy", | |
53 | wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR }, | |
54 | { wxCMD_LINE_OPTION, PROCESS_ONLY_OPTION, "process-only", | |
d5978709 FM |
55 | "processes only header files matching the given wildcard", |
56 | wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR }, | |
5934cda1 FM |
57 | { wxCMD_LINE_SWITCH, MODIFY_SWITCH, "modify", |
58 | "modify the interface headers to match the real ones" }, | |
d5978709 FM |
59 | { wxCMD_LINE_SWITCH, DUMP_SWITCH, "dump", |
60 | "dump both interface and API to plain text dump.*.txt files" }, | |
5934cda1 FM |
61 | { wxCMD_LINE_SWITCH, HELP_SWITCH, "help", |
62 | "show help message", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, | |
63 | { wxCMD_LINE_SWITCH, VERBOSE_SWITCH, "verbose", | |
64 | "be verbose" }, | |
65 | { wxCMD_LINE_PARAM, NULL, NULL, | |
66 | "gccXML", wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY }, | |
67 | { wxCMD_LINE_PARAM, NULL, NULL, | |
68 | "doxygenXML", wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY }, | |
69 | wxCMD_LINE_DESC_END | |
70 | }; | |
71 | ||
7f8fae98 FM |
72 | class IfaceCheckLog : public wxLog |
73 | { | |
74 | public: | |
75 | IfaceCheckLog() {} | |
76 | ||
74e67db7 | 77 | virtual void DoLogText(const wxString& msg) |
7f8fae98 | 78 | { |
e2d1c0e7 | 79 | // send all messages to stdout (normal behaviour is to sent them to stderr) |
74e67db7 VZ |
80 | wxPuts(msg); |
81 | fflush(stdout); | |
7f8fae98 FM |
82 | } |
83 | }; | |
84 | ||
5934cda1 FM |
85 | class IfaceCheckApp : public wxAppConsole |
86 | { | |
87 | public: | |
88 | // don't use builtin cmd line parsing: | |
89 | virtual bool OnInit() { m_modify=false; return true; } | |
90 | virtual int OnRun(); | |
91 | ||
5570107a FM |
92 | bool ParsePreprocessorOutput(const wxString& filename); |
93 | ||
5934cda1 | 94 | bool Compare(); |
673ae68a | 95 | int CompareClasses(const wxClass* iface, const wxClass* api); |
97f0dbd6 | 96 | bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api); |
83fdf796 | 97 | bool StringContainsMethodName(const wxString& str, const wxMethod* m); |
5934cda1 | 98 | |
5934cda1 FM |
99 | void PrintStatistics(long secs); |
100 | ||
d5978709 FM |
101 | bool IsToProcess(const wxString& headername) const |
102 | { | |
103 | if (m_strToMatch.IsEmpty()) | |
104 | return true; | |
105 | return wxMatchWild(m_strToMatch, headername, false); | |
106 | } | |
107 | ||
5934cda1 | 108 | protected: |
03d4f7b9 FM |
109 | wxXmlGccInterface m_gccInterface; // "real" headers API |
110 | wxXmlDoxygenInterface m_doxyInterface; // doxygen-commented headers API | |
5934cda1 FM |
111 | |
112 | // was the MODIFY_SWITCH passed? | |
113 | bool m_modify; | |
d5978709 | 114 | |
5570107a | 115 | // if non-empty, then PROCESS_ONLY_OPTION was passed and this is the |
d5978709 FM |
116 | // wildcard expression to match |
117 | wxString m_strToMatch; | |
5934cda1 FM |
118 | }; |
119 | ||
120 | IMPLEMENT_APP_CONSOLE(IfaceCheckApp) | |
121 | ||
122 | int IfaceCheckApp::OnRun() | |
123 | { | |
124 | long startTime = wxGetLocalTime(); // for timing purpose | |
125 | ||
5934cda1 | 126 | wxCmdLineParser parser(g_cmdLineDesc, argc, argv); |
5570107a FM |
127 | parser.SetLogo( |
128 | wxString::Format("wxWidgets Interface checker utility (built %s against %s)", | |
129 | __DATE__, wxVERSION_STRING)); | |
130 | ||
7f8fae98 FM |
131 | // make the output more readable: |
132 | wxLog::SetActiveTarget(new IfaceCheckLog); | |
133 | wxLog::DisableTimestamp(); | |
134 | ||
5570107a | 135 | // parse the command line... |
5934cda1 | 136 | bool ok = true; |
5570107a | 137 | wxString preprocFile; |
5934cda1 FM |
138 | switch (parser.Parse()) |
139 | { | |
5934cda1 FM |
140 | case 0: |
141 | if (parser.Found(VERBOSE_SWITCH)) | |
142 | g_verbose = true; | |
143 | ||
5570107a FM |
144 | // IMPORTANT: parsing #define values must be done _before_ actually |
145 | // parsing the GCC/doxygen XML files | |
146 | if (parser.Found(USE_PREPROCESSOR_OPTION, &preprocFile)) | |
147 | { | |
148 | if (!ParsePreprocessorOutput(preprocFile)) | |
149 | return 1; | |
150 | } | |
151 | ||
152 | // in any case set basic std preprocessor #defines: | |
03d4f7b9 | 153 | m_doxyInterface.AddPreprocessorValue("NULL", "0"); |
5570107a FM |
154 | |
155 | // parse the two XML files which contain the real and the doxygen interfaces | |
156 | // for wxWidgets API: | |
03d4f7b9 FM |
157 | if (!m_gccInterface.Parse(parser.GetParam(0)) || |
158 | !m_doxyInterface.Parse(parser.GetParam(1))) | |
5934cda1 FM |
159 | return 1; |
160 | ||
161 | if (parser.Found(DUMP_SWITCH)) | |
162 | { | |
7f8fae98 | 163 | wxLogMessage("Dumping real API to '%s'...", API_DUMP_FILE); |
03d4f7b9 | 164 | m_gccInterface.Dump(API_DUMP_FILE); |
5934cda1 | 165 | |
7f8fae98 | 166 | wxLogMessage("Dumping interface API to '%s'...", INTERFACE_DUMP_FILE); |
03d4f7b9 | 167 | m_doxyInterface.Dump(INTERFACE_DUMP_FILE); |
5934cda1 FM |
168 | } |
169 | else | |
170 | { | |
171 | if (parser.Found(MODIFY_SWITCH)) | |
172 | m_modify = true; | |
173 | ||
5570107a | 174 | if (parser.Found(PROCESS_ONLY_OPTION, &m_strToMatch)) |
d5978709 FM |
175 | { |
176 | size_t len = m_strToMatch.Len(); | |
177 | if (m_strToMatch.StartsWith("\"") && | |
178 | m_strToMatch.EndsWith("\"") && | |
179 | len > 2) | |
180 | m_strToMatch = m_strToMatch.Mid(1, len-2); | |
181 | } | |
182 | ||
97f0dbd6 | 183 | |
5934cda1 FM |
184 | ok = Compare(); |
185 | } | |
186 | ||
187 | PrintStatistics(wxGetLocalTime() - startTime); | |
188 | return ok ? 0 : 1; | |
5570107a FM |
189 | |
190 | default: | |
191 | wxPrintf("\nThis utility checks that the interface XML files created by Doxygen are in\n"); | |
192 | wxPrintf("synch with the real headers (whose contents are extracted by the gcc XML file).\n\n"); | |
193 | wxPrintf("The 'gccXML' parameter should be the wxapi.xml file created by the 'rungccxml.sh'\n"); | |
194 | wxPrintf("script which resides in 'utils/ifacecheck'.\n"); | |
195 | wxPrintf("The 'doxygenXML' parameter should be the index.xml file created by Doxygen\n"); | |
196 | wxPrintf("for the wxWidgets 'interface' folder.\n\n"); | |
197 | wxPrintf("Since the gcc XML file does not contain info about #defines, if you use\n"); | |
198 | wxPrintf("the -%s option, you'll get a smaller number of false warnings.\n", | |
199 | USE_PREPROCESSOR_OPTION); | |
200 | ||
201 | // HELP_SWITCH was passed or a syntax error occurred | |
202 | return 0; | |
5934cda1 | 203 | } |
5934cda1 FM |
204 | } |
205 | ||
5934cda1 FM |
206 | bool IfaceCheckApp::Compare() |
207 | { | |
d2875249 | 208 | const wxClassArray& interfaces = m_doxyInterface.GetClasses(); |
5934cda1 | 209 | const wxClass* c; |
5934cda1 FM |
210 | int mcount = 0, ccount = 0; |
211 | ||
7f8fae98 FM |
212 | wxLogMessage("Comparing the interface API to the real API (%d classes to compare)...", |
213 | interfaces.GetCount()); | |
5934cda1 | 214 | |
d5978709 | 215 | if (!m_strToMatch.IsEmpty()) |
43b2d5e7 | 216 | { |
7f8fae98 | 217 | wxLogMessage("Processing only header files matching '%s' expression.", m_strToMatch); |
43b2d5e7 | 218 | } |
d5978709 | 219 | |
d2875249 | 220 | for (unsigned int i=0; i<interfaces.GetCount(); i++) |
5934cda1 | 221 | { |
03d4f7b9 FM |
222 | // only compare the methods which are available for the port |
223 | // for which the gcc XML was produced | |
d2875249 VZ |
224 | if (interfaces[i].GetAvailability() != wxPORT_UNKNOWN && |
225 | (interfaces[i].GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) { | |
03d4f7b9 FM |
226 | |
227 | if (g_verbose) | |
43b2d5e7 | 228 | { |
7f8fae98 | 229 | wxLogMessage("skipping class '%s' since it's not available for the %s port.", |
d2875249 | 230 | interfaces[i].GetName(), m_gccInterface.GetInterfacePortName()); |
43b2d5e7 | 231 | } |
03d4f7b9 FM |
232 | |
233 | continue; // skip this method | |
234 | } | |
235 | ||
d5978709 FM |
236 | // shorten the name of the header so the log file is more readable |
237 | // and also for calling IsToProcess() against it | |
d2875249 | 238 | wxString header = wxFileName(interfaces[i].GetHeader()).GetFullName(); |
d5978709 FM |
239 | |
240 | if (!IsToProcess(header)) | |
241 | continue; // skip this one | |
242 | ||
d2875249 | 243 | wxString cname = interfaces[i].GetName(); |
5934cda1 | 244 | |
9d9c1c24 FM |
245 | // search in the real headers for i-th interface class; we search for |
246 | // both class cname and cnameBase since in wxWidgets world tipically | |
5934cda1 FM |
247 | // class cname is platform-specific while the real public interface of |
248 | // that class is part of the cnameBase class. | |
673ae68a FM |
249 | /*c = m_gccInterface.FindClass(cname + "Base"); |
250 | if (c) api.Add(c);*/ | |
9d9c1c24 | 251 | |
673ae68a FM |
252 | c = m_gccInterface.FindClass(cname); |
253 | if (!c) | |
254 | { | |
255 | // sometimes the platform-specific class is named "wxGeneric" + cname | |
256 | // or similar: | |
257 | c = m_gccInterface.FindClass("wxGeneric" + cname.Mid(2)); | |
258 | if (!c) | |
259 | { | |
260 | c = m_gccInterface.FindClass("wxGtk" + cname.Mid(2)); | |
261 | } | |
262 | } | |
5934cda1 | 263 | |
673ae68a | 264 | if (c) { |
5934cda1 | 265 | |
673ae68a FM |
266 | // there is a class with the same (logic) name! |
267 | mcount += CompareClasses(&interfaces[i], c); | |
5934cda1 FM |
268 | |
269 | } else { | |
270 | ||
7f8fae98 | 271 | wxLogMessage("%s: couldn't find the real interface for the '%s' class", |
4168bc45 | 272 | header, cname); |
5934cda1 FM |
273 | ccount++; |
274 | } | |
275 | } | |
276 | ||
7f8fae98 | 277 | wxLogMessage("%d on a total of %d methods (%.1f%%) of the interface headers do not exist in the real headers", |
187c2f81 | 278 | mcount, m_doxyInterface.GetMethodCount(), (float)(100.0 * mcount/m_doxyInterface.GetMethodCount())); |
7f8fae98 | 279 | wxLogMessage("%d on a total of %d classes (%.1f%%) of the interface headers do not exist in the real headers", |
187c2f81 | 280 | ccount, m_doxyInterface.GetClassesCount(), (float)(100.0 * ccount/m_doxyInterface.GetClassesCount())); |
5934cda1 FM |
281 | |
282 | return true; | |
283 | } | |
284 | ||
673ae68a | 285 | int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api) |
5934cda1 | 286 | { |
5934cda1 FM |
287 | const wxMethod *real; |
288 | int count = 0; | |
289 | ||
673ae68a | 290 | wxASSERT(iface && api); |
5934cda1 | 291 | |
5934cda1 | 292 | // shorten the name of the header so the log file is more readable |
d5978709 | 293 | wxString header = wxFileName(iface->GetHeader()).GetFullName(); |
5934cda1 FM |
294 | |
295 | for (unsigned int i=0; i<iface->GetMethodCount(); i++) | |
296 | { | |
297 | const wxMethod& m = iface->GetMethod(i); | |
5934cda1 | 298 | |
03d4f7b9 FM |
299 | // only compare the methods which are available for the port |
300 | // for which the gcc XML was produced | |
301 | if (m.GetAvailability() != wxPORT_UNKNOWN && | |
302 | (m.GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) { | |
303 | ||
304 | if (g_verbose) | |
43b2d5e7 | 305 | { |
7f8fae98 | 306 | wxLogMessage("skipping method '%s' since it's not available for the %s port.", |
03d4f7b9 | 307 | m.GetAsString(), m_gccInterface.GetInterfacePortName()); |
43b2d5e7 | 308 | } |
03d4f7b9 FM |
309 | |
310 | continue; // skip this method | |
311 | } | |
312 | ||
5934cda1 | 313 | // search in the methods of the api classes provided |
673ae68a | 314 | real = api->RecursiveUpwardFindMethod(m, &m_gccInterface); |
5934cda1 | 315 | |
187c2f81 | 316 | // avoid some false positives: |
f3998820 FM |
317 | if (!real && m.ActsAsDefaultCtor()) |
318 | { | |
187c2f81 | 319 | // build an artificial default ctor for this class: |
f3998820 FM |
320 | wxMethod temp(m); |
321 | temp.GetArgumentTypes().Clear(); | |
322 | ||
187c2f81 | 323 | // repeat search: |
f3998820 FM |
324 | real = api->RecursiveUpwardFindMethod(temp, &m_gccInterface); |
325 | } | |
326 | ||
187c2f81 | 327 | // no matches? |
fce3374f | 328 | if (!real) |
5934cda1 | 329 | { |
187c2f81 | 330 | bool proceed = true; |
673ae68a FM |
331 | wxMethodPtrArray overloads = |
332 | api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface); | |
97f0dbd6 | 333 | |
187c2f81 FM |
334 | // avoid false positives: |
335 | for (unsigned int k=0; k<overloads.GetCount(); k++) | |
336 | if (overloads[k]->MatchesExceptForAttributes(m) && | |
337 | m.IsDeprecated() && !overloads[k]->IsDeprecated()) | |
338 | { | |
339 | // maybe the iface method is marked as deprecated but the | |
340 | // real method is not? | |
341 | wxMethod tmp(*overloads[k]); | |
342 | tmp.SetDeprecated(true); | |
343 | ||
344 | if (tmp == m) | |
345 | { | |
346 | // in this case, we can disregard this warning... the real | |
347 | // method probably is included in WXWIN_COMPAT sections! | |
348 | proceed = false; // skip this method | |
349 | } | |
350 | } | |
351 | ||
352 | #define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES 0 | |
8cd22478 | 353 | #if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES |
673ae68a | 354 | for (unsigned int k=0; k<overloads.GetCount(); k++) |
f3998820 | 355 | if (overloads[k]->MatchesExceptForAttributes(m)) |
673ae68a FM |
356 | { |
357 | // fix default values of results[k]: | |
358 | wxMethod tmp(*overloads[k]); | |
359 | tmp.SetArgumentTypes(m.GetArgumentTypes()); | |
360 | ||
361 | // modify interface header | |
362 | if (FixMethod(iface->GetHeader(), &m, &tmp)) | |
43b2d5e7 | 363 | { |
7f8fae98 | 364 | wxLogMessage("Adjusted attributes of '%s' method", m.GetAsString()); |
43b2d5e7 | 365 | } |
673ae68a | 366 | |
187c2f81 | 367 | proceed = false; |
97f0dbd6 | 368 | break; |
673ae68a | 369 | } |
71179c67 | 370 | #endif // HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES |
97f0dbd6 | 371 | |
187c2f81 | 372 | if (proceed) |
5934cda1 | 373 | { |
187c2f81 | 374 | if (overloads.GetCount()==0) |
a7be99c8 | 375 | { |
7f8fae98 | 376 | wxLogMessage("%s: real '%s' class and their parents have no method '%s'", |
187c2f81 FM |
377 | header, api->GetName(), m.GetAsString()); |
378 | // we've found no overloads | |
a7be99c8 FM |
379 | } |
380 | else | |
381 | { | |
187c2f81 FM |
382 | // first, output a warning |
383 | wxString warning = header; | |
384 | if (overloads.GetCount()>1) | |
385 | warning += wxString::Format(": in the real headers there are %d overloads of '%s' for " | |
386 | "'%s' all with different signatures:\n", | |
387 | overloads.GetCount(), m.GetName(), api->GetName()); | |
388 | else { | |
389 | warning += wxString::Format(": in the real headers there is a method '%s' for '%s'" | |
390 | " but has different signature:\n", | |
391 | m.GetName(), api->GetName()); | |
392 | } | |
a7be99c8 | 393 | |
187c2f81 FM |
394 | // get a list of the prototypes with _all_ possible attributes: |
395 | warning += "\tdoxy header: " + m.GetAsString(true, true, true, true); | |
396 | for (unsigned int j=0; j<overloads.GetCount(); j++) | |
397 | warning += "\n\treal header: " + overloads[j]->GetAsString(true, true, true, true); | |
398 | ||
d196416c | 399 | wxLogWarning("%s", warning); |
187c2f81 FM |
400 | count++; |
401 | ||
402 | if (overloads.GetCount()>1) | |
403 | { | |
404 | // TODO: decide which of these overloads is the most "similar" to m | |
405 | // and eventually modify it | |
406 | if (m_modify) | |
43b2d5e7 | 407 | { |
7f8fae98 | 408 | wxLogWarning("\tmanual fix is required"); |
43b2d5e7 | 409 | } |
187c2f81 FM |
410 | } |
411 | else | |
a7be99c8 | 412 | { |
187c2f81 | 413 | wxASSERT(overloads.GetCount() == 1); |
a7be99c8 | 414 | |
187c2f81 FM |
415 | if (m_modify || m.IsCtor()) |
416 | { | |
7f8fae98 | 417 | wxLogWarning("\tfixing it..."); |
187c2f81 FM |
418 | |
419 | // try to modify it! | |
420 | FixMethod(iface->GetHeader(), &m, overloads[0]); | |
421 | } | |
a7be99c8 FM |
422 | } |
423 | } | |
a7be99c8 | 424 | |
187c2f81 FM |
425 | count++; |
426 | } // if (proceed) | |
5934cda1 FM |
427 | } |
428 | } | |
429 | ||
430 | return count; | |
431 | } | |
432 | ||
83fdf796 FM |
433 | bool IfaceCheckApp::StringContainsMethodName(const wxString& str, const wxMethod* m) |
434 | { | |
435 | return str.Contains(m->GetName()) || | |
436 | (m->IsOperator() && str.Contains("operator")); | |
437 | } | |
438 | ||
97f0dbd6 | 439 | bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api) |
5934cda1 | 440 | { |
0a1bce69 | 441 | unsigned int i,j; |
5934cda1 FM |
442 | wxASSERT(iface && api); |
443 | ||
444 | wxTextFile file; | |
445 | if (!file.Open(header)) { | |
7f8fae98 | 446 | wxLogError("\tcan't open the '%s' header file.", header); |
97f0dbd6 | 447 | return false; |
5934cda1 FM |
448 | } |
449 | ||
83fdf796 FM |
450 | // GetLocation() returns the line where the last part of the prototype is placed; |
451 | // i.e. the line containing the semicolon at the end of the declaration. | |
5934cda1 | 452 | int end = iface->GetLocation()-1; |
919ccb4c | 453 | if (end <= 0 || end >= (int)file.GetLineCount()) { |
7f8fae98 | 454 | wxLogWarning("\tinvalid location info for method '%s': %d.", |
919ccb4c | 455 | iface->GetAsString(), iface->GetLocation()); |
97f0dbd6 | 456 | return false; |
919ccb4c | 457 | } |
5934cda1 | 458 | |
7fbadf87 | 459 | if (!file.GetLine(end).Contains(";")) { |
7f8fae98 | 460 | wxLogWarning("\tinvalid location info for method '%s': %d.", |
a7be99c8 | 461 | iface->GetAsString(), iface->GetLocation()); |
97f0dbd6 | 462 | return false; |
a7be99c8 FM |
463 | } |
464 | ||
97f0dbd6 | 465 | // is this a one-line prototype declaration? |
7fbadf87 | 466 | bool founddecl = false; |
97f0dbd6 | 467 | int start; |
83fdf796 | 468 | if (StringContainsMethodName(file.GetLine(end), iface)) |
7fbadf87 | 469 | { |
97f0dbd6 FM |
470 | // yes, this prototype is all on this line: |
471 | start = end; | |
472 | founddecl = true; | |
473 | } | |
474 | else | |
475 | { | |
83fdf796 | 476 | start = end; // will be decremented inside the while{} loop below |
919ccb4c | 477 | |
83fdf796 FM |
478 | // find the start point of this prototype declaration; i.e. the line |
479 | // containing the function name, which is also the line following | |
480 | // the marker '*/' for the closure of the doxygen comment | |
481 | do | |
97f0dbd6 | 482 | { |
83fdf796 | 483 | start--; // go up one line |
97f0dbd6 | 484 | |
83fdf796 FM |
485 | if (StringContainsMethodName(file.GetLine(start), iface)) |
486 | founddecl = true; | |
97f0dbd6 | 487 | } |
83fdf796 FM |
488 | while (start > 0 && !founddecl && |
489 | !file.GetLine(start).Contains(";") && | |
490 | !file.GetLine(start).Contains("*/")); | |
7fbadf87 FM |
491 | } |
492 | ||
493 | if (start <= 0 || !founddecl) | |
919ccb4c | 494 | { |
7f8fae98 | 495 | wxLogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header looking backwards from line %d; I arrived at %d and gave up", |
83fdf796 | 496 | iface->GetAsString(), header, end+1 /* zero-based => 1-based */, start); |
97f0dbd6 | 497 | return false; |
5934cda1 FM |
498 | } |
499 | ||
500 | // remove the old prototype | |
2985d7b7 | 501 | for (int k=start; k<=end; k++) |
919ccb4c FM |
502 | file.RemoveLine(start); // remove (end-start)-nth times the start-th line |
503 | ||
504 | #define INDENTATION_STR wxString(" ") | |
505 | ||
7fbadf87 FM |
506 | // if possible, add also the @deprecated tag in the doxygen comment if it's missing |
507 | int deprecationOffset = 0; | |
508 | if (file.GetLine(start-1).Contains("*/") && | |
509 | (api->IsDeprecated() && !iface->IsDeprecated())) | |
919ccb4c FM |
510 | { |
511 | file.RemoveLine(start-1); | |
512 | file.InsertLine(INDENTATION_STR + INDENTATION_STR + | |
513 | "@deprecated @todo provide deprecation description", start-1); | |
514 | file.InsertLine(INDENTATION_STR + "*/", start++); | |
7fbadf87 FM |
515 | |
516 | // we have added a new line in the final balance | |
517 | deprecationOffset=1; | |
919ccb4c | 518 | } |
5934cda1 | 519 | |
f270e1dd FM |
520 | wxMethod tmp(*api); |
521 | ||
83fdf796 FM |
522 | // discard gcc XML argument names and replace them with those parsed from doxygen XML; |
523 | // in this way we should avoid introducing doxygen warnings about cases where the argument | |
524 | // 'xx' of the prototype is called 'yy' in the function's docs. | |
f270e1dd FM |
525 | const wxArgumentTypeArray& doxygenargs = iface->GetArgumentTypes(); |
526 | const wxArgumentTypeArray& realargs = api->GetArgumentTypes(); | |
527 | if (realargs.GetCount() == doxygenargs.GetCount()) | |
528 | { | |
0a1bce69 | 529 | for (j=0; j<doxygenargs.GetCount(); j++) |
f270e1dd | 530 | if (doxygenargs[j]==realargs[j]) |
83fdf796 | 531 | { |
f270e1dd FM |
532 | realargs[j].SetArgumentName(doxygenargs[j].GetArgumentName()); |
533 | ||
83fdf796 FM |
534 | if (realargs[j].GetDefaultValue().IsNumber() && |
535 | doxygenargs[j].GetDefaultValue().StartsWith("wx")) | |
536 | realargs[j].SetDefaultValue(doxygenargs[j].GetDefaultValue()); | |
537 | } | |
538 | ||
f270e1dd FM |
539 | tmp.SetArgumentTypes(realargs); |
540 | } | |
541 | ||
7fbadf87 FM |
542 | #define WRAP_COLUMN 80 |
543 | ||
544 | wxArrayString toinsert; | |
545 | toinsert.Add(INDENTATION_STR + tmp.GetAsString() + ";"); | |
546 | ||
547 | int nStartColumn = toinsert[0].Find('('); | |
548 | wxASSERT(nStartColumn != wxNOT_FOUND); | |
549 | ||
550 | // wrap lines too long at comma boundaries | |
0a1bce69 | 551 | for (i=0; i<toinsert.GetCount(); i++) |
7fbadf87 FM |
552 | { |
553 | size_t len = toinsert[i].Len(); | |
554 | if (len > WRAP_COLUMN) | |
555 | { | |
556 | wxASSERT(i == toinsert.GetCount()-1); | |
557 | ||
558 | // break this line | |
559 | wxString tmpleft = toinsert[i].Left(WRAP_COLUMN); | |
560 | int comma = tmpleft.Find(',', true /* from end */); | |
561 | if (comma == wxNOT_FOUND) | |
562 | break; // break out of the for cycle... | |
563 | ||
564 | toinsert.Add(wxString(' ', nStartColumn+1) + | |
565 | toinsert[i].Right(len-comma-2)); // exclude the comma and the space after it | |
566 | toinsert[i] = tmpleft.Left(comma+1); // include the comma | |
567 | } | |
568 | } | |
569 | ||
570 | // insert the new lines | |
0a1bce69 | 571 | for (i=0; i<toinsert.GetCount(); i++) |
7fbadf87 | 572 | file.InsertLine(toinsert[i], start+i); |
5934cda1 | 573 | |
919ccb4c | 574 | // now save the modification |
5934cda1 | 575 | if (!file.Write()) { |
7f8fae98 | 576 | wxLogError("\tcan't save the '%s' header file.", header); |
97f0dbd6 | 577 | return false; |
7fbadf87 FM |
578 | } |
579 | ||
580 | // how many lines did we add/remove in total? | |
581 | int nOffset = toinsert.GetCount() + deprecationOffset - (end-start+1); | |
582 | if (nOffset == 0) | |
97f0dbd6 | 583 | return false; |
7fbadf87 FM |
584 | |
585 | if (g_verbose) | |
43b2d5e7 | 586 | { |
7f8fae98 | 587 | wxLogMessage("\tthe final row offset for following methods is %d lines.", nOffset); |
43b2d5e7 | 588 | } |
7fbadf87 FM |
589 | |
590 | // update the other method's locations for those methods which belong to the modified header | |
591 | // and are placed _below_ the modified method | |
03d4f7b9 | 592 | wxClassPtrArray cToUpdate = m_doxyInterface.FindClassesDefinedIn(header); |
0a1bce69 | 593 | for (i=0; i < cToUpdate.GetCount(); i++) |
7fbadf87 | 594 | { |
0a1bce69 | 595 | for (j=0; j < cToUpdate[i]->GetMethodCount(); j++) |
7fbadf87 FM |
596 | { |
597 | wxMethod& m = cToUpdate[i]->GetMethod(j); | |
598 | if (m.GetLocation() > iface->GetLocation()) | |
599 | { | |
600 | // update the location of this method | |
601 | m.SetLocation(m.GetLocation()+nOffset); | |
602 | } | |
603 | } | |
5934cda1 | 604 | } |
97f0dbd6 FM |
605 | |
606 | return true; | |
5934cda1 FM |
607 | } |
608 | ||
5570107a FM |
609 | bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename) |
610 | { | |
611 | wxTextFile tf; | |
612 | if (!tf.Open(filename)) { | |
7f8fae98 | 613 | wxLogError("can't open the '%s' preprocessor output file.", filename); |
5570107a FM |
614 | return false; |
615 | } | |
616 | ||
617 | size_t useful = 0; | |
618 | for (unsigned int i=0; i < tf.GetLineCount(); i++) | |
619 | { | |
620 | const wxString& line = tf.GetLine(i); | |
621 | wxString defnameval = line.Mid(8); // what follows the "#define " string | |
622 | ||
623 | // the format of this line should be: | |
624 | // #define DEFNAME DEFVALUE | |
0d2f4076 | 625 | if (!line.StartsWith("#define ")) { |
7f8fae98 | 626 | wxLogError("unexpected content in '%s' at line %d.", filename, i+1); |
5570107a FM |
627 | return false; |
628 | } | |
629 | ||
0d2f4076 FM |
630 | if (defnameval.Contains(" ")) |
631 | { | |
632 | // get DEFNAME | |
633 | wxString defname = defnameval.BeforeFirst(' '); | |
634 | if (defname.Contains("(")) | |
635 | continue; // this is a macro, skip it! | |
636 | ||
637 | // get DEFVAL | |
638 | wxString defval = defnameval.AfterFirst(' ').Strip(wxString::both); | |
639 | if (defval.StartsWith("(") && defval.EndsWith(")")) | |
640 | defval = defval.Mid(1, defval.Len()-2); | |
641 | ||
642 | // store this pair in the doxygen interface, where it can be useful | |
643 | m_doxyInterface.AddPreprocessorValue(defname, defval); | |
644 | useful++; | |
645 | } | |
646 | else | |
647 | { | |
648 | // it looks like the format of this line is: | |
649 | // #define DEFNAME | |
650 | // we are not interested to symbols #defined to nothing, | |
651 | // so we just ignore this line. | |
652 | } | |
5570107a FM |
653 | } |
654 | ||
7f8fae98 | 655 | wxLogMessage("Parsed %d preprocessor #defines from '%s' which will be used later...", |
5570107a FM |
656 | useful, filename); |
657 | ||
658 | return true; | |
659 | } | |
660 | ||
5934cda1 FM |
661 | void IfaceCheckApp::PrintStatistics(long secs) |
662 | { | |
f3998820 FM |
663 | // these stats, for what regards the gcc XML, are all referred to the wxWidgets |
664 | // classes only! | |
665 | ||
7f8fae98 | 666 | wxLogMessage("wx real headers contains declaration of %d classes (%d methods)", |
03d4f7b9 | 667 | m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount()); |
7f8fae98 | 668 | wxLogMessage("wx interface headers contains declaration of %d classes (%d methods)", |
03d4f7b9 | 669 | m_doxyInterface.GetClassesCount(), m_doxyInterface.GetMethodCount()); |
96c65755 FM |
670 | |
671 | // build a list of the undocumented wx classes | |
672 | wxString list; | |
673 | int undoc = 0; | |
674 | const wxClassArray& arr = m_gccInterface.GetClasses(); | |
675 | for (unsigned int i=0; i<arr.GetCount(); i++) { | |
676 | if (m_doxyInterface.FindClass(arr[i].GetName()) == NULL) { | |
677 | list += arr[i].GetName() + ", "; | |
678 | undoc++; | |
679 | } | |
680 | } | |
681 | ||
682 | list.RemoveLast(); | |
683 | list.RemoveLast(); | |
684 | ||
7f8fae98 FM |
685 | wxLogMessage("the list of the %d undocumented wx classes is: %s", undoc, list); |
686 | wxLogMessage("total processing took %d seconds.", secs); | |
5934cda1 FM |
687 | } |
688 |