Changeset b83467 in git


Ignore:
Timestamp:
Aug 31, 2012, 12:50:14 AM (10 years ago)
Author:
Alexander Dreyer <alexander.dreyer@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'ad2543eab51733612ba7d118afc77edca719600e')
Children:
2cdc84e758384927d435934f4ed945fbbdf5cedf
Parents:
a5e907a16ec70a7bfd4c506efb3f1a7b48693387
git-author:
Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-31 00:50:14+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-09-05 15:52:16+02:00
Message:
Nested subexpressions via shared
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/countedref.cc

    ra5e907 rb83467  
    202202
    203203
    204   BOOLEAN get(leftv result) {
    205     leftv next = result->next;
    206     result->next = NULL;
    207     result->CleanUp();
    208 
    209     copy(result, m_data);
    210     result->next = next;
    211     return FALSE;
    212   }
    213204
    214205  /// Access to object
     
    249240
    250241class LeftvDeep:
    251   public LeftvShallow {
     242  protected LeftvShallow {
    252243  typedef LeftvDeep self;
    253244  typedef LeftvShallow base;
    254245
     246  self& operator=(const self&);
    255247public:
    256248  LeftvDeep(): base() {}
    257   LeftvDeep(leftv data): base(data) {
    258     if(m_data->rtyp != IDHDL) {
    259       m_data->data = data->CopyD();
    260     }
    261   }
     249  LeftvDeep(leftv data): base(data) {  if(!isid()) m_data->data=data->CopyD(); }
    262250
    263251  LeftvDeep(leftv data,int,int): base() {  m_data->Copy(data);  }
     
    269257
    270258  ~LeftvDeep() { m_data->CleanUp(); }
    271 
    272   self& operator=(const self& rhs) { return operator=(rhs.m_data); }
     259  operator const base&() { return static_cast<const base&>(*this); }
     260
     261  bool like(const self& rhs) const { return m_data->data == rhs.m_data->data; }
     262
    273263  self& operator=(leftv rhs) {
    274     m_data->e = rhs->e;
    275     rhs->e=NULL;
    276     if(m_data->rtyp == IDHDL) {
     264    if(isid()) {
     265      m_data->e = rhs->e;
     266      rhs->e = NULL;
    277267      IDTYP((idhdl)m_data->data) =  rhs->Typ();
    278268      IDDATA((idhdl)m_data->data) = (char*) rhs->CopyD();
     
    280270    else {
    281271      m_data->CleanUp();
    282       m_data->rtyp = rhs->Typ();
    283       m_data->data =  rhs->CopyD();
     272      m_data->Copy(rhs);
    284273    }
    285 
    286274    return *this;
    287275  }
    288   int Typ() const {return m_data->Typ(); }
    289    leftv access() { return m_data; }
     276
     277  leftv access() { return m_data; }
     278
     279
     280  /// Check a given context for our identifier
     281  BOOLEAN brokenid(idhdl context) const {
     282    assume(isid());
     283    return (context == NULL) ||
     284      ((context != (idhdl) m_data->data) && brokenid(IDNEXT(context)));
     285  }
     286  BOOLEAN get(leftv result) {
     287    leftv next = result->next;
     288    result->next = NULL;
     289    result->CleanUp();
     290
     291    copy(result, m_data);
     292    result->next = next;
     293    return FALSE;
     294  }
     295
     296  BOOLEAN isid() const { return m_data->rtyp==IDHDL;}
     297  BOOLEAN ringed() { return m_data->RingDependend(); }
     298  BOOLEAN unassigned() const { return m_data->Typ()==0; }
    290299};
    291300
     
    301310
    302311  /// Subscripted object
    303   CountedRefData(idhdl handle, CountedRefPtr<self*> back):
    304     base(), m_data(init(handle)), m_ring(back->Ring()), m_back(back) { }
    305 
     312  CountedRefData(leftv wrapped, CountedRefPtr<self*> back):
     313    base(), m_data(wrapped), m_ring(back->m_ring), m_back(back) {
     314
     315    assume(wrapped->rtyp == IDHDL);
     316    ++((idhdl)m_data.access()->data)->ref;
     317  }
     318
     319  /// Disallow assignment
     320  self& operator=(const self&);
    306321public:
    307322  /// Construct shared memory empty Singular object
     
    322337  /// Destruct
    323338  ~CountedRefData() {
    324     if (m_back) CountedRefEnv::clearid((idhdl)m_data.access()->data, root());
    325    }
     339    if (m_back && (--((idhdl)m_data.access()->data)->ref <= 0))  // clear only if we own
     340      CountedRefEnv::clearid((idhdl)m_data.access()->data, root());     
     341  }
    326342
    327343  CountedRefPtr<self*> subscripted() {
    328     return new self(CountedRefEnv::idify(m_data.access(), root()), this);
    329   }
    330 
    331   /// Replace data
    332   self& operator=(const self& rhs) {
    333     m_data = rhs.m_data;
    334     m_ring = rhs.m_ring;
     344    if (m_back)
     345      return new self(operator*().operator->(), m_back);
     346
     347    return new self(init(CountedRefEnv::idify(m_data.access(), root())), this);
     348  }
     349
     350  /// Replace with other Singular data
     351  self& operator=(leftv rhs) {
     352    m_data = rhs;
     353    m_ring = parent(rhs);
    335354    return *this;
    336   }
    337 
    338   /// Replace with other Singular data
    339   void set(leftv rhs) {
    340     if (m_data->rtyp==IDHDL)
    341       m_data = rhs;
    342    else
    343      m_data->Copy(rhs);
    344 
    345     m_ring = parent(rhs);
    346355  }
    347356
     
    350359
    351360  /// Extract (shallow) copy of stored data
    352   LeftvShallow operator*() const { return (broken()? LeftvShallow(): LeftvShallow(m_data)); }
     361  LeftvShallow operator*() const { return (broken()? LeftvShallow(): (const LeftvShallow&)m_data); }
    353362
    354363
    355364  BOOLEAN rering() {
    356     if (m_ring ^ m_data->RingDependend()) m_ring = (m_ring? NULL: currRing);
     365    if (m_ring ^ m_data.ringed()) m_ring = (m_ring? NULL: currRing);
    357366    return (m_back && m_back->rering());
    358367  }
     
    367376        return complain("Referenced identifier not from current ring");   
    368377
    369       return (m_data->rtyp == IDHDL)  && brokenid(currRing->idroot) &&
     378      return m_data.isid()  && m_data.brokenid(currRing->idroot) &&
    370379        complain("Referenced identifier not available in ring anymore"); 
    371380    }
    372 
    373    if (m_data->rtyp != IDHDL) return FALSE;
    374    return brokenid(IDROOT) &&
    375      ((currPack == basePack) || brokenid(basePack->idroot)) &&
     381   
     382    if (!m_data.isid()) return FALSE;
     383    return  m_data.brokenid(IDROOT) &&
     384     ((currPack == basePack) ||  m_data.brokenid(basePack->idroot)) &&
    376385     complain("Referenced identifier not available in current context");
    377386  }
    378387
    379388  BOOLEAN assign(leftv result, leftv arg) {
    380     if (m_data->rtyp!=IDHDL) {
    381       set(arg);
     389    if (!m_data.isid()) {
     390      (*this) = arg;
    382391      return FALSE;
    383392    }
    384393    return get(result) || iiAssign(result, arg) || rering();
    385   }
    386 
    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());
    390394  }
    391395
     
    399403  }
    400404
    401   CountedRefPtr<ring, true> Ring() { return m_ring; }
    402   int Typ() const {return m_data->Typ(); }
     405  BOOLEAN unassigned() const { return m_data.unassigned(); }
    403406private:
    404407
     
    409412  }
    410413
    411   /// Check a given context for our identifier
    412   BOOLEAN brokenid(idhdl context) const {
    413     return (context == NULL) ||
    414       ((context != (idhdl) m_data->data) && brokenid(IDNEXT(context)));
    415   }
     414
    416415
    417416  /// Store ring for ring-dependent objects
     
    439438};
    440439
     440/// Supporting smart pointer @c CountedRefPtr
     441inline void CountedRefPtr_kill(CountedRefData* data) { delete data; }
     442
     443
    441444/// blackbox support - initialization
    442445/// @note deals as marker for compatible references, too.
     
    446449}
    447450
    448 
    449 
    450 inline void CountedRefPtr_kill(CountedRefData* data) { delete data; }
    451451
    452452class CountedRef {
     
    469469
    470470  /// Construct new reference from Singular data 
    471   CountedRef(leftv arg):  m_data(new data_type(arg)) { }
     471  explicit CountedRef(leftv arg):  m_data(new data_type(arg)) { }
    472472
    473473protected:
     
    485485  }
    486486
    487   /// Replace data that reference is pointing to
    488   self& operator=(leftv rhs) {
    489     m_data->set(rhs);
    490     return *this;
    491   }
    492 
    493487  BOOLEAN assign(leftv result, leftv arg) {
    494488    return m_data->assign(result,arg);
    495489  }
    496490  BOOLEAN rering() { return m_data->rering(); }
     491
    497492  /// Extract (shallow) copy of stored data
    498493  LeftvShallow operator*() { return m_data->operator*(); }
     
    560555  /// Check whther argument is not defined yet
    561556  BOOLEAN undefined(leftv res) { return construct(res, operator*()->Typ() == NONE); }
    562 
     557  BOOLEAN unassigned() const { return  m_data->unassigned(); }
    563558  /// Recover the actual object from raw Singular data
    564559  static self cast(void* data) {
     
    579574    return (arg->next != NULL) && resolve(arg->next);
    580575  }
    581   int Typ() const {return m_data->Typ(); }
     576  //  int Typ() const {return m_data->Typ(); }
    582577protected:
    583578  /// Construct integer value
     
    708703public:
    709704  CountedRefShared():  base(new data_type) { }
    710   CountedRefShared(leftv arg):  base(new data_type(arg, FALSE,0)) { }
     705  explicit CountedRefShared(leftv arg):  base(new data_type(arg, FALSE,0)) { }
    711706
    712707  /// Construct copy
     
    719714  }
    720715
    721   /// Replace data that reference is pointing to
    722   self& operator=(leftv rhs) {
    723     return static_cast<self&>(base::operator=(rhs));
    724   }
    725 
    726716  static self cast(leftv arg) { return base::cast(arg); }
    727717  static self cast(void* arg) { return base::cast(arg); }
    728718
    729   self subscripted() {
    730     return self(m_data->subscripted());//new CountedRefDataIndexed(m_data->idify(), m_data);
    731   }
     719  /// Temporarily wrap with identifier for '[' and '.' operation
     720  self subscripted() { return self(m_data->subscripted()); }
    732721
    733722  BOOLEAN retrieve(leftv res, int typ) {
     
    749738
    750739    int typ = head->Typ();
    751     return indexed.dereference(head) || CountedRef::resolve(arg) ||
     740    return indexed.dereference(head) || CountedRefShared::resolve(arg) ||
    752741      iiExprArith2(res, head, op, arg) || indexed.retrieve(res, typ);
    753742  }
     
    793782{
    794783  /// Case: replace assignment behind reference
    795   if ((result->Data() != NULL)  && (CountedRefShared::cast(result).Typ() !=0 )) {
     784  if ((result->Data() != NULL)  && !CountedRefShared::cast(result).unassigned()) {
    796785    if (CountedRefShared::resolve(arg)) return TRUE;
    797786    return CountedRefShared::cast(result).assign(result, arg);
     
    805794    return CountedRefShared::cast(arg).outcast(result);
    806795  } 
    807   if(CountedRefShared::cast(result).Typ() == 0) {
     796  if(CountedRefShared::cast(result).unassigned()) {
    808797   // CountedRefShared::cast(result) = arg;
    809798   return CountedRefShared::cast(result).assign(result, arg);
Note: See TracChangeset for help on using the changeset viewer.