coolray.org FAQ Contact Us
CoolRay Banner
CoolRay / Documentation
Main Page   Class Hierarchy   Compound List   Compound Members   Related Pages  

Expression Class Reference

The class Expression is the base for expression code generation. More...

#include <Expression.h>

Inheritance diagram for Expression

Inheritance graph
[legend]
List of all members.

Public Methods

virtual ~Expression ()
virtual void GenerateCode (Assembler *pAssembler,bool lvalue)=0
 Generate the virtual machine code. More...

virtual bool freeRegister ()const
 Query if the register returned by GenerateCode must be freed. More...

virtual Expression* optimizeConstants ()
 Optimize and evaluate constant expressions.

virtual Type getResultType ()=0
virtual bool isConstant ()=0

Detailed Description

The class Expression is the base for expression code generation.

It it is used internally by the Parser to generate code for all expressions. The class also allows a constant optimization scene to be applied.


Member Function Documentation

void Expression::GenerateCode ( Assembler * pAssembler,
bool lvalue ) [pure virtual]
 

Generate the virtual machine code.

Implement this method to generate the needed code for a concrete Expression object.

Parameters:
pAssembler   the assembler helping by code generation
lvalue   true - if the expression is a lvalue false - otherwise (rvalue)

if rvalue then the result is put on top of the stack and the caller has to consume this element if lvalue then the top of stack is consumed (removed from the stack)

bool Expression::freeRegister ( ) const [virtual]
 

Query if the register returned by GenerateCode must be freed.

For almost all Expression nodes freeRegister always returns true, which means the return register is temporarly allocated. Therefore it must be freed by the caller of GenerateCode. In some rare cases a register is allocated permenently in a scope (e.g. this), and freeRegister will return false. The use of this 'switch' allows generation of much more efficent code.

Returns:
true - if register obtained by GenerateCode should be freed false - if register obtained by GenerateCode shouldn't be freed


The documentation for this class was generated from the following file:
  • Expression.h
You are visitor No.

counter

Copyright (c) 2001 Stefan Michel, All Rights Reserved.
Last modified: