[cfe-commits] r38862 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp Parse/ParseExpr.cpp Parse/ParseStmt.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:17 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:17 2007
New Revision: 38862
URL: http://llvm.org/viewvc/llvm-project?rev=38862&view=rev
Log:
Implement most of unary-expression parsing.
Modified:
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Parse/ParseExpr.cpp
cfe/cfe/trunk/Parse/ParseStmt.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:17 2007
@@ -486,7 +486,7 @@
} else {
// expected ')': skip until we find ')'.
Diag(Tok, diag::err_expected_rparen);
- Diag(StartLoc, diag::err_matching);
+ Diag(StartLoc, diag::err_matching, "(");
SkipUntil(tok::r_paren);
}
return;
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:25:17 2007
@@ -25,7 +25,7 @@
Parser::ExprTy Parser::ParseExpression() {
- ParsePostfixExpression();
+ ParseCastExpression();
return 0;
}
@@ -34,6 +34,116 @@
ParseExpression();
}
+
+void Parser::ParseCastExpression() {
+ ParseUnaryExpression();
+}
+
+/// ParseUnaryExpression
+/// unary-expression: [C99 6.5.3]
+/// postfix-expression
+/// '++' unary-expression
+/// '--' unary-expression
+/// unary-operator cast-expression
+/// 'sizeof' unary-expression
+/// 'sizeof' '(' type-name ')'
+/// [GNU] '__alignof' unary-expression
+/// [GNU] '__alignof' '(' type-name ')'
+/// [GNU] '&&' identifier
+/// unary-operator: one of
+/// '&' '*' '+' '-' '~' '!'
+/// [GNU] '__extension__' '__real' '__imag'
+///
+void Parser::ParseUnaryExpression() {
+ switch (Tok.getKind()) {
+ default: // unary-expression: postfix-expression
+ ParsePostfixExpression();
+ break;
+ case tok::plusplus: // unary-expression: '++' unary-expression
+ case tok::minusminus: // unary-expression: '--' unary-expression
+ ConsumeToken();
+ ParseUnaryExpression();
+ break;
+ case tok::amp: // unary-expression: '&' cast-expression
+ case tok::star: // unary-expression: '*' cast-expression
+ case tok::plus: // unary-expression: '+' cast-expression
+ case tok::minus: // unary-expression: '-' cast-expression
+ case tok::tilde: // unary-expression: '~' cast-expression
+ case tok::exclaim: // unary-expression: '!' cast-expression
+ case tok::kw___real: // unary-expression: '__real' cast-expression [GNU]
+ case tok::kw___imag: // unary-expression: '__real' cast-expression [GNU]
+ //case tok::kw__extension__: [TODO]
+ ConsumeToken();
+ ParseCastExpression();
+ break;
+
+ case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression
+ // unary-expression: 'sizeof' '(' type-name ')'
+ case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
+ // unary-expression: '__alignof' '(' type-name ')'
+ ParseSizeofAlignofExpression();
+ break;
+ case tok::ampamp: // unary-expression: '&&' identifier
+ Diag(Tok, diag::ext_gnu_address_of_label);
+ ConsumeToken();
+ if (Tok.getKind() == tok::identifier) {
+ ConsumeToken();
+ } else {
+ Diag(Tok, diag::err_expected_ident);
+ ConsumeToken(); // FIXME: Should just return error!
+ return;
+ }
+ break;
+ }
+}
+
+/// ParseSizeofAlignofExpression - Parse a sizeof or alignof expression.
+/// unary-expression: [C99 6.5.3]
+/// 'sizeof' unary-expression
+/// 'sizeof' '(' type-name ')'
+/// [GNU] '__alignof' unary-expression
+/// [GNU] '__alignof' '(' type-name ')'
+void Parser::ParseSizeofAlignofExpression() {
+ assert((Tok.getKind() == tok::kw_sizeof ||
+ Tok.getKind() == tok::kw___alignof) &&
+ "Not a sizeof/alignof expression!");
+ ConsumeToken();
+
+ // If the operand doesn't start with an '(', it must be an expression.
+ if (Tok.getKind() != tok::l_paren) {
+ ParseUnaryExpression();
+ return;
+ }
+
+ // If it starts with a '(', we know that it is either a parenthesized
+ // type-name, or it is a unary-expression that starts with a compound literal,
+ // or starts with a primary-expression that is a parenthesized expression.
+ SourceLocation LParenLoc = Tok.getLocation();
+ ConsumeParen();
+
+ if (isTypeSpecifierQualifier()) {
+ // This is now known to be either a parenthesized type-name, or a compound
+ // literal.
+
+
+ // FIXME: ParseTypeName.
+ assert(0 && "implement!");
+ } else {
+ // Otherwise, this is known to be a parenthesized-expression. Parse the
+ // rest of the parethesized-expression here.
+ ParseExpression();
+
+ }
+
+ if (Tok.getKind() == tok::r_paren) {
+ ConsumeParen();
+ } else {
+ Diag(Tok, diag::err_expected_rparen);
+ Diag(LParenLoc, diag::err_matching, "(");
+ SkipUntil(tok::r_paren);
+ }
+}
+
/// ParsePostfixExpression
/// postfix-expression: [C99 6.5.2]
/// primary-expression
@@ -132,7 +242,7 @@
ConsumeBracket();
} else {
Diag(Tok, diag::err_expected_rsquare);
- Diag(Loc, diag::err_matching);
+ Diag(Loc, diag::err_matching, "[");
SkipUntil(tok::r_square);
}
break;
@@ -154,7 +264,7 @@
ConsumeParen();
} else {
Diag(Tok, diag::err_expected_rparen);
- Diag(Loc, diag::err_matching);
+ Diag(Loc, diag::err_matching, "(");
SkipUntil(tok::r_paren);
}
break;
@@ -211,8 +321,9 @@
!getLang().NoExtensions) {
Diag(Tok, diag::ext_gnu_statement_expr);
ParseCompoundStatement();
- } else if (!ParenExprOnly && 0 /*type */) {
+ } else if (!ParenExprOnly && isTypeSpecifierQualifier()) {
// FIXME: Implement compound literals: C99 6.5.2.5. Type-name: C99 6.7.6.
+ assert(0 && "IMPLEMENT THIS!");
} else {
ParseExpression();
}
@@ -221,6 +332,6 @@
ConsumeParen();
} else {
Diag(Tok, diag::err_expected_rparen);
- Diag(OpenLoc, diag::err_matching);
+ Diag(OpenLoc, diag::err_matching, "(");
}
}
Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:25:17 2007
@@ -369,7 +369,7 @@
if (Tok.getKind() != tok::kw_while) {
Diag(Tok, diag::err_expected_while);
- Diag(DoLoc, diag::err_matching);
+ Diag(DoLoc, diag::err_matching, "do");
SkipUntil(tok::semi);
return;
}
@@ -419,7 +419,6 @@
ConsumeToken();
} else {
Diag(Tok, diag::err_expected_semi_for);
- Diag(ForLoc, diag::err_matching);
SkipUntil(tok::semi);
}
}
@@ -435,7 +434,6 @@
ConsumeToken();
} else {
Diag(Tok, diag::err_expected_semi_for);
- Diag(ForLoc, diag::err_matching);
SkipUntil(tok::semi);
}
@@ -450,7 +448,7 @@
ConsumeParen();
} else {
Diag(Tok, diag::err_expected_rparen);
- Diag(LParenLoc, diag::err_matching);
+ Diag(LParenLoc, diag::err_matching, "(");
SkipUntil(tok::r_paren);
return;
}
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:25:17 2007
@@ -258,6 +258,8 @@
"variable declaration in for loop is a c99-specific feature")
DIAG(ext_gnu_indirect_goto, EXTENSION,
"use of GNU indirect-goto extension")
+DIAG(ext_gnu_address_of_label, EXTENSION,
+ "use of GNU address-of-label extension")
DIAG(ext_gnu_statement_expr, EXTENSION,
"use of GNU statement expression extension")
@@ -302,7 +304,7 @@
/// special sort of diagnostic kind to indicate that it is the second half of
/// the previous diagnostic.
DIAG(err_matching, ERROR,
- "to match")
+ "to match this '%s'")
DIAG(err_invalid_decl_spec_combination, ERROR,
Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:17 2007
@@ -164,6 +164,9 @@
//ExprTy ParseExpression(); // Above.
void ParseAssignmentExpression(); // Expr that doesn't include commas.
+ void ParseCastExpression();
+ void ParseUnaryExpression();
+ void ParseSizeofAlignofExpression();
void ParsePostfixExpression();
void ParseParenExpression(bool ParenExprOnly = true);
void ParseStringLiteralExpression();
@@ -193,6 +196,7 @@
void ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D);
void ParseDeclarationSpecifiers(DeclSpec &DS);
bool isDeclarationSpecifier() const;
+ bool isTypeSpecifierQualifier() const { return false; } // FIXME!
/// ParseDeclarator - Parse and verify a newly-initialized declarator.
void ParseDeclarator(Declarator &D);
More information about the cfe-commits
mailing list