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