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