本文整理汇总了C++中Procedure::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Procedure::getValue方法的具体用法?C++ Procedure::getValue怎么用?C++ Procedure::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Procedure
的用法示例。
在下文中一共展示了Procedure::getValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assign
Variable* assign(Variable* A, Variable* B)
{
if(A == NULL || B == NULL)
{
interpreter.error("Error: Void variable in assignment.\n");
return NULL;
}
if(!A->reference)
{
interpreter.error("Error: Assigning value to a non-reference variable.\n");
return NULL;
}
TypeEnum a = A->getType();
TypeEnum b = B->getType();
bool mismatch = false;
if(a == STRING)
{
if(b != STRING)
mismatch = true;
else
{
String* C = static_cast<String*>(A);
String* D = static_cast<String*>(B);
C->setValue(D->getValue());
}
}
else if(a == INT)
{
if(b != BOOL && b != INT && b != FLOAT)
mismatch = true;
else
{
Int* C = static_cast<Int*>(A);
if(b == BOOL)
{
Bool* D = static_cast<Bool*>(B);
C->setValue(D->getValue());
}
else if(b == INT)
{
Int* D = static_cast<Int*>(B);
C->setValue(D->getValue());
}
else
{
Float* D = static_cast<Float*>(B);
C->setValue(D->getValue());
}
}
}
else if(a == FLOAT)
{
if(b != BOOL && b != INT && b != FLOAT)
mismatch = true;
else
{
Float* C = static_cast<Float*>(A);
if(b == BOOL)
{
Bool* D = static_cast<Bool*>(B);
C->setValue(D->getValue());
}
else if(b == INT)
{
Int* D = static_cast<Int*>(B);
C->setValue(D->getValue());
}
else
{
Float* D = static_cast<Float*>(B);
C->setValue(D->getValue());
}
}
}
else if(a == BOOL)
{
if(b != BOOL && b != INT && b != FLOAT)
mismatch = true;
else
{
Bool* C = static_cast<Bool*>(A);
if(b == BOOL)
{
Bool* D = static_cast<Bool*>(B);
C->setValue(D->getValue());
}
else if(b == INT)
{
Int* D = static_cast<Int*>(B);
C->setValue(D->getValue());
}
else
{
Float* D = static_cast<Float*>(B);
C->setValue(D->getValue());
}
}
}
//.........这里部分代码省略.........
示例2: add
Variable* add(Variable* A, Variable* B)
{
if(A == NULL || B == NULL)
{
interpreter.error("Error: Void variable in addition.\n");
return NULL;
}
TypeEnum a = A->getType();
TypeEnum b = B->getType();
if(a != b && !(a == FLOAT && b == INT) && !(b == FLOAT && a == INT))
{
interpreter.error("Error: Types do not match in addition: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
return NULL;
}
if(a == STRING)
{
String* C = static_cast<String*>(A);
String* D = static_cast<String*>(B);
String* R = new String("<temp>");
R->setValue(C->getValue() + D->getValue());
return R;
}
else if(a == INT)
{
Int* C = static_cast<Int*>(A);
if(b == INT)
{
Int* D = static_cast<Int*>(B);
Int* R = new Int;
R->setValue(C->getValue() + D->getValue());
return R;
}
else
{
Float* D = static_cast<Float*>(B);
Float* R = new Float;
R->setValue(C->getValue() + D->getValue());
return R;
}
}
else if(a == FLOAT)
{
Float* C = static_cast<Float*>(A);
Float* R = new Float;
if(b == INT)
{
Int* D = static_cast<Int*>(B);
R->setValue(C->getValue() + D->getValue());
}
else
{
Float* D = static_cast<Float*>(B);
R->setValue(C->getValue() + D->getValue());
}
return R;
}
else if(a == BOOL)
{
interpreter.error("Error: Addition operation not defined for type 'bool'.\n");
return NULL;
}
else if(a == MACRO)
{
Macro* C = static_cast<Macro*>(A);
Macro* D = static_cast<Macro*>(B);
Macro* R = new Macro;
R->setValue(C->getValue() + D->getValue());
return R;
}
else if(a == ARRAY)
{
Array* C = static_cast<Array*>(A);
Array* D = static_cast<Array*>(B);
a = C->getValueType();
b = D->getValueType();
if(a != b)
{
interpreter.error("Error: Types do not match in addition: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
return NULL;
}
vector<Variable*> va = C->getValue();
vector<Variable*>& vb = D->getValue();
for(vector<Variable*>::iterator e = vb.begin(); e != vb.end(); e++)
{
va.push_back(*e);
}
Array* arr = new Array("<temp>", va, a);
return arr;
}
else if(a == LIST)
{
List* C = static_cast<List*>(A);
List* D = static_cast<List*>(B);
list<Variable*> va = C->getValue();
list<Variable*>& vb = D->getValue();
//.........这里部分代码省略.........
示例3: comparison
Bool* comparison(Variable* A, Variable* B, OperatorEnum oper)
{
if(A == NULL || B == NULL)
{
interpreter.error("Error: Void variable in assignment.\n");
return NULL;
}
TypeEnum a = A->getType();
TypeEnum b = B->getType();
bool mismatch = false;
if(a == STRING)
{
if(b != STRING)
mismatch = true;
else
{
String* C = static_cast<String*>(A);
String* D = static_cast<String*>(B);
switch(oper)
{
case EQUALS:
return new Bool(C->getValue() == D->getValue());
case NOT_GREATER:
case LESS_EQUAL:
return new Bool(C->getValue() <= D->getValue());
case NOT_LESS:
case GREATER_EQUAL:
return new Bool(C->getValue() >= D->getValue());
case LESS:
return new Bool(C->getValue() < D->getValue());
case GREATER:
return new Bool(C->getValue() > D->getValue());
case NOT_EQUALS:
return new Bool(C->getValue() != D->getValue());
default:
UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
return NULL;
}
}
}
else if(a == INT)
{
if(b != BOOL && b != INT && b != FLOAT)
mismatch = true;
else
{
Int* C = static_cast<Int*>(A);
if(b == BOOL)
{
Bool* D = static_cast<Bool*>(B);
switch(oper)
{
case EQUALS:
return new Bool(C->getValue() == D->getValue());
case NOT_GREATER:
case LESS_EQUAL:
return new Bool(C->getValue() <= D->getValue());
case NOT_LESS:
case GREATER_EQUAL:
return new Bool(C->getValue() >= D->getValue());
case LESS:
return new Bool(C->getValue() < D->getValue());
case GREATER:
return new Bool(C->getValue() > D->getValue());
case AND:
return new Bool(C->getValue() && D->getValue());
case OR:
return new Bool(C->getValue() || D->getValue());
case NOT_EQUALS:
return new Bool(C->getValue() != D->getValue());
default:
UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
return NULL;
}
}
else if(b == INT)
{
Int* D = static_cast<Int*>(B);
switch(oper)
{
case EQUALS:
return new Bool(C->getValue() == D->getValue());
case NOT_GREATER:
case LESS_EQUAL:
return new Bool(C->getValue() <= D->getValue());
case NOT_LESS:
case GREATER_EQUAL:
return new Bool(C->getValue() >= D->getValue());
case LESS:
return new Bool(C->getValue() < D->getValue());
case GREATER:
return new Bool(C->getValue() > D->getValue());
case AND:
return new Bool(C->getValue() && D->getValue());
case OR:
return new Bool(C->getValue() || D->getValue());
case NOT_EQUALS:
return new Bool(C->getValue() != D->getValue());
//.........这里部分代码省略.........