forked from OSchip/llvm-project
Start capturing declarator information in a new Declarator object.
llvm-svn: 38823
This commit is contained in:
parent
2df305abfa
commit
15356a7065
|
@ -198,7 +198,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
|
|||
/// '*' 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 @@ void Parser::ParseDeclarator() {
|
|||
// TODO: do something with DS.
|
||||
}
|
||||
|
||||
ParseDirectDeclarator();
|
||||
ParseDirectDeclarator(D);
|
||||
}
|
||||
|
||||
/// ParseTypeQualifierListOpt
|
||||
|
@ -286,9 +286,11 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) {
|
|||
/// 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);
|
||||
|
|
|
@ -107,23 +107,26 @@ void Parser::ParseDeclarationOrFunctionDefinition() {
|
|||
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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace llvm {
|
|||
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 @@ public:
|
|||
/// 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
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace llvm {
|
|||
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 @@ private:
|
|||
// C99 6.7: Declarations.
|
||||
void ParseDeclarationSpecifiers(DeclSpec &DS);
|
||||
|
||||
void ParseDeclarator();
|
||||
void ParseDeclarator(Declarator &D);
|
||||
void ParseTypeQualifierListOpt(DeclSpec &DS);
|
||||
void ParseDirectDeclarator();
|
||||
void ParseDirectDeclarator(Declarator &D);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue