Changeset f88521 in git
- Timestamp:
- Aug 30, 2012, 4:13:11 PM (11 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- a5e907a16ec70a7bfd4c506efb3f1a7b48693387
- Parents:
- 2fbb4e014a0f3dda591b3df6f317ef27d9856de7
- git-author:
- Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-30 16:13:11+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
r2fbb4e0 rf88521 94 94 95 95 //{ @name Reference count interface 96 count_type count() const { return (*this? m_ptr->ref: 1); }96 count_type count() const { return (*this? m_ptr->ref: 0); } 97 97 void reclaim() { if (*this) ++m_ptr->ref; } 98 98 void release() { … … 284 284 return *this; 285 285 } 286 286 int Typ() const {return m_data->Typ(); } 287 287 leftv access() { return m_data; } 288 288 }; … … 381 381 382 382 CountedRefPtr<ring, true> Ring() { return m_ring; } 383 383 int Typ() const {return m_data->Typ(); } 384 384 private: 385 385 386 /// Raise error message and return @c TRUE 386 387 BOOLEAN complain(const char* text) const { … … 415 416 416 417 418 417 419 inline void CountedRefPtr_kill(CountedRefData* data) { delete data; } 418 420 … … 430 432 static BOOLEAN is_ref(leftv arg) { 431 433 int typ = arg->Typ(); 432 return ((typ > MAX_TOK) && 433 (getBlackboxStuff(typ)->blackbox_Init == countedref_Init)); 434 return ((typ==CountedRefEnv::ref_id()) ||(typ==CountedRefEnv::sh_id()) || 435 (typ==CountedRefEnv::idx_id()) ); 436 // return ((typ > MAX_TOK) && 437 // (getBlackboxStuff(typ)->blackbox_Init == countedref_Init)); 434 438 } 435 439 … … 465 469 466 470 /// Construct reference data object from 467 BOOLEAN outcast(leftv res ult) {468 if (res ult->rtyp == IDHDL)469 IDDATA((idhdl)res ult->data) = (char *)outcast();471 BOOLEAN outcast(leftv res) { 472 if (res->rtyp == IDHDL) 473 IDDATA((idhdl)res->data) = (char *)outcast(); 470 474 else 471 res ult->data = (void *)outcast();475 res->data = (void *)outcast(); 472 476 return FALSE; 473 477 } … … 518 522 BOOLEAN name(leftv res) { return construct(res, operator*()->Name()); } 519 523 524 /// Check whther argument is not defined yet 525 BOOLEAN undefined(leftv res) { return construct(res, operator*()->Typ() == NONE); } 526 520 527 /// Recover the actual object from raw Singular data 521 528 static self cast(void* data) { … … 536 543 return (arg->next != NULL) && resolve(arg->next); 537 544 } 538 545 int Typ() const {return m_data->Typ(); } 539 546 protected: 540 547 /// Construct integer value … … 612 619 return blackboxDefaultOp1(op, res, head); 613 620 621 614 622 if (countedref_CheckInit(res, head)) return TRUE; 615 616 if (op == head->Typ()) {617 res->rtyp = op;623 624 if ((op == DEF_CMD) || (op == head->Typ())) { 625 res->rtyp = head->Typ(); 618 626 return iiAssign(res, head); 619 627 } 620 628 621 if(op == DEF_CMD) {622 res->rtyp = DEF_CMD;629 if(op == LINK_CMD) { 630 res->rtyp = DEF_CMD; 623 631 return CountedRef::cast(head).dereference(head) || iiAssign(res, head); 624 632 } … … 748 756 }; 749 757 750 758 void* countedref_InitShared(blackbox*) 759 { 760 LeftvDeep empty; 761 return CountedRefShared(LeftvShallow(empty).operator->()).outcast(); 762 } 751 763 752 764 /// blackbox support - binary operations … … 793 805 if (strcmp(name, "name") == 0) return obj.name(res); 794 806 if (strncmp(name, "type", 4) == 0) return obj.type(res); 807 if (strncmp(name, "undef", 5) == 0) return obj.undefined(res); 795 808 } 796 809 return TRUE; 797 810 } 811 if (op == LIST_CMD){ 812 res->rtyp=op; 813 return jjLIST_PL(res, args); 814 } 815 798 816 return CountedRef::cast(args).dereference(args) || iiExprArithM(res, args, op); 799 817 } 818 800 819 /// blackbox support - assign element 801 820 BOOLEAN countedref_AssignShared(leftv result, leftv arg) 802 821 { 803 822 /// Case: replace assignment behind reference 804 if ((result->Data() ) != NULL) {823 if ((result->Data() != NULL) && (CountedRefShared::cast(result).Typ() !=0 )) { 805 824 if (CountedRefShared::resolve(arg)) return TRUE; 806 825 CountedRefShared::cast(result) = arg; … … 809 828 810 829 /// Case: new reference to already shared data 811 if (result->Typ() == arg->Typ()) 830 if (result->Typ() == arg->Typ()) { 831 if (result->Data() != NULL) 832 CountedRefShared::cast(result).destruct(); 812 833 return CountedRefShared::cast(arg).outcast(result); 813 834 } 835 if(CountedRefShared::cast(result).Typ() == 0) { 836 CountedRefShared::cast(result) = arg; 837 return FALSE; 838 } 839 814 840 /// Case: new shared data 815 841 return CountedRefShared(arg).outcast(result); … … 845 871 bbxshared->blackbox_destroy = countedref_destroyShared; 846 872 bbxshared->blackbox_Op2 = countedref_Op2Shared; 873 bbxshared->blackbox_Init = countedref_InitShared; 847 874 bbxshared->data = omAlloc0(newstruct_desc_size()); 848 875 CountedRefEnv::sh_id()=setBlackboxStuff(bbxshared, "shared"); 876 849 877 850 878 blackbox *bbxindexed =
Note: See TracChangeset
for help on using the changeset viewer.