Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / units_obsolete.cc
blob30a550468a3b42f62c782e7e0c08f85837c55454
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 class UserLength : public Expression
21 Ast::SourceLocation loc;
22 double val;
23 const char * unit;
24 public:
25 UserLength( const Ast::SourceLocation & _loc, double _val, const char * _unit );
26 virtual ~UserLength( );
27 virtual void eval( Kernel::EvalState * evalState ) const;
28 virtual const Ast::SourceLocation & firstLoc( ) const;
29 virtual const Ast::SourceLocation & lastLoc( ) const;
32 class IntroduceUnitStmt : public Expression
34 Ast::SourceLocation idLoc;
35 const char * id;
36 Ast::Expression * expr;
37 public:
38 IntroduceUnitStmt( const Ast::SourceLocation & _idLoc, const char * _id, Ast::Expression * _expr );
39 virtual ~IntroduceUnitStmt( );
40 virtual void eval( Kernel::EvalState * evalState ) const;
41 virtual const Ast::SourceLocation & firstLoc( ) const;
42 virtual const Ast::SourceLocation & lastLoc( ) const;
48 Shapes::UserLength::UserLength( const Ast::SourceLocation & _loc, double _val, const char * _unit )
49 : loc( _loc ), val( _val ), unit( _unit )
50 { }
52 Shapes::UserLength::~UserLength( )
54 delete unit;
57 void
58 Shapes::UserLength::eval( Kernel::EvalState * evalState ) const
60 Kernel::ContRef cont = evalState->cont_;
61 (*cont)( Kernel::ValueRef( new Lang::Length( val * evalState->env->lookupUnit( loc, unit ) ) ),
62 evalState );
65 const Ast::SourceLocation &
66 Shapes::UserLength::firstLoc( ) const
68 return loc;
71 const Ast::SourceLocation &
72 Shapes::UserLength::lastLoc( ) const
74 return loc;
78 Shapes::IntroduceUnitStmt::IntroduceUnitStmt( const Ast::SourceLocation & _idLoc, const char * _id, Ast::Expression * _expr )
79 : idLoc( _idLoc ), id( _id ), expr( _expr )
80 { }
82 Shapes::IntroduceUnitStmt::~IntroduceUnitStmt( )
84 delete id;
85 delete expr;
88 RefCountPtr< const Lang::Value >
89 Shapes::IntroduceUnitStmt::value( Kernel::VariableHandle dstgroup, SimplePDF::PDF_out * pdfo, Kernel::GraphicsState * metaState, Kernel::PassedEnv env ) const
91 RefCountPtr< const Lang::Value > untypedVal = expr->value( dstgroup, pdfo, metaState, env );
92 typedef const Lang::Length ArgType;
93 ArgType * val = dynamic_cast< ArgType * >( untypedVal.getPtr( ) );
94 if( val == 0 )
96 throw Exceptions::TypeMismatch( expr, untypedVal->getTypeName( ), ArgType::staticTypeName( ) );
98 env->defineUnit( idLoc, id, val->getVal( ) );
99 return Shapes::THE_VOID;
102 const Ast::SourceLocation &
103 Shapes::IntroduceUnitStmt::firstLoc( ) const
105 return idLoc;
108 const Ast::SourceLocation &
109 Shapes::IntroduceUnitStmt::lastLoc( ) const
111 return expr->lastLoc( );
115 Shapes::AssignUnitStmt::AssignUnitStmt( const Ast::SourceLocation & _idLoc, const char * _id, Ast::Expression * _expr )
116 : idLoc( _idLoc ), id( _id ), expr( _expr )
119 Shapes::AssignUnitStmt::~AssignUnitStmt( )
121 delete id;
122 delete expr;
125 RefCountPtr< const Lang::Value >
126 Shapes::AssignUnitStmt::value( Kernel::VariableHandle dstgroup, SimplePDF::PDF_out * pdfo, Kernel::GraphicsState * metaState, Kernel::PassedEnv env ) const
128 RefCountPtr< const Lang::Value > untypedVal = expr->value( dstgroup, pdfo, metaState, env );
129 typedef const Lang::Length ArgType;
130 ArgType * val = dynamic_cast< ArgType * >( untypedVal.getPtr( ) );
131 if( val == 0 )
133 throw Exceptions::TypeMismatch( expr, untypedVal->getTypeName( ), ArgType::staticTypeName( ) );
135 env->redefineUnit( idLoc, id, val->getVal( ) );
136 return Shapes::THE_VOID;
139 const Ast::SourceLocation &
140 Shapes::AssignUnitStmt::firstLoc( ) const
142 return idLoc;
145 const Ast::SourceLocation &
146 Shapes::AssignUnitStmt::lastLoc( ) const
148 return expr->lastLoc( );