Introducing mutators.
[shapes.git] / source / astvar.h
blobb96a85097f63414287b50ce35e637fc3d3a424d1
1 #ifndef astvar_h
2 #define astvar_h
4 #include "Shapes_Kernel_decls.h"
6 #include "ast.h"
8 namespace Shapes
10 namespace Ast
13 class CodeBracket : public Expression
15 std::list< Ast::Node * > * nodes_;
16 std::map< const char *, size_t, charPtrLess > * argumentOrder_;
17 std::map< const char *, size_t, charPtrLess > * dynamicMap_;
18 std::map< const char *, size_t, charPtrLess > * stateOrder_;
19 public:
20 CodeBracket( const Ast::SourceLocation & loc, std::list< Ast::Node * > * nodes );
21 virtual ~CodeBracket( );
23 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
24 virtual void eval( Kernel::EvalState * evalState ) const;
26 void evalAt( const RefCountPtr< const Kernel::CodeBracketContInfo > & info, const std::list< Ast::Node * >::const_iterator & i, Kernel::EvalState * evalState ) const;
31 namespace Kernel
33 class CodeBracketContInfo
35 public:
36 const Ast::CodeBracket * bracketExpr_;
37 Kernel::PassedEnv env_;
38 Kernel::PassedDyn dyn_;
39 Kernel::ContRef cont_;
41 CodeBracketContInfo( const Ast::CodeBracket * bracketExpr, const Kernel::EvalState & evalState );
42 ~CodeBracketContInfo( );
44 void gcMark( Kernel::GCMarkedSet & marked );
47 class CodeBracketContinuation : public Kernel::Continuation
49 RefCountPtr< const Kernel::CodeBracketContInfo > info_;
50 std::list< Ast::Node * >::const_iterator pos_;
51 public:
52 CodeBracketContinuation( const Ast::SourceLocation & _traceLoc, const RefCountPtr< const Kernel::CodeBracketContInfo > & _info, const std::list< Ast::Node * >::const_iterator & _pos );
53 virtual ~CodeBracketContinuation( );
54 virtual void takeValue( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState, bool dummy ) const;
55 virtual void backTrace( std::list< Kernel::Continuation::BackTraceElem > * trace ) const;
56 virtual void gcMark( Kernel::GCMarkedSet & marked );
60 class DynamicBindingContinuation : public Kernel::Continuation
62 Kernel::PassedEnv env_;
63 Kernel::Environment::LexicalKey key_;
64 Ast::SourceLocation idLoc_;
65 Kernel::ContRef cont_;
66 public:
67 DynamicBindingContinuation( const Ast::SourceLocation & traceLoc, const Kernel::PassedEnv & env, const Kernel::Environment::LexicalKey & key, const Ast::SourceLocation & idLoc, const Kernel::ContRef & cont );
68 virtual ~DynamicBindingContinuation( );
69 virtual void takeHandle( Kernel::VariableHandle val, Kernel::EvalState * evalState, bool dummy ) const;
70 virtual void backTrace( std::list< Kernel::Continuation::BackTraceElem > * trace ) const;
71 virtual void gcMark( Kernel::GCMarkedSet & marked );
74 class WithDynamicContinuation : public Kernel::Continuation
76 Ast::Expression * expr_;
77 Kernel::PassedEnv env_;
78 Kernel::PassedDyn dyn_;
79 Kernel::ContRef cont_;
80 public:
81 WithDynamicContinuation( const Ast::SourceLocation & traceLoc, Ast::Expression * expr, const Kernel::EvalState & evalState );
82 virtual ~WithDynamicContinuation( );
83 virtual void takeValue( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState, bool dummy ) const;
84 virtual void backTrace( std::list< Kernel::Continuation::BackTraceElem > * trace ) const;
85 virtual void gcMark( Kernel::GCMarkedSet & marked );
88 class DynamicVariableDeclContinuation : public Kernel::Continuation
90 const Ast::DynamicVariableDecl * declExpr_;
91 Kernel::PassedEnv env_;
92 Kernel::PassedDyn dyn_;
93 Kernel::ContRef cont_;
94 public:
95 DynamicVariableDeclContinuation( const Ast::SourceLocation & traceLoc, const Ast::DynamicVariableDecl * declExpr, Kernel::EvalState & evalState );
96 virtual ~DynamicVariableDeclContinuation( );
97 virtual void takeValue( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState, bool dummy ) const;
98 virtual void backTrace( std::list< Kernel::Continuation::BackTraceElem > * trace ) const;
99 virtual void gcMark( Kernel::GCMarkedSet & marked );
102 class AssertStructureContinuation : public Kernel::Continuation
104 Kernel::ContRef cont_;
105 public:
106 AssertStructureContinuation( const Kernel::ContRef & cont, const Ast::SourceLocation & traceLoc );
107 ~AssertStructureContinuation( );
108 virtual void takeValue( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState, bool dummy ) const;
109 virtual void backTrace( std::list< Kernel::Continuation::BackTraceElem > * trace ) const;
110 virtual void gcMark( Kernel::GCMarkedSet & marked );
113 } // End of namespace Kernel.
115 namespace Ast
117 class LexiographicVariable : public Expression
119 const char * id_;
120 mutable Kernel::Environment::LexicalKey ** idKey_;
121 public:
122 LexiographicVariable( const Ast::SourceLocation & loc, const char * id, Kernel::Environment::LexicalKey ** idKey );
123 virtual ~LexiographicVariable( );
124 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
125 virtual void eval( Kernel::EvalState * evalState ) const;
128 class EvalOutsideExpr : public Expression
130 Ast::Expression * expr_;
131 public:
132 EvalOutsideExpr( const Ast::SourceLocation & loc, Ast::Expression * expr );
133 virtual ~EvalOutsideExpr( );
134 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
135 virtual void eval( Kernel::EvalState * evalState ) const;
138 class DefineVariable : public BindNode
140 Ast::Expression * expr_;
141 mutable size_t ** idPos_;
142 public:
143 DefineVariable( const Ast::SourceLocation & idLoc, const char * id, Ast::Expression * expr, size_t ** idPos );
144 virtual ~DefineVariable( );
145 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
146 virtual void eval( Kernel::EvalState * evalState ) const;
149 class StructSplitReference : public Expression
151 Ast::SourceLocation structLoc_;
152 size_t ** structPos_;
153 Ast::SourceLocation fieldLoc_;
154 const char * fieldId_;
155 size_t fieldPos_;
156 Ast::Expression * defaultExpr_;
157 public:
158 StructSplitReference( Ast::SourceLocation fieldLoc, const char * fieldId, Ast::Expression * defaultExpr );
159 StructSplitReference( Ast::SourceLocation fieldLoc, size_t fieldPos, Ast::Expression * defaultExpr );
160 virtual ~StructSplitReference( );
161 void setStruct( Ast::SourceLocation structLoc, size_t ** structPos );
162 bool isOrdered( ) const { return fieldId_ == 0; }
163 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
164 virtual void eval( Kernel::EvalState * evalState ) const;
167 class StructSplitSink : public Expression
169 Ast::SourceLocation structLoc_;
170 size_t ** structPos_;
171 size_t consumedArguments_;
172 public:
173 StructSplitSink( );
174 virtual ~StructSplitSink( );
175 void setStruct( Ast::SourceLocation structLoc, size_t ** structPos, size_t consumedArguments );
176 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
177 virtual void eval( Kernel::EvalState * evalState ) const;
180 class AssertNoSinkNeeded : public Expression
182 size_t orderedCount_;
183 Ast::SourceLocation structLoc_;
184 size_t ** structPos_;
185 public:
186 AssertNoSinkNeeded( const Ast::SourceLocation & loc, size_t orderedCount, Ast::SourceLocation structLoc, size_t ** structPos );
187 virtual ~AssertNoSinkNeeded( );
188 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
189 virtual void eval( Kernel::EvalState * evalState ) const;
192 class SplitDefineVariables
194 static size_t splitVarCount;
195 static PtrOwner_back_Access< std::list< const char * > > mem;
196 const char * splitVarId_;
197 public:
198 std::list< std::pair< Ast::DefineVariable *, Ast::StructSplitReference * > > exprs_;
199 Ast::DefineVariable * sinkDefine_;
200 Ast::StructSplitSink * sinkExpr_;
201 bool seenNamed_;
202 bool seenDefault_;
203 SplitDefineVariables( );
204 const char * newSplitVarId( ) const;
207 class StateReference : public Node
209 public:
210 StateReference( const Ast::SourceLocation & loc );
211 virtual ~StateReference( );
212 virtual void eval( Kernel::EvalState * evalState ) const; // illegal to call
213 virtual Kernel::StateHandle getHandle( Kernel::PassedEnv env, Kernel::PassedDyn dyn ) const = 0;
216 class LexiographicState : public StateReference
218 const char * id_;
219 mutable Kernel::Environment::LexicalKey ** idKey_;
220 public:
221 LexiographicState( const Ast::SourceLocation & loc, const char * id, Kernel::Environment::LexicalKey ** idKey );
222 virtual ~LexiographicState( );
223 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
224 Kernel::StateHandle getHandle( Kernel::PassedEnv env, Kernel::PassedDyn dyn ) const;
227 class DynamicState : public Ast::StateReference
229 const char * id_;
230 mutable Kernel::Environment::LexicalKey ** idKey_;
231 public:
232 DynamicState( const Ast::SourceLocation & loc, const char * id );
233 virtual ~DynamicState( );
234 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
235 Kernel::StateHandle getHandle( Kernel::PassedEnv env, Kernel::PassedDyn dyn ) const;
238 class IntroduceState : public BindNode
240 Ast::Expression * expr_;
241 mutable size_t ** idPos_;
242 public:
243 IntroduceState( const Ast::SourceLocation & idLoc, const char * id, Ast::Expression * expr, size_t ** idPos );
244 virtual ~IntroduceState( );
245 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
246 virtual void eval( Kernel::EvalState * evalState ) const;
249 class Insertion : public Node
251 Ast::StateReference * stateRef_;
252 Ast::Expression * expr_;
253 public:
254 Insertion( Ast::StateReference * stateRef, Ast::Expression * expr );
255 virtual ~Insertion( );
256 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
257 virtual void eval( Kernel::EvalState * evalState ) const;
260 class Freeze : public Expression
262 const char * id_;
263 mutable size_t ** idPos_;
264 public:
265 Freeze( const Ast::SourceLocation & idLoc, const char * id, size_t ** idPos );
266 virtual ~Freeze( );
267 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
268 virtual void eval( Kernel::EvalState * evalState ) const;
271 class Peek : public Expression
273 Ast::StateReference * stateRef_;
274 public:
275 Peek( const Ast::SourceLocation & idLoc, Ast::StateReference * stateRef );
276 virtual ~Peek( );
277 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
278 virtual void eval( Kernel::EvalState * evalState ) const;
281 class EvalSymbolFunction : public Lang::Function
283 Ast::SourceLocation loc_;
284 Ast::Expression * expr_;
285 const Ast::AnalysisEnvironment * analysisEnv_;
286 public:
287 EvalSymbolFunction( const Ast::SourceLocation & loc, Ast::Expression * expr );
288 virtual ~EvalSymbolFunction( );
289 void push_exprs( Ast::ArgListExprs * args ) const;
290 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
291 virtual void call( Kernel::EvalState * evalState, Kernel::Arguments & args, const Ast::SourceLocation & callLoc ) const;
292 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
293 virtual bool isTransforming( ) const { return false; }
296 class MemberReferenceFunction : public Lang::Function
298 Ast::SourceLocation loc_;
299 Ast::Expression * variable_;
300 const char * fieldID_;
301 public:
302 MemberReferenceFunction( const Ast::SourceLocation & loc, Ast::Expression * variable, const char * fieldID );
303 virtual ~MemberReferenceFunction( );
304 void push_exprs( Ast::ArgListExprs * args ) const;
305 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
306 virtual void call( Kernel::EvalState * evalState, Kernel::Arguments & args, const Ast::SourceLocation & callLoc ) const;
307 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
308 virtual bool isTransforming( ) const { return false; }
311 class MutatorReference : public Ast::Expression
313 Ast::SourceLocation mutatorLoc_;
314 Ast::StateReference * state_;
315 const char * mutatorID_;
316 public:
317 MutatorReference( const Ast::SourceLocation & mutatorLoc, Ast::StateReference * state, const char * mutatorID );
318 virtual ~MutatorReference( );
319 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
320 virtual void eval( Kernel::EvalState * evalState ) const;
323 class SpecialLength : public Expression
325 Ast::SourceLocation loc_;
326 double val_;
327 int sort_;
328 public:
329 SpecialLength( const Ast::SourceLocation & loc, double val, int sort );
330 virtual ~SpecialLength( );
331 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
332 virtual void eval( Kernel::EvalState * evalState ) const;
335 class DynamicVariable : public Ast::Expression
337 Ast::SourceLocation loc_;
338 const char * id_;
339 mutable Kernel::Environment::LexicalKey ** idKey_;
340 public:
341 DynamicVariable( const Ast::SourceLocation & loc, const char * id );
342 virtual ~DynamicVariable( );
343 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
344 virtual void eval( Kernel::EvalState * evalState ) const;
347 class DynamicBindingExpression : public Ast::Expression
349 Ast::SourceLocation idLoc_;
350 const char * id_;
351 Ast::Expression * expr_;
352 mutable Kernel::Environment::LexicalKey ** idKey_;
353 public:
354 DynamicBindingExpression( const Ast::SourceLocation & idLoc, const char * id, Ast::Expression * expr, Kernel::Environment::LexicalKey ** idKey );
355 virtual ~DynamicBindingExpression( );
356 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
357 virtual void eval( Kernel::EvalState * evalState ) const;
360 class DynamicStateBindingExpression : public Ast::Expression
362 Ast::SourceLocation loc_;
363 Ast::SourceLocation dstLoc_;
364 const char * dstId_;
365 mutable Kernel::Environment::LexicalKey ** dstIdKey_;
366 Ast::StateReference * src_;
367 public:
368 DynamicStateBindingExpression( const Ast::SourceLocation & loc, const Ast::SourceLocation & dstLoc, const char * dstId, Ast::StateReference * src );
369 virtual ~DynamicStateBindingExpression( );
370 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
371 virtual void eval( Kernel::EvalState * evalState ) const;
374 class WithDynamicExpr : public Ast::Expression
376 Ast::Expression * bindings_;
377 Ast::Expression * expr_;
378 public:
379 WithDynamicExpr( const Ast::SourceLocation & loc, Ast::Expression * bindings, Ast::Expression * expr );
380 virtual ~WithDynamicExpr( );
381 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
382 virtual void eval( Kernel::EvalState * evalState ) const;
385 class DynamicVariableDecl : public Ast::BindNode
387 mutable size_t ** idPos_;
388 Ast::Expression * impl_;
389 public:
390 DynamicVariableDecl( const Ast::SourceLocation & loc, const Ast::SourceLocation & idLoc, const char * id, Ast::Expression * filterExpr, Ast::Expression * defaultExpr );
391 virtual ~DynamicVariableDecl( );
392 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
393 virtual void eval( Kernel::EvalState * evalState ) const;
396 class DynamicVariableDeclFunction : public Lang::Function
398 const char * id_;
399 Ast::Expression * filterExpr_;
400 Ast::Expression * defaultExpr_;
401 size_t ** idPos_;
402 public:
403 DynamicVariableDeclFunction( const char * id, Ast::Expression * filterExpr, Ast::Expression * defaultExpr, size_t ** idPos );
404 virtual ~DynamicVariableDeclFunction( );
405 void push_exprs( Ast::ArgListExprs * args ) const;
406 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
407 virtual void call( Kernel::EvalState * evalState, Kernel::Arguments & args, const Ast::SourceLocation & callLoc ) const;
408 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
409 virtual bool isTransforming( ) const { return false; }
412 class DynamicStateDecl : public Ast::BindNode
414 const char * defaultStateID_;
415 mutable size_t ** idPos_;
416 Ast::StateReference * defaultState_;
417 public:
418 DynamicStateDecl( const Ast::SourceLocation & loc, const Ast::SourceLocation & idLoc, const char * id, Ast::StateReference * defaultState, size_t ** idPos );
419 virtual ~DynamicStateDecl( );
420 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
421 virtual void eval( Kernel::EvalState * evalState ) const;
424 class DynamicExpression : public Ast::Expression
426 Ast::Expression * expr_;
427 public:
428 DynamicExpression( const Ast::SourceLocation & loc, Ast::Expression * expr );
429 virtual ~DynamicExpression( );
430 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
431 virtual void eval( Kernel::EvalState * evalState ) const;
434 class LexiographicType : public Expression
436 const char * id_;
437 mutable Kernel::Environment::LexicalKey ** idKey_;
438 public:
439 LexiographicType( const Ast::SourceLocation & loc, const char * id, Kernel::Environment::LexicalKey ** idKey );
440 virtual ~LexiographicType( );
441 virtual void analyze( Ast::Node * parent, const Ast::AnalysisEnvironment * env );
442 virtual void eval( Kernel::EvalState * evalState ) const;
450 #endif