Builder Class Reference

Inheritance diagram for Builder:

Inheritance graph
[legend]
Collaboration diagram for Builder:

Collaboration graph
[legend]

List of all members.


Detailed Description

see IBuilder interface documentation

Definition at line 37 of file builder.cc.


Public Member Functions

 Builder (Vm *)
virtual ~Builder ()
virtual bool hasError () const
virtual void errorDetected ()
 called if error is detected
virtual void glVar (EToken type, Token id)
 define global variable
virtual void fncDeclInit (EToken type, Token id)
 fnc decl detected
virtual void fncDeclArg (EToken type)
 fnc decl arg
virtual void fncDecl ()
 fnc decl complete
virtual void fncDefInit (EToken type, Token id)
 fnc def detected
virtual void fncDefArg (EToken type, Token id)
 fnc def arg
virtual void fncDefVar (EToken type, Token id)
 fnc local variable
virtual void fncDefBody ()
 fnc body
virtual void fncDef ()
 fnc def complete
virtual void assign (Token token)
 assign command
virtual void ifEnter (Token token)
 if statement, if part
virtual void ifElse ()
 if statement, else part
virtual void ifLeave ()
 if statement complete
virtual void whileInit (Token token)
 while, B_EXPR follows
virtual void whileEnter ()
 while, CMD_LIST follows
virtual void whileLeave ()
 while statement complete
virtual void pushToken (Token token)
 push token
virtual void evalUnOp (Token token)
 eval unary operator
virtual void evalBinOp (Token token)
 eval binary operator
virtual void fncCall (Token id, int argsToPop, bool pushResult)
virtual void fncCallPrint (Token id, EToken valType)

Private Types

typedef TBlockTBlockStack
typedef Value::VTypeTTypeStack

Private Member Functions

PVar createVar (EToken type, Token id)
 common code for variable creation
bool appendCmd (PCmd)
 append given command to current stack top
bool chkBlockStack ()
 return true if stack is not empty, print error otherwise
void pushTypeToStack (Value::VType)
 push type to stack
Value::VType popTypeFromStack (const Token &)
 pop type from stack, V_NULL if empty
void chkTypeOnTop (Value::VType type, const Token &)
 pop type from stack and compare with given type

Private Attributes

Vmvm_
 virtual machine being built
bool hasError_
 true if any error occurred
FncDeclarationfncDecl_
 pointer to declaration being built, or 0 if not building declaration
FncDefinitionfncDef_
 pointer to definition being built, or 0 if not building definition
CmdFactory cmdFactory_
 common factory for virtual machine commands creation
TBlockStack blockStack_
 stack for blocks of commands
TTypeStack typeStack_
 stack for expression types

Classes

struct  TBlock

Member Typedef Documentation

typedef TBlock* TBlockStack [private]

Definition at line 72 of file builder.cc.

typedef Value::VType* TTypeStack [private]

Definition at line 75 of file builder.cc.


Constructor & Destructor Documentation

Builder ( Vm vm  ) 

Definition at line 94 of file builder.cc.

Referenced by BuilderFactory::createBuilder().

Here is the caller graph for this function:

~Builder (  )  [virtual]

Definition at line 103 of file builder.cc.

References fncDecl_, and fncDef_.


Member Function Documentation

virtual bool hasError (  )  const [inline, virtual]

Return true if any error was detected.

Implements IErrorSensitive.

Definition at line 41 of file builder.cc.

References hasError_.

void errorDetected (  )  [virtual]

called if error is detected

Implements IBuilder.

Definition at line 108 of file builder.cc.

References blockStack_, fncDecl_, fncDef_, and hasError_.

void glVar ( EToken  type,
Token  id 
) [virtual]

define global variable

Implements IBuilder.

Definition at line 118 of file builder.cc.

References VarSet::add(), createVar(), Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, Vm::fileName, hasError_, Token::lineno, and vm_.

Here is the call graph for this function:

void fncDeclInit ( EToken  type,
Token  id 
) [virtual]

fnc decl detected

Implements IBuilder.

Definition at line 133 of file builder.cc.

References createVar(), StreamDecorator::E_WARNING, Vm::fileName, fncDecl_, and vm_.

Here is the call graph for this function:

void fncDeclArg ( EToken  type  )  [virtual]

fnc decl arg

Implements IBuilder.

Definition at line 147 of file builder.cc.

References VarSet::add(), FncDeclaration::args, createVar(), StreamDecorator::E_WARNING, Vm::fileName, fncDecl_, and vm_.

Here is the call graph for this function:

void fncDecl (  )  [virtual]

fnc decl complete

Implements IBuilder.

Definition at line 159 of file builder.cc.

References FncSet::addDeclaration(), Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, Vm::fileName, fncDecl_, FncSet::getDeclaration(), hasError_, Token::lineno, FncDeclaration::self, and vm_.

Here is the call graph for this function:

void fncDefInit ( EToken  type,
Token  id 
) [virtual]

fnc def detected

Implements IBuilder.

Definition at line 177 of file builder.cc.

References createVar(), StreamDecorator::E_WARNING, Vm::fileName, fncDef_, and vm_.

Here is the call graph for this function:

void fncDefArg ( EToken  type,
Token  id 
) [virtual]

fnc def arg

Implements IBuilder.

Definition at line 191 of file builder.cc.

References VarSet::add(), FncDeclaration::args, createVar(), Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, StreamDecorator::E_WARNING, Vm::fileName, fncDef_, hasError_, Token::lineno, Var::name, FncDeclaration::self, and vm_.

Here is the call graph for this function:

void fncDefVar ( EToken  type,
Token  id 
) [virtual]

fnc local variable

Implements IBuilder.

Definition at line 218 of file builder.cc.

References VarSet::add(), FncDeclaration::args, createVar(), Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, StreamDecorator::E_WARNING, Vm::fileName, fncDef_, hasError_, Token::lineno, Var::name, FncDeclaration::self, FncDefinition::vars, and vm_.

Here is the call graph for this function:

void fncDefBody (  )  [virtual]

fnc body

Implements IBuilder.

Definition at line 256 of file builder.cc.

References FncSet::addDeclaration(), blockStack_, FncDefinition::cmdList, Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, StreamDecorator::E_WARNING, Vm::fileName, fncDef_, FncSet::getDeclaration(), FncSet::getDefinition(), hasError_, Token::lineno, FncDeclaration::self, and vm_.

Here is the call graph for this function:

void fncDef (  )  [virtual]

fnc def complete

Implements IBuilder.

Definition at line 293 of file builder.cc.

References FncSet::addDefinition(), blockStack_, chkBlockStack(), Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_WARNING, Vm::fileName, fncDef_, hasError_, FncDeclaration::self, and vm_.

Here is the call graph for this function:

void assign ( Token  token  )  [virtual]

assign command

Implements IBuilder.

Definition at line 312 of file builder.cc.

References appendCmd(), chkTypeOnTop(), cmdFactory_, CmdFactory::createAssign(), StreamDecorator::E_WARNING, Vm::fileName, fncDef_, and vm_.

Here is the call graph for this function:

void ifEnter ( Token  token  )  [virtual]

if statement, if part

Implements IBuilder.

Definition at line 322 of file builder.cc.

References blockStack_, chkTypeOnTop(), and Value::V_BOOL.

Here is the call graph for this function:

void ifElse (  )  [virtual]

if statement, else part

Implements IBuilder.

Definition at line 328 of file builder.cc.

References blockStack_, chkBlockStack(), and Builder::TBlock::first.

Here is the call graph for this function:

void ifLeave (  )  [virtual]

if statement complete

Implements IBuilder.

Definition at line 337 of file builder.cc.

References appendCmd(), blockStack_, chkBlockStack(), cmdFactory_, CmdFactory::createIf(), Builder::TBlock::first, and Builder::TBlock::second.

Here is the call graph for this function:

void whileInit ( Token  token  )  [virtual]

while, B_EXPR follows

Implements IBuilder.

Definition at line 357 of file builder.cc.

References blockStack_.

void whileEnter (  )  [virtual]

while, CMD_LIST follows

Implements IBuilder.

Definition at line 362 of file builder.cc.

References blockStack_, chkBlockStack(), and Builder::TBlock::first.

Here is the call graph for this function:

void whileLeave (  )  [virtual]

while statement complete

Implements IBuilder.

Definition at line 371 of file builder.cc.

References appendCmd(), blockStack_, chkBlockStack(), cmdFactory_, CmdFactory::createWhile(), Builder::TBlock::first, and Builder::TBlock::second.

Here is the call graph for this function:

void pushToken ( Token  token  )  [virtual]

push token

Implements IBuilder.

Definition at line 391 of file builder.cc.

References appendCmd(), cmdFactory_, CmdFactory::createPush(), StreamDecorator::E_WARNING, Vm::fileName, fncDef_, pushTypeToStack(), and vm_.

Here is the call graph for this function:

void evalUnOp ( Token  token  )  [virtual]

eval unary operator

Implements IBuilder.

Definition at line 401 of file builder.cc.

References appendCmd(), cmdFactory_, CmdFactory::createUnary(), StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, ETOKEN_KW_NOT, ETOKEN_OP_MINUS, Vm::fileName, hasError_, popTypeFromStack(), pushTypeToStack(), Token::type, Value::V_BOOL, Value::V_DOUBLE, Value::V_INT, and vm_.

Here is the call graph for this function:

void evalBinOp ( Token  token  )  [virtual]

eval binary operator

Implements IBuilder.

Definition at line 415 of file builder.cc.

References appendCmd(), cmdFactory_, CmdFactory::createBinary(), StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, Vm::fileName, hasError_, popTypeFromStack(), pushTypeToStack(), Value::V_NULL, and vm_.

Here is the call graph for this function:

void fncCall ( Token  id,
int  argsToPop,
bool  pushResult 
) [virtual]

function call

Parameters:
id token initiating function call
argsToPop count of arguments to pop from stack and give them to function
pushResult true if function return value is going to be used

Implements IBuilder.

Definition at line 430 of file builder.cc.

References CalleeSet::add(), appendCmd(), FncDeclaration::args, Vm::calleeSet, chkTypeOnTop(), cmdFactory_, CmdFactory::createCall(), CmdFactory::createInput(), Var::defined, StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, StreamDecorator::E_WARNING, Vm::fileName, Vm::fncSet, FncSet::getDeclaration(), hasError_, Token::lineno, pushTypeToStack(), FncDeclaration::self, VarSet::size(), Value::type, Value::V_DOUBLE, Value::V_INT, Value::V_STRING, Var::value, and vm_.

Here is the call graph for this function:

void fncCallPrint ( Token  id,
EToken  valType 
) [virtual]

print function call

Parameters:
id token initiating function call
valType type of expression expected by print function

Implements IBuilder.

Definition at line 482 of file builder.cc.

References appendCmd(), chkTypeOnTop(), cmdFactory_, and CmdFactory::createPrint().

Here is the call graph for this function:

PVar createVar ( EToken  type,
Token  id 
) [private]

common code for variable creation

Definition at line 488 of file builder.cc.

References StreamDecorator::E_WARNING, ETOKEN_KW_DOUBLE, ETOKEN_KW_INT, ETOKEN_KW_STRING, ETOKEN_KW_VOID, Vm::fileName, Value::V_DOUBLE, Value::V_INT, Value::V_NULL, Value::V_STRING, and vm_.

Referenced by fncDeclArg(), fncDeclInit(), fncDefArg(), fncDefInit(), fncDefVar(), and glVar().

Here is the caller graph for this function:

bool appendCmd ( PCmd  cmd  )  [private]

append given command to current stack top

Definition at line 507 of file builder.cc.

References blockStack_, chkBlockStack(), hasError_, and Builder::TBlock::second.

Referenced by assign(), evalBinOp(), evalUnOp(), fncCall(), fncCallPrint(), ifLeave(), pushToken(), and whileLeave().

Here is the call graph for this function:

Here is the caller graph for this function:

bool chkBlockStack (  )  [private]

return true if stack is not empty, print error otherwise

Definition at line 519 of file builder.cc.

References blockStack_, Var::defined, StreamDecorator::E_WARNING, Vm::fileName, fncDef_, FncDeclaration::self, and vm_.

Referenced by appendCmd(), fncDef(), ifElse(), ifLeave(), whileEnter(), and whileLeave().

Here is the caller graph for this function:

void pushTypeToStack ( Value::VType  type  )  [private]

push type to stack

Definition at line 526 of file builder.cc.

References StreamDecorator::C_LIGHT_CYAN, StreamDecorator::C_NO_COLOR, and typeStack_.

Referenced by evalBinOp(), evalUnOp(), fncCall(), and pushToken().

Here is the caller graph for this function:

Value::VType popTypeFromStack ( const Token t  )  [private]

pop type from stack, V_NULL if empty

Definition at line 533 of file builder.cc.

References StreamDecorator::C_LIGHT_CYAN, StreamDecorator::C_NO_COLOR, StreamDecorator::E_WARNING, Vm::fileName, typeStack_, Value::V_NULL, and vm_.

Referenced by chkTypeOnTop(), evalBinOp(), and evalUnOp().

Here is the caller graph for this function:

void chkTypeOnTop ( Value::VType  type,
const Token t 
) [private]

pop type from stack and compare with given type

Definition at line 547 of file builder.cc.

References StreamDecorator::E_ERROR, StreamDecorator::E_NOTE, Vm::fileName, hasError_, popTypeFromStack(), and vm_.

Referenced by assign(), fncCall(), fncCallPrint(), and ifEnter().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Vm* vm_ [private]

virtual machine being built

Definition at line 65 of file builder.cc.

Referenced by assign(), chkBlockStack(), chkTypeOnTop(), createVar(), evalBinOp(), evalUnOp(), fncCall(), fncDecl(), fncDeclArg(), fncDeclInit(), fncDef(), fncDefArg(), fncDefBody(), fncDefInit(), fncDefVar(), glVar(), popTypeFromStack(), and pushToken().

bool hasError_ [private]

true if any error occurred

Definition at line 66 of file builder.cc.

Referenced by appendCmd(), chkTypeOnTop(), errorDetected(), evalBinOp(), evalUnOp(), fncCall(), fncDecl(), fncDef(), fncDefArg(), fncDefBody(), fncDefVar(), glVar(), and hasError().

FncDeclaration* fncDecl_ [private]

pointer to declaration being built, or 0 if not building declaration

Definition at line 67 of file builder.cc.

Referenced by errorDetected(), fncDecl(), fncDeclArg(), fncDeclInit(), and ~Builder().

FncDefinition* fncDef_ [private]

pointer to definition being built, or 0 if not building definition

Definition at line 68 of file builder.cc.

Referenced by assign(), chkBlockStack(), errorDetected(), fncDef(), fncDefArg(), fncDefBody(), fncDefInit(), fncDefVar(), pushToken(), and ~Builder().

CmdFactory cmdFactory_ [private]

common factory for virtual machine commands creation

Definition at line 69 of file builder.cc.

Referenced by assign(), evalBinOp(), evalUnOp(), fncCall(), fncCallPrint(), ifLeave(), pushToken(), and whileLeave().

TBlockStack blockStack_ [private]

stack for blocks of commands

Definition at line 73 of file builder.cc.

Referenced by appendCmd(), chkBlockStack(), errorDetected(), fncDef(), fncDefBody(), ifElse(), ifEnter(), ifLeave(), whileEnter(), whileInit(), and whileLeave().

TTypeStack typeStack_ [private]

stack for expression types

Definition at line 76 of file builder.cc.

Referenced by popTypeFromStack(), and pushTypeToStack().


The documentation for this class was generated from the following file:
Generated on Sat Jul 4 18:33:08 2009 for vyp08 (compiler and interpreter of VYP08 language) by  doxygen 1.5.4