Changeset 1986
- Timestamp:
- Jun 15, 2006, 2:13:49 AM (15 years ago)
- Location:
- to-imperative/trunk/runtime
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
to-imperative/trunk/runtime/rf_expr.hh
r1778 r1986 28 28 class Result; 29 29 30 class True; 31 30 32 using namespace rftype ; 33 34 using pxx::WString; 31 35 32 36 /// … … 204 208 /// whether a result expression was already constructed and delete it. 205 209 static inline void clear (Expr* _ptr) ; 210 /// 211 /// Try to get a reference to the object underlying the first term. 212 /// If the term has a type other then RF_SYMBOL(ObjClass) then throw 213 /// InvalidParam(). 214 template <class ObjClass> 215 inline ObjClass const& get_object () const ; 216 /// 217 /// Try to cast the first term to the concrete term type 218 /// (RF_SYMBOL(ObjClass)) and return a pointer to the underlying object. 219 /// If not success return null. 220 template <class ObjClass> 221 inline ObjClass* try_get_ptr () const ; 222 /// 223 /// If a type of the first term is RF_SYMBOL(ObjClass1) then convert the 224 /// underlying object to ObjClass2. 225 /// Else throw InvalidParam(). 226 template <class ObjClass1, class ObjClass2> 227 inline ObjClass2 convert_object() const ; 228 /// 229 /// Same as convert_object() but before converting check that Cond::check() 230 /// is true for the object. 231 template <class ObjClass1, class ObjClass2, class Cond> 232 inline ObjClass2 check_convert_object() const ; 206 233 207 234 template<class TermClass, typename CppType> … … 211 238 static inline Expr create_seq (CppType const* _array) ; 212 239 240 template<class ObjClass, typename CppType1> 241 static inline Expr create_terms (CppType1 const* _array) ; 242 243 template<class ObjClass, typename CppType1, typename CppType2> 244 static inline Expr create_terms (CppType1 const* _array, CppType2 const& _arg2) ; 245 213 246 template<class ObjClass> 214 247 static inline Expr create () ; 248 249 template<class ObjClass1, class ObjClass2> 250 inline Expr convert () const ; 251 252 template<class ObjClass1, class ObjClass2> 253 inline Expr (Expr const& _expr) ; 215 254 216 255 template<class ObjClass, class CppType1> … … 238 277 static inline Expr create_sym (const CppType1& _arg1, const CppType2& _arg2) ; 239 278 279 template <class ObjClass, class CppType1, class CppType2, class CppType3> 280 static inline Expr create_sym ( 281 const CppType1& _arg1, const CppType2& _arg2, const CppType3& _arg3) ; 282 240 283 template <class ObjClass> 241 284 static inline Expr create_static_sym (wchar_t const* _name) ; 285 286 template <class TypeCond, class ObjCond> 287 inline bool check () const ; 288 289 template <class TypeCond> 290 inline bool check_type () const ; 242 291 243 292 private: … … 321 370 /// Check whether we can copy another expression to the left from our 322 371 /// in the same memory block. 323 inline bool lt_alloc( uintptr_t _len ) const ; 324 372 inline bool lt_alloc (uintptr_t _len) const ; 373 374 protected: 375 376 /// 377 /// Set term at _p as a border. To use in case of expression construction 378 /// failure. 379 static inline void set_border (Term* _p) ; 325 380 326 381 public: 327 382 328 383 class TooLargeArgument : 329 public Exception384 public pxx::Exception 330 385 { 331 386 public: … … 333 388 { fprintf(stderr, "Argument too large for conversion\n"); } 334 389 }; 390 391 class InvalidParam : 392 public pxx::Exception 393 { 394 public: 395 void print() 396 { fprintf(stderr, "Invalid parameter\n"); } 397 }; 398 399 template <class C> 400 class Iterator 401 { 402 Term* curr; 403 Term* last; 404 public: 405 Iterator (Expr const& _expr) : 406 curr (_expr.get_first()), 407 last (_expr.get_last()) 408 {} 409 /// 410 inline Iterator& operator ++ () 411 { 412 curr++; 413 return self; 414 } 415 /// 416 inline Iterator& operator ++ (int) 417 { 418 return operator++(); 419 } 420 /// 421 inline operator bool () const 422 { 423 return curr < last; 424 } 425 }; 426 427 template <class TypeCond, class Conv, class Cond = True> 428 class Convert; 335 429 336 430 inline Expr const& operator , (Expr const& _expr) const ; … … 405 499 /// 406 500 /// A macro naming iterator for expression variable 407 #define iter(e) e##_iter501 #define RF_iter(e) e##_iter 408 502 /// 409 503 /// A macro splitting an expression variable 410 #define lsplit(e, minlen, le, re) \411 SplitIterator<d_lt> iter(e)(e, minlen); \412 Expr const& le = iter(e).get_left(); \413 Expr const& re = iter(e).get_right()504 #define RF_lsplit(e, minlen, le, re) \ 505 SplitIterator<d_lt> RF_iter(e)(e, minlen); \ 506 Expr const& le = RF_iter(e).get_left(); \ 507 Expr const& re = RF_iter(e).get_right() 414 508 415 #define rsplit(e, minlen, le, re) \416 SplitIterator<d_rt> iter(e)(e, minlen); \417 Expr const& le = iter(e).get_left(); \418 Expr const& re = iter(e).get_right()509 #define RF_rsplit(e, minlen, le, re) \ 510 SplitIterator<d_rt> RF_iter(e)(e, minlen); \ 511 Expr const& le = RF_iter(e).get_left(); \ 512 Expr const& re = RF_iter(e).get_right() 419 513 420 514 -
to-imperative/trunk/runtime/rf_expr.ih
r1772 r1986 17 17 #include "rf_object_ref.ih" 18 18 #include "rf_static_object.ih" 19 #include "rf_integer.ih"20 #include "rf_short_int.ih"21 19 #include "rf_common.ih" 22 20 #include "rf_expr_constr.hh" … … 463 461 } 464 462 463 template <class ObjClass> 464 inline ObjClass const& Expr::get_object () const 465 { 466 assert(get_len() > 0); 467 if (first->is_instance_of<ObjClass>()) 468 return first->get_object<ObjClass>(); 469 throw InvalidParam();; 470 } 471 472 template <class ObjClass> 473 inline ObjClass* Expr::try_get_ptr () const 474 { 475 assert(get_len() > 0); 476 if (first->is_instance_of<ObjClass>()) 477 return first->get_obj_ptr<ObjClass>(); 478 return null; 479 } 480 481 template <class ObjClass> 482 inline Expr Expr::create () 483 { 484 return CreateExpr0<ObjClass::term_class, ObjClass>(); 485 } 486 487 template <class ObjClass, class CppType1> 488 inline Expr Expr::create (const CppType1& _arg1) 489 { 490 return CreateExpr1<ObjClass::term_class, ObjClass, CppType1>(_arg1); 491 } 492 493 template <class ObjClass, class CppType1, class CppType2> 494 inline Expr Expr::create (const CppType1& _arg1, const CppType2& _arg2) 495 { 496 return CreateExpr2<ObjClass::term_class, ObjClass, CppType1, CppType2>( 497 _arg1, _arg2); 498 } 499 500 template <class ObjClass> 501 inline Expr Expr::create_sym () 502 { 503 Expr e(1); 504 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(); 505 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 506 return e; 507 } 508 509 template <class ObjClass> 510 inline Expr Expr::create_static_sym (wchar_t const* _name) 511 { 512 Expr e(1); 513 new (e.first) Symbol<NamedObject<ObjClass>, ObjectTerm>(_name); 514 e.set_flat_bit<ObjectTerm>(); 515 return e; 516 } 517 518 519 template <class ObjClass, class CppType1> 520 inline Expr Expr::create_sym (const CppType1& _arg1) 521 { 522 Expr e(1); 523 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1); 524 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 525 return e; 526 } 527 528 template <class ObjClass, class CppType1, class CppType2> 529 inline Expr Expr::create_sym (const CppType1& _arg1, const CppType2& _arg2) 530 { 531 Expr e(1); 532 new (e.first) 533 Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1, _arg2); 534 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 535 return e; 536 } 537 538 template <class ObjClass, class CppType1, class CppType2, class CppType3> 539 inline Expr Expr::create_sym ( 540 const CppType1& _arg1, const CppType2& _arg2, const CppType3& _arg3 541 ) 542 { 543 Expr e(1); 544 new (e.first) 545 Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1, _arg2, _arg3); 546 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 547 return e; 548 } 549 550 //! template<class ObjClass, typename CppType> 551 //! inline Expr Expr::create_seq (CppType const* _array, size_t _size) 552 //! { 553 //! Expr e(_size); 554 //! e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 555 //! Term* p = e.get_first(); 556 //! while (_size--) 557 //! new (p++) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(*_array++); 558 //! return e; 559 //! } 560 //! 561 //! template<class ObjClass, typename CppType> 562 //! inline Expr Expr::create_seq (CppType const* _array) 563 //! { 564 //! return 565 //! create_seq<ObjClass, CppType>( 566 //! _array, 567 //! Symbol<ObjClass, typename SymbolType<ObjClass>::Type>:: 568 //! compute_length(_array) 569 //! ); 570 //! } 571 465 572 template<class TermClass, typename CppType> 466 573 inline Expr Expr::create_seq (CppType const* _array, size_t _size) 467 { 574 { 468 575 Expr e(_size); 469 576 if (TermClass::is_flat()) e.flags |= FLAT_BIT; … … 476 583 template<class TermClass, typename CppType> 477 584 inline Expr Expr::create_seq (CppType const* _array) 478 { 585 { 479 586 return 480 587 create_seq<TermClass, CppType>(_array, TermClass::compute_length(_array)); 481 } 482 483 template <class ObjClass> 484 inline Expr Expr::create () 485 { 486 return CreateExpr0<ObjClass::term_class, ObjClass>(); 487 } 488 489 template <class ObjClass, class CppType1> 490 inline Expr Expr::create (const CppType1& _arg1) 491 { 492 return CreateExpr1<ObjClass::term_class, ObjClass, CppType1>(_arg1); 493 } 494 495 template <class ObjClass, class CppType1, class CppType2> 496 inline Expr Expr::create (const CppType1& _arg1, const CppType2& _arg2) 497 { 498 return CreateExpr2<ObjClass::term_class, ObjClass, CppType1, CppType2>( 499 _arg1, _arg2); 500 } 501 502 template <class ObjClass> 503 inline Expr Expr::create_sym () 504 { 505 Expr e(1); 506 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(); 588 } 589 590 template<class ObjClass, typename CppType1> 591 inline Expr Expr::create_terms (CppType1 const* _array) 592 { 593 Expr e(ObjClass::compute_length(_array)); 507 594 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 595 for (Term* p = e.get_first(); p < e.get_last(); p++) 596 { 597 new (p) 598 Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(&_array); 599 } 508 600 return e; 509 601 } 510 602 511 template <class ObjClass> 512 inline Expr Expr::create_static_sym (wchar_t const* _name) 513 { 514 Expr e(1); 515 new (e.first) Symbol<NamedObject<ObjClass>, ObjectTerm>(_name); 516 e.set_flat_bit<ObjectTerm>(); 603 template<class ObjClass, typename CppType1, typename CppType2> 604 inline Expr Expr::create_terms (CppType1 const* _array, CppType2 const& _arg2) 605 { 606 Expr e(ObjClass::compute_length(_array, _arg2)); 607 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 608 for (Term* p = e.get_first(); p < e.get_last(); p++) 609 { 610 new (p) 611 Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(&_array, _arg2); 612 } 517 613 return e; 518 614 } 519 615 520 521 template <class ObjClass, class CppType1> 522 inline Expr Expr::create_sym (const CppType1& _arg1) 523 { 524 Expr e(1); 525 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1); 526 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 616 template<class ObjClass1, class ObjClass2> 617 inline Expr Expr::convert () const 618 { 619 Expr e(get_len()); 620 e.set_flat_bit<typename SymbolType<ObjClass2>::Type>(); 621 Term* q = e.get_first(); 622 for (Term* p = get_first(); p < get_last(); p++, q++) { 623 new (q) 624 Symbol<ObjClass2, typename SymbolType<ObjClass2>::Type>( 625 Term::Convert<ObjClass1, ObjClass2>::convert(*p) 626 ); 627 } 527 628 return e; 528 629 } 529 630 530 template <class ObjClass, class CppType1, class CppType2> 531 inline Expr Expr::create_sym (const CppType1& _arg1, const CppType2& _arg2) 532 { 533 Expr e(1); 534 new (e.first) 535 Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1, _arg2); 536 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 537 return e; 631 template<class ObjClass1, class ObjClass2> 632 inline Expr::Expr (Expr const& _expr) 633 { 634 init(_expr.get_len(), 0); 635 set_flat_bit<typename SymbolType<ObjClass2>::Type>(); 636 Term* q = first; 637 for (Term* p = _expr.get_first(); p < _expr.get_last(); p++, q++) { 638 new (q) Symbol<ObjClass2, typename SymbolType<ObjClass2>::Type>( 639 p->get_object<ObjClass1>().convert<ObjClass2>()); 640 } 538 641 } 539 642 … … 956 1059 if (!write_wstr(_fp, ws)) return false; 957 1060 if (!f) fputc('\"', _fp); 958 } else if (p->get_type() == type_int32) {959 if (fprintf(_fp, "%" PRIdPTR, ((Int32 const&)(*p)).to_int()) == -1)960 return false;1061 // } else if (p->get_type() == type_int32) { 1062 // if (fprintf(_fp, "%" PRIdPTR, ((Int32 const&)(*p)).to_int()) == -1) 1063 // return false; 961 1064 } else { // if (p->get_type() == type_int) { 962 1065 // mpz_t* z = static_cast<Integer*>(p)->get_mpz_ptr(); … … 1005 1108 INLINE Expr::operator WString () const 1006 1109 { 1110 static const WString lp = L"("; 1111 static const WString rp = L")"; 1007 1112 WString res; 1008 1113 for (Term* p = first; p < last; p++) { 1009 1114 if (p->is_sym()) { 1010 res = res + (WString)(*p);1115 res = res + *p; 1011 1116 } 1012 1117 else { 1013 res = res + WString(L"(") + (WString)(Expr(p)) + WString(L")");1118 res = res + lp + Expr(p) + rp; 1014 1119 } 1015 1120 } -
to-imperative/trunk/runtime/rf_func.cc
r1778 r1986 26 26 } 27 27 Expr _v_subexpr__arg1 (_v_arg1, 1, (_v_arg1.get_len () - 1)); 28 lsplit (_v_subexpr__arg1, 0, _ve_code, _v_lsplit__arg1);29 for ( ; ; iter(_v_subexpr__arg1)++)28 RF_lsplit (_v_subexpr__arg1, 0, _ve_code, _v_lsplit__arg1); 29 for ( ; ; RF_iter(_v_subexpr__arg1)++) 30 30 { 31 31 { 32 if (! iter(_v_subexpr__arg1))32 if (!RF_iter(_v_subexpr__arg1)) 33 33 { 34 34 goto _block1__branch1; … … 46 46 } 47 47 Expr _ve_rest (_v_lsplit__arg1, 1, _v_len__rest); 48 lsplit (Conv_m_Table, 0, _ve__e__e_tmp_m_CppManglerf_m_131_m_20, _v_lsplit__Conv_m_Table);48 RF_lsplit (Conv_m_Table, 0, _ve__e__e_tmp_m_CppManglerf_m_131_m_20, _v_lsplit__Conv_m_Table); 49 49 (void)_ve__e__e_tmp_m_CppManglerf_m_131_m_20; 50 for ( ; ; iter(Conv_m_Table)++)50 for ( ; ; RF_iter(Conv_m_Table)++) 51 51 { 52 52 { 53 if (! iter(Conv_m_Table))53 if (!RF_iter(Conv_m_Table)) 54 54 { 55 55 RF_RETFAIL; -
to-imperative/trunk/runtime/rf_macros.hh
r1778 r1986 320 320 /*enum { type = c };*/ \ 321 321 typedef TermClass Type; \ 322 } ;322 } 323 323 324 324 #define RF_SYMBOL(CppType) Symbol<CppType, SymbolType< CppType >::Type> -
to-imperative/trunk/runtime/rf_symbol.hh
r1778 r1986 22 22 {}; 23 23 24 #if UINTPTR_MAX != UINT32_MAX 25 template<> 26 class CheckShortObjectSize<4> 27 {}; 28 #endif 29 30 template<> 31 class CheckShortObjectSize<2> 32 {}; 33 34 template<> 35 class CheckShortObjectSize<1> 36 {}; 37 38 24 39 //template<class C, term_class_t tc = object_term> 25 40 //class Symbol; … … 35 50 public: 36 51 37 inline Symbol (C _obj) ; 38 39 inline operator C () ; 40 41 static void ctor (Symbol* _to, Symbol const* _from) ; 42 static void dtor (Symbol* _term) ; 43 static bool eq (Symbol const* _term1, Symbol const* _term2) ; 44 static int compare (Symbol const* _term1, Symbol const* _term2) ; 45 static uint32_t hash (Symbol const* _term) ; 46 static pxx::WString to_string (Symbol const* _term) ; 47 48 static short_type_funcs_t funcs ; 49 static const TypeRegister reg ; 50 52 inline Symbol () ; 53 54 template<typename CppType1> 55 inline Symbol (CppType1 const& _arg1) ; 56 57 template<typename CppType1, typename CppType2> 58 inline Symbol (CppType1 const& _arg1, CppType2 const& _arg2) ; 59 60 template<typename CppType1, typename CppType2, typename CppType3> 61 inline Symbol ( 62 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3) ; 63 64 inline C const& get_object () const ; 65 66 static void ctor (Symbol* _to, Symbol const* _from) ; 67 static void dtor (Symbol* _term) ; 68 static bool eq (Symbol const* _term1, Symbol const* _term2) ; 69 static int compare (Symbol const* _term1, Symbol const* _term2) ; 70 static uint32_t hash (Symbol const* _term) ; 71 static pxx::WString to_string (Symbol const* _term) ; 72 static size_t get_name (Symbol const* _s, wchar_t const** _np) ; 73 74 static short_type_funcs_t funcs ; 75 static const TypeRegister reg ; 76 77 static inline unsigned get_type () ; 78 79 template<typename CppType> 80 static inline size_t compute_length (CppType const* _array) ; 51 81 }; 52 82 … … 100 130 101 131 template<typename CppType1> 102 inline Symbol (CppType1 _arg1) ; 103 104 template<typename CppType1, typename CppType2> 105 inline Symbol (CppType1 _arg1, CppType2 _arg2) ; 132 inline Symbol (CppType1 const& _arg1) ; 133 134 template<typename CppType1, typename CppType2> 135 inline Symbol (CppType1 const& _arg1, CppType2 const& _arg2) ; 136 137 template<typename CppType1, typename CppType2, typename CppType3> 138 inline Symbol ( 139 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3) ; 140 141 inline void replace_object () ; 142 143 template<typename CppType1> 144 inline void replace_object (CppType1 const& _arg1) ; 145 146 template<typename CppType1, typename CppType2> 147 inline void replace_object (CppType1 const& _arg1, CppType2 const& _arg2) ; 148 149 template<typename CppType1, typename CppType2, typename CppType3> 150 inline void replace_object ( 151 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3) ; 152 153 inline C const& get_object () const ; 106 154 107 155 inline C* get_obj_ptr () const ; … … 120 168 121 169 static inline unsigned get_type() ; 122 123 170 }; 124 171 … … 132 179 public: 133 180 pxx::WString name; 181 134 182 inline NamedObject (wchar_t const* _name) : C(), name(_name) {}; 183 184 template<typename CppType1> 185 inline NamedObject (wchar_t const* _name, CppType1 _arg1) : 186 C(_arg1), name(_name) 187 {}; 135 188 }; 136 189 … … 159 212 inline Symbol (CppType1 _arg1, CppType2 _arg2) ; 160 213 214 inline NamedObject<C> const& get_object () const ; 215 161 216 inline NamedObject<C>* get_obj_ptr () const ; 162 217 -
to-imperative/trunk/runtime/rf_symbol.ih
r1778 r1986 16 16 17 17 template <class C> 18 inline Symbol<C, FlatTerm>::Symbol (C _obj) : 19 Term (reg.get_type()) 20 { 21 uint_data2 = *reinterpret_cast<uintptr_t*>(&_obj); 22 } 23 24 /* 25 template <class C, term_class_t tc> 26 inline ShortObject<C, tc>::operator C () 27 { 28 return *reinterpret_cast<C*>(&uint_data2); 29 } 30 */ 18 inline Symbol<C, FlatTerm>::Symbol () : 19 Term (get_type()) 20 { 21 new (&ptr_data2) C(); 22 } 23 24 template <class C> 25 template <typename CppType1> 26 inline Symbol<C, FlatTerm>::Symbol (CppType1 const& _arg1) : 27 Term (get_type()) 28 { 29 new (&ptr_data2) C(_arg1); 30 } 31 32 template <class C> 33 template <typename CppType1, typename CppType2> 34 inline Symbol<C, FlatTerm>::Symbol ( 35 CppType1 const& _arg1, CppType2 const& _arg2 36 ) : 37 Term (get_type()) 38 { 39 new (&ptr_data2) C(_arg1, _arg2); 40 } 41 42 template <class C> 43 template <typename CppType1, typename CppType2, typename CppType3> 44 inline Symbol<C, FlatTerm>::Symbol ( 45 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3 46 ) : 47 Term (get_type()) 48 { 49 new (&ptr_data2) C(_arg1, _arg2, _arg3); 50 } 51 52 template <class C> 53 inline C const& Symbol<C, FlatTerm>::get_object () const 54 { 55 return *reinterpret_cast<C const*>(&int_data2); 56 } 57 58 template <class C> 59 void Symbol<C, FlatTerm>::ctor ( 60 Symbol<C, FlatTerm>* _to, Symbol<C, FlatTerm> const* _from 61 ) 62 { 63 _to->data1 = _from->data1; 64 _to->int_data2 = _from->int_data2; 65 } 66 67 template <class C> 68 void Symbol<C, FlatTerm>::dtor (Symbol<C, FlatTerm>*) 69 {} 70 71 template <class C> 72 bool Symbol<C, FlatTerm>::eq ( 73 Symbol<C, FlatTerm> const* _s1, Symbol<C, FlatTerm> const* _s2 74 ) 75 { 76 return _s1->int_data2 == _s2->int_data2; 77 } 78 79 template <class C> 80 int Symbol<C, FlatTerm>::compare ( 81 Symbol<C, FlatTerm> const* _s1, Symbol<C, FlatTerm> const* _s2 82 ) 83 { 84 if (_s1->int_data2 > _s2->int_data2) return 1; 85 if (_s1->int_data2 < _s2->int_data2) return -1; 86 return 0; 87 } 88 89 template <class C> 90 WString Symbol<C, FlatTerm>::to_string ( 91 Symbol<C, FlatTerm> const* _s 92 ) 93 { 94 wchar_t s[2]; 95 s[0] = _s->int_data2; 96 s[1] = '\0'; 97 return WString(s, 1); 98 } 99 100 template <class C> 101 size_t Symbol<C, FlatTerm>::get_name ( 102 Symbol<C, FlatTerm> const*, wchar_t const** 103 ) 104 { 105 return (size_t)-1; 106 } 107 108 template <class C> 109 short_type_funcs_t Symbol<C, FlatTerm>::funcs = { 110 0, 111 (void (*)(Term*, Term const*)) (Symbol<C, FlatTerm>::ctor), 112 (void (*)(Term*)) (Symbol<C, FlatTerm>::dtor), 113 (bool (*)(Term const*, Term const*)) (Symbol<C, FlatTerm>::eq), 114 (int (*)(Term const*, Term const*)) (Symbol<C, FlatTerm>::compare), 115 null, // (uint32_t (*)(Term const*)) (Symbol<C, FlatTerm>::hash), 116 (pxx::WString (*)(Term const*)) (Symbol<C, FlatTerm>::to_string), 117 (size_t (*)(Term const*, wchar_t const**)) (Symbol<C, FlatTerm>::get_name) 118 }; 119 120 template <class C> 121 inline unsigned Symbol<C, FlatTerm>::get_type () 122 { 123 return reg.get_type(); 124 } 125 126 template <class C> 127 template <typename CppType> 128 inline size_t Symbol<C, FlatTerm>::compute_length (CppType const* _array) 129 { 130 size_t len = 0; 131 while (*_array++) len++; 132 return len; 133 } 31 134 32 135 … … 126 229 template <class C> 127 230 template <typename CppType1> 128 inline Symbol<C, ObjectTerm>::Symbol (CppType1 _arg1) :231 inline Symbol<C, ObjectTerm>::Symbol (CppType1 const& _arg1) : 129 232 Term (reg.get_type()) 130 233 { … … 137 240 template <class C> 138 241 template <typename CppType1, typename CppType2> 139 inline Symbol<C, ObjectTerm>::Symbol (CppType1 _arg1, CppType2 _arg2) : 242 inline Symbol<C, ObjectTerm>::Symbol ( 243 CppType1 const& _arg1, CppType2 const& _arg2 244 ) : 140 245 Term (reg.get_type()) 141 246 { … … 144 249 w->ref_count = 1; 145 250 ptr_data2 = w; 251 } 252 253 template <class C> 254 template <typename CppType1, typename CppType2, typename CppType3> 255 inline Symbol<C, ObjectTerm>::Symbol ( 256 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3 257 ) : 258 Term (reg.get_type()) 259 { 260 Wrapper* w = static_cast<Wrapper*>(allocator->allocate(sizeof(Wrapper))); 261 new (&(w->object)) C(_arg1, _arg2, _arg3); 262 w->ref_count = 1; 263 ptr_data2 = w; 264 } 265 266 template <class C> 267 inline void Symbol<C, ObjectTerm>::replace_object () 268 { 269 C* p = get_obj_ptr(); 270 p->~C(); 271 new (p) C(); 272 } 273 274 template <class C> 275 template<typename CppType1> 276 inline void Symbol<C, ObjectTerm>::replace_object (CppType1 const& _arg1) 277 { 278 C* p = get_obj_ptr(); 279 p->~C(); 280 new (p) C(_arg1); 281 } 282 283 template <class C> 284 template<typename CppType1, typename CppType2> 285 inline void Symbol<C, ObjectTerm>::replace_object ( 286 CppType1 const& _arg1, CppType2 const& _arg2 287 ) 288 { 289 C* p = get_obj_ptr(); 290 p->~C(); 291 new (p) C(_arg1, _arg2); 292 } 293 294 template <class C> 295 template<typename CppType1, typename CppType2, typename CppType3> 296 inline void Symbol<C, ObjectTerm>::replace_object ( 297 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3 298 ) 299 { 300 C* p = get_obj_ptr(); 301 p->~C(); 302 new (p) C(_arg1, _arg2, _arg3); 303 } 304 305 template <class C> 306 inline C const& Symbol<C, ObjectTerm>::get_object () const 307 { 308 return static_cast<Wrapper*>(ptr_data2)->object; 146 309 } 147 310 … … 250 413 251 414 template <class C> 415 inline NamedObject<C> const& 416 Symbol<NamedObject<C>, ObjectTerm>::get_object () const 417 { 418 return static_cast<Wrapper*>(ptr_data2)->object; 419 } 420 421 template <class C> 252 422 inline NamedObject<C>* Symbol<NamedObject<C>, ObjectTerm>::get_obj_ptr () const 253 423 { -
to-imperative/trunk/runtime/rf_term.hh
r1885 r1986 21 21 namespace rfrt 22 22 { 23 24 template <class C1, class C2> 25 class OR; 23 26 24 27 // … … 160 163 template <class C> 161 164 inline C* cast_to () ; 162 165 /// 166 /// Get a reference to underlying object. The object must have type C. 167 template <class C> 168 inline C const& get_object () const ; 169 /// 170 /// Get a pointer to underlying object for changing it. The object must have 171 /// type C and the term must be changable (i.e. to be reference term). 163 172 template <class C> 164 173 inline C* get_obj_ptr () const ; 165 174 /// 175 /// Check that underlying object has type C. 166 176 template <class C> 167 177 inline bool is_instance_of () const ; 168 178 /// 179 /// Check that underlying object satisfies the TypeCond::check() condition. 180 template <class TypeCond> 181 inline bool check_type () const ; 182 /// 183 /// Destruct underlying object, then construct a new one in its place. The 184 /// object must have type C and the term must be changable (i.e. to be 185 /// reference term). Old object is destroyed at first, so it can't be used 186 /// in construction of a new one. 187 template <class ObjClass> 188 inline void replace_object () ; 189 190 template <class ObjClass, class CppType1> 191 inline void replace_object (CppType1 const& _arg1) ; 192 193 template <class ObjClass, class CppType1, class CppType2> 194 inline void replace_object (CppType1 const& _arg1, CppType2 const& _arg2) ; 195 196 template <class ObjClass, class CppType1, class CppType2, class CppType3> 197 inline void replace_object ( 198 CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3) ; 199 169 200 inline operator pxx::WString () const ; 170 201 /// … … 178 209 ) ; 179 210 211 template <class C1, class C2> 212 class Convert 213 { 214 public: 215 static C2 convert (C1 const& _obj) 216 { 217 return _obj; 218 } 219 }; 220 221 template <class C1, class C2> 222 class ConvertObject 223 { 224 public: 225 static bool convert (Term const& _t, C2* _p) 226 { 227 if (!_t.is_instance_of<C1>()) 228 return false; 229 *_p = Convert<C1, C2>::convert(_t.get_object<C1>()); 230 return true; 231 } 232 }; 233 234 template <class C11, class C12, class C2> 235 class ConvertObject<OR<C11, C12>, C2> 236 { 237 public: 238 static bool convert (Term const& _t, C2* _p) 239 { 240 if (ConvertObject<C11, C2>::convert(_t, _p)) 241 return true; 242 return ConvertObject<C12, C2>::convert(_t, _p); 243 } 244 }; 245 246 template <class C1, class C2, class Cond> 247 class CheckConvert 248 { 249 public: 250 static int convert (Term const& _t, C2* _p) 251 { 252 if (!_t.is_instance_of<C1>()) 253 return -1; 254 C1 obj = _t.get_object<C1>(); 255 if (!Cond::check(obj)) 256 return 0; 257 *_p = Convert<C1, C2>::convert(obj); 258 return 1; 259 } 260 }; 261 262 template <class C11, class C12, class C2, class Cond> 263 class CheckConvert<OR<C11, C12>, C2, Cond> 264 { 265 public: 266 static int convert (Term const& _t, C2* _p) 267 { 268 int c = CheckConvert<C11, C2, Cond>::convert(_t, _p); 269 if (c == -1) 270 return CheckConvert<C12, C2, Cond>::convert(_t, _p); 271 return c; 272 } 273 }; 274 180 275 #if defined(RF_STORE_CHUNK_ORDER_IN_TERM) 181 276 inline unsigned get_order () const -
to-imperative/trunk/runtime/rf_term.ih
r1778 r1986 182 182 183 183 template <class C> 184 inline C const& Term::get_object () const 185 { 186 assert(is_instance_of<C>()); 187 return 188 static_cast<Symbol<C, typename SymbolType<C>::Type> const*>(this)-> 189 get_object(); 190 } 191 192 template <class C> 184 193 inline C* Term::get_obj_ptr () const 185 194 { 195 assert(is_instance_of<C>()); 186 196 return 187 197 static_cast<Symbol<C, typename SymbolType<C>::Type> const*>(this)->
Note: See TracChangeset
for help on using the changeset viewer.