Chris Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 1 | //===--- 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 Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Declarations.h" |
| 16 | #include "clang/Parse/Scope.h" |
Chris Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 17 | using namespace llvm; |
| 18 | using namespace clang; |
| 19 | |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame] | 20 | /// TypedefInfo - A link exists here for each scope that an identifier is |
| 21 | /// defined. |
| 22 | struct TypedefInfo { |
| 23 | TypedefInfo *Prev; |
| 24 | bool isTypedef; |
| 25 | }; |
| 26 | |
Chris Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 27 | /// isTypedefName - This looks at the IdentifierInfo::FETokenInfo field to |
| 28 | /// determine whether the name is a typedef or not in this scope. |
| 29 | bool EmptyAction::isTypedefName(const IdentifierInfo &II, Scope *S) const { |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame] | 30 | TypedefInfo *TI = II.getFETokenInfo<TypedefInfo>(); |
| 31 | return TI != 0 && TI->isTypedef; |
Chris Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 32 | } |
| 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 Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 37 | Action::DeclTy * |
| 38 | EmptyAction::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, |
| 39 | DeclTy *LastInGroup) { |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame] | 40 | // If there is no identifier associated with this declarator, bail out. |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 41 | if (D.getIdentifier() == 0) return 0; |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame] | 42 | |
| 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 Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 54 | return 0; |
Chris Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 55 | } |
| 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. |
| 59 | void EmptyAction::PopScope(SourceLocation Loc, Scope *S) { |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame] | 60 | 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 Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 71 | } |