Implement scope tracking for empty-action.

llvm-svn: 38919
This commit is contained in:
Chris Lattner 2006-08-14 01:28:29 +00:00
parent 68ca25f8a9
commit ffe65b3ffd
1 changed files with 36 additions and 4 deletions

View File

@ -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 @@ bool EmptyAction::isTypedefName(const IdentifierInfo &II, Scope *S) const {
/// 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);
}
}