Scope.cpp revision fb44de956f27875def889482b5393475060392af
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;
22fb44de956f27875def889482b5393475060392afJohn McCall
23fb44de956f27875def889482b5393475060392afJohn McCall  if (parent) {
24fb44de956f27875def889482b5393475060392afJohn McCall    Depth = parent->Depth + 1;
25fb44de956f27875def889482b5393475060392afJohn McCall    PrototypeDepth = parent->PrototypeDepth;
26fb44de956f27875def889482b5393475060392afJohn McCall    PrototypeIndex = 0;
27fb44de956f27875def889482b5393475060392afJohn McCall    FnParent       = parent->FnParent;
28fb44de956f27875def889482b5393475060392afJohn McCall    BreakParent    = parent->BreakParent;
29fb44de956f27875def889482b5393475060392afJohn McCall    ContinueParent = parent->ContinueParent;
30fb44de956f27875def889482b5393475060392afJohn McCall    ControlParent  = parent->ControlParent;
31fb44de956f27875def889482b5393475060392afJohn McCall    BlockParent    = parent->BlockParent;
32fb44de956f27875def889482b5393475060392afJohn McCall    TemplateParamParent = parent->TemplateParamParent;
33fb44de956f27875def889482b5393475060392afJohn McCall  } else {
34fb44de956f27875def889482b5393475060392afJohn McCall    Depth = 0;
35fb44de956f27875def889482b5393475060392afJohn McCall    PrototypeDepth = 0;
36fb44de956f27875def889482b5393475060392afJohn McCall    PrototypeIndex = 0;
37fb44de956f27875def889482b5393475060392afJohn McCall    FnParent = BreakParent = ContinueParent = BlockParent = 0;
38fb44de956f27875def889482b5393475060392afJohn McCall    ControlParent = 0;
39fb44de956f27875def889482b5393475060392afJohn McCall    TemplateParamParent = 0;
40fb44de956f27875def889482b5393475060392afJohn McCall  }
41fb44de956f27875def889482b5393475060392afJohn McCall
42fb44de956f27875def889482b5393475060392afJohn McCall  // If this scope is a function or contains breaks/continues, remember it.
43fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & FnScope)            FnParent = this;
44fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & BreakScope)         BreakParent = this;
45fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & ContinueScope)      ContinueParent = this;
46fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & ControlScope)       ControlParent = this;
47fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & BlockScope)         BlockParent = this;
48fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & TemplateParamScope) TemplateParamParent = this;
49fb44de956f27875def889482b5393475060392afJohn McCall
50fb44de956f27875def889482b5393475060392afJohn McCall  // If this is a prototype scope, record that.
51fb44de956f27875def889482b5393475060392afJohn McCall  if (flags & FunctionPrototypeScope) PrototypeDepth++;
52fb44de956f27875def889482b5393475060392afJohn McCall
53fb44de956f27875def889482b5393475060392afJohn McCall  DeclsInScope.clear();
54fb44de956f27875def889482b5393475060392afJohn McCall  UsingDirectives.clear();
55fb44de956f27875def889482b5393475060392afJohn McCall  Entity = 0;
56fb44de956f27875def889482b5393475060392afJohn McCall  ErrorTrap.reset();
57fb44de956f27875def889482b5393475060392afJohn McCall}
58