OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
antlr::ASTFactory Class Reference

AST Super Factory shared by TreeParser and Parser. More...

#include <ASTFactory.hpp>

Public Types

typedef factory_type_ factory_type
 
typedef factory_descriptor_ factory_descriptor
 
typedef factory_descriptor_list_ factory_descriptor_list
 

Public Member Functions

 ASTFactory ()
 Make new factory. Per default (Ref)CommonAST instances are generated.
 
 ASTFactory (const char *factory_node_name, factory_type factory)
 Initialize factory with a non default node type.
 
virtual ~ASTFactory ()
 Destroy factory.
 
void registerFactory (int type, const char *ast_name, factory_type factory)
 Register a node factory for the node type type with name ast_name.
 
void setMaxNodeType (int type)
 Set the maximum node (AST) type this factory may encounter.
 
void addASTChild (ASTPair &currentAST, RefAST child)
 Add a child to the current AST.
 
virtual RefAST create ()
 Create new empty AST node. The right default type shou.
 
RefAST create (int type)
 Create AST node of the right type for 'type'.
 
RefAST create (int type, const std ::string &txt)
 Create AST node of the right type for 'type' and initialize with txt.
 
RefAST create (RefAST tr)
 Create duplicate of tr.
 
RefAST create (RefToken tok)
 Create new AST node and initialize contents from a token.
 
RefAST create (const std ::string &txt, std ::istream &infile)
 Create new AST node and initialize contents from a stream.
 
RefAST dup (RefAST t)
 Deep copy a single node.
 
RefAST dupList (RefAST t)
 Duplicate tree including siblings of root.
 
RefAST dupTree (RefAST t)
 Duplicate a tree, assuming this is a root node of a tree– duplicate that node and what's below; ignore siblings of root node.
 
RefAST make (std ::vector< RefAST > &nodes)
 Make a tree from a list of nodes.
 
RefAST make (ASTArray *nodes)
 Make a tree from a list of nodes, where the nodes are contained in an ASTArray object.
 
void makeASTRoot (ASTPair &currentAST, RefAST root)
 Make an AST the root of current AST.
 
void setASTNodeFactory (const char *factory_node_name, factory_type factory)
 Set a new default AST type.
 

Protected Member Functions

void loadChildren (std ::istream &infile, RefAST current)
 
void loadSiblings (std ::istream &infile, RefAST current)
 
bool checkCloseTag (std ::istream &infile)
 
RefAST getNodeOfType (unsigned int type)
 
const char * getASTNodeType (unsigned int type)
 get the name of the node 'type'
 
factory_type getASTNodeFactory (unsigned int type)
 

Protected Attributes

factory_descriptor default_factory_descriptor
 
factory_descriptor_list nodeFactories
 

Detailed Description

AST Super Factory shared by TreeParser and Parser.

This super factory maintains a map of all AST node types to their respective AST factories. One instance should be shared among a parser/treeparser chain.

Todo
check all this code for possible use of references in stead of RefAST's.

Definition at line 36 of file ASTFactory.hpp.

Member Typedef Documentation

◆ factory_descriptor

typedef factory_descriptor_ antlr::ASTFactory::factory_descriptor

Definition at line 39 of file ASTFactory.hpp.

◆ factory_descriptor_list

typedef factory_descriptor_list_ antlr::ASTFactory::factory_descriptor_list

Definition at line 40 of file ASTFactory.hpp.

◆ factory_type

typedef factory_type_ antlr::ASTFactory::factory_type

Definition at line 38 of file ASTFactory.hpp.

Constructor & Destructor Documentation

◆ ASTFactory() [1/2]

antlr::ASTFactory::ASTFactory ( )

Make new factory. Per default (Ref)CommonAST instances are generated.

AST Support code shared by TreeParser and Parser.

We use delegation to share code (and have only one bit of code to maintain) rather than subclassing or superclassing (forces AST support code to be loaded even when you don't want to do AST stuff).

This class collects all factories of AST types used inside the code. New AST node types are registered with the registerFactory method. On creation of an ASTFactory object a default AST node factory may be specified.

When registering types gaps between different types are filled with entries for the default factory. Initialize factory

Definition at line 39 of file ASTFactory.cpp.

◆ ASTFactory() [2/2]

antlr::ASTFactory::ASTFactory ( const char * factory_node_name,
factory_type fact )

Initialize factory with a non default node type.

factory_node_name should be the name of the AST node type the factory generates. (should exist during the existance of this ASTFactory instance)

Definition at line 49 of file ASTFactory.cpp.

◆ ~ASTFactory()

antlr::ASTFactory::~ASTFactory ( )
virtual

Destroy factory.

Delete ASTFactory.

Definition at line 56 of file ASTFactory.cpp.

Member Function Documentation

◆ addASTChild()

void antlr::ASTFactory::addASTChild ( ASTPair & currentAST,
RefAST child )

Add a child to the current AST.

Definition at line 161 of file ASTFactory.cpp.

References antlr::ASTPair::advanceChildToEnd(), antlr::AST::setFirstChild(), and antlr::AST::setNextSibling().

◆ create() [1/5]

RefAST antlr::ASTFactory::create ( )
virtual

Create new empty AST node. The right default type shou.

Create a new empty AST node; if the user did not specify an AST node type, then create a default one: CommonAST.

Definition at line 95 of file ASTFactory.cpp.

References antlr::AST::setType().

◆ create() [2/5]

RefAST antlr::ASTFactory::create ( int type)

Create AST node of the right type for 'type'.

Definition at line 102 of file ASTFactory.cpp.

References antlr::AST::initialize().

◆ create() [3/5]

RefAST antlr::ASTFactory::create ( int type,
const std ::string & txt )

Create AST node of the right type for 'type' and initialize with txt.

Definition at line 109 of file ASTFactory.cpp.

References antlr::AST::initialize().

◆ create() [4/5]

RefAST antlr::ASTFactory::create ( RefAST tr)

Create duplicate of tr.

Create a new empty AST node; if the user did not specify an AST node type, then create a default one: CommonAST.

Definition at line 140 of file ASTFactory.cpp.

References antlr::AST::getType(), and antlr::AST::initialize().

◆ create() [5/5]

RefAST antlr::ASTFactory::create ( RefToken tok)

Create new AST node and initialize contents from a token.

Definition at line 152 of file ASTFactory.cpp.

References antlr::AST::initialize().

◆ dup()

RefAST antlr::ASTFactory::dup ( RefAST t)

Deep copy a single node.

This function the new clone() methods in the AST interface. Returns a new RefAST(nullASTptr) if t is null.

This function the new clone() methods in the AST interface. Returns nullAST if t is null.

Definition at line 191 of file ASTFactory.cpp.

References antlr::AST::clone().

Referenced by dupTree().

◆ dupList()

RefAST antlr::ASTFactory::dupList ( RefAST t)

Duplicate tree including siblings of root.

Definition at line 200 of file ASTFactory.cpp.

References dupTree(), antlr::AST::getNextSibling(), and antlr::AST::setNextSibling().

Referenced by dupTree().

◆ dupTree()

RefAST antlr::ASTFactory::dupTree ( RefAST t)

Duplicate a tree, assuming this is a root node of a tree– duplicate that node and what's below; ignore siblings of root node.

Duplicate a tree, assuming this is a root node of a tree duplicate that node and what's below; ignore siblings of root node.

Definition at line 217 of file ASTFactory.cpp.

References dup(), dupList(), antlr::AST::getFirstChild(), and antlr::AST::setFirstChild().

Referenced by dupList().

◆ getASTNodeFactory()

factory_type antlr::ASTFactory::getASTNodeFactory ( unsigned int type)
inlineprotected

Definition at line 149 of file ASTFactory.hpp.

◆ getASTNodeType()

const char * antlr::ASTFactory::getASTNodeType ( unsigned int type)
inlineprotected

get the name of the node 'type'

Definition at line 145 of file ASTFactory.hpp.

◆ getNodeOfType()

RefAST antlr::ASTFactory::getNodeOfType ( unsigned int type)
inlineprotected

Definition at line 140 of file ASTFactory.hpp.

◆ make() [1/2]

RefAST antlr::ASTFactory::make ( ASTArray * nodes)

Make a tree from a list of nodes, where the nodes are contained in an ASTArray object.

The ASTArray is deleted after use.

Todo
FIXME! I have a feeling we can get rid of this ugly ASTArray thing

Definition at line 276 of file ASTFactory.cpp.

References make().

◆ make() [2/2]

RefAST antlr::ASTFactory::make ( std ::vector< RefAST > & nodes)

Make a tree from a list of nodes.

The first element in the array is the root. If the root is null, then the tree is a simple list not a tree. Handles null children nodes correctly. For example, make(a, b, null, c) yields tree (a b c). make(null,a,b) yields tree (nil a b).

Definition at line 232 of file ASTFactory.cpp.

References antlr::AST::getFirstChild(), antlr::AST::getNextSibling(), antlr::AST::setFirstChild(), and antlr::AST::setNextSibling().

Referenced by make().

◆ makeASTRoot()

void antlr::ASTFactory::makeASTRoot ( ASTPair & currentAST,
RefAST root )

Make an AST the root of current AST.

Definition at line 284 of file ASTFactory.cpp.

References antlr::AST::addChild(), and antlr::ASTPair::advanceChildToEnd().

◆ registerFactory()

void antlr::ASTFactory::registerFactory ( int type,
const char * ast_name,
factory_type factory )

Register a node factory for the node type type with name ast_name.

Register a factory for a given AST type.

Definition at line 69 of file ASTFactory.cpp.

◆ setASTNodeFactory()

void antlr::ASTFactory::setASTNodeFactory ( const char * factory_node_name,
factory_type factory )

Set a new default AST type.

factory_node_name should be the name of the AST node type the factory generates. (should exist during the existance of this ASTFactory instance). Only change factory between parser runs. You might get unexpected results otherwise.

Definition at line 298 of file ASTFactory.cpp.

◆ setMaxNodeType()

void antlr::ASTFactory::setMaxNodeType ( int type)

Set the maximum node (AST) type this factory may encounter.

Definition at line 86 of file ASTFactory.cpp.

Member Data Documentation

◆ default_factory_descriptor

factory_descriptor antlr::ASTFactory::default_factory_descriptor
protected

Definition at line 44 of file ASTFactory.hpp.

◆ nodeFactories

factory_descriptor_list antlr::ASTFactory::nodeFactories
protected

Definition at line 45 of file ASTFactory.hpp.


The documentation for this class was generated from the following files: