diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-06-20 00:51:54 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-06-20 00:51:54 +0000 |
commit | 9cfbe48a7a20a217fdb2920b29b67ae7941cb116 (patch) | |
tree | 43a0039929a24ceb9f232089e83fda23c07c7ff1 /lib/Sema | |
parent | 6aed766538c9d996b709354386c861037b9eedba (diff) |
Parsing and AST support for using declarations, from John Thompson!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73812 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.h | 8 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 37 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 6 |
4 files changed, 52 insertions, 4 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 230bcffa72..560f952bff 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1547,6 +1547,14 @@ public: const CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *Ident); + + virtual DeclPtrTy ActOnUsingDeclaration(Scope *CurScope, + SourceLocation UsingLoc, + const CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *TargetName, + AttributeList *AttrList, + bool IsTypeName); /// AddCXXDirectInitializerToDecl - This action is called immediately after /// ActOnDeclarator, when a C++ direct initializer is present. diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2dd02af7b9..06fd1a1736 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2284,7 +2284,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, Diag(NewFD->getLocation(), diag::err_out_of_line_declaration) << D.getCXXScopeSpec().getRange(); NewFD->setInvalidDecl(); - } else if (!Redeclaration) { + } else if (!Redeclaration && (!PrevDecl || !isa<UsingDecl>(PrevDecl))) { // The user tried to provide an out-of-line definition for a // function that is a member of a class or namespace, but there // was no such member function declared (C++ [class.mfct]p2, @@ -2455,7 +2455,8 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, if (PrevDecl && (!AllowOverloadingOfFunction(PrevDecl, Context) || - !IsOverload(NewFD, PrevDecl, MatchedDecl))) { + !IsOverload(NewFD, PrevDecl, MatchedDecl)) && + !isa<UsingDecl>(PrevDecl)) { Redeclaration = true; Decl *OldDecl = PrevDecl; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8c547cd1cc..7524cbf500 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1748,6 +1748,43 @@ void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) { S->PushUsingDirective(DeclPtrTy::make(UDir)); } + +Sema::DeclPtrTy Sema::ActOnUsingDeclaration(Scope *S, + SourceLocation UsingLoc, + const CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *TargetName, + AttributeList *AttrList, + bool IsTypeName) { + assert(!SS.isInvalid() && "Invalid CXXScopeSpec."); + assert(TargetName && "Invalid TargetName."); + assert(IdentLoc.isValid() && "Invalid TargetName location."); + assert(S->getFlags() & Scope::DeclScope && "Invalid Scope."); + + UsingDecl *UsingAlias = 0; + + // Lookup target name. + LookupResult R = LookupParsedName(S, &SS, TargetName, + LookupOrdinaryName, false); + + if (NamedDecl *NS = R) { + if (IsTypeName && !isa<TypeDecl>(NS)) { + Diag(IdentLoc, diag::err_using_typename_non_type); + } + UsingAlias = UsingDecl::Create(Context, CurContext, IdentLoc, SS.getRange(), + NS->getLocation(), UsingLoc, NS, + static_cast<NestedNameSpecifier *>(SS.getScopeRep()), + IsTypeName); + PushOnScopeChains(UsingAlias, S); + } else { + Diag(IdentLoc, diag::err_using_requires_qualname) << SS.getRange(); + } + + // FIXME: We ignore attributes for now. + delete AttrList; + return DeclPtrTy::make(UsingAlias); +} + /// getNamespaceDecl - Returns the namespace a decl represents. If the decl /// is a namespace alias, returns the namespace it points to. static inline NamespaceDecl *getNamespaceDecl(NamedDecl *D) { diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 52de4e6f4c..37e1df3a19 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1151,8 +1151,10 @@ Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS, Name, NameKind, RedeclarationOnly); } - return LookupName(S, Name, NameKind, RedeclarationOnly, - AllowBuiltinCreation, Loc); + LookupResult result(LookupName(S, Name, NameKind, RedeclarationOnly, + AllowBuiltinCreation, Loc)); + + return(result); } |