CDT Parser Framework for 1.2 and Beyond This document serves as an overview for the work that is being done to support CDT 1.2 & 2.0 language related features. |
![]() |
Author | : John Camelon |
Revision Date | : 07/14/2003 - Version: 1.0 |
In order to better communicate the changes that are happening related to the Parser/CDOM architecture, I have been asked to put together a document to describe the problems with the 1.1 parser architecture, where we are going with the parser framework in CDT 1.2 & beyond. This document serves mostly as a plan of record, a catch-all for requirement and design discussions that have for the most part have happened exclusively @ IBM Canada.
The CDT Parser improved significantly between release 1.0 & 1.1, yet while this was a significant achievement, the language support provided was only at a coarse structural level; features such as the Outline View and the Structure Compare features only rely upon having a structural view of the file, without parsing into function bodies or maintaining strict cross-reference information.
We had also discovered a couple of serious problems with our Parser/IParserCallback strategy:
ISourceElementRequestor has two different categories of callback methods: acceptXXXX style methods are provided for completely parsed units that do not relate to Scopes or Inclusions. enterXXXX and exitXXXX style methods are provided for when we enter and exit a scope. It is the client's responsibility to keep a stack of scopes so that they can make sure to be aware of the current scope/inclusion level.
It is expected that clients of ISourceElementRequestor do not keep hold of the nodes once they are processed in the callback. In ParserMode.COMPLETE_PARSE mode, local variable definitions are garbage collected when they go out of scope, by holding onto these references you would be doing the CDT a disservice.
All Parser implementations can be instantiated using static methods upon the ParserFactory class. Please do not instantiate Parser internal classes from outside the Parser package.
3.2 Internals
Our parser uses an IASTFactory to create the AST nodes that are called back through ISourceElementRequestor. This way, the Parser can remain agnostic with regards to the specific implementation of an IAST-interface.
Thus, we can have different IASTFactory implementations that allow for different semantic validation. In particular, our ParserSymbolTable (which implements the ANSI C++ scoping and lookup rules) resides exclusively in the FullParseFactory.
In the COMPLETE_PARSE mode, the AST Nodes serve as facades to the ParserSymbolTable Declaration-nodes. In QUICK_PARSE mode, the AST Nodes have simple implementations.
3.3 C/C++ Language Variants
It is undecided at this point to what extent we shall support non-ISO variants in the 1.2 time-frame. If substantial support is deemed necessary, then it will be necessary to add Parser variants to the CDT Target Model.
3.4 Selection Search/Code Assists
It will be necessary to provide another interface upon IParser that will allow for the client to specify an offset to parse up to. In this mode, ISourceElementRequestor callbacks will not be provided, but a node will be returned as a result of parse() that will qualify the client as to what the cursor/selection is referring to in the overall AST Parse-tree.