[cfe-commits] r44445 - in /cfe/trunk: Parse/Parser.cpp Sema/ASTStreamer.cpp Sema/Sema.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/Parse/Parser.h
Steve Naroff
snaroff at apple.com
Thu Nov 29 15:05:20 PST 2007
Author: snaroff
Date: Thu Nov 29 17:05:20 2007
New Revision: 44445
URL: http://llvm.org/viewvc/llvm-project?rev=44445&view=rev
Log:
Yesterday, I simplified how we stream top-level decls.
After a discussion with Ted, we both came to the conclusion that adding a "HandleTopLevelDeclaration" hook to ASConsumer is far more elegant. The default implementation of HandleTopLevelDeclaration will be responsible for iterating over the ScopedDecl (which has a chain of the decls:-).
TODO: Once Ted adds HandleTopLevelDeclaration, make sure TagDecls are chainged appropriately...
Modified:
cfe/trunk/Parse/Parser.cpp
cfe/trunk/Sema/ASTStreamer.cpp
cfe/trunk/Sema/Sema.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=44445&r1=44444&r2=44445&view=diff
==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Thu Nov 29 17:05:20 2007
@@ -259,10 +259,11 @@
/// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
/// action tells us to. This returns true if the EOF was encountered.
-bool Parser::ParseTopLevelDecl() {
+bool Parser::ParseTopLevelDecl(DeclTy*& Result) {
+ Result = 0;
if (Tok.is(tok::eof)) return true;
- ParseExternalDeclaration();
+ Result = ParseExternalDeclaration();
return false;
}
@@ -280,7 +281,8 @@
void Parser::ParseTranslationUnit() {
Initialize();
- while (!ParseTopLevelDecl())
+ DeclTy *Res;
+ while (!ParseTopLevelDecl(Res))
/*parse them all*/;
Finalize();
Modified: cfe/trunk/Sema/ASTStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/ASTStreamer.cpp?rev=44445&r1=44444&r2=44445&view=diff
==============================================================================
--- cfe/trunk/Sema/ASTStreamer.cpp (original)
+++ cfe/trunk/Sema/ASTStreamer.cpp Thu Nov 29 17:05:20 2007
@@ -24,10 +24,9 @@
namespace {
class ASTStreamer {
Parser P;
- std::vector<Decl*> TopLevelDeclList;
public:
ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
- : P(pp, *new Sema(pp, ctxt, TopLevelDeclList)) {
+ : P(pp, *new Sema(pp, ctxt)) {
pp.EnterMainSourceFile(MainFileID);
// Initialize the parser.
@@ -51,30 +50,14 @@
Decl *ASTStreamer::ReadTopLevelDecl() {
Parser::DeclTy *Result;
- /// If the previous time through we read something like 'int X, Y', return
- /// the next declarator.
- if (!TopLevelDeclList.empty()) {
- Result = TopLevelDeclList.back();
- TopLevelDeclList.pop_back();
- return static_cast<Decl*>(Result);
- }
-
do {
- if (P.ParseTopLevelDecl())
+ 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 (TopLevelDeclList.size() == 0);
-
- // If we parsed a declspec with multiple declarators, reverse the list and
- // return the first one.
- if (TopLevelDeclList.size() > 1)
- std::reverse(TopLevelDeclList.begin(), TopLevelDeclList.end());
-
- Result = TopLevelDeclList.back();
- TopLevelDeclList.pop_back();
+ } while (Result == 0);
return static_cast<Decl*>(Result);
}
Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=44445&r1=44444&r2=44445&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Thu Nov 29 17:05:20 2007
@@ -63,8 +63,8 @@
return Context.getObjcProtoType();
}
-Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
- : PP(pp), Context(ctxt), CurFunctionDecl(0), TopLevelDeclList(prevInGroup) {
+Sema::Sema(Preprocessor &pp, ASTContext &ctxt)
+ : PP(pp), Context(ctxt), CurFunctionDecl(0) {
// Get IdentifierInfo objects for known functions for which we
// do extra checking.
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44445&r1=44444&r2=44445&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Nov 29 17:05:20 2007
@@ -69,10 +69,6 @@
/// the method decl for the method being parsed.
ObjcMethodDecl *CurMethodDecl;
- /// TopLevelDeclList - This vector is populated with all declarators from
- /// a top-level declaration. This is used by the ASTStreamer.
- std::vector<Decl*> &TopLevelDeclList;
-
/// LabelMap - This is a mapping from label identifiers to the LabelStmt for
/// it (which acts like the label decl in some ways). Forward referenced
/// labels have a LabelStmt created for them with a null location & SubStmt.
@@ -141,7 +137,7 @@
llvm::DenseMap<Selector, ObjcMethodList> InstanceMethodPool;
llvm::DenseMap<Selector, ObjcMethodList> FactoryMethodPool;
public:
- Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
+ Sema(Preprocessor &pp, ASTContext &ctxt);
const LangOptions &getLangOptions() const;
@@ -227,9 +223,6 @@
TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
- /// AddTopLevelDecl - called after the decl has been fully processed.
- /// Allows for bookkeeping and post-processing of each declaration.
- void AddTopLevelDecl(Decl *current);
/// More parsing and symbol table subroutines...
ParmVarDecl *ActOnParamDeclarator(struct DeclaratorChunk::ParamInfo &PI,
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=44445&r1=44444&r2=44445&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Nov 29 17:05:20 2007
@@ -191,9 +191,6 @@
} else {
II->setFETokenInfo(New);
}
- // Make sure clients iterating over decls see this.
- AddTopLevelDecl(New);
-
return New;
}
@@ -676,10 +673,6 @@
II->setFETokenInfo(New);
S->AddDecl(New);
}
-
- if (S->getParent() == 0)
- AddTopLevelDecl(New);
-
// If any semantic error occurred, mark the decl as invalid.
if (D.getInvalidType() || InvalidDecl)
New->setInvalidDecl();
@@ -975,7 +968,6 @@
NewFD->setNext(II->getFETokenInfo<ScopedDecl>());
II->setFETokenInfo(NewFD);
GlobalScope->AddDecl(NewFD);
- AddTopLevelDecl(NewFD);
// Allow all of Sema to see that we are entering a method definition.
CurMethodDecl = MDecl;
@@ -1685,12 +1677,6 @@
break;
}
- // For top-level tag definitions, make sure we chain the the tag decl to
- // the vardecl. This enables the AST streamer to see both X and D in the
- // following example: struct X { int A; } D;
- if (S->getParent() == 0)
- AddTopLevelDecl(New);
-
// If this has an identifier, add it to the scope stack.
if (Name) {
// The scope passed in may not be a decl scope. Zip up the scope tree until
@@ -2464,14 +2450,6 @@
Enum->defineElements(EltList, BestType);
}
-void Sema::AddTopLevelDecl(Decl *current) {
- if (!current) return;
-
- // If this is a top-level decl that is chained to some other (e.g. int A,B,C;)
- // remember this in the TopLevelDeclList list.
- TopLevelDeclList.push_back((Decl*)current);
-}
-
void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) {
if (!strcmp(rawAttr->getAttributeName()->getName(), "vector_size") ||
!strcmp(rawAttr->getAttributeName()->getName(), "__vector_size__")) {
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=44445&r1=44444&r2=44445&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Nov 29 17:05:20 2007
@@ -76,7 +76,7 @@
/// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
/// the EOF was encountered.
- bool ParseTopLevelDecl();
+ bool ParseTopLevelDecl(DeclTy*& Result);
/// Finalize - Shut down the parser.
///
More information about the cfe-commits
mailing list