本文整理汇总了C++中QualType::addConst方法的典型用法代码示例。如果您正苦于以下问题:C++ QualType::addConst方法的具体用法?C++ QualType::addConst怎么用?C++ QualType::addConst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QualType
的用法示例。
在下文中一共展示了QualType::addConst方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
C2::ExprResult C2Sema::ActOnTypeQualifier(ExprResult R, unsigned qualifier) {
assert(R.get());
if (qualifier) {
#ifdef SEMA_DEBUG
std::cerr << COL_SEMA << "SEMA: Qualifier Type" << ANSI_NORMAL"\n";
#endif
TypeExpr* typeExpr = cast<TypeExpr>(R.get());
// TODO use typeExpr.addConst() and just return QualType (not ref) in getType()
QualType qt = typeExpr->getType();
if (qualifier & TYPE_CONST) qt.addConst();
if (qualifier & TYPE_VOLATILE) qt.addVolatile();
if (qualifier & TYPE_LOCAL) typeExpr->setLocalQualifier();
typeExpr->setType(qt);
}
return R;
}
示例2: resolveUnresolved
QualType TypeResolver::resolveUnresolved(QualType Q) const {
const Type* T = Q.getTypePtr();
switch (Q->getTypeClass()) {
case TC_BUILTIN:
return Q;
case TC_POINTER:
{
// Dont return new type if not needed
const PointerType* P = cast<PointerType>(T);
QualType t1 = P->getPointeeType();
QualType Result = resolveUnresolved(t1);
if (t1 == Result) return Q;
// TODO qualifiers
return typeContext.getPointerType(Result);
}
case TC_ARRAY:
{
const ArrayType* A = cast<ArrayType>(T);
QualType t1 = A->getElementType();
QualType Result = resolveUnresolved(t1);
if (t1 == Result) return Q;
// TODO qualifiers
return typeContext.getArrayType(Result, A->getSizeExpr(), false, A->isIncremental());
}
case TC_UNRESOLVED:
{
const UnresolvedType* U = cast<UnresolvedType>(T);
TypeDecl* TD = U->getDecl();
assert(TD);
QualType result = TD->getType();
if (Q.isConstQualified()) result.addConst();
if (Q.isVolatileQualified()) result.addVolatile();
return result;
}
case TC_ALIAS:
case TC_STRUCT:
case TC_ENUM:
case TC_FUNCTION:
return Q;
case TC_MODULE:
assert(0 && "TBD");
return Q;
}
return Q;
}
示例3: new
Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
TypeSourceInfo *EncodedTypeInfo,
SourceLocation RParenLoc) {
QualType EncodedType = EncodedTypeInfo->getType();
QualType StrTy;
if (EncodedType->isDependentType())
StrTy = Context.DependentTy;
else {
std::string Str;
Context.getObjCEncodingForType(EncodedType, Str);
// The type of @encode is the same as the type of the corresponding string,
// which is an array type.
StrTy = Context.CharTy;
// A C++ string literal has a const-qualified element type (C++ 2.13.4p1).
if (getLangOptions().CPlusPlus || getLangOptions().ConstStrings)
StrTy.addConst();
StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1),
ArrayType::Normal, 0);
}
return new (Context) ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
}
示例4: CheckPointerToMemberOperands
QualType Sema::CheckPointerToMemberOperands(
Expr *&lex, Expr *&rex, SourceLocation Loc, bool isIndirect)
{
const char *OpSpelling = isIndirect ? "->*" : ".*";
// C++ 5.5p2
// The binary operator .* [p3: ->*] binds its second operand, which shall
// be of type "pointer to member of T" (where T is a completely-defined
// class type) [...]
QualType RType = rex->getType();
const MemberPointerType *MemPtr = RType->getAsMemberPointerType();
if (!MemPtr) {
Diag(Loc, diag::err_bad_memptr_rhs)
<< OpSpelling << RType << rex->getSourceRange();
return QualType();
} else if (RequireCompleteType(Loc, QualType(MemPtr->getClass(), 0),
diag::err_memptr_rhs_incomplete,
rex->getSourceRange()))
return QualType();
QualType Class(MemPtr->getClass(), 0);
// C++ 5.5p2
// [...] to its first operand, which shall be of class T or of a class of
// which T is an unambiguous and accessible base class. [p3: a pointer to
// such a class]
QualType LType = lex->getType();
if (isIndirect) {
if (const PointerType *Ptr = LType->getAsPointerType())
LType = Ptr->getPointeeType().getNonReferenceType();
else {
Diag(Loc, diag::err_bad_memptr_lhs)
<< OpSpelling << 1 << LType << lex->getSourceRange();
return QualType();
}
}
if (Context.getCanonicalType(Class).getUnqualifiedType() !=
Context.getCanonicalType(LType).getUnqualifiedType()) {
BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/false,
/*DetectVirtual=*/false);
// FIXME: Would it be useful to print full ambiguity paths,
// or is that overkill?
if (!IsDerivedFrom(LType, Class, Paths) ||
Paths.isAmbiguous(Context.getCanonicalType(Class))) {
Diag(Loc, diag::err_bad_memptr_lhs) << OpSpelling
<< (int)isIndirect << lex->getType() << lex->getSourceRange();
return QualType();
}
}
// C++ 5.5p2
// The result is an object or a function of the type specified by the
// second operand.
// The cv qualifiers are the union of those in the pointer and the left side,
// in accordance with 5.5p5 and 5.2.5.
// FIXME: This returns a dereferenced member function pointer as a normal
// function type. However, the only operation valid on such functions is
// calling them. There's also a GCC extension to get a function pointer to
// the thing, which is another complication, because this type - unlike the
// type that is the result of this expression - takes the class as the first
// argument.
// We probably need a "MemberFunctionClosureType" or something like that.
QualType Result = MemPtr->getPointeeType();
if (LType.isConstQualified())
Result.addConst();
if (LType.isVolatileQualified())
Result.addVolatile();
return Result;
}
示例5: QT
//.........这里部分代码省略.........
VarDecl* Arg3 = new VarDecl(VARDECL_PARAM, "n", loc, Type::UInt32(), 0, true);
Arg3->setType(Type::UInt32());
func->addArg(Arg3);
stringMod->addSymbol(func);
// function type
func->setType(QualType(new FunctionType(func), 0));
}
return stringMod;
}
if (name == "stdlib") {
Module* stdlibMod = new C2::Module("stdlib", true, true);
//void exit(int status);
{
FunctionDecl* func = new FunctionDecl("exit", loc, true, Type::Void());
// TODO correct arg
VarDecl* Arg1 = new VarDecl(VARDECL_PARAM, "status", loc, Type::Int32(), 0, true);
Arg1->setType(Type::Int32());
func->addArg(Arg1);
stdlibMod->addSymbol(func);
// function type
func->setType(QualType(new FunctionType(func), 0));
}
return stdlibMod;
}
if (name == "c2") {
Module* c2Mod = new C2::Module("c2", true, false);
// uint64 buildtime
{
// make constant, CTC_NONE
QualType QT = Type::UInt64();
QT.addConst();
uint64_t value = time(0);
Expr* init = new IntegerLiteral(loc, llvm::APInt(64, value, false));
// TODO get error without value if CTC_NONE, CTC_FULL gives out-of-bounds for value 123?!!
init->setCTC(CTC_NONE); // Don't check range, only type
init->setConstant();
init->setType(QT);
VarDecl* var = new VarDecl(VARDECL_GLOBAL, "buildtime", loc, QT, init, true);
var->setType(QT);
c2Mod->addSymbol(var);
}
// int8 min_int8
{
QualType QT = Type::Int8();
QT.addConst();
Expr* init = new IntegerLiteral(loc, llvm::APInt(64, -128, true));
init->setCTC(CTC_FULL);
init->setConstant();
init->setType(QT);
VarDecl* var = new VarDecl(VARDECL_GLOBAL, "min_int8", loc, QT, init, true);
var->setType(QT);
c2Mod->addSymbol(var);
}
// int8 max_int8
{
QualType QT = Type::Int8();
QT.addConst();
Expr* init = new IntegerLiteral(loc, llvm::APInt(64, 127, true));
init->setCTC(CTC_FULL);
init->setConstant();
init->setType(QT);
VarDecl* var = new VarDecl(VARDECL_GLOBAL, "max_int8", loc, QT, init, true);
var->setType(QT);