本文整理汇总了C++中CAstStatement::GetNext方法的典型用法代码示例。如果您正苦于以下问题:C++ CAstStatement::GetNext方法的具体用法?C++ CAstStatement::GetNext怎么用?C++ CAstStatement::GetNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAstStatement
的用法示例。
在下文中一共展示了CAstStatement::GetNext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToTac
CTacAddr* CAstStatIf::ToTac(CCodeBlock *cb, CTacLabel *next)
{
CTacLabel* truelabel = cb->CreateLabel("if_true"); // true label
CTacLabel* falselabel = cb->CreateLabel("if_false"); // false label
_cond->ToTac(cb, truelabel, falselabel); // calculate condition
CAstStatement *s = _ifBody;
cb->AddInstr(truelabel); // install true label
while(s != NULL) { // TAC of ifBody
CTacLabel* tempnext = cb->CreateLabel();
s->ToTac(cb, tempnext);
cb->AddInstr(tempnext);
s = s->GetNext();
}
cb->AddInstr(new CTacInstr(opGoto, next)); // skip to next
s = _elseBody;
cb->AddInstr(falselabel); // install false label
while(s != NULL) { // TAC of elseBody
CTacLabel* tempnext = cb->CreateLabel();
s->ToTac(cb, tempnext);
cb->AddInstr(tempnext);
s = s->GetNext();
}
cb->AddInstr(new CTacInstr(opGoto, next)); // goto next
return NULL;
}
示例2: ind
ostream& CAstStatIf::print(ostream &out, int indent) const
{
string ind(indent, ' ');
out << ind << "if cond" << endl;
_cond->print(out, indent+2);
out << ind << "if-body" << endl;
if (_ifBody != NULL) {
CAstStatement *s = _ifBody;
do {
s->print(out, indent+2);
s = s->GetNext();
} while (s != NULL);
} else out << ind << " empty." << endl;
out << ind << "else-body" << endl;
if (_elseBody != NULL) {
CAstStatement *s = _elseBody;
do {
s->print(out, indent+2);
s = s->GetNext();
} while (s != NULL);
} else out << ind << " empty." << endl;
return out;
}
示例3: TypeCheck
bool CAstStatIf::TypeCheck(CToken *t, string *msg) const
{
CAstExpression *cond = GetCondition();
bool result = true;
if (!cond->TypeCheck(t, msg)) return false;
if (cond->GetType() != CTypeManager::Get()->GetBool()) {
if (t != NULL) *t = cond->GetToken();
if (msg != NULL) *msg = "boolean expression expected.";
return false;
}
try {
CAstStatement *ifBody = GetIfBody();
CAstStatement *elseBody = GetElseBody();
while (result && (ifBody != NULL)) {
result = ifBody->TypeCheck(t, msg);
ifBody = ifBody->GetNext();
}
while (result && (elseBody != NULL)) {
result = elseBody->TypeCheck(t, msg);
elseBody = elseBody->GetNext();
}
} catch (...) {
result = false;
}
return result;
}
示例4: toDot
void CAstScope::toDot(ostream &out, int indent) const
{
string ind(indent, ' ');
CAstNode::toDot(out, indent);
CAstStatement *s = GetStatementSequence();
if (s != NULL) {
string prev = dotID();
do {
s->toDot(out, indent);
out << ind << prev << " -> " << s->dotID() << " [style=dotted];" << endl;
prev = s->dotID();
s = s->GetNext();
} while (s != NULL);
}
vector<CAstScope*>::const_iterator it = _children.begin();
while (it != _children.end()) {
CAstScope *s = *it++;
s->toDot(out, indent);
out << ind << dotID() << " -> " << s->dotID() << ";" << endl;
}
}
示例5: ToTac
CTacAddr* CAstStatWhile::ToTac(CCodeBlock *cb, CTacLabel *next)
{
assert(cb != NULL && next != NULL);
CAstExpression *cond = GetCondition();
CAstStatement *body = GetBody();
CTacLabel *while_cond = cb->CreateLabel("while_cond");
CTacLabel *c_true = cb->CreateLabel("while_body");
// while condition begins
cb->AddInstr(while_cond);
CTacAddr *tCond = cond->ToTac(cb, c_true, next);
if(dynamic_cast<CAstDesignator*>(cond)) { // if cond is a single boolean
cb->AddInstr(new CTacInstr(opEqual, c_true, tCond, new CTacConst(1)));
cb->AddInstr(new CTacInstr(opGoto, next));
}
// while body starts..
cb->AddInstr(c_true);
while(body) {
CTacLabel *while_next = cb->CreateLabel("while_next");
body->ToTac(cb, while_next);
cb->AddInstr(while_next);
body = body->GetNext();
}
cb->AddInstr(new CTacInstr(opGoto, while_cond));
return NULL;
}
示例6: TypeCheck
bool CAstStatIf::TypeCheck(CToken *t, string *msg) const
{
if(!_cond->TypeCheck(t, msg)) return false; // Do TypeCheck on condition expression
if(!_cond->GetType()->IsBoolean()) {
if(t != NULL) *t = _cond->GetToken();
if(msg != NULL) *msg = "boolean expression expected.";
return false;
}
bool result = true;
CAstStatement *s = _ifBody;
while(result && (s != NULL)) { // Do TypeCheck on all ifBody-statements
result = s->TypeCheck(t, msg);
s = s->GetNext();
}
s = _elseBody;
while(result && (s != NULL)) { // Do TypeCheck on all elseBody-statements
result = s->TypeCheck(t, msg);
s = s->GetNext();
}
return result;
}