KDevelop API Documentation

ASTFactory Class Reference

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

#include <ASTFactory.hpp>

Inheritance diagram for ASTFactory:

Inheritance graph
[legend]
Collaboration diagram for ASTFactory:

Collaboration graph
[legend]
List of all members.

Public Types

typedef RefAST(* factory_type )()
typedef std::pair< const char *,
factory_type
factory_descriptor
typedef std::vector< factory_descriptor * > 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

Private Member Functions

 ASTFactory (const ASTFactory &)
ASTFactoryoperator= (const ASTFactory &)

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 30 of file ASTFactory.hpp.


Member Typedef Documentation

typedef std ::pair< const char*, factory_type > ASTFactory::factory_descriptor
 

Definition at line 33 of file ASTFactory.hpp.

typedef std ::vector< factory_descriptor* > ASTFactory::factory_descriptor_list
 

Definition at line 34 of file ASTFactory.hpp.

typedef RefAST(* ASTFactory::factory_type)()
 

Definition at line 32 of file ASTFactory.hpp.

Referenced by getASTNodeFactory().


Constructor & Destructor Documentation

ASTFactory::ASTFactory  ) 
 

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

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.

Definition at line 38 of file ASTFactory.cpp.

References ANTLR_USE_NAMESPACE, default_factory_descriptor, and nodeFactories.

ASTFactory::ASTFactory const char *  factory_node_name,
factory_type  factory
 

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 48 of file ASTFactory.cpp.

References ANTLR_USE_NAMESPACE, default_factory_descriptor, and nodeFactories.

ASTFactory::~ASTFactory  )  [virtual]
 

Destroy factory.

Definition at line 55 of file ASTFactory.cpp.

References nodeFactories.

ASTFactory::ASTFactory const ASTFactory  )  [private]
 


Member Function Documentation

void ASTFactory::addASTChild ASTPair currentAST,
RefAST  child
 

Add a child to the current AST.

Definition at line 160 of file ASTFactory.cpp.

References ASTPair::advanceChildToEnd(), ASTPair::child, RefAST, and ASTPair::root.

bool ASTFactory::checkCloseTag std::istream &  infile  )  [protected]
 

RefAST ASTFactory::create const std::string &  txt,
std::istream &  infile
 

Create new AST node and initialize contents from a stream.

RefAST ASTFactory::create RefToken  tok  ) 
 

Create new AST node and initialize contents from a token.

Definition at line 151 of file ASTFactory.cpp.

References nodeFactories, RefAST, and RefToken.

RefAST ASTFactory::create RefAST  tr  ) 
 

Create duplicate of tr.

Definition at line 139 of file ASTFactory.cpp.

References nodeFactories, and RefAST.

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

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

Definition at line 108 of file ASTFactory.cpp.

References nodeFactories, and RefAST.

RefAST ASTFactory::create int  type  ) 
 

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

Definition at line 101 of file ASTFactory.cpp.

References nodeFactories, and RefAST.

RefAST ASTFactory::create  )  [virtual]
 

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

Definition at line 94 of file ASTFactory.cpp.

References nodeFactories, and RefAST.

RefAST 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.

Definition at line 190 of file ASTFactory.cpp.

References nullASTptr, and RefAST.

Referenced by dupTree().

RefAST ASTFactory::dupList RefAST  t  ) 
 

Duplicate tree including siblings of root.

Definition at line 199 of file ASTFactory.cpp.

References dupTree(), and RefAST.

Referenced by dupTree().

RefAST 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.

Definition at line 216 of file ASTFactory.cpp.

References dup(), dupList(), and RefAST.

Referenced by dupList().

factory_type ASTFactory::getASTNodeFactory unsigned int  type  )  [inline, protected]
 

Definition at line 143 of file ASTFactory.hpp.

References factory_type, and nodeFactories.

const char* ASTFactory::getASTNodeType unsigned int  type  )  [inline, protected]
 

get the name of the node 'type'

Definition at line 139 of file ASTFactory.hpp.

References nodeFactories.

RefAST ASTFactory::getNodeOfType unsigned int  type  )  [inline, protected]
 

Definition at line 134 of file ASTFactory.hpp.

References nodeFactories, and RefAST.

void ASTFactory::loadChildren std::istream &  infile,
RefAST  current
[protected]
 

void ASTFactory::loadSiblings std::istream &  infile,
RefAST  current
[protected]
 

RefAST 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.

Fixme:
I have a feeling we can get rid of this ugly ASTArray thing

Definition at line 275 of file ASTFactory.cpp.

References ASTArray::array, make(), and RefAST.

RefAST 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 231 of file ASTFactory.cpp.

References nullASTptr, and RefAST.

Referenced by make().

void ASTFactory::makeASTRoot ASTPair currentAST,
RefAST  root
 

Make an AST the root of current AST.

Definition at line 283 of file ASTFactory.cpp.

References ASTPair::advanceChildToEnd(), ASTPair::child, RefAST, and ASTPair::root.

ASTFactory& ASTFactory::operator= const ASTFactory  )  [private]
 

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

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

Definition at line 68 of file ASTFactory.cpp.

References ANTLR_USE_NAMESPACE, default_factory_descriptor, and nodeFactories.

void 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 297 of file ASTFactory.cpp.

References default_factory_descriptor.

void ASTFactory::setMaxNodeType int  type  ) 
 

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

Definition at line 85 of file ASTFactory.cpp.

References default_factory_descriptor, and nodeFactories.


Member Data Documentation

factory_descriptor ASTFactory::default_factory_descriptor [protected]
 

Definition at line 38 of file ASTFactory.hpp.

Referenced by ASTFactory(), registerFactory(), setASTNodeFactory(), and setMaxNodeType().

factory_descriptor_list ASTFactory::nodeFactories [protected]
 

Definition at line 39 of file ASTFactory.hpp.

Referenced by ASTFactory(), create(), getASTNodeFactory(), getASTNodeType(), getNodeOfType(), registerFactory(), setMaxNodeType(), and ~ASTFactory().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:36:49 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003