blob: de7443c194f1ff09ce412babbd995e10df698edf [file] [log] [blame]
Chris Lattnera5534f92006-08-14 00:38:06 +00001//===--- EmptyAction.cpp - Minimalistic action implementation -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the EmptyAction interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Chris Lattnerffe65b32006-08-14 01:28:29 +000015#include "clang/Parse/Declarations.h"
16#include "clang/Parse/Scope.h"
Chris Lattnera5534f92006-08-14 00:38:06 +000017using namespace llvm;
18using namespace clang;
19
Chris Lattnerffe65b32006-08-14 01:28:29 +000020/// TypedefInfo - A link exists here for each scope that an identifier is
21/// defined.
22struct TypedefInfo {
23 TypedefInfo *Prev;
24 bool isTypedef;
25};
26
Chris Lattnera5534f92006-08-14 00:38:06 +000027/// isTypedefName - This looks at the IdentifierInfo::FETokenInfo field to
28/// determine whether the name is a typedef or not in this scope.
29bool EmptyAction::isTypedefName(const IdentifierInfo &II, Scope *S) const {
Chris Lattnerffe65b32006-08-14 01:28:29 +000030 TypedefInfo *TI = II.getFETokenInfo<TypedefInfo>();
31 return TI != 0 && TI->isTypedef;
Chris Lattnera5534f92006-08-14 00:38:06 +000032}
33
34/// ParseDeclarator - If this is a typedef declarator, we modify the
35/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
36/// popped.
37void EmptyAction::ParseDeclarator(SourceLocation Loc, Scope *S, Declarator &D,
38 ExprTy *Init) {
Chris Lattnerffe65b32006-08-14 01:28:29 +000039 // If there is no identifier associated with this declarator, bail out.
40 if (D.getIdentifier() == 0) return;
41
42 // Remember whether or not this declarator is a typedef.
43 TypedefInfo *TI = new TypedefInfo();
44 TI->isTypedef = D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef;
45
46 // Add this to the linked-list hanging off the identifier.
47 IdentifierInfo &II = *D.getIdentifier();
48 TI->Prev = II.getFETokenInfo<TypedefInfo>();
49 II.setFETokenInfo(TI);
50
51 // Remember that this needs to be removed when the scope is popped.
52 S->AddDecl(&II);
Chris Lattnera5534f92006-08-14 00:38:06 +000053}
54
55/// PopScope - When a scope is popped, if any typedefs are now out-of-scope,
56/// they are removed from the IdentifierInfo::FETokenInfo field.
57void EmptyAction::PopScope(SourceLocation Loc, Scope *S) {
Chris Lattnerffe65b32006-08-14 01:28:29 +000058 for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
59 I != E; ++I) {
60 IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
61 TypedefInfo *TI = II.getFETokenInfo<TypedefInfo>();
62 assert(TI && "This decl didn't get pushed??");
63
64 TypedefInfo *Next = TI->Prev;
65 delete TI;
66
67 II.setFETokenInfo(Next);
68 }
Chris Lattnera5534f92006-08-14 00:38:06 +000069}