diff options
author | John McCall <rjmccall@apple.com> | 2009-10-24 08:00:42 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-10-24 08:00:42 +0000 |
commit | ba6a9bd384df475780be636ca45bcef5c5bbd19f (patch) | |
tree | 5a424cd2045611749ab24e8da7d7d872f3f9d5f8 /lib/Sema | |
parent | 3eefb1c4bd2c562e43f25e0dba657bb32361dd14 (diff) |
Preserve type source information in TypedefDecls. Preserve it across
template instantiation. Preserve it through PCH. Show it off to the indexer.
I'm healthily ignoring the vector type cases because we don't have a sensible
TypeLoc implementation for them anyway.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84994 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.cpp | 38 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 17 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 17 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 |
5 files changed, 52 insertions, 37 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index fc9c14f456..64007f2323 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -277,15 +277,20 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { PushDeclContext(S, Context.getTranslationUnitDecl()); if (PP.getTargetInfo().getPointerWidth(0) >= 64) { + DeclaratorInfo *DInfo; + // Install [u]int128_t for 64-bit targets. + DInfo = Context.getTrivialDeclaratorInfo(Context.Int128Ty); PushOnScopeChains(TypedefDecl::Create(Context, CurContext, SourceLocation(), &Context.Idents.get("__int128_t"), - Context.Int128Ty), TUScope); + DInfo), TUScope); + + DInfo = Context.getTrivialDeclaratorInfo(Context.UnsignedInt128Ty); PushOnScopeChains(TypedefDecl::Create(Context, CurContext, SourceLocation(), &Context.Idents.get("__uint128_t"), - Context.UnsignedInt128Ty), TUScope); + DInfo), TUScope); } @@ -298,10 +303,10 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { PushOnScopeChains(SelTag, TUScope); QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag)); - TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext, - SourceLocation(), - &Context.Idents.get("SEL"), - SelT); + DeclaratorInfo *SelInfo = Context.getTrivialDeclaratorInfo(SelT); + TypedefDecl *SelTypedef + = TypedefDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("SEL"), SelInfo); PushOnScopeChains(SelTypedef, TUScope); Context.setObjCSelType(Context.getTypeDeclType(SelTypedef)); } @@ -317,22 +322,23 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { } // Create the built-in typedef for 'id'. if (Context.getObjCIdType().isNull()) { - TypedefDecl *IdTypedef = - TypedefDecl::Create( - Context, CurContext, SourceLocation(), &Context.Idents.get("id"), - Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy) - ); + QualType IdT = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy); + DeclaratorInfo *IdInfo = Context.getTrivialDeclaratorInfo(IdT); + TypedefDecl *IdTypedef + = TypedefDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("id"), IdInfo); PushOnScopeChains(IdTypedef, TUScope); Context.setObjCIdType(Context.getTypeDeclType(IdTypedef)); Context.ObjCIdRedefinitionType = Context.getObjCIdType(); } // Create the built-in typedef for 'Class'. if (Context.getObjCClassType().isNull()) { - TypedefDecl *ClassTypedef = - TypedefDecl::Create( - Context, CurContext, SourceLocation(), &Context.Idents.get("Class"), - Context.getObjCObjectPointerType(Context.ObjCBuiltinClassTy) - ); + QualType ClassType + = Context.getObjCObjectPointerType(Context.ObjCBuiltinClassTy); + DeclaratorInfo *ClassInfo = Context.getTrivialDeclaratorInfo(ClassType); + TypedefDecl *ClassTypedef + = TypedefDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("Class"), ClassInfo); PushOnScopeChains(ClassTypedef, TUScope); Context.setObjCClassType(Context.getTypeDeclType(ClassTypedef)); Context.ObjCClassRedefinitionType = Context.getObjCClassType(); diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 7f3c49acc8..5cff7a5840 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -767,7 +767,8 @@ public: /// Subroutines of ActOnDeclarator(). - TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T); + TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, + DeclaratorInfo *DInfo); void MergeTypeDefDecl(TypedefDecl *New, Decl *Old); bool MergeFunctionDecl(FunctionDecl *New, Decl *Old); bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 98b71c7360..1b4c594aae 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1986,12 +1986,9 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (D.getDeclSpec().isThreadSpecified()) Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread); - TypedefDecl *NewTD = ParseTypedefDecl(S, D, R); + TypedefDecl *NewTD = ParseTypedefDecl(S, D, R, DInfo); if (!NewTD) return 0; - if (D.isInvalidType()) - NewTD->setInvalidDecl(); - // Handle attributes prior to checking for duplicates in MergeVarDecl ProcessDeclAttributes(S, NewTD, D); // Merge the decl with the existing one if appropriate. If the decl is @@ -2013,7 +2010,7 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative); if (!FixedTy.isNull()) { Diag(D.getIdentifierLoc(), diag::warn_illegal_constant_array_size); - NewTD->setUnderlyingType(FixedTy); + NewTD->setTypeDeclaratorInfo(Context.getTrivialDeclaratorInfo(FixedTy)); } else { if (SizeIsNegative) Diag(D.getIdentifierLoc(), diag::err_typecheck_negative_array_size); @@ -4097,15 +4094,21 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { } } -TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T) { +TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T, + DeclaratorInfo *DInfo) { assert(D.getIdentifier() && "Wrong callback for declspec without declarator"); assert(!T.isNull() && "GetTypeForDeclarator() returned null type"); + if (!DInfo) { + assert(D.isInvalidType() && "no declarator info for valid type"); + DInfo = Context.getTrivialDeclaratorInfo(T); + } + // Scope manipulation handled by caller. TypedefDecl *NewTD = TypedefDecl::Create(Context, CurContext, D.getIdentifierLoc(), D.getIdentifier(), - T); + DInfo); if (const TagType *TT = T->getAs<TagType>()) { TagDecl *TD = TT->getDecl(); diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 341d49ead4..090a6cd540 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -193,7 +193,8 @@ static void HandleExtVectorTypeAttr(Scope *scope, Decl *d, // This will run the reguired checks. QualType T = S.BuildExtVectorType(curType, S.Owned(sizeExpr), Attr.getLoc()); if (!T.isNull()) { - tDecl->setUnderlyingType(T); + // FIXME: preserve the old source info. + tDecl->setTypeDeclaratorInfo(S.Context.getTrivialDeclaratorInfo(T)); // Remember this typedef decl, we will need it later for diagnostics. S.ExtVectorDecls.push_back(tDecl); @@ -278,8 +279,11 @@ static void HandleVectorSizeAttr(Decl *D, const AttributeList &Attr, Sema &S) { if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) VD->setType(CurType); - else - cast<TypedefDecl>(D)->setUnderlyingType(CurType); + else { + // FIXME: preserve existing source info. + DeclaratorInfo *DInfo = S.Context.getTrivialDeclaratorInfo(CurType); + cast<TypedefDecl>(D)->setTypeDeclaratorInfo(DInfo); + } } static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) { @@ -1636,9 +1640,10 @@ static void HandleModeAttr(Decl *D, const AttributeList &Attr, Sema &S) { } // Install the new type. - if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) - TD->setUnderlyingType(NewTy); - else + if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { + // FIXME: preserve existing source info. + TD->setTypeDeclaratorInfo(S.Context.getTrivialDeclaratorInfo(NewTy)); + } else cast<ValueDecl>(D)->setType(NewTy); } diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index c30f48e803..422a7bc04d 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -99,20 +99,20 @@ TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) { Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { bool Invalid = false; - QualType T = D->getUnderlyingType(); - if (T->isDependentType()) { - T = SemaRef.SubstType(T, TemplateArgs, - D->getLocation(), D->getDeclName()); - if (T.isNull()) { + DeclaratorInfo *DI = D->getTypeDeclaratorInfo(); + if (DI->getType()->isDependentType()) { + DI = SemaRef.SubstType(DI, TemplateArgs, + D->getLocation(), D->getDeclName()); + if (!DI) { Invalid = true; - T = SemaRef.Context.IntTy; + DI = SemaRef.Context.getTrivialDeclaratorInfo(SemaRef.Context.IntTy); } } // Create the new typedef TypedefDecl *Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getLocation(), - D->getIdentifier(), T); + D->getIdentifier(), DI); if (Invalid) Typedef->setInvalidDecl(); |