[cfe-commits] r38919 - /cfe/cfe/trunk/Parse/MinimalAction.cpp
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:46 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:45 2007
New Revision: 38919
URL: http://llvm.org/viewvc/llvm-project?rev=38919&view=rev
Log:
Implement scope tracking for empty-action.
Modified:
cfe/cfe/trunk/Parse/MinimalAction.cpp
Modified: cfe/cfe/trunk/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/MinimalAction.cpp?rev=38919&r1=38918&r2=38919&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/MinimalAction.cpp (original)
+++ cfe/cfe/trunk/Parse/MinimalAction.cpp Wed Jul 11 11:25:45 2007
@@ -12,15 +12,23 @@
//===----------------------------------------------------------------------===//
#include "clang/Parse/Parser.h"
-//#include "clang/Parse/Declarations.h"
-//#include "clang/Parse/Scope.h"
+#include "clang/Parse/Declarations.h"
+#include "clang/Parse/Scope.h"
using namespace llvm;
using namespace clang;
+/// TypedefInfo - A link exists here for each scope that an identifier is
+/// defined.
+struct TypedefInfo {
+ TypedefInfo *Prev;
+ bool isTypedef;
+};
+
/// isTypedefName - This looks at the IdentifierInfo::FETokenInfo field to
/// determine whether the name is a typedef or not in this scope.
bool EmptyAction::isTypedefName(const IdentifierInfo &II, Scope *S) const {
- return true;
+ TypedefInfo *TI = II.getFETokenInfo<TypedefInfo>();
+ return TI != 0 && TI->isTypedef;
}
/// ParseDeclarator - If this is a typedef declarator, we modify the
@@ -28,10 +36,34 @@
/// popped.
void EmptyAction::ParseDeclarator(SourceLocation Loc, Scope *S, Declarator &D,
ExprTy *Init) {
+ // If there is no identifier associated with this declarator, bail out.
+ if (D.getIdentifier() == 0) return;
+
+ // Remember whether or not this declarator is a typedef.
+ TypedefInfo *TI = new TypedefInfo();
+ TI->isTypedef = D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef;
+
+ // Add this to the linked-list hanging off the identifier.
+ IdentifierInfo &II = *D.getIdentifier();
+ TI->Prev = II.getFETokenInfo<TypedefInfo>();
+ II.setFETokenInfo(TI);
+
+ // Remember that this needs to be removed when the scope is popped.
+ S->AddDecl(&II);
}
/// PopScope - When a scope is popped, if any typedefs are now out-of-scope,
/// they are removed from the IdentifierInfo::FETokenInfo field.
void EmptyAction::PopScope(SourceLocation Loc, Scope *S) {
-
+ for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
+ I != E; ++I) {
+ IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
+ TypedefInfo *TI = II.getFETokenInfo<TypedefInfo>();
+ assert(TI && "This decl didn't get pushed??");
+
+ TypedefInfo *Next = TI->Prev;
+ delete TI;
+
+ II.setFETokenInfo(Next);
+ }
}
More information about the cfe-commits
mailing list