| 1 | #include "capi.h" |
| 2 | |
| 3 | // include all headers from datatype.cxx and example01.cxx here, |
| 4 | // allowing those .cxx files to be placed in the "dummy" namespace |
| 5 | #include <cassert> |
| 6 | #include <cstddef> |
| 7 | #include <cstdint> |
| 8 | #include <cstring> |
| 9 | #include <cwchar> |
| 10 | |
| 11 | #include <complex> |
| 12 | #include <functional> |
| 13 | #include <map> |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | #include <sstream> |
| 17 | #include <utility> |
| 18 | #include <vector> |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #pragma GCC diagnostic ignored "-Winvalid-offsetof" |
| 23 | |
| 24 | #if defined(_MSC_VER) |
| 25 | #define INLINE __inline |
| 26 | #elif defined(__GNUC__) |
| 27 | #if defined(__STRICT_ANSI__) |
| 28 | #define INLINE __inline__ |
| 29 | #else |
| 30 | #define INLINE inline |
| 31 | #endif |
| 32 | #else |
| 33 | #define INLINE |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | // union for argument passing |
| 38 | struct CPPYY_G__value { |
| 39 | union { |
| 40 | double d; |
| 41 | long i; /* used to be int */ |
| 42 | char ch; |
| 43 | short sh; |
| 44 | int in; |
| 45 | float fl; |
| 46 | unsigned char uch; |
| 47 | unsigned short ush; |
| 48 | unsigned int uin; |
| 49 | unsigned long ulo; |
| 50 | long long ll; |
| 51 | unsigned long long ull; |
| 52 | long double ld; |
| 53 | } obj; |
| 54 | long ref; |
| 55 | int type; |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | // gInterpreter |
| 60 | namespace dummy { |
| 61 | class TInterpreter { |
| 62 | public: |
| 63 | int ProcessLine(const char* line) { |
| 64 | if (strcmp(line, "__cplusplus;") == 0) |
| 65 | return 0; |
| 66 | return -1; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | TInterpreter gInterpreter; |
| 71 | } // namespace dummy |
| 72 | |
| 73 | |
| 74 | // add example01.cxx code |
| 75 | int globalAddOneToInt(int a); |
| 76 | |
| 77 | namespace dummy { |
| 78 | #include "example01.cxx" |
| 79 | #include "datatypes.cxx" |
| 80 | } |
| 81 | |
| 82 | int globalAddOneToInt(int a) { |
| 83 | return dummy::globalAddOneToInt(a); |
| 84 | } |
| 85 | |
| 86 | /* pseudo-reflection data ------------------------------------------------- */ |
| 87 | namespace { |
| 88 | |
| 89 | typedef std::map<std::string, cppyy_scope_t> Handles_t; |
| 90 | static Handles_t s_handles; |
| 91 | |
| 92 | enum EMethodType { kNormal=0, kConstructor=1, kStatic=2 }; |
| 93 | |
| 94 | struct Cppyy_PseudoMethodInfo { |
| 95 | Cppyy_PseudoMethodInfo(const std::string& name, |
| 96 | const std::vector<std::string>& argtypes, |
| 97 | const std::string& returntype, |
| 98 | EMethodType mtype = kNormal) : |
| 99 | m_name(name), m_argtypes(argtypes), m_returntype(returntype), m_type(mtype) {} |
| 100 | std::string m_name; |
| 101 | std::vector<std::string> m_argtypes; |
| 102 | std::vector<std::string> m_argdefaults; |
| 103 | std::string m_returntype; |
| 104 | EMethodType m_type; |
| 105 | }; |
| 106 | |
| 107 | struct Cppyy_PseudoDatambrInfo { |
| 108 | Cppyy_PseudoDatambrInfo(const std::string& name, |
| 109 | const std::string& type, |
| 110 | ptrdiff_t offset, bool isstatic) : |
| 111 | m_name(name), m_type(type), m_offset(offset), m_isstatic(isstatic) {} |
| 112 | std::string m_name; |
| 113 | std::string m_type; |
| 114 | ptrdiff_t m_offset; |
| 115 | bool m_isstatic; |
| 116 | }; |
| 117 | |
| 118 | struct Cppyy_PseudoClassInfo { |
| 119 | Cppyy_PseudoClassInfo() {} |
| 120 | Cppyy_PseudoClassInfo(const std::vector<Cppyy_PseudoMethodInfo*>& methods, |
| 121 | const std::vector<Cppyy_PseudoDatambrInfo>& data) : |
| 122 | m_methods(methods), m_datambrs(data) {} |
| 123 | std::vector<Cppyy_PseudoMethodInfo*> m_methods; |
| 124 | std::vector<Cppyy_PseudoDatambrInfo> m_datambrs; |
| 125 | }; |
| 126 | |
| 127 | typedef std::map<cppyy_scope_t, Cppyy_PseudoClassInfo> Scopes_t; |
| 128 | static Scopes_t s_scopes; |
| 129 | |
| 130 | static std::map<std::string, Cppyy_PseudoMethodInfo*> s_methods; |
| 131 | struct CleanPseudoMethods { |
| 132 | ~CleanPseudoMethods() { for (auto& x : s_methods) delete x.second; } |
| 133 | } _clean; |
| 134 | |
| 135 | int Pseudo_kNothing = 6; |
| 136 | int Pseudo_kSomething = 111; |
| 137 | int Pseudo_kLots = 42; |
| 138 | |
| 139 | #define PUBLIC_CPPYY_DATA(dmname, dmtype) \ |
| 140 | data.push_back(Cppyy_PseudoDatambrInfo("m_"#dmname, #dmtype, \ |
| 141 | offsetof(dummy::CppyyTestData, m_##dmname), false)); \ |
| 142 | /* <type> get_<type>() */ \ |
| 143 | argtypes.clear(); \ |
| 144 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 145 | "get_"#dmname, argtypes, #dmtype)); \ |
| 146 | s_methods["CppyyTestData::get_"#dmname] = methods.back(); \ |
| 147 | /* <type>& get_<type>_r() */ \ |
| 148 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 149 | "get_"#dmname"_r", argtypes, #dmtype"&")); \ |
| 150 | s_methods["CppyyTestData::get_"#dmname"_r"] = methods.back(); \ |
| 151 | /* const <type>& get_<type>_cr() */ \ |
| 152 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 153 | "get_"#dmname"_cr", argtypes, "const "#dmtype"&")); \ |
| 154 | s_methods["CppyyTestData::get_"#dmname"_cr"] = methods.back(); \ |
| 155 | /* void set_<type>(<type>) */ \ |
| 156 | argtypes.push_back(#dmtype); \ |
| 157 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 158 | "set_"#dmname, argtypes, "void")); \ |
| 159 | s_methods["CppyyTestData::set_"#dmname] = methods.back(); \ |
| 160 | argtypes.clear(); \ |
| 161 | /* void set_<type>(const <type>&) */ \ |
| 162 | argtypes.push_back("const "#dmtype"&"); \ |
| 163 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 164 | "set_"#dmname"_cr", argtypes, "void")); \ |
| 165 | s_methods["CppyyTestData::set_"#dmname"_cr"] = methods.back() |
| 166 | |
| 167 | #define PUBLIC_CPPYY_DATA2(dmname, dmtype) \ |
| 168 | PUBLIC_CPPYY_DATA(dmname, dmtype); \ |
| 169 | data.push_back(Cppyy_PseudoDatambrInfo("m_"#dmname"_array", #dmtype"[5]", \ |
| 170 | offsetof(dummy::CppyyTestData, m_##dmname##_array), false)); \ |
| 171 | data.push_back(Cppyy_PseudoDatambrInfo("m_"#dmname"_array2", #dmtype"*", \ |
| 172 | offsetof(dummy::CppyyTestData, m_##dmname##_array2), false)); \ |
| 173 | argtypes.clear(); \ |
| 174 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 175 | "get_"#dmname"_array", argtypes, #dmtype"*")); \ |
| 176 | s_methods["CppyyTestData::get_"#dmname"_array"] = methods.back(); \ |
| 177 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 178 | "get_"#dmname"_array2", argtypes, #dmtype"*")); \ |
| 179 | s_methods["CppyyTestData::get_"#dmname"_array2"] = methods.back() |
| 180 | |
| 181 | #define PUBLIC_CPPYY_DATA3(dmname, dmtype, key) \ |
| 182 | PUBLIC_CPPYY_DATA2(dmname, dmtype); \ |
| 183 | argtypes.push_back(#dmtype"*"); \ |
| 184 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 185 | "pass_array", argtypes, #dmtype"*")); \ |
| 186 | s_methods["CppyyTestData::pass_array_"#dmname] = methods.back(); \ |
| 187 | argtypes.clear(); argtypes.push_back("void*"); \ |
| 188 | methods.push_back(new Cppyy_PseudoMethodInfo( \ |
| 189 | "pass_void_array_"#key, argtypes, #dmtype"*")); \ |
| 190 | s_methods["CppyyTestData::pass_void_array_"#key] = methods.back() |
| 191 | |
| 192 | #define PUBLIC_CPPYY_STATIC_DATA(dmname, dmtype) \ |
| 193 | data.push_back(Cppyy_PseudoDatambrInfo("s_"#dmname, #dmtype, \ |
| 194 | (ptrdiff_t)&dummy::CppyyTestData::s_##dmname, true)) |
| 195 | |
| 196 | |
| 197 | struct Cppyy_InitPseudoReflectionInfo { |
| 198 | Cppyy_InitPseudoReflectionInfo() { |
| 199 | static cppyy_scope_t s_scope_id = 0; |
| 200 | |
| 201 | { // namespace '' |
| 202 | s_handles[""] = (cppyy_scope_t)++s_scope_id; |
| 203 | |
| 204 | std::vector<Cppyy_PseudoDatambrInfo> data; |
| 205 | data.push_back(Cppyy_PseudoDatambrInfo("N", "int", (ptrdiff_t)&dummy::N, true)); |
| 206 | data.push_back(Cppyy_PseudoDatambrInfo( |
| 207 | "gInterpreter", "TInterpreter", (ptrdiff_t)&dummy::gInterpreter, true)); |
| 208 | |
| 209 | Cppyy_PseudoClassInfo info(std::vector<Cppyy_PseudoMethodInfo*>(), data); |
| 210 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 211 | } |
| 212 | |
| 213 | { // namespace std |
| 214 | s_handles["std"] = (cppyy_scope_t)++s_scope_id; |
| 215 | } |
| 216 | |
| 217 | { // class TInterpreter |
| 218 | s_handles["TInterpreter"] = (cppyy_scope_t)++s_scope_id; |
| 219 | |
| 220 | std::vector<Cppyy_PseudoMethodInfo*> methods; |
| 221 | |
| 222 | std::vector<std::string> argtypes; |
| 223 | argtypes.push_back("const char*"); |
| 224 | methods.push_back(new Cppyy_PseudoMethodInfo("ProcessLine", argtypes, "int")); |
| 225 | s_methods["TInterpreter::ProcessLine_cchar*"] = methods.back(); |
| 226 | |
| 227 | Cppyy_PseudoClassInfo info(methods, std::vector<Cppyy_PseudoDatambrInfo>()); |
| 228 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 229 | } |
| 230 | |
| 231 | { // class example01 -- |
| 232 | s_handles["example01"] = (cppyy_scope_t)++s_scope_id; |
| 233 | |
| 234 | std::vector<Cppyy_PseudoMethodInfo*> methods; |
| 235 | |
| 236 | // static double staticAddToDouble(double a) |
| 237 | std::vector<std::string> argtypes; |
| 238 | argtypes.push_back("double"); |
| 239 | methods.push_back(new Cppyy_PseudoMethodInfo("staticAddToDouble", argtypes, "double", kStatic)); |
| 240 | s_methods["static_example01::staticAddToDouble_double"] = methods.back(); |
| 241 | |
| 242 | // static int staticAddOneToInt(int a) |
| 243 | // static int staticAddOneToInt(int a, int b) |
| 244 | argtypes.clear(); |
| 245 | argtypes.push_back("int"); |
| 246 | methods.push_back(new Cppyy_PseudoMethodInfo("staticAddOneToInt", argtypes, "int", kStatic)); |
| 247 | s_methods["static_example01::staticAddOneToInt_int"] = methods.back(); |
| 248 | argtypes.push_back("int"); |
| 249 | methods.push_back(new Cppyy_PseudoMethodInfo("staticAddOneToInt", argtypes, "int", kStatic)); |
| 250 | s_methods["static_example01::staticAddOneToInt_int_int"] = methods.back(); |
| 251 | |
| 252 | // static int staticAtoi(const char* str) |
| 253 | argtypes.clear(); |
| 254 | argtypes.push_back("const char*"); |
| 255 | methods.push_back(new Cppyy_PseudoMethodInfo("staticAtoi", argtypes, "int", kStatic)); |
| 256 | s_methods["static_example01::staticAtoi_cchar*"] = methods.back(); |
| 257 | |
| 258 | // static char* staticStrcpy(const char* strin) |
| 259 | methods.push_back(new Cppyy_PseudoMethodInfo("staticStrcpy", argtypes, "char*", kStatic)); |
| 260 | s_methods["static_example01::staticStrcpy_cchar*"] = methods.back(); |
| 261 | |
| 262 | // static void staticSetPayload(payload* p, double d) |
| 263 | // static payload* staticCyclePayload(payload* p, double d) |
| 264 | // static payload staticCopyCyclePayload(payload* p, double d) |
| 265 | argtypes.clear(); |
| 266 | argtypes.push_back("payload*"); |
| 267 | argtypes.push_back("double"); |
| 268 | methods.push_back(new Cppyy_PseudoMethodInfo("staticSetPayload", argtypes, "void", kStatic)); |
| 269 | s_methods["static_example01::staticSetPayload_payload*_double"] = methods.back(); |
| 270 | methods.push_back(new Cppyy_PseudoMethodInfo("staticCyclePayload", argtypes, "payload*", kStatic)); |
| 271 | s_methods["static_example01::staticCyclePayload_payload*_double"] = methods.back(); |
| 272 | methods.push_back(new Cppyy_PseudoMethodInfo("staticCopyCyclePayload", argtypes, "payload", kStatic)); |
| 273 | s_methods["static_example01::staticCopyCyclePayload_payload*_double"] = methods.back(); |
| 274 | |
| 275 | // static int getCount() |
| 276 | // static void setCount(int) |
| 277 | argtypes.clear(); |
| 278 | methods.push_back(new Cppyy_PseudoMethodInfo("getCount", argtypes, "int", kStatic)); |
| 279 | s_methods["static_example01::getCount"] = methods.back(); |
| 280 | argtypes.push_back("int"); |
| 281 | methods.push_back(new Cppyy_PseudoMethodInfo("setCount", argtypes, "void", kStatic)); |
| 282 | s_methods["static_example01::setCount_int"] = methods.back(); |
| 283 | |
| 284 | // example01() |
| 285 | // example01(int a) |
| 286 | argtypes.clear(); |
| 287 | methods.push_back(new Cppyy_PseudoMethodInfo("example01", argtypes, "constructor", kConstructor)); |
| 288 | s_methods["example01::example01"] = methods.back(); |
| 289 | argtypes.push_back("int"); |
| 290 | methods.push_back(new Cppyy_PseudoMethodInfo("example01", argtypes, "constructor", kConstructor)); |
| 291 | s_methods["example01::example01_int"] = methods.back(); |
| 292 | |
| 293 | // int addDataToInt(int a) |
| 294 | argtypes.clear(); |
| 295 | argtypes.push_back("int"); |
| 296 | methods.push_back(new Cppyy_PseudoMethodInfo("addDataToInt", argtypes, "int")); |
| 297 | s_methods["example01::addDataToInt_int"] = methods.back(); |
| 298 | |
| 299 | // int addDataToIntConstRef(const int& a) |
| 300 | argtypes.clear(); |
| 301 | argtypes.push_back("const int&"); |
| 302 | methods.push_back(new Cppyy_PseudoMethodInfo("addDataToIntConstRef", argtypes, "int")); |
| 303 | s_methods["example01::addDataToIntConstRef_cint&"] = methods.back(); |
| 304 | |
| 305 | // int overloadedAddDataToInt(int a, int b) |
| 306 | argtypes.clear(); |
| 307 | argtypes.push_back("int"); |
| 308 | argtypes.push_back("int"); |
| 309 | methods.push_back(new Cppyy_PseudoMethodInfo("overloadedAddDataToInt", argtypes, "int")); |
| 310 | s_methods["example01::overloadedAddDataToInt_int_int"] = methods.back(); |
| 311 | |
| 312 | // int overloadedAddDataToInt(int a) |
| 313 | // int overloadedAddDataToInt(int a, int b, int c) |
| 314 | argtypes.clear(); |
| 315 | argtypes.push_back("int"); |
| 316 | methods.push_back(new Cppyy_PseudoMethodInfo("overloadedAddDataToInt", argtypes, "int")); |
| 317 | s_methods["example01::overloadedAddDataToInt_int"] = methods.back(); |
| 318 | argtypes.push_back("int"); |
| 319 | argtypes.push_back("int"); |
| 320 | methods.push_back(new Cppyy_PseudoMethodInfo("overloadedAddDataToInt", argtypes, "int")); |
| 321 | s_methods["example01::overloadedAddDataToInt_int_int_int"] = methods.back(); |
| 322 | |
| 323 | // double addDataToDouble(double a) |
| 324 | argtypes.clear(); |
| 325 | argtypes.push_back("double"); |
| 326 | methods.push_back(new Cppyy_PseudoMethodInfo("addDataToDouble", argtypes, "double")); |
| 327 | s_methods["example01::addDataToDouble_double"] = methods.back(); |
| 328 | |
| 329 | // int addDataToAtoi(const char* str) |
| 330 | // char* addToStringValue(const char* str) |
| 331 | argtypes.clear(); |
| 332 | argtypes.push_back("const char*"); |
| 333 | methods.push_back(new Cppyy_PseudoMethodInfo("addDataToAtoi", argtypes, "int")); |
| 334 | s_methods["example01::addDataToAtoi_cchar*"] = methods.back(); |
| 335 | methods.push_back(new Cppyy_PseudoMethodInfo("addToStringValue", argtypes, "char*")); |
| 336 | s_methods["example01::addToStringValue_cchar*"] = methods.back(); |
| 337 | |
| 338 | // void setPayload(payload* p) |
| 339 | // payload* cyclePayload(payload* p) |
| 340 | // payload copyCyclePayload(payload* p) |
| 341 | argtypes.clear(); |
| 342 | argtypes.push_back("payload*"); |
| 343 | methods.push_back(new Cppyy_PseudoMethodInfo("setPayload", argtypes, "void")); |
| 344 | s_methods["example01::setPayload_payload*"] = methods.back(); |
| 345 | methods.push_back(new Cppyy_PseudoMethodInfo("cyclePayload", argtypes, "payload*")); |
| 346 | s_methods["example01::cyclePayload_payload*"] = methods.back(); |
| 347 | methods.push_back(new Cppyy_PseudoMethodInfo("copyCyclePayload", argtypes, "payload")); |
| 348 | s_methods["example01::copyCyclePayload_payload*"] = methods.back(); |
| 349 | |
| 350 | Cppyy_PseudoClassInfo info(methods, std::vector<Cppyy_PseudoDatambrInfo>()); |
| 351 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 352 | } // -- class example01 |
| 353 | |
| 354 | //==================================================================== |
| 355 | |
| 356 | { // class complex<double> -- |
| 357 | s_handles["complex_t"] = (cppyy_scope_t)++s_scope_id; |
| 358 | s_handles["std::complex<double>"] = s_handles["complex_t"]; |
| 359 | |
| 360 | std::vector<Cppyy_PseudoMethodInfo*> methods; |
| 361 | |
| 362 | std::vector<std::string> argtypes; |
| 363 | |
| 364 | // double real() |
| 365 | argtypes.clear(); |
| 366 | methods.push_back(new Cppyy_PseudoMethodInfo("real", argtypes, "double")); |
| 367 | s_methods["std::complex<double>::real"] = methods.back(); |
| 368 | |
| 369 | // double imag() |
| 370 | argtypes.clear(); |
| 371 | methods.push_back(new Cppyy_PseudoMethodInfo("imag", argtypes, "double")); |
| 372 | s_methods["std::complex<double>::imag"] = methods.back(); |
| 373 | |
| 374 | // complex<double>(double r, double i) |
| 375 | argtypes.clear(); |
| 376 | argtypes.push_back("double"); |
| 377 | argtypes.push_back("double"); |
| 378 | methods.push_back(new Cppyy_PseudoMethodInfo("complex<double>", argtypes, "constructor", kConstructor)); |
| 379 | s_methods["std::complex<double>::complex<double>_double_double"] = methods.back(); |
| 380 | |
| 381 | Cppyy_PseudoClassInfo info(methods, std::vector<Cppyy_PseudoDatambrInfo>()); |
| 382 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 383 | } |
| 384 | |
| 385 | { // class complex<int> -- |
| 386 | s_handles["icomplex_t"] = (cppyy_scope_t)++s_scope_id; |
| 387 | s_handles["std::complex<int>"] = s_handles["icomplex_t"]; |
| 388 | |
| 389 | std::vector<Cppyy_PseudoMethodInfo*> methods; |
| 390 | |
| 391 | std::vector<std::string> argtypes; |
| 392 | |
| 393 | // int real() |
| 394 | argtypes.clear(); |
| 395 | methods.push_back(new Cppyy_PseudoMethodInfo("real", argtypes, "int")); |
| 396 | s_methods["std::complex<int>::real"] = methods.back(); |
| 397 | |
| 398 | // int imag() |
| 399 | argtypes.clear(); |
| 400 | methods.push_back(new Cppyy_PseudoMethodInfo("imag", argtypes, "int")); |
| 401 | s_methods["std::complex<int>::imag"] = methods.back(); |
| 402 | |
| 403 | // complex<int>(int r, int i) |
| 404 | argtypes.clear(); |
| 405 | argtypes.push_back("int"); |
| 406 | argtypes.push_back("int"); |
| 407 | methods.push_back(new Cppyy_PseudoMethodInfo("complex<int>", argtypes, "constructor", kConstructor)); |
| 408 | s_methods["std::complex<int>::complex<int>_int_int"] = methods.back(); |
| 409 | |
| 410 | Cppyy_PseudoClassInfo info(methods, std::vector<Cppyy_PseudoDatambrInfo>()); |
| 411 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 412 | } |
| 413 | |
| 414 | { // class payload -- |
| 415 | s_handles["payload"] = (cppyy_scope_t)++s_scope_id; |
| 416 | |
| 417 | std::vector<Cppyy_PseudoMethodInfo*> methods; |
| 418 | |
| 419 | // payload(double d = 0.) |
| 420 | std::vector<std::string> argtypes; |
| 421 | argtypes.push_back("double"); |
| 422 | methods.push_back(new Cppyy_PseudoMethodInfo("payload", argtypes, "constructor", kConstructor)); |
| 423 | s_methods["payload::payload_double"] = methods.back(); |
| 424 | |
| 425 | // double getData() |
| 426 | argtypes.clear(); |
| 427 | methods.push_back(new Cppyy_PseudoMethodInfo("getData", argtypes, "double")); |
| 428 | s_methods["payload::getData"] = methods.back(); |
| 429 | |
| 430 | // void setData(double d) |
| 431 | argtypes.clear(); |
| 432 | argtypes.push_back("double"); |
| 433 | methods.push_back(new Cppyy_PseudoMethodInfo("setData", argtypes, "void")); |
| 434 | s_methods["payload::setData_double"] = methods.back(); |
| 435 | |
| 436 | Cppyy_PseudoClassInfo info(methods, std::vector<Cppyy_PseudoDatambrInfo>()); |
| 437 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 438 | } // -- class payload |
| 439 | |
| 440 | //==================================================================== |
| 441 | |
| 442 | { // class CppyyTestData -- |
| 443 | s_handles["CppyyTestData"] = (cppyy_scope_t)++s_scope_id; |
| 444 | |
| 445 | std::vector<Cppyy_PseudoMethodInfo*> methods; |
| 446 | |
| 447 | // CppyyTestData() |
| 448 | std::vector<std::string> argtypes; |
| 449 | methods.push_back(new Cppyy_PseudoMethodInfo("CppyyTestData", argtypes, "constructor", kConstructor)); |
| 450 | s_methods["CppyyTestData::CppyyTestData"] = methods.back(); |
| 451 | |
| 452 | methods.push_back(new Cppyy_PseudoMethodInfo("destroy_arrays", argtypes, "void")); |
| 453 | s_methods["CppyyTestData::destroy_arrays"] = methods.back(); |
| 454 | |
| 455 | std::vector<Cppyy_PseudoDatambrInfo> data; |
| 456 | PUBLIC_CPPYY_DATA2(bool, bool); |
| 457 | PUBLIC_CPPYY_DATA (char, char); |
| 458 | PUBLIC_CPPYY_DATA2(schar, signed char); |
| 459 | PUBLIC_CPPYY_DATA2(uchar, unsigned char); |
| 460 | PUBLIC_CPPYY_DATA (wchar, wchar_t); |
| 461 | PUBLIC_CPPYY_DATA (char16, char16_t); |
| 462 | PUBLIC_CPPYY_DATA (char32, char32_t); |
| 463 | PUBLIC_CPPYY_DATA (int8, int8_t); |
| 464 | PUBLIC_CPPYY_DATA (uint8, uint8_t); |
| 465 | PUBLIC_CPPYY_DATA3(short, short, h); |
| 466 | PUBLIC_CPPYY_DATA3(ushort, unsigned short, H); |
| 467 | PUBLIC_CPPYY_DATA3(int, int, i); |
| 468 | PUBLIC_CPPYY_DATA (const_int, const int); |
| 469 | PUBLIC_CPPYY_DATA3(uint, unsigned int, I); |
| 470 | PUBLIC_CPPYY_DATA3(long, long, l); |
| 471 | PUBLIC_CPPYY_DATA3(ulong, unsigned long, L); |
| 472 | PUBLIC_CPPYY_DATA (llong, long long); |
| 473 | PUBLIC_CPPYY_DATA (ullong, unsigned long long); |
| 474 | PUBLIC_CPPYY_DATA (long64, Long64_t); |
| 475 | PUBLIC_CPPYY_DATA (ulong64, ULong64_t); |
| 476 | PUBLIC_CPPYY_DATA3(float, float, f); |
| 477 | PUBLIC_CPPYY_DATA3(double, double, d); |
| 478 | PUBLIC_CPPYY_DATA (ldouble, long double); |
| 479 | PUBLIC_CPPYY_DATA (complex, complex_t); |
| 480 | PUBLIC_CPPYY_DATA (icomplex, icomplex_t); |
| 481 | PUBLIC_CPPYY_DATA (enum, CppyyTestData::EWhat); |
| 482 | PUBLIC_CPPYY_DATA (voidp, void*); |
| 483 | |
| 484 | PUBLIC_CPPYY_STATIC_DATA(char, char); |
| 485 | PUBLIC_CPPYY_STATIC_DATA(schar, signed char); |
| 486 | PUBLIC_CPPYY_STATIC_DATA(uchar, unsigned char); |
| 487 | PUBLIC_CPPYY_STATIC_DATA(wchar, wchar_t); |
| 488 | PUBLIC_CPPYY_STATIC_DATA(char16, char16_t); |
| 489 | PUBLIC_CPPYY_STATIC_DATA(char32, char32_t); |
| 490 | PUBLIC_CPPYY_STATIC_DATA(int8, int8_t); |
| 491 | PUBLIC_CPPYY_STATIC_DATA(uint8, uint8_t); |
| 492 | PUBLIC_CPPYY_STATIC_DATA(short, short); |
| 493 | PUBLIC_CPPYY_STATIC_DATA(ushort, unsigned short); |
| 494 | PUBLIC_CPPYY_STATIC_DATA(int, int); |
| 495 | PUBLIC_CPPYY_STATIC_DATA(uint, unsigned int); |
| 496 | PUBLIC_CPPYY_STATIC_DATA(long, long); |
| 497 | PUBLIC_CPPYY_STATIC_DATA(ulong, unsigned long); |
| 498 | PUBLIC_CPPYY_STATIC_DATA(llong, long long); |
| 499 | PUBLIC_CPPYY_STATIC_DATA(ullong, unsigned long long); |
| 500 | PUBLIC_CPPYY_STATIC_DATA(long64, Long64_t); |
| 501 | PUBLIC_CPPYY_STATIC_DATA(ulong64, ULong64_t); |
| 502 | PUBLIC_CPPYY_STATIC_DATA(float, float); |
| 503 | PUBLIC_CPPYY_STATIC_DATA(double, double); |
| 504 | PUBLIC_CPPYY_STATIC_DATA(ldouble, long double); |
| 505 | PUBLIC_CPPYY_STATIC_DATA(enum, CppyyTestData::EWhat); |
| 506 | PUBLIC_CPPYY_STATIC_DATA(voidp, void*); |
| 507 | |
| 508 | // default tester for long double |
| 509 | argtypes.clear(); |
| 510 | argtypes.push_back("long double"); |
| 511 | methods.push_back(new Cppyy_PseudoMethodInfo("get_ldouble_def", argtypes, "long double")); |
| 512 | methods.back()->m_argdefaults.push_back("aap_t(1)"); |
| 513 | s_methods["CppyyTestData::get_ldouble_def"] = methods.back(); |
| 514 | |
| 515 | // pretend enum values |
| 516 | data.push_back(Cppyy_PseudoDatambrInfo( |
| 517 | "kNothing", "CppyyTestData::EWhat", (ptrdiff_t)&Pseudo_kNothing, true)); |
| 518 | data.push_back(Cppyy_PseudoDatambrInfo( |
| 519 | "kSomething", "CppyyTestData::EWhat", (ptrdiff_t)&Pseudo_kSomething, true)); |
| 520 | data.push_back(Cppyy_PseudoDatambrInfo( |
| 521 | "kLots", "CppyyTestData::EWhat", (ptrdiff_t)&Pseudo_kLots, true)); |
| 522 | |
| 523 | Cppyy_PseudoClassInfo info(methods, data); |
| 524 | s_scopes[(cppyy_scope_t)s_scope_id] = info; |
| 525 | } // -- class CppyyTest_data |
| 526 | |
| 527 | //==================================================================== |
| 528 | |
| 529 | { // namespace pyzables -- |
| 530 | s_handles["pyzables"] = (cppyy_scope_t)++s_scope_id; |
| 531 | s_scopes[(cppyy_scope_t)s_scope_id] = Cppyy_PseudoClassInfo{}; |
| 532 | s_handles["pyzables::SomeDummy1"] = (cppyy_scope_t)++s_scope_id; |
| 533 | s_scopes[(cppyy_scope_t)s_scope_id] = Cppyy_PseudoClassInfo{}; |
| 534 | s_handles["pyzables::SomeDummy2"] = (cppyy_scope_t)++s_scope_id; |
| 535 | s_scopes[(cppyy_scope_t)s_scope_id] = Cppyy_PseudoClassInfo{}; |
| 536 | } // -- namespace pyzables |
| 537 | } |
| 538 | } _init; |
| 539 | |
| 540 | } // unnamed namespace |
| 541 | |
| 542 | |
| 543 | /* local helpers ---------------------------------------------------------- */ |
| 544 | static INLINE char* cppstring_to_cstring(const std::string& name) { |
| 545 | char* name_char = (char*)malloc(name.size() + 1); |
| 546 | strcpy(name_char, name.c_str()); |
| 547 | return name_char; |
| 548 | } |
| 549 | |
| 550 | |
| 551 | /* name to opaque C++ scope representation -------------------------------- */ |
| 552 | char* cppyy_resolve_name(const char* cppitem_name) { |
| 553 | if (strcmp(cppitem_name, "complex_t") == 0) |
| 554 | return cppstring_to_cstring("std::complex<double>"); |
| 555 | else if (strcmp(cppitem_name, "icomplex_t") == 0) |
| 556 | return cppstring_to_cstring("std::complex<int>"); |
| 557 | else if (cppyy_is_enum(cppitem_name)) |
| 558 | return cppstring_to_cstring("internal_enum_type_t"); |
| 559 | else if (strcmp(cppitem_name, "aap_t") == 0) |
| 560 | return cppstring_to_cstring("long double"); |
| 561 | return cppstring_to_cstring(cppitem_name); |
| 562 | } |
| 563 | |
| 564 | cppyy_scope_t cppyy_get_scope(const char* scope_name) { |
| 565 | return s_handles[scope_name]; // lookup failure will return 0 (== error) |
| 566 | } |
| 567 | |
| 568 | cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t /* obj */) { |
| 569 | return klass; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | /* memory management ------------------------------------------------------ */ |
| 574 | void cppyy_destruct(cppyy_type_t handle, cppyy_object_t self) { |
| 575 | if (handle == s_handles["example01"]) |
| 576 | delete (dummy::example01*)self; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | /* method/function dispatching -------------------------------------------- */ |
| 581 | void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 582 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 583 | if (idx == s_methods["static_example01::staticSetPayload_payload*_double"]) { |
| 584 | assert(!self && nargs == 2); |
| 585 | dummy::example01::staticSetPayload((dummy::payload*)(*(intptr_t*)&((CPPYY_G__value*)args)[0]), |
| 586 | ((CPPYY_G__value*)args)[1].obj.d); |
| 587 | } else if (idx == s_methods["static_example01::setCount_int"]) { |
| 588 | assert(!self && nargs == 1); |
| 589 | dummy::example01::setCount(((CPPYY_G__value*)args)[0].obj.in); |
| 590 | } else if (idx == s_methods["example01::setPayload_payload*"]) { |
| 591 | assert(self && nargs == 1); |
| 592 | ((dummy::example01*)self)->setPayload((dummy::payload*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 593 | } else if (idx == s_methods["CppyyTestData::destroy_arrays"]) { |
| 594 | assert(self && nargs == 0); |
| 595 | ((dummy::CppyyTestData*)self)->destroy_arrays(); |
| 596 | } else if (idx == s_methods["CppyyTestData::set_bool"]) { |
| 597 | assert(self && nargs == 1); |
| 598 | ((dummy::CppyyTestData*)self)->set_bool((bool)((CPPYY_G__value*)args)[0].obj.i); |
| 599 | } else if (idx == s_methods["CppyyTestData::set_char"]) { |
| 600 | assert(self && nargs == 1); |
| 601 | ((dummy::CppyyTestData*)self)->set_char(((CPPYY_G__value*)args)[0].obj.ch); |
| 602 | } else if (idx == s_methods["CppyyTestData::set_uchar"]) { |
| 603 | assert(self && nargs == 1); |
| 604 | ((dummy::CppyyTestData*)self)->set_uchar(((CPPYY_G__value*)args)[0].obj.uch); |
| 605 | } else if (idx == s_methods["CppyyTestData::set_wchar"]) { |
| 606 | assert(self && nargs == 1); |
| 607 | ((dummy::CppyyTestData*)self)->set_wchar(((CPPYY_G__value*)args)[0].obj.i); |
| 608 | } else if (idx == s_methods["CppyyTestData::set_char16"]) { |
| 609 | assert(self && nargs == 1); |
| 610 | ((dummy::CppyyTestData*)self)->set_char16(((CPPYY_G__value*)args)[0].obj.i); |
| 611 | } else if (idx == s_methods["CppyyTestData::set_char32"]) { |
| 612 | assert(self && nargs == 1); |
| 613 | ((dummy::CppyyTestData*)self)->set_char32(((CPPYY_G__value*)args)[0].obj.i); |
| 614 | } else if (idx == s_methods["CppyyTestData::set_int8"]) { |
| 615 | assert(self && nargs == 1); |
| 616 | ((dummy::CppyyTestData*)self)->set_int8(((CPPYY_G__value*)args)[0].obj.ch); |
| 617 | } else if (idx == s_methods["CppyyTestData::set_int8_cr"]) { |
| 618 | assert(self && nargs == 1); |
| 619 | ((dummy::CppyyTestData*)self)->set_int8_cr(*(int8_t*)&((CPPYY_G__value*)args)[0]); |
| 620 | } else if (idx == s_methods["CppyyTestData::set_uint8"]) { |
| 621 | assert(self && nargs == 1); |
| 622 | ((dummy::CppyyTestData*)self)->set_uint8(((CPPYY_G__value*)args)[0].obj.ch); |
| 623 | } else if (idx == s_methods["CppyyTestData::set_uint8_cr"]) { |
| 624 | assert(self && nargs == 1); |
| 625 | ((dummy::CppyyTestData*)self)->set_uint8_cr(*(uint8_t*)&((CPPYY_G__value*)args)[0]); |
| 626 | } else if (idx == s_methods["CppyyTestData::set_short"]) { |
| 627 | assert(self && nargs == 1); |
| 628 | ((dummy::CppyyTestData*)self)->set_short(((CPPYY_G__value*)args)[0].obj.sh); |
| 629 | } else if (idx == s_methods["CppyyTestData::set_short_cr"]) { |
| 630 | assert(self && nargs == 1); |
| 631 | ((dummy::CppyyTestData*)self)->set_short_cr(*(short*)&((CPPYY_G__value*)args)[0]); |
| 632 | } else if (idx == s_methods["CppyyTestData::set_ushort"]) { |
| 633 | assert(self && nargs == 1); |
| 634 | ((dummy::CppyyTestData*)self)->set_ushort(((CPPYY_G__value*)args)[0].obj.ush); |
| 635 | } else if (idx == s_methods["CppyyTestData::set_ushort_cr"]) { |
| 636 | assert(self && nargs == 1); |
| 637 | ((dummy::CppyyTestData*)self)->set_ushort_cr(*(unsigned short*)&((CPPYY_G__value*)args)[0]); |
| 638 | } else if (idx == s_methods["CppyyTestData::set_int"]) { |
| 639 | assert(self && nargs == 1); |
| 640 | ((dummy::CppyyTestData*)self)->set_int(((CPPYY_G__value*)args)[0].obj.in); |
| 641 | } else if (idx == s_methods["CppyyTestData::set_int_cr"]) { |
| 642 | assert(self && nargs == 1); |
| 643 | ((dummy::CppyyTestData*)self)->set_int_cr(*(int*)&((CPPYY_G__value*)args)[0]); |
| 644 | } else if (idx == s_methods["CppyyTestData::set_uint"]) { |
| 645 | assert(self && nargs == 1); |
| 646 | ((dummy::CppyyTestData*)self)->set_uint(((CPPYY_G__value*)args)[0].obj.uin); |
| 647 | } else if (idx == s_methods["CppyyTestData::set_uint_cr"]) { |
| 648 | assert(self && nargs == 1); |
| 649 | ((dummy::CppyyTestData*)self)->set_uint_cr(*(unsigned int*)&((CPPYY_G__value*)args)[0]); |
| 650 | } else if (idx == s_methods["CppyyTestData::set_long"]) { |
| 651 | assert(self && nargs == 1); |
| 652 | ((dummy::CppyyTestData*)self)->set_long(((CPPYY_G__value*)args)[0].obj.i); |
| 653 | } else if (idx == s_methods["CppyyTestData::set_long_cr"]) { |
| 654 | assert(self && nargs == 1); |
| 655 | ((dummy::CppyyTestData*)self)->set_long_cr(*(long*)&((CPPYY_G__value*)args)[0]); |
| 656 | } else if (idx == s_methods["CppyyTestData::set_ulong"]) { |
| 657 | assert(self && nargs == 1); |
| 658 | ((dummy::CppyyTestData*)self)->set_ulong(((CPPYY_G__value*)args)[0].obj.ulo); |
| 659 | } else if (idx == s_methods["CppyyTestData::set_ulong_cr"]) { |
| 660 | assert(self && nargs == 1); |
| 661 | ((dummy::CppyyTestData*)self)->set_ulong_cr(*(unsigned long*)&((CPPYY_G__value*)args)[0]); |
| 662 | } else if (idx == s_methods["CppyyTestData::set_llong"]) { |
| 663 | assert(self && nargs == 1); |
| 664 | ((dummy::CppyyTestData*)self)->set_llong(((CPPYY_G__value*)args)[0].obj.ll); |
| 665 | } else if (idx == s_methods["CppyyTestData::set_llong_cr"]) { |
| 666 | assert(self && nargs == 1); |
| 667 | ((dummy::CppyyTestData*)self)->set_llong_cr(*(long long*)&((CPPYY_G__value*)args)[0]); |
| 668 | } else if (idx == s_methods["CppyyTestData::set_ullong"]) { |
| 669 | assert(self && nargs == 1); |
| 670 | ((dummy::CppyyTestData*)self)->set_ullong(((CPPYY_G__value*)args)[0].obj.ull); |
| 671 | } else if (idx == s_methods["CppyyTestData::set_ullong_cr"]) { |
| 672 | assert(self && nargs == 1); |
| 673 | ((dummy::CppyyTestData*)self)->set_ullong_cr(*(unsigned long*)&((CPPYY_G__value*)args)[0]); |
| 674 | } else if (idx == s_methods["CppyyTestData::set_float"]) { |
| 675 | assert(self && nargs == 1); |
| 676 | ((dummy::CppyyTestData*)self)->set_float(((CPPYY_G__value*)args)[0].obj.fl); |
| 677 | } else if (idx == s_methods["CppyyTestData::set_float_cr"]) { |
| 678 | assert(self && nargs == 1); |
| 679 | ((dummy::CppyyTestData*)self)->set_float_cr(*(float*)&((CPPYY_G__value*)args)[0]); |
| 680 | } else if (idx == s_methods["CppyyTestData::set_double"]) { |
| 681 | assert(self && nargs == 1); |
| 682 | ((dummy::CppyyTestData*)self)->set_double(((CPPYY_G__value*)args)[0].obj.d); |
| 683 | } else if (idx == s_methods["CppyyTestData::set_double_cr"]) { |
| 684 | assert(self && nargs == 1); |
| 685 | ((dummy::CppyyTestData*)self)->set_double_cr(*(double*)&((CPPYY_G__value*)args)[0]); |
| 686 | } else if (idx == s_methods["CppyyTestData::set_ldouble"]) { |
| 687 | assert(self && nargs == 1); |
| 688 | ((dummy::CppyyTestData*)self)->set_ldouble(((CPPYY_G__value*)args)[0].obj.ld); |
| 689 | } else if (idx == s_methods["CppyyTestData::set_ldouble_cr"]) { |
| 690 | assert(self && nargs == 1); |
| 691 | ((dummy::CppyyTestData*)self)->set_ldouble_cr(*(long double*)&((CPPYY_G__value*)args)[0]); |
| 692 | } else { |
| 693 | assert(!"method unknown in cppyy_call_v"); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 698 | unsigned char result = 0; |
| 699 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 700 | if (idx == s_methods["CppyyTestData::get_bool"]) { |
| 701 | assert(self && nargs == 0); |
| 702 | result = (unsigned char)((dummy::CppyyTestData*)self)->get_bool(); |
| 703 | } else { |
| 704 | assert(!"method unknown in cppyy_call_b"); |
| 705 | } |
| 706 | return result; |
| 707 | } |
| 708 | |
| 709 | char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 710 | char result = 0; |
| 711 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 712 | if (idx == s_methods["CppyyTestData::get_char"]) { |
| 713 | assert(self && nargs == 0); |
| 714 | result = ((dummy::CppyyTestData*)self)->get_char(); |
| 715 | } else if (idx == s_methods["CppyyTestData::get_uchar"]) { |
| 716 | assert(self && nargs == 0); |
| 717 | result = (char)((dummy::CppyyTestData*)self)->get_uchar(); |
| 718 | } else if (idx == s_methods["CppyyTestData::get_int8"]) { |
| 719 | assert(self && nargs == 0); |
| 720 | result = (long)((dummy::CppyyTestData*)self)->get_int8(); |
| 721 | } else if (idx == s_methods["CppyyTestData::get_uint8"]) { |
| 722 | assert(self && nargs == 0); |
| 723 | result = (long)((dummy::CppyyTestData*)self)->get_uint8(); |
| 724 | } else { |
| 725 | assert(!"method unknown in cppyy_call_c"); |
| 726 | } |
| 727 | return result; |
| 728 | } |
| 729 | |
| 730 | short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 731 | short result = 0; |
| 732 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 733 | if (idx == s_methods["CppyyTestData::get_short"]) { |
| 734 | assert(self && nargs == 0); |
| 735 | result = ((dummy::CppyyTestData*)self)->get_short(); |
| 736 | } else if (idx == s_methods["CppyyTestData::get_ushort"]) { |
| 737 | assert(self && nargs == 0); |
| 738 | result = (short)((dummy::CppyyTestData*)self)->get_ushort(); |
| 739 | } else { |
| 740 | assert(!"method unknown in cppyy_call_h"); |
| 741 | } |
| 742 | return result; |
| 743 | } |
| 744 | |
| 745 | int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 746 | int result = 0; |
| 747 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 748 | if (idx == s_methods["TInterpreter::ProcessLine_cchar*"]) { |
| 749 | assert(self && nargs == 1); |
| 750 | result = ((dummy::TInterpreter*)self)->ProcessLine( |
| 751 | (const char*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 752 | } else if (idx == s_methods["static_example01::staticAddOneToInt_int"]) { |
| 753 | assert(!self && nargs == 1); |
| 754 | result = dummy::example01::staticAddOneToInt(((CPPYY_G__value*)args)[0].obj.in); |
| 755 | } else if (idx == s_methods["static_example01::staticAddOneToInt_int_int"]) { |
| 756 | assert(!self && nargs == 2); |
| 757 | result = dummy::example01::staticAddOneToInt( |
| 758 | ((CPPYY_G__value*)args)[0].obj.in, ((CPPYY_G__value*)args)[1].obj.in); |
| 759 | } else if (idx == s_methods["static_example01::staticAtoi_cchar*"]) { |
| 760 | assert(!self && nargs == 1); |
| 761 | result = dummy::example01::staticAtoi((const char*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 762 | } else if (idx == s_methods["static_example01::getCount"]) { |
| 763 | assert(!self && nargs == 0); |
| 764 | result = dummy::example01::getCount(); |
| 765 | } else if (idx == s_methods["example01::addDataToInt_int"]) { |
| 766 | assert(self && nargs == 1); |
| 767 | result = ((dummy::example01*)self)->addDataToInt(((CPPYY_G__value*)args)[0].obj.in); |
| 768 | } else if (idx == s_methods["example01::addDataToAtoi_cchar*"]) { |
| 769 | assert(self && nargs == 1); |
| 770 | result = ((dummy::example01*)self)->addDataToAtoi( |
| 771 | (const char*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 772 | } else if (idx == s_methods["CppyyTestData::get_int"]) { |
| 773 | assert(self && nargs == 0); |
| 774 | result = ((dummy::CppyyTestData*)self)->get_int(); |
| 775 | } else if (idx == s_methods["std::complex<int>::real"]) { |
| 776 | assert(self && nargs == 0); |
| 777 | result = ((std::complex<int>*)self)->real(); |
| 778 | } else if (idx == s_methods["std::complex<int>::imag"]) { |
| 779 | assert(self && nargs == 0); |
| 780 | result = ((std::complex<int>*)self)->imag(); |
| 781 | } else { |
| 782 | assert(!"method unknown in cppyy_call_i"); |
| 783 | } |
| 784 | return result; |
| 785 | } |
| 786 | |
| 787 | long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 788 | long result = 0; |
| 789 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 790 | if (idx == s_methods["CppyyTestData::get_wchar"]) { |
| 791 | assert(self && nargs == 0); |
| 792 | result = (long)((dummy::CppyyTestData*)self)->get_wchar(); |
| 793 | } else if (idx == s_methods["CppyyTestData::get_char16"]) { |
| 794 | assert(self && nargs == 0); |
| 795 | result = (long)((dummy::CppyyTestData*)self)->get_char16(); |
| 796 | } else if (idx == s_methods["CppyyTestData::get_char32"]) { |
| 797 | assert(self && nargs == 0); |
| 798 | result = (long)((dummy::CppyyTestData*)self)->get_char32(); |
| 799 | } else if (idx == s_methods["CppyyTestData::get_uint"]) { |
| 800 | assert(self && nargs == 0); |
| 801 | result = (long)((dummy::CppyyTestData*)self)->get_uint(); |
| 802 | } else if (idx == s_methods["CppyyTestData::get_long"]) { |
| 803 | assert(self && nargs == 0); |
| 804 | result = ((dummy::CppyyTestData*)self)->get_long(); |
| 805 | } else if (idx == s_methods["CppyyTestData::get_ulong"]) { |
| 806 | assert(self && nargs == 0); |
| 807 | result = (long)((dummy::CppyyTestData*)self)->get_ulong(); |
| 808 | } else { |
| 809 | assert(!"method unknown in cppyy_call_l"); |
| 810 | } |
| 811 | return result; |
| 812 | } |
| 813 | |
| 814 | long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 815 | long long result = 0; |
| 816 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 817 | if (idx == s_methods["CppyyTestData::get_llong"]) { |
| 818 | assert(self && nargs == 0); |
| 819 | result = ((dummy::CppyyTestData*)self)->get_llong(); |
| 820 | } else if (idx == s_methods["CppyyTestData::get_ullong"]) { |
| 821 | assert(self && nargs == 0); |
| 822 | result = (long long)((dummy::CppyyTestData*)self)->get_ullong(); |
| 823 | } else { |
| 824 | assert(!"method unknown in cppyy_call_ll"); |
| 825 | } |
| 826 | return result; |
| 827 | } |
| 828 | |
| 829 | float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 830 | float result = 0; |
| 831 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 832 | if (idx == s_methods["CppyyTestData::get_float"]) { |
| 833 | assert(self && nargs == 0); |
| 834 | result = ((dummy::CppyyTestData*)self)->get_float(); |
| 835 | } else { |
| 836 | assert(!"method unknown in cppyy_call_f"); |
| 837 | } |
| 838 | return result; |
| 839 | } |
| 840 | |
| 841 | double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 842 | double result = 0.; |
| 843 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 844 | if (idx == s_methods["static_example01::staticAddToDouble_double"]) { |
| 845 | assert(!self && nargs == 1); |
| 846 | result = dummy::example01::staticAddToDouble(((CPPYY_G__value*)args)[0].obj.d); |
| 847 | } else if (idx == s_methods["example01::addDataToDouble_double"]) { |
| 848 | assert(self && nargs == 1); |
| 849 | result = ((dummy::example01*)self)->addDataToDouble(((CPPYY_G__value*)args)[0].obj.d); |
| 850 | } else if (idx == s_methods["payload::getData"]) { |
| 851 | assert(self && nargs == 0); |
| 852 | result = ((dummy::payload*)self)->getData(); |
| 853 | } else if (idx == s_methods["CppyyTestData::get_double"]) { |
| 854 | assert(self && nargs == 0); |
| 855 | result = ((dummy::CppyyTestData*)self)->get_double(); |
| 856 | } else if (idx == s_methods["std::complex<double>::real"]) { |
| 857 | assert(self && nargs == 0); |
| 858 | result = ((std::complex<double>*)self)->real(); |
| 859 | } else if (idx == s_methods["std::complex<double>::imag"]) { |
| 860 | assert(self && nargs == 0); |
| 861 | result = ((std::complex<double>*)self)->imag(); |
| 862 | } else { |
| 863 | assert(!"method unknown in cppyy_call_d"); |
| 864 | } |
| 865 | return result; |
| 866 | } |
| 867 | |
| 868 | double cppyy_call_nld(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 869 | double result = 0.; |
| 870 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 871 | if (idx == s_methods["CppyyTestData::get_ldouble_def"]) { |
| 872 | if (nargs == 1) |
| 873 | result = (double)((dummy::CppyyTestData*)self)->get_ldouble_def( |
| 874 | ((CPPYY_G__value*)args)[0].obj.ld); |
| 875 | else { |
| 876 | assert(self && nargs == 0); |
| 877 | result = (double)((dummy::CppyyTestData*)self)->get_ldouble_def(); |
| 878 | } |
| 879 | } else if (idx == s_methods["CppyyTestData::get_ldouble"]) { |
| 880 | assert(self && nargs == 0); |
| 881 | result = (double)((dummy::CppyyTestData*)self)->get_ldouble(); |
| 882 | } else { |
| 883 | assert(!"method unknown in cppyy_call_nld"); |
| 884 | } |
| 885 | return result; |
| 886 | } |
| 887 | |
| 888 | #define DISPATCH_CALL_R_GET(tpname) \ |
| 889 | else if (idx == s_methods["CppyyTestData::get_"#tpname"_r"]) { \ |
| 890 | assert(self && nargs == 0); \ |
| 891 | result = (void*)&((dummy::CppyyTestData*)self)->get_##tpname##_r(); \ |
| 892 | } else if (idx == s_methods["CppyyTestData::get_"#tpname"_cr"]) { \ |
| 893 | assert(self && nargs == 0); \ |
| 894 | result = (void*)&((dummy::CppyyTestData*)self)->get_##tpname##_cr(); \ |
| 895 | } |
| 896 | |
| 897 | #define DISPATCH_CALL_R_GET2(tpname) \ |
| 898 | DISPATCH_CALL_R_GET(tpname) \ |
| 899 | else if (idx == s_methods["CppyyTestData::get_"#tpname"_array"]) { \ |
| 900 | assert(self && nargs == 0); \ |
| 901 | result = (void*)((dummy::CppyyTestData*)self)->get_##tpname##_array();\ |
| 902 | } else if (idx == s_methods["CppyyTestData::get_"#tpname"_array2"]) { \ |
| 903 | assert(self && nargs == 0); \ |
| 904 | result = (void*)((dummy::CppyyTestData*)self)->get_##tpname##_array2();\ |
| 905 | } |
| 906 | |
| 907 | #define DISPATCH_CALL_R_GET3(tpname, tpcode, type) \ |
| 908 | DISPATCH_CALL_R_GET2(tpname) \ |
| 909 | else if (idx == s_methods["CppyyTestData::pass_array_"#tpname]) { \ |
| 910 | assert(self && nargs == 1); \ |
| 911 | result = (void*)((dummy::CppyyTestData*)self)->pass_array( \ |
| 912 | (*(type**)&((CPPYY_G__value*)args)[0])); \ |
| 913 | } else if (idx == s_methods["CppyyTestData::pass_void_array_"#tpcode]) { \ |
| 914 | assert(self && nargs == 1); \ |
| 915 | result = (void*)((dummy::CppyyTestData*)self)->pass_void_array_##tpcode (\ |
| 916 | (*(type**)&((CPPYY_G__value*)args)[0])); \ |
| 917 | } |
| 918 | |
| 919 | void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { |
| 920 | void* result = nullptr; |
| 921 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 922 | if (idx == s_methods["static_example01::staticStrcpy_cchar*"]) { |
| 923 | assert(!self && nargs == 1); |
| 924 | result = (void*)dummy::example01::staticStrcpy( |
| 925 | (const char*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 926 | } else if (idx == s_methods["static_example01::staticCyclePayload_payload*_double"]) { |
| 927 | assert(!self && nargs == 2); |
| 928 | result = (void*)dummy::example01::staticCyclePayload( |
| 929 | (dummy::payload*)(*(intptr_t*)&((CPPYY_G__value*)args)[0]), |
| 930 | ((CPPYY_G__value*)args)[1].obj.d); |
| 931 | } else if (idx == s_methods["example01::addToStringValue_cchar*"]) { |
| 932 | assert(self && nargs == 1); |
| 933 | result = (void*)((dummy::example01*)self)->addToStringValue( |
| 934 | (const char*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 935 | } else if (idx == s_methods["example01::cyclePayload_payload*"]) { |
| 936 | assert(self && nargs == 1); |
| 937 | result = (void*)((dummy::example01*)self)->cyclePayload( |
| 938 | (dummy::payload*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 939 | } |
| 940 | DISPATCH_CALL_R_GET2(bool) |
| 941 | DISPATCH_CALL_R_GET (wchar) |
| 942 | DISPATCH_CALL_R_GET (int8) |
| 943 | DISPATCH_CALL_R_GET (uint8) |
| 944 | DISPATCH_CALL_R_GET3(short, h, short) |
| 945 | DISPATCH_CALL_R_GET3(ushort, H, unsigned short) |
| 946 | DISPATCH_CALL_R_GET3(int, i, int) |
| 947 | DISPATCH_CALL_R_GET3(uint, I, unsigned int) |
| 948 | DISPATCH_CALL_R_GET3(long, l, long) |
| 949 | DISPATCH_CALL_R_GET3(ulong, L, unsigned long) |
| 950 | DISPATCH_CALL_R_GET (llong) |
| 951 | DISPATCH_CALL_R_GET (ullong) |
| 952 | DISPATCH_CALL_R_GET (long64) |
| 953 | DISPATCH_CALL_R_GET (ulong64) |
| 954 | DISPATCH_CALL_R_GET3(float, f, float) |
| 955 | DISPATCH_CALL_R_GET3(double, d, double) |
| 956 | DISPATCH_CALL_R_GET (ldouble) |
| 957 | DISPATCH_CALL_R_GET (complex) |
| 958 | DISPATCH_CALL_R_GET (icomplex) |
| 959 | else { |
| 960 | assert(!"method unknown in cppyy_call_r"); |
| 961 | } |
| 962 | return result; |
| 963 | } |
| 964 | |
| 965 | char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void* args, size_t* /* length */) { |
| 966 | char* result = 0; |
| 967 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 968 | if (idx == s_methods["static_example01::staticStrcpy_cchar*"]) { |
| 969 | assert(!self && nargs == 1); |
| 970 | result = dummy::example01::staticStrcpy((const char*)(*(intptr_t*)&((CPPYY_G__value*)args)[0])); |
| 971 | } else { |
| 972 | assert(!"method unknown in cppyy_call_s"); |
| 973 | } |
| 974 | return result; |
| 975 | } |
| 976 | |
| 977 | cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t handle, int nargs, void* args) { |
| 978 | void* result = 0; |
| 979 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 980 | if (idx == s_methods["example01::example01"]) { |
| 981 | assert(nargs == 0); |
| 982 | result = new dummy::example01; |
| 983 | } else if (idx == s_methods["example01::example01_int"]) { |
| 984 | assert(nargs == 1); |
| 985 | result = new dummy::example01(((CPPYY_G__value*)args)[0].obj.in); |
| 986 | } else if (idx == s_methods["payload::payload_double"]) { |
| 987 | assert(nargs == 0 || nargs == 1); |
| 988 | if (nargs == 0) result = new dummy::payload; |
| 989 | else if (nargs == 1) result = new dummy::payload(((CPPYY_G__value*)args)[0].obj.d); |
| 990 | } else if (idx == s_methods["CppyyTestData::CppyyTestData"]) { |
| 991 | assert(nargs == 0); |
| 992 | result = new dummy::CppyyTestData; |
| 993 | } else if (idx == s_methods["std::complex<double>::complex<double>_double_double"]) { |
| 994 | assert(nargs == 2); |
| 995 | result = new std::complex<double>(((CPPYY_G__value*)args)[0].obj.d, ((CPPYY_G__value*)args)[1].obj.d); |
| 996 | } else if (idx == s_methods["std::complex<int>::complex<int>_int_int"]) { |
| 997 | assert(nargs == 2); |
| 998 | result = new std::complex<int>(((CPPYY_G__value*)args)[0].obj.i, ((CPPYY_G__value*)args)[1].obj.i); |
| 999 | } else { |
| 1000 | assert(!"method unknown in cppyy_constructor"); |
| 1001 | } |
| 1002 | return (cppyy_object_t)result; |
| 1003 | } |
| 1004 | |
| 1005 | cppyy_object_t cppyy_call_o( |
| 1006 | cppyy_method_t method, cppyy_object_t self, int nargs, void* args, cppyy_type_t result_type) { |
| 1007 | void* result = 0; |
| 1008 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 1009 | if (idx == s_methods["CppyyTestData::get_complex"]) { |
| 1010 | assert(self && nargs == 0); |
| 1011 | result = new std::complex<double>(((dummy::CppyyTestData*)self)->get_complex()); |
| 1012 | } else if (idx == s_methods["CppyyTestData::get_icomplex"]) { |
| 1013 | assert(self && nargs == 0); |
| 1014 | result = new std::complex<int>(((dummy::CppyyTestData*)self)->get_icomplex()); |
| 1015 | } |
| 1016 | return (cppyy_object_t)result; |
| 1017 | } |
| 1018 | |
| 1019 | cppyy_funcaddr_t cppyy_function_address(cppyy_method_t /* method */) { |
| 1020 | return (cppyy_funcaddr_t)0; |
| 1021 | } |
| 1022 | |
| 1023 | /* handling of function argument buffer ----------------------------------- */ |
| 1024 | void* cppyy_allocate_function_args(int nargs) { |
| 1025 | /* nargs parameters + one unsigned long for exception status output */ |
| 1026 | CPPYY_G__value* args = (CPPYY_G__value*)malloc(nargs*sizeof(CPPYY_G__value)+sizeof(unsigned long)); |
| 1027 | for (int i = 0; i < nargs; ++i) |
| 1028 | args[i].type = 'l'; |
| 1029 | return (void*)args; |
| 1030 | } |
| 1031 | |
| 1032 | |
| 1033 | /* handling of function argument buffer ----------------------------------- */ |
| 1034 | void cppyy_deallocate_function_args(void* args) { |
| 1035 | free(args); |
| 1036 | } |
| 1037 | |
| 1038 | size_t cppyy_function_arg_sizeof() { |
| 1039 | return sizeof(CPPYY_G__value); |
| 1040 | } |
| 1041 | |
| 1042 | size_t cppyy_function_arg_typeoffset() { |
| 1043 | return offsetof(CPPYY_G__value, type); |
| 1044 | } |
| 1045 | |
| 1046 | |
| 1047 | /* scope reflection information ------------------------------------------- */ |
| 1048 | int cppyy_is_namespace(cppyy_scope_t handle) { |
| 1049 | if (handle == s_handles[std::string("")] || |
| 1050 | handle == s_handles["std"] || |
| 1051 | handle == s_handles["pyzables"]) |
| 1052 | return 1; |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | int cppyy_is_template(const char* template_name) { |
| 1057 | if (strcmp(template_name, "std::complex") == 0) |
| 1058 | return 1; |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | int cppyy_is_abstract(cppyy_type_t /* type) */) { |
| 1063 | return 0; |
| 1064 | } |
| 1065 | |
| 1066 | int cppyy_is_enum(const char* type_name) { |
| 1067 | if (strcmp(type_name, "CppyyTestData::EWhat") == 0) |
| 1068 | return 1; |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | |
| 1073 | /* class reflection information ------------------------------------------- */ |
| 1074 | char* cppyy_final_name(cppyy_type_t handle) { |
| 1075 | for (Handles_t::iterator isp = s_handles.begin(); isp != s_handles.end(); ++isp) { |
| 1076 | if (isp->second == handle) |
| 1077 | return cppstring_to_cstring(isp->first); |
| 1078 | } |
| 1079 | return cppstring_to_cstring("<unknown>"); |
| 1080 | } |
| 1081 | |
| 1082 | char* cppyy_scoped_final_name(cppyy_type_t handle) { |
| 1083 | const std::string& rec_name = cppyy_final_name(handle); |
| 1084 | if (rec_name == "complex_t") |
| 1085 | return cppstring_to_cstring("std::complex<double>"); |
| 1086 | else if (rec_name == "icomplex_t") |
| 1087 | return cppstring_to_cstring("std::complex<int>"); |
| 1088 | return cppstring_to_cstring(rec_name); |
| 1089 | } |
| 1090 | |
| 1091 | int cppyy_has_complex_hierarchy(cppyy_type_t /* handle */) { |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | int cppyy_num_bases(cppyy_type_t /*handle*/) { |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | int cppyy_smartptr_info(const char* name, cppyy_type_t* raw, cppyy_method_t* deref) { |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | /* method/function reflection information --------------------------------- */ |
| 1105 | cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t idx) { |
| 1106 | if (s_scopes.find(handle) != s_scopes.end()) { |
| 1107 | return (cppyy_method_t)s_scopes[handle].m_methods[idx]; |
| 1108 | } |
| 1109 | assert(!"unknown class in cppyy_get_method"); |
| 1110 | return (cppyy_method_t)0; |
| 1111 | } |
| 1112 | |
| 1113 | int cppyy_num_methods(cppyy_scope_t handle) { |
| 1114 | return s_scopes[handle].m_methods.size(); |
| 1115 | } |
| 1116 | |
| 1117 | char* cppyy_method_name(cppyy_method_t method) { |
| 1118 | return cppstring_to_cstring(((Cppyy_PseudoMethodInfo*)method)->m_name); |
| 1119 | } |
| 1120 | |
| 1121 | char* cppyy_method_full_name(cppyy_method_t method) { |
| 1122 | return cppstring_to_cstring(((Cppyy_PseudoMethodInfo*)method)->m_name); |
| 1123 | } |
| 1124 | |
| 1125 | char* cppyy_method_result_type(cppyy_method_t method) { |
| 1126 | return cppstring_to_cstring(((Cppyy_PseudoMethodInfo*)method)->m_returntype); |
| 1127 | } |
| 1128 | |
| 1129 | int cppyy_method_num_args(cppyy_method_t method) { |
| 1130 | return ((Cppyy_PseudoMethodInfo*)method)->m_argtypes.size(); |
| 1131 | } |
| 1132 | |
| 1133 | int cppyy_method_req_args(cppyy_method_t method) { |
| 1134 | return cppyy_method_num_args(method)-((Cppyy_PseudoMethodInfo*)method)->m_argdefaults.size(); |
| 1135 | } |
| 1136 | |
| 1137 | char* cppyy_method_arg_type(cppyy_method_t method, int idx) { |
| 1138 | return cppstring_to_cstring(((Cppyy_PseudoMethodInfo*)method)->m_argtypes[idx]); |
| 1139 | } |
| 1140 | |
| 1141 | char* cppyy_method_arg_default(cppyy_method_t method, int idx) { |
| 1142 | if (idx < (int)((Cppyy_PseudoMethodInfo*)method)->m_argdefaults.size()) |
| 1143 | return cppstring_to_cstring(((Cppyy_PseudoMethodInfo*)method)->m_argdefaults[idx]); |
| 1144 | return cppstring_to_cstring(""); |
| 1145 | } |
| 1146 | |
| 1147 | char* cppyy_method_signature(cppyy_method_t method, int /* show_formalargs */) { |
| 1148 | Cppyy_PseudoMethodInfo* idx = (Cppyy_PseudoMethodInfo*)method; |
| 1149 | if (idx == s_methods["std::complex<double>::real"]) |
| 1150 | return cppstring_to_cstring("()"); |
| 1151 | else if (idx == s_methods["std::complex<double>::imag"]) |
| 1152 | return cppstring_to_cstring("()"); |
| 1153 | else if (idx == s_methods["std::complex<int>::real"]) |
| 1154 | return cppstring_to_cstring("()"); |
| 1155 | else if (idx == s_methods["std::complex<int>::imag"]) |
| 1156 | return cppstring_to_cstring("()"); |
| 1157 | return cppstring_to_cstring(""); |
| 1158 | } |
| 1159 | |
| 1160 | char* cppyy_method_prototype(cppyy_scope_t, cppyy_method_t, int /* show_formalargs */) { |
| 1161 | return cppstring_to_cstring(""); |
| 1162 | } |
| 1163 | |
| 1164 | int cppyy_get_num_templated_methods(cppyy_scope_t scope) { |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | int cppyy_exists_method_template(cppyy_scope_t scope, const char* name) { |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | int cppyy_method_is_template(cppyy_scope_t /* handle */, cppyy_index_t /* method_index */) { |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | cppyy_index_t cppyy_get_global_operator(cppyy_scope_t /* scope */, |
| 1177 | cppyy_scope_t /* lc */, cppyy_scope_t /* rc */, const char* /* op */) { |
| 1178 | return (cppyy_index_t)-1; |
| 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | /* method properties ----------------------------------------------------- */ |
| 1183 | int cppyy_is_publicmethod(cppyy_method_t) { |
| 1184 | return 1; |
| 1185 | } |
| 1186 | |
| 1187 | int cppyy_is_constructor(cppyy_method_t method) { |
| 1188 | if (method) |
| 1189 | return ((Cppyy_PseudoMethodInfo*)method)->m_type == kConstructor; |
| 1190 | assert(!"unknown class in cppyy_is_constructor"); |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | int cppyy_is_destructor(cppyy_method_t) { |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | int cppyy_is_staticmethod(cppyy_method_t method) { |
| 1199 | if (method) |
| 1200 | return ((Cppyy_PseudoMethodInfo*)method)->m_type == kStatic; |
| 1201 | assert(!"unknown class in cppyy_is_staticmethod"); |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | /* data member reflection information ------------------------------------- */ |
| 1207 | int cppyy_num_datamembers(cppyy_scope_t handle) { |
| 1208 | if (cppyy_is_namespace(handle)) |
| 1209 | return 0; |
| 1210 | return s_scopes[handle].m_datambrs.size(); |
| 1211 | } |
| 1212 | |
| 1213 | char* cppyy_datamember_name(cppyy_scope_t handle, int idatambr) { |
| 1214 | return cppstring_to_cstring(s_scopes[handle].m_datambrs[idatambr].m_name); |
| 1215 | } |
| 1216 | |
| 1217 | char* cppyy_datamember_type(cppyy_scope_t handle, int idatambr) { |
| 1218 | return cppstring_to_cstring(s_scopes[handle].m_datambrs[idatambr].m_type); |
| 1219 | } |
| 1220 | |
| 1221 | ptrdiff_t cppyy_datamember_offset(cppyy_scope_t handle, int idatambr) { |
| 1222 | return s_scopes[handle].m_datambrs[idatambr].m_offset; |
| 1223 | } |
| 1224 | |
| 1225 | int cppyy_datamember_index(cppyy_scope_t handle, const char* name) { |
| 1226 | if (handle == s_handles[std::string("")]) { |
| 1227 | if (strcmp(name, "N") == 0) return 0; |
| 1228 | if (strcmp(name, "gInterpreter") == 0) return 1; |
| 1229 | } |
| 1230 | |
| 1231 | return (int)-1; |
| 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | /* data member properties ------------------------------------------------ */ |
| 1236 | int cppyy_is_publicdata(cppyy_scope_t /* handle */, cppyy_index_t /* idatambr */) { |
| 1237 | return 1; |
| 1238 | } |
| 1239 | |
| 1240 | int cppyy_is_staticdata(cppyy_scope_t handle, cppyy_index_t idatambr) { |
| 1241 | return s_scopes[handle].m_datambrs[idatambr].m_isstatic; |
| 1242 | } |
| 1243 | |
| 1244 | int cppyy_is_const_data(cppyy_scope_t handle, cppyy_index_t idatambr) { |
| 1245 | if (s_scopes[handle].m_datambrs[idatambr].m_name == "m_const_int") |
| 1246 | return 1; |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | int cppyy_is_enum_data(cppyy_scope_t /* handle */, cppyy_index_t /* idatambr */) { |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | int cppyy_get_dimension_size( |
| 1255 | cppyy_scope_t /* scope */, cppyy_index_t /* idata */, int /* dimension */) { |
| 1256 | return -1; // no dimensions |
| 1257 | } |
| 1258 | |
| 1259 | |
| 1260 | /* misc helpers ----------------------------------------------------------- */ |
| 1261 | #if defined(_MSC_VER) |
| 1262 | long long cppyy_strtoll(const char* str) { |
| 1263 | return _strtoi64(str, NULL, 0); |
| 1264 | } |
| 1265 | |
| 1266 | extern "C" { |
| 1267 | unsigned long long cppyy_strtoull(const char* str) { |
| 1268 | return _strtoui64(str, NULL, 0); |
| 1269 | } |
| 1270 | } |
| 1271 | #else |
| 1272 | long long cppyy_strtoll(const char* str) { |
| 1273 | return strtoll(str, NULL, 0); |
| 1274 | } |
| 1275 | |
| 1276 | extern "C" { |
| 1277 | unsigned long long cppyy_strtoull(const char* str) { |
| 1278 | return strtoull(str, NULL, 0); |
| 1279 | } |
| 1280 | } |
| 1281 | #endif |
| 1282 | |
| 1283 | void cppyy_free(void* ptr) { |
| 1284 | free(ptr); |
| 1285 | } |
| 1286 | |
| 1287 | cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz) { |
| 1288 | return (cppyy_object_t)new std::string(str, sz); |
| 1289 | } |
| 1290 | |
| 1291 | const char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz) { |
| 1292 | *lsz = ((std::string*)ptr)->size(); |
| 1293 | return ((std::string*)ptr)->data(); |
| 1294 | } |
| 1295 | |
| 1296 | cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr) { |
| 1297 | return (cppyy_object_t)new std::string(*(std::string*)ptr); |
| 1298 | } |
| 1299 | |
| 1300 | double cppyy_longdouble2double(void* p) { |
| 1301 | return (double)*(long double*)p; |
| 1302 | } |
| 1303 | |
| 1304 | void cppyy_double2longdouble(double d, void* p) { |
| 1305 | *(long double*)p = d; |
| 1306 | } |
| 1307 | |
| 1308 | int cppyy_vectorbool_getitem(cppyy_object_t ptr, int idx) { |
| 1309 | return (int)(*(std::vector<bool>*)ptr)[idx]; |
| 1310 | } |
| 1311 | |
| 1312 | void cppyy_vectorbool_setitem(cppyy_object_t ptr, int idx, int value) { |
| 1313 | (*(std::vector<bool>*)ptr)[idx] = (bool)value; |
| 1314 | } |