Update procedures
[shapes.git] / source / methodbase.h
blobcde23f3cdd0c927ee71ec2264b3ed7842aa4de0b
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 #pragma once
21 #include "functiontypes.h"
23 namespace Shapes
25 namespace Kernel
27 class MethodBaseBase : public Lang::Function
29 protected:
30 RefCountPtr< const Interaction::FileIDLocation > coreLoc_;
31 public:
32 MethodBaseBase( const Ast::FileID * coreLoc, bool forceAll )
33 : Lang::Function( new Kernel::EvaluatedFormals( coreLoc, forceAll ) ),
34 coreLoc_( new Interaction::FileIDLocation( coreLoc ) )
35 { }
36 MethodBaseBase( const Ast::FileID * coreLoc )
37 : Lang::Function( new Kernel::EvaluatedFormals( coreLoc ) ),
38 coreLoc_( new Interaction::FileIDLocation( coreLoc ) )
39 { }
40 virtual ~MethodBaseBase( )
41 { }
45 namespace Lang
48 template< class T >
49 class MethodBase : public Kernel::MethodBaseBase
51 public:
52 typedef T class_type;
53 protected:
54 RefCountPtr< const T > self_;
55 bool transforming_;
56 public:
57 MethodBase( RefCountPtr< const T > self, const Ast::FileID * coreLoc, bool transforming );
58 MethodBase( RefCountPtr< const T > self, const Ast::FileID * coreLoc, bool transforming, bool forceAll );
59 virtual ~MethodBase( );
60 virtual void gcMark( Kernel::GCMarkedSet & marked );
61 virtual bool isTransforming( ) const;
66 namespace Kernel
69 class MethodFactoryBase
71 protected:
72 const char * field_;
73 public:
74 MethodFactoryBase( const char * field )
75 : field_( field )
76 { }
77 virtual ~MethodFactoryBase( )
78 { }
79 const char * field( ) const { return field_; }
80 virtual Kernel::VariableHandle build( const RefCountPtr< const Lang::Value > self ) const = 0;
83 template< class ValueType, class Method >
84 class MethodFactory : public MethodFactoryBase
86 RefCountPtr< const char > fullMethodID_mem_;
87 const Ast::FileID * fullMethodID_;
88 public:
89 MethodFactory( )
90 : MethodFactoryBase( Method::staticFieldID( ) ),
91 fullMethodID_mem_( Kernel::MethodId( ValueType::TypeID, Method::staticFieldID( ) ).prettyName( ) ),
92 fullMethodID_( Ast::FileID::build_internal( fullMethodID_mem_.getPtr( ) ) )
93 { }
94 virtual ~MethodFactory( )
95 { }
96 virtual Kernel::VariableHandle build( const RefCountPtr< const Lang::Value > self ) const
98 return Helpers::newValHandle( new Method( Helpers::down_cast_internal< const ValueType >( self ), fullMethodID_ ) );
105 #include "methodbase_impl.h"