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.