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_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 NoOperatorOverloadValue
: public Lang::Value
90 NoOperatorOverloadValue( ){ }
91 virtual ~NoOperatorOverloadValue( ){ }
96 class Geometric2D
: public Lang::Value
100 virtual ~Geometric2D( ){ }
101 virtual RefCountPtr
< const Lang::Geometric2D
> transformed( const Lang::Transform2D
& transform
, const RefCountPtr
< const Lang::Geometric2D
> & self
) const = 0;
102 virtual RefCountPtr
< const Lang::Geometric3D
> to3D( const RefCountPtr
< const Lang::Geometric2D
> & self
) const = 0;
106 class NoOperatorOverloadGeometric2D
: public Lang::Geometric2D
109 NoOperatorOverloadGeometric2D( ){ }
110 virtual ~NoOperatorOverloadGeometric2D( ){ }
115 class Geometric3D
: public Lang::Value
119 virtual ~Geometric3D( ){ }
120 virtual RefCountPtr
< const Lang::Geometric3D
> transformed( const Lang::Transform3D
& transform
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const = 0;
121 virtual RefCountPtr
< const Lang::Geometric2D
> to2D( const Kernel::PassedDyn
& dyn
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const = 0;
132 down_cast( const RefCountPtr
< const Lang::Value
> & val
, const Ast::SourceLocation
& loc
, bool voidIsNull
= false )
134 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
135 if( res
== NullPtr
< T
>( ) )
138 dynamic_cast< const Lang::Void
* >( val
.getPtr( ) ) == 0 )
140 throw Exceptions::TypeMismatch( loc
, val
->getTypeName( ), T::staticTypeName( ) );
148 down_cast( const RefCountPtr
< const Lang::Value
> & val
, const char * internalLocStr
, bool voidIsNull
= false )
150 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
151 if( res
== NullPtr
< T
>( ) )
154 dynamic_cast< const Lang::Void
* >( val
.getPtr( ) ) == 0 )
156 throw Exceptions::TypeMismatch( Ast::SourceLocation( Ast::FileID::build_internal( internalLocStr
) ), val
->getTypeName( ), T::staticTypeName( ) );
164 down_cast_internal( const RefCountPtr
< const Lang::Value
> & val
)
166 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
167 if( res
== NullPtr
< T
>( ) )
169 throw Exceptions::InternalError( "down_cast_internal: type mismatch." );
174 Kernel::VariableHandle
newValHandle( const Lang::Value
* val
);