]> git.saurik.com Git - wxWidgets.git/blame - utils/HelpGen/src/srcparser.h
fix unused parameter warning when wxHAS_NATIVE_OVERLAY (patch 1692332)
[wxWidgets.git] / utils / HelpGen / src / srcparser.h
CommitLineData
cecfc5e7
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: No names yet.
3// Purpose: To provide a simple _framework_
4// for series of source code parsers with
5// compatible interfaces
6// Author: Aleksandras Gluchovas
7// Modified by: AG on 28/12/98
8// Created: 22/09/98
9// RCS-ID: $Id$
10// Copyright: (c) Aleskandars Gluchovas
4ed87fa7 11// Licence: wxWindows licence
cecfc5e7
VZ
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef __SRCPARSER_G__
15#define __SRCPARSER_G__
16
17#if defined( wxUSE_TEMPLATE_STL )
d12e3536 18 #include <vector>
cecfc5e7 19
d12e3536
VZ
20 #ifdef WIN32
21 #include <bstring.h>
22 #else
cecfc5e7 23
d12e3536
VZ
24 #include <strclass.h>
25 #include <string.h>
cecfc5e7 26
d12e3536 27 #endif
cecfc5e7
VZ
28
29#else
d12e3536
VZ
30 #include "wx/string.h"
31 #include "wxstlvec.h"
cecfc5e7 32
cecfc5e7
VZ
33#endif
34
35#include "markup.h" // markup tags used in spOperator::GetFullName()
36
d12e3536
VZ
37// these methods are used for debugging only and disappear in the release build
38#ifdef __WXDEBUG__
39 #define DECLARE_DUMP virtual void DumpThis(const wxString& indent) const;
40#else
41 #define DECLARE_DUMP
42#endif
43
cecfc5e7
VZ
44// context class list in "inside-out" order :
45
46class spContext;
47
48class spParameter;
49class spAttribute;
50class spOperation;
51class spEnumeration;
52class spTypeDef;
53class spPreprocessorLine;
54class spClass;
55class spNameSpace;
56class spFile;
57
58// source context visibilities
59enum SRC_VISIBLITY_TYPES
60{
d12e3536
VZ
61 SP_VIS_PUBLIC,
62 SP_VIS_PROTECTED,
63 SP_VIS_PRIVATE
cecfc5e7
VZ
64};
65
66// class types
67enum SP_CLASS_TYPES
68{
d12e3536
VZ
69 SP_CLTYPE_INVALID,
70 SP_CLTYPE_CLASS,
71 SP_CLTYPE_TEMPLATE_CLASS,
72 SP_CLTYPE_STRUCTURE,
73 SP_CLTYPE_UNION,
74 SP_CLTYPE_INTERFACE
cecfc5e7
VZ
75};
76
77// inheritance types
78enum SP_INHERITANCE_TYPES
79{
d12e3536
VZ
80 SP_INHERIT_VIRTUAL,
81 SP_INHERIT_PUBLIC,
82 SP_INHERIT_PRIVATE
cecfc5e7
VZ
83};
84
85// proprocessor definitions types (specific to C++ code)
86
87enum SP_PREP_DEFINITION_TYPES
88{
d12e3536
VZ
89 SP_PREP_DEF_DEFINE_SYMBOL,
90 SP_PREP_DEF_REDEFINE_SYMBOL,
91 SP_PREP_DEF_INCLUDE_FILE,
92 SP_PREP_DEF_OTHER
cecfc5e7
VZ
93};
94
95// common context types
96
97#define SP_CTX_UNKNOWN 0x000
d12e3536
VZ
98#define SP_CTX_FILE 0x001
99#define SP_CTX_NAMESPACE 0x002
100#define SP_CTX_CLASS 0x004
cecfc5e7
VZ
101#define SP_CTX_TYPEDEF 0x008
102#define SP_CTX_PREPROCESSOR 0x010
103#define SP_CTX_ENUMERATION 0x020
d12e3536
VZ
104#define SP_CTX_ATTRIBUTE 0x040
105#define SP_CTX_OPERATION 0x080
106#define SP_CTX_PARAMETER 0x100
cecfc5e7
VZ
107
108// other (custom) context codes may be defined elsewere, however they should
109// not clash with above codes for common type and also should not
d12e3536 110// exceed 16-bits of in value
cecfc5e7
VZ
111
112// masks all context types (up to 16 custom context can be defined)
113
114#define SP_CTX_ANY 0xFFFF
115
116class spComment;
117
118
119
120#if defined( wxUSE_TEMPLATE_STL )
121
d12e3536
VZ
122 // context members
123 typedef vector<spContext*> MMemberListT;
124 // comments list
125 typedef vector<spComment*> MCommentListT;
126 // list of parameters
127 typedef vector<spParameter*> MParamListT;
2af95167 128 // wxString list
33882d15 129 typedef vector<wxString> StrListT;
cecfc5e7
VZ
130
131#else
132
d12e3536
VZ
133 typedef spContext* spContextPtrT;
134 typedef spComment* spCommentPtrT;
135 typedef spParameter* spParameterPtrT;
136 typedef WXSTL_VECTOR_SHALLOW_COPY(spContextPtrT) MMemberListT;
137 typedef WXSTL_VECTOR_SHALLOW_COPY(spCommentPtrT) MCommentListT;
138 typedef WXSTL_VECTOR_SHALLOW_COPY(spParameterPtrT) MParamListT;
33882d15 139 typedef WXSTL_VECTOR_SHALLOW_COPY(wxString) StrListT;
cecfc5e7 140
7f2e78ed 141#endif
cecfc5e7
VZ
142// base class for all visitors of source code contents
143
d12e3536 144class spVisitor
cecfc5e7
VZ
145{
146protected:
d12e3536
VZ
147 bool mSiblingSkipped;
148 bool mChildSkipped;
149 int mContextMask;
cecfc5e7 150
d12e3536 151 spContext* mpCurCxt;
cecfc5e7
VZ
152
153public:
d12e3536 154 // methods invoked by context
cecfc5e7 155
d12e3536
VZ
156 // method invoked from user's controling code
157 // to visit all nodes staring at the given context.
158 // Content is sorted if requrired, see comments
159 // spClass on sorting the class members
cecfc5e7 160
d12e3536 161 void VisitAll( spContext& atContext,
8bc17f14 162 bool sortContent = true
d12e3536 163 );
cecfc5e7 164
d12e3536 165 // methods invoked by visitor
cecfc5e7 166
d12e3536
VZ
167 // goes to the next context in the outter scope
168 // NOTE:: should not be invoked more than once while
169 // visiting certain context
cecfc5e7 170
d12e3536 171 void SkipSiblings();
cecfc5e7 172
d12e3536
VZ
173 // prevents going down into the contexts contained by
174 // the current context
175 // NOTE:: the same as above
cecfc5e7 176
d12e3536 177 void SkipChildren();
cecfc5e7 178
d12e3536
VZ
179 // can be called only in from visiting procedure
180 void RemoveCurrentContext();
cecfc5e7 181
d12e3536
VZ
182 // method enables fast filtered traversal
183 // of source content, e.g. collecting only classes,
184 // or only global functions
cecfc5e7 185
d12e3536
VZ
186 // arg. context - can contain combination of contexts concatinated
187 // with bitwise OR, e.g. SP_CTX_CLASS | SP_CTX_NAMESPACE
188 //
189 // method can be invoked from the user's controling as well as
190 // from within the visting procedure
cecfc5e7 191
d12e3536 192 void SetFilter( int contextMask );
cecfc5e7 193
d12e3536 194 // methods should be implemneted by specific visitor:
cecfc5e7 195
d12e3536
VZ
196 // NOTE:: Do not confuse visiting with parsing, first
197 // the source is parsed, and than can be visited
198 // multiple times by variouse visitors (there can
199 // be more the one visitor visiting content at a time)
cecfc5e7 200
9d6eda5f 201 virtual void VisitFile( spFile& WXUNUSED(fl) ) {}
cecfc5e7 202
9d6eda5f 203 virtual void VisitNameSpace( spNameSpace& WXUNUSED(ns) ) {}
cecfc5e7 204
9d6eda5f 205 virtual void VisitClass( spClass& WXUNUSED(cl) ) {}
cecfc5e7 206
9d6eda5f 207 virtual void VisitEnumeration( spEnumeration& WXUNUSED(en) ) {}
cecfc5e7 208
9d6eda5f 209 virtual void VisitTypeDef( spTypeDef& WXUNUSED(td) ) {}
cecfc5e7 210
9d6eda5f 211 virtual void VisitPreprocessorLine( spPreprocessorLine& WXUNUSED(pd) ) {}
cecfc5e7 212
9d6eda5f 213 virtual void VisitAttribute( spAttribute& WXUNUSED(attr) ) {}
cecfc5e7 214
9d6eda5f 215 virtual void VisitOperation( spOperation& WXUNUSED(op) ) {}
cecfc5e7 216
9d6eda5f 217 virtual void VisitParameter( spParameter& WXUNUSED(param) ) {}
cecfc5e7 218
9d6eda5f 219 virtual void VisitCustomContext( spContext& WXUNUSED(ctx) ) {}
89fad939
VZ
220
221 virtual ~spVisitor() { }
cecfc5e7
VZ
222};
223
224// stores one section of comments,
225// multiple sections can be put to geather
226// and attached to some context
227
228class spComment
229{
230public:
fa1af598
WS
231 wxString m_Text;
232 bool mIsMultiline; // multiline comments ar those with /**/'s
cecfc5e7 233
8bc17f14 234 // true, if these was an empty empty
d12e3536
VZ
235 // line above single line comment
236
fa1af598 237 bool mStartsPar;
cecfc5e7 238
cecfc5e7
VZ
239public:
240
fa1af598
WS
241 bool IsMultiline() const;
242 bool StartsParagraph() const;
cecfc5e7 243
fa1af598 244 wxString& GetText();
cecfc5e7 245
d12e3536 246 // contstant version of GetText()
fa1af598 247 wxString GetText() const;
cecfc5e7
VZ
248};
249
d12e3536
VZ
250// abstract base class for common (to most languages) code
251// contexts (constructs), e.g file, namespace, class, operation,
cecfc5e7
VZ
252// etc
253
254class spContext
255{
256protected:
d12e3536
VZ
257 // "linked" list of comments belonging to this context
258 MCommentListT mComments;
259
260 // NULL, if this is file context
261 MMemberListT mMembers;
cecfc5e7 262
d12e3536 263 // NULL, if this is top-most context
2af95167 264 spContext* m_pParent;
cecfc5e7 265
d12e3536
VZ
266 // points to context object, where the this context
267 // was originally declared, meaning that this object
268 // is redeclaration (or if in the case of operation
269 // this context object most probably referres to the
270 // implemnetation in .cpp file for example)
cecfc5e7 271
d12e3536
VZ
272 // is NULL, if this object referres to the first occurence
273 // of the context
cecfc5e7 274
d12e3536 275 spContext* mpFirstOccurence;
cecfc5e7 276
d12e3536
VZ
277 // used, to avoid excessive sorting of context's agreggates
278 bool mAlreadySorted;
cecfc5e7
VZ
279
280public:
281
d12e3536
VZ
282 // source line number, (-1) if unknown
283 int mSrcLineNo;
284
285 // offset of context in the source file, (-1) if unknown
286 int mSrcOffset;
cecfc5e7 287
d12e3536
VZ
288 // lentgh of the context in characters, (-1) if unknown
289 int mContextLength;
cecfc5e7 290
d12e3536
VZ
291 // source line number, in which this cotext ends, (-1) if unknown
292 int mLastScrLineNo;
cecfc5e7 293
d12e3536
VZ
294 // fields are valid, if the may contain other contexts nested inside
295 int mHeaderLength;
296 int mFooterLength;
cecfc5e7 297
d12e3536
VZ
298 // zero-based index of the first character of
299 // this context in the source line, (-1) if unknown
300 int mFirstCharPos;
cecfc5e7 301
d12e3536
VZ
302 // zero-based index of the first character of
303 // this context in the last source line of this context, (-1) if unknown
304 int mLastCharPos;
cecfc5e7 305
d12e3536
VZ
306 // see SRC_VISIBLITY_TYPES enumeration
307 int mVisibility;
cecfc5e7 308
8bc17f14 309 // true, if context does not really exist in the source
d12e3536 310 // but was created by external tools (e.g. forward engineering)
cecfc5e7 311
d12e3536
VZ
312 bool mIsVirtualContext;
313 bool mVirtualContextHasChildren;
cecfc5e7 314
8bc17f14 315 // body of the context in case (mIsVirtual == true)
2af95167
WS
316 wxString mVirtualContextBody;
317 wxString mVittualContextFooter;
d12e3536
VZ
318
319 // e.g. can be used by documentation generator to store
320 // reference to section object
321 void* mpUserData;
cecfc5e7
VZ
322
323public:
d12e3536 324 // universal identifier of the context (e.g. class name)
8bc17f14 325 wxString m_Name;
cecfc5e7
VZ
326
327public:
d12e3536
VZ
328 // default constructor
329 spContext();
330
331 // automatically destorys all aggregated contexts
332 // (thus, it's enought to call destructor of root-context)
333 virtual ~spContext();
cecfc5e7 334
d12e3536
VZ
335 // see mUererData member;
336 void* GetUserData() { return mpUserData; }
cecfc5e7 337
d12e3536
VZ
338 // sets untyped pointer to user data
339 void SetUserData( void* pUserData )
340 { mpUserData = pUserData; }
cecfc5e7 341
d12e3536
VZ
342 // searches the whole context tree for the cotnexts
343 // which match given masks, pust results into lst array
344 void GetContextList( MMemberListT& lst, int contextMask );
cecfc5e7 345
d12e3536
VZ
346 // used by default visitor's implementation
347 bool IsSorted();
cecfc5e7 348
d12e3536 349 /*** forward/reverse ingineering fecilities ***/
cecfc5e7 350
d12e3536 351 bool PositionIsKnown();
cecfc5e7 352
d12e3536 353 bool IsVirtualContext();
cecfc5e7 354
d12e3536 355 bool VitualContextHasChildren();
cecfc5e7 356
2af95167 357 void SetVirtualContextBody( const wxString& body,
8bc17f14 358 bool hasChildren = false,
2af95167 359 const wxString& footer = wxEmptyString );
cecfc5e7 360
2af95167
WS
361 wxString GetVirtualContextBody();
362 wxString GetFooterOfVirtualContextBody();
cecfc5e7 363
d12e3536
VZ
364 // can be overriden by top-level context classes
365 // to find-out ot the source-fragment of this
366 // context using it's position information
fa1af598 367 virtual wxString GetBody( spContext* pCtx = NULL );
cecfc5e7 368
fa1af598 369 virtual wxString GetHeader( spContext* pCtx = NULL );
cecfc5e7 370
8bc17f14 371 // true, if there is at least one entry
d12e3536
VZ
372 // in the comment list of this context
373 bool HasComments();
374 MCommentListT& GetCommentList() { return mComments; }
375 const MCommentListT& GetCommentList() const { return mComments; }
cecfc5e7 376
d12e3536
VZ
377 // should be overriden, if the context supports sorting
378 // of it's members
379 virtual void SortMembers() {}
cecfc5e7 380
d12e3536 381 // returns identifier of this context
8bc17f14 382 inline wxString& GetName() { return m_Name; }
cecfc5e7 383
d12e3536
VZ
384 // returns -1, if souce line # is unknow
385 inline int GetSourceLineNo() { return mSrcLineNo; }
cecfc5e7 386
d12e3536
VZ
387 // see comments on mpFirstOccurence member variable
388 bool IsFirstOccurence();
389 spContext* GetFirstOccurence();
cecfc5e7 390
d12e3536
VZ
391 // returns not-NULL value if this context
392 // is aggregated by another cotnext
393 spContext* GetOutterContext();
cecfc5e7 394
d12e3536 395 // perhaps more intuitive alias for `GetOutterContext()'
2af95167 396 inline spContext* GetParent() { return m_pParent; }
cecfc5e7 397
d12e3536 398 bool HasOutterContext();
cecfc5e7 399
d12e3536
VZ
400 // add one aggregate (or child) into this context
401 void AddMember ( spContext* pMember );
402 MMemberListT& GetMembers();
cecfc5e7 403
d12e3536
VZ
404 // append comment to the comment list decribing
405 // this context
406 void AddComment( spComment* pComment );
cecfc5e7 407
d12e3536
VZ
408 // returns NULL, if the context with the given
409 // name and type is not contained by this context
410 // and it's children. Children's children are not
8bc17f14 411 // searched recursivelly if searchSubMembers is false
cecfc5e7 412
2af95167 413 spContext* FindContext( const wxString& identifier,
d12e3536 414 int contextType = SP_CTX_ANY,
8bc17f14 415 bool searchSubMembers = true
d12e3536 416 );
cecfc5e7 417
d12e3536
VZ
418 // removes this context from it's parent
419 // (NOTE:: context should have an outter cotnext
420 // to when this method is called, otherwise removal
421 // will result assertion failure)
422 void RemoveThisContext();
cecfc5e7 423
8bc17f14 424 // returns true, if this object is aggregated in the file
d12e3536 425 bool IsInFile();
cecfc5e7 426
8bc17f14 427 // true, if outter context is a namespace
d12e3536 428 bool IsInNameSpace();
cecfc5e7 429
8bc17f14 430 // true, if outter context is a class
d12e3536 431 bool IsInClass();
cecfc5e7 432
8bc17f14 433 // true, if outter cotext is an operation (true for "spParameter"s)
d12e3536 434 bool IsInOperation();
cecfc5e7 435
8bc17f14 436 // true if the context is public
cecfc5e7
VZ
437 bool IsPublic() const { return mVisibility == SP_VIS_PUBLIC; }
438
d12e3536
VZ
439 // NOTE:: method returns not the type of this object
440 // but the file/namespace/class/operation or file in which this
441 // attribute is contained. First, check for the type of
442 // context using the above method.
443
444 // Requiering container which does not exist, will result
445 // in assertion failure
446
447 spClass& GetClass();
448 spFile& GetFile();
449 spNameSpace& GetNameSpace();
450 spOperation& GetOperation();
451
452 // each new context should override this method
453 // to return it's specific type
454 virtual int GetContextType() const { return SP_CTX_UNKNOWN; }
cecfc5e7 455
d12e3536
VZ
456 // perhaps more intuitive short-cut
457 inline int GetType() { return GetContextType(); }
cecfc5e7 458
d12e3536
VZ
459 // cast this context to the desired type - returns NULL if type is wrong
460 spAttribute *CastToAttribute()
461 {
462 return GetContextType() == SP_CTX_ATTRIBUTE ? (spAttribute *)this
463 : NULL;
464 }
cecfc5e7 465
d12e3536
VZ
466 // derived classes override this to invoke VisitXXX method
467 // which corresponds to the class of specific context,
468 // - this is what the "Visitor" pattern told us ^)
cecfc5e7 469
d12e3536
VZ
470 // if method is not overriden, then it's probably user-defined
471 // custom context
cecfc5e7 472
d12e3536 473 virtual void AcceptVisitor( spVisitor& visitor )
cecfc5e7 474
d12e3536 475 { visitor.VisitCustomContext( *this ); };
cecfc5e7 476
d12e3536
VZ
477 // called by visitors, to remove given subcontext
478 // of this context object
479 void RemoveChild( spContext* pChild );
cecfc5e7 480
d12e3536 481 void RemoveChildren();
cecfc5e7 482
d12e3536
VZ
483 spContext* GetEnclosingContext( int mask = SP_CTX_ANY );
484
485#ifdef __WXDEBUG__
486 virtual void Dump(const wxString& indent) const;
487#endif // __WXDEBUG__
488
489 DECLARE_DUMP
cecfc5e7
VZ
490};
491
492// stores information about single argument of operation
493
494class spParameter : public spContext
495{
496public:
d12e3536 497 // type of argument (parameter)
821d644d 498 wxString m_Type;
cecfc5e7 499
d12e3536 500 // "stringified" initial value
fa1af598 501 wxString m_InitVal;
cecfc5e7
VZ
502
503public:
d12e3536
VZ
504 virtual int GetContextType() const { return SP_CTX_PARAMETER; }
505
506 virtual void AcceptVisitor( spVisitor& visitor )
507 { visitor.VisitParameter( *this ); }
cecfc5e7 508
d12e3536 509 DECLARE_DUMP
cecfc5e7
VZ
510};
511
512
513// stores information about member(or global) variable
514
515class spAttribute : public spContext
516{
517public:
d12e3536 518 // type of the attribute
821d644d 519 wxString m_Type;
cecfc5e7 520
d12e3536 521 // it's initial value
fa1af598 522 wxString m_InitVal;
cecfc5e7 523
d12e3536
VZ
524 // constantness
525 bool mIsConstant;
cecfc5e7
VZ
526public:
527
d12e3536 528 virtual int GetContextType() const { return SP_CTX_ATTRIBUTE; }
cecfc5e7 529
d12e3536
VZ
530 virtual void AcceptVisitor( spVisitor& visitor )
531 { visitor.VisitAttribute( *this ); }
532
533 DECLARE_DUMP
cecfc5e7
VZ
534};
535
536class spOperation : public spContext
537{
538public:
d12e3536 539 // type of return value
821d644d 540 wxString m_RetType;
cecfc5e7 541
d12e3536
VZ
542 // argument list
543 //MParamListT mParams;
cecfc5e7 544
8bc17f14 545 // true, if operation does not modify
d12e3536
VZ
546 // the content of the object
547 bool mIsConstant;
cecfc5e7 548
d12e3536
VZ
549 // flag, specific to C++
550 bool mIsVirtual;
cecfc5e7 551
8bc17f14 552 // true, if definition follows the declaration immediatelly
d12e3536 553 bool mHasDefinition;
cecfc5e7 554
d12e3536
VZ
555 // scope if any (e.g. MyClass::MyFunction(), scope stirng is "MyClass" )
556 // usually found along with implementation of the method, which is now skipped
cecfc5e7 557
2af95167 558 wxString mScope;
cecfc5e7
VZ
559
560public:
d12e3536 561 spOperation();
cecfc5e7 562
d12e3536
VZ
563 // returns full declaration of the operations
564 // (ret val., identifier, arg. list),
cecfc5e7 565
d12e3536
VZ
566 // arguments are marked up with italic,
567 // default values marked up with bold-italic,
568 // all the rest is marked as bold
cecfc5e7 569
d12e3536
VZ
570 // NOTE:: this method may be overriden by class
571 // specific to concrete parser, to provide
572 // language-dependent reperesnetation of
573 // operation and it's argumetn list
574 //
575 // the default implementation outputs name in
576 // C++/Java syntax
cecfc5e7 577
fa1af598 578 virtual wxString GetFullName(MarkupTagsT tags);
cecfc5e7 579
d12e3536 580 virtual int GetContextType() const { return SP_CTX_OPERATION; }
cecfc5e7 581
d12e3536
VZ
582 virtual void AcceptVisitor( spVisitor& visitor )
583 { visitor.VisitOperation( *this ); }
cecfc5e7 584
d12e3536 585 DECLARE_DUMP
cecfc5e7
VZ
586};
587
588// stores infromation about preprocessor directive
589
d12e3536 590class spPreprocessorLine : public spContext
cecfc5e7
VZ
591{
592
593public:
594
d12e3536
VZ
595 // prepocessor statement including '#' and
596 // attached multiple lines with '\' character
c69a7d10 597 wxString m_Line;
cecfc5e7 598
d12e3536 599 int mDefType; // see SP_PREP_DEFINITION_TYPES enumeration
cecfc5e7
VZ
600
601public:
602
d12e3536
VZ
603 virtual int GetContextType() const { return SP_CTX_PREPROCESSOR; }
604
605 virtual int GetStatementType() const { return mDefType; }
cecfc5e7 606
fa1af598 607 wxString CPP_GetIncludedFileNeme() const;
cecfc5e7 608
d12e3536
VZ
609 virtual void AcceptVisitor( spVisitor& visitor )
610 { visitor.VisitPreprocessorLine( *this ); }
cecfc5e7 611
d12e3536 612 DECLARE_DUMP
cecfc5e7
VZ
613};
614
d12e3536 615// stores information about the class
cecfc5e7
VZ
616
617class spClass : public spContext
618{
619public:
d12e3536 620 // list of superclasses/interfaces
33882d15 621 StrListT m_SuperClassNames;
cecfc5e7 622
d12e3536
VZ
623 // see SP_CLASS_TYPES enumeration
624 int mClassSubType;
cecfc5e7 625
d12e3536
VZ
626 // see SP_INHERITANCE_TYPES enumeration
627 int mInheritanceType;
cecfc5e7 628
d12e3536 629 // valid if mClassSubType is SP_CLTYPE_TEMPLATE_CLASS
2af95167 630 wxString mTemplateTypes;
cecfc5e7 631
8bc17f14 632 // true, if it's and interface of abstract base class
d12e3536 633 bool mIsAbstract;
cecfc5e7
VZ
634
635public:
d12e3536
VZ
636 // sorts class members in the following order:
637 //
638 // (by "privacy level" - first private, than protected, public)
639 //
640 // within above set
641 //
642 // (by member type - attributes first, than methods, nested classes)
643 //
644 // within above set
645 //
646 // (by identifier of the member)
647
648 virtual void SortMembers();
649
650 virtual int GetContextType() const { return SP_CTX_CLASS; }
651
652 virtual void AcceptVisitor( spVisitor& visitor )
653 { visitor.VisitClass( *this ); }
654
655 DECLARE_DUMP
cecfc5e7
VZ
656};
657
658// stores information about enum statement
659
660class spEnumeration : public spContext
661{
662public:
c69a7d10 663 wxString m_EnumContent; // full-text content of enumeration
cecfc5e7
VZ
664
665public:
d12e3536 666 virtual int GetContextType() const { return SP_CTX_ENUMERATION; }
cecfc5e7 667
d12e3536
VZ
668 virtual void AcceptVisitor( spVisitor& visitor )
669 { visitor.VisitEnumeration( *this ); }
670
671 DECLARE_DUMP
cecfc5e7
VZ
672};
673
674class spTypeDef : public spContext
675{
676public:
d12e3536
VZ
677 // the original type which is redefined
678 // by this type definition
c69a7d10 679 wxString m_OriginalType;
cecfc5e7
VZ
680
681public:
d12e3536
VZ
682 virtual int GetContextType() const { return SP_CTX_TYPEDEF; }
683
684 virtual void AcceptVisitor( spVisitor& visitor )
685 { visitor.VisitTypeDef( *this ); }
cecfc5e7 686
d12e3536 687 DECLARE_DUMP
cecfc5e7
VZ
688};
689
690// NOTE:: files context may be put to other
691// file context, resulting in a collection
692// of parsed file contexts, with a virtual "superfile"
693
694class spFile : public spContext
695{
696public:
d12e3536
VZ
697 // since file name cannot be determined from
698 // source code, filling in this field is optional
60ec1c87 699 wxString m_FileName;
cecfc5e7
VZ
700
701public:
d12e3536
VZ
702 virtual int GetContextType() const { return SP_CTX_FILE; }
703
704 virtual void AcceptVisitor( spVisitor& visitor )
705 { visitor.VisitFile( *this ); }
cecfc5e7 706
d12e3536 707 DECLARE_DUMP
cecfc5e7
VZ
708};
709
710//TODO:: comments.
711
712class SourceParserPlugin
713{
714public:
d12e3536
VZ
715 virtual bool CanUnderstandContext( char* cur, char* end, spContext* pOuttterCtx ) = 0;
716 virtual void ParseContext( char* start, char*& cur, char* end, spContext* pOuttterCtx ) = 0;
89fad939
VZ
717
718 virtual ~SourceParserPlugin() { }
cecfc5e7
VZ
719};
720
721// abstract interface for source parsers
722// which can output parsing results in the
723// form of context-tree, where each node
724// should be derivative of spContext, (see
725// above classes)
726
d12e3536 727class SourceParserBase
cecfc5e7
VZ
728{
729private:
d12e3536
VZ
730 // auto-resizing file buffer, created in ParseFile()
731 // to reuse large heap block for multiple parsings
732
733 char* mpFileBuf;
734 int mFileBufSz;
cecfc5e7
VZ
735
736protected:
d12e3536
VZ
737 SourceParserPlugin* mpPlugin;
738
cecfc5e7 739protected:
d12e3536
VZ
740 // value is set in the derived parser classes
741 int mParserStatus;
cecfc5e7
VZ
742
743public:
d12e3536
VZ
744 SourceParserBase();
745 virtual ~SourceParserBase();
cecfc5e7 746
d12e3536
VZ
747 // loads entier source file(as text) into memory,
748 // and passes it's contents to ParseAll() method,
749 // memory occupied by source text is released after
750 // parsing is done
751 //
752 // (NOTE:: this is the default implementation),
cecfc5e7 753
d12e3536 754 virtual spFile* ParseFile( const char* fname );
cecfc5e7 755
d12e3536
VZ
756 // should returns the root-node of the created context tree
757 // (user is responsible for releasing it from the heep)
758 // "end" should point to the (last character + 1) of the
759 // source text area
cecfc5e7 760
d12e3536 761 virtual spFile* Parse( char* start, char* end ) = 0;
cecfc5e7 762
d12e3536
VZ
763 // returns parser "status word" (specific to concrete parser)
764 int GetParserStatus() { return mParserStatus; }
cecfc5e7 765
d12e3536 766 void SetPlugin( SourceParserPlugin* pPlugin );
cecfc5e7
VZ
767};
768
769#endif