Changeset a5e907 in git
- Timestamp:
- Aug 30, 2012, 11:20:14 PM (12 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'fc741b6502fd8a97288eaa3eba6e5220f3c3df87')
- Children:
- b8346741b9c72d735f018ce57120e6782a5d4d2d
- Parents:
- f8852177b833def200699ea2f50f0328ff40ce94
- git-author:
- Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-30 23:20:14+02:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-09-05 15:52:16+02:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/countedref.cc
rf88521 ra5e907 56 56 //} 57 57 58 /// Default constructor @note: exisis only if @c NeverNull is false 59 CountedRefPtr(): m_ptr(NULL) {} 60 58 61 /// Convert from pointer 59 62 CountedRefPtr(ptr_type ptr): m_ptr(ptr) { reclaim(); } … … 107 110 }; 108 111 112 /// Default constructor only implemented if @c NeverNull is false 113 //template <class PtrType, bool isWeak,bool val,class CountType> 114 //inline CountedRefPtr<PtrType, isWeak, val, CountType>::CountedRefPtr(): 115 // m_ptr(NULL) { } 109 116 110 117 /** @class RefCounter … … 163 170 return g_sh_id; 164 171 } 165 static int& idx_id() {166 static int g_sh_id = 0;167 return g_sh_id;168 }169 170 172 }; 171 173 … … 298 300 typedef RefCounter base; 299 301 302 /// Subscripted object 303 CountedRefData(idhdl handle, CountedRefPtr<self*> back): 304 base(), m_data(init(handle)), m_ring(back->Ring()), m_back(back) { } 305 300 306 public: 307 /// Construct shared memory empty Singular object 308 explicit CountedRefData(): 309 base(), m_data(), m_ring(), m_back() { } 310 301 311 /// Construct reference for Singular object 302 312 explicit CountedRefData(leftv data): 303 base(), m_data(data), m_ring(parent(data)) { }313 base(), m_data(data), m_ring(parent(data)), m_back() { } 304 314 305 315 CountedRefData(leftv data, BOOLEAN global, int): 306 base(), m_data(data, global,0), m_ring(parent(data)) { }316 base(), m_data(data, global,0), m_ring(parent(data)), m_back() { } 307 317 308 318 /// Construct deep copy 309 319 CountedRefData(const self& rhs): 310 base(), m_data(rhs.m_data), m_ring(rhs.m_ring) 320 base(), m_data(rhs.m_data), m_ring(rhs.m_ring), m_back() { } 311 321 312 322 /// Destruct 313 ~CountedRefData() { } 323 ~CountedRefData() { 324 if (m_back) CountedRefEnv::clearid((idhdl)m_data.access()->data, root()); 325 } 326 327 CountedRefPtr<self*> subscripted() { 328 return new self(CountedRefEnv::idify(m_data.access(), root()), this); 329 } 314 330 315 331 /// Replace data … … 339 355 BOOLEAN rering() { 340 356 if (m_ring ^ m_data->RingDependend()) m_ring = (m_ring? NULL: currRing); 341 return FALSE;357 return (m_back && m_back->rering()); 342 358 } 343 359 … … 362 378 363 379 BOOLEAN assign(leftv result, leftv arg) { 380 if (m_data->rtyp!=IDHDL) { 381 set(arg); 382 return FALSE; 383 } 364 384 return get(result) || iiAssign(result, arg) || rering(); 365 385 } 366 386 367 /// @note Enables write-access via identifier 368 idhdl idify() { return CountedRefEnv::idify(m_data.access(), root()); } 369 370 /// @note Only call, if @c idify had been called before! 371 void clearid() { CountedRefEnv::clearid((idhdl)m_data.access()->data, root()); } 387 /// @note If we have a callback, our identifier was temporary, so remove it 388 void clear() { 389 if (m_back) CountedRefEnv::clearid((idhdl)m_data.access()->data, root()); 390 } 372 391 373 392 BOOLEAN retrieve(leftv res) { … … 400 419 return (rhs->RingDependend()? currRing: NULL); 401 420 } 421 422 static leftv init(idhdl handle) { 423 assume(handle); 424 leftv res = (leftv)omAlloc0(sizeof(*res)); 425 res->data =(void*) handle; 426 res->rtyp = IDHDL; 427 return res; 428 } 429 402 430 protected: 403 431 /// Singular object … … 406 434 /// Store namespace for ring-dependent objects 407 435 CountedRefPtr<ring, true> m_ring; 436 437 /// Reference to actual object for indexed structures 438 CountedRefPtr<self*> m_back; 408 439 }; 409 440 … … 432 463 static BOOLEAN is_ref(leftv arg) { 433 464 int typ = arg->Typ(); 434 return ((typ==CountedRefEnv::ref_id()) ||(typ==CountedRefEnv::sh_id()) || 435 (typ==CountedRefEnv::idx_id()) ); 465 return ((typ==CountedRefEnv::ref_id()) ||(typ==CountedRefEnv::sh_id()) ); 436 466 // return ((typ > MAX_TOK) && 437 467 // (getBlackboxStuff(typ)->blackbox_Init == countedref_Init)); … … 464 494 return m_data->assign(result,arg); 465 495 } 466 496 BOOLEAN rering() { return m_data->rering(); } 467 497 /// Extract (shallow) copy of stored data 468 498 LeftvShallow operator*() { return m_data->operator*(); } 499 500 /// Construct reference data object marked by given identifier number 501 BOOLEAN outcast(leftv res, int typ) { 502 res->rtyp = typ; 503 return outcast(res); 504 } 469 505 470 506 /// Construct reference data object from … … 644 680 } 645 681 646 class CountedRefDataIndexed:647 public CountedRefData {648 typedef CountedRefData base;649 typedef CountedRefDataIndexed self;650 651 public:652 CountedRefDataIndexed(idhdl handle, CountedRefPtr<base*> back):653 base(init(handle)), m_back(back) {654 m_ring = back->Ring();655 }656 657 CountedRefDataIndexed(const self& rhs): base(rhs), m_back(rhs.m_back) { }658 659 ~CountedRefDataIndexed() { clearid();}660 661 BOOLEAN assign(leftv result, leftv arg) {662 return base::assign(result, arg) || m_back->rering();663 }664 665 private:666 static leftv init(idhdl handle) {667 assume(handle);668 leftv res = (leftv)omAlloc0(sizeof(*res));669 res->data =(void*) handle;670 res->rtyp = IDHDL;671 return res;672 }673 674 CountedRefPtr<CountedRefData*> m_back;675 };676 inline void CountedRefPtr_kill(CountedRefDataIndexed* data) { delete data; }677 678 679 682 680 683 /// blackbox support - ternary operations … … 688 691 689 692 690 691 693 /// blackbox support - destruction 692 694 void countedref_destroy(blackbox *b, void* ptr) … … 695 697 } 696 698 697 698 /// blackbox support - assign element699 BOOLEAN countedref_AssignIndexed(leftv result, leftv arg)700 {701 // Case: replace assignment behind reference702 if (result->Data() != NULL) {703 CountedRefPtr<CountedRefDataIndexed*> indexed =(CountedRefDataIndexed*)(result->Data());704 return CountedRef::resolve(arg) || indexed->assign(result, arg);705 }706 707 // Case: copy reference708 if (result->Typ() == arg->Typ())709 return CountedRef::cast(arg).outcast(result);710 711 Werror("Cannot generate subscripted shared from plain type. Use shared[i] or shared.attr");712 return TRUE;713 }714 715 716 /// blackbox support - destruction717 void countedref_destroyIndexed(blackbox *b, void* ptr)718 {719 if (ptr) {720 CountedRefPtr<CountedRefDataIndexed*> data =721 static_cast<CountedRefDataIndexed*>(ptr);722 data.release();723 }724 }725 699 726 700 class CountedRefShared: … … 730 704 731 705 CountedRefShared(const base& rhs): base(rhs) { } 706 CountedRefShared(data_type* rhs): base(rhs) { } 732 707 733 708 public: 709 CountedRefShared(): base(new data_type) { } 734 710 CountedRefShared(leftv arg): base(new data_type(arg, FALSE,0)) { } 735 711 … … 751 727 static self cast(void* arg) { return base::cast(arg); } 752 728 753 CountedRefPtr<CountedRefDataIndexed*> subscripted() { 754 return new CountedRefDataIndexed(m_data->idify(), m_data); 729 self subscripted() { 730 return self(m_data->subscripted());//new CountedRefDataIndexed(m_data->idify(), m_data); 731 } 732 733 BOOLEAN retrieve(leftv res, int typ) { 734 return (m_data->retrieve(res) && outcast(res, typ)); 755 735 } 756 736 }; … … 758 738 void* countedref_InitShared(blackbox*) 759 739 { 760 LeftvDeep empty; 761 return CountedRefShared(LeftvShallow(empty).operator->()).outcast(); 740 return CountedRefShared().outcast(); 762 741 } 763 742 … … 767 746 if ((op == '[') || (op == '.')) { 768 747 if (countedref_CheckInit(res, head)) return TRUE; 769 CountedRefPtr<CountedRefDataIndexed*> indexed = CountedRefShared::cast(head).subscripted(); 770 if(indexed->operator*().get(head)) return TRUE; 771 772 if (CountedRef::resolve(arg) || iiExprArith2(res, head, op, arg)) return 773 TRUE; 774 775 if(indexed->retrieve(res)) { 776 indexed.reclaim(); 777 res->rtyp = CountedRefEnv::idx_id(); 778 res->data = (void *)indexed; 779 } 780 return FALSE; 748 CountedRefShared indexed = CountedRefShared::cast(head).subscripted(); 749 750 int typ = head->Typ(); 751 return indexed.dereference(head) || CountedRef::resolve(arg) || 752 iiExprArith2(res, head, op, arg) || indexed.retrieve(res, typ); 781 753 } 782 754 … … 810 782 } 811 783 if (op == LIST_CMD){ 812 res->rtyp =op;784 res->rtyp = op; 813 785 return jjLIST_PL(res, args); 814 786 } … … 823 795 if ((result->Data() != NULL) && (CountedRefShared::cast(result).Typ() !=0 )) { 824 796 if (CountedRefShared::resolve(arg)) return TRUE; 825 CountedRefShared::cast(result) = arg;797 return CountedRefShared::cast(result).assign(result, arg); 826 798 return FALSE; 827 799 } … … 834 806 } 835 807 if(CountedRefShared::cast(result).Typ() == 0) { 836 CountedRefShared::cast(result) = arg; 808 // CountedRefShared::cast(result) = arg; 809 return CountedRefShared::cast(result).assign(result, arg); 810 837 811 return FALSE; 838 812 } … … 874 848 bbxshared->data = omAlloc0(newstruct_desc_size()); 875 849 CountedRefEnv::sh_id()=setBlackboxStuff(bbxshared, "shared"); 876 877 878 blackbox *bbxindexed =879 (blackbox*)memcpy(omAlloc(sizeof(blackbox)), bbx, sizeof(blackbox));880 bbxindexed->blackbox_destroy = countedref_destroyIndexed;881 bbxindexed->blackbox_Assign = countedref_AssignIndexed;882 bbxindexed->data = omAlloc0(newstruct_desc_size());883 CountedRefEnv::idx_id()=setBlackboxStuff(bbxindexed, "shared_subexpr");884 885 850 } 886 851
Note: See TracChangeset
for help on using the changeset viewer.