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