expression Class Reference

#include <expression.h>

Inheritance diagram for expression:

expression_addition expression_address expression_array_index expression_assignment expression_boolean expression_cast expression_char expression_check_range expression_dereference expression_eq expression_error expression_function expression_function_call expression_ge expression_gt expression_inc expression_indirect_store expression_integer expression_integer_division expression_ixp expression_ldl expression_ldo expression_le expression_load expression_load_address expression_lod expression_logical_and expression_logical_not expression_logical_or expression_lt expression_multiplication expression_name expression_ne expression_negate expression_real expression_real_division expression_real_from_integer expression_sas expression_set expression_set2set expression_set_difference expression_set_intersection expression_set_union expression_sgs expression_sizeof_expression expression_sizeof_type expression_sro expression_srs expression_stl expression_store expression_str expression_string expression_subtraction expression_uptr2pptr List of all members.

Public Types

enum  side_effect_t { side_effect_no, side_effect_partial, side_effect_yes }
typedef expression_smart_pointer pointer

Public Member Functions

virtual void traversal (int pprec)=0
virtual void logical_traversal (int pprec, label::pointer &true_branch, label::pointer &false_branch, bool fall_through_preference)=0
virtual int get_precedence () const=0
virtual type::pointer get_type () const=0
const locationget_location () const
void set_location (const location &where)
virtual bool is_lvalue () const=0
virtual expression::pointer assignment_expression_factory (const expression::pointer &rhs) const
virtual expression::pointer function_call_expression_factory (expression_list *args)
virtual expression::pointer dot_expression_factory (const symbol *rhs)
virtual expression::pointer array_index_expression_factory (const expression::pointer &rhs) const
virtual expression::pointer strip_indirection () const
virtual side_effect_t has_side_effect () const=0
void reference_count_up ()
void reference_count_down ()
virtual bool is_constant () const
virtual bool execution_flows_out () const
virtual expression::pointer optimize () const=0
bool get_boolean_value () const
virtual long get_integer_value () const
double get_real_value () const
rcstring get_string_value () const
virtual const symbolget_symbol_hint () const
bool is_error () const

Protected Types

enum  {
  prec_comma = 2, prec_assign = 4, prec_quest = 6, prec_or = 8,
  prec_and = 10, prec_bit_or = 12, prec_bit_xor = 14, prec_bit_and = 16,
  prec_eq = 18, prec_rel = 20, prec_shift = 22, prec_add = 24,
  prec_mul = 26, prec_unary = 28, prec_paren = 30, prec_id = 99
}

Protected Member Functions

virtual ~expression ()
 expression (const location &locn)
bool need_parens (int pprec, int cprec)
bool need_parens (int pprec)
expression::pointer self () const

Private Member Functions

bool reference_count_valid () const
 expression ()
 expression (const expression &)
expressionoperator= (const expression &)

Private Attributes

long reference_count
location loc

Detailed Description

The abstract expression base class is used to represent any type of expression.

Definition at line 37 of file expression.h.


Member Typedef Documentation

typedef expression_smart_pointer expression::pointer

The pointer type is to be used for all pointers to statements. It guarantees correct reference counted storage management.

Definition at line 44 of file expression.h.


Member Enumeration Documentation

enum expression::side_effect_t

Enumerator:
side_effect_no 
side_effect_partial 
side_effect_yes 

Definition at line 206 of file expression.h.

anonymous enum [protected]

Enumerator:
prec_comma 
prec_assign 
prec_quest 
prec_or 
prec_and 
prec_bit_or 
prec_bit_xor 
prec_bit_and 
prec_eq 
prec_rel 
prec_shift 
prec_add 
prec_mul 
prec_unary 
prec_paren 
prec_id 

Definition at line 322 of file expression.h.


Constructor & Destructor Documentation

virtual expression::~expression (  )  [protected, virtual]

The destructor.

This is private on purpose. You must always go via the reference_count_down method.

expression::expression ( const location locn  )  [protected]

The constructor.

Parameters:
locn the source code location of the expression.

expression::expression (  )  [private]

The default constructor.

expression::expression ( const expression  )  [private]

The copy constructor. Do not use.


Member Function Documentation

virtual void expression::traversal ( int  pprec  )  [pure virtual]

The traversal method may be used to traverse each of the declaractions in the list.

Parameters:
pprec The precedence of the parent expression node.

Implemented in expression_addition, expression_assignment, expression_dereference, expression_eq, expression_error, expression_function_call, expression_ge, expression_gt, expression_integer_division, expression_le, expression_logical_and, expression_logical_not, expression_logical_or, expression_lt, expression_multiplication, expression_ne, expression_negate, expression_real_division, expression_real_from_integer, expression_set2set, expression_sgs, expression_srs, expression_subtraction, expression_address_global, expression_address_intermediate, expression_address_local, expression_boolean_compile, expression_cast, expression_char_compile, expression_check_range, expression_function, expression_inc, expression_indirect_store, expression_integer_compile, expression_ixp, expression_ldl, expression_ldo, expression_load_bogus, expression_load_indirect, expression_load_indirect_packed, expression_load_local, expression_load_address, expression_lod, expression_name_compile, expression_real_compile, expression_sas, expression_set_compile, expression_set_difference, expression_set_intersection, expression_set_union, expression_sro, expression_stl, expression_store, expression_str, expression_string_compile, expression_uptr2pptr, expression_array_index, expression_boolean_pretty, expression_char_pretty, expression_integer_pretty, expression_name_pretty, expression_real_pretty, expression_set_pretty, expression_sizeof_expression, expression_sizeof_type, and expression_string_pretty.

virtual void expression::logical_traversal ( int  pprec,
label::pointer true_branch,
label::pointer false_branch,
bool  fall_through_preference 
) [pure virtual]

The logical_traversal method is used to traverse an expression, with the intention of using to to implement a logical condition, as would be found for an "if" statement or a "for" statement, etc.

Parameters:
pprec The precedence of the parent expression node.
true_branch Where to branch to if the expression is true
false_branch Where to branch to if the expression is false
fall_through_preference This is true if true expressions should fall out the bottom, rather than branch to the true_branch. This is false if false expressions should fall out the bottom, rather than branch to the false_branch.
Note:
The default implementation simply calls the traversal method. Compilers implementing short-circuit boolean evaluation will need to impliment this more completely.

virtual int expression::get_precedence (  )  const [pure virtual]

The get_precedence method is used to obtain the precedence of this expression node.

The highest precedence has the highest absolute value, the lowest precedence gets the lowest absolute value.

Implemented in expression_addition, expression_assignment, expression_boolean, expression_char, expression_dereference, expression_eq, expression_error, expression_function_call, expression_ge, expression_gt, expression_integer, expression_integer_division, expression_le, expression_logical_and, expression_logical_not, expression_logical_or, expression_lt, expression_multiplication, expression_name, expression_ne, expression_negate, expression_real, expression_real_division, expression_real_from_integer, expression_set, expression_set2set, expression_sgs, expression_srs, expression_string, expression_subtraction, expression_address, expression_cast, expression_check_range, expression_function, expression_inc, expression_indirect_store, expression_ixp, expression_ldl, expression_ldo, expression_load, expression_load_address, expression_lod, expression_sas, expression_set_difference, expression_set_intersection, expression_set_union, expression_sro, expression_stl, expression_store, expression_str, expression_uptr2pptr, expression_array_index, expression_sizeof_expression, and expression_sizeof_type.

virtual type::pointer expression::get_type (  )  const [pure virtual]

The get_type method is used to get the type of this expression.

Implemented in expression_addition, expression_assignment, expression_boolean, expression_char, expression_dereference, expression_eq, expression_error, expression_function_call, expression_ge, expression_gt, expression_integer, expression_integer_division, expression_le, expression_logical_and, expression_logical_not, expression_logical_or, expression_lt, expression_multiplication, expression_name, expression_ne, expression_negate, expression_real, expression_real_division, expression_real_from_integer, expression_set, expression_set2set, expression_sgs, expression_srs, expression_string, expression_subtraction, expression_addition_address, expression_address, expression_cast, expression_check_range, expression_function, expression_function_call_chr, expression_function_call_odd, expression_function_call_sqr, expression_function_call_time, expression_function_call_user_defined, expression_inc, expression_indirect_store, expression_integer_compile_enumerated, expression_ixp, expression_ldl, expression_ldo, expression_load, expression_load_address, expression_lod, expression_sas, expression_set_difference, expression_set_intersection, expression_set_union, expression_sro, expression_stl, expression_store, expression_str, expression_uptr2pptr, expression_array_index, expression_name_pretty, expression_sizeof_expression, and expression_sizeof_type.

const location& expression::get_location (  )  const [inline]

The get_location method is used to obtain the location of the expression.

Definition at line 107 of file expression.h.

References loc.

void expression::set_location ( const location where  ) 

The set_location method is used to set the location of the expression.

Note:
Use sparingly. Abuse has the potential to completely confuse the user.

virtual bool expression::is_lvalue (  )  const [pure virtual]

The is_lvalue method is used to determine whether or not this expression is suitable to appear on the left hand side of an assignment expression.

Implemented in expression_addition, expression_assignment, expression_boolean, expression_char, expression_dereference, expression_eq, expression_error, expression_function_call, expression_ge, expression_gt, expression_integer, expression_integer_division, expression_le, expression_logical_and, expression_logical_not, expression_logical_or, expression_lt, expression_multiplication, expression_name, expression_ne, expression_negate, expression_real, expression_real_division, expression_real_from_integer, expression_set, expression_set2set, expression_sgs, expression_srs, expression_string, expression_subtraction, expression_address, expression_cast, expression_check_range, expression_function, expression_inc, expression_indirect_store, expression_ixp, expression_ldl, expression_ldo, expression_load, expression_load_address, expression_lod, expression_sas, expression_set_difference, expression_set_intersection, expression_set_union, expression_sro, expression_stl, expression_store, expression_str, expression_uptr2pptr, expression_array_index, expression_sizeof_expression, and expression_sizeof_type.

virtual expression::pointer expression::assignment_expression_factory ( const expression::pointer rhs  )  const [virtual]

The assignment_expression_factory method is used by the assignment_expression method to build an assignment expression node.

The default implementation prints and error saying that the left hand side of the assignment is inappropriate.

Parameters:
rhs The right hand side of the assignment ("this" is the left hand side).
Note:
The parser will delete this expression tree once the assignment tree has been manufactored. If you wish to keep using this tree, you will need to self() it.

Reimplemented in expression_function, expression_load_bogus, expression_load_indirect, expression_load_indirect_packed, and expression_name_pretty.

virtual expression::pointer expression::function_call_expression_factory ( expression_list args  )  [virtual]

The function_call_expression_factory method is used by the function_call_expression method to build a function call expression node.

The default implementation prints and error saying that the left hand side of the function_call is inappropriate.

Parameters:
args All of the arguments of the function call, including the function name as the first argument (usually [0] == this).
Note:
The parser will delete this expression tree once the function_call tree has been manufactured. If you wish to keep using this tree, you will need to self() it.

Reimplemented in expression_error, expression_name, and expression_function.

virtual expression::pointer expression::dot_expression_factory ( const symbol rhs  )  [virtual]

The dot_expression_factory method is used to build a record member reference expression.

The default implementation prints and error saying that the left hand side of the dot is inappropriate.

Parameters:
rhs The symbol information corresponding to the member to access
Returns:
pointer to an expression node

Reimplemented in expression_load_indirect.

virtual expression::pointer expression::array_index_expression_factory ( const expression::pointer rhs  )  const [virtual]

The array_index_expression_factory method is used to build an array index expression.

The default implementation prints and error saying that the left hand side of the array index expression is inappropriate.

Parameters:
rhs The value of the array element to be indexed
Returns:
pointer to an expression node

Reimplemented in expression_load_indirect, and expression_name_pretty.

virtual expression::pointer expression::strip_indirection (  )  const [virtual]

The strip_indirection method is used to obtain the address expression of an abstract indirection expression. This is used to pass variables by reference to functions and procedures.

The default implementation returns a NULL pointer, because the error has to be printer by the caller.

Reimplemented in expression_load_bogus, expression_load_indirect, and expression_load_indirect_packed.

virtual side_effect_t expression::has_side_effect (  )  const [pure virtual]

The has_side_effect method is used to determine if an expression has any effect. It is used by the parse to produce "statement with no effect" warnings.

Implemented in expression_addition, expression_assignment, expression_boolean, expression_char, expression_dereference, expression_eq, expression_error, expression_function_call, expression_ge, expression_gt, expression_integer, expression_integer_division, expression_le, expression_logical_and, expression_logical_not, expression_logical_or, expression_lt, expression_multiplication, expression_name, expression_ne, expression_negate, expression_real, expression_real_division, expression_real_from_integer, expression_set, expression_set2set, expression_sgs, expression_srs, expression_string, expression_subtraction, expression_address, expression_cast, expression_check_range, expression_function, expression_inc, expression_indirect_store, expression_ixp, expression_ldl, expression_ldo, expression_load, expression_load_address, expression_lod, expression_sas, expression_set_difference, expression_set_intersection, expression_set_union, expression_sro, expression_stl, expression_store, expression_str, expression_uptr2pptr, expression_array_index, expression_sizeof_expression, and expression_sizeof_type.

void expression::reference_count_up (  ) 

The reference_count_up method is used to increase the number of references to this.

void expression::reference_count_down (  ) 

The reference_count_up method is used to decrease the number of references to this. If the count gets too low, we delete outself.

virtual bool expression::is_constant (  )  const [virtual]

The is_constant method may be used to determine whether this expression node is a constant, or this tree would evaluate to a constant.

The default implementation is conservative, and always returns false.

Returns:
bool; true if constant, false if not.

Reimplemented in expression_addition, expression_boolean, expression_char, expression_eq, expression_ge, expression_gt, expression_integer, expression_integer_division, expression_le, expression_lt, expression_multiplication, expression_ne, expression_negate, expression_real, expression_real_division, expression_real_from_integer, expression_set, expression_string, expression_subtraction, expression_address_global, expression_address_intermediate, and expression_address_local.

virtual bool expression::execution_flows_out (  )  const [virtual]

The execution_flows_out method is used to determine whether an expression ever finished executing. This is usually true (and the default implimentation returns true) but some functions (the halt function, for example) do not.

virtual expression::pointer expression::optimize (  )  const [pure virtual]

The optimize method may be used to evaluate constant expressions, or substitute more efficient expressions.

This is intended to be called by the translator:: expression_statement method, or similar, where the expression is in its final form, and will get no deeper. In other words, when all available information has been provided.

There is no default implementation, even though most optimize implementations return self(), because this gives the compiler no opportunity to remind the authors of new classes that they have forgotten something.

Returns:
If the expression tree is not constant, or it is already as reduced as it can get, it returns itself. Otherwise, it returns a new expression node.

Implemented in expression_error, expression_set, expression_addition_address, expression_addition_integer, expression_addition_real, expression_address, expression_assignment_compile, expression_boolean_compile, expression_cast, expression_char_compile, expression_check_range, expression_eq_boolean, expression_eq_integer, expression_eq_real, expression_eq_string, expression_function, expression_function_call_chr, expression_function_call_odd, expression_function_call_sqr, expression_function_call_time, expression_function_call_user_defined, expression_ge_boolean, expression_ge_integer, expression_ge_real, expression_ge_string, expression_gt_boolean, expression_gt_integer, expression_gt_real, expression_gt_string, expression_inc, expression_indirect_store, expression_integer_compile, expression_integer_division_compile, expression_ixp, expression_ldl, expression_ldo, expression_le_boolean, expression_le_integer, expression_le_real, expression_le_string, expression_load_bogus, expression_load_indirect, expression_load_indirect_packed, expression_load_address, expression_lod, expression_logical_and_compile, expression_logical_not_compile, expression_logical_or_compile, expression_lt_boolean, expression_lt_integer, expression_lt_real, expression_lt_string, expression_multiplication_integer, expression_multiplication_real, expression_name_compile, expression_ne_boolean, expression_ne_integer, expression_ne_real, expression_ne_string, expression_negate_integer, expression_negate_real, expression_real_compile, expression_real_division_compile, expression_real_from_integer_compile, expression_sas, expression_set2set_compile, expression_set_difference, expression_set_intersection, expression_set_union, expression_sgs_compile, expression_sro, expression_srs_compile, expression_stl, expression_store_indirect, expression_store_indirect_packed, expression_str, expression_string_compile, expression_subtraction_integer, expression_subtraction_real, expression_uptr2pptr, expression_addition_pretty, expression_array_index, expression_assignment_pretty, expression_boolean_pretty, expression_char_pretty, expression_dereference_pretty, expression_eq_pretty, expression_function_call_pretty, expression_ge_pretty, expression_gt_pretty, expression_integer_pretty, expression_integer_division_pretty, expression_le_pretty, expression_logical_and_pretty, expression_logical_not_pretty, expression_logical_or_pretty, expression_lt_pretty, expression_multiplication_pretty, expression_name_pretty, expression_ne_pretty, expression_negate_pretty, expression_real_pretty, expression_real_division_pretty, expression_real_from_integer_pretty, expression_set2set_pretty, expression_sgs_pretty, expression_sizeof_expression, expression_sizeof_type, expression_srs_pretty, expression_string_pretty, and expression_subtraction_pretty.

bool expression::get_boolean_value (  )  const

The get_boolean_value method is used to obtain the boolean value of an expression node. It is an error, and the results are undefined (probably plays electro punk music), if this is not a constant boolean expression node.

virtual long expression::get_integer_value (  )  const [virtual]

The get_integer_value method is used to obtain the integer value of an expression node. It is an error, and the results are undefined (probably rm -rf or worse), if this is not a constant integer expression node.

Reimplemented in expression_boolean, expression_char, and expression_integer.

double expression::get_real_value (  )  const

The get_real_value method is used to obtain the real value of an expression node. It is an error, and the results are undefined (probably downloads porn), if this is not a constant real expression node.

rcstring expression::get_string_value (  )  const

The get_string_value method is used to obtain the string value of an expression node. It is an error, and the results are undefined (probably reboots into windows), if this is not a constant string expression node.

virtual const symbol* expression::get_symbol_hint (  )  const [virtual]

The get_symbol_hint method is used to get the symbol associated with the expression.

Returns:
pointer to a symbol, or NULL if there is no hint present

Reimplemented in expression_addition_address, expression_address_global, expression_address_intermediate, expression_address_local, expression_check_range, expression_inc, expression_load_indirect, and expression_load_indirect_packed.

bool expression::is_error (  )  const

The is_error method is used to determine whether or not this expression is an error (and that the error has already been reported).

bool expression::need_parens ( int  pprec,
int  cprec 
) [protected]

The need_parens function is used to calculate whether or not parentheses are required.

Parameters:
pprec The parent node prececence
cprec The child node precedence

bool expression::need_parens ( int  pprec  )  [protected]

The need_parens function is used to calculate whether or not parentheses are required.

Parameters:
pprec The parent node prececence

expression::pointer expression::self (  )  const [protected]

The self method is used to obtain a second logical copy of ourself. It isn't actually a copy, it just bumps the reference count, so the operating is very quick.

bool expression::reference_count_valid (  )  const [inline, private]

The reference_count_valid method is used to esablish that the reference count is valid. Use mostly for debugging, via assert.

Definition at line 388 of file expression.h.

References reference_count.

expression& expression::operator= ( const expression  )  [private]

The assignment operator. Do not use.


Member Data Documentation

long expression::reference_count [private]

The reference_count instance variable is used to remember how many references to this object currently exist.

Definition at line 382 of file expression.h.

Referenced by reference_count_valid().

location expression::loc [private]

The loc instance variable is used to remember the location of the expression.

Definition at line 394 of file expression.h.

Referenced by get_location().


The documentation for this class was generated from the following file:
Generated on Sun Feb 25 01:27:11 2007 for UCSDp-SystemCrossCompiler by  doxygen 1.5.1