]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Sema/ScopeInfo.h
Merge ^/vendor/binutils/dist@214571 into contrib/binutils, which brings
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Sema / ScopeInfo.h
1 //===--- ScopeInfo.h - Information about a semantic context -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines FunctionScopeInfo and BlockScopeInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H
15 #define LLVM_CLANG_SEMA_SCOPE_INFO_H
16
17 #include "clang/AST/Type.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20
21 namespace clang {
22
23 class BlockDecl;
24 class IdentifierInfo;
25 class LabelStmt;
26 class ReturnStmt;
27 class Scope;
28 class SwitchStmt;
29
30 namespace sema {
31
32 /// \brief Retains information about a function, method, or block that is
33 /// currently being parsed.
34 class FunctionScopeInfo {
35 public:
36
37   /// \brief Whether this scope information structure defined information for
38   /// a block.
39   bool IsBlockInfo;
40
41   /// \brief Whether this function contains a VLA, @try, try, C++
42   /// initializer, or anything else that can't be jumped past.
43   bool HasBranchProtectedScope;
44
45   /// \brief Whether this function contains any switches or direct gotos.
46   bool HasBranchIntoScope;
47
48   /// \brief Whether this function contains any indirect gotos.
49   bool HasIndirectGoto;
50
51   /// \brief The number of errors that had occurred before starting this
52   /// function or block.
53   unsigned NumErrorsAtStartOfFunction;
54
55   /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
56   /// it (which acts like the label decl in some ways).  Forward referenced
57   /// labels have a LabelStmt created for them with a null location & SubStmt.
58   llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
59
60   /// SwitchStack - This is the current set of active switch statements in the
61   /// block.
62   llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
63
64   /// \brief The list of return statements that occur within the function or
65   /// block, if there is any chance of applying the named return value
66   /// optimization.
67   llvm::SmallVector<ReturnStmt *, 4> Returns;
68
69   void setHasBranchIntoScope() {
70     HasBranchIntoScope = true;
71   }
72
73   void setHasBranchProtectedScope() {
74     HasBranchProtectedScope = true;
75   }
76
77   void setHasIndirectGoto() {
78     HasIndirectGoto = true;
79   }
80
81   bool NeedsScopeChecking() const {
82     return HasIndirectGoto ||
83           (HasBranchProtectedScope && HasBranchIntoScope);
84   }
85   
86   FunctionScopeInfo(unsigned NumErrors)
87     : IsBlockInfo(false),
88       HasBranchProtectedScope(false),
89       HasBranchIntoScope(false),
90       HasIndirectGoto(false),
91       NumErrorsAtStartOfFunction(NumErrors) { }
92
93   virtual ~FunctionScopeInfo();
94
95   /// \brief Clear out the information in this function scope, making it
96   /// suitable for reuse.
97   void Clear(unsigned NumErrors);
98
99   static bool classof(const FunctionScopeInfo *FSI) { return true; }
100 };
101
102 /// \brief Retains information about a block that is currently being parsed.
103 class BlockScopeInfo : public FunctionScopeInfo {
104 public:
105   bool hasBlockDeclRefExprs;
106
107   BlockDecl *TheDecl;
108   
109   /// TheScope - This is the scope for the block itself, which contains
110   /// arguments etc.
111   Scope *TheScope;
112
113   /// ReturnType - The return type of the block, or null if the block
114   /// signature didn't provide an explicit return type.
115   QualType ReturnType;
116
117   /// BlockType - The function type of the block, if one was given.
118   /// Its return type may be BuiltinType::Dependent.
119   QualType FunctionType;
120
121   BlockScopeInfo(unsigned NumErrors, Scope *BlockScope, BlockDecl *Block)
122     : FunctionScopeInfo(NumErrors), hasBlockDeclRefExprs(false),
123       TheDecl(Block), TheScope(BlockScope)
124   {
125     IsBlockInfo = true;
126   }
127
128   virtual ~BlockScopeInfo();
129
130   static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; }
131   static bool classof(const BlockScopeInfo *BSI) { return true; }
132 };
133
134 }
135 }
136
137 #endif