本文整理汇总了C++中Method::items方法的典型用法代码示例。如果您正苦于以下问题:C++ Method::items方法的具体用法?C++ Method::items怎么用?C++ Method::items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Method
的用法示例。
在下文中一共展示了Method::items方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(OOModel, JavaLibraryAndHelloWorldTest)
{
Model::Model model;
Project* prj = dynamic_cast<Project*> (model.createRoot("Project"));
model.beginModification(prj, "build simple java library and a hello world app");
prj->setName("HelloWorld");
// Build a simple Java Library
Library* java = prj->libraries()->append<Library>();
java->setName("Java");
Class* string = java->classes()->append<Class>();
string->setName("String");
string->setVisibility(Visibility::PUBLIC);
Module* io = java->modules()->append<Module>();
io->setName("io");
Class* printstream = io->classes()->append<Class>();
printstream->setName("PrintStream");
printstream->setVisibility(Visibility::PUBLIC);
Method* println = printstream->methods()->append<Method>();
println->setName("println");
println->setVisibility(Visibility::PUBLIC);
FormalArgument* arg = println->arguments()->append<FormalArgument>();
arg->setName("x");
NamedType* argType = arg->setType<NamedType>();
argType->type()->ref()->set("class:String");
Class* system = java->classes()->append<Class>();
system->setName("System");
system->setVisibility(Visibility::PUBLIC);
Field* out = system->fields()->append<Field>();
out->setName("out");
out->setVisibility(Visibility::PUBLIC);
out->setStorageSpecifier(StorageSpecifier::CLASS_VARIABLE);
NamedType* outtype = out->setType<NamedType>();
outtype->type()->ref()->set("class:PrintStream");
outtype->type()->setPrefix<ReferenceExpression>()->ref()->set("mod:io");
// Build a simple HelloWorld Application
Class* hello = prj->classes()->append<Class>();
hello->setName("HelloWorld");
hello->setVisibility(Visibility::PUBLIC);
Method* main = hello->methods()->append<Method>();
main->setName("main");
main->setVisibility(Visibility::PUBLIC);
main->setStorageSpecifier(StorageSpecifier::CLASS_VARIABLE);
//TODO make an array argument
MethodCallStatement* callPrintln = main->items()->append<MethodCallStatement>();
StringLiteral* helloStr = callPrintln->arguments()->append<StringLiteral>();
helloStr->setValue("Hello World");
callPrintln->ref()->set("met:println");
VariableAccess* va = callPrintln->setPrefix<VariableAccess>();
va->ref()->set("field:out");
ReferenceExpression* ref = va->setPrefix<ReferenceExpression>();
ref->ref()->set("lib:Java,class:System");
model.endModification();
CHECK_STR_EQUAL("Java", java->name());
CHECK_CONDITION(callPrintln->methodDefinition() != nullptr);
CHECK_CONDITION(callPrintln->methodDefinition() == println);
}
示例2: addDivBySix
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;
}
示例3: addComplicated
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));
//.........这里部分代码省略.........
示例4: addDivBySix
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"));
//.........这里部分代码省略.........