How do I change the AST type using C++?

Peter Wells

Because of the reference counted RefAST class, you don't override AST, you override ASTNode (or CommonASTNode).

Be sure to provide a static method 'factory' which constructs a new instance of your node class (see CommonASTNode for an example).

Then call parser.setASTNodeFactory(&MyASTNode::factory) for your parser.

You don't need to set the ASTLabelType option (it won't help).

If you need to explicitly access your extended class, you will need to call getNode(), and cast the resulting ASTNode down to your class. For example:

      wall : ... b:brick
            { MyASTNode* node = (MyASTNode*) (#b->getNode()); ... }
         ;

Note that getNode doesn't transfer the ownership of the pointer, in other words, the RefAST will still delete the pointer when it's finished with it, so you should only use this pointer while you know the tree is still active.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact