]>
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 | // 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" | |
20 | #include "wx/crt.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/cmdline.h" | |
24 | #include "wx/textfile.h" | |
25 | #include "wx/filename.h" | |
26 | #include "wx/stopwatch.h" // for wxGetLocalTime | |
27 | #include "xmlparser.h" | |
28 | ||
29 | // global verbosity flag | |
30 | bool g_verbose = false; | |
31 | ||
32 | ||
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // IfaceCheckApp | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | #define API_DUMP_FILE "dump.api.txt" | |
39 | #define INTERFACE_DUMP_FILE "dump.interface.txt" | |
40 | ||
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" | |
48 | ||
49 | static const wxCmdLineEntryDesc g_cmdLineDesc[] = | |
50 | { | |
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", | |
55 | "processes only header files matching the given wildcard", | |
56 | wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR }, | |
57 | { wxCMD_LINE_SWITCH, MODIFY_SWITCH, "modify", | |
58 | "modify the interface headers to match the real ones" }, | |
59 | { wxCMD_LINE_SWITCH, DUMP_SWITCH, "dump", | |
60 | "dump both interface and API to plain text dump.*.txt files" }, | |
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 | ||
72 | class IfaceCheckLog : public wxLog | |
73 | { | |
74 | public: | |
75 | IfaceCheckLog() {} | |
76 | ||
77 | virtual void DoLogText(const wxString& msg) | |
78 | { | |
79 | // send all messages to stdout (normal behaviour is to sent them to stderr) | |
80 | wxPuts(msg); | |
81 | fflush(stdout); | |
82 | } | |
83 | }; | |
84 | ||
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 | ||
92 | bool ParsePreprocessorOutput(const wxString& filename); | |
93 | ||
94 | bool Compare(); | |
95 | int CompareClasses(const wxClass* iface, const wxClass* api); | |
96 | bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api); | |
97 | bool StringContainsMethodName(const wxString& str, const wxMethod* m); | |
98 | ||
99 | void PrintStatistics(long secs); | |
100 | ||
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 | ||
108 | protected: | |
109 | wxXmlGccInterface m_gccInterface; // "real" headers API | |
110 | wxXmlDoxygenInterface m_doxyInterface; // doxygen-commented headers API | |
111 | ||
112 | // was the MODIFY_SWITCH passed? | |
113 | bool m_modify; | |
114 | ||
115 | // if non-empty, then PROCESS_ONLY_OPTION was passed and this is the | |
116 | // wildcard expression to match | |
117 | wxString m_strToMatch; | |
118 | }; | |
119 | ||
120 | IMPLEMENT_APP_CONSOLE(IfaceCheckApp) | |
121 | ||
122 | int IfaceCheckApp::OnRun() | |
123 | { | |
124 | long startTime = wxGetLocalTime(); // for timing purpose | |
125 | ||
126 | wxCmdLineParser parser(g_cmdLineDesc, argc, argv); | |
127 | parser.SetLogo( | |
128 | wxString::Format("wxWidgets Interface checker utility (built %s against %s)", | |
129 | __DATE__, wxVERSION_STRING)); | |
130 | ||
131 | // make the output more readable: | |
132 | wxLog::SetActiveTarget(new IfaceCheckLog); | |
133 | wxLog::DisableTimestamp(); | |
134 | ||
135 | // parse the command line... | |
136 | bool ok = true; | |
137 | wxString preprocFile; | |
138 | switch (parser.Parse()) | |
139 | { | |
140 | case 0: | |
141 | if (parser.Found(VERBOSE_SWITCH)) | |
142 | g_verbose = true; | |
143 | ||
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: | |
153 | m_doxyInterface.AddPreprocessorValue("NULL", "0"); | |
154 | ||
155 | // parse the two XML files which contain the real and the doxygen interfaces | |
156 | // for wxWidgets API: | |
157 | if (!m_gccInterface.Parse(parser.GetParam(0)) || | |
158 | !m_doxyInterface.Parse(parser.GetParam(1))) | |
159 | return 1; | |
160 | ||
161 | if (parser.Found(DUMP_SWITCH)) | |
162 | { | |
163 | wxLogMessage("Dumping real API to '%s'...", API_DUMP_FILE); | |
164 | m_gccInterface.Dump(API_DUMP_FILE); | |
165 | ||
166 | wxLogMessage("Dumping interface API to '%s'...", INTERFACE_DUMP_FILE); | |
167 | m_doxyInterface.Dump(INTERFACE_DUMP_FILE); | |
168 | } | |
169 | else | |
170 | { | |
171 | if (parser.Found(MODIFY_SWITCH)) | |
172 | m_modify = true; | |
173 | ||
174 | if (parser.Found(PROCESS_ONLY_OPTION, &m_strToMatch)) | |
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 | ||
183 | ||
184 | ok = Compare(); | |
185 | } | |
186 | ||
187 | PrintStatistics(wxGetLocalTime() - startTime); | |
188 | return ok ? 0 : 1; | |
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; | |
203 | } | |
204 | } | |
205 | ||
206 | bool IfaceCheckApp::Compare() | |
207 | { | |
208 | const wxClassArray& interfaces = m_doxyInterface.GetClasses(); | |
209 | const wxClass* c; | |
210 | int mcount = 0, ccount = 0; | |
211 | ||
212 | wxLogMessage("Comparing the interface API to the real API (%d classes to compare)...", | |
213 | interfaces.GetCount()); | |
214 | ||
215 | if (!m_strToMatch.IsEmpty()) | |
216 | { | |
217 | wxLogMessage("Processing only header files matching '%s' expression.", m_strToMatch); | |
218 | } | |
219 | ||
220 | for (unsigned int i=0; i<interfaces.GetCount(); i++) | |
221 | { | |
222 | // only compare the methods which are available for the port | |
223 | // for which the gcc XML was produced | |
224 | if (interfaces[i].GetAvailability() != wxPORT_UNKNOWN && | |
225 | (interfaces[i].GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) { | |
226 | ||
227 | if (g_verbose) | |
228 | { | |
229 | wxLogMessage("skipping class '%s' since it's not available for the %s port.", | |
230 | interfaces[i].GetName(), m_gccInterface.GetInterfacePortName()); | |
231 | } | |
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 | { | |
306 | wxLogMessage("skipping method '%s' since it's not available for the %s port.", | |
307 | m.GetAsString(), m_gccInterface.GetInterfacePortName()); | |
308 | } | |
309 | ||
310 | continue; // skip this method | |
311 | } | |
312 | ||
313 | // search in the methods of the api classes provided | |
314 | real = api->RecursiveUpwardFindMethod(m, &m_gccInterface); | |
315 | ||
316 | // avoid some false positives: | |
317 | if (!real && m.ActsAsDefaultCtor()) | |
318 | { | |
319 | // build an artificial default ctor for this class: | |
320 | wxMethod temp(m); | |
321 | temp.GetArgumentTypes().Clear(); | |
322 | ||
323 | // repeat search: | |
324 | real = api->RecursiveUpwardFindMethod(temp, &m_gccInterface); | |
325 | } | |
326 | ||
327 | // no matches? | |
328 | if (!real) | |
329 | { | |
330 | bool proceed = true; | |
331 | wxMethodPtrArray overloads = | |
332 | api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface); | |
333 | ||
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 | |
353 | #if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES | |
354 | for (unsigned int k=0; k<overloads.GetCount(); k++) | |
355 | if (overloads[k]->MatchesExceptForAttributes(m)) | |
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)) | |
363 | { | |
364 | wxLogMessage("Adjusted attributes of '%s' method", m.GetAsString()); | |
365 | } | |
366 | ||
367 | proceed = false; | |
368 | break; | |
369 | } | |
370 | #endif // HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES | |
371 | ||
372 | if (proceed) | |
373 | { | |
374 | if (overloads.GetCount()==0) | |
375 | { | |
376 | wxLogMessage("%s: real '%s' class and their parents have no method '%s'", | |
377 | header, api->GetName(), m.GetAsString()); | |
378 | // we've found no overloads | |
379 | } | |
380 | else | |
381 | { | |
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 | } | |
393 | ||
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 | ||
399 | wxLogWarning("%s", warning); | |
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) | |
407 | { | |
408 | wxLogWarning("\tmanual fix is required"); | |
409 | } | |
410 | } | |
411 | else | |
412 | { | |
413 | wxASSERT(overloads.GetCount() == 1); | |
414 | ||
415 | if (m_modify || m.IsCtor()) | |
416 | { | |
417 | wxLogWarning("\tfixing it..."); | |
418 | ||
419 | // try to modify it! | |
420 | FixMethod(iface->GetHeader(), &m, overloads[0]); | |
421 | } | |
422 | } | |
423 | } | |
424 | ||
425 | count++; | |
426 | } // if (proceed) | |
427 | } | |
428 | } | |
429 | ||
430 | return count; | |
431 | } | |
432 | ||
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 | ||
439 | bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api) | |
440 | { | |
441 | unsigned int i,j; | |
442 | wxASSERT(iface && api); | |
443 | ||
444 | wxTextFile file; | |
445 | if (!file.Open(header)) { | |
446 | wxLogError("\tcan't open the '%s' header file.", header); | |
447 | return false; | |
448 | } | |
449 | ||
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. | |
452 | int end = iface->GetLocation()-1; | |
453 | if (end <= 0 || end >= (int)file.GetLineCount()) { | |
454 | wxLogWarning("\tinvalid location info for method '%s': %d.", | |
455 | iface->GetAsString(), iface->GetLocation()); | |
456 | return false; | |
457 | } | |
458 | ||
459 | if (!file.GetLine(end).Contains(";")) { | |
460 | wxLogWarning("\tinvalid location info for method '%s': %d.", | |
461 | iface->GetAsString(), iface->GetLocation()); | |
462 | return false; | |
463 | } | |
464 | ||
465 | // is this a one-line prototype declaration? | |
466 | bool founddecl = false; | |
467 | int start; | |
468 | if (StringContainsMethodName(file.GetLine(end), iface)) | |
469 | { | |
470 | // yes, this prototype is all on this line: | |
471 | start = end; | |
472 | founddecl = true; | |
473 | } | |
474 | else | |
475 | { | |
476 | start = end; // will be decremented inside the while{} loop below | |
477 | ||
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 | |
482 | { | |
483 | start--; // go up one line | |
484 | ||
485 | if (StringContainsMethodName(file.GetLine(start), iface)) | |
486 | founddecl = true; | |
487 | } | |
488 | while (start > 0 && !founddecl && | |
489 | !file.GetLine(start).Contains(";") && | |
490 | !file.GetLine(start).Contains("*/")); | |
491 | } | |
492 | ||
493 | if (start <= 0 || !founddecl) | |
494 | { | |
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", | |
496 | iface->GetAsString(), header, end+1 /* zero-based => 1-based */, start); | |
497 | return false; | |
498 | } | |
499 | ||
500 | // remove the old prototype | |
501 | for (int k=start; k<=end; k++) | |
502 | file.RemoveLine(start); // remove (end-start)-nth times the start-th line | |
503 | ||
504 | #define INDENTATION_STR wxString(" ") | |
505 | ||
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())) | |
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++); | |
515 | ||
516 | // we have added a new line in the final balance | |
517 | deprecationOffset=1; | |
518 | } | |
519 | ||
520 | wxMethod tmp(*api); | |
521 | ||
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. | |
525 | const wxArgumentTypeArray& doxygenargs = iface->GetArgumentTypes(); | |
526 | const wxArgumentTypeArray& realargs = api->GetArgumentTypes(); | |
527 | if (realargs.GetCount() == doxygenargs.GetCount()) | |
528 | { | |
529 | for (j=0; j<doxygenargs.GetCount(); j++) | |
530 | if (doxygenargs[j]==realargs[j]) | |
531 | { | |
532 | realargs[j].SetArgumentName(doxygenargs[j].GetArgumentName()); | |
533 | ||
534 | if (realargs[j].GetDefaultValue().IsNumber() && | |
535 | doxygenargs[j].GetDefaultValue().StartsWith("wx")) | |
536 | realargs[j].SetDefaultValue(doxygenargs[j].GetDefaultValue()); | |
537 | } | |
538 | ||
539 | tmp.SetArgumentTypes(realargs); | |
540 | } | |
541 | ||
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 | |
551 | for (i=0; i<toinsert.GetCount(); i++) | |
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 | |
571 | for (i=0; i<toinsert.GetCount(); i++) | |
572 | file.InsertLine(toinsert[i], start+i); | |
573 | ||
574 | // now save the modification | |
575 | if (!file.Write()) { | |
576 | wxLogError("\tcan't save the '%s' header file.", header); | |
577 | return false; | |
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) | |
583 | return false; | |
584 | ||
585 | if (g_verbose) | |
586 | { | |
587 | wxLogMessage("\tthe final row offset for following methods is %d lines.", nOffset); | |
588 | } | |
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 | |
592 | wxClassPtrArray cToUpdate = m_doxyInterface.FindClassesDefinedIn(header); | |
593 | for (i=0; i < cToUpdate.GetCount(); i++) | |
594 | { | |
595 | for (j=0; j < cToUpdate[i]->GetMethodCount(); j++) | |
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 | } | |
604 | } | |
605 | ||
606 | return true; | |
607 | } | |
608 | ||
609 | bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename) | |
610 | { | |
611 | wxTextFile tf; | |
612 | if (!tf.Open(filename)) { | |
613 | wxLogError("can't open the '%s' preprocessor output file.", filename); | |
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 | |
625 | if (!line.StartsWith("#define ")) { | |
626 | wxLogError("unexpected content in '%s' at line %d.", filename, i+1); | |
627 | return false; | |
628 | } | |
629 | ||
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 | } | |
653 | } | |
654 | ||
655 | wxLogMessage("Parsed %d preprocessor #defines from '%s' which will be used later...", | |
656 | useful, filename); | |
657 | ||
658 | return true; | |
659 | } | |
660 | ||
661 | void IfaceCheckApp::PrintStatistics(long secs) | |
662 | { | |
663 | // these stats, for what regards the gcc XML, are all referred to the wxWidgets | |
664 | // classes only! | |
665 | ||
666 | wxLogMessage("wx real headers contains declaration of %d classes (%d methods)", | |
667 | m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount()); | |
668 | wxLogMessage("wx interface headers contains declaration of %d classes (%d methods)", | |
669 | m_doxyInterface.GetClassesCount(), m_doxyInterface.GetMethodCount()); | |
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 | ||
685 | wxLogMessage("the list of the %d undocumented wx classes is: %s", undoc, list); | |
686 | wxLogMessage("total processing took %d seconds.", secs); | |
687 | } | |
688 |