#include <ast.h>
Inheritance diagram for exprNode::
Public Methods | |
exprNode (NodeType typ, typeNode *type, const Coord coord) | |
Create a new expression node. More... | |
virtual | ~exprNode () |
Destroy a exprNode. More... | |
virtual typeNode * | base_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... | |
typeNode * | no_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. | |
typeNode * | type () const |
Return the node data type. More... | |
typeNode * | get_type () |
void | type (typeNode *type) |
const constant & | value () const |
constant & | value () |
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... |
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.
|
Create a new expression node. This constructor is only called directly by the exprNode subclasses. The NodeType is determined by the subclass.
|
|
Destroy a exprNode.
|
|
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.
Reimplemented from Node. |
|
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. |
|
|
|
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.
|
|
Is l-value. Indicates if the expression is an l-value (that is, the left side of an assignment).
|
|
|
|
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.
Reimplemented from Node. |
|
Output a expression.
Reimplemented in constNode, idNode, binaryNode, unaryNode, castNode, commaNode, ternaryNode, callNode, initializerNode, and metaexprNode. |
|
Determine if parenthesis are needed. This method takes the associativity and precedence values of the enclosing expression and determines if parentheses are needed.
|
|
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.
Reimplemented in binaryNode, unaryNode, castNode, commaNode, and ternaryNode. |
|
|
|
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.
Reimplemented from Node. |
|
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.
|
|
|
|
|
|
|
|
the type of the expression. This field is only populated by calling the semcheck_walker. |
|
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.
|