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