00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00033 #ifndef Y2NamespaceCPP_h
00034 #define Y2NamespaceCPP_h
00035
00036 #include <string>
00037 using std::string;
00038
00039 #include "ycp/YCPValue.h"
00040 #include "ycp/YCode.h"
00041 #include "ycp/YBlock.h"
00042 #include "ycp/SymbolEntryPtr.h"
00043 #include "ycp/y2log.h"
00044
00045 class SymbolTable;
00046 class Y2Function;
00047
00048 class Y2CPPFunction;
00049
00050 class Y2CPPFunctionCallBase : public YBlock
00051 {
00052 protected:
00053 SymbolEntryPtr m_param1;
00054 SymbolEntryPtr m_param2;
00055 SymbolEntryPtr m_param3;
00056 SymbolEntryPtr m_param4;
00057
00058 string m_signature;
00059
00060 void newParameter (YBlockPtr decl, uint pos, constTypePtr type);
00061
00062 public:
00063 Y2CPPFunctionCallBase (string ns, string signature) :
00064 YBlock (ns, YBlock::b_unknown)
00065 , m_param1 (NULL)
00066 , m_param2 (NULL)
00067 , m_param3 (NULL)
00068 , m_param4 (NULL)
00069 , m_signature (signature)
00070 {}
00071
00072 virtual void registerParameters (YBlockPtr decl) = 0;
00073
00074 friend class Y2CPPFunction;
00075 };
00076
00077 template <class T> class Y2CPPFunctionCall : public Y2CPPFunctionCallBase
00078 {
00079 protected:
00080 T* m_instance;
00081
00082 public:
00083 Y2CPPFunctionCall (string signature, T* instance) :
00084 Y2CPPFunctionCallBase (instance->name (), signature)
00085 , m_instance (instance)
00086 {}
00087
00088 friend class Y2CPPFunction;
00089 };
00090
00091
00092 class Y2CPPFunction : public YFunction {
00093 string m_name;
00094 Y2Namespace* m_parent;
00095 Y2CPPFunctionCallBase* m_impl;
00096 public:
00097 Y2CPPFunction( Y2Namespace* parent, string name, Y2CPPFunctionCallBase* call_impl );
00098
00099 SymbolEntryPtr sentry (uint position);
00100 };
00101
00102
00120 #define Y2FUNCTIONCALL(namespace, name, signature, impl_class, impl_func) \
00121 class namespace##name##Function : public Y2CPPFunctionCall <impl_class> { \
00122 public: \
00123 namespace##name##Function(impl_class* instance) : \
00124 Y2CPPFunctionCall <impl_class> (signature, instance) \
00125 {} \
00126 virtual void registerParameters (YBlockPtr) \
00127 { \
00128 } \
00129 virtual YCPValue evaluate (bool cse=false) \
00130 { \
00131 if (cse) return YCPNull (); \
00132 return m_instance->impl_func (); \
00133 } \
00134 }
00135
00136
00157 #define Y2FUNCTIONCALL1(namespace, name, signature, param1type, impl_class, impl_func) \
00158 class namespace##name##Function1 : public Y2CPPFunctionCall <impl_class> { \
00159 public: \
00160 namespace##name##Function1(impl_class* instance) : \
00161 Y2CPPFunctionCall <impl_class> (signature, instance) \
00162 {} \
00163 virtual void registerParameters (YBlockPtr decl) \
00164 { \
00165 newParameter (decl, 1, Type::Const##param1type ); \
00166 } \
00167 virtual YCPValue evaluate (bool cse=false) \
00168 { \
00169 if (cse) return YCPNull (); \
00170 YCPValue param1 = m_param1->value (); \
00171 if (param1.isNull () || param1->isVoid ()) \
00172 { \
00173 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00174 return YCPNull (); \
00175 } \
00176 return m_instance->impl_func (param1->as##param1type ()); \
00177 } \
00178 }
00179
00201 #define Y2FUNCTIONCALL2(namespace, name, signature, param1type, param2type, impl_class, impl_func) \
00202 class namespace##name##Function2 : public Y2CPPFunctionCall <impl_class> { \
00203 public: \
00204 namespace##name##Function2(impl_class* instance) : \
00205 Y2CPPFunctionCall <impl_class> (signature, instance) \
00206 {} \
00207 virtual void registerParameters (YBlockPtr decl) \
00208 { \
00209 newParameter (decl, 1, Type::Const##param1type ); \
00210 newParameter (decl, 2, Type::Const##param2type ); \
00211 } \
00212 virtual YCPValue evaluate (bool cse=false) \
00213 { \
00214 if (cse) return YCPNull (); \
00215 YCPValue param1 = m_param1->value (); \
00216 YCPValue param2 = m_param2->value (); \
00217 if (param1.isNull () || param1->isVoid ()) \
00218 { \
00219 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00220 return YCPNull (); \
00221 } \
00222 if (param2.isNull () || param2->isVoid ()) \
00223 { \
00224 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00225 return YCPNull (); \
00226 } \
00227 return m_instance->impl_func ( \
00228 param1->as##param1type () \
00229 , param2->as##param2type ()); \
00230 } \
00231 }
00232
00256 #define Y2FUNCTIONCALL3(namespace, name, signature, param1type, param2type, param3type, impl_class, impl_func) \
00257 class namespace##name##Function3 : public Y2CPPFunctionCall <impl_class> { \
00258 public: \
00259 namespace##name##Function3(impl_class* instance) : \
00260 Y2CPPFunctionCall <impl_class> (signature, instance) \
00261 {} \
00262 virtual void registerParameters (YBlockPtr decl) \
00263 { \
00264 newParameter (decl, 1, Type::Const##param1type ); \
00265 newParameter (decl, 2, Type::Const##param2type ); \
00266 newParameter (decl, 3, Type::Const##param3type ); \
00267 } \
00268 virtual YCPValue evaluate (bool cse=false) \
00269 { \
00270 if (cse) return YCPNull (); \
00271 YCPValue param1 = m_param1->value (); \
00272 YCPValue param2 = m_param2->value (); \
00273 YCPValue param3 = m_param3->value (); \
00274 if (param1.isNull () || param1->isVoid ()) \
00275 { \
00276 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00277 return YCPNull (); \
00278 } \
00279 if (param2.isNull () || param2->isVoid ()) \
00280 { \
00281 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00282 return YCPNull (); \
00283 } \
00284 if (param3.isNull () || param3->isVoid ()) \
00285 { \
00286 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00287 return YCPNull (); \
00288 } \
00289 return m_instance->impl_func ( param1->as##param1type () \
00290 ,param2->as##param2type () \
00291 ,param3->as##param3type ()); \
00292 } \
00293 }
00294
00321 #define Y2FUNCTIONCALL4(namespace, name, signature, param1type, param2type, param3type, param4type, impl_class, impl_func) \
00322 class namespace##name##Function4 : public Y2CPPFunctionCall <impl_class> { \
00323 public: \
00324 namespace##name##Function4(impl_class* instance) : \
00325 Y2CPPFunctionCall <impl_class> (signature, instance) \
00326 {} \
00327 virtual void registerParameters (YBlockPtr decl) \
00328 { \
00329 newParameter (decl, 1, Type::Const##param1type ); \
00330 newParameter (decl, 2, Type::Const##param2type ); \
00331 newParameter (decl, 3, Type::Const##param3type ); \
00332 newParameter (decl, 4, Type::Const##param4type ); \
00333 } \
00334 virtual YCPValue evaluate (bool cse=false) \
00335 { \
00336 if (cse) return YCPNull (); \
00337 YCPValue param1 = m_param1->value (); \
00338 YCPValue param2 = m_param2->value (); \
00339 YCPValue param3 = m_param3->value (); \
00340 YCPValue param4 = m_param4->value (); \
00341 if (param1.isNull () || param1->isVoid ()) \
00342 { \
00343 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00344 return YCPNull (); \
00345 } \
00346 if (param2.isNull () || param2->isVoid ()) \
00347 { \
00348 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00349 return YCPNull (); \
00350 } \
00351 if (param3.isNull () || param3->isVoid ()) \
00352 { \
00353 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00354 return YCPNull (); \
00355 } \
00356 if (param4.isNull () || param4->isVoid ()) \
00357 { \
00358 ycperror ("Passing 'nil' to %s::%s", #namespace, #name); \
00359 return YCPNull (); \
00360 } \
00361 return m_instance->impl_func (param1->as##param1type () \
00362 ,param2->as##param2type () \
00363 ,param3->as##param3type () \
00364 ,param4->as##param4type ()); \
00365 } \
00366 }
00367
00380 #define REGISTERFUNCTIONCALL(position, namespace, name) \
00381 do { \
00382 Y2CPPFunction* mf = new Y2CPPFunction ( \
00383 this, \
00384 #name, \
00385 new namespace##name##Function (this)); \
00386 enterSymbol (mf->sentry (position), 0); \
00387 } while (0)
00388
00389
00402 #define REGISTERFUNCTIONCALL1(position, namespace, name) \
00403 do { \
00404 Y2CPPFunction* mf = new Y2CPPFunction ( \
00405 this, \
00406 #name, \
00407 new namespace##name##Function1 (this)); \
00408 enterSymbol (mf->sentry (position), 0); \
00409 } while (0)
00410
00411
00424 #define REGISTERFUNCTIONCALL2(position, namespace, name) \
00425 do { \
00426 Y2CPPFunction* mf = new Y2CPPFunction ( \
00427 this, \
00428 #name, \
00429 new namespace##name##Function2 (this)); \
00430 enterSymbol (mf->sentry (position), 0); \
00431 } while (0)
00432
00433
00446 #define REGISTERFUNCTIONCALL3(position, namespace, name) \
00447 do { \
00448 Y2CPPFunction* mf = new Y2CPPFunction ( \
00449 this, \
00450 #name, \
00451 new namespace##name##Function3 (this)); \
00452 enterSymbol (mf->sentry (position), 0); \
00453 } while (0)
00454
00455
00468 #define REGISTERFUNCTIONCALL4(position, namespace, name) \
00469 do { \
00470 Y2CPPFunction* mf = new Y2CPPFunction ( \
00471 this, \
00472 #name, \
00473 new namespace##name##Function4 (this)); \
00474 enterSymbol (mf->sentry (position), 0); \
00475 } while (0)
00476
00477
00478 #endif // Y2Namespace_h