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; 22235633Sdim 23235633Sdim if (parent && !(flags & FnScope)) { 24235633Sdim BreakParent = parent->BreakParent; 25235633Sdim ContinueParent = parent->ContinueParent; 26235633Sdim } else { 27235633Sdim // Control scopes do not contain the contents of nested function scopes for 28235633Sdim // control flow purposes. 29235633Sdim BreakParent = ContinueParent = 0; 30235633Sdim } 31235633Sdim 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; 43235633Sdim 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} 62235633Sdim 63235633Sdimbool Scope::containedInPrototypeScope() const { 64235633Sdim const Scope *S = this; 65235633Sdim while (S) { 66235633Sdim if (S->isFunctionPrototypeScope()) 67235633Sdim return true; 68235633Sdim S = S->getParent(); 69235633Sdim } 70235633Sdim return false; 71235633Sdim} 72