Accept "in" instance variables
[delight/core.git] / d-irstate.h
blobcba90959ad3743890dfeb25254877b49e669ba4f
1 /* GDC -- D front-end for GCC
2 Copyright (C) 2004 David Friedman
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef GCC_DCMPLR_IRSTATE_H
20 #define GCC_DCMPLR_IRSTATE_H
22 // Due to the inlined functions, "dc-gcc-includes.h" needs to
23 // be included before this header is included.
25 #include "mars.h"
26 #include "root.h"
27 #include "lexer.h"
28 #include "mtype.h"
29 #include "declaration.h"
30 #include "statement.h"
31 #include "expression.h"
32 #include "aggregate.h"
33 #include "symbol.h"
35 // IRBase contains the core functionality of IRState. The actual IRState class
36 // extends this with lots of code generation utilities.
38 // Currently, each function gets its own IRState when emitting code. There is
39 // also a global IRState.
41 // Most toElem calls don't actually need the IRState because they create GCC
42 // expression trees rather than emit instructions.
44 struct IRBase : Object
46 IRBase * parent;
48 IRBase();
50 // ** Functions
52 // This is used by LabelStatement to find the LabelDsymbol that
53 // GotoStatements refer to.
54 FuncDeclaration * func; // %% make this a stack
56 static IRState * startFunction(FuncDeclaration * decl);
57 void endFunction();
58 public:
59 static Array deferredFuncDecls;
60 bool shouldDeferFunction(FuncDeclaration * decl);
62 static void initFunctionStart(tree fn_decl, const Loc & loc);
64 // ** Statement Lists
66 void addExp(tree e);
67 #if D_GCC_VER >= 40
68 tree statementList;
70 void pushStatementList();
71 tree popStatementList();
72 #endif
74 // ** Labels
76 // It is only valid to call this while the function in which the label is defined
77 // is being compiled.
78 tree getLabelTree(LabelDsymbol * label);
81 // ** Loops (and case statements)
82 #if D_GCC_VER < 40
83 typedef struct
85 Statement * statement;
86 // expand_start_case doesn't return a nesting structure, so
87 // we have to generate our own label for 'break'
88 nesting * loop;
89 tree exitLabel;
90 tree overrideContinueLabel;
91 } Flow;
92 #else
93 typedef struct
95 Statement * statement;
96 tree exitLabel;
97 union {
98 struct {
99 tree continueLabel;
100 tree unused;
102 struct {
103 tree condition; // only need this if it is not okay to convert an IfStatement's condition after converting it's branches...
104 tree trueBranch;
106 struct {
107 tree tryBody;
108 tree catchType;
111 } Flow;
112 #endif
114 Array loops; // of Flow
116 // These routines don't generate code. They are for tracking labeled loops.
117 Flow * getLoopForLabel(Identifier * ident, bool want_continue = false);
118 #if D_GCC_VER < 40
119 Flow * beginFlow(Statement * stmt, nesting * loop);
120 #else
121 //typedef enum { Break = 0x1, Continue = 0x2 } FlowLabel;
122 Flow * beginFlow(Statement * stmt/*, int labels*/);
123 #endif
124 void endFlow();
125 Flow * currentFlow() { return (Flow *) loops.tos(); }
126 void doLabel(tree t_label);
128 // ** DECL_CONTEXT support
130 tree getLocalContext() { return func ? func->toSymbol()->Stree : NULL_TREE; }
132 // ** "Binding contours"
134 /* Definitions for IRBase scope code:
135 "Scope": A container for binding contours. Each user-declared
136 function has a toplevel scope. Every ScopeStatement creates
137 a new scope. (And for now, until the emitLocalVar crash is
138 solved, this also creates a default binding contour.)
140 "Binding countour": Same as GCC's definition, whatever that is.
141 Each user-declared variable will have a binding contour that begins
142 where the variable is declared and ends at it's containing scope.
144 Array scopes; // of unsigned*
146 void startScope();
147 void endScope();
149 void startBindings();
150 void endBindings();
153 // ** Volatile state
155 unsigned volatileDepth;
156 bool inVolatile() { return volatileDepth != 0; }
157 void pushVolatile() { ++volatileDepth; }
158 void popVolatile() { --volatileDepth; }
163 #endif