[cfe-commits] r38823 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp Parse/Parser.cpp include/clang/Parse/Decl.h include/clang/Parse/DeclSpec.h include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:24:56 PDT 2007
Author: sabre
Date: Wed Jul 11 11:24:56 2007
New Revision: 38823
URL: http://llvm.org/viewvc/llvm-project?rev=38823&view=rev
Log:
Start capturing declarator information in a new Declarator object.
Modified:
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Parse/Parser.cpp
cfe/cfe/trunk/include/clang/Parse/Decl.h
cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
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=38823&r1=38822&r2=38823&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:24:56 2007
@@ -198,7 +198,7 @@
/// '*' type-qualifier-list[opt]
/// '*' type-qualifier-list[opt] pointer
///
-void Parser::ParseDeclarator() {
+void Parser::ParseDeclarator(Declarator &D) {
while (Tok.getKind() == tok::star) { // '*' -> pointer.
ConsumeToken(); // Eat the *.
DeclSpec DS;
@@ -206,7 +206,7 @@
// TODO: do something with DS.
}
- ParseDirectDeclarator();
+ ParseDirectDeclarator(D);
}
/// ParseTypeQualifierListOpt
@@ -286,9 +286,11 @@
/// identifier
/// identifier-list ',' identifier
///
-void Parser::ParseDirectDeclarator() {
+void Parser::ParseDirectDeclarator(Declarator &D) {
// Parse the first direct-declarator seen.
if (Tok.getKind() == tok::identifier) {
+ assert(Tok.getIdentifierInfo() && "Not an identifier?");
+ D.SetIdentifier(Tok.getIdentifierInfo());
ConsumeToken();
} else if (0 && Tok.getKind() == tok::l_paren) {
//char (*X);
Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38823&r1=38822&r2=38823&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:24:56 2007
@@ -107,23 +107,26 @@
assert(0 && "Unimp!");
- // Parse the common declarator piece.
- ParseDeclarator();
+ // Parse the declarator.
+ {
+ Declarator DeclaratorInfo(DS);
+ ParseDeclarator(DeclaratorInfo);
-
- // If the declarator was a function type... handle it.
+ // 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!");
+ // 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::comma) {
// Consume the comma.
ConsumeToken();
- // Parse the common declarator piece.
- ParseDeclarator();
+ // Parse the declarator.
+ Declarator DeclaratorInfo(DS);
+ ParseDeclarator(DeclaratorInfo);
// declarator '=' initializer
if (Tok.getKind() == tok::equal)
Modified: cfe/cfe/trunk/include/clang/Parse/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Decl.h?rev=38823&r1=38822&r2=38823&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Decl.h Wed Jul 11 11:24:56 2007
@@ -18,7 +18,7 @@
namespace llvm {
namespace clang {
-
+class IdentifierInfo;
/// Decl - This represents one declaration (or definition), e.g. a variable,
/// typedef, function, struct, etc.
Modified: cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=38823&r1=38822&r2=38823&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:24:56 2007
@@ -20,6 +20,7 @@
namespace clang {
class LangOptions;
class SourceLocation;
+ class IdentifierInfo;
/// DeclSpec - This class captures information about "declaration specifiers",
/// which encompases storage-class-specifiers, type-specifiers, type-qualifiers,
@@ -128,6 +129,23 @@
/// DeclSpec is guaranteed self-consistent, even if an error occurred.
void Finish(SourceLocation Loc, Diagnostic &D,const LangOptions &Lang);
};
+
+
+/// DeclaratorInfo - Information about one declarator, including the parsed type
+/// information and the identifier. When the declarator is fully formed, this
+/// is turned into the appropriate Decl object.
+class Declarator {
+ const DeclSpec &DS;
+ IdentifierInfo *Identifier;
+public:
+ Declarator(const DeclSpec &ds) : DS(ds) {
+ Identifier = 0;
+ }
+
+ IdentifierInfo *getIdentifier() const { return Identifier; }
+ void SetIdentifier(IdentifierInfo *ID) { Identifier = ID; }
+};
+
} // end namespace clang
} // end namespace llvm
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=38823&r1=38822&r2=38823&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:24:56 2007
@@ -21,6 +21,7 @@
namespace clang {
class ParserActions;
class DeclSpec;
+ class Declarator;
class Scope;
/// Parser - This implements a parser for the C family of languages. After
@@ -78,9 +79,9 @@
// C99 6.7: Declarations.
void ParseDeclarationSpecifiers(DeclSpec &DS);
- void ParseDeclarator();
+ void ParseDeclarator(Declarator &D);
void ParseTypeQualifierListOpt(DeclSpec &DS);
- void ParseDirectDeclarator();
+ void ParseDirectDeclarator(Declarator &D);
};
More information about the cfe-commits
mailing list