diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-10-16 00:33:54 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-10-16 00:33:54 +0000 |
| commit | 2dacc3ff2efb981deea1188f097c7e5c8330990f (patch) | |
| tree | 742dbd466e8bd799e30f1482951b8efb433df1a9 /clang/Sema/ASTStreamer.cpp | |
| parent | a11999d83a8ed1a2661feb858f0af786f2b829ad (diff) | |
| download | bcm5719-llvm-2dacc3ff2efb981deea1188f097c7e5c8330990f.tar.gz bcm5719-llvm-2dacc3ff2efb981deea1188f097c7e5c8330990f.zip | |
Changes through out the parser and actions/ast interface to return top-level
declarations through the asm streamer. For a testcase like:
int G;
int H, I, *J;
int func() {}
'clang -parse-print-ast' prints:
Read top-level decl: G
Read top-level decl: H
Read top-level decl: I
Read top-level decl: J
Read top-level decl: func
llvm-svn: 38992
Diffstat (limited to 'clang/Sema/ASTStreamer.cpp')
| -rw-r--r-- | clang/Sema/ASTStreamer.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/clang/Sema/ASTStreamer.cpp b/clang/Sema/ASTStreamer.cpp index 7db53f3ae6f..2e6c7f6b790 100644 --- a/clang/Sema/ASTStreamer.cpp +++ b/clang/Sema/ASTStreamer.cpp @@ -19,15 +19,17 @@ using namespace clang; /// Interface to the Builder.cpp file. /// -Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo); +Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo, + std::vector<Decl*> &LastInGroupList); namespace { class ASTStreamer { Parser P; + std::vector<Decl*> LastInGroupList; public: ASTStreamer(Preprocessor &PP, unsigned MainFileID, bool FullLocInfo) - : P(PP, *CreateASTBuilderActions(PP, FullLocInfo)) { + : P(PP, *CreateASTBuilderActions(PP, FullLocInfo, LastInGroupList)) { PP.EnterSourceFile(MainFileID, 0, true); // Initialize the parser. @@ -37,9 +39,33 @@ namespace { /// ReadTopLevelDecl - Parse and return the next top-level declaration. Decl *ReadTopLevelDecl() { Parser::DeclTy *Result; - if (P.ParseTopLevelDecl(Result)) - return 0; - Result = (Decl*)1; // FIXME! + + /// If the previous time through we read something like 'int X, Y', return + /// the next declarator. + if (!LastInGroupList.empty()) { + Result = LastInGroupList.back(); + LastInGroupList.pop_back(); + return (Decl*)Result; + } + + do { + if (P.ParseTopLevelDecl(Result)) + return 0; // End of file. + + // If we got a null return and something *was* parsed, try again. This + // is due to a top-level semicolon, an action override, or a parse error + // skipping something. + } while (Result == 0); + + // If we parsed a declspec with multiple declarators, reverse the list and + // return the first one. + if (!LastInGroupList.empty()) { + LastInGroupList.push_back((Decl*)Result); + std::reverse(LastInGroupList.begin(), LastInGroupList.end()); + Result = LastInGroupList.back(); + LastInGroupList.pop_back(); + } + return (Decl*)Result; } |

