本文整理汇总了C++中TypeSourceInfo类的典型用法代码示例。如果您正苦于以下问题:C++ TypeSourceInfo类的具体用法?C++ TypeSourceInfo怎么用?C++ TypeSourceInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TypeSourceInfo类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VisitCompoundStmt
bool VisitCompoundStmt(CompoundStmt* CS) {
for(CompoundStmt::body_iterator I = CS->body_begin(), E = CS->body_end();
I != E; ++I) {
if (!isa<BinaryOperator>(*I))
continue;
const BinaryOperator* BinOp = cast<BinaryOperator>(*I);
if (isAutoCandidate(BinOp)) {
ASTContext& C = m_Sema->getASTContext();
VarDecl* VD
= cast<VarDecl>(cast<DeclRefExpr>(BinOp->getLHS())->getDecl());
TypeSourceInfo* ResTSI = 0;
TypeSourceInfo* TrivialTSI
= C.getTrivialTypeSourceInfo(VD->getType());
Expr* RHS = BinOp->getRHS();
m_Sema->DeduceAutoType(TrivialTSI, RHS, ResTSI);
VD->setTypeSourceInfo(ResTSI);
VD->setType(ResTSI->getType());
VD->setInit(RHS);
Sema::DeclGroupPtrTy VDPtrTy = m_Sema->ConvertDeclToDeclGroup(VD);
// Transform the AST into a "sane" state. Replace the binary operator
// with decl stmt, because the binop semantically is a decl with init.
StmtResult DS = m_Sema->ActOnDeclStmt(VDPtrTy, BinOp->getLocStart(),
BinOp->getLocEnd());
assert(!DS.isInvalid() && "Invalid DeclStmt.");
*I = DS.take();
}
}
return true; // returning false will abort the in-depth traversal.
}
示例2: assert
TemplateArgumentLoc
Sema::getTemplateArgumentPackExpansionPattern(
TemplateArgumentLoc OrigLoc,
SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
const TemplateArgument &Argument = OrigLoc.getArgument();
assert(Argument.isPackExpansion());
switch (Argument.getKind()) {
case TemplateArgument::Type: {
// FIXME: We shouldn't ever have to worry about missing
// type-source info!
TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
if (!ExpansionTSInfo)
ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
Ellipsis);
PackExpansionTypeLoc Expansion =
ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
Ellipsis = Expansion.getEllipsisLoc();
TypeLoc Pattern = Expansion.getPatternLoc();
NumExpansions = Expansion.getTypePtr()->getNumExpansions();
// We need to copy the TypeLoc because TemplateArgumentLocs store a
// TypeSourceInfo.
// FIXME: Find some way to avoid the copy?
TypeLocBuilder TLB;
TLB.pushFullCopy(Pattern);
TypeSourceInfo *PatternTSInfo =
TLB.getTypeSourceInfo(Context, Pattern.getType());
return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
PatternTSInfo);
}
case TemplateArgument::Expression: {
PackExpansionExpr *Expansion
= cast<PackExpansionExpr>(Argument.getAsExpr());
Expr *Pattern = Expansion->getPattern();
Ellipsis = Expansion->getEllipsisLoc();
NumExpansions = Expansion->getNumExpansions();
return TemplateArgumentLoc(Pattern, Pattern);
}
case TemplateArgument::TemplateExpansion:
Ellipsis = OrigLoc.getTemplateEllipsisLoc();
NumExpansions = Argument.getNumTemplateExpansions();
return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
OrigLoc.getTemplateQualifierLoc(),
OrigLoc.getTemplateNameLoc());
case TemplateArgument::Declaration:
case TemplateArgument::NullPtr:
case TemplateArgument::Template:
case TemplateArgument::Integral:
case TemplateArgument::Pack:
case TemplateArgument::Null:
return TemplateArgumentLoc();
}
llvm_unreachable("Invalid TemplateArgument Kind!");
}
示例3: VisitFriendDecl
void VisitFriendDecl(const FriendDecl *D) {
TypeSourceInfo *TSI = D->getFriendType();
Hash.AddBoolean(TSI);
if (TSI) {
AddQualType(TSI->getType());
} else {
AddDecl(D->getFriendDecl());
}
}
示例4: GetTypeFromParser
TypeResult Sema::ActOnPackExpansion(ParsedType Type,
SourceLocation EllipsisLoc) {
TypeSourceInfo *TSInfo;
GetTypeFromParser(Type, &TSInfo);
if (!TSInfo)
return true;
TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
if (!TSResult)
return true;
return CreateParsedType(TSResult->getType(), TSResult);
}
示例5: TransAssert
// ISSUE: I am not sure why, but RecursiveASTVisitor doesn't recursively
// visit base classes from explicit template specialization, e.g.,
// struct A { };
// template<typename T> class B : public A<T> { };
// template<> class B : public A<short> { };
// In the above case, A<short> won't be touched.
// So we have to do it manually
bool RemoveNamespaceRewriteVisitor::VisitClassTemplateSpecializationDecl(
ClassTemplateSpecializationDecl *TSD)
{
if (!TSD->isExplicitSpecialization() || !TSD->isCompleteDefinition())
return true;
for (CXXRecordDecl::base_class_const_iterator I = TSD->bases_begin(),
E = TSD->bases_end(); I != E; ++I) {
TypeSourceInfo *TSI = (*I).getTypeSourceInfo();
TransAssert(TSI && "Bad TypeSourceInfo!");
TraverseTypeLoc(TSI->getTypeLoc());
}
return true;
}
示例6: switch
void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM) {
ObjCInstanceTypeFamily OIT_Family =
Selector::getInstTypeMethodFamily(OM->getSelector());
if (OIT_Family == OIT_None)
return;
// TODO. Many more to come
switch (OIT_Family) {
case OIT_Array:
break;
case OIT_Dictionary:
break;
default:
return;
}
if (!OM->getResultType()->isObjCIdType())
return;
ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
if (!IDecl) {
if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
IDecl = CatDecl->getClassInterface();
else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
IDecl = ImpDecl->getClassInterface();
}
if (!IDecl)
return;
if (OIT_Family == OIT_Array &&
!IDecl->lookupInheritedClass(&Ctx.Idents.get("NSArray")))
return;
else if (OIT_Family == OIT_Dictionary &&
!IDecl->lookupInheritedClass(&Ctx.Idents.get("NSDictionary")))
return;
TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo();
TypeLoc TL = TSInfo->getTypeLoc();
SourceRange R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
edit::Commit commit(*Editor);
std::string ClassString = "instancetype";
commit.replace(R, ClassString);
Editor->commit(commit);
}
示例7: getCursorExpr
CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
if (cursor.kind != CXCursor_CallExpr)
return cursor;
if (cursor.xdata == 0)
return cursor;
const Expr *E = getCursorExpr(cursor);
TypeSourceInfo *Type = 0;
if (const CXXUnresolvedConstructExpr *
UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
Type = UnCtor->getTypeSourceInfo();
} else if (const CXXTemporaryObjectExpr *Tmp =
dyn_cast<CXXTemporaryObjectExpr>(E)) {
Type = Tmp->getTypeSourceInfo();
}
if (!Type)
return cursor;
CXTranslationUnit TU = getCursorTU(cursor);
QualType Ty = Type->getType();
TypeLoc TL = Type->getTypeLoc();
SourceLocation Loc = TL.getBeginLoc();
if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
Ty = ElabT->getNamedType();
ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();
Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
}
if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
if (const TagType *Tag = Ty->getAs<TagType>())
return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
return cursor;
}
示例8: while
void NestedNameSpecifierLocBuilder::MakeTrivial(ASTContext &Context,
NestedNameSpecifier *Qualifier,
SourceRange R) {
Representation = Qualifier;
// Construct bogus (but well-formed) source information for the
// nested-name-specifier.
BufferSize = 0;
SmallVector<NestedNameSpecifier *, 4> Stack;
for (NestedNameSpecifier *NNS = Qualifier; NNS; NNS = NNS->getPrefix())
Stack.push_back(NNS);
while (!Stack.empty()) {
NestedNameSpecifier *NNS = Stack.back();
Stack.pop_back();
switch (NNS->getKind()) {
case NestedNameSpecifier::Identifier:
case NestedNameSpecifier::Namespace:
case NestedNameSpecifier::NamespaceAlias:
SaveSourceLocation(R.getBegin(), Buffer, BufferSize, BufferCapacity);
break;
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate: {
TypeSourceInfo *TSInfo
= Context.getTrivialTypeSourceInfo(QualType(NNS->getAsType(), 0),
R.getBegin());
SavePointer(TSInfo->getTypeLoc().getOpaqueData(), Buffer, BufferSize,
BufferCapacity);
break;
}
case NestedNameSpecifier::Global:
break;
}
// Save the location of the '::'.
SaveSourceLocation(Stack.empty()? R.getEnd() : R.getBegin(),
Buffer, BufferSize, BufferCapacity);
}
}
示例9: FindAndCacheRuntimeDecls
//.........这里部分代码省略.........
locStart, CallArgs, locEnd);
if (E)
Call = m_Sema->CreateBuiltinBinOp(locStart, BO_Comma, Call.take(), E);
}
else if (desugaredTy->isRecordType() || desugaredTy->isConstantArrayType()){
// 2) object types :
// check existance of copy constructor before call
if (!availableCopyConstructor(desugaredTy, m_Sema))
return E;
// call new (setValueWithAlloc(gCling, &SVR, ETy)) (E)
Call = m_Sema->ActOnCallExpr(/*Scope*/0, m_UnresolvedWithAlloc,
locStart, CallArgs, locEnd);
Expr* placement = Call.take();
if (const ConstantArrayType* constArray
= dyn_cast<ConstantArrayType>(desugaredTy.getTypePtr())) {
CallArgs.clear();
CallArgs.push_back(E);
CallArgs.push_back(placement);
uint64_t arrSize
= m_Context->getConstantArrayElementCount(constArray);
Expr* arrSizeExpr
= utils::Synthesize::IntegerLiteralExpr(*m_Context, arrSize);
CallArgs.push_back(arrSizeExpr);
// 2.1) arrays:
// call copyArray(T* src, void* placement, int size)
Call = m_Sema->ActOnCallExpr(/*Scope*/0, m_UnresolvedCopyArray,
locStart, CallArgs, locEnd);
}
else {
TypeSourceInfo* ETSI
= m_Context->getTrivialTypeSourceInfo(ETy, noLoc);
Call = m_Sema->BuildCXXNew(E->getSourceRange(),
/*useGlobal ::*/true,
/*placementLParen*/ noLoc,
MultiExprArg(placement),
/*placementRParen*/ noLoc,
/*TypeIdParens*/ SourceRange(),
/*allocType*/ ETSI->getType(),
/*allocTypeInfo*/ETSI,
/*arraySize*/0,
/*directInitRange*/E->getSourceRange(),
/*initializer*/E,
/*mayContainAuto*/false
);
}
}
else if (desugaredTy->isIntegralOrEnumerationType()
|| desugaredTy->isReferenceType()
|| desugaredTy->isPointerType()
|| desugaredTy->isFloatingType()) {
if (desugaredTy->isIntegralOrEnumerationType()) {
// 1) enum, integral, float, double, referece, pointer types :
// call to cling::internal::setValueNoAlloc(...);
// If the type is enum or integral we need to force-cast it into
// uint64 in order to pick up the correct overload.
if (desugaredTy->isIntegralOrEnumerationType()) {
QualType UInt64Ty = m_Context->UnsignedLongLongTy;
TypeSourceInfo* TSI
= m_Context->getTrivialTypeSourceInfo(UInt64Ty, noLoc);
Expr* castedE
示例10: assert
bool DeclExtractor::CheckTagDeclaration(TagDecl* NewTD,
LookupResult& Previous){
// If the decl is already known invalid, don't check it.
if (NewTD->isInvalidDecl())
return false;
IdentifierInfo* Name = NewTD->getIdentifier();
// If this is not a definition, it must have a name.
assert((Name != 0 || NewTD->isThisDeclarationADefinition()) &&
"Nameless record must be a definition!");
// Figure out the underlying type if this a enum declaration. We need to do
// this early, because it's needed to detect if this is an incompatible
// redeclaration.
TagDecl::TagKind Kind = NewTD->getTagKind();
bool Invalid = false;
assert(NewTD->getNumTemplateParameterLists() == 0
&& "Cannot handle that yet!");
bool isExplicitSpecialization = false;
if (Kind == TTK_Enum) {
EnumDecl* ED = cast<EnumDecl>(NewTD);
bool ScopedEnum = ED->isScoped();
const QualType QT = ED->getIntegerType();
if (QT.isNull() && ScopedEnum)
// No underlying type explicitly specified, or we failed to parse the
// type, default to int.
; //EnumUnderlying = m_Context->IntTy.getTypePtr();
else if (!QT.isNull()) {
// C++0x 7.2p2: The type-specifier-seq of an enum-base shall name an
// integral type; any cv-qualification is ignored.
SourceLocation UnderlyingLoc;
TypeSourceInfo* TI = 0;
if ((TI = ED->getIntegerTypeSourceInfo()))
UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
if (!QT->isDependentType() && !QT->isIntegralType(*m_Context)) {
m_Sema->Diag(UnderlyingLoc, diag::err_enum_invalid_underlying)
<< QT;
}
if (TI)
m_Sema->DiagnoseUnexpandedParameterPack(UnderlyingLoc, TI,
Sema::UPPC_FixedUnderlyingType);
}
}
DeclContext *SearchDC = m_Sema->CurContext;
DeclContext *DC = m_Sema->CurContext;
//bool isStdBadAlloc = false;
SourceLocation NameLoc = NewTD->getLocation();
// if (Name && SS.isNotEmpty()) {
// // We have a nested-name tag ('struct foo::bar').
// // Check for invalid 'foo::'.
// if (SS.isInvalid()) {
// Name = 0;
// goto CreateNewDecl;
// }
// // If this is a friend or a reference to a class in a dependent
// // context, don't try to make a decl for it.
// if (TUK == TUK_Friend || TUK == TUK_Reference) {
// DC = computeDeclContext(SS, false);
// if (!DC) {
// IsDependent = true;
// return 0;
// }
// } else {
// DC = computeDeclContext(SS, true);
// if (!DC) {
// Diag(SS.getRange().getBegin(),
// diag::err_dependent_nested_name_spec)
// << SS.getRange();
// return 0;
// }
// }
// if (RequireCompleteDeclContext(SS, DC))
// return 0;
// SearchDC = DC;
// // Look-up name inside 'foo::'.
// LookupQualifiedName(Previous, DC);
// if (Previous.isAmbiguous())
// return 0;
// if (Previous.empty()) {
// // Name lookup did not find anything. However, if the
// // nested-name-specifier refers to the current instantiation,
// // and that current instantiation has any dependent base
// // classes, we might find something at instantiation time: treat
// // this as a dependent elaborated-type-specifier.
// // But this only makes any sense for reference-like lookups.
// if (Previous.wasNotFoundInCurrentInstantiation() &&
// (TUK == TUK_Reference || TUK == TUK_Friend)) {
// IsDependent = true;
//.........这里部分代码省略.........
示例11: checkAllAtProps
static void checkAllAtProps(MigrationContext &MigrateCtx,
SourceLocation AtLoc,
IndivPropsTy &IndProps) {
if (IndProps.empty())
return;
for (IndivPropsTy::iterator
PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
QualType T = (*PI)->getType();
if (T.isNull() || !T->isObjCRetainableType())
return;
}
SmallVector<std::pair<AttributedTypeLoc, ObjCPropertyDecl *>, 4> ATLs;
bool hasWeak = false, hasStrong = false;
ObjCPropertyDecl::PropertyAttributeKind
Attrs = ObjCPropertyDecl::OBJC_PR_noattr;
for (IndivPropsTy::iterator
PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
ObjCPropertyDecl *PD = *PI;
Attrs = PD->getPropertyAttributesAsWritten();
TypeSourceInfo *TInfo = PD->getTypeSourceInfo();
if (!TInfo)
return;
TypeLoc TL = TInfo->getTypeLoc();
if (AttributedTypeLoc ATL =
TL.getAs<AttributedTypeLoc>()) {
ATLs.push_back(std::make_pair(ATL, PD));
if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
hasWeak = true;
} else if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong)
hasStrong = true;
else
return;
}
}
if (ATLs.empty())
return;
if (hasWeak && hasStrong)
return;
TransformActions &TA = MigrateCtx.Pass.TA;
Transaction Trans(TA);
if (GCAttrsCollector::hasObjCImpl(
cast<Decl>(IndProps.front()->getDeclContext()))) {
if (hasWeak)
MigrateCtx.AtPropsWeak.insert(AtLoc.getRawEncoding());
} else {
StringRef toAttr = "strong";
if (hasWeak) {
if (canApplyWeak(MigrateCtx.Pass.Ctx, IndProps.front()->getType(),
/*AllowOnUnkwownClass=*/true))
toAttr = "weak";
else
toAttr = "unsafe_unretained";
}
if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
MigrateCtx.rewritePropertyAttribute("assign", toAttr, AtLoc);
else
MigrateCtx.addPropertyAttribute(toAttr, AtLoc);
}
for (unsigned i = 0, e = ATLs.size(); i != e; ++i) {
SourceLocation Loc = ATLs[i].first.getAttrNameLoc();
if (Loc.isMacroID())
Loc = MigrateCtx.Pass.Ctx.getSourceManager()
.getImmediateExpansionRange(Loc).first;
TA.remove(Loc);
TA.clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
TA.clearDiagnostic(diag::err_arc_inconsistent_property_ownership,
ATLs[i].second->getLocation());
MigrateCtx.RemovedAttrSet.insert(Loc.getRawEncoding());
}
}
示例12: getASTContext
void
CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
unsigned NumBases) {
ASTContext &C = getASTContext();
// C++ [dcl.init.aggr]p1:
// An aggregate is an array or a class (clause 9) with [...]
// no base classes [...].
data().Aggregate = false;
if (data().Bases)
C.Deallocate(data().Bases);
// The set of seen virtual base types.
llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
// The virtual bases of this class.
llvm::SmallVector<const CXXBaseSpecifier *, 8> VBases;
data().Bases = new(C) CXXBaseSpecifier [NumBases];
data().NumBases = NumBases;
for (unsigned i = 0; i < NumBases; ++i) {
data().Bases[i] = *Bases[i];
// Keep track of inherited vbases for this base class.
const CXXBaseSpecifier *Base = Bases[i];
QualType BaseType = Base->getType();
// Skip dependent types; we can't do any checking on them now.
if (BaseType->isDependentType())
continue;
CXXRecordDecl *BaseClassDecl
= cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
// Now go through all virtual bases of this base and add them.
for (CXXRecordDecl::base_class_iterator VBase =
BaseClassDecl->vbases_begin(),
E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) {
// Add this base if it's not already in the list.
if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType())))
VBases.push_back(VBase);
}
if (Base->isVirtual()) {
// Add this base if it's not already in the list.
if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)))
VBases.push_back(Base);
}
}
if (VBases.empty())
return;
// Create base specifier for any direct or indirect virtual bases.
data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
data().NumVBases = VBases.size();
for (int I = 0, E = VBases.size(); I != E; ++I) {
TypeSourceInfo *VBaseTypeInfo = VBases[I]->getTypeSourceInfo();
// Skip dependent types; we can't do any checking on them now.
if (VBaseTypeInfo->getType()->isDependentType())
continue;
CXXRecordDecl *VBaseClassDecl = cast<CXXRecordDecl>(
VBaseTypeInfo->getType()->getAs<RecordType>()->getDecl());
data().VBases[I] =
CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true,
VBaseClassDecl->getTagKind() == TTK_Class,
VBases[I]->getAccessSpecifier(), VBaseTypeInfo);
}
}