本文整理汇总了C++中ParseTree::CompleteTypes方法的典型用法代码示例。如果您正苦于以下问题:C++ ParseTree::CompleteTypes方法的具体用法?C++ ParseTree::CompleteTypes怎么用?C++ ParseTree::CompleteTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTree
的用法示例。
在下文中一共展示了ParseTree::CompleteTypes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessParseTree
void CodeGenerator::ProcessParseTree(int flags)
{
infunc(CodeGenerator::ProcessParseTree);
ParseTree *tree;
// Allocate some space for the parse tree
if ((tree = new ParseTree) == NULL)
throw CError("Couldn't allocate parse tree");
// Build the parse tree (steps passed all the tokens)
tree->Build(tokeniser, TOKEN_END_OF_LINE, TOKEN_NULL);
// Reduce the tree if possible
tree->Optimise();
if (g_Object)
{
tree->CompleteTypes(flags);
tree->GenerateCode(flags);
// Yacka
// tree->Debug();
}
// The tree is no longer needed
delete tree;
outfunc;
}
示例2: ProcessReturnTerm
void CodeGenerator::ProcessReturnTerm(int flags)
{
infunc(CodeGenerator::ProcessKeywordTerm);
ParseTree *tree;
if (!(flags & FLAGS_IN_FUNCTION))
throw CompileError("(Line %d) Cannot specify return keyword outside of a function", CUR_TOKEN.line);
INC_TOKEN;
// Does this function return any values?
if (cur_class->cur_function->GetReturnType().id == VARIABLE_TYPEID_VOID)
{
// Can only end here
if (CUR_TOKEN.type != TOKEN_END_OF_LINE)
throw CompileError("(Line %d) Cannot specify return value for void function", CUR_TOKEN.line);
return;
}
// Allocate the parse tree
if ((tree = new ParseTree) == NULL)
throw CError("Couldn't allocate parse tree");
// Build the parse tree
tree->Build(tokeniser, TOKEN_END_OF_LINE, TOKEN_NULL);
// Reduce it
tree->Optimise();
if (g_Object)
{
tree->CompleteTypes(flags | FLAGS_IMPLICIT_ASSIGNMENT);
tree->GenerateCode(flags | FLAGS_IMPLICIT_ASSIGNMENT);
}
// Don't need the tree
delete tree;
// Mark the return
cur_class->cur_function->had_return = 1;
if (g_Object)
{
// Pop the return value to a safe place
if (cur_class->cur_function->GetReturnType().id != VARIABLE_TYPEID_VOID)
g_Object->WriteOp(OPCODE_POP_RETURN);
// Write the return code
cur_class->cur_function->WriteReturn(g_Object);
}
outfunc;
}
示例3: ProcessWhileTerm
void CodeGenerator::ProcessWhileTerm(int flags)
{
infunc(CodeGenerator::ProcessWhileTerm);
ParseTree *tree;
int code_position;
if (!(flags & FLAGS_IN_CLASS))
throw CompileError("(Line %d) Can't have a while loop statement outside of a class", CUR_TOKEN.line);
// Go passed the declare
INC_TOKEN;
if (CUR_TOKEN.type != TOKEN_LEFT_BRACKET)
throw CompileError("(Line %d) Expecting an opening bracket", CUR_TOKEN.line);
// Should be at the expression opening here
INC_TOKEN;
// Allocate the parse tree for the test expression
if ((tree = new ParseTree) == NULL)
throw CError("Couldn't allocate parse tree");
// Build the tree, ending at the closing bracket
tree->Build(tokeniser, TOKEN_RIGHT_BRACKET, TOKEN_NULL);
INC_TOKEN;
// Reduce the tree
tree->Optimise();
if (g_Object)
{
// Mark before the loop test
code_position = g_Object->GetPosition();
// Generate the test statement
tree->CompleteTypes(flags | FLAGS_IMPLICIT_ASSIGNMENT);
tree->GenerateCode(flags | FLAGS_IMPLICIT_ASSIGNMENT);
}
// Valid?
if (tree->GetTop() == NULL)
throw CompileError("(Line %d) Expecting an expression for the if statement", CUR_TOKEN.line);
if (g_Object)
{
g_Object->AddBackpatchItem(14);
// Generate the jump out of the loop
if (tree->GetTop()->out_type.id == VARIABLE_TYPEID_FLOAT)
g_Object->WriteOp(OPCODE_FJZ, 0);
else
g_Object->WriteOp(OPCODE_JZ, 0);
}
// Don't need this anymore
delete tree;
ProcessBlock(flags | FLAGS_ALLOW_LINE_BLOCKS | FLAGS_ALLOW_BREAK_CONTINUE);
if (g_Object)
{
// Jump back to the beginning of the loop
g_Object->WriteOp(OPCODE_JMP, code_position);
// Update the loop jump out
g_Object->UpdateItems(14);
// Update all breaks
g_Object->UpdateItems(12);
// Update all continues
g_Object->UpdateItems(13, code_position);
}
outfunc;
}
示例4: ProcessIfTerm
void CodeGenerator::ProcessIfTerm(int flags)
{
infunc(CodeGenerator::ProcessIfTerm);
ParseTree *tree;
ParseTreeNode *top;
int a, b;
a = b = 100 + rand();
while (a == b) b = 100 + rand();
if (!(flags & FLAGS_IN_CLASS))
throw CompileError("(Line %d) Can't have an if statement outside of a class", CUR_TOKEN.line);
// Go passed the declare
INC_TOKEN;
if (CUR_TOKEN.type != TOKEN_LEFT_BRACKET)
throw CompileError("(Line %d) Expecting an opening bracket", CUR_TOKEN.line);
// Should be at the expression opening here
INC_TOKEN;
// Allocate the parse tree for the expression
if ((tree = new ParseTree) == NULL)
throw CError("Couldn't allocate parse tree");
// Build the tree, ending at the if close
tree->Build(tokeniser, TOKEN_RIGHT_BRACKET, TOKEN_NULL);
INC_TOKEN;
// Reduce the tree
tree->Optimise();
if (g_Object)
{
tree->CompleteTypes(flags | FLAGS_IMPLICIT_ASSIGNMENT);
// Implicit assignment (no need for asg at the end of the expression)
tree->GenerateCode(flags | FLAGS_IMPLICIT_ASSIGNMENT);
}
if (tree->GetTop() == NULL)
throw CompileError("(Line %d) Expecting an expression for the if statement", CUR_TOKEN.line);
if (g_Object)
{
// Mark this jump
g_Object->AddBackpatchItem(a);
// Grab the top tree node
if ((top = tree->GetTop()) == NULL)
throw CompileError("(Line %d) Expecting an expression for the if statement", CUR_TOKEN.line);
// Jump over the following block if the expression is false
if (top->out_type.id == VARIABLE_TYPEID_FLOAT)
g_Object->WriteOp(OPCODE_FJZ, 0);
else
g_Object->WriteOp(OPCODE_JZ, 0);
}
// The tree is no longer needed
delete tree;
BlockType bt = ProcessBlock(flags | FLAGS_ALLOW_LINE_BLOCKS);
if (NEXT_TOKEN.type == TOKEN_ELSE)
{
// Step over the close scope
INC_TOKEN;
if (g_Object)
{
// Mark this jump, at the end of the if's true block
g_Object->AddBackpatchItem(b);
// Jump over the else false block
g_Object->WriteOp(OPCODE_JMP, 0);
}
}
if (g_Object)
g_Object->UpdateItems(a);
if (CUR_TOKEN.type == TOKEN_ELSE)
{
// Step over the keyword
INC_TOKEN;
ProcessBlock(flags | FLAGS_ALLOW_LINE_BLOCKS);
// Back patch the jump over the else block
if (g_Object)
g_Object->UpdateItems(b);
}
outfunc;
}