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, 2013, 2014 Henrik Tidefelt
21 #include "Shapes_Lang_decls.h"
22 #include "Shapes_Kernel_decls.h"
25 #include "classtreemacros.h"
26 #include "shapesexceptions.h"
35 #define MAKE_TYPEID( T ) TYPEID_ ## T ,
39 { SINGLELOOP1( CLASSTREE1_ROOT
, MAKE_TYPEID
)
43 #define TYPEINFODECL \
44 static RefCountPtr< const ::Shapes::Lang::Class > TypeID; \
45 virtual const RefCountPtr< const ::Shapes::Lang::Class > & getClass( ) const; \
46 static RefCountPtr< const char > staticTypeName( );
49 #define TYPEINFOIMPL( T ) \
50 const RefCountPtr< const ::Shapes::Lang::Class > & \
51 Lang::T::getClass( ) const \
55 RefCountPtr< const char > \
56 Lang::T::staticTypeName( ) \
58 return TypeID->getPrettyName( ); \
66 mutable const Ast::Node
* node_
;
70 virtual const RefCountPtr
< const ::Shapes::Lang::Class
> & getClass( ) const = 0;
71 virtual Kernel::QuickTypeID
getTypeID( ) const = 0;
73 virtual void gcMark( Kernel::GCMarkedSet
& marked
) = 0;
75 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
77 virtual void show( std::ostream
& os
) const;
79 RefCountPtr
< const char > getTypeName( ) const;
81 inline void set_node( const Ast::Node
* node
) const { node_
= node
; }
82 inline const Ast::Node
* node( ) const { return node_
; }
87 class Void
: public Lang::Value
91 virtual void show( std::ostream
& os
) const;
92 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
94 virtual Kernel::QuickTypeID
getTypeID( ) const { return Kernel::TYPEID_NoOperatorOverloadValue
; };
97 class NoOperatorOverloadValue
: public Lang::Value
100 NoOperatorOverloadValue( ){ }
101 virtual ~NoOperatorOverloadValue( ){ }
106 class Geometric2D
: public Lang::Value
110 virtual ~Geometric2D( ){ }
111 virtual RefCountPtr
< const Lang::Geometric2D
> transformed( const Lang::Transform2D
& transform
, const RefCountPtr
< const Lang::Geometric2D
> & self
) const = 0;
112 virtual RefCountPtr
< const Lang::Geometric3D
> to3D( const RefCountPtr
< const Lang::Geometric2D
> & self
) const = 0;
116 class NoOperatorOverloadGeometric2D
: public Lang::Geometric2D
119 NoOperatorOverloadGeometric2D( ){ }
120 virtual ~NoOperatorOverloadGeometric2D( ){ }
125 class Geometric3D
: public Lang::Value
129 virtual ~Geometric3D( ){ }
130 virtual RefCountPtr
< const Lang::Geometric3D
> transformed( const Lang::Transform3D
& transform
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const = 0;
131 virtual RefCountPtr
< const Lang::Geometric2D
> to2D( const Kernel::PassedDyn
& dyn
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const = 0;
135 class Hot
: public Lang::NoOperatorOverloadValue
140 virtual Kernel::State
* newState( ) const = 0;
151 down_cast( const RefCountPtr
< const Lang::Value
> & val
, const Ast::SourceLocation
& loc
, bool voidIsNull
= false )
153 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
154 if( res
== NullPtr
< T
>( ) )
157 dynamic_cast< const Lang::Void
* >( val
.getPtr( ) ) == 0 )
159 throw Exceptions::TypeMismatch( loc
, val
->getTypeName( ), T::staticTypeName( ) );
167 down_cast( const RefCountPtr
< const Lang::Value
> & val
, const char * internalLocStr
, bool voidIsNull
= false )
169 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
170 if( res
== NullPtr
< T
>( ) )
173 dynamic_cast< const Lang::Void
* >( val
.getPtr( ) ) == 0 )
175 throw Exceptions::TypeMismatch( Ast::theSourceLocationFactory
.construct_internal( internalLocStr
), val
->getTypeName( ), T::staticTypeName( ) );
183 down_cast_internal( const RefCountPtr
< const Lang::Value
> & val
)
185 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
186 if( res
== NullPtr
< T
>( ) )
188 throw Exceptions::InternalError( "down_cast_internal: type mismatch." );
193 Kernel::VariableHandle
newValHandle( const Lang::Value
* val
);