Make MatchRHSPunctuation smarter, allowing its clients to be simpler.

llvm-svn: 38926
This commit is contained in:
Chris Lattner 2006-08-15 04:55:54 +00:00
parent e37e2336b4
commit 04f8019616
6 changed files with 25 additions and 25 deletions

View File

@ -504,7 +504,7 @@ void Parser::ParseStructUnionSpecifier(DeclSpec &DS) {
}
}
MatchRHSPunctuation(tok::r_brace, LBraceLoc, "{",diag::err_expected_rbrace);
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
// If attributes exist after struct contents, parse them.
if (Tok.getKind() == tok::kw___attribute)
@ -580,8 +580,7 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS) {
}
// Eat the }.
MatchRHSPunctuation(tok::r_brace, LBraceLoc, "{",
diag::err_expected_rbrace);
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
// If attributes exist after the identifier list, parse them.
if (Tok.getKind() == tok::kw___attribute)
@ -886,8 +885,7 @@ void Parser::ParseParenDeclarator(Declarator &D) {
ParseDeclaratorInternal(D);
// Match the ')'.
MatchRHSPunctuation(tok::r_paren, StartLoc, "(",
diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, StartLoc);
return;
}
@ -1072,7 +1070,7 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
return;
}
MatchRHSPunctuation(tok::r_square, StartLoc, "[", diag::err_expected_rsquare);
MatchRHSPunctuation(tok::r_square, StartLoc);
// If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if
// it was not a constant expression.

View File

@ -541,7 +541,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
ConsumeBracket();
ParseExpression();
// Match the ']'.
MatchRHSPunctuation(tok::r_square, Loc, "[", diag::err_expected_rsquare);
MatchRHSPunctuation(tok::r_square, Loc);
break;
case tok::l_paren: // p-e: p-e '(' argument-expression-list[opt] ')'
@ -558,7 +558,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
}
// Match the ')'.
MatchRHSPunctuation(tok::r_paren, Loc, "(", diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, Loc);
break;
case tok::arrow: // postfix-expression: p-e '->' identifier
@ -678,8 +678,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() {
return Res;
}
MatchRHSPunctuation(tok::r_square, LSquareLoc, "[",
diag::err_expected_rsquare);
MatchRHSPunctuation(tok::r_square, LSquareLoc);
} else {
break;
}
@ -708,8 +707,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() {
break;
}
MatchRHSPunctuation(tok::r_paren, LParenLoc, "(",
diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, LParenLoc);
// These can be followed by postfix-expr pieces because they are
// primary-expressions.
@ -763,7 +761,7 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType) {
ParseTypeName();
// Match the ')'.
MatchRHSPunctuation(tok::r_paren, OpenLoc, "(", diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, OpenLoc);
if (Tok.getKind() == tok::l_brace) {
if (!getLang().C99) // Compound literals don't exist in C90.
@ -787,6 +785,6 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType) {
if (Result.isInvalid)
SkipUntil(tok::r_paren);
else
MatchRHSPunctuation(tok::r_paren, OpenLoc, "(", diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, OpenLoc);
return Result;
}

View File

@ -107,8 +107,7 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() {
}
}
MatchRHSPunctuation(tok::r_square, StartLoc, "[",
diag::err_expected_rsquare);
MatchRHSPunctuation(tok::r_square, StartLoc);
break;
}
case tok::identifier: {
@ -186,8 +185,7 @@ Parser::ExprResult Parser::ParseInitializer() {
}
// Match the '}'.
MatchRHSPunctuation(tok::r_brace, LBraceLoc, "{",
diag::err_expected_rbrace);
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
return ExprResult(false);
}

View File

@ -501,7 +501,7 @@ void Parser::ParseForStatement() {
}
// Match the ')'.
MatchRHSPunctuation(tok::r_paren, LParenLoc, "(", diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, LParenLoc);
// Read the body statement.
ParseStatement();

View File

@ -44,13 +44,20 @@ void Parser::Diag(SourceLocation Loc, unsigned DiagID,
/// present. If not present, it emits the specified diagnostic indicating
/// that the parser failed to match the RHS of the token at LHSLoc. LHSName
/// should be the name of the unmatched LHS token.
void Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc,
const char *LHSName, unsigned DiagID) {
void Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc) {
if (Tok.getKind() == RHSTok) {
ConsumeAnyToken();
} else {
Diag(Tok, DiagID);
const char *LHSName = "unknown";
diag::kind DID = diag::err_parse_error;
switch (RHSTok) {
default: break;
case tok::r_paren : LHSName = "("; DID = diag::err_expected_rparen; break;
case tok::r_brace : LHSName = "{"; DID = diag::err_expected_rbrace; break;
case tok::r_square: LHSName = "["; DID = diag::err_expected_rsquare; break;
}
Diag(Tok, DID);
Diag(LHSLoc, diag::err_matching, LHSName);
SkipUntil(RHSTok);
}
@ -403,5 +410,5 @@ void Parser::ParseSimpleAsm() {
// TODO: Diagnose: wide string literal in 'asm'
MatchRHSPunctuation(tok::r_paren, Loc, "(", diag::err_expected_rparen);
MatchRHSPunctuation(tok::r_paren, Loc);
}

View File

@ -156,8 +156,7 @@ private:
/// present. If not present, it emits the specified diagnostic indicating
/// that the parser failed to match the RHS of the token at LHSLoc. LHSName
/// should be the name of the unmatched LHS token.
void MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc,
const char *LHSName, unsigned Diag);
void MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc);
/// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
/// input. If so, it is consumed and false is returned.