Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / dynamicenvironment.h
blob5bf745afe15fbfb554fde6d9e3d2b3a2261c3b4d
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 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 DynamicEnvironment
70 RefCountPtr< Kernel::DynamicEnvironment > parent_;
71 public:
72 typedef DynamicEnvironmentKeyType KeyType;
73 typedef Lang::DynamicBindings::MapType MapType;
74 private:
75 MapType bindings_;
76 Kernel::SystemDynamicVariables * sysBindings_;
77 Kernel::SpecialUnitVariables * specialBindings_;
78 const char * contId_;
79 Kernel::ContRef contVal_;
80 public:
81 DynamicEnvironment( const RefCountPtr< const Kernel::GraphicsState > & graphicsState );
82 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const Lang::DynamicBindings & bindings );
83 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const RefCountPtr< const Kernel::GraphicsState > & graphicsState );
84 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, Kernel::SystemDynamicVariables * sysBindings );
85 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, Kernel::SpecialUnitVariables * specialBindings );
86 DynamicEnvironment( RefCountPtr< Kernel::DynamicEnvironment > parent, const char * contId, const Kernel::ContRef & contVal );
87 ~DynamicEnvironment( );
89 void tackOn( const KeyType & key, Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
90 void lookup( const KeyType & key, Kernel::EvalState * evalState ) const;
91 Kernel::VariableHandle getVarHandle( const KeyType & key ) const;
93 RefCountPtr< Kernel::DynamicEnvironment > selectParent( RefCountPtr< Kernel::DynamicEnvironment > & self, const MapType & newBindings );
95 void gcMark( Kernel::GCMarkedSet & marked );
97 RefCountPtr< const Kernel::GraphicsState > getGraphicsState( ) const;
98 RefCountPtr< const Kernel::FacetState > getFacetState( ) const;
99 RefCountPtr< const Kernel::TextState > getTextState( ) const;
100 Concrete::Length getEyeZ( ) const;
101 Concrete::Length getTeXBleed( ) const;
102 RefCountPtr< const Kernel::PolarHandlePromise > getDefaultUnit( ) const;
103 Kernel::ContRef getEscapeContinuation( const char * id, const Ast::SourceLocation & loc ) const;
104 RefCountPtr< const Lang::ColorSpace > getBlendSpace( ) const;
106 void specialUnitService( Concrete::Length * d, double * a0, double * a1 );
108 bool isBaseEnvironment( ) const;
110 void print( std::ostream & os ) const;
111 size_t recursivePrint( std::ostream & os, std::set< MapType::key_type > * shadowed ) const;
113 private:
114 static KeyType nextKey;
115 public:
116 static KeyType getFreshKey( );
121 namespace Lang
124 class DynamicExpression : public Lang::NoOperatorOverloadValue
126 Kernel::PassedEnv env_;
127 Ast::Expression * expr_;
128 public:
129 DynamicExpression( Kernel::PassedEnv env, Ast::Expression * expr );
130 virtual ~DynamicExpression( );
131 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. */
132 virtual void gcMark( Kernel::GCMarkedSet & marked );
133 TYPEINFODECL;
138 class EyeZBinding : public Lang::DynamicBindings
140 const Ast::DynamicBindingExpression * bindingExpr_;
141 Concrete::Length val_;
142 const char * id_;
143 public:
144 EyeZBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val );
145 virtual ~EyeZBinding( );
146 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
147 virtual void show( std::ostream & os ) const;
148 virtual void gcMark( Kernel::GCMarkedSet & marked );
151 class TeXBleedBinding : public Lang::DynamicBindings
153 const Ast::DynamicBindingExpression * bindingExpr_;
154 Concrete::Length val_;
155 const char * id_;
156 public:
157 TeXBleedBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val );
158 virtual ~TeXBleedBinding( );
159 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
160 virtual void show( std::ostream & os ) const;
161 virtual void gcMark( Kernel::GCMarkedSet & marked );
164 class DefaultUnitBinding : public Lang::DynamicBindings
166 const Ast::DynamicBindingExpression * bindingExpr_;
167 RefCountPtr< const Kernel::PolarHandlePromise > val_;
168 const char * id_;
169 public:
170 DefaultUnitBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Kernel::PolarHandlePromise > & val );
171 virtual ~DefaultUnitBinding( );
172 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
173 virtual void show( std::ostream & os ) const;
174 virtual void gcMark( Kernel::GCMarkedSet & marked );
177 class BlendSpaceBinding : public Lang::DynamicBindings
179 const Ast::DynamicBindingExpression * bindingExpr_;
180 RefCountPtr< const Lang::ColorSpace > space_;
181 const char * id_;
182 public:
183 BlendSpaceBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Lang::ColorSpace > & space );
184 virtual ~BlendSpaceBinding( );
185 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
186 virtual void show( std::ostream & os ) const;
187 virtual void gcMark( Kernel::GCMarkedSet & marked );
192 namespace Kernel
195 class EyeZDynamicVariableProperties : public Kernel::DynamicVariableProperties
197 public:
198 EyeZDynamicVariableProperties( const char * name );
199 virtual ~EyeZDynamicVariableProperties( );
200 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
201 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
204 class TeXBleedDynamicVariableProperties : public Kernel::DynamicVariableProperties
206 public:
207 TeXBleedDynamicVariableProperties( const char * name );
208 virtual ~TeXBleedDynamicVariableProperties( );
209 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
210 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
213 class DefaultUnitDynamicVariableProperties : public Kernel::DynamicVariableProperties
215 public:
216 DefaultUnitDynamicVariableProperties( const char * name );
217 virtual ~DefaultUnitDynamicVariableProperties( );
218 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
219 virtual bool forceValue( ) const { return false; };
220 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
223 class BlendSpaceDynamicVariableProperties : public Kernel::DynamicVariableProperties
225 public:
226 BlendSpaceDynamicVariableProperties( const char * name );
227 virtual ~BlendSpaceDynamicVariableProperties( );
228 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
229 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;