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

exprNode Class Reference

Expression node. More...

#include <ast.h>

Inheritance diagram for exprNode::

Node binaryNode callNode castNode commaNode constNode idNode initializerNode metaexprNode ternaryNode unaryNode List of all members.

Public Methods

 exprNode (NodeType typ, typeNode *type, const Coord coord)
 Create a new expression node. More...

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

virtual typeNodebase_type (bool TdefIndir) const
 Return the base data type of a node. More...

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

virtual bool is_lvalue ()
 Is l-value. More...

typeNodeno_tdef_type ()
virtual void output (output_context &ct, Node *par)
 Generate C code. More...

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

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

bool parens (int outer_prec, Assoc outer_assoc)
 Determine if parenthesis are needed. More...

Accessors
Methods to get and set fields in the class.

typeNodetype () const
 Return the node data type. More...

typeNodeget_type ()
void type (typeNode *type)
const constantvalue () const
constantvalue ()
void value (const constant &newval)

Static Public Methods

exprNode * integral_promotions (exprNode *old_expr)
 Add integral promotions. More...

pair< exprNode *, exprNode *> usual_arithmetic_conversions (exprNode *left, exprNode *right)
 Usual arithmetic conversions. More...


Private Attributes

TREE typeNode_type
 the type of the expression. More...

constant _value
 the value of the expression. More...


Detailed Description

Expression node.

This class rovides a base class for all expression nodes. It contains two fields that all expressions have: a type and a value. Initially, both fields are empty, with two exceptions. Constant expression have their values set, and the cast expressions have their type set. We can compute these values for any expression subtree using the appropriate facility. To compute the type of intermediate expressions, use the semcheck_walker. To compute the values of constant expressions, call the eval() method.

The NodeType depends on the specific exprNode subclass.

See also:
semcheck_walker


Constructor & Destructor Documentation

exprNode::exprNode NodeType    typ,
typeNode   type,
const Coord    coord
 

Create a new expression node.

This constructor is only called directly by the exprNode subclasses. The NodeType is determined by the subclass.

Parameters:
typ  the kind of expression node
type  the type of the expression (only for casts) or null
coord  the location of the construct in the source file.

exprNode::~exprNode   [virtual]
 

Destroy a exprNode.

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


Member Function Documentation

typeNode * exprNode::base_type bool    TdefIndir const [virtual]
 

Return the base data type of a node.

This method differs from the Node::type() method in two respects. First, it follows some of the simple type inferences. For example, calling it on an idNode will return the type of its declaration. Second, the boolean argument indicates whether or not to follow typedef links.

Parameters:
TdefIndir  pass true to follow typedefs to their definitions.

Reimplemented from Node.

Reimplemented in idNode, commaNode, and callNode.

virtual void exprNode::eval   [pure 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 in constNode, idNode, binaryNode, unaryNode, castNode, commaNode, ternaryNode, callNode, initializerNode, and metaexprNode.

typeNode* exprNode::get_type   [inline]
 

exprNode * exprNode::integral_promotions exprNode *    old_expr [static]
 

Add integral promotions.

This method takes an expression and calls typeNode::integral_promotions() on its type to determine if any apply. If they do, it inserts an implicit castNode above the input expression that represents this implicit conversion.

See also:
castNode
Parameters:
old_expr  the expression to perform integral promotion on
Returns:
the resulting expression, with a cast added if necessary

virtual bool exprNode::is_lvalue   [inline, virtual]
 

Is l-value.

Indicates if the expression is an l-value (that is, the left side of an assignment).

Todo:
This doesn't work yet.

Returns:
true if the given expression is an l-value

typeNode* exprNode::no_tdef_type   [inline]
 

void exprNode::output output_context   ct,
Node   parent
[virtual]
 

Generate C code.

Each subclass overrides this method to define how to produce the output C code. To use this method, pass an output_context and a null parent.

Parameters:
ct  the output context which describes the formatting.
par  the parent node (or null, if at the top of a subtree).

Reimplemented from Node.

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

Output a expression.

Reimplemented in constNode, idNode, binaryNode, unaryNode, castNode, commaNode, ternaryNode, callNode, initializerNode, and metaexprNode.

bool exprNode::parens int    outer_prec,
Assoc    outer_assoc
 

Determine if parenthesis are needed.

This method takes the associativity and precedence values of the enclosing expression and determines if parentheses are needed.

See also:
exprNode::output_expr() , exprNode::precedence()
Parameters:
outer_prec  the precedence value of the enclosing expression
outer_assoc  the associativity value of the enclosing expression
Returns:
true if parentheses are needed.

int exprNode::precedence Assoc   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 in binaryNode, unaryNode, castNode, commaNode, and ternaryNode.

void exprNode::type typeNode   type [inline]
 

typeNode* exprNode::type   const [inline, virtual]
 

Return the node data type.

This method returns the C data type of a node. Several different kinds of nodes contain typeNode pointers. This method is just a unified way to access them. It does not attempt to compute the type, it just returns whatever typeNode pointer resides on the node. The subclasses that have types return them, and the others return null.

Returns:
the typeNode pointer on the node.

Reimplemented from Node.

pair< exprNode *, exprNode *> exprNode::usual_arithmetic_conversions exprNode *    left,
exprNode *    right
[static]
 

Usual arithmetic conversions.

This method takes two expressions and adds any casts that are necessary to make them compatible for arithmetic operations. It calls typeNode::usual_arithmetic_conversions(), passing the types of the expressions, to determine when the casts are needed. It inserts implicit castNode objects above the expressions for the casts.

See also:
castNode
Parameters:
left  the left-hand expression
right  the right-hand expression
Returns:
the left and right expressions, possibly with casts added

void exprNode::value const constant   newval [inline]
 

constant& exprNode::value   [inline]
 

const constant& exprNode::value   const [inline]
 


Member Data Documentation

TREE typeNode* exprNode::_type [private]
 

the type of the expression.

This field is only populated by calling the semcheck_walker.

constant exprNode::_value [private]
 

the value of the expression.

This field is only populated by calling the eval() method. For non-constant expressions, the result may be a special "no val" value.

See also:
constant::no_val()


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