本文整理汇总了C++中VariableSymbol::isResolvingConstExpr方法的典型用法代码示例。如果您正苦于以下问题:C++ VariableSymbol::isResolvingConstExpr方法的具体用法?C++ VariableSymbol::isResolvingConstExpr怎么用?C++ VariableSymbol::isResolvingConstExpr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableSymbol
的用法示例。
在下文中一共展示了VariableSymbol::isResolvingConstExpr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: helper
void
TypeResolver::visitVarDecl(VarDecl *node)
{
VariableSymbol *sym = node->sym();
assert(!sym->type());
Type* type;
if (TypeSpecifier *spec = node->te().spec()) {
// We always infer sizes for postdims in variable scope. In argument
// scope, we don't want something like:
//
// f(x[] = {}), or
//
// To infer as int[0]. However, this should be illegal:
//
// f(int x[] = {})
//
// So we simply never infer dimensions for arguments.
//
// Note: we should not be able to recurse from inside this block. If it
// could, we'd have to mark spec as resolving earlier.
Vector<int> literal_dims;
if (Expression *init = node->initialization()) {
if (spec->hasPostDims() && !sym->isArgument()) {
// Compute the dimensions of initializers in case the declaration type
// requires inference.
if (ArrayLiteral *lit = init->asArrayLiteral()) {
literal_dims = fixedArrayLiteralDimensions(spec, lit);
} else if (StringLiteral *lit = init->asStringLiteral()) {
literal_dims.append(lit->arrayLength());
}
}
}
VarDeclSpecHelper helper(node, &literal_dims);
type = resolveType(node->te(), &helper);
} else {
type = node->te().resolved();
}
if (!assignTypeToSymbol(sym, type))
return;
if (sym->isConstExpr() || !sym->canUseInConstExpr())
return;
// If we're currently trying to resolve this variable's constant
// expression, report an error.
if (sym->isResolvingConstExpr()) {
cc_.report(node->loc(), rmsg::recursive_constexpr)
<< sym->name();
// Pawn requires that const variables have constexprs, so we just set a
// default one to quell as many other errors as we can. In the future we
// may want to lax this restriction.
sym->setConstExpr(DefaultValueForPlainType(sym->type()));
return;
}
// We got a constexpr with no initialization. Just assume it's 0, but
// report an error as SP1 does.
if (!node->initialization()) {
cc_.report(node->loc(), rmsg::constant_var_needs_constexpr)
<< sym->name();
sym->setConstExpr(DefaultValueForPlainType(sym->type()));
return;
}
sym->setResolvingConstExpr();
// In Pawn, a const var *must* be a constexpr. We only care about this for
// ints/floats since constexprs aren't really relevant yet otherwise.
BoxedValue box;
ConstantEvaluator ceval(cc_, this, ConstantEvaluator::Required);
switch (ceval.Evaluate(node->initialization(), &box)) {
case ConstantEvaluator::Ok:
break;
case ConstantEvaluator::NotConstant:
cc_.report(node->loc(), rmsg::constant_var_needs_constexpr)
<< sym->name();
// FALLTHROUGH.
case ConstantEvaluator::TypeError:
// Error has already been reported.
box = DefaultValueForPlainType(sym->type());
break;
default:
assert(false);
}
// :TODO: type check box
sym->setConstExpr(box);
}