[cfe-commits] r86027 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Basic/DiagnosticSemaKinds.td include/clang/Parse/Action.h lib/Parse/MinimalAction.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp
Douglas Gregor
dgregor at apple.com
Wed Nov 4 08:30:06 PST 2009
Author: dgregor
Date: Wed Nov 4 10:30:06 2009
New Revision: 86027
URL: http://llvm.org/viewvc/llvm-project?rev=86027&view=rev
Log:
Switch parsing of using declarations over to ParseUnqualifiedId.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/MinimalAction.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Nov 4 10:30:06 2009
@@ -166,9 +166,6 @@
"use of tagged type %0 without '%1' tag">;
def err_expected_ident_in_using : Error<
"expected an identifier in using directive">;
-def err_using_decl_can_not_refer_to_template_spec : Error<
- "using declaration can not refer to template specialization">;
-
/// Objective-C parser diagnostics
def err_objc_no_attributes_on_category : Error<
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 4 10:30:06 2009
@@ -107,8 +107,14 @@
"using declaration refers into '%0', which is not a base class of %1">;
def err_using_decl_can_not_refer_to_class_member : Error<
"using declaration can not refer to class member">;
- def err_using_decl_can_not_refer_to_namespace : Error<
+def err_using_decl_can_not_refer_to_namespace : Error<
"using declaration can not refer to namespace">;
+def err_using_decl_constructor : Error<
+ "using declaration can not refer to a constructor">;
+def err_using_decl_destructor : Error<
+ "using declaration can not refer to a destructor">;
+def err_using_decl_template_id : Error<
+ "using declaration can not refer to a template specialization">;
def err_invalid_thread : Error<
"'__thread' is only allowed on variable declarations">;
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Nov 4 10:30:06 2009
@@ -1174,14 +1174,41 @@
return DeclPtrTy();
}
- /// ActOnUsingDirective - This is called when using-directive is parsed.
+ /// \brief Parsed a C++ using-declaration.
+ ///
+ /// This callback will be invoked when the parser has parsed a C++
+ /// using-declaration, e.g.,
+ ///
+ /// \code
+ /// namespace std {
+ /// template<typename T, typename Alloc> class vector;
+ /// }
+ ///
+ /// using std::vector; // using-declaration here
+ /// \endcode
+ ///
+ /// \param CurScope the scope in which this using declaration was parsed.
+ ///
+ /// \param AS the currently-active access specifier.
+ ///
+ /// \param UsingLoc the location of the 'using' keyword.
+ ///
+ /// \param SS the nested-name-specifier that precedes the name.
+ ///
+ /// \param Name the name to which the using declaration refers.
+ ///
+ /// \param AttrList attributes applied to this using declaration, if any.
+ ///
+ /// \param IsTypeName whether this using declaration started with the
+ /// 'typename' keyword. FIXME: This will eventually be split into a
+ /// separate action.
+ ///
+ /// \returns a representation of the using declaration.
virtual DeclPtrTy ActOnUsingDeclaration(Scope *CurScope,
AccessSpecifier AS,
SourceLocation UsingLoc,
const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *TargetName,
- OverloadedOperatorKind Op,
+ UnqualifiedId &Name,
AttributeList *AttrList,
bool IsTypeName);
Modified: cfe/trunk/lib/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/MinimalAction.cpp?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/MinimalAction.cpp (original)
+++ cfe/trunk/lib/Parse/MinimalAction.cpp Wed Nov 4 10:30:06 2009
@@ -42,14 +42,12 @@
return DeclPtrTy();
}
-// Defined out-of-line here because of dependecy on AttributeList
+// Defined out-of-line here because of dependency on AttributeList
Action::DeclPtrTy Action::ActOnUsingDeclaration(Scope *CurScope,
AccessSpecifier AS,
SourceLocation UsingLoc,
const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *TargetName,
- OverloadedOperatorKind Op,
+ UnqualifiedId &Name,
AttributeList *AttrList,
bool IsTypeName) {
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Nov 4 10:30:06 2009
@@ -285,6 +285,7 @@
bool IsTypeName;
// Ignore optional 'typename'.
+ // FIXME: This is wrong; we should parse this as a typename-specifier.
if (Tok.is(tok::kw_typename)) {
ConsumeToken();
IsTypeName = true;
@@ -302,41 +303,21 @@
SkipUntil(tok::semi);
return DeclPtrTy();
}
- if (Tok.is(tok::annot_template_id)) {
- // C++0x N2914 [namespace.udecl]p5:
- // A using-declaration shall not name a template-id.
- Diag(Tok, diag::err_using_decl_can_not_refer_to_template_spec);
- SkipUntil(tok::semi);
- return DeclPtrTy();
- }
- IdentifierInfo *TargetName = 0;
- OverloadedOperatorKind Op = OO_None;
- SourceLocation IdentLoc;
-
- if (Tok.is(tok::kw_operator)) {
- IdentLoc = Tok.getLocation();
-
- Op = TryParseOperatorFunctionId();
- if (!Op) {
- // If there was an invalid operator, skip to end of decl, and eat ';'.
- SkipUntil(tok::semi);
- return DeclPtrTy();
- }
- // FIXME: what about conversion functions?
- } else if (Tok.is(tok::identifier)) {
- // Parse identifier.
- TargetName = Tok.getIdentifierInfo();
- IdentLoc = ConsumeToken();
- } else {
- // FIXME: Use a better diagnostic here.
- Diag(Tok, diag::err_expected_ident_in_using);
-
- // If there was invalid identifier, skip to end of decl, and eat ';'.
+ // Parse the unqualified-id. We allow parsing of both constructor and
+ // destructor names and allow the action module to diagnose any semantic
+ // errors.
+ UnqualifiedId Name;
+ if (ParseUnqualifiedId(SS,
+ /*EnteringContext=*/false,
+ /*AllowDestructorName=*/true,
+ /*AllowConstructorName=*/true,
+ /*ObjectType=*/0,
+ Name)) {
SkipUntil(tok::semi);
return DeclPtrTy();
}
-
+
// Parse (optional) attributes (most likely GNU strong-using extension).
if (Tok.is(tok::kw___attribute))
AttrList = ParseAttributes();
@@ -344,10 +325,10 @@
// Eat ';'.
DeclEnd = Tok.getLocation();
ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
- AttrList ? "attributes list" : "namespace name", tok::semi);
+ AttrList ? "attributes list" : "using declaration",
+ tok::semi);
- return Actions.ActOnUsingDeclaration(CurScope, AS, UsingLoc, SS,
- IdentLoc, TargetName, Op,
+ return Actions.ActOnUsingDeclaration(CurScope, AS, UsingLoc, SS, Name,
AttrList, IsTypeName);
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Nov 4 10:30:06 2009
@@ -1893,9 +1893,7 @@
AccessSpecifier AS,
SourceLocation UsingLoc,
const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *TargetName,
- OverloadedOperatorKind Op,
+ UnqualifiedId &Name,
AttributeList *AttrList,
bool IsTypeName);
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Nov 4 10:30:06 2009
@@ -2700,22 +2700,37 @@
AccessSpecifier AS,
SourceLocation UsingLoc,
const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *TargetName,
- OverloadedOperatorKind Op,
+ UnqualifiedId &Name,
AttributeList *AttrList,
bool IsTypeName) {
- assert((TargetName || Op) && "Invalid TargetName.");
assert(S->getFlags() & Scope::DeclScope && "Invalid Scope.");
- DeclarationName Name;
- if (TargetName)
- Name = TargetName;
- else
- Name = Context.DeclarationNames.getCXXOperatorName(Op);
-
- NamedDecl *UD = BuildUsingDeclaration(UsingLoc, SS, IdentLoc,
- Name, AttrList, IsTypeName);
+ switch (Name.getKind()) {
+ case UnqualifiedId::IK_Identifier:
+ case UnqualifiedId::IK_OperatorFunctionId:
+ case UnqualifiedId::IK_ConversionFunctionId:
+ break;
+
+ case UnqualifiedId::IK_ConstructorName:
+ Diag(Name.getSourceRange().getBegin(), diag::err_using_decl_constructor)
+ << SS.getRange();
+ return DeclPtrTy();
+
+ case UnqualifiedId::IK_DestructorName:
+ Diag(Name.getSourceRange().getBegin(), diag::err_using_decl_destructor)
+ << SS.getRange();
+ return DeclPtrTy();
+
+ case UnqualifiedId::IK_TemplateId:
+ Diag(Name.getSourceRange().getBegin(), diag::err_using_decl_template_id)
+ << SourceRange(Name.TemplateId->LAngleLoc, Name.TemplateId->RAngleLoc);
+ return DeclPtrTy();
+ }
+
+ DeclarationName TargetName = GetNameFromUnqualifiedId(Name);
+ NamedDecl *UD = BuildUsingDeclaration(UsingLoc, SS,
+ Name.getSourceRange().getBegin(),
+ TargetName, AttrList, IsTypeName);
if (UD) {
PushOnScopeChains(UD, S);
UD->setAccess(AS);
Modified: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp?rev=86027&r1=86026&r2=86027&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp Wed Nov 4 10:30:06 2009
@@ -7,6 +7,6 @@
};
struct B : A {
- using A::f<double>; // expected-error{{using declaration can not refer to template specialization}}
- using A::X<int>; // expected-error{{using declaration can not refer to template specialization}}
-};
\ No newline at end of file
+ using A::f<double>; // expected-error{{using declaration can not refer to a template specialization}}
+ using A::X<int>; // expected-error{{using declaration can not refer to a template specialization}}
+};
More information about the cfe-commits
mailing list