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
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
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"
39 class SystemDynamicVariables
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
61 bool reverseDirection_
;
62 const Concrete::PathPoint2D
* p0_
;
63 const Concrete::PathPoint2D
* p1_
;
65 void specialUnitService( Concrete::Length
* d
, double * a0
, double * a1
);
71 RefCountPtr
< const Lang::Value
> last_
;
73 SpanLastValue( const RefCountPtr
< const Lang::Value
> & last
)
80 class DynamicEnvironment
82 RefCountPtr
< Kernel::DynamicEnvironment
> parent_
;
84 typedef DynamicEnvironmentKeyType KeyType
;
85 typedef Lang::DynamicBindings::MapType MapType
;
88 Kernel::SystemDynamicVariables
* sysBindings_
;
89 Kernel::SpecialUnitVariables
* specialBindings_
;
90 SpanLastValue
* spanLast_
;
92 Kernel::ContRef contVal_
;
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;
129 static KeyType nextKey
;
131 static KeyType
getFreshKey( );
139 class DynamicExpression
: public Lang::NoOperatorOverloadValue
141 Kernel::PassedEnv env_
;
142 Ast::Expression
* expr_
;
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
);
153 class EyeZBinding
: public Lang::DynamicBindings
155 const Ast::DynamicBindingExpression
* bindingExpr_
;
156 Concrete::Length val_
;
157 const Ast::PlacedIdentifier
* id_
;
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_
;
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_
;
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_
;
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
);
210 class EyeZDynamicVariableProperties
: public Kernel::DynamicVariableProperties
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
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
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
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
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;