aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Parse/ParseExpr.cpp32
-rw-r--r--lib/Parse/ParseStmt.cpp15
2 files changed, 20 insertions, 27 deletions
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 12761e8d9f..c990c52e7b 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -174,11 +174,8 @@ static prec::Level getBinOpPrecedence(tok::TokenKind Kind,
/// expression: [C99 6.5.17]
/// assignment-expression ...[opt]
/// expression ',' assignment-expression ...[opt]
-///
-/// \param Primary if non-empty, an already-parsed expression that will be used
-/// as the first primary expression.
-ExprResult Parser::ParseExpression(ExprResult Primary) {
- ExprResult LHS(ParseAssignmentExpression(Primary));
+ExprResult Parser::ParseExpression() {
+ ExprResult LHS(ParseAssignmentExpression());
return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
}
@@ -214,27 +211,16 @@ Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
}
/// ParseAssignmentExpression - Parse an expr that doesn't include commas.
-///
-/// \param Primary if non-empty, an already-parsed expression that will be used
-/// as the first primary expression.
-ExprResult Parser::ParseAssignmentExpression(ExprResult Primary) {
+ExprResult Parser::ParseAssignmentExpression() {
if (Tok.is(tok::code_completion)) {
- if (Primary.isUsable())
- Actions.CodeCompletePostfixExpression(getCurScope(), Primary);
- else
- Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression);
+ Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression);
ConsumeCodeCompletionToken();
}
- if (!Primary.isUsable() && Tok.is(tok::kw_throw))
+ if (Tok.is(tok::kw_throw))
return ParseThrowExpression();
- ExprResult LHS;
- if (Primary.get() || Primary.isInvalid())
- LHS = ParsePostfixExpressionSuffix(Primary);
- else
- LHS = ParseCastExpression(false, false, ParsedType());
-
+ ExprResult LHS = ParseCastExpression(false, false, ParsedType());
return ParseRHSOfBinaryExpression(move(LHS), prec::Assignment);
}
@@ -628,6 +614,12 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
case tok::kw_nullptr:
return Actions.ActOnCXXNullPtrLiteral(ConsumeToken());
+ case tok::annot_primary_expr:
+ assert(Res.get() == 0 && "Stray primary-expression annotation?");
+ Res = getExprAnnotation(Tok);
+ ConsumeToken();
+ break;
+
case tok::identifier: { // primary-expression: identifier
// unqualified-id: identifier
// constant: enumeration-constant
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 2ab2fcc69d..07cef5597b 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -146,13 +146,15 @@ Retry:
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
- return ParseExprStatement(attrs, Classification.getExpression());
+ Tok.setKind(tok::annot_primary_expr);
+ setExprAnnotation(Tok, Classification.getExpression());
+ Tok.setAnnotationEndLoc(NameLoc);
+ PP.AnnotateCachedTokens(Tok);
+ break;
case Sema::NC_TypeTemplate:
case Sema::NC_FunctionTemplate: {
@@ -210,7 +212,7 @@ Retry:
return StmtError();
}
- return ParseExprStatement(attrs, ExprResult());
+ return ParseExprStatement(attrs);
}
case tok::kw_case: // C99 6.8.1: labeled-statement
@@ -288,14 +290,13 @@ Retry:
}
/// \brief Parse an expression statement.
-StmtResult Parser::ParseExprStatement(ParsedAttributes &Attrs,
- ExprResult Primary) {
+StmtResult Parser::ParseExprStatement(ParsedAttributes &Attrs) {
// If a case keyword is missing, this is where it should be inserted.
Token OldToken = Tok;
// FIXME: Use the attributes
// expression[opt] ';'
- ExprResult Expr(ParseExpression(Primary));
+ ExprResult Expr(ParseExpression());
if (Expr.isInvalid()) {
// If the expression is invalid, skip ahead to the next semicolon or '}'.
// Not doing this opens us up to the possibility of infinite loops if