blob: be700f059a34686f5d343de6634b7e6666b47975 [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.
Chris Lattner2dacc3f2006-10-16 00:33:54 +000037Action::DeclTy *
38EmptyAction::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
39 DeclTy *LastInGroup) {
Chris Lattnerffe65b32006-08-14 01:28:29 +000040 // If there is no identifier associated with this declarator, bail out.
Chris Lattner2dacc3f2006-10-16 00:33:54 +000041 if (D.getIdentifier() == 0) return 0;
Chris Lattnerffe65b32006-08-14 01:28:29 +000042
43 // Remember whether or not this declarator is a typedef.
44 TypedefInfo *TI = new TypedefInfo();
45 TI->isTypedef = D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef;
46
47 // Add this to the linked-list hanging off the identifier.
48 IdentifierInfo &II = *D.getIdentifier();
49 TI->Prev = II.getFETokenInfo<TypedefInfo>();
50 II.setFETokenInfo(TI);
51
52 // Remember that this needs to be removed when the scope is popped.
53 S->AddDecl(&II);
Chris Lattner2dacc3f2006-10-16 00:33:54 +000054 return 0;
Chris Lattnera5534f92006-08-14 00:38:06 +000055}
56
57/// PopScope - When a scope is popped, if any typedefs are now out-of-scope,
58/// they are removed from the IdentifierInfo::FETokenInfo field.
59void EmptyAction::PopScope(SourceLocation Loc, Scope *S) {
Chris Lattnerffe65b32006-08-14 01:28:29 +000060 for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
61 I != E; ++I) {
62 IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
63 TypedefInfo *TI = II.getFETokenInfo<TypedefInfo>();
64 assert(TI && "This decl didn't get pushed??");
65
66 TypedefInfo *Next = TI->Prev;
67 delete TI;
68
69 II.setFETokenInfo(Next);
70 }
Chris Lattnera5534f92006-08-14 00:38:06 +000071}