Several fixes/simplifications surrounding how we stream top-level decl AST's.
The following code...
typedef struct cssm_data {} CSSM_DATA, *CSSM_DATA_PTR;
struct Y { int A; };
struct X { int A; } D;
struct X E, F;
...now produces the following output...
> ../../Debug/bin/clang xx.c -ast-print
Read top-level tag decl: 'cssm_data'
typedef struct cssm_data CSSM_DATA;
typedef struct cssm_data *CSSM_DATA_PTR;
Read top-level tag decl: 'Y'
Read top-level tag decl: 'X'
Read top-level variable decl: 'D'
Read top-level variable decl: 'E'
Read top-level variable decl: 'F'
...which is much more accurate than the previous -ast-print output...
typedef struct cssm_data CSSM_DATA;
typedef struct cssm_data CSSM_DATA;
Read top-level variable decl: 'D'
Read top-level variable decl: 'E'
Read top-level variable decl: 'E'
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44421 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/ASTStreamer.cpp b/Sema/ASTStreamer.cpp
index be43289..5a372da 100644
--- a/Sema/ASTStreamer.cpp
+++ b/Sema/ASTStreamer.cpp
@@ -24,10 +24,10 @@
namespace {
class ASTStreamer {
Parser P;
- std::vector<Decl*> LastInGroupList;
+ std::vector<Decl*> TopLevelDeclList;
public:
ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
- : P(pp, *new Sema(pp, ctxt, LastInGroupList)) {
+ : P(pp, *new Sema(pp, ctxt, TopLevelDeclList)) {
pp.EnterMainSourceFile(MainFileID);
// Initialize the parser.
@@ -53,29 +53,28 @@
/// 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();
+ if (!TopLevelDeclList.empty()) {
+ Result = TopLevelDeclList.back();
+ TopLevelDeclList.pop_back();
return static_cast<Decl*>(Result);
}
do {
- if (P.ParseTopLevelDecl(Result))
+ if (P.ParseTopLevelDecl())
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);
+ } while (TopLevelDeclList.size() == 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();
- }
+ if (TopLevelDeclList.size() > 1)
+ std::reverse(TopLevelDeclList.begin(), TopLevelDeclList.end());
+
+ Result = TopLevelDeclList.back();
+ TopLevelDeclList.pop_back();
return static_cast<Decl*>(Result);
}