[cfe-commits] r38818 - in /cfe/cfe/trunk: Parse/DeclSpec.cpp Parse/ParseDecl.cpp Parse/Parser.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:24:54 PDT 2007
Author: sabre
Date: Wed Jul 11 11:24:54 2007
New Revision: 38818
URL: http://llvm.org/viewvc/llvm-project?rev=38818&view=rev
Log:
Continue work on declspecs and declarations
Modified:
cfe/cfe/trunk/Parse/DeclSpec.cpp
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Parse/Parser.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/DeclSpec.cpp?rev=38818&r1=38817&r2=38818&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/DeclSpec.cpp (original)
+++ cfe/cfe/trunk/Parse/DeclSpec.cpp Wed Jul 11 11:24:54 2007
@@ -224,12 +224,6 @@
}
}
- // If this is C99, require that at least one specifier is present!
- if (Lang.C99 && (getParsedSpecifiers() & PQ_TypeSpecifier) == 0) {
- D.Report(Loc, diag::w_type_defaults_to_int); // C99 2.7.2p2.
- TypeSpecType = TST_int;
- }
-
// Verify __thread.
if (SCS_thread_specified) {
if (StorageClassSpec == SCS_unspecified) {
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38818&r1=38817&r2=38818&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:24:54 2007
@@ -201,7 +201,9 @@
void Parser::ParseDeclarator() {
while (Tok.getKind() == tok::star) { // '*' -> pointer.
ConsumeToken(); // Eat the *.
- ParseTypeQualifierListOpt();
+ DeclSpec DS;
+ ParseTypeQualifierListOpt(DS);
+ // TODO: do something with DS.
}
ParseDirectDeclarator();
@@ -214,17 +216,39 @@
/// type-qualifier-list type-qualifier
/// [GNU] type-qualifier-list attributes [TODO]
///
-void Parser::ParseTypeQualifierListOpt() {
+void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) {
+ SourceLocation StartLoc = Tok.getLocation();
while (1) {
+ int isInvalid = false;
+ const char *PrevSpec = 0;
+
switch (Tok.getKind()) {
- default: break;
+ default:
+ // If this is not a declaration specifier token, we're done reading decl
+ // specifiers. First verify that DeclSpec's are consistent.
+ DS.Finish(StartLoc, Diags, getLang());
+ return;
// TODO: attributes.
case tok::kw_const:
+ isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , PrevSpec, getLang())*2;
+ break;
case tok::kw_volatile:
+ isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, PrevSpec, getLang())*2;
+ break;
case tok::kw_restrict:
- ConsumeToken();
+ isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, PrevSpec, getLang())*2;
break;
}
+
+ // If the specifier combination wasn't legal, issue a diagnostic.
+ if (isInvalid) {
+ assert(PrevSpec && "Method did not return previous specifier!");
+ if (isInvalid == 1) // Error.
+ Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec);
+ else // extwarn.
+ Diag(Tok, diag::ext_duplicate_declspec, PrevSpec);
+ }
+ ConsumeToken();
}
}
@@ -234,7 +258,11 @@
/// identifier
/// '(' declarator ')'
/// [GNU] '(' attributes declarator ')'
-/// direct-declarator array-declarator
+/// [C90] direct-declarator [ constant-expression[opt] ]
+/// [C99] direct-declarator [ type-qual-list[opt] assignment-expr[opt] ]
+/// [C99] direct-declarator [ 'static' type-qual-list[opt] assignment-expr ]
+/// [C99] direct-declarator [ type-qual-list 'static' assignment-expr ]
+/// [C99] direct-declarator [ type-qual-list[opt] * ]
/// direct-declarator '(' parameter-type-list ')'
/// direct-declarator '(' identifier-list[opt] ')'
/// [GNU] direct-declarator '(' parameter-forward-declarations
@@ -259,10 +287,22 @@
/// identifier-list ',' identifier
///
void Parser::ParseDirectDeclarator() {
+ // Parse the first direct-declarator seen.
if (Tok.getKind() == tok::identifier) {
ConsumeToken();
- return;
+ } else if (0 && Tok.getKind() == tok::l_paren) {
+ //char (*X);
+ //int (*XX)(void);
}
- // FIXME: missing most stuff.
- assert(0 && "Unknown token!");
+
+ while (1) {
+ if (Tok.getKind() == tok::l_paren) {
+ assert(0 && "Unimp!");
+ } else if (Tok.getKind() == tok::l_square) {
+ assert(0 && "Unimp!");
+ } else {
+ break;
+ }
+ }
+
}
Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38818&r1=38817&r2=38818&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:24:54 2007
@@ -77,7 +77,7 @@
/// compound-statement [TODO]
/// declaration: [C99 6.7]
/// declaration-specifiers init-declarator-list[opt] ';' [TODO]
-/// [!C99] init-declarator-list ';' [TODO]
+/// [!C99] init-declarator-list ';' [TODO]
/// [OMP] threadprivate-directive [TODO]
///
/// init-declarator-list: [C99 6.7]
@@ -96,10 +96,33 @@
// Parse the common declarator piece.
ParseDeclarator();
- // If the declarator was a function type...
-
+ // If the declarator was a function type... handle it.
+
+ // must be: decl-spec[opt] declarator init-declarator-list
+ // Parse declarator '=' initializer.
+ if (Tok.getKind() == tok::equal)
+ assert(0 && "cannot handle initializer yet!");
+
+ while (Tok.getKind() != tok::semi) {
+ if (Tok.getKind() != tok::comma && Tok.getKind() != tok::semi) {
+ // FIXME: skip toe nd of block or statement
+ Diag(Tok, diag::err_parse_error);
+ ConsumeToken();
+ }
+
+ // Consume the comma.
+ ConsumeToken();
+
+ // Parse the common declarator piece.
+ ParseDeclarator();
+
+ // declarator '=' initializer
+ if (Tok.getKind() == tok::equal)
+ assert(0 && "cannot handle initializer yet!");
+
+
+ }
switch (Tok.getKind()) {
- case tok::equal: // must be: decl-spec[opt] declarator init-declarator-list
case tok::comma: // must be: decl-spec[opt] declarator init-declarator-list
default:
assert(0 && "unimp!");
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=38818&r1=38817&r2=38818&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:24:54 2007
@@ -250,6 +250,8 @@
DIAG(ext_thread_before, EXTENSION,
"'__thread' before 'static'")
+DIAG(err_parse_error, ERROR,
+ "parse error")
DIAG(err_invalid_decl_spec_combination, ERROR,
"cannot combine with previous '%s' declaration specifier")
DIAG(err_invalid_sign_spec, 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=38818&r1=38817&r2=38818&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:24:54 2007
@@ -77,7 +77,7 @@
void ParseDeclarationSpecifiers(DeclSpec &DS);
void ParseDeclarator();
- void ParseTypeQualifierListOpt();
+ void ParseTypeQualifierListOpt(DeclSpec &DS);
void ParseDirectDeclarator();
};
More information about the cfe-commits
mailing list