void NormalizeProcedureReturns::
do_procedure_definition( ProcedureDefinition *pd ) {
  ProcedureSymbol *ps = pd->get_procedure_symbol();
  if (!ps) return;
  ProcedureType *t = to<ProcedureType>(ps->get_type());
  if (!is_kind_of<CProcedureType>(t))
    return;
  CProcedureType *ct = to<CProcedureType>(t);
  DataType *result = ct->get_result_type();
  bool is_void = is_kind_of<VoidType>(result);

  for (Iter<ReturnStatement> iter = object_iterator<ReturnStatement>(pd);
       iter.is_valid(); iter.next()) {
    ReturnStatement *ret = &iter.current();
    if (ret == NULL) continue;
    
    Expression *ret_expr = ret->get_return_value();

    if (is_void) {
      if (ret_expr != NULL) {
	// Should not be here
	trash_it(remove_suif_object(ret_expr));
      }
    } else {
      if (ret_expr == NULL) {
	// build a NULL expression to match the DataType.
	Expression *x = build_empty_expression(result);
	ret->set_return_value(x);
      }
    }
  }
}
Пример #2
0
static
String handle_static_return_statement(CPrintStyleModule *state,
				    const SuifObject *obj)
{
  ReturnStatement *stmt = to<ReturnStatement>(obj);
  String return_str = "Return";
  if (stmt->get_return_value() != NULL) {
    String op = state->print_to_string(stmt->get_return_value());
    return_str = return_str + "(" + op + ")";
  }
  return(return_str);
}
Пример #3
0
Method* addComplicated(Model::Model* model, Class* parent)
{
	Method* met = nullptr;

	if (!parent) met = dynamic_cast<Method*> (model->createRoot("Method"));
	model->beginModification(parent? static_cast<Model::Node*> (parent) : met, "Adding a Complicated method.");
	if (!met)
	{
		met = new Method();
		parent->methods()->append(met);
	}

	met->setName("complicated");

	VariableDeclarationExpression* a = new VariableDeclarationExpression("a");
	met->items()->append(new ExpressionStatement(a));
	a->decl()->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));

	VariableDeclarationExpression* b = new VariableDeclarationExpression("b");
	met->items()->append(new ExpressionStatement(b));
	b->decl()->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::UNSIGNED_INT));
	b->decl()->setInitialValue(new IntegerLiteral(1000));

	LoopStatement* loop = new LoopStatement();
	met->items()->append(loop);
	VariableDeclarationExpression* initStep = new VariableDeclarationExpression("i");
	loop->setInitStep(initStep);
	initStep->decl()->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));
	initStep->decl()->setInitialValue(new IntegerLiteral(0));
	BinaryOperation* loopCondition = new BinaryOperation();
	loop->setCondition(loopCondition);
	loopCondition->setLeft(new ReferenceExpression("i"));
	loopCondition->setOp(BinaryOperation::LESS);
	loopCondition->setRight(new ReferenceExpression("a"));
	AssignmentExpression* updateStep = new AssignmentExpression();
	loop->setUpdateStep(updateStep);
	updateStep->setLeft(new ReferenceExpression("i"));
	updateStep->setOp(AssignmentExpression::PLUS_ASSIGN);
	updateStep->setRight(new IntegerLiteral(1));

	AssignmentExpression* loopBodyAssignment = new AssignmentExpression();
	loop->body()->append(loopBodyAssignment);
	loopBodyAssignment->setLeft(new ReferenceExpression("b"));
	loopBodyAssignment->setOp(AssignmentExpression::TIMES_ASSIGN);
	loopBodyAssignment->setRight(new IntegerLiteral(2));

	IfStatement* loopIf = new IfStatement();
	loop->body()->append(loopIf);
	BinaryOperation* ifCond = new BinaryOperation();
	loopIf->setCondition(ifCond);
	ifCond->setLeft(new ReferenceExpression("i"));
	ifCond->setOp(BinaryOperation::NOT_EQUALS);
	ifCond->setRight(new IntegerLiteral(10));
	IfStatement* loopIfLeft = new IfStatement();
	loopIf->thenBranch()->append(loopIfLeft);
	IfStatement* loopIfRight = new IfStatement();
	loopIf->elseBranch()->append(loopIfRight);

	BinaryOperation* ifLeftCondition = new BinaryOperation();
	loopIfLeft->setCondition(ifLeftCondition);
	ifLeftCondition->setLeft(new ReferenceExpression("a"));
	ifLeftCondition->setOp(BinaryOperation::GREATER_EQUALS);
	ifLeftCondition->setRight(new IntegerLiteral(3));
	loopIfLeft->thenBranch()->append(new ContinueStatement());
	loopIfLeft->thenBranch()->append(new BreakStatement());
	loopIfLeft->thenBranch()->append(new ContinueStatement());
	loopIfLeft->thenBranch()->append(new BreakStatement());

	BinaryOperation* ifRightCondition = new BinaryOperation();
	loopIfRight->setCondition(ifRightCondition);
	ifRightCondition->setLeft(new ReferenceExpression("b"));
	ifRightCondition->setOp(BinaryOperation::EQUALS);
	ifRightCondition->setRight(new IntegerLiteral(-20));
	loopIfRight->thenBranch()->append(new ContinueStatement());
	loopIfRight->thenBranch()->append(new BreakStatement());
	loopIfRight->thenBranch()->append(new ContinueStatement());
	loopIfRight->thenBranch()->append(new BreakStatement());
	loopIfRight->elseBranch()->append(new ContinueStatement());
	loopIfRight->elseBranch()->append(new BreakStatement());
	loopIfRight->elseBranch()->append(new ContinueStatement());
	loopIfRight->elseBranch()->append(new BreakStatement());


	loop->body()->append(new ContinueStatement());
	loop->body()->append(new BreakStatement());

	ForEachStatement* forEach = new ForEachStatement();
	met->items()->append(forEach);
	forEach->setVarName("elem");
	forEach->setVarType( new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::UNSIGNED_INT) );
	forEach->setCollection(new ReferenceExpression("SomeCollection"));
	AssignmentExpression* assignEach = new AssignmentExpression();
	forEach->body()->append(assignEach);
	assignEach->setLeft(new ReferenceExpression("a"));
	assignEach->setOp(AssignmentExpression::DIVIDE_ASSIGN);
	assignEach->setRight(new ReferenceExpression("elem"));


	ReturnStatement* metReturn = new ReturnStatement();
	metReturn->values()->append(new IntegerLiteral(42));
	met->items()->append(metReturn);
	met->extension<Position>()->setX(500);

	model->endModification();
	return met;
}
Пример #4
0
Method* addDivBySix(Model::Model* model, Class* parent)
{
	Method* divbysix = nullptr;

	if (!parent) divbysix = dynamic_cast<Method*> (model->createRoot("Method"));
	model->beginModification(parent? static_cast<Model::Node*> (parent) : divbysix, "Adding a divBySix method.");
	if (!divbysix)
	{
		divbysix = new Method();
		parent->methods()->append(divbysix);
	}

	divbysix->setName("findDivBySix");
	FormalResult* divbysixResult = new FormalResult();
	divbysixResult->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));
	divbysix->results()->append(divbysixResult);
	FormalArgument* arg = new FormalArgument();
	divbysix->arguments()->append(arg);
	arg->setName("numbers");
	ArrayTypeExpression* argType = new ArrayTypeExpression();
	argType->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));
	arg->setTypeExpression(argType);

	VariableDeclarationExpression* result = new VariableDeclarationExpression("result");
	divbysix->items()->append(new ExpressionStatement(result));
	result->decl()->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));
	result->decl()->setInitialValue(new IntegerLiteral(-1));

	LoopStatement* sixloop = new LoopStatement();
	divbysix->items()->append(sixloop);
	VariableDeclarationExpression* sixLoopInit = new VariableDeclarationExpression("i");
	sixloop->setInitStep(sixLoopInit);
	sixLoopInit->decl()->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));
	sixLoopInit->decl()->setInitialValue(new IntegerLiteral(0));
	BinaryOperation* sixLoopCond = new BinaryOperation();
	sixloop->setCondition(sixLoopCond);
	sixLoopCond->setLeft(new ReferenceExpression("i"));
	sixLoopCond->setOp(BinaryOperation::LESS);
	MethodCallExpression* sizeCall = new MethodCallExpression("size", new ReferenceExpression("numbers"));
	sixLoopCond->setRight(sizeCall);

	//TODO test the visualization without the remaining parts of this method
	AssignmentExpression* sixLoopUpdate = new AssignmentExpression();
	sixloop->setUpdateStep(sixLoopUpdate);
	sixLoopUpdate->setLeft(new ReferenceExpression("i"));
	sixLoopUpdate->setOp(AssignmentExpression::PLUS_ASSIGN);
	sixLoopUpdate->setRight(new IntegerLiteral(1));

	VariableDeclarationExpression* n = new VariableDeclarationExpression("n");
	sixloop->body()->append(new ExpressionStatement(n));
	n->decl()->setTypeExpression(new PrimitiveTypeExpression(PrimitiveTypeExpression::PrimitiveTypes::INT));
	BinaryOperation* item = new BinaryOperation();
	n->decl()->setInitialValue(item);
	item->setLeft(new ReferenceExpression("numbers"));
	item->setOp(BinaryOperation::ARRAY_INDEX);
	item->setRight(new ReferenceExpression("i"));

	IfStatement* ifdiv2 = new IfStatement();
	sixloop->body()->append(ifdiv2);
	BinaryOperation* eq0 = new BinaryOperation();
	ifdiv2->setCondition(eq0);
	eq0->setOp(BinaryOperation::EQUALS);
	eq0->setRight(new IntegerLiteral(0));
	BinaryOperation* div2 = new BinaryOperation();
	eq0->setLeft(div2);
	div2->setLeft(new ReferenceExpression("n"));
	div2->setOp(BinaryOperation::REMAINDER);
	div2->setRight(new IntegerLiteral(2));
	ifdiv2->elseBranch()->append(new  ContinueStatement());

	IfStatement* ifdiv3 = new IfStatement();
	ifdiv2->thenBranch()->append(ifdiv3);
	eq0 = new BinaryOperation();
	ifdiv3->setCondition(eq0);
	eq0->setOp(BinaryOperation::EQUALS);
	eq0->setRight(new IntegerLiteral(0));
	BinaryOperation* div3 = new BinaryOperation();
	eq0->setLeft(div3);
	div3->setLeft(new ReferenceExpression("n"));
	div3->setOp(BinaryOperation::REMAINDER);
	div3->setRight(new IntegerLiteral(3));

	AssignmentExpression* resultFound = new AssignmentExpression();
	ifdiv3->thenBranch()->append(resultFound);
	resultFound->setLeft(new ReferenceExpression("result"));
	resultFound->setOp(AssignmentExpression::ASSIGN);
	resultFound->setRight(new ReferenceExpression("i"));
	ifdiv3->thenBranch()->append( new BreakStatement());

	ReturnStatement* divbysixFinalReturn = new ReturnStatement();
	divbysixFinalReturn->values()->append(new ReferenceExpression("result"));
	divbysix->items()->append(divbysixFinalReturn);

	model->endModification();
	return divbysix;
}
Пример #5
0
void RtlTest::testVisitor()
{
	StmtVisitorStub* visitor = new StmtVisitorStub();

	/* rtl */
	RTL *rtl = new RTL();
	rtl->accept(visitor);
	CPPUNIT_ASSERT(visitor->a);
	delete rtl;

	/* jump stmt */
	GotoStatement *jump = new GotoStatement;
	jump->accept(visitor);
	CPPUNIT_ASSERT(visitor->b);
	delete jump;

	/* branch stmt */
	BranchStatement *jcond = new BranchStatement;
	jcond->accept(visitor);
	CPPUNIT_ASSERT(visitor->c);
	delete jcond;

	/* nway jump stmt */
	CaseStatement *nwayjump = new CaseStatement;
	nwayjump->accept(visitor);
	CPPUNIT_ASSERT(visitor->d);
	delete nwayjump;

	/* call stmt */
	CallStatement *call = new CallStatement;
	call->accept(visitor);
	CPPUNIT_ASSERT(visitor->e);
	delete call;

	/* return stmt */
	ReturnStatement *ret = new ReturnStatement;
	ret->accept(visitor);
	CPPUNIT_ASSERT(visitor->f);
	delete ret;

	/* "bool" assgn */
	BoolAssign *scond = new BoolAssign(0);
	scond->accept(visitor);
	CPPUNIT_ASSERT(visitor->g);
	delete scond;

	/* assignment stmt */
	Assign *as = new Assign;
	as->accept(visitor);
	CPPUNIT_ASSERT(visitor->h);
	delete as;

	/* polymorphic */
	Statement* s = new CallStatement;
	s->accept(visitor);
	CPPUNIT_ASSERT(visitor->e);
	delete s;

	/* cleanup */
	delete visitor;
}
void DismantleStructuredReturns::do_file_set_block( FileSetBlock* file_set_block ) {
    suif_map<CProcedureType *,QualifiedType *> type_map;
    list<ArrayReferenceExpression*> ref_exprs;
    SuifEnv *env = 0;
    TypeBuilder *tb = 0;
    VoidType *vt = 0;
    for (Iter<ProcedureSymbol> iter =
                object_iterator<ProcedureSymbol>(file_set_block);
	iter.is_valid();
	iter.next()) {
	ProcedureSymbol *sym = &iter.current();
	Type *type = sym->get_type();
	if (!is_kind_of<CProcedureType>(type))
	    continue;
	CProcedureType *cp_type = to<CProcedureType>(type);
	type = cp_type->get_result_type();
	if (!env) {
	    env = type->get_suif_env();
	    tb = (TypeBuilder*)
                env->get_object_factory(TypeBuilder::get_class_name());
	    vt = tb->get_void_type();
	    }
	suif_map<CProcedureType *,QualifiedType *>::iterator t_iter = type_map.find(cp_type);

	QualifiedType *qtype;
	
 	if (t_iter == type_map.end()) {
	    if (!is_kind_of<GroupType>(type) && !is_kind_of<ArrayType>(type))
                continue;
	    qtype = tb->get_qualified_type(
                        tb->get_pointer_type(to<DataType>(type)));

	    cp_type->set_result_type(vt);
	    
	    cp_type->insert_argument(0,qtype);
	    type_map.enter_value(cp_type,qtype);
	    }
	else {
	    qtype = (*t_iter).second;
	    }
	ProcedureDefinition *def = sym->get_definition();
	if (!def) 
	    continue;
	ParameterSymbol *par = create_parameter_symbol(env,qtype);
	def->get_symbol_table()->append_symbol_table_object(par);
        def->insert_formal_parameter(0,par);
	//	Convert all returns into assigned and returns
	for (Iter<ReturnStatement> ret_iter = object_iterator<ReturnStatement>(def->get_body());
        	ret_iter.is_valid();
        	ret_iter.next()) {
	    ReturnStatement *ret = &ret_iter.current();
	    Expression *retval = ret->get_return_value();
	    ret->set_return_value(0);
	    retval->set_parent(0);
	    insert_statement_before(ret,
			create_store_statement(env,retval,create_var_use(par)));
	    }
	}
    //	Change all calls to the new form
    for (Iter<CallStatement> cs_iter =
                object_iterator<CallStatement>(file_set_block);
        cs_iter.is_valid();
        cs_iter.next()) {
        CallStatement *call = &cs_iter.current();
	Type *type = call->get_callee_address()->get_result_type();
	Type *p_type = tb->unqualify_type(to<PointerType>(type)->get_reference_type());
        if (!is_kind_of<PointerType>(p_type))
            continue;
        p_type = tb->unqualify_type(to<PointerType>(p_type)->get_reference_type());

	if (!is_kind_of<CProcedureType>(p_type))
	    continue;
	CProcedureType *cp_type = to<CProcedureType>(p_type);
	
	suif_map<CProcedureType *,QualifiedType *>::iterator t_iter = type_map.find(cp_type);
	if (t_iter == type_map.end())
	    continue;
	QualifiedType *qtype = (*t_iter).second;
	DataType *var_type = to<DataType>(tb->unqualify_type(to<PointerType>(qtype->get_base_type())
		->get_reference_type()));
	VariableSymbol *var =
      	    new_anonymous_variable(env,call,tb->get_qualified_type(var_type));
	Expression *exp = create_symbol_address_expression(
		env,
		tb->get_pointer_type(var_type),
		var);
        call->insert_argument(0,exp);
        call->set_destination(0);
	}

    for (Iter<CallExpression> ce_iter =
                object_iterator<CallExpression>(file_set_block);
        ce_iter.is_valid();
        ce_iter.next()) {
        CallExpression *call = &ce_iter.current();
        Type *type = call->get_callee_address()->get_result_type();
        Type *p_type = tb->unqualify_type(to<PointerType>(type)->get_reference_type());
	if (!is_kind_of<PointerType>(p_type))
            continue;
	p_type = tb->unqualify_type(to<PointerType>(p_type)->get_reference_type());
        if (!is_kind_of<CProcedureType>(p_type))
            continue;
        CProcedureType *cp_type = to<CProcedureType>(p_type);
;
        suif_map<CProcedureType *,QualifiedType *>::iterator t_iter = type_map.find(cp_type);
        if (t_iter == type_map.end())
            continue;
        QualifiedType *qtype = (*t_iter).second;
        DataType *var_type = to<DataType>(tb->unqualify_type(to<PointerType>(qtype->get_base_type())
                ->get_reference_type()));
        VariableSymbol *var =
            new_anonymous_variable(env,call,tb->get_qualified_type(var_type));
        Expression *exp = create_symbol_address_expression(
                env,
                tb->get_pointer_type(var_type),
                var);
        call->insert_argument(0,exp);

	Statement *loc = get_expression_owner(call);
	call->get_parent()->replace(call,create_var_use(var));
	call->set_parent(0);
        suif_assert(vt != 0);
        call->set_result_type(vt);

	EvalStatement *es = create_eval_statement(env);
	insert_statement_before(loc,es);
	// Would be better to turn this into a call statement
	es->append_expression(call);
        }
    }
Пример #7
0
Method* addDivBySix(Model::Model* model, Class* parent)
{
	Method* divbysix = nullptr;

	if (!parent) divbysix = dynamic_cast<Method*> (model->createRoot("Method"));
	model->beginModification(parent? static_cast<Model::Node*> (parent) : divbysix, "Adding a divBySix method.");
	if (!divbysix)
	{
		divbysix = new Method();
		parent->methods()->append(divbysix);
	}

	divbysix->setName("findDivBySix");
	FormalResult* divbysixResult = new FormalResult();
	divbysixResult->setType(new PrimitiveType(PrimitiveType::INT));
	divbysix->results()->append(divbysixResult);
	FormalArgument* arg = new FormalArgument();
	divbysix->arguments()->append(arg);
	arg->setName("numbers");
	ArrayType* argType = new ArrayType();
	argType->setType(new PrimitiveType(PrimitiveType::INT));
	arg->setType(argType);

	ExpressionStatement* es = new ExpressionStatement();
	es->setExpression( new EmptyExpression());
	divbysix->items()->append(es);

	VariableDeclaration* exprtest = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest));
	exprtest->setName("exprtest");
	exprtest->setType(new PrimitiveType(PrimitiveType::INT));
	exprtest->setInitialValue( OOExpressionBuilder::getOOExpression("+aa++&b,*e/d-#") );

	VariableDeclaration* exprtest2 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest2));
	exprtest2->setName("exprtest2");
	exprtest2->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest2->setInitialValue( OOExpressionBuilder::getOOExpression("a*b+c/e-d++%--e*-f==g") );

	VariableDeclaration* exprtest3 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest3));
	exprtest3->setName("exprtest3");
	exprtest3->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest3->setInitialValue( OOExpressionBuilder::getOOExpression("a<b||c>d&&e<=f|g&h^~i") );

	VariableDeclaration* exprtest4 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest4));
	exprtest4->setName("exprtest4");
	exprtest4->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest4->setInitialValue( OOExpressionBuilder::getOOExpression("new value[5]") );

	VariableDeclaration* exprtest5 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest5));
	exprtest5->setName("exprtest5");
	exprtest5->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest5->setInitialValue( OOExpressionBuilder::getOOExpression("(castto)object") );

	VariableDeclaration* exprtest6 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest6));
	exprtest6->setName("exprtest6");
	exprtest6->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest6->setInitialValue( OOExpressionBuilder::getOOExpression("{a,bb,ccc}") );

	VariableDeclaration* exprtest7 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest7));
	exprtest7->setName("exprtest7");
	exprtest7->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest7->setInitialValue( OOExpressionBuilder::getOOExpression("{{123,hello},{2,b}}") );

	VariableDeclaration* exprtest8 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest8));
	exprtest8->setName("exprtest8");
	exprtest8->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest8->setInitialValue( OOExpressionBuilder::getOOExpression("a.b+c.d[i].f") );

	VariableDeclaration* exprtest9 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest9));
	exprtest9->setName("exprtest9");
	exprtest9->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest9->setInitialValue( OOExpressionBuilder::getOOExpression("a()+a.b()+a.b[i].f().g()") );

	VariableDeclaration* exprtest10 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest10));
	exprtest10->setName("exprtest10");
	exprtest10->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest10->setInitialValue( OOExpressionBuilder::getOOExpression("this.b(a,b,c,123,false)") );

	VariableDeclaration* exprtest11 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest11));
	exprtest11->setName("exprtest11");
	exprtest11->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest11->setInitialValue( OOExpressionBuilder::getOOExpression("a+\"hello world\"") );

	VariableDeclaration* exprtest12 = new VariableDeclaration();
	divbysix->items()->append(new ExpressionStatement(exprtest12));
	exprtest12->setName("exprtest12");
	exprtest12->setType(new PrimitiveType(PrimitiveType::VOID));
	exprtest12->setInitialValue( OOExpressionBuilder::getOOExpression("int[]") );

	auto exprtest13 = dynamic_cast<AssignmentExpression*>( OOExpressionBuilder::getOOExpression("a=b%=c>>>=d+C"));
	divbysix->items()->append(new ExpressionStatement(exprtest13));

	divbysix->items()->append(new ExpressionStatement( OOExpressionBuilder::getOOExpression("int abc")));

	divbysix->items()->append(new ExpressionStatement( OOExpressionBuilder::getOOExpression("int abc=5+3")));

	divbysix->items()->append(new ExpressionStatement( OOExpressionBuilder::getOOExpression("int cond=abc<50?42:b+c")));

	VariableDeclaration* result = new VariableDeclaration();
	divbysix->items()->append( new ExpressionStatement(result) );
	result->setName("result");
	result->setType(new PrimitiveType(PrimitiveType::INT));
	result->setInitialValue(new IntegerLiteral(-1));

	LoopStatement* sixloop = new LoopStatement();
	divbysix->items()->append(sixloop);
	VariableDeclaration* sixLoopInit = new VariableDeclaration();
	sixloop->setInitStep(sixLoopInit);
	sixLoopInit->setName("i");
	sixLoopInit->setType(new PrimitiveType(PrimitiveType::INT));
	sixLoopInit->setInitialValue(new IntegerLiteral(0));
	BinaryOperation* sixLoopCond = new BinaryOperation();
	sixloop->setCondition(sixLoopCond);
	sixLoopCond->setLeft(new VariableAccess("local:i"));
	sixLoopCond->setOp(BinaryOperation::LESS);
	MethodCallExpression* sizeCall = new MethodCallExpression();
	sixLoopCond->setRight(sizeCall);
	sizeCall->ref()->set("size");
	sizeCall->setPrefix(new VariableAccess("local:numbers"));

	//TODO test the visualization without the remaining parts of this method
	AssignmentExpression* sixLoopUpdate = new AssignmentExpression();
	sixloop->setUpdateStep(sixLoopUpdate);
	sixLoopUpdate->setLeft(new VariableAccess("local:i"));
	sixLoopUpdate->setOp(AssignmentExpression::PLUS_ASSIGN);
	sixLoopUpdate->setRight(new IntegerLiteral(1));

	VariableDeclaration* n = new VariableDeclaration();
	sixloop->body()->append(new ExpressionStatement(n));
	n->setName("n");
	n->setType(new PrimitiveType(PrimitiveType::INT));
	BinaryOperation* item = new BinaryOperation();
	n->setInitialValue(item);
	item->setLeft(new VariableAccess("local:numbers"));
	item->setOp(BinaryOperation::ARRAY_INDEX);
	item->setRight(new VariableAccess("local:i"));

	IfStatement* ifdiv2 = new IfStatement();
	sixloop->body()->append(ifdiv2);
	BinaryOperation* eq0 = new BinaryOperation();
	ifdiv2->setCondition(eq0);
	eq0->setOp(BinaryOperation::EQUALS);
	eq0->setRight(new IntegerLiteral(0));
	BinaryOperation* div2 = new BinaryOperation();
	eq0->setLeft(div2);
	div2->setLeft(new VariableAccess("local:n"));
	div2->setOp(BinaryOperation::REMAINDER);
	div2->setRight(new IntegerLiteral(2));
	ifdiv2->elseBranch()->append(new ContinueStatement());

	IfStatement* ifdiv3 = new IfStatement();
	ifdiv2->thenBranch()->append(ifdiv3);
	eq0 = new BinaryOperation();
	ifdiv3->setCondition(eq0);
	eq0->setOp(BinaryOperation::EQUALS);
	eq0->setRight(new IntegerLiteral(0));
	BinaryOperation* div3 = new BinaryOperation();
	eq0->setLeft(div3);
	div3->setLeft(new VariableAccess("local:n"));
	div3->setOp(BinaryOperation::REMAINDER);
	div3->setRight(new IntegerLiteral(3));

	AssignmentExpression* resultFound = new AssignmentExpression();
	ifdiv3->thenBranch()->append(resultFound);
	resultFound->setLeft(new VariableAccess("local:result"));
	resultFound->setOp(AssignmentExpression::ASSIGN);
	resultFound->setRight(new VariableAccess("local:i"));
	ifdiv3->thenBranch()->append(new BreakStatement());

	ReturnStatement* divbysixReturn = new ReturnStatement();
	divbysixReturn->values()->append(new VariableAccess("local:result"));
	divbysix->items()->append(divbysixReturn);

	model->endModification();
	return divbysix;
}