本文整理汇总了C++中Mapping::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Mapping::Add方法的具体用法?C++ Mapping::Add怎么用?C++ Mapping::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapping
的用法示例。
在下文中一共展示了Mapping::Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExpandFunction
void CallStmt::ExpandFunction(FunctionDef *func, Fragment *fragment)
{
size_t argCount = func->GetArgCount();
// check number of parameters
if (argCount != fParams.size())
{
Error(kErr_ParamCount).Raise(&fLocation);
return;
}
/* statement should look like this:
*
* CallStmt
* |
* InlineStmt
* |
* ScopeStmt
* |
* BlockStmt
* / | \
* DeclareStmt... body of function
*/
BlockStmt *block = new BlockStmt();
SetBody( new InlineStmt(new ScopeStmt(block), func));
Mapping mapping;
for(size_t i=0; i<argCount; i++)
{
const Expr* arg = fParams[i];
int var = func->GetArgVar(i);
int val;
switch(func->GetArgType(i))
{
case FunctionDef::kConstantArg:
if (!arg->Evaluate(val))
{
Error(kErr_ParamType, "constant").Raise(&arg->GetLoc());
return;
}
mapping.Add(var, new AtomExpr(kRCX_ConstantType, val, fLocation));
break;
case FunctionDef::kIntegerArg:
val = gProgram->NextVirtualVar();
mapping.Add(var, new AtomExpr(kRCX_VariableType, val, fLocation));
{
DeclareStmt *ds = new DeclareStmt(func->GetArgName(i), val, fLocation, 1, false, true);
ds->SetInitialValue(arg->Clone(0));
block->Add(ds);
}
break;
case FunctionDef::kReferenceArg:
val = arg->GetLValue();
if (val == kIllegalVar)
{
Error(kErr_ParamType, "variable").Raise(&arg->GetLoc());
return;
}
mapping.Add(var, new AtomExpr(kRCX_VariableType, val, fLocation));
break;
case FunctionDef::kConstRefArg:
mapping.Add(var, arg->Clone(0));
break;
case FunctionDef::kSensorArg:
if (RCX_VALUE_TYPE(arg->GetStaticEA()) != kRCX_InputValueType)
{
Error(kErr_ParamType, "sensor").Raise(&arg->GetLoc());
return;
}
mapping.Add(var, arg->Clone(0));
break;
case FunctionDef::kPointerArg:
if (!arg->LValueIsPointer())
{
Error(kErr_ParamType, "pointer").Raise(&arg->GetLoc());
return;
}
mapping.Add(var, arg->Clone(0));
break;
case FunctionDef::kConstPtrArg:
if (!arg->LValueIsPointer())
{
Error(kErr_ParamType, "pointer").Raise(&arg->GetLoc());
return;
}
val = gProgram->NextVirtualVar();
{
DeclareStmt *ds = new DeclareStmt(func->GetArgName(i), val, fLocation, 1, true, true);
ds->SetInitialValue(arg->Clone(0));
block->Add(ds);
}
mapping.Add(var, new AtomExpr(kRCX_VariableType, val, fLocation, true));
break;
default:
Error(kErr_ParamType, "???").Raise(&fParams[i]->GetLoc());
return;
}
}
//.........这里部分代码省略.........