Public Types | Public Member Functions | Static Public Attributes | Protected Attributes

SyntaxNode Class Reference

This is a node in the operator tree. More...

#include <nodes.h>

Inheritance diagram for SyntaxNode:
IDNode ListNode OpNode SetNode SetSpec StageNodeNode SyntaxNodeIDREF SyntaxNodeIx ValueNode< T >

List of all members.

Public Types

typedef std::vector
< SyntaxNode * >
::const_iterator 
iterator

Public Member Functions

iterator begin () const
iterator end () const
SyntaxNodefront () const
SyntaxNodeback () const
SyntaxNodeoperator[] (int i) const
virtual void clear ()
 Clear the child list.
 SyntaxNode (int opCode, SyntaxNode *val1=NULL, SyntaxNode *val2=NULL, SyntaxNode *val3=NULL)
 Constructor.
 SyntaxNode (const SyntaxNode &src)
 Copy constructor.
virtual ~SyntaxNode ()
 Destructor.
virtual int nchild () const
 Retrieve the number of children.
int getOpCode () const
 Retrieve the opCode.
std::string print () const
 Recursive printing of expression.
virtual std::string getValue () const
 Return the value of this node as a string.
void dump (std::ostream &fout) const
 Diagnostic printing.
std::string printDummyVar () const
std::string getArgumentList () const
 Return comma separated list of arguments for IDREF nodes.
virtual void findIDREF (std::list< ModelComp * > &lmc) const
 Find all the IDREF nodes at or below the current node.
virtual void findIDREF (std::list< SyntaxNode * > *lnd)
 Find all the IDREF nodes at or below the current node.
virtual void findOpCode (int oc, std::list< SyntaxNode * > *lnd)
 Find all nodes of opCode oc at or below the current node.
ModelCompfindModelComp () const
 Find the ModelComp (if it exists) referred to by this SyntaxNode.
SyntaxNodemerge (const SyntaxNode *src)
 Merges the values list of src into that of this object.
virtual SyntaxNodedeep_copy ()
 Creates a deep copy of the nodes: SyntaxNodes pointed to are recreated as well.
virtual SyntaxNodeclone ()
 Creates a copy of the node, reusing the pointer in the current node.
virtual std::ostream & put (std::ostream &s) const
virtual SyntaxNodepush_back (SyntaxNode *newitem)
 Add an item to the back.
virtual SyntaxNodepush_front (SyntaxNode *newitem)
 Add an item to the front.

Static Public Attributes

static int use_global_names = 0
 if use_global_names is set then the print() method will print out model component names as global names
static AmplModeldefault_model = NULL

Protected Attributes

int opCode
 ID CODE of this node (a list can be found in ampl.tab.h).
std::vector< SyntaxNode * > values
 List of arguments.

Detailed Description

This is a node in the operator tree.

All AMPL/SML expressions are broken down into a tree of operators. The nodes of this tree are objects of type SyntaxNode.

Note that values[] is a list of untyped pointers. Normally these would point to further SyntaxNode structure (children of the current node). For an ID it is simply a pointer to the string containing the name.

There are a few special meanings of the values array depending on the type of node (i.e. the value of opCode).

Bug:
This should probably be implemented by deriving subclasses, however an attempt for ID nodes resulted in problems with dynamic_casts
Bug:
A comma separated list is currently represented by a SyntaxNode with opCode==COMMA and values[0/1] pointing to the first and last member in a linked list of SyntaxNodes. This linked list is implemented using _indexNode objects (which is a SyntaxNode plus a pointer to next). This is done to facilitate adding members to the list without knowing the dimension beforehand. Better implemented by replacing the SyntaxNode::values array with a C++ list.

Member Typedef Documentation

typedef std::vector<SyntaxNode*>::const_iterator SyntaxNode::iterator

Constructor & Destructor Documentation

SyntaxNode::SyntaxNode ( int  opCode,
SyntaxNode val1 = NULL,
SyntaxNode val2 = NULL,
SyntaxNode val3 = NULL 
)

Constructor.

References logCreate, opCode, and values.

Referenced by clone(), and deep_copy().

SyntaxNode::SyntaxNode ( const SyntaxNode src  ) 

Copy constructor.

SyntaxNode::~SyntaxNode (  )  [virtual]

Destructor.

References nchild(), and values.


Member Function Documentation

SyntaxNode* SyntaxNode::back (  )  const [inline]

References values.

virtual void SyntaxNode::clear (  )  [inline, virtual]

Clear the child list.

References opCode, and values.

SyntaxNode * SyntaxNode::clone (  )  [virtual]

Creates a copy of the node, reusing the pointer in the current node.

Reimplemented in StageNodeNode, SyntaxNodeIDREF, and OpNode.

References IDREF, opCode, SyntaxNode(), and values.

Referenced by StochModel::expandToFlatModel().

SyntaxNode * SyntaxNode::deep_copy (  )  [virtual]

Creates a deep copy of the nodes: SyntaxNodes pointed to are recreated as well.

Non-SyntaxNode objects pointed to are not recreated, here just pointers are copied (->ref in the case of a SyntaxNodeIDREF object). The int/double entries pointed to by INT_VAL/FLOAT_VAL SyntaxNodes *are* recreated.

Reimplemented in StageNodeNode, SyntaxNodeIx, IDNode, SyntaxNodeIDREF, and OpNode.

References begin(), end(), ID, IDREF, IDREFM, opCode, push_back(), and SyntaxNode().

Referenced by OpNode::deep_copy(), SyntaxNodeIx::deep_copy(), ModelComp::deep_copy(), and StochModelComp::transcribeToModelComp().

void SyntaxNode::dump ( std::ostream &  fout  )  const

Diagnostic printing.

References print_SyntaxNodesymb().

Referenced by AmplModel::dump().

void SyntaxNode::findIDREF ( std::list< ModelComp * > &  lmc  )  const [virtual]

Find all the IDREF nodes at or below the current node.

References begin(), end(), ID, IDREF, and opCode.

Referenced by StochModel::expandStagesOfComp(), ModelComp::findDependencies(), OpNode::findIDREF(), ModelComp::moveUp(), and ModelComp::reassignDependencies().

void SyntaxNode::findIDREF ( std::list< SyntaxNode * > *  lnd  )  [virtual]

Find all the IDREF nodes at or below the current node.

Reimplemented in IDNode, and OpNode.

References findOpCode(), and IDREF.

ModelComp * SyntaxNode::findModelComp (  )  const

Find the ModelComp (if it exists) referred to by this SyntaxNode.

If the expression given by this SyntaxNode is an immediate reference to a ModelComp then return that, otherwise return NULL.

Returns:
The ModelComp only if the expression given by this SyntaxNode is an immediate reference to a ModelComp, otherwise NULL.

References IDREF, LBRACE, LBRACKET, nchild(), opCode, SyntaxNodeIDREF::ref, and values.

Referenced by SyntaxNodeIx::splitExpression().

void SyntaxNode::findOpCode ( int  oc,
std::list< SyntaxNode * > *  lnd 
) [virtual]

Find all nodes of opCode oc at or below the current node.

Reimplemented in IDNode, and OpNode.

References begin(), end(), ID, and opCode.

Referenced by findIDREF(), OpNode::findOpCode(), and StochModelComp::transcribeToModelComp().

string SyntaxNode::getArgumentList (  )  const

Return comma separated list of arguments for IDREF nodes.

This is for a SyntaxNode of type IDREF (and should eventually be moved to SyntaxNodeIDREF:getArgumentList()).

Returns:
A comma separated list of the arguments (the bit in [..] brackets).

References begin(), end(), getOpCode(), IDREF, nchild(), print(), and values.

Referenced by getGlobalName(), and getGlobalNameNew().

virtual std::string SyntaxNode::getValue (  )  const [inline, virtual]

Return the value of this node as a string.

Reimplemented in IDNode.

Referenced by CompDescrParam::CompDescrParam().

SyntaxNode * SyntaxNode::merge ( const SyntaxNode src  ) 

Merges the values list of src into that of this object.

The items from src are prepended to this object's values.

References nchild(), and values.

SyntaxNode* SyntaxNode::operator[] ( int  i  )  const [inline]

References values.

string SyntaxNode::print (  )  const
string SyntaxNode::printDummyVar (  )  const

References COMMA, front(), ID, LBRACKET, opCode, and print().

Referenced by getGlobalName(), and getGlobalNameNew().

SyntaxNode * SyntaxNode::push_front ( SyntaxNode newitem  )  [virtual]

Add an item to the front.

References values.

Referenced by ModelComp::moveUp(), and StochModelComp::transcribeToModelComp().

ostream & SyntaxNode::put ( std::ostream &  s  )  const [virtual]

Member Data Documentation

int SyntaxNode::use_global_names = 0 [static]

if use_global_names is set then the print() method will print out model component names as global names

Referenced by print_model(), SyntaxNodeIDREF::put(), and write_ampl_for_submodel().

std::vector<SyntaxNode*> SyntaxNode::values [protected]

List of arguments.

For opCode==ID, there is usually one argument, this is a (char*) to the name of the entity. If there are two arguments the second argument is an (int*) stating the ancestor information as set by ancestor(1).ID in stochastic programming

Referenced by back(), begin(), clear(), SyntaxNodeIDREF::clone(), clone(), SyntaxNodeIDREF::deep_copy(), SyntaxNodeIx::deep_copy(), end(), findModelComp(), front(), getArgumentList(), merge(), nchild(), operator[](), push_back(), push_front(), SyntaxNode(), and ~SyntaxNode().


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