[cfe-commits] r66661 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.def include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseTentative.cpp lib/Parse/Parser.cpp
Anders Carlsson
andersca at mac.com
Wed Mar 11 09:27:10 PDT 2009
Author: andersca
Date: Wed Mar 11 11:27:10 2009
New Revision: 66661
URL: http://llvm.org/viewvc/llvm-project?rev=66661&view=rev
Log:
Add parser support for static_assert.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.def
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Parse/Parser.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.def?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.def Wed Mar 11 11:27:10 2009
@@ -142,6 +142,8 @@
"expected ';' after expression")
DIAG(err_expected_semi_after_method_proto, ERROR,
"expected ';' after method prototype")
+DIAG(err_expected_semi_after_static_assert, ERROR,
+ "expected ';' after static_assert")
DIAG(err_expected_semi_for, ERROR,
"expected ';' in 'for' statement specifier")
DIAG(err_expected_colon_after, ERROR,
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Mar 11 11:27:10 2009
@@ -884,6 +884,15 @@
virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method) {
}
+ virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation LParenLoc,
+ ExprArg AssertExpr,
+ SourceLocation CommaLoc,
+ ExprArg AssertMessageExpr,
+ SourceLocation RParenLoc) {
+ return 0;
+ }
+
+
//===------------------------- C++ Expressions --------------------------===//
/// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Mar 11 11:27:10 2009
@@ -989,6 +989,7 @@
DeclTy *ParseUsingDirectiveOrDeclaration(unsigned Context);
DeclTy *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc);
DeclTy *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc);
+ DeclTy *ParseStaticAssertDeclaration();
//===--------------------------------------------------------------------===//
// C++ 9: classes [class] and C structs/unions.
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Mar 11 11:27:10 2009
@@ -225,6 +225,7 @@
/// [C++] namespace-definition
/// [C++] using-directive
/// [C++] using-declaration [TODO]
+// [C++0x] static_assert-declaration
/// others... [FIXME]
///
Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) {
@@ -236,6 +237,8 @@
return ParseNamespace(Context);
case tok::kw_using:
return ParseUsingDirectiveOrDeclaration(Context);
+ case tok::kw_static_assert:
+ return ParseStaticAssertDeclaration();
default:
return ParseSimpleDeclaration(Context);
}
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Mar 11 11:27:10 2009
@@ -217,6 +217,55 @@
return 0;
}
+/// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion.
+///
+/// static_assert-declaration:
+/// static_assert ( constant-expression , string-literal ) ;
+///
+Parser::DeclTy *Parser::ParseStaticAssertDeclaration() {
+ assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration");
+ SourceLocation StaticAssertLoc = ConsumeToken();
+
+ if (Tok.isNot(tok::l_paren)) {
+ Diag(Tok, diag::err_expected_lparen);
+ return 0;
+ }
+
+ SourceLocation LParenLoc = ConsumeParen();
+
+ OwningExprResult AssertExpr(ParseConstantExpression());
+ if (AssertExpr.isInvalid()) {
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ if (Tok.isNot(tok::comma)) {
+ Diag(Tok, diag::err_expected_comma);
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ SourceLocation CommaLoc = ConsumeToken();
+
+ if (Tok.isNot(tok::string_literal)) {
+ Diag(Tok, diag::err_expected_string_literal);
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ OwningExprResult AssertMessage(ParseStringLiteralExpression());
+ if (AssertMessage.isInvalid())
+ return 0;
+
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+
+ ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert);
+
+ return Actions.ActOnStaticAssertDeclaration(LParenLoc, move(AssertExpr),
+ CommaLoc, move(AssertMessage),
+ RParenLoc);
+}
+
/// ParseClassName - Parse a C++ class-name, which names a class. Note
/// that we only check that the result names a type; semantic analysis
/// will need to verify that the type names a class. The result is
@@ -568,7 +617,7 @@
/// function-definition ';'[opt]
/// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO]
/// using-declaration [TODO]
-/// [C++0x] static_assert-declaration [TODO]
+/// [C++0x] static_assert-declaration
/// template-declaration [TODO]
/// [GNU] '__extension__' member-declaration
///
@@ -588,6 +637,10 @@
/// '=' constant-expression
///
Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
+ // static_assert-declaration
+ if (Tok.is(tok::kw_static_assert))
+ return ParseStaticAssertDeclaration();
+
// Handle: member-declaration ::= '__extension__' member-declaration
if (Tok.is(tok::kw___extension__)) {
// __extension__ silences extension warnings in the subexpression.
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Wed Mar 11 11:27:10 2009
@@ -29,7 +29,7 @@
/// namespace-alias-definition
/// using-declaration
/// using-directive
-/// [C++0x] static_assert-declaration [TODO]
+/// [C++0x] static_assert-declaration
///
/// asm-definition:
/// 'asm' '(' string-literal ')' ';'
@@ -46,9 +46,6 @@
/// 'using' 'namespace' '::'[opt] nested-name-specifier[opt]
/// namespace-name ';'
///
-/// [C++0x] static_assert-declaration: [TODO]
-/// [C++0x] static_assert '(' constant-expression ',' string-literal ')' ';'
-///
bool Parser::isCXXDeclarationStatement() {
switch (Tok.getKind()) {
// asm-definition
@@ -59,6 +56,9 @@
// using-directive
case tok::kw_using:
return true;
+ case tok::kw_static_assert:
+ // static_assert-declaration
+ return true;
default:
// simple-declaration
return isCXXSimpleDeclaration();
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=66661&r1=66660&r2=66661&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Mar 11 11:27:10 2009
@@ -408,6 +408,7 @@
case tok::kw_typedef:
case tok::kw_template:
case tok::kw_export: // As in 'export template'
+ case tok::kw_static_assert:
// A function definition cannot start with a these keywords.
return ParseDeclaration(Declarator::FileContext);
default:
More information about the cfe-commits
mailing list