| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1 | //===- Scope.cpp - Lexical scope information --------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This file implements the Scope class, which is used for recording | 
|  | 11 | // information about a lexical scope. | 
|  | 12 | // | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
|  | 15 | #include "clang/Sema/Scope.h" | 
|  | 16 |  | 
|  | 17 | using namespace clang; | 
|  | 18 |  | 
|  | 19 | void Scope::Init(Scope *parent, unsigned flags) { | 
|  | 20 | AnyParent = parent; | 
|  | 21 | Flags = flags; | 
| Richard Smith | 1002d10 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 22 |  | 
|  | 23 | if (parent && !(flags & FnScope)) { | 
|  | 24 | BreakParent    = parent->BreakParent; | 
|  | 25 | ContinueParent = parent->ContinueParent; | 
|  | 26 | } else { | 
|  | 27 | // Control scopes do not contain the contents of nested function scopes for | 
|  | 28 | // control flow purposes. | 
|  | 29 | BreakParent = ContinueParent = 0; | 
|  | 30 | } | 
|  | 31 |  | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 32 | if (parent) { | 
|  | 33 | Depth = parent->Depth + 1; | 
|  | 34 | PrototypeDepth = parent->PrototypeDepth; | 
|  | 35 | PrototypeIndex = 0; | 
|  | 36 | FnParent       = parent->FnParent; | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 37 | BlockParent    = parent->BlockParent; | 
|  | 38 | TemplateParamParent = parent->TemplateParamParent; | 
|  | 39 | } else { | 
|  | 40 | Depth = 0; | 
|  | 41 | PrototypeDepth = 0; | 
|  | 42 | PrototypeIndex = 0; | 
| Richard Smith | 1002d10 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 43 | FnParent = BlockParent = 0; | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 44 | TemplateParamParent = 0; | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | // If this scope is a function or contains breaks/continues, remember it. | 
|  | 48 | if (flags & FnScope)            FnParent = this; | 
|  | 49 | if (flags & BreakScope)         BreakParent = this; | 
|  | 50 | if (flags & ContinueScope)      ContinueParent = this; | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 51 | if (flags & BlockScope)         BlockParent = this; | 
|  | 52 | if (flags & TemplateParamScope) TemplateParamParent = this; | 
|  | 53 |  | 
|  | 54 | // If this is a prototype scope, record that. | 
|  | 55 | if (flags & FunctionPrototypeScope) PrototypeDepth++; | 
|  | 56 |  | 
|  | 57 | DeclsInScope.clear(); | 
|  | 58 | UsingDirectives.clear(); | 
|  | 59 | Entity = 0; | 
|  | 60 | ErrorTrap.reset(); | 
|  | 61 | } | 
| James Molloy | 6f8780b | 2012-02-29 10:24:19 +0000 | [diff] [blame] | 62 |  | 
|  | 63 | bool Scope::containedInPrototypeScope() const { | 
|  | 64 | const Scope *S = this; | 
|  | 65 | while (S) { | 
|  | 66 | if (S->isFunctionPrototypeScope()) | 
|  | 67 | return true; | 
|  | 68 | S = S->getParent(); | 
|  | 69 | } | 
|  | 70 | return false; | 
|  | 71 | } |