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