summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-09 15:09:02 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-09 15:09:02 +0000
commit9817f4a71764543bfd683773bedbe20c3cb68d2b (patch)
treee1a45a5fc5ae6a923db66b9e28c9d9c7b882d681 /clang/lib/Sema/SemaDecl.cpp
parentb9ad4921fd89a3a15b38a2782eca793f39580000 (diff)
downloadbcm5719-llvm-9817f4a71764543bfd683773bedbe20c3cb68d2b.tar.gz
bcm5719-llvm-9817f4a71764543bfd683773bedbe20c3cb68d2b.zip
Make Sema::getTypeName return the opaque pointer of a QualType rather
than a Decl, which gives us some more flexibility to express the results with the type system. There are no clients using this flexibility yet, but it's meant to be able to describe qualified names as written in the source (e.g., "foo::type") or template-ids that name a class template specialization (e.g., "std::vector<INT>"). DeclSpec's TST_typedef has become TST_typename, to reflect its use to describe types found by name (that may or may not be typedefs). The type representation of a DeclSpec with TST_typename is an opaque QualType pointer. All users of TST_typedef, both direct and indirect, have been updated for these changes. llvm-svn: 64141
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c0160b2d423..4bba5e50f18 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -36,12 +36,13 @@ using namespace clang;
///
/// This routine performs ordinary name lookup of the identifier II
/// within the given scope, with optional C++ scope specifier SS, to
-/// determine whether the name refers to a type. If so, returns the
-/// declaration corresponding to that type. Otherwise, returns NULL.
+/// determine whether the name refers to a type. If so, returns an
+/// opaque pointer (actually a QualType) corresponding to that
+/// type. Otherwise, returns NULL.
///
/// If name lookup results in an ambiguity, this routine will complain
/// and then return NULL.
-Sema::DeclTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
+Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Scope *S, const CXXScopeSpec *SS) {
Decl *IIDecl = 0;
LookupResult Result = LookupParsedName(S, SS, &II, LookupOrdinaryName, false);
@@ -62,11 +63,10 @@ Sema::DeclTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
}
if (IIDecl) {
- if (isa<TypedefDecl>(IIDecl) ||
- isa<ObjCInterfaceDecl>(IIDecl) ||
- isa<TagDecl>(IIDecl) ||
- isa<TemplateTypeParmDecl>(IIDecl))
- return IIDecl;
+ if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl))
+ return Context.getTypeDeclType(TD).getAsOpaquePtr();
+ else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl))
+ return Context.getObjCInterfaceType(IDecl).getAsOpaquePtr();
}
return 0;
}
@@ -695,8 +695,13 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
- TagDecl *Tag
- = dyn_cast_or_null<TagDecl>(static_cast<Decl *>(DS.getTypeRep()));
+ TagDecl *Tag = 0;
+ if (DS.getTypeSpecType() == DeclSpec::TST_class ||
+ DS.getTypeSpecType() == DeclSpec::TST_struct ||
+ DS.getTypeSpecType() == DeclSpec::TST_union ||
+ DS.getTypeSpecType() == DeclSpec::TST_enum)
+ Tag = dyn_cast<TagDecl>(static_cast<Decl *>(DS.getTypeRep()));
+
if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
if (!Record->getDeclName() && Record->isDefinition() &&
DS.getStorageClassSpec() != DeclSpec::SCS_typedef)
@@ -1111,18 +1116,19 @@ DeclarationName Sema::GetNameForDeclarator(Declarator &D) {
return DeclarationName(D.getIdentifier());
case Declarator::DK_Constructor: {
- QualType Ty = Context.getTypeDeclType((TypeDecl *)D.getDeclaratorIdType());
+ QualType Ty = QualType::getFromOpaquePtr(D.getDeclaratorIdType());
Ty = Context.getCanonicalType(Ty);
return Context.DeclarationNames.getCXXConstructorName(Ty);
}
case Declarator::DK_Destructor: {
- QualType Ty = Context.getTypeDeclType((TypeDecl *)D.getDeclaratorIdType());
+ QualType Ty = QualType::getFromOpaquePtr(D.getDeclaratorIdType());
Ty = Context.getCanonicalType(Ty);
return Context.DeclarationNames.getCXXDestructorName(Ty);
}
case Declarator::DK_Conversion: {
+ // FIXME: We'd like to keep the non-canonical type for diagnostics!
QualType Ty = QualType::getFromOpaquePtr(D.getDeclaratorIdType());
Ty = Context.getCanonicalType(Ty);
return Context.DeclarationNames.getCXXConversionFunctionName(Ty);
OpenPOWER on IntegriCloud