1fb44de956f27875def889482b5393475060392afJohn McCall//===- Scope.cpp - Lexical scope information --------------------*- C++ -*-===// 2fb44de956f27875def889482b5393475060392afJohn McCall// 3fb44de956f27875def889482b5393475060392afJohn McCall// The LLVM Compiler Infrastructure 4fb44de956f27875def889482b5393475060392afJohn McCall// 5fb44de956f27875def889482b5393475060392afJohn McCall// This file is distributed under the University of Illinois Open Source 6fb44de956f27875def889482b5393475060392afJohn McCall// License. See LICENSE.TXT for details. 7fb44de956f27875def889482b5393475060392afJohn McCall// 8fb44de956f27875def889482b5393475060392afJohn McCall//===----------------------------------------------------------------------===// 9fb44de956f27875def889482b5393475060392afJohn McCall// 10fb44de956f27875def889482b5393475060392afJohn McCall// This file implements the Scope class, which is used for recording 11fb44de956f27875def889482b5393475060392afJohn McCall// information about a lexical scope. 12fb44de956f27875def889482b5393475060392afJohn McCall// 13fb44de956f27875def889482b5393475060392afJohn McCall//===----------------------------------------------------------------------===// 14fb44de956f27875def889482b5393475060392afJohn McCall 15fb44de956f27875def889482b5393475060392afJohn McCall#include "clang/Sema/Scope.h" 16fb44de956f27875def889482b5393475060392afJohn McCall 17fb44de956f27875def889482b5393475060392afJohn McCallusing namespace clang; 18fb44de956f27875def889482b5393475060392afJohn McCall 19fb44de956f27875def889482b5393475060392afJohn McCallvoid Scope::Init(Scope *parent, unsigned flags) { 20fb44de956f27875def889482b5393475060392afJohn McCall AnyParent = parent; 21fb44de956f27875def889482b5393475060392afJohn McCall Flags = flags; 2285b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith 2385b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith if (parent && !(flags & FnScope)) { 2485b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith BreakParent = parent->BreakParent; 2585b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith ContinueParent = parent->ContinueParent; 2685b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith } else { 2785b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith // Control scopes do not contain the contents of nested function scopes for 2885b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith // control flow purposes. 2985b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith BreakParent = ContinueParent = 0; 3085b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith } 3185b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith 32fb44de956f27875def889482b5393475060392afJohn McCall if (parent) { 33fb44de956f27875def889482b5393475060392afJohn McCall Depth = parent->Depth + 1; 34fb44de956f27875def889482b5393475060392afJohn McCall PrototypeDepth = parent->PrototypeDepth; 35fb44de956f27875def889482b5393475060392afJohn McCall PrototypeIndex = 0; 36fb44de956f27875def889482b5393475060392afJohn McCall FnParent = parent->FnParent; 37fb44de956f27875def889482b5393475060392afJohn McCall BlockParent = parent->BlockParent; 38fb44de956f27875def889482b5393475060392afJohn McCall TemplateParamParent = parent->TemplateParamParent; 39fb44de956f27875def889482b5393475060392afJohn McCall } else { 40fb44de956f27875def889482b5393475060392afJohn McCall Depth = 0; 41fb44de956f27875def889482b5393475060392afJohn McCall PrototypeDepth = 0; 42fb44de956f27875def889482b5393475060392afJohn McCall PrototypeIndex = 0; 4385b29a4c862bb9f41d9739e5dab6436fe6d44ff8Richard Smith FnParent = BlockParent = 0; 44fb44de956f27875def889482b5393475060392afJohn McCall TemplateParamParent = 0; 45fb44de956f27875def889482b5393475060392afJohn McCall } 46fb44de956f27875def889482b5393475060392afJohn McCall 47fb44de956f27875def889482b5393475060392afJohn McCall // If this scope is a function or contains breaks/continues, remember it. 48fb44de956f27875def889482b5393475060392afJohn McCall if (flags & FnScope) FnParent = this; 49fb44de956f27875def889482b5393475060392afJohn McCall if (flags & BreakScope) BreakParent = this; 50fb44de956f27875def889482b5393475060392afJohn McCall if (flags & ContinueScope) ContinueParent = this; 51fb44de956f27875def889482b5393475060392afJohn McCall if (flags & BlockScope) BlockParent = this; 52fb44de956f27875def889482b5393475060392afJohn McCall if (flags & TemplateParamScope) TemplateParamParent = this; 53fb44de956f27875def889482b5393475060392afJohn McCall 54fb44de956f27875def889482b5393475060392afJohn McCall // If this is a prototype scope, record that. 55fb44de956f27875def889482b5393475060392afJohn McCall if (flags & FunctionPrototypeScope) PrototypeDepth++; 56fb44de956f27875def889482b5393475060392afJohn McCall 57fb44de956f27875def889482b5393475060392afJohn McCall DeclsInScope.clear(); 58fb44de956f27875def889482b5393475060392afJohn McCall UsingDirectives.clear(); 59fb44de956f27875def889482b5393475060392afJohn McCall Entity = 0; 60fb44de956f27875def889482b5393475060392afJohn McCall ErrorTrap.reset(); 61fb44de956f27875def889482b5393475060392afJohn McCall} 6216f1f717af196b1448258857b2e6dcfe144b39d0James Molloy 6316f1f717af196b1448258857b2e6dcfe144b39d0James Molloybool Scope::containedInPrototypeScope() const { 6416f1f717af196b1448258857b2e6dcfe144b39d0James Molloy const Scope *S = this; 6516f1f717af196b1448258857b2e6dcfe144b39d0James Molloy while (S) { 6616f1f717af196b1448258857b2e6dcfe144b39d0James Molloy if (S->isFunctionPrototypeScope()) 6716f1f717af196b1448258857b2e6dcfe144b39d0James Molloy return true; 6816f1f717af196b1448258857b2e6dcfe144b39d0James Molloy S = S->getParent(); 6916f1f717af196b1448258857b2e6dcfe144b39d0James Molloy } 7016f1f717af196b1448258857b2e6dcfe144b39d0James Molloy return false; 7116f1f717af196b1448258857b2e6dcfe144b39d0James Molloy} 72