1221339Sdim//===- Scope.cpp - Lexical scope information --------------------*- C++ -*-===// 2221339Sdim// 3221339Sdim// The LLVM Compiler Infrastructure 4221339Sdim// 5221339Sdim// This file is distributed under the University of Illinois Open Source 6221339Sdim// License. See LICENSE.TXT for details. 7221339Sdim// 8221339Sdim//===----------------------------------------------------------------------===// 9221339Sdim// 10221339Sdim// This file implements the Scope class, which is used for recording 11221339Sdim// information about a lexical scope. 12221339Sdim// 13221339Sdim//===----------------------------------------------------------------------===// 14221339Sdim 15221339Sdim#include "clang/Sema/Scope.h" 16221339Sdim 17221339Sdimusing namespace clang; 18221339Sdim 19221339Sdimvoid Scope::Init(Scope *parent, unsigned flags) { 20221339Sdim AnyParent = parent; 21221339Sdim Flags = flags; 22234353Sdim 23234353Sdim if (parent && !(flags & FnScope)) { 24234353Sdim BreakParent = parent->BreakParent; 25234353Sdim ContinueParent = parent->ContinueParent; 26234353Sdim } else { 27234353Sdim // Control scopes do not contain the contents of nested function scopes for 28234353Sdim // control flow purposes. 29234353Sdim BreakParent = ContinueParent = 0; 30234353Sdim } 31234353Sdim 32221339Sdim if (parent) { 33221339Sdim Depth = parent->Depth + 1; 34221339Sdim PrototypeDepth = parent->PrototypeDepth; 35221339Sdim PrototypeIndex = 0; 36221339Sdim FnParent = parent->FnParent; 37221339Sdim BlockParent = parent->BlockParent; 38221339Sdim TemplateParamParent = parent->TemplateParamParent; 39221339Sdim } else { 40221339Sdim Depth = 0; 41221339Sdim PrototypeDepth = 0; 42221339Sdim PrototypeIndex = 0; 43234353Sdim FnParent = BlockParent = 0; 44221339Sdim TemplateParamParent = 0; 45221339Sdim } 46221339Sdim 47221339Sdim // If this scope is a function or contains breaks/continues, remember it. 48221339Sdim if (flags & FnScope) FnParent = this; 49221339Sdim if (flags & BreakScope) BreakParent = this; 50221339Sdim if (flags & ContinueScope) ContinueParent = this; 51221339Sdim if (flags & BlockScope) BlockParent = this; 52221339Sdim if (flags & TemplateParamScope) TemplateParamParent = this; 53221339Sdim 54221339Sdim // If this is a prototype scope, record that. 55221339Sdim if (flags & FunctionPrototypeScope) PrototypeDepth++; 56221339Sdim 57221339Sdim DeclsInScope.clear(); 58221339Sdim UsingDirectives.clear(); 59221339Sdim Entity = 0; 60221339Sdim ErrorTrap.reset(); 61221339Sdim} 62234353Sdim 63234353Sdimbool Scope::containedInPrototypeScope() const { 64234353Sdim const Scope *S = this; 65234353Sdim while (S) { 66234353Sdim if (S->isFunctionPrototypeScope()) 67234353Sdim return true; 68234353Sdim S = S->getParent(); 69234353Sdim } 70234353Sdim return false; 71234353Sdim} 72