From 9cfbe48a7a20a217fdb2920b29b67ae7941cb116 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 20 Jun 2009 00:51:54 +0000 Subject: 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 --- lib/Sema/SemaDeclCXX.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/Sema/SemaDeclCXX.cpp') 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(NS)) { + Diag(IdentLoc, diag::err_using_typename_non_type); + } + UsingAlias = UsingDecl::Create(Context, CurContext, IdentLoc, SS.getRange(), + NS->getLocation(), UsingLoc, NS, + static_cast(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) { -- cgit v1.2.3-70-g09d2