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 Henrik Tidefelt
21 #include "Shapes_Helpers_decls.h"
23 #include "shapescore.h"
25 #include "shapesexceptions.h"
29 #include "simplepdfi.h"
37 using namespace Shapes
;
40 RefCountPtr
< const Lang::ElementaryPath2D
>
41 Helpers::elementaryPathCast2D( const char * title
, Kernel::Arguments
& args
, size_t argNo
, const Ast::SourceLocation
& callLoc
)
43 RefCountPtr
< const Lang::Value
> ptr
= args
.getValue( argNo
);
44 typedef const Lang::ElementaryPath2D ArgType
;
45 RefCountPtr
< ArgType
> res
= ptr
.down_cast
< ArgType
>( );
46 if( res
!= NullPtr
< ArgType
>( ) )
51 typedef const Lang::CompositePath2D ArgType2
;
52 ArgType2
* res2
= dynamic_cast< ArgType2
* >( ptr
.getPtr( ) );
55 throw Exceptions::CoreTypeMismatch( callLoc
, title
, args
, argNo
, ArgType::staticTypeName( ) );
58 return res2
->getElementaryPath( );
61 RefCountPtr
< const Lang::ElementaryPath2D
>
62 Helpers::elementaryPathCast2D( const RefCountPtr
< const Lang::Value
> & ptr
, const Kernel::Continuation
* loc
)
64 typedef const Lang::ElementaryPath2D ArgType
;
65 RefCountPtr
< ArgType
> res
= ptr
.down_cast
< ArgType
>( );
66 if( res
!= NullPtr
< ArgType
>( ) )
71 typedef const Lang::CompositePath2D ArgType2
;
72 ArgType2
* res2
= dynamic_cast< ArgType2
* >( ptr
.getPtr( ) );
75 throw Exceptions::ContinuationTypeMismatch( loc
, ptr
->getTypeName( ), ArgType::staticTypeName( ) );
78 return res2
->getElementaryPath( );
81 RefCountPtr
< const Lang::ElementaryPath2D
>
82 Helpers::elementaryPathTry2D( const RefCountPtr
< const Lang::Value
> & ptr
)
84 typedef const Lang::ElementaryPath2D ArgType
;
85 RefCountPtr
< ArgType
> res
= ptr
.down_cast
< ArgType
>( );
86 if( res
!= NullPtr
< ArgType
>( ) )
91 typedef const Lang::CompositePath2D ArgType2
;
92 ArgType2
* res2
= dynamic_cast< ArgType2
* >( ptr
.getPtr( ) );
95 throw NonLocalExit::NotThisType( );
98 return res2
->getElementaryPath( );
103 Helpers::pathTimeCast( const char * title
, const RefCountPtr
< const Lang::ElementaryPath2D
> & pRef
, Kernel::Arguments
& args
, size_t argNo
, const Ast::SourceLocation
& callLoc
)
105 const Lang::ElementaryPath2D
* p
= pRef
.getPtr( );
106 const Lang::Value
* tPtr
= args
.getValue( argNo
).getPtr( );
107 typedef const Lang::Float ArgType
;
108 ArgType
* res
= dynamic_cast< ArgType
* >( tPtr
);
111 return Concrete::Time( res
->val_
);
114 typedef const Lang::Length ArgType2
;
115 ArgType2
* res2
= dynamic_cast< ArgType2
* >( tPtr
);
118 throw Exceptions::CoreTypeMismatch( callLoc
, title
, args
, argNo
, typeSetString( ArgType::staticTypeName( ), ArgType::staticTypeName( ) ) );
121 return p
->arcTime( res2
->get( ) );
125 Helpers::pathTimeCast( const Lang::ElementaryPath2D
* p
, const Lang::Value
* tPtr
, const Kernel::Continuation
* loc
)
127 typedef const Lang::Float ArgType
;
128 ArgType
* res
= dynamic_cast< ArgType
* >( tPtr
);
131 return Concrete::Time( res
->val_
);
134 typedef const Lang::Length ArgType2
;
135 ArgType2
* res2
= dynamic_cast< ArgType2
* >( tPtr
);
138 throw Exceptions::ContinuationTypeMismatch( loc
, tPtr
->getTypeName( ), typeSetString( ArgType::staticTypeName( ), ArgType2::staticTypeName( ) ) );
141 return p
->arcTime( res2
->get( ) );
145 RefCountPtr
< const Lang::ElementaryPath3D
>
146 Helpers::elementaryPathCast3D( const char * title
, Kernel::Arguments
& args
, size_t argNo
, const Ast::SourceLocation
& callLoc
)
148 RefCountPtr
< const Lang::Value
> ptr
= args
.getValue( argNo
);
149 typedef const Lang::ElementaryPath3D ArgType
;
150 RefCountPtr
< ArgType
> res
= ptr
.down_cast
< ArgType
>( );
151 if( res
!= NullPtr
< ArgType
>( ) )
156 typedef const Lang::CompositePath3D ArgType2
;
157 ArgType2
* res2
= dynamic_cast< ArgType2
* >( ptr
.getPtr( ) );
160 throw Exceptions::CoreTypeMismatch( callLoc
, title
, args
, argNo
, ArgType::staticTypeName( ) );
163 return res2
->getElementaryPath( );
166 RefCountPtr
< const Lang::ElementaryPath3D
>
167 Helpers::elementaryPathCast3D( const RefCountPtr
< const Lang::Value
> & ptr
, const Kernel::Continuation
* loc
)
169 typedef const Lang::ElementaryPath3D ArgType
;
170 RefCountPtr
< ArgType
> res
= ptr
.down_cast
< ArgType
>( );
171 if( res
!= NullPtr
< ArgType
>( ) )
176 typedef const Lang::CompositePath3D ArgType2
;
177 ArgType2
* res2
= dynamic_cast< ArgType2
* >( ptr
.getPtr( ) );
180 throw Exceptions::ContinuationTypeMismatch( loc
, ptr
->getTypeName( ), ArgType::staticTypeName( ) );
183 return res2
->getElementaryPath( );
186 RefCountPtr
< const Lang::ElementaryPath3D
>
187 Helpers::elementaryPathTry3D( const RefCountPtr
< const Lang::Value
> & ptr
)
189 typedef const Lang::ElementaryPath3D ArgType
;
190 RefCountPtr
< ArgType
> res
= ptr
.down_cast
< ArgType
>( );
191 if( res
!= NullPtr
< ArgType
>( ) )
196 typedef const Lang::CompositePath3D ArgType2
;
197 ArgType2
* res2
= dynamic_cast< ArgType2
* >( ptr
.getPtr( ) );
200 throw NonLocalExit::NotThisType( );
203 return res2
->getElementaryPath( );
208 Helpers::pathTimeCast( const char * title
, const RefCountPtr
< const Lang::ElementaryPath3D
> & pRef
, Kernel::Arguments
& args
, size_t argNo
, const Ast::SourceLocation
& callLoc
)
210 const Lang::ElementaryPath3D
* p
= pRef
.getPtr( );
211 const Lang::Value
* tPtr
= args
.getValue( argNo
).getPtr( );
212 typedef const Lang::Float ArgType
;
213 ArgType
* res
= dynamic_cast< ArgType
* >( tPtr
);
216 return Concrete::Time( res
->val_
);
219 typedef const Lang::Length ArgType2
;
220 ArgType2
* res2
= dynamic_cast< ArgType2
* >( tPtr
);
223 throw Exceptions::CoreTypeMismatch( callLoc
, title
, args
, argNo
, typeSetString( ArgType::staticTypeName( ), ArgType::staticTypeName( ) ) );
226 return p
->arcTime( res2
->get( ) );
230 Helpers::pathTimeCast( const Lang::ElementaryPath3D
* p
, const Lang::Value
* tPtr
, const Kernel::Continuation
* loc
)
232 typedef const Lang::Float ArgType
;
233 ArgType
* res
= dynamic_cast< ArgType
* >( tPtr
);
236 return Concrete::Time( res
->val_
);
239 typedef const Lang::Length ArgType2
;
240 ArgType2
* res2
= dynamic_cast< ArgType2
* >( tPtr
);
243 throw Exceptions::ContinuationTypeMismatch( loc
, tPtr
->getTypeName( ), typeSetString( ArgType::staticTypeName( ), ArgType2::staticTypeName( ) ) );
246 return p
->arcTime( res2
->get( ) );
250 RefCountPtr
< const char >
251 Helpers::typeSetString( RefCountPtr
< const char > type1
, RefCountPtr
< const char > type2
)
253 std::list
< RefCountPtr
< const char > > types
;
254 types
.push_back( type1
);
255 types
.push_back( type2
);
256 return typeSetString( types
);
259 RefCountPtr
< const char >
260 Helpers::typeSetString( RefCountPtr
< const char > type1
, RefCountPtr
< const char > type2
, RefCountPtr
< const char > type3
)
262 std::list
< RefCountPtr
< const char > > types
;
263 types
.push_back( type1
);
264 types
.push_back( type2
);
265 types
.push_back( type3
);
266 return typeSetString( types
);
269 RefCountPtr
< const char >
270 Helpers::typeSetString( RefCountPtr
< const char > type1
, RefCountPtr
< const char > type2
, RefCountPtr
< const char > type3
, RefCountPtr
< const char > type4
)
272 std::list
< RefCountPtr
< const char > > types
;
273 types
.push_back( type1
);
274 types
.push_back( type2
);
275 types
.push_back( type3
);
276 types
.push_back( type4
);
277 return typeSetString( types
);
280 RefCountPtr
< const char >
281 Helpers::typeSetString( RefCountPtr
< const char > type1
, RefCountPtr
< const char > type2
, RefCountPtr
< const char > type3
, RefCountPtr
< const char > type4
, RefCountPtr
< const char > type5
)
283 std::list
< RefCountPtr
< const char > > types
;
284 types
.push_back( type1
);
285 types
.push_back( type2
);
286 types
.push_back( type3
);
287 types
.push_back( type4
);
288 types
.push_back( type5
);
289 return typeSetString( types
);
292 RefCountPtr
< const char >
293 Helpers::typeSetString( const std::list
< RefCountPtr
< const char > > types
)
295 std::ostringstream oss
;
297 if( ! types
.empty( ) )
299 typedef typeof types ListType
;
300 ListType::const_iterator i
= types
.begin( );
303 for( ; i
!= types
.end( ); ++i
)
309 return strrefdup( oss
);
312 Lang::CoreFunction::CoreFunction( const char * title
)
313 : Lang::Function( new Kernel::EvaluatedFormals( Ast::FileID::build_internal( title
), true ) ), title_( title
)
316 Lang::CoreFunction::CoreFunction( const char * title
, Kernel::EvaluatedFormals
* formals
)
317 : Lang::Function( formals
), title_( title
)
321 Lang::CoreFunction::analyze_impl( Ast::Node
* parent
, Ast::AnalysisEnvironment
* env
, Ast::StateIDSet
* freeStatesDst
)
323 /* Nothing to be done! */
327 Lang::CoreFunction::isTransforming( ) const
333 Lang::CoreFunction::getTitle( ) const
339 Lang::CoreFunction::show( std::ostream
& os
) const
341 os
<< "< core function: " << title_
<< " >" ;