]>
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 | |
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 | #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 | ||
72 | class IfaceCheckApp : public wxAppConsole | |
73 | { | |
74 | public: | |
75 | // don't use builtin cmd line parsing: | |
76 | virtual bool OnInit() { m_modify=false; return true; } | |
77 | virtual int OnRun(); | |
78 | ||
5570107a FM |
79 | bool ParsePreprocessorOutput(const wxString& filename); |
80 | ||
5934cda1 | 81 | bool Compare(); |
673ae68a | 82 | int CompareClasses(const wxClass* iface, const wxClass* api); |
97f0dbd6 | 83 | bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api); |
5934cda1 FM |
84 | |
85 | void ShowProgress(); | |
86 | void PrintStatistics(long secs); | |
87 | ||
d5978709 FM |
88 | bool IsToProcess(const wxString& headername) const |
89 | { | |
90 | if (m_strToMatch.IsEmpty()) | |
91 | return true; | |
92 | return wxMatchWild(m_strToMatch, headername, false); | |
93 | } | |
94 | ||
5934cda1 | 95 | protected: |
03d4f7b9 FM |
96 | wxXmlGccInterface m_gccInterface; // "real" headers API |
97 | wxXmlDoxygenInterface m_doxyInterface; // doxygen-commented headers API | |
5934cda1 FM |
98 | |
99 | // was the MODIFY_SWITCH passed? | |
100 | bool m_modify; | |
d5978709 | 101 | |
5570107a | 102 | // if non-empty, then PROCESS_ONLY_OPTION was passed and this is the |
d5978709 FM |
103 | // wildcard expression to match |
104 | wxString m_strToMatch; | |
5934cda1 FM |
105 | }; |
106 | ||
107 | IMPLEMENT_APP_CONSOLE(IfaceCheckApp) | |
108 | ||
109 | int IfaceCheckApp::OnRun() | |
110 | { | |
111 | long startTime = wxGetLocalTime(); // for timing purpose | |
112 | ||
5934cda1 | 113 | wxCmdLineParser parser(g_cmdLineDesc, argc, argv); |
5570107a FM |
114 | parser.SetLogo( |
115 | wxString::Format("wxWidgets Interface checker utility (built %s against %s)", | |
116 | __DATE__, wxVERSION_STRING)); | |
117 | ||
118 | // parse the command line... | |
5934cda1 | 119 | bool ok = true; |
5570107a | 120 | wxString preprocFile; |
5934cda1 FM |
121 | switch (parser.Parse()) |
122 | { | |
5934cda1 FM |
123 | case 0: |
124 | if (parser.Found(VERBOSE_SWITCH)) | |
125 | g_verbose = true; | |
126 | ||
5570107a FM |
127 | // IMPORTANT: parsing #define values must be done _before_ actually |
128 | // parsing the GCC/doxygen XML files | |
129 | if (parser.Found(USE_PREPROCESSOR_OPTION, &preprocFile)) | |
130 | { | |
131 | if (!ParsePreprocessorOutput(preprocFile)) | |
132 | return 1; | |
133 | } | |
134 | ||
135 | // in any case set basic std preprocessor #defines: | |
03d4f7b9 | 136 | m_doxyInterface.AddPreprocessorValue("NULL", "0"); |
5570107a | 137 | |
8cd22478 | 138 | //g_bLogEnabled = false; |
97f0dbd6 | 139 | |
5570107a FM |
140 | // parse the two XML files which contain the real and the doxygen interfaces |
141 | // for wxWidgets API: | |
03d4f7b9 FM |
142 | if (!m_gccInterface.Parse(parser.GetParam(0)) || |
143 | !m_doxyInterface.Parse(parser.GetParam(1))) | |
5934cda1 FM |
144 | return 1; |
145 | ||
97f0dbd6 FM |
146 | g_bLogEnabled = true; |
147 | ||
5934cda1 FM |
148 | if (parser.Found(DUMP_SWITCH)) |
149 | { | |
150 | LogMessage("Dumping real API to '%s'...", API_DUMP_FILE); | |
03d4f7b9 | 151 | m_gccInterface.Dump(API_DUMP_FILE); |
5934cda1 FM |
152 | |
153 | LogMessage("Dumping interface API to '%s'...", INTERFACE_DUMP_FILE); | |
03d4f7b9 | 154 | m_doxyInterface.Dump(INTERFACE_DUMP_FILE); |
5934cda1 FM |
155 | } |
156 | else | |
157 | { | |
158 | if (parser.Found(MODIFY_SWITCH)) | |
159 | m_modify = true; | |
160 | ||
5570107a | 161 | if (parser.Found(PROCESS_ONLY_OPTION, &m_strToMatch)) |
d5978709 FM |
162 | { |
163 | size_t len = m_strToMatch.Len(); | |
164 | if (m_strToMatch.StartsWith("\"") && | |
165 | m_strToMatch.EndsWith("\"") && | |
166 | len > 2) | |
167 | m_strToMatch = m_strToMatch.Mid(1, len-2); | |
168 | } | |
169 | ||
97f0dbd6 | 170 | |
5934cda1 FM |
171 | ok = Compare(); |
172 | } | |
173 | ||
174 | PrintStatistics(wxGetLocalTime() - startTime); | |
175 | return ok ? 0 : 1; | |
5570107a FM |
176 | |
177 | default: | |
178 | wxPrintf("\nThis utility checks that the interface XML files created by Doxygen are in\n"); | |
179 | wxPrintf("synch with the real headers (whose contents are extracted by the gcc XML file).\n\n"); | |
180 | wxPrintf("The 'gccXML' parameter should be the wxapi.xml file created by the 'rungccxml.sh'\n"); | |
181 | wxPrintf("script which resides in 'utils/ifacecheck'.\n"); | |
182 | wxPrintf("The 'doxygenXML' parameter should be the index.xml file created by Doxygen\n"); | |
183 | wxPrintf("for the wxWidgets 'interface' folder.\n\n"); | |
184 | wxPrintf("Since the gcc XML file does not contain info about #defines, if you use\n"); | |
185 | wxPrintf("the -%s option, you'll get a smaller number of false warnings.\n", | |
186 | USE_PREPROCESSOR_OPTION); | |
187 | ||
188 | // HELP_SWITCH was passed or a syntax error occurred | |
189 | return 0; | |
5934cda1 | 190 | } |
5934cda1 FM |
191 | } |
192 | ||
193 | void IfaceCheckApp::ShowProgress() | |
194 | { | |
195 | wxPrint("."); | |
196 | //fflush(stdout); | |
197 | } | |
198 | ||
199 | bool IfaceCheckApp::Compare() | |
200 | { | |
d2875249 | 201 | const wxClassArray& interfaces = m_doxyInterface.GetClasses(); |
5934cda1 | 202 | const wxClass* c; |
5934cda1 FM |
203 | int mcount = 0, ccount = 0; |
204 | ||
205 | LogMessage("Comparing the interface API to the real API (%d classes to compare)...", | |
d2875249 | 206 | interfaces.GetCount()); |
5934cda1 | 207 | |
d5978709 FM |
208 | if (!m_strToMatch.IsEmpty()) |
209 | LogMessage("Processing only header files matching '%s' expression.", m_strToMatch); | |
210 | ||
d2875249 | 211 | for (unsigned int i=0; i<interfaces.GetCount(); i++) |
5934cda1 | 212 | { |
03d4f7b9 FM |
213 | // only compare the methods which are available for the port |
214 | // for which the gcc XML was produced | |
d2875249 VZ |
215 | if (interfaces[i].GetAvailability() != wxPORT_UNKNOWN && |
216 | (interfaces[i].GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) { | |
03d4f7b9 FM |
217 | |
218 | if (g_verbose) | |
219 | LogMessage("skipping class '%s' since it's not available for the %s port.", | |
d2875249 | 220 | interfaces[i].GetName(), m_gccInterface.GetInterfacePortName()); |
03d4f7b9 FM |
221 | |
222 | continue; // skip this method | |
223 | } | |
224 | ||
d5978709 FM |
225 | // shorten the name of the header so the log file is more readable |
226 | // and also for calling IsToProcess() against it | |
d2875249 | 227 | wxString header = wxFileName(interfaces[i].GetHeader()).GetFullName(); |
d5978709 FM |
228 | |
229 | if (!IsToProcess(header)) | |
230 | continue; // skip this one | |
231 | ||
d2875249 | 232 | wxString cname = interfaces[i].GetName(); |
5934cda1 | 233 | |
9d9c1c24 FM |
234 | // search in the real headers for i-th interface class; we search for |
235 | // both class cname and cnameBase since in wxWidgets world tipically | |
5934cda1 FM |
236 | // class cname is platform-specific while the real public interface of |
237 | // that class is part of the cnameBase class. | |
673ae68a FM |
238 | /*c = m_gccInterface.FindClass(cname + "Base"); |
239 | if (c) api.Add(c);*/ | |
9d9c1c24 | 240 | |
673ae68a FM |
241 | c = m_gccInterface.FindClass(cname); |
242 | if (!c) | |
243 | { | |
244 | // sometimes the platform-specific class is named "wxGeneric" + cname | |
245 | // or similar: | |
246 | c = m_gccInterface.FindClass("wxGeneric" + cname.Mid(2)); | |
247 | if (!c) | |
248 | { | |
249 | c = m_gccInterface.FindClass("wxGtk" + cname.Mid(2)); | |
250 | } | |
251 | } | |
5934cda1 | 252 | |
673ae68a | 253 | if (c) { |
5934cda1 | 254 | |
673ae68a FM |
255 | // there is a class with the same (logic) name! |
256 | mcount += CompareClasses(&interfaces[i], c); | |
5934cda1 FM |
257 | |
258 | } else { | |
259 | ||
260 | LogMessage("%s: couldn't find the real interface for the '%s' class", | |
4168bc45 | 261 | header, cname); |
5934cda1 FM |
262 | ccount++; |
263 | } | |
264 | } | |
265 | ||
266 | LogMessage("%d methods (%.1f%%) of the interface headers do not exist in the real headers", | |
03d4f7b9 | 267 | mcount, (float)(100.0 * mcount/m_doxyInterface.GetMethodCount())); |
5934cda1 | 268 | LogMessage("%d classes (%.1f%%) of the interface headers do not exist in the real headers", |
03d4f7b9 | 269 | ccount, (float)(100.0 * ccount/m_doxyInterface.GetClassesCount())); |
5934cda1 FM |
270 | |
271 | return true; | |
272 | } | |
273 | ||
673ae68a | 274 | int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api) |
5934cda1 | 275 | { |
5934cda1 FM |
276 | const wxMethod *real; |
277 | int count = 0; | |
278 | ||
673ae68a | 279 | wxASSERT(iface && api); |
5934cda1 | 280 | |
5934cda1 | 281 | // shorten the name of the header so the log file is more readable |
d5978709 | 282 | wxString header = wxFileName(iface->GetHeader()).GetFullName(); |
5934cda1 FM |
283 | |
284 | for (unsigned int i=0; i<iface->GetMethodCount(); i++) | |
285 | { | |
286 | const wxMethod& m = iface->GetMethod(i); | |
5934cda1 | 287 | |
03d4f7b9 FM |
288 | // only compare the methods which are available for the port |
289 | // for which the gcc XML was produced | |
290 | if (m.GetAvailability() != wxPORT_UNKNOWN && | |
291 | (m.GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) { | |
292 | ||
293 | if (g_verbose) | |
294 | LogMessage("skipping method '%s' since it's not available for the %s port.", | |
295 | m.GetAsString(), m_gccInterface.GetInterfacePortName()); | |
296 | ||
297 | continue; // skip this method | |
298 | } | |
299 | ||
5934cda1 | 300 | // search in the methods of the api classes provided |
673ae68a | 301 | real = api->RecursiveUpwardFindMethod(m, &m_gccInterface); |
5934cda1 | 302 | |
673ae68a | 303 | if (real) |
5934cda1 | 304 | { |
97f0dbd6 | 305 | bool exit = false; |
673ae68a FM |
306 | wxMethodPtrArray overloads = |
307 | api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface); | |
97f0dbd6 | 308 | |
8cd22478 FM |
309 | #define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES 0 |
310 | #if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES | |
673ae68a FM |
311 | for (unsigned int k=0; k<overloads.GetCount(); k++) |
312 | if (overloads[k]->MatchesExceptForAttributes(m) && | |
313 | overloads[k]->IsPureVirtual() == m.IsPureVirtual()) | |
314 | { | |
315 | // fix default values of results[k]: | |
316 | wxMethod tmp(*overloads[k]); | |
317 | tmp.SetArgumentTypes(m.GetArgumentTypes()); | |
318 | ||
319 | // modify interface header | |
320 | if (FixMethod(iface->GetHeader(), &m, &tmp)) | |
321 | LogMessage("Adjusted attributes of '%s' method", m.GetAsString()); | |
322 | ||
323 | exit = true; | |
97f0dbd6 | 324 | break; |
673ae68a | 325 | } |
5934cda1 | 326 | |
97f0dbd6 FM |
327 | if (!exit) |
328 | { | |
329 | #endif | |
330 | ||
a7be99c8 | 331 | if (overloads.GetCount()==0) |
5934cda1 | 332 | { |
673ae68a FM |
333 | LogMessage("%s: real '%s' class and their parents have no method '%s'", |
334 | header, api->GetName(), m.GetAsString()); | |
a7be99c8 | 335 | // we've found no overloads |
5934cda1 | 336 | } |
a7be99c8 | 337 | else |
5934cda1 | 338 | { |
a7be99c8 FM |
339 | // first, output a warning |
340 | wxString warning = header; | |
341 | if (overloads.GetCount()>1) | |
342 | warning += wxString::Format(": in the real headers there are %d overloads of '%s' for " | |
343 | "'%s' all with different signatures:\n", | |
673ae68a | 344 | overloads.GetCount(), m.GetName(), api->GetName()); |
a7be99c8 FM |
345 | else |
346 | warning += wxString::Format(": in the real headers there is a method '%s' for '%s'" | |
347 | " but has different signature:\n", | |
673ae68a | 348 | m.GetName(), api->GetName()); |
a7be99c8 | 349 | |
97f0dbd6 | 350 | // get a list of the prototypes with _all_ possible attributes: |
8cd22478 | 351 | warning += "\tdoxy header: " + m.GetAsString(true, true, true, true); |
a7be99c8 | 352 | for (unsigned int j=0; j<overloads.GetCount(); j++) |
8cd22478 | 353 | warning += "\n\treal header: " + overloads[j]->GetAsString(true, true, true, true); |
a7be99c8 FM |
354 | |
355 | wxPrint(warning + "\n"); | |
4168bc45 | 356 | count++; |
5934cda1 | 357 | |
a7be99c8 FM |
358 | if (overloads.GetCount()>1) |
359 | { | |
360 | // TODO: decide which of these overloads is the most "similar" to m | |
361 | // and eventually modify it | |
362 | if (m_modify) | |
363 | wxPrint("\tmanual fix is required\n"); | |
364 | } | |
365 | else | |
366 | { | |
367 | wxASSERT(overloads.GetCount() == 1); | |
368 | ||
369 | if (m_modify) | |
370 | { | |
371 | wxPrint("\tfixing it...\n"); | |
372 | ||
373 | // try to modify it! | |
374 | FixMethod(iface->GetHeader(), &m, overloads[0]); | |
375 | } | |
376 | } | |
5934cda1 | 377 | } |
a7be99c8 FM |
378 | |
379 | count++; | |
97f0dbd6 | 380 | |
8cd22478 | 381 | #if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES |
97f0dbd6 FM |
382 | } |
383 | #endif | |
5934cda1 FM |
384 | } |
385 | } | |
386 | ||
387 | return count; | |
388 | } | |
389 | ||
97f0dbd6 | 390 | bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api) |
5934cda1 FM |
391 | { |
392 | wxASSERT(iface && api); | |
393 | ||
394 | wxTextFile file; | |
395 | if (!file.Open(header)) { | |
7fbadf87 | 396 | LogError("\tcan't open the '%s' header file.", header); |
97f0dbd6 | 397 | return false; |
5934cda1 FM |
398 | } |
399 | ||
5934cda1 FM |
400 | // GetLocation() returns the line where the last part of the prototype is placed: |
401 | int end = iface->GetLocation()-1; | |
919ccb4c | 402 | if (end <= 0 || end >= (int)file.GetLineCount()) { |
7fbadf87 | 403 | LogWarning("\tinvalid location info for method '%s': %d.", |
919ccb4c | 404 | iface->GetAsString(), iface->GetLocation()); |
97f0dbd6 | 405 | return false; |
919ccb4c | 406 | } |
5934cda1 | 407 | |
7fbadf87 FM |
408 | if (!file.GetLine(end).Contains(";")) { |
409 | LogWarning("\tinvalid location info for method '%s': %d.", | |
a7be99c8 | 410 | iface->GetAsString(), iface->GetLocation()); |
97f0dbd6 | 411 | return false; |
a7be99c8 FM |
412 | } |
413 | ||
97f0dbd6 | 414 | // is this a one-line prototype declaration? |
7fbadf87 | 415 | bool founddecl = false; |
97f0dbd6 FM |
416 | int start; |
417 | if (file.GetLine(end).Contains(iface->GetName())) | |
7fbadf87 | 418 | { |
97f0dbd6 FM |
419 | // yes, this prototype is all on this line: |
420 | start = end; | |
421 | founddecl = true; | |
422 | } | |
423 | else | |
424 | { | |
425 | start = end-1; | |
919ccb4c | 426 | |
97f0dbd6 FM |
427 | // find the start point of this prototype declaration: |
428 | while (start > 0 && | |
429 | !file.GetLine(start).Contains(";") && | |
430 | !file.GetLine(start).Contains("*/")) | |
431 | { | |
432 | start--; | |
433 | ||
434 | founddecl |= file.GetLine(start).Contains(iface->GetName()); | |
435 | } | |
436 | ||
437 | // start-th line contains either the declaration of another prototype | |
438 | // or the closing tag */ of a doxygen comment; start one line below | |
439 | start++; | |
7fbadf87 FM |
440 | } |
441 | ||
442 | if (start <= 0 || !founddecl) | |
919ccb4c | 443 | { |
97f0dbd6 FM |
444 | LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header looking backwards from line %d", |
445 | iface->GetAsString(), header, end); | |
446 | return false; | |
5934cda1 FM |
447 | } |
448 | ||
449 | // remove the old prototype | |
450 | for (int i=start; i<=end; i++) | |
919ccb4c FM |
451 | file.RemoveLine(start); // remove (end-start)-nth times the start-th line |
452 | ||
453 | #define INDENTATION_STR wxString(" ") | |
454 | ||
7fbadf87 FM |
455 | // if possible, add also the @deprecated tag in the doxygen comment if it's missing |
456 | int deprecationOffset = 0; | |
457 | if (file.GetLine(start-1).Contains("*/") && | |
458 | (api->IsDeprecated() && !iface->IsDeprecated())) | |
919ccb4c FM |
459 | { |
460 | file.RemoveLine(start-1); | |
461 | file.InsertLine(INDENTATION_STR + INDENTATION_STR + | |
462 | "@deprecated @todo provide deprecation description", start-1); | |
463 | file.InsertLine(INDENTATION_STR + "*/", start++); | |
7fbadf87 FM |
464 | |
465 | // we have added a new line in the final balance | |
466 | deprecationOffset=1; | |
919ccb4c | 467 | } |
5934cda1 | 468 | |
f270e1dd FM |
469 | wxMethod tmp(*api); |
470 | ||
471 | // discard API argument names and replace them with those parsed from doxygen XML: | |
472 | const wxArgumentTypeArray& doxygenargs = iface->GetArgumentTypes(); | |
473 | const wxArgumentTypeArray& realargs = api->GetArgumentTypes(); | |
474 | if (realargs.GetCount() == doxygenargs.GetCount()) | |
475 | { | |
476 | for (unsigned int j=0; j<doxygenargs.GetCount(); j++) | |
477 | if (doxygenargs[j]==realargs[j]) | |
478 | realargs[j].SetArgumentName(doxygenargs[j].GetArgumentName()); | |
479 | ||
480 | tmp.SetArgumentTypes(realargs); | |
481 | } | |
482 | ||
7fbadf87 FM |
483 | #define WRAP_COLUMN 80 |
484 | ||
485 | wxArrayString toinsert; | |
486 | toinsert.Add(INDENTATION_STR + tmp.GetAsString() + ";"); | |
487 | ||
488 | int nStartColumn = toinsert[0].Find('('); | |
489 | wxASSERT(nStartColumn != wxNOT_FOUND); | |
490 | ||
491 | // wrap lines too long at comma boundaries | |
492 | for (unsigned int i=0; i<toinsert.GetCount(); i++) | |
493 | { | |
494 | size_t len = toinsert[i].Len(); | |
495 | if (len > WRAP_COLUMN) | |
496 | { | |
497 | wxASSERT(i == toinsert.GetCount()-1); | |
498 | ||
499 | // break this line | |
500 | wxString tmpleft = toinsert[i].Left(WRAP_COLUMN); | |
501 | int comma = tmpleft.Find(',', true /* from end */); | |
502 | if (comma == wxNOT_FOUND) | |
503 | break; // break out of the for cycle... | |
504 | ||
505 | toinsert.Add(wxString(' ', nStartColumn+1) + | |
506 | toinsert[i].Right(len-comma-2)); // exclude the comma and the space after it | |
507 | toinsert[i] = tmpleft.Left(comma+1); // include the comma | |
508 | } | |
509 | } | |
510 | ||
511 | // insert the new lines | |
512 | for (unsigned int i=0; i<toinsert.GetCount(); i++) | |
513 | file.InsertLine(toinsert[i], start+i); | |
5934cda1 | 514 | |
919ccb4c | 515 | // now save the modification |
5934cda1 | 516 | if (!file.Write()) { |
7fbadf87 | 517 | LogError("\tcan't save the '%s' header file.", header); |
97f0dbd6 | 518 | return false; |
7fbadf87 FM |
519 | } |
520 | ||
521 | // how many lines did we add/remove in total? | |
522 | int nOffset = toinsert.GetCount() + deprecationOffset - (end-start+1); | |
523 | if (nOffset == 0) | |
97f0dbd6 | 524 | return false; |
7fbadf87 FM |
525 | |
526 | if (g_verbose) | |
527 | LogMessage("\tthe final row offset for following methods is %d lines.", nOffset); | |
528 | ||
529 | // update the other method's locations for those methods which belong to the modified header | |
530 | // and are placed _below_ the modified method | |
03d4f7b9 | 531 | wxClassPtrArray cToUpdate = m_doxyInterface.FindClassesDefinedIn(header); |
7fbadf87 FM |
532 | for (unsigned int i=0; i < cToUpdate.GetCount(); i++) |
533 | { | |
534 | for (unsigned int j=0; j < cToUpdate[i]->GetMethodCount(); j++) | |
535 | { | |
536 | wxMethod& m = cToUpdate[i]->GetMethod(j); | |
537 | if (m.GetLocation() > iface->GetLocation()) | |
538 | { | |
539 | // update the location of this method | |
540 | m.SetLocation(m.GetLocation()+nOffset); | |
541 | } | |
542 | } | |
5934cda1 | 543 | } |
97f0dbd6 FM |
544 | |
545 | return true; | |
5934cda1 FM |
546 | } |
547 | ||
5570107a FM |
548 | bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename) |
549 | { | |
550 | wxTextFile tf; | |
551 | if (!tf.Open(filename)) { | |
552 | LogError("can't open the '%s' preprocessor output file.", filename); | |
553 | return false; | |
554 | } | |
555 | ||
556 | size_t useful = 0; | |
557 | for (unsigned int i=0; i < tf.GetLineCount(); i++) | |
558 | { | |
559 | const wxString& line = tf.GetLine(i); | |
560 | wxString defnameval = line.Mid(8); // what follows the "#define " string | |
561 | ||
562 | // the format of this line should be: | |
563 | // #define DEFNAME DEFVALUE | |
0d2f4076 FM |
564 | if (!line.StartsWith("#define ")) { |
565 | LogError("unexpected content in '%s' at line %d.", filename, i+1); | |
5570107a FM |
566 | return false; |
567 | } | |
568 | ||
0d2f4076 FM |
569 | if (defnameval.Contains(" ")) |
570 | { | |
571 | // get DEFNAME | |
572 | wxString defname = defnameval.BeforeFirst(' '); | |
573 | if (defname.Contains("(")) | |
574 | continue; // this is a macro, skip it! | |
575 | ||
576 | // get DEFVAL | |
577 | wxString defval = defnameval.AfterFirst(' ').Strip(wxString::both); | |
578 | if (defval.StartsWith("(") && defval.EndsWith(")")) | |
579 | defval = defval.Mid(1, defval.Len()-2); | |
580 | ||
581 | // store this pair in the doxygen interface, where it can be useful | |
582 | m_doxyInterface.AddPreprocessorValue(defname, defval); | |
583 | useful++; | |
584 | } | |
585 | else | |
586 | { | |
587 | // it looks like the format of this line is: | |
588 | // #define DEFNAME | |
589 | // we are not interested to symbols #defined to nothing, | |
590 | // so we just ignore this line. | |
591 | } | |
5570107a FM |
592 | } |
593 | ||
594 | LogMessage("Parsed %d preprocessor #defines from '%s' which will be used later...", | |
595 | useful, filename); | |
596 | ||
597 | return true; | |
598 | } | |
599 | ||
5934cda1 FM |
600 | void IfaceCheckApp::PrintStatistics(long secs) |
601 | { | |
602 | LogMessage("wx real headers contains declaration of %d classes (%d methods)", | |
03d4f7b9 | 603 | m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount()); |
5934cda1 | 604 | LogMessage("wx interface headers contains declaration of %d classes (%d methods)", |
03d4f7b9 | 605 | m_doxyInterface.GetClassesCount(), m_doxyInterface.GetMethodCount()); |
5934cda1 FM |
606 | LogMessage("total processing took %d seconds.", secs); |
607 | } | |
608 |