1 //===- Scope.cpp - Lexical scope information --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Scope class, which is used for recording
11 // information about a lexical scope.
13 //===----------------------------------------------------------------------===//
15 #include "clang/Sema/Scope.h"
17 using namespace clang;
19 void Scope::Init(Scope *parent, unsigned flags) {
23 if (parent && !(flags & FnScope)) {
24 BreakParent = parent->BreakParent;
25 ContinueParent = parent->ContinueParent;
27 // Control scopes do not contain the contents of nested function scopes for
28 // control flow purposes.
29 BreakParent = ContinueParent = 0;
33 Depth = parent->Depth + 1;
34 PrototypeDepth = parent->PrototypeDepth;
36 FnParent = parent->FnParent;
37 BlockParent = parent->BlockParent;
38 TemplateParamParent = parent->TemplateParamParent;
43 FnParent = BlockParent = 0;
44 TemplateParamParent = 0;
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;
51 if (flags & BlockScope) BlockParent = this;
52 if (flags & TemplateParamScope) TemplateParamParent = this;
54 // If this is a prototype scope, record that.
55 if (flags & FunctionPrototypeScope) PrototypeDepth++;
58 UsingDirectives.clear();
63 bool Scope::containedInPrototypeScope() const {
64 const Scope *S = this;
66 if (S->isFunctionPrototypeScope())