Update procedures
[shapes.git] / source / dynamicenvironment.h
blob5766090fffb9860ab22b7439036d2703a8d608fc
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008, 2010 Henrik Tidefelt
19 #pragma once
21 #include <cmath>
23 #include "Shapes_Lang_decls.h"
24 #include "Shapes_Kernel_decls.h"
25 #include "Shapes_Concrete_decls.h"
26 #include "Shapes_Ast_decls.h"
28 #include "statetypes.h"
29 #include "facettypes.h"
30 #include "texttypes.h"
31 #include "charptrless.h"
34 namespace Shapes
36 namespace Kernel
39 class SystemDynamicVariables
41 public:
42 SystemDynamicVariables( );
43 SystemDynamicVariables( const RefCountPtr< const Kernel::GraphicsState > & graphicsState );
45 void addFrom( const SystemDynamicVariables & other ); /* Take those bindings from other that we don't already have in *this. */
47 RefCountPtr< const Kernel::GraphicsState > graphicsState_;
48 RefCountPtr< const Kernel::FacetState > facetState_;
49 RefCountPtr< const Kernel::TextState > textState_;
50 Concrete::Length eyez_;
51 Concrete::Length TeX_bleed_;
52 RefCountPtr< const Kernel::PolarHandlePromise > defaultUnit_;
53 RefCountPtr< const Lang::ColorSpace > blendSpace_;
55 void print( std::ostream & os, const std::string & indentation ) const;
58 class SpecialUnitVariables
60 public:
61 bool reverseDirection_;
62 const Concrete::PathPoint2D * p0_;
63 const Concrete::PathPoint2D * p1_;
65 void specialUnitService( Concrete::Length * d, double * a0, double * a1 );
68 class SpanLastValue
70 public:
71 RefCountPtr< const Lang::Value > last_;
73 SpanLastValue( const RefCountPtr< const Lang::Value > & last )
74 : last_( last )
75 { }
76 ~SpanLastValue( )
77 { }
80 class DynamicEnvironment
82 RefCountPtr< Kernel::DynamicEnvironment > parent_;
83 public:
84 typedef DynamicEnvironmentKeyType KeyType;
85 typedef Lang::DynamicBindings::MapType MapType;
86 private:
87 MapType bindings_;
88 Kernel::SystemDynamicVariables * sysBindings_;
89 Kernel::SpecialUnitVariables * specialBindings_;
90 SpanLastValue * spanLast_;
91 const char * contId_;
92 Kernel::ContRef contVal_;
93 public:
94 DynamicEnvironment( const RefCountPtr< const Kernel::GraphicsState > & graphicsState );
95 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const Lang::DynamicBindings & bindings );
96 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const RefCountPtr< const Kernel::GraphicsState > & graphicsState );
97 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, Kernel::SystemDynamicVariables * sysBindings );
98 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, Kernel::SpecialUnitVariables * specialBindings );
99 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const RefCountPtr< const Lang::Value > & spanLast );
100 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const char * contId, const Kernel::ContRef & contVal );
101 ~DynamicEnvironment( );
103 void tackOn( const KeyType & key, Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
104 void lookup( const KeyType & key, Kernel::EvalState * evalState ) const;
105 Kernel::VariableHandle getVarHandle( const KeyType & key ) const;
107 RefCountPtr< Kernel::DynamicEnvironment > selectParent( RefCountPtr< Kernel::DynamicEnvironment > & self, const MapType & newBindings );
109 void gcMark( Kernel::GCMarkedSet & marked );
111 RefCountPtr< const Kernel::GraphicsState > getGraphicsState( ) const;
112 RefCountPtr< const Kernel::FacetState > getFacetState( ) const;
113 RefCountPtr< const Kernel::TextState > getTextState( ) const;
114 Concrete::Length getEyeZ( ) const;
115 Concrete::Length getTeXBleed( ) const;
116 RefCountPtr< const Kernel::PolarHandlePromise > getDefaultUnit( ) const;
117 RefCountPtr< const Lang::Value > getSpanLast( ) const;
118 Kernel::ContRef getEscapeContinuation( const char * id, const Ast::SourceLocation & loc ) const;
119 RefCountPtr< const Lang::ColorSpace > getBlendSpace( ) const;
121 void specialUnitService( Concrete::Length * d, double * a0, double * a1 );
123 bool isBaseEnvironment( ) const;
125 void print( std::ostream & os ) const;
126 size_t recursivePrint( std::ostream & os, std::set< MapType::key_type > * shadowed ) const;
128 private:
129 static KeyType nextKey;
130 public:
131 static KeyType getFreshKey( );
136 namespace Lang
139 class DynamicExpression : public Lang::NoOperatorOverloadValue
141 Kernel::PassedEnv env_;
142 Ast::Expression * expr_;
143 public:
144 DynamicExpression( Kernel::PassedEnv env, Ast::Expression * expr );
145 virtual ~DynamicExpression( );
146 void evalHelper( Kernel::EvalState * evalState ) const; /* Avoid the name <eval>, to make it easy to keep track of all places in the source where Expression::eval is invoked. */
147 virtual void gcMark( Kernel::GCMarkedSet & marked );
148 TYPEINFODECL;
153 class EyeZBinding : public Lang::DynamicBindings
155 const Ast::DynamicBindingExpression * bindingExpr_;
156 Concrete::Length val_;
157 const Ast::PlacedIdentifier * id_;
158 public:
159 EyeZBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val );
160 virtual ~EyeZBinding( );
161 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
162 virtual void show( std::ostream & os ) const;
163 virtual void gcMark( Kernel::GCMarkedSet & marked );
166 class TeXBleedBinding : public Lang::DynamicBindings
168 const Ast::DynamicBindingExpression * bindingExpr_;
169 Concrete::Length val_;
170 const Ast::PlacedIdentifier * id_;
171 public:
172 TeXBleedBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val );
173 virtual ~TeXBleedBinding( );
174 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
175 virtual void show( std::ostream & os ) const;
176 virtual void gcMark( Kernel::GCMarkedSet & marked );
179 class DefaultUnitBinding : public Lang::DynamicBindings
181 const Ast::DynamicBindingExpression * bindingExpr_;
182 RefCountPtr< const Kernel::PolarHandlePromise > val_;
183 const Ast::PlacedIdentifier * id_;
184 public:
185 DefaultUnitBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Kernel::PolarHandlePromise > & val );
186 virtual ~DefaultUnitBinding( );
187 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
188 virtual void show( std::ostream & os ) const;
189 virtual void gcMark( Kernel::GCMarkedSet & marked );
192 class BlendSpaceBinding : public Lang::DynamicBindings
194 const Ast::DynamicBindingExpression * bindingExpr_;
195 RefCountPtr< const Lang::ColorSpace > space_;
196 const Ast::PlacedIdentifier * id_;
197 public:
198 BlendSpaceBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Lang::ColorSpace > & space );
199 virtual ~BlendSpaceBinding( );
200 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
201 virtual void show( std::ostream & os ) const;
202 virtual void gcMark( Kernel::GCMarkedSet & marked );
207 namespace Kernel
210 class EyeZDynamicVariableProperties : public Kernel::DynamicVariableProperties
212 public:
213 EyeZDynamicVariableProperties( const Ast::PlacedIdentifier * id );
214 virtual ~EyeZDynamicVariableProperties( );
215 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
216 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
219 class TeXBleedDynamicVariableProperties : public Kernel::DynamicVariableProperties
221 public:
222 TeXBleedDynamicVariableProperties( const Ast::PlacedIdentifier * id );
223 virtual ~TeXBleedDynamicVariableProperties( );
224 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
225 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
228 class DefaultUnitDynamicVariableProperties : public Kernel::DynamicVariableProperties
230 public:
231 DefaultUnitDynamicVariableProperties( const Ast::PlacedIdentifier * id );
232 virtual ~DefaultUnitDynamicVariableProperties( );
233 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
234 virtual bool forceValue( ) const { return false; };
235 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
238 class BlendSpaceDynamicVariableProperties : public Kernel::DynamicVariableProperties
240 public:
241 BlendSpaceDynamicVariableProperties( const Ast::PlacedIdentifier * id );
242 virtual ~BlendSpaceDynamicVariableProperties( );
243 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
244 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
247 class SpotDynamicVariableProperties : public Kernel::DynamicVariableProperties
249 public:
250 SpotDynamicVariableProperties( const Ast::PlacedIdentifier * id );
251 virtual ~SpotDynamicVariableProperties( );
252 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
253 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;