clang API Documentation
00001 //===- Scope.cpp - Lexical scope information --------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the Scope class, which is used for recording 00011 // information about a lexical scope. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "clang/Sema/Scope.h" 00016 00017 using namespace clang; 00018 00019 void Scope::Init(Scope *parent, unsigned flags) { 00020 AnyParent = parent; 00021 Flags = flags; 00022 00023 if (parent && !(flags & FnScope)) { 00024 BreakParent = parent->BreakParent; 00025 ContinueParent = parent->ContinueParent; 00026 } else { 00027 // Control scopes do not contain the contents of nested function scopes for 00028 // control flow purposes. 00029 BreakParent = ContinueParent = 0; 00030 } 00031 00032 if (parent) { 00033 Depth = parent->Depth + 1; 00034 PrototypeDepth = parent->PrototypeDepth; 00035 PrototypeIndex = 0; 00036 FnParent = parent->FnParent; 00037 BlockParent = parent->BlockParent; 00038 TemplateParamParent = parent->TemplateParamParent; 00039 } else { 00040 Depth = 0; 00041 PrototypeDepth = 0; 00042 PrototypeIndex = 0; 00043 FnParent = BlockParent = 0; 00044 TemplateParamParent = 0; 00045 } 00046 00047 // If this scope is a function or contains breaks/continues, remember it. 00048 if (flags & FnScope) FnParent = this; 00049 if (flags & BreakScope) BreakParent = this; 00050 if (flags & ContinueScope) ContinueParent = this; 00051 if (flags & BlockScope) BlockParent = this; 00052 if (flags & TemplateParamScope) TemplateParamParent = this; 00053 00054 // If this is a prototype scope, record that. 00055 if (flags & FunctionPrototypeScope) PrototypeDepth++; 00056 00057 DeclsInScope.clear(); 00058 UsingDirectives.clear(); 00059 Entity = 0; 00060 ErrorTrap.reset(); 00061 } 00062 00063 bool Scope::containedInPrototypeScope() const { 00064 const Scope *S = this; 00065 while (S) { 00066 if (S->isFunctionPrototypeScope()) 00067 return true; 00068 S = S->getParent(); 00069 } 00070 return false; 00071 }