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