Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

binaryNode Class Reference

Binary operator. More...

#include <ast.h>

Inheritance diagram for binaryNode::

exprNode Node List of all members.

Public Methods

 binaryNode (unsigned int op_id, exprNode *left, exprNode *right, const Coord coord=Coord::Unknown)
 Create a new binary expression. More...

virtual ~binaryNode ()
 Destroy a binaryNode. More...

virtual void eval ()
 Constant expression evaluator. More...

virtual void dataflow (FlowVal *v, FlowProblem &fp)
 Run the dataflow analyzer. More...

virtual Nodeclone () const
 Clone the input node. More...

virtual void output_expr (output_context &ct, Node *par, int prec, Assoc assoc)
 Output a expression. More...

virtual int precedence (Assoc &assoc)
 Associativity and precedence. More...

Accessors
Methods to get and set fields in the class.

Operatorop () const
void op (Operator *op)
exprNodeleft () const
exprNodeget_left ()
void left (exprNode *left)
exprNoderight () const
exprNodeget_right ()
void right (exprNode *right)
AST Traversal
Methods to uniformly traverse the AST. See the documentation in the Node class.

virtual void visit (Visitor *the_visitor)
 Dispatch a Visitor. More...

virtual void walk (Walker &the_walker)
 Dispatch a Walker. More...

virtual Nodechange (Changer &the_changer, bool redispatch=false)
 Dispatch a Changer. More...


Private Attributes

Operator_op
 the operator. More...

TREE exprNode_left
 the left expression subtree. More...

TREE exprNode_right
 the right expression subtree. More...


Detailed Description

Binary operator.

This class represents most expressions with two arguments (binary operator expressions). The only exception is the castNode, because it takes a type as an argument.

The indexNode class has been folded into the binaryNode class, so now array index expressions are represented as binary operations. The operator is Operator::Index. The left expression is the array and the right expression is the index. Note that multi-dimensional array access generates nested index operators, one for each dimension. The operator is left associative, so the tree for "A[2][7]" looks like this: indexNode [7] --> indexNode [2] --> idNode "A".

The NodeType is Binary.


Constructor & Destructor Documentation

binaryNode::binaryNode unsigned int    op_id,
exprNode   left,
exprNode   right,
const Coord    coord = Coord::Unknown
 

Create a new binary expression.

The new expression has the given operator, and left and right subexpressions. The operator is given using its identifier from the parser. For most operators, this is simply the char representation. For example, we pass '+' to get the addition operator. For ambiguous operators and multiple-character operators, you need to look up the proper identifier in the Operators table.

See also:
Operator , Operators , Operators::table
Parameters:
op_id  the id of the operator (usually, just the char representation)
left  the left expression subtree
right  the right expression subtree
coord  the location of the construct in the source file.

binaryNode::~binaryNode   [virtual]
 

Destroy a binaryNode.

Warning:
Do not use the destructors to delete AST nodes. Instead, rely on the node garbage collector.


Member Function Documentation

Node * binaryNode::change Changer   the_changer,
bool    redispatch = false
[virtual]
 

Dispatch a Changer.

This abstract method works much the walker, but allows the tree to be changed.

Parameters:
the_changer  the specific Changer object to use.
redispatch  pass true to revisit parts of the tree that have changed.

Reimplemented from Node.

virtual Node* binaryNode::clone   const [inline, virtual]
 

Clone the input node.

This is not a "deep" clone, so be careful. For a deep clone, use the clone_changer class.

Returns:
a shallow copy of the node (no subtrees are copied).

Reimplemented from Node.

void binaryNode::dataflow FlowVal   v,
FlowProblem   fp
[virtual]
 

Run the dataflow analyzer.

Each subclass overrides this method to define it's semantics for dataflow analysis. It alters the input flow value to reflect the effect of the node within the given flow problem, calling dataflow() on it's subtrees as necessary. See the dataflow analysis documentation for more information.

Parameters:
v  the flow value to pass through the node.
fp  the flow problem (specifying the transfer functions).

Reimplemented from Node.

void binaryNode::eval   [virtual]
 

Constant expression evaluator.

This method attempts to evaluate an expression at compile-time. This only yields a meaningful value when the leaves of the given expression are constants, enums, or other compile-time values (e.g., sizeof). The resulting value is stored on each exprNode, in the _value field. Each exprNode sublcass implements this method, calling it recursively when necessary.

Reimplemented from exprNode.

exprNode* binaryNode::get_left   [inline]
 

exprNode* binaryNode::get_right   [inline]
 

void binaryNode::left exprNode   left [inline]
 

exprNode* binaryNode::left   const [inline]
 

void binaryNode::op Operator   op [inline]
 

Operator* binaryNode::op   const [inline]
 

void binaryNode::output_expr output_context   ct,
Node   parent,
int    prec,
Assoc    assoc
[virtual]
 

Output a expression.

Reimplemented from exprNode.

int binaryNode::precedence Assoc   my_assoc [virtual]
 

Associativity and precedence.

Determine the associativity and precedence of the expression. Each exprNode subclass overrides this method to provide the specific results. The default is highest precedence and left-associative.

See also:
exprNode::output_expr() , exprNode::parens()
Parameters:
assoc  a reference parameter that is set to the associativity value
Returns:
the precedence value

Reimplemented from exprNode.

void binaryNode::right exprNode   right [inline]
 

exprNode* binaryNode::right   const [inline]
 

void binaryNode::visit Visitor   the_visitor [virtual]
 

Dispatch a Visitor.

This abstract method is the entry point for the visitor design pattern. Each node subclass defines a visit() method that calls the appropriate at_ method in the visitor. For more information see the Visitor documentation.

Parameters:
the_visitor  the specific Visitor object to use.

Reimplemented from Node.

void binaryNode::walk Walker   the_walker [virtual]
 

Dispatch a Walker.

This abstract method works much like the visitor, but instead walks the entire underlying subtree calling the appropriate at_ method at each node. For more information see the Walker documentation.

Parameters:
the_walker  the specific Walker object to use.

Reimplemented from Node.


Member Data Documentation

TREE exprNode* binaryNode::_left [private]
 

the left expression subtree.

Operator* binaryNode::_op [private]
 

the operator.

The operator object actually resides the Operators table.

See also:
Operator , Operators

TREE exprNode* binaryNode::_right [private]
 

the right expression subtree.


The documentation for this class was generated from the following files:
Generated on Thu Jan 10 12:06:24 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001