本文整理汇总了C++中StatementList类的典型用法代码示例。如果您正苦于以下问题:C++ StatementList类的具体用法?C++ StatementList怎么用?C++ StatementList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StatementList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create_statement_list
Statement* multi_way_branch_statement_walker::dismantle_multi_way_branch_statement(MultiWayBranchStatement *the_case){
StatementList *replacement = create_statement_list(the_case->get_suif_env());
Expression *operand = the_case->get_decision_operand ();
remove_suif_object(operand);
DataType *type = operand->get_result_type();
CodeLabelSymbol *default_lab = the_case->get_default_target();
the_case->set_default_target(0);
Iter<MultiWayBranchStatement::case_pair > iter = the_case->get_case_iterator();
while (iter.is_valid()) {
MultiWayBranchStatement::case_pair pair = iter.current();
IInteger value = pair.first;
CodeLabelSymbol *lab = pair.second;
IntConstant *exp = create_int_constant(the_case->get_suif_env(),type, value);
// Expression *exp = create_load_constant_expression(get_env(),type,iconst);
TypeBuilder *type_builder = (TypeBuilder *)
the_case->get_suif_env()->get_object_factory(TypeBuilder::get_class_name());
Expression *compare =
create_binary_expression(the_case->get_suif_env(),type_builder->get_boolean_type(),
k_is_equal_to,
deep_suif_clone(operand),
exp);
replacement->append_statement(create_branch_statement(the_case->get_suif_env(),compare,lab));
iter.next();
}
delete operand;
replacement->append_statement(create_jump_statement(the_case->get_suif_env(),default_lab));
the_case->get_parent()->replace(the_case,replacement);
return replacement;
}
示例2: gen_block
void GenTree::gen_block( const StatementList &list, int depth, const char *prefix )
{
if( list.empty() )
return;
if ( prefix != 0 ) {
String line;
line.writeNumber( (int64) list.front()->line() );
int pos = 0;
while( pos + line.length() < 5 )
{
m_out->writeString( " " );
pos++;
}
m_out->writeString( line + " : " );
for (int i = 0; i < depth; i++ )
m_out->writeString( " " );
m_out->writeString( prefix );
m_out->writeString( "\n" );
}
const Statement *stmt = list.front();
while( stmt != 0 ) {
generate( stmt, 0, false, depth + 1 );
stmt = static_cast<const Statement *>(stmt->next());
}
}
示例3: StatementList
void CodeGenVisitor::JIT(Expression* e) {
StatementList* sl = new StatementList();
sl->addStatement(new ReturnStatement(e));
FunctionDefinition* fd = new FunctionDefinition(Type::INT, "", new ParameterList(), sl);
value_ = 0;
fd->accept(this);
if (!value_) {
delete fd;
throw "error evaluating expression";
}
llvm::Function* f = dynamic_cast<llvm::Function*>(value_);
void* fPtr = ee_->getPointerToFunction(f);
// some casting ... because we like magic
int (*fP)() = (int (*)())(intptr_t)fPtr;
std::cout << "Evaluated to: " << fP() << std::endl;
// throw it away
f->eraseFromParent();
}
示例4: assert
void TransformSystemsToModules::ReplaceUses(VariableSymbol* original,
VariableSymbol* replacement)
{
assert(procDef != NULL) ;
StatementList* bodyList = dynamic_cast<StatementList*>(procDef->get_body()) ;
assert(bodyList != NULL) ;
for (int i = 0 ; i < bodyList->get_statement_count() ; ++i)
{
list<LoadVariableExpression*>* allLoads =
collect_objects<LoadVariableExpression>(bodyList->get_statement(i)) ;
list<LoadVariableExpression*>::iterator loadIter = allLoads->begin() ;
while (loadIter != allLoads->end())
{
if ((*loadIter)->get_source() == original)
{
(*loadIter)->set_source(replacement) ;
}
++loadIter ;
}
delete allLoads ;
if (IsDefinition(bodyList->get_statement(i), original))
{
// We no longer have to replace the value
return ;
}
}
}
示例5: CorrectTypes
bool IfConversionPass2::VerifyIf(IfStatement* toConvert)
{
Statement* thenPart = toConvert->get_then_part() ;
Statement* elsePart = toConvert->get_else_part() ;
if (thenPart == NULL || elsePart == NULL)
{
return false ;
}
StatementList* thenList = dynamic_cast<StatementList*>(thenPart) ;
StatementList* elseList = dynamic_cast<StatementList*>(elsePart) ;
if (thenList != NULL && thenList->get_statement_count() != 1)
{
return false ;
}
if (elseList != NULL && elseList->get_statement_count() != 1)
{
return false ;
}
thenPart = Denormalize(thenPart) ;
elsePart = Denormalize(elsePart) ;
return CorrectTypes(thenPart, elsePart) ;
}
示例6: makeIsect
void StatementList::makeIsect(StatementList &a, LocationSet &b)
{
if (this == &a) { // *this = *this isect b
for (auto it = a.begin(); it != a.end();) {
assert((*it)->isAssignment());
Assignment *as = static_cast<Assignment *>(*it);
if (!b.contains(as->getLeft())) {
it = m_list.erase(it);
}
else {
it++;
}
}
}
else { // normal assignment
clear();
for (Statement *stmt : a) {
assert(stmt->isAssignment());
Assignment *as = static_cast<Assignment *>(stmt);
if (b.contains(as->getLeft())) {
append(as);
}
}
}
}
示例7:
void
SemanticAnalysis::visitBlockStatement(BlockStatement *node)
{
StatementList *stmts = node->statements();
for (size_t i = 0; i < stmts->length(); i++) {
Statement *stmt = stmts->at(i);
stmt->accept(this);
}
}
示例8: getLibraryDefines
// Return a list of locations defined by library calls
void PPCSignature::getLibraryDefines(StatementList &defs)
{
if (defs.size() > 0) {
return; // Do only once
}
for (int r = REG_PPC_G3; r <= REG_PPC_G12; ++r) {
defs.append(
new ImplicitAssign(Location::regOf(r))); // Registers 3-12 are volatile (caller save)
}
}
示例9: removeRedundantBlocks
void removeRedundantBlocks(BlockPtr b) {
StatementList& children = b->getChildren();
for (size_t i = 0; i < children.size(); ++i) {
if (REN_DYNAMIC_CAST_PTR(ib, Block, children[i])) {
removeRedundantBlocks(ib);
StatementList sl = ib->getChildren();
children.erase(children.begin() + i);
children.insert(children.begin() + i, sl.begin(), sl.end());
--i;
}
}
}
示例10: find_scope
Walker::ApplyStatus multi_way_branch_statement_compactor::operator () (SuifObject *x)
{
MultiWayBranchStatement *the_case = to<MultiWayBranchStatement>(x);
// is the table already compact?
if (is_compact(the_case))
return Walker::Continue;
SymbolTable *scope = find_scope(x);
if (!scope)
return Walker::Continue;
CodeLabelSymbol *default_lab = the_case->get_default_target();
// very special case - the case list is empty, so just jump to the default label
if (the_case->get_case_count() == 0) {
Statement *replacement = create_jump_statement(get_env(),default_lab);
the_case->get_parent()->replace(the_case,replacement);
set_address(replacement);
return Walker::Replaced;
}
StatementList *replacement = create_statement_list(get_env());
Expression *operand = the_case->get_decision_operand ();
remove_suif_object(operand);
DataType *type = operand->get_result_type();
VariableSymbol *decision = create_variable_symbol(get_env(),get_type_builder(get_env())->get_qualified_type(type));
scope->add_symbol(decision);
replacement->append_statement(create_store_variable_statement(get_env(),decision,operand));
the_case->set_default_target(0);
MultiWayGroupList jump_list(get_env(),default_lab,decision);;
Iter<MultiWayBranchStatement::case_pair > iter = the_case->get_case_iterator();
while (iter.is_valid()) {
MultiWayBranchStatement::case_pair pair = iter.current();
jump_list.add_element(pair.first,pair.second);
iter.next();
}
// we have built the new structure, now need to generate code for it
jump_list.generate_code(replacement);
the_case->get_parent()->replace(the_case,replacement);
set_address(replacement);
return Walker::Replaced;
}
示例11: assert
Statement* IfConversionPass2::Denormalize(Statement* x)
{
if (dynamic_cast<StatementList*>(x) != NULL)
{
StatementList* theList = dynamic_cast<StatementList*>(x) ;
assert(theList->get_statement_count() == 1 && "Unsupported if detected!") ;
return theList->get_statement(0) ;
}
else
{
return x ;
}
}
示例12: append
void StatementList::append(const StatementList &sl)
{
if (&sl == this) {
const size_t oldSize = m_list.size();
auto it = m_list.begin();
for (size_t i = 0; i < oldSize; i++) {
m_list.push_back(*it++);
}
}
else {
m_list.insert(end(), sl.begin(), sl.end());
}
}
示例13: main
int main(int argc, char **argv)
{
vector<Token> tokens = lexerFile(argv[1]);
Parser parser(tokens, &std::cout);
StatementList * list = parser.file();
Printer p(std::cout);
cout << "Statements " << list->size() << endl;
for( Statement *s : *list )
s->print(p);
return 0;
}
示例14: Assign
void RtlTest::testSetConscripts()
{
// m[1000] = m[1000] + 1000
Statement* s1 = new Assign(
Location::memOf(
new Const(1000), 0),
new Binary(opPlus,
Location::memOf(
new Const(1000), NULL),
new Const(1000)));
// "printf("max is %d", (local0 > 0) ? local0 : global1)
CallStatement* s2 = new CallStatement();
std::string name("printf");
Proc* proc = new UserProc(new Prog(), name, 0x2000); // Making a true LibProc is problematic
s2->setDestProc(proc);
s2->setCalleeReturn(new ReturnStatement); // So it's not a childless call
Exp* e1 = new Const("max is %d");
Exp* e2 = new Ternary(opTern,
new Binary(opGtr,
Location::local("local0", NULL),
new Const(0)),
Location::local("local0", NULL),
Location::global("global1", NULL));
StatementList args;
args.append(new Assign(Location::regOf(8), e1));
args.append(new Assign(Location::regOf(9), e2));
s2->setArguments(args);
std::list<Statement*> list;
list.push_back(s1);
list.push_back(s2);
RTL* rtl = new RTL(0x1000, &list);
rtl->setConscripts(0, false);
std::string expected(
"00001000 0 *v* m[1000\\1\\] := m[1000\\2\\] + 1000\\3\\\n"
" 0 CALL printf(\n"
" *v* r8 := \"max is %d\"\\4\\\n"
" *v* r9 := (local0 > 0\\5\\) ? local0 : global1\n"
" )\n"
" Reaching definitions: \n"
" Live variables: \n");
std::ostringstream ost;
rtl->print(ost);
std::string actual = ost.str();
CPPUNIT_ASSERT_EQUAL(expected, actual);
}
示例15: findInterpolatable
CodeNodePtr findInterpolatable(StatementPtr stmt) {
if (CodeNodePtr e = stmt->getExpression()) {
if (CodeNodePtr f = findInterpolatable(e)) {
return f;
}
}
StatementList children = stmt->getChildren();
for (size_t i = 0; i < children.size(); ++i) {
if (CodeNodePtr f = findInterpolatable(children[i])) {
return f;
}
}
return CodeNodePtr();
}