]> 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
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) ) {}
cecfc5e7
VZ
220};
221
222// stores one section of comments,
223// multiple sections can be put to geather
224// and attached to some context
225
226class spComment
227{
228public:
fa1af598
WS
229 wxString m_Text;
230 bool mIsMultiline; // multiline comments ar those with /**/'s
cecfc5e7 231
8bc17f14 232 // true, if these was an empty empty
d12e3536
VZ
233 // line above single line comment
234
fa1af598 235 bool mStartsPar;
cecfc5e7 236
cecfc5e7
VZ
237public:
238
fa1af598
WS
239 bool IsMultiline() const;
240 bool StartsParagraph() const;
cecfc5e7 241
fa1af598 242 wxString& GetText();
cecfc5e7 243
d12e3536 244 // contstant version of GetText()
fa1af598 245 wxString GetText() const;
cecfc5e7
VZ
246};
247
d12e3536
VZ
248// abstract base class for common (to most languages) code
249// contexts (constructs), e.g file, namespace, class, operation,
cecfc5e7
VZ
250// etc
251
252class spContext
253{
254protected:
d12e3536
VZ
255 // "linked" list of comments belonging to this context
256 MCommentListT mComments;
257
258 // NULL, if this is file context
259 MMemberListT mMembers;
cecfc5e7 260
d12e3536 261 // NULL, if this is top-most context
2af95167 262 spContext* m_pParent;
cecfc5e7 263
d12e3536
VZ
264 // points to context object, where the this context
265 // was originally declared, meaning that this object
266 // is redeclaration (or if in the case of operation
267 // this context object most probably referres to the
268 // implemnetation in .cpp file for example)
cecfc5e7 269
d12e3536
VZ
270 // is NULL, if this object referres to the first occurence
271 // of the context
cecfc5e7 272
d12e3536 273 spContext* mpFirstOccurence;
cecfc5e7 274
d12e3536
VZ
275 // used, to avoid excessive sorting of context's agreggates
276 bool mAlreadySorted;
cecfc5e7
VZ
277
278public:
279
d12e3536
VZ
280 // source line number, (-1) if unknown
281 int mSrcLineNo;
282
283 // offset of context in the source file, (-1) if unknown
284 int mSrcOffset;
cecfc5e7 285
d12e3536
VZ
286 // lentgh of the context in characters, (-1) if unknown
287 int mContextLength;
cecfc5e7 288
d12e3536
VZ
289 // source line number, in which this cotext ends, (-1) if unknown
290 int mLastScrLineNo;
cecfc5e7 291
d12e3536
VZ
292 // fields are valid, if the may contain other contexts nested inside
293 int mHeaderLength;
294 int mFooterLength;
cecfc5e7 295
d12e3536
VZ
296 // zero-based index of the first character of
297 // this context in the source line, (-1) if unknown
298 int mFirstCharPos;
cecfc5e7 299
d12e3536
VZ
300 // zero-based index of the first character of
301 // this context in the last source line of this context, (-1) if unknown
302 int mLastCharPos;
cecfc5e7 303
d12e3536
VZ
304 // see SRC_VISIBLITY_TYPES enumeration
305 int mVisibility;
cecfc5e7 306
8bc17f14 307 // true, if context does not really exist in the source
d12e3536 308 // but was created by external tools (e.g. forward engineering)
cecfc5e7 309
d12e3536
VZ
310 bool mIsVirtualContext;
311 bool mVirtualContextHasChildren;
cecfc5e7 312
8bc17f14 313 // body of the context in case (mIsVirtual == true)
2af95167
WS
314 wxString mVirtualContextBody;
315 wxString mVittualContextFooter;
d12e3536
VZ
316
317 // e.g. can be used by documentation generator to store
318 // reference to section object
319 void* mpUserData;
cecfc5e7
VZ
320
321public:
d12e3536 322 // universal identifier of the context (e.g. class name)
8bc17f14 323 wxString m_Name;
cecfc5e7
VZ
324
325public:
d12e3536
VZ
326 // default constructor
327 spContext();
328
329 // automatically destorys all aggregated contexts
330 // (thus, it's enought to call destructor of root-context)
331 virtual ~spContext();
cecfc5e7 332
d12e3536
VZ
333 // see mUererData member;
334 void* GetUserData() { return mpUserData; }
cecfc5e7 335
d12e3536
VZ
336 // sets untyped pointer to user data
337 void SetUserData( void* pUserData )
338 { mpUserData = pUserData; }
cecfc5e7 339
d12e3536
VZ
340 // searches the whole context tree for the cotnexts
341 // which match given masks, pust results into lst array
342 void GetContextList( MMemberListT& lst, int contextMask );
cecfc5e7 343
d12e3536
VZ
344 // used by default visitor's implementation
345 bool IsSorted();
cecfc5e7 346
d12e3536 347 /*** forward/reverse ingineering fecilities ***/
cecfc5e7 348
d12e3536 349 bool PositionIsKnown();
cecfc5e7 350
d12e3536 351 bool IsVirtualContext();
cecfc5e7 352
d12e3536 353 bool VitualContextHasChildren();
cecfc5e7 354
2af95167 355 void SetVirtualContextBody( const wxString& body,
8bc17f14 356 bool hasChildren = false,
2af95167 357 const wxString& footer = wxEmptyString );
cecfc5e7 358
2af95167
WS
359 wxString GetVirtualContextBody();
360 wxString GetFooterOfVirtualContextBody();
cecfc5e7 361
d12e3536
VZ
362 // can be overriden by top-level context classes
363 // to find-out ot the source-fragment of this
364 // context using it's position information
fa1af598 365 virtual wxString GetBody( spContext* pCtx = NULL );
cecfc5e7 366
fa1af598 367 virtual wxString GetHeader( spContext* pCtx = NULL );
cecfc5e7 368
8bc17f14 369 // true, if there is at least one entry
d12e3536
VZ
370 // in the comment list of this context
371 bool HasComments();
372 MCommentListT& GetCommentList() { return mComments; }
373 const MCommentListT& GetCommentList() const { return mComments; }
cecfc5e7 374
d12e3536
VZ
375 // should be overriden, if the context supports sorting
376 // of it's members
377 virtual void SortMembers() {}
cecfc5e7 378
d12e3536 379 // returns identifier of this context
8bc17f14 380 inline wxString& GetName() { return m_Name; }
cecfc5e7 381
d12e3536
VZ
382 // returns -1, if souce line # is unknow
383 inline int GetSourceLineNo() { return mSrcLineNo; }
cecfc5e7 384
d12e3536
VZ
385 // see comments on mpFirstOccurence member variable
386 bool IsFirstOccurence();
387 spContext* GetFirstOccurence();
cecfc5e7 388
d12e3536
VZ
389 // returns not-NULL value if this context
390 // is aggregated by another cotnext
391 spContext* GetOutterContext();
cecfc5e7 392
d12e3536 393 // perhaps more intuitive alias for `GetOutterContext()'
2af95167 394 inline spContext* GetParent() { return m_pParent; }
cecfc5e7 395
d12e3536 396 bool HasOutterContext();
cecfc5e7 397
d12e3536
VZ
398 // add one aggregate (or child) into this context
399 void AddMember ( spContext* pMember );
400 MMemberListT& GetMembers();
cecfc5e7 401
d12e3536
VZ
402 // append comment to the comment list decribing
403 // this context
404 void AddComment( spComment* pComment );
cecfc5e7 405
d12e3536
VZ
406 // returns NULL, if the context with the given
407 // name and type is not contained by this context
408 // and it's children. Children's children are not
8bc17f14 409 // searched recursivelly if searchSubMembers is false
cecfc5e7 410
2af95167 411 spContext* FindContext( const wxString& identifier,
d12e3536 412 int contextType = SP_CTX_ANY,
8bc17f14 413 bool searchSubMembers = true
d12e3536 414 );
cecfc5e7 415
d12e3536
VZ
416 // removes this context from it's parent
417 // (NOTE:: context should have an outter cotnext
418 // to when this method is called, otherwise removal
419 // will result assertion failure)
420 void RemoveThisContext();
cecfc5e7 421
8bc17f14 422 // returns true, if this object is aggregated in the file
d12e3536 423 bool IsInFile();
cecfc5e7 424
8bc17f14 425 // true, if outter context is a namespace
d12e3536 426 bool IsInNameSpace();
cecfc5e7 427
8bc17f14 428 // true, if outter context is a class
d12e3536 429 bool IsInClass();
cecfc5e7 430
8bc17f14 431 // true, if outter cotext is an operation (true for "spParameter"s)
d12e3536 432 bool IsInOperation();
cecfc5e7 433
8bc17f14 434 // true if the context is public
cecfc5e7
VZ
435 bool IsPublic() const { return mVisibility == SP_VIS_PUBLIC; }
436
d12e3536
VZ
437 // NOTE:: method returns not the type of this object
438 // but the file/namespace/class/operation or file in which this
439 // attribute is contained. First, check for the type of
440 // context using the above method.
441
442 // Requiering container which does not exist, will result
443 // in assertion failure
444
445 spClass& GetClass();
446 spFile& GetFile();
447 spNameSpace& GetNameSpace();
448 spOperation& GetOperation();
449
450 // each new context should override this method
451 // to return it's specific type
452 virtual int GetContextType() const { return SP_CTX_UNKNOWN; }
cecfc5e7 453
d12e3536
VZ
454 // perhaps more intuitive short-cut
455 inline int GetType() { return GetContextType(); }
cecfc5e7 456
d12e3536
VZ
457 // cast this context to the desired type - returns NULL if type is wrong
458 spAttribute *CastToAttribute()
459 {
460 return GetContextType() == SP_CTX_ATTRIBUTE ? (spAttribute *)this
461 : NULL;
462 }
cecfc5e7 463
d12e3536
VZ
464 // derived classes override this to invoke VisitXXX method
465 // which corresponds to the class of specific context,
466 // - this is what the "Visitor" pattern told us ^)
cecfc5e7 467
d12e3536
VZ
468 // if method is not overriden, then it's probably user-defined
469 // custom context
cecfc5e7 470
d12e3536 471 virtual void AcceptVisitor( spVisitor& visitor )
cecfc5e7 472
d12e3536 473 { visitor.VisitCustomContext( *this ); };
cecfc5e7 474
d12e3536
VZ
475 // called by visitors, to remove given subcontext
476 // of this context object
477 void RemoveChild( spContext* pChild );
cecfc5e7 478
d12e3536 479 void RemoveChildren();
cecfc5e7 480
d12e3536
VZ
481 spContext* GetEnclosingContext( int mask = SP_CTX_ANY );
482
483#ifdef __WXDEBUG__
484 virtual void Dump(const wxString& indent) const;
485#endif // __WXDEBUG__
486
487 DECLARE_DUMP
cecfc5e7
VZ
488};
489
490// stores information about single argument of operation
491
492class spParameter : public spContext
493{
494public:
d12e3536 495 // type of argument (parameter)
821d644d 496 wxString m_Type;
cecfc5e7 497
d12e3536 498 // "stringified" initial value
fa1af598 499 wxString m_InitVal;
cecfc5e7
VZ
500
501public:
d12e3536
VZ
502 virtual int GetContextType() const { return SP_CTX_PARAMETER; }
503
504 virtual void AcceptVisitor( spVisitor& visitor )
505 { visitor.VisitParameter( *this ); }
cecfc5e7 506
d12e3536 507 DECLARE_DUMP
cecfc5e7
VZ
508};
509
510
511// stores information about member(or global) variable
512
513class spAttribute : public spContext
514{
515public:
d12e3536 516 // type of the attribute
821d644d 517 wxString m_Type;
cecfc5e7 518
d12e3536 519 // it's initial value
fa1af598 520 wxString m_InitVal;
cecfc5e7 521
d12e3536
VZ
522 // constantness
523 bool mIsConstant;
cecfc5e7
VZ
524public:
525
d12e3536 526 virtual int GetContextType() const { return SP_CTX_ATTRIBUTE; }
cecfc5e7 527
d12e3536
VZ
528 virtual void AcceptVisitor( spVisitor& visitor )
529 { visitor.VisitAttribute( *this ); }
530
531 DECLARE_DUMP
cecfc5e7
VZ
532};
533
534class spOperation : public spContext
535{
536public:
d12e3536 537 // type of return value
821d644d 538 wxString m_RetType;
cecfc5e7 539
d12e3536
VZ
540 // argument list
541 //MParamListT mParams;
cecfc5e7 542
8bc17f14 543 // true, if operation does not modify
d12e3536
VZ
544 // the content of the object
545 bool mIsConstant;
cecfc5e7 546
d12e3536
VZ
547 // flag, specific to C++
548 bool mIsVirtual;
cecfc5e7 549
8bc17f14 550 // true, if definition follows the declaration immediatelly
d12e3536 551 bool mHasDefinition;
cecfc5e7 552
d12e3536
VZ
553 // scope if any (e.g. MyClass::MyFunction(), scope stirng is "MyClass" )
554 // usually found along with implementation of the method, which is now skipped
cecfc5e7 555
2af95167 556 wxString mScope;
cecfc5e7
VZ
557
558public:
d12e3536 559 spOperation();
cecfc5e7 560
d12e3536
VZ
561 // returns full declaration of the operations
562 // (ret val., identifier, arg. list),
cecfc5e7 563
d12e3536
VZ
564 // arguments are marked up with italic,
565 // default values marked up with bold-italic,
566 // all the rest is marked as bold
cecfc5e7 567
d12e3536
VZ
568 // NOTE:: this method may be overriden by class
569 // specific to concrete parser, to provide
570 // language-dependent reperesnetation of
571 // operation and it's argumetn list
572 //
573 // the default implementation outputs name in
574 // C++/Java syntax
cecfc5e7 575
fa1af598 576 virtual wxString GetFullName(MarkupTagsT tags);
cecfc5e7 577
d12e3536 578 virtual int GetContextType() const { return SP_CTX_OPERATION; }
cecfc5e7 579
d12e3536
VZ
580 virtual void AcceptVisitor( spVisitor& visitor )
581 { visitor.VisitOperation( *this ); }
cecfc5e7 582
d12e3536 583 DECLARE_DUMP
cecfc5e7
VZ
584};
585
586// stores infromation about preprocessor directive
587
d12e3536 588class spPreprocessorLine : public spContext
cecfc5e7
VZ
589{
590
591public:
592
d12e3536
VZ
593 // prepocessor statement including '#' and
594 // attached multiple lines with '\' character
c69a7d10 595 wxString m_Line;
cecfc5e7 596
d12e3536 597 int mDefType; // see SP_PREP_DEFINITION_TYPES enumeration
cecfc5e7
VZ
598
599public:
600
d12e3536
VZ
601 virtual int GetContextType() const { return SP_CTX_PREPROCESSOR; }
602
603 virtual int GetStatementType() const { return mDefType; }
cecfc5e7 604
fa1af598 605 wxString CPP_GetIncludedFileNeme() const;
cecfc5e7 606
d12e3536
VZ
607 virtual void AcceptVisitor( spVisitor& visitor )
608 { visitor.VisitPreprocessorLine( *this ); }
cecfc5e7 609
d12e3536 610 DECLARE_DUMP
cecfc5e7
VZ
611};
612
d12e3536 613// stores information about the class
cecfc5e7
VZ
614
615class spClass : public spContext
616{
617public:
d12e3536 618 // list of superclasses/interfaces
33882d15 619 StrListT m_SuperClassNames;
cecfc5e7 620
d12e3536
VZ
621 // see SP_CLASS_TYPES enumeration
622 int mClassSubType;
cecfc5e7 623
d12e3536
VZ
624 // see SP_INHERITANCE_TYPES enumeration
625 int mInheritanceType;
cecfc5e7 626
d12e3536 627 // valid if mClassSubType is SP_CLTYPE_TEMPLATE_CLASS
2af95167 628 wxString mTemplateTypes;
cecfc5e7 629
8bc17f14 630 // true, if it's and interface of abstract base class
d12e3536 631 bool mIsAbstract;
cecfc5e7
VZ
632
633public:
d12e3536
VZ
634 // sorts class members in the following order:
635 //
636 // (by "privacy level" - first private, than protected, public)
637 //
638 // within above set
639 //
640 // (by member type - attributes first, than methods, nested classes)
641 //
642 // within above set
643 //
644 // (by identifier of the member)
645
646 virtual void SortMembers();
647
648 virtual int GetContextType() const { return SP_CTX_CLASS; }
649
650 virtual void AcceptVisitor( spVisitor& visitor )
651 { visitor.VisitClass( *this ); }
652
653 DECLARE_DUMP
cecfc5e7
VZ
654};
655
656// stores information about enum statement
657
658class spEnumeration : public spContext
659{
660public:
c69a7d10 661 wxString m_EnumContent; // full-text content of enumeration
cecfc5e7
VZ
662
663public:
d12e3536 664 virtual int GetContextType() const { return SP_CTX_ENUMERATION; }
cecfc5e7 665
d12e3536
VZ
666 virtual void AcceptVisitor( spVisitor& visitor )
667 { visitor.VisitEnumeration( *this ); }
668
669 DECLARE_DUMP
cecfc5e7
VZ
670};
671
672class spTypeDef : public spContext
673{
674public:
d12e3536
VZ
675 // the original type which is redefined
676 // by this type definition
c69a7d10 677 wxString m_OriginalType;
cecfc5e7
VZ
678
679public:
d12e3536
VZ
680 virtual int GetContextType() const { return SP_CTX_TYPEDEF; }
681
682 virtual void AcceptVisitor( spVisitor& visitor )
683 { visitor.VisitTypeDef( *this ); }
cecfc5e7 684
d12e3536 685 DECLARE_DUMP
cecfc5e7
VZ
686};
687
688// NOTE:: files context may be put to other
689// file context, resulting in a collection
690// of parsed file contexts, with a virtual "superfile"
691
692class spFile : public spContext
693{
694public:
d12e3536
VZ
695 // since file name cannot be determined from
696 // source code, filling in this field is optional
60ec1c87 697 wxString m_FileName;
cecfc5e7
VZ
698
699public:
d12e3536
VZ
700 virtual int GetContextType() const { return SP_CTX_FILE; }
701
702 virtual void AcceptVisitor( spVisitor& visitor )
703 { visitor.VisitFile( *this ); }
cecfc5e7 704
d12e3536 705 DECLARE_DUMP
cecfc5e7
VZ
706};
707
708//TODO:: comments.
709
710class SourceParserPlugin
711{
712public:
d12e3536
VZ
713 virtual bool CanUnderstandContext( char* cur, char* end, spContext* pOuttterCtx ) = 0;
714 virtual void ParseContext( char* start, char*& cur, char* end, spContext* pOuttterCtx ) = 0;
cecfc5e7
VZ
715};
716
717// abstract interface for source parsers
718// which can output parsing results in the
719// form of context-tree, where each node
720// should be derivative of spContext, (see
721// above classes)
722
d12e3536 723class SourceParserBase
cecfc5e7
VZ
724{
725private:
d12e3536
VZ
726 // auto-resizing file buffer, created in ParseFile()
727 // to reuse large heap block for multiple parsings
728
729 char* mpFileBuf;
730 int mFileBufSz;
cecfc5e7
VZ
731
732protected:
d12e3536
VZ
733 SourceParserPlugin* mpPlugin;
734
cecfc5e7 735protected:
d12e3536
VZ
736 // value is set in the derived parser classes
737 int mParserStatus;
cecfc5e7
VZ
738
739public:
d12e3536
VZ
740 SourceParserBase();
741 virtual ~SourceParserBase();
cecfc5e7 742
d12e3536
VZ
743 // loads entier source file(as text) into memory,
744 // and passes it's contents to ParseAll() method,
745 // memory occupied by source text is released after
746 // parsing is done
747 //
748 // (NOTE:: this is the default implementation),
cecfc5e7 749
d12e3536 750 virtual spFile* ParseFile( const char* fname );
cecfc5e7 751
d12e3536
VZ
752 // should returns the root-node of the created context tree
753 // (user is responsible for releasing it from the heep)
754 // "end" should point to the (last character + 1) of the
755 // source text area
cecfc5e7 756
d12e3536 757 virtual spFile* Parse( char* start, char* end ) = 0;
cecfc5e7 758
d12e3536
VZ
759 // returns parser "status word" (specific to concrete parser)
760 int GetParserStatus() { return mParserStatus; }
cecfc5e7 761
d12e3536 762 void SetPlugin( SourceParserPlugin* pPlugin );
cecfc5e7
VZ
763};
764
765#endif