aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-04-27 05:41:15 +0000
committerDouglas Gregor <dgregor@apple.com>2011-04-27 05:41:15 +0000
commitd9d75e57dfa22366c0379c92beac1db82db34e9a (patch)
tree534e71d8fd4a668648d97c35209349d8f0fa414f
parent6b4f567109d76ce1f1de289554e35f2a7bbeff6b (diff)
Simplify the parser's handling of Sema::ClassifyName() for types, by
creating a type-annotation token rather than jumping into the declaration parsing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130293 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Parse/Parser.h2
-rw-r--r--lib/Parse/ParseDecl.cpp8
-rw-r--r--lib/Parse/ParseExprCXX.cpp3
-rw-r--r--lib/Parse/ParseStmt.cpp53
4 files changed, 8 insertions, 58 deletions
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 0311c06ece..8ed6919208 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -149,7 +149,7 @@ class Parser : public CodeCompletionHandler {
/// ColonProtectionRAIIObject RAII object.
bool ColonIsSacred;
- /// \brief When true, we are directly inside an Ojective-C messsage
+ /// \brief When true, we are directly inside an Objective-C messsage
/// send expression.
///
/// This is managed by the \c InMessageExpressionRAIIObject class, and
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index c09a93a84f..a021b84d15 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -2954,9 +2954,6 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
case tok::kw_virtual:
case tok::kw_explicit:
- // typedef-name
- case tok::annot_typename:
-
// static_assert-declaration
case tok::kw__Static_assert:
@@ -2971,6 +2968,11 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
case tok::less:
return getLang().ObjC1;
+ // typedef-name
+ case tok::annot_typename:
+ return !DisambiguatingWithExpression ||
+ !isStartOfObjCClassMessageMissingOpenBracket();
+
case tok::kw___declspec:
case tok::kw___cdecl:
case tok::kw___stdcall:
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index e6abac3b4c..7bf76a917f 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -956,8 +956,7 @@ bool Parser::isCXXSimpleTypeSpecifier() const {
case tok::kw_char16_t:
case tok::kw_char32_t:
case tok::kw_bool:
- // FIXME: C++0x decltype support.
- // GNU typeof support.
+ case tok::kw_decltype:
case tok::kw_typeof:
return true;
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 5138cc1595..28be864bdf 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -114,7 +114,6 @@ Retry:
}
if (Next.isNot(tok::coloncolon)) {
- // FIXME: Temporarily enable this code only for C.
CXXScopeSpec SS;
IdentifierInfo *Name = Tok.getIdentifierInfo();
SourceLocation NameLoc = Tok.getLocation();
@@ -147,63 +146,13 @@ Retry:
// we're in a syntactic context we haven't handled yet.
break;
- case Sema::NC_Type: {
- // We have a type. In C, this means that we have a declaration.
- if (!getLang().CPlusPlus) {
- ParsedType Type = Classification.getType();
- const char *PrevSpec = 0;
- unsigned DiagID;
- ConsumeToken(); // the identifier
- ParsingDeclSpec DS(*this);
- DS.takeAttributesFrom(attrs);
- DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec, DiagID,
- Type);
- DS.SetRangeStart(NameLoc);
- DS.SetRangeEnd(NameLoc);
-
- // In Objective-C, check whether this is the start of a class message
- // send that is missing an opening square bracket ('[').
- if (getLang().ObjC1 && Tok.is(tok::identifier) &&
- Type.get()->isObjCObjectOrInterfaceType() &&
- isColonOrRSquareBracket(NextToken())) {
- // Fake up a Declarator to use with ActOnTypeName.
- Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
- TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
- if (Ty.isInvalid()) {
- SkipUntil(tok::r_brace, /*StopAtSemi=*/true, /*DontConsume=*/true);
- if (Tok.is(tok::semi))
- ConsumeToken();
- return StmtError();
- }
-
- ExprResult MsgExpr = ParseObjCMessageExpressionBody(SourceLocation(),
- SourceLocation(),
- Ty.get(), 0);
- return ParseExprStatement(attrs, MsgExpr);
- }
-
- // Objective-C supports syntax of the form 'id<proto1,proto2>' where
- // 'id' is a specific typedef and 'itf<proto1,proto2>' where 'itf' is
- // an Objective-C interface.
- if (Tok.is(tok::less) && getLang().ObjC1)
- ParseObjCProtocolQualifiers(DS);
-
- SourceLocation DeclStart = NameLoc, DeclEnd;
- DeclGroupPtrTy Decl = ParseSimpleDeclaration(DS, Stmts,
- Declarator::BlockContext,
- DeclEnd, true);
- return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
- }
-
- // In C++, we might also have a functional-style cast. Just annotate
- // this as a type token.
+ case Sema::NC_Type:
Tok.setKind(tok::annot_typename);
setTypeAnnotation(Tok, Classification.getType());
Tok.setAnnotationEndLoc(NameLoc);
Tok.setLocation(NameLoc);
PP.AnnotateCachedTokens(Tok);
break;
- }
case Sema::NC_Expression:
ConsumeToken(); // the identifier