coins.cfront
Class Evaluator

java.lang.Object
  extended bycoins.cfront.Evaluator
All Implemented Interfaces:
TokenId, TypeId

class Evaluator
extends java.lang.Object
implements TokenId, TypeId

Evaluator computes constant expressions. All integer constants are processed as long int values.


Field Summary
(package private)  int[] toSize
           
 
Fields inherited from interface coins.ast.TokenId
AND_E, ANDAND, ARROW, ASM, AUTO, BAD_TOKEN, BREAK, CASE, CAST_OP, CHAR, CHAR_CONST, COND_OP, CONST, CONTINUE, DEFAULT, DIV_E, DO, DOUBLE, DOUBLE_CONST, ELLIPSIS, ELSE, ENUM, EOF, EQ, EXOR_E, EXTERN, FLOAT, FLOAT_CONST, FOR, FUNCALL, GE, GOTO, IDENTIFIER, IF, IGNORE, INDEX_OP, INLINE, INT, INT_CONST, LE, LONG, LONG_CONST, LONG_DOUBLE_CONST, LONGLONG_CONST, LSHIFT, LSHIFT_E, MINUS_E, MINUSMINUS, MOD_E, MUL_E, MUTABLE, NEQ, OR_E, OROR, PLUS_E, PLUSPLUS, PRAGMA, REGISTER, RESTRICT, RETURN, RSHIFT, RSHIFT_E, SHORT, SIGNED, SIZEOF, SKIP_GCC_ASM, SKIP_GCC_ATTRIBUTE, STATIC, STRING_L, STRING_WL, STRUCT, SWITCH, TYPEDEF, TYPEDEF_NAME, UINT_CONST, ULONG_CONST, ULONGLONG_CONST, UNION, UNSIGNED, VOID, VOLATILE, WHILE
 
Fields inherited from interface coins.ast.TypeId
ARRAY_T, CHAR_T, CONST_T, DOUBLE_T, ELLIPSIS_T, ENUM_BEGIN, ENUM_END, FLOAT_T, FUNCTION_T, INT_T, LONG_DOUBLE_T, LONG_LONG_T, LONG_T, NO_DIMENSION_T, OFFSET_T, POINTER_T, RESTRICT_T, RETURN_T, S_AUTO, S_EXTERN, S_INLINE, S_NONE, S_REGISTER, S_STATIC, SHORT_T, SIGNED_T, SIZE_T, STRUCT_BEGIN, STRUCT_END, UNION_BEGIN, UNION_END, UNSIGNED_T, VOID_T, VOLATILE_T
 
Constructor Summary
Evaluator(MachineParam mp)
           
 
Method Summary
 ConstantExpr applyBinaryOp(Lex lex, ConstantExpr expr1, int op, ConstantExpr expr2)
          Constant folding for arithmetic binary expression.
 ConstantExpr applyUnaryOp(Lex lex, int op, ConstantExpr expr)
          Constant folding for arithmetic unary expression.
 ConstantExpr cast(Lex lex, ConstantExpr expr, EncodedType etype)
          Do constant folding by casting the constant expression expr to the type shown by etype.
 ConstantExpr make(double value)
           
 ConstantExpr make(double value, byte[] type)
           
 ConstantExpr make(double value, char type)
          Make floating constant expression.
 ConstantExpr make(double value, EncodedType type)
           
 ConstantExpr make(long value)
           
 ConstantExpr make(long value, byte[] type)
           
 ConstantExpr make(long value, char sign, char type)
          Make integer constant expression.
 ConstantExpr make(long value, EncodedType type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toSize

final int[] toSize
Constructor Detail

Evaluator

public Evaluator(MachineParam mp)
Method Detail

make

public ConstantExpr make(long value)

make

public ConstantExpr make(long value,
                         byte[] type)

make

public ConstantExpr make(long value,
                         EncodedType type)

make

public ConstantExpr make(long value,
                         char sign,
                         char type)
Make integer constant expression. If the precision of "type" is less than 64, upper bits are filled by sign extension (if "sign" is S) or 0-extension (if "sign" is U).

Returns:
Constant expression.

make

public ConstantExpr make(double value)

make

public ConstantExpr make(double value,
                         byte[] type)

make

public ConstantExpr make(double value,
                         EncodedType type)

make

public ConstantExpr make(double value,
                         char type)
Make floating constant expression. (How to adjust precision according to "type" ?)

Returns:
Constant expression.

cast

public ConstantExpr cast(Lex lex,
                         ConstantExpr expr,
                         EncodedType etype)
                  throws ParseError
Do constant folding by casting the constant expression expr to the type shown by etype.

Returns:
Constant expression.
Throws:
ParseError

applyUnaryOp

public ConstantExpr applyUnaryOp(Lex lex,
                                 int op,
                                 ConstantExpr expr)
                          throws ParseError
Constant folding for arithmetic unary expression.

Returns:
Constant expression.
Throws:
ParseError

applyBinaryOp

public ConstantExpr applyBinaryOp(Lex lex,
                                  ConstantExpr expr1,
                                  int op,
                                  ConstantExpr expr2)
                           throws ParseError
Constant folding for arithmetic binary expression.

Returns:
Constant expression.
Throws:
ParseError