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