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. |
| 37 | void EmptyAction::ParseDeclarator(SourceLocation Loc, Scope *S, Declarator &D, |
| 38 | ExprTy *Init) { |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame^] | 39 | // 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 Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 53 | } |
| 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. |
| 57 | void EmptyAction::PopScope(SourceLocation Loc, Scope *S) { |
Chris Lattner | ffe65b3 | 2006-08-14 01:28:29 +0000 | [diff] [blame^] | 58 | 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 Lattner | a5534f9 | 2006-08-14 00:38:06 +0000 | [diff] [blame] | 69 | } |