本文整理汇总了C++中ExpressionPtr::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionPtr::getType方法的具体用法?C++ ExpressionPtr::getType怎么用?C++ ExpressionPtr::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionPtr
的用法示例。
在下文中一共展示了ExpressionPtr::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkParamTypeCodeErrors
void FunctionCall::checkParamTypeCodeErrors(AnalysisResultPtr ar) {
if (!m_funcScope || m_arrayParams) return;
for (int i = 0, n = m_funcScope->getMaxParamCount(); i < n; ++i) {
TypePtr specType = m_funcScope->getParamTypeSpec(i);
if (!specType) continue;
const char *fmt = 0;
string ptype;
if (!m_params || m_params->getCount() <= i) {
if (i >= m_funcScope->getMinParamCount()) break;
fmt = "parameter %d of %s() requires %s, none given";
} else {
ExpressionPtr param = (*m_params)[i];
if (!Type::Inferred(ar, param->getType(), specType)) {
fmt = "parameter %d of %s() requires %s, called with %s";
}
ptype = param->getType()->toString();
}
if (fmt) {
string msg;
string_printf
(msg, fmt,
i + 1,
escapeStringForCPP(m_funcScope->getOriginalName()).c_str(),
specType->toString().c_str(), ptype.c_str());
Compiler::Error(Compiler::BadArgumentType,
shared_from_this(), msg);
}
}
}
示例2: buildPtrOfFunction
ExpressionPtr buildPtrOfFunction(const ExpressionPtr& funExpr) {
assert_true(funExpr->getType().isa<FunctionTypePtr>()) << "Trying to build a ptr of a non-function type:\n" << dumpColor(funExpr)
<< "\nType: " << dumpColor(funExpr->getType());
IRBuilder builder(funExpr->getNodeManager());
auto& pExt = funExpr->getNodeManager().getLangExtension<PointerExtension>();
return builder.callExpr(pExt.getPtrOfFunction(), funExpr);
}
示例3: analyzeProgram
void FunctionCall::analyzeProgram(AnalysisResultPtr ar) {
if (m_class) m_class->analyzeProgram(ar);
if (m_nameExp) m_nameExp->analyzeProgram(ar);
if (m_params) m_params->analyzeProgram(ar);
if (ar->getPhase() == AnalysisResult::AnalyzeFinal) {
if (m_funcScope && !m_arrayParams) {
for (int i = 0, n = m_funcScope->getMaxParamCount(); i < n; ++i) {
if (TypePtr specType = m_funcScope->getParamTypeSpec(i)) {
const char *fmt = 0;
string ptype;
if (!m_params || m_params->getCount() <= i) {
if (i >= m_funcScope->getMinParamCount()) break;
fmt = "parameter %d of %s() requires %s, none given";
} else {
ExpressionPtr param = (*m_params)[i];
if (!Type::Inferred(ar, param->getType(), specType)) {
fmt = "parameter %d of %s() requires %s, called with %s";
}
ptype = param->getType()->toString();
}
if (fmt) {
string msg;
Util::string_printf
(msg, fmt,
i + 1,
Util::escapeStringForCPP(m_funcScope->getOriginalName()).c_str(),
specType->toString().c_str(), ptype.c_str());
Compiler::Error(Compiler::BadArgumentType,
shared_from_this(), msg);
}
}
}
}
}
}
示例4: updateStruct
/*
* Changes the type of the field of a struct
*/
void updateStruct(const ExpressionPtr& structure, TypePtr& type, const ExpressionPtr& identifier) {
NodeManager& mgr = structure->getNodeManager();
IRBuilder builder(mgr);
TypePtr baseType = structure->getType();
RefTypePtr refTy = baseType.isa<RefTypePtr>();
StructTypePtr kst = refTy ? refTy->getElementType().as<StructTypePtr>() : structure->getType().as<StructTypePtr>();
std::string name = identifier->toString();
NamedTypePtr oldType = kst->getNamedTypeEntryOf(name);
NamedTypePtr newType = builder.namedType(name, refTy ? builder.refType(type) : type);
TypePtr newStructType = transform::replaceAll(mgr, baseType, oldType, newType).as<TypePtr>();
type = newStructType;
}
示例5: buildPtrFromIntegral
ExpressionPtr buildPtrFromIntegral(const ExpressionPtr& intExpr, const TypePtr& ptrType) {
assert_pred1(intExpr->getNodeManager().getLangBasic().isInt, intExpr->getType()) << "Trying to build ptr from non-integral.";
assert_pred1(isPointer, ptrType) << "Trying to build non-ptr-type from integral.";
IRBuilder builder(intExpr->getNodeManager());
auto& pExt = intExpr->getNodeManager().getLangExtension<PointerExtension>();
return builder.callExpr(pExt.getPtrFromIntegral(), intExpr, builder.getTypeLiteral(ptrType));
}
示例6: buildPtrSubscript
ExpressionPtr buildPtrSubscript(const ExpressionPtr& ptrExpr, const ExpressionPtr& subscriptExpr) {
assert_pred1(isPointer, ptrExpr) << "Trying to build a ptr subscript from non-ptr.";
assert_pred1(ptrExpr->getNodeManager().getLangBasic().isInt, subscriptExpr->getType()) << "Trying to build a ptr subscript with non-integral subscript.";
IRBuilder builder(ptrExpr->getNodeManager());
auto& pExt = ptrExpr->getNodeManager().getLangExtension<PointerExtension>();
return builder.callExpr(pExt.getPtrSubscript(), ptrExpr, subscriptExpr);
}
示例7: inferTypes
TypePtr ClosureExpression::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
if (m_vars) {
assert(m_values && m_values->getCount() == m_vars->getCount());
// containing function's variable table (not closure function's)
VariableTablePtr variables = getScope()->getVariables();
// closure function's variable table
VariableTablePtr cvariables = m_func->getFunctionScope()->getVariables();
// force all reference use vars into variant for this function scope
for (int i = 0; i < m_vars->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_vars)[i]);
const string &name = param->getName();
if (param->isRef()) {
variables->forceVariant(ar, name, VariableTable::AnyVars);
}
}
// infer the types of the values
m_values->inferAndCheck(ar, Type::Some, false);
// coerce the types inferred from m_values into m_vars
for (int i = 0; i < m_vars->getCount(); i++) {
ExpressionPtr value = (*m_values)[i];
ParameterExpressionPtr var =
dynamic_pointer_cast<ParameterExpression>((*m_vars)[i]);
assert(!var->getExpectedType());
assert(!var->getImplementedType());
if (var->isRef()) {
var->setActualType(Type::Variant);
} else {
TypePtr origVarType(var->getActualType() ?
var->getActualType() : Type::Some);
var->setActualType(Type::Coerce(ar, origVarType, value->getType()));
}
}
{
// this lock isn't technically needed for thread-safety, since
// the dependencies are all set up. however, the lock assertions
// will fail if we don't acquire it.
GET_LOCK(m_func->getFunctionScope());
// bootstrap the closure function's variable table with
// the types from m_vars
for (int i = 0; i < m_vars->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_vars)[i]);
const string &name = param->getName();
cvariables->addParamLike(name, param->getType(), ar,
shared_from_this(),
getScope()->isFirstPass());
}
}
}
return s_ClosureType;
}
示例8: replaceValue
ExpressionPtr Expression::replaceValue(ExpressionPtr rep) {
if (hasContext(Expression::RefValue) &&
isRefable(true) && !rep->isRefable(true)) {
/*
An assignment isRefable, but the rhs may not be. Need this to
prevent "bad pass by reference" errors.
*/
ExpressionListPtr el(new ExpressionList(getScope(), getRange(),
ExpressionList::ListKindWrapped));
el->addElement(rep);
rep->clearContext(AssignmentRHS);
rep = el;
}
if (rep->is(KindOfSimpleVariable) && !is(KindOfSimpleVariable)) {
static_pointer_cast<SimpleVariable>(rep)->setAlwaysStash();
}
rep->copyContext(m_context & ~(DeadStore|AccessContext));
if (TypePtr t1 = getType()) {
if (TypePtr t2 = rep->getType()) {
if (!Type::SameType(t1, t2)) {
rep->setExpectedType(t1);
}
}
}
if (rep->getScope() != getScope()) {
rep->resetScope(getScope());
}
return rep;
}
示例9: buildPtrFromArray
ExpressionPtr buildPtrFromArray(const ExpressionPtr& arrExpr) {
assert_pred1(isReference, arrExpr) << "Trying to buildPtrFromArray from non-ref.";
assert_pred1(isArray, core::analysis::getReferencedType(arrExpr->getType())) << "Trying to buildPtrFromArray from non-array.";
IRBuilder builder(arrExpr->getNodeManager());
auto& pExt = arrExpr->getNodeManager().getLangExtension<PointerExtension>();
return builder.callExpr(pExt.getPtrFromArray(), arrExpr);
}
示例10: buildPtrReinterpret
ExpressionPtr buildPtrReinterpret(const ExpressionPtr& ptrExpr, const TypePtr& newElementType) {
assert_pred1(core::lang::isPointer, ptrExpr) << "Trying to build a ptr reinterpret from non-ptr.";
PointerType srcTy(ptrExpr->getType());
// early exit if there is nothing to do
if(srcTy.getElementType() == newElementType) return ptrExpr;
// otherwise, build reinterpret
IRBuilder builder(ptrExpr->getNodeManager());
auto& pExt = ptrExpr->getNodeManager().getLangExtension<PointerExtension>();
return builder.callExpr(pExt.getPtrReinterpret(), ptrExpr, builder.getTypeLiteral(newElementType));
}
示例11: buildPtrCast
ExpressionPtr buildPtrCast(const ExpressionPtr& ptrExpr, bool newConst, bool newVolatile) {
assert_pred1(core::lang::isPointer, ptrExpr) << "Trying to build a ptr cast from non-ptr.";
PointerType srcTy(ptrExpr->getType());
// early exit if there is nothing to do
if(srcTy.isConst() == newConst && srcTy.isVolatile() == newVolatile) return ptrExpr;
// otherwise, build cast
IRBuilder builder(ptrExpr->getNodeManager());
auto& pExt = ptrExpr->getNodeManager().getLangExtension<PointerExtension>();
auto& bmExt = ptrExpr->getNodeManager().getLangExtension<BooleanMarkerExtension>();
return builder.callExpr(pExt.getPtrCast(), ptrExpr, bmExt.getMarkerTypeLiteral(newConst), bmExt.getMarkerTypeLiteral(newVolatile));
}
示例12: wrapBoolean
void QOpExpression::wrapBoolean(CodeGenerator &cg,
AnalysisResultPtr ar,
ExpressionPtr exp) {
TypePtr t(exp->getType());
ASSERT(t);
bool wrap = false;
if (!t->is(Type::KindOfBoolean)) {
wrap = true;
cg_printf("toBoolean(");
}
exp->outputCPP(cg, ar);
if (wrap) cg_printf(")");
}
示例13: buildPtrOperation
ExpressionPtr buildPtrOperation(BasicGenerator::Operator op, const ExpressionPtr& ptrExpr) {
assert_true(isReference(ptrExpr) && isPointer(core::analysis::getReferencedType(ptrExpr->getType())))
<< "Trying to build a unary pointer operation with non-ref<ptr>.";
IRBuilder builder(ptrExpr->getNodeManager());
auto& pExt = ptrExpr->getNodeManager().getLangExtension<PointerExtension>();
switch(op) {
case BasicGenerator::Operator::PostInc: return builder.callExpr(pExt.getPtrPostInc(), ptrExpr);
case BasicGenerator::Operator::PostDec: return builder.callExpr(pExt.getPtrPostDec(), ptrExpr);
case BasicGenerator::Operator::PreInc: return builder.callExpr(pExt.getPtrPreInc(), ptrExpr);
case BasicGenerator::Operator::PreDec: return builder.callExpr(pExt.getPtrPreDec(), ptrExpr);
default: break;
}
assert_fail() << "Unsupported unary pointer operation " << op;
return ExpressionPtr();
}
示例14: CheckNeededRHS
bool Expression::CheckNeededRHS(ExpressionPtr value) {
bool needed = true;
always_assert(value);
while (value->is(KindOfAssignmentExpression)) {
value = dynamic_pointer_cast<AssignmentExpression>(value)->getValue();
}
if (value->isScalar()) {
needed = false;
} else {
TypePtr type = value->getType();
if (type && (type->is(Type::KindOfSome) || type->is(Type::KindOfAny))) {
type = value->getActualType();
}
if (type && type->isNoObjectInvolved()) needed = false;
}
return needed;
}
示例15: updateParams
void RefDict::updateParams() {
ControlFlowGraph *g = m_am.graph();
ControlBlock *b = g->getDfBlock(1);
BitOps::Bits *refbv = b->getRow(DataFlow::PRefIn);
BitOps::Bits *objbv = b->getRow(DataFlow::PObjIn);
for (int i = size(); i--; ) {
if (ExpressionPtr e = get(i)) {
always_assert(e->is(Expression::KindOfSimpleVariable));
always_assert(((unsigned int)i) == e->getCanonID());
Symbol *sym = static_pointer_cast<SimpleVariable>(e)->getSymbol();
if (sym && (sym->isParameter() || sym->isClosureVar())) {
TypePtr paramType;
bool isRef;
if (sym->isParameter()) {
ExpressionListPtr methodParams = m_method_stmt->getParams();
ExpressionPtr paramExprPtr =
(*methodParams)[sym->getParameterIndex()];
paramType = paramExprPtr->getType();
isRef = m_method_stmt->isRef(sym->getParameterIndex());
} else {
assert(sym->isClosureVar());
// can only assume it is a Variant for now
paramType = Type::Variant;
isRef = sym->isRefClosureVar();
}
if (first_pass) {
if (isRef || sym->isCallTimeRef()) {
BitOps::set_bit(i, refbv, true);
}
} else {
if (paramType) {
if (!paramType->isNoObjectInvolved()) {
BitOps::set_bit(i, objbv, true);
}
} else {
// no type information, so we must assume it holds an object
BitOps::set_bit(i, objbv, true);
}
}
}
}
}
}