My Project
Loading...
Searching...
No Matches
countedref.cc
Go to the documentation of this file.
1// -*- c++ -*-
2//*****************************************************************************
3/** @file countedref.cc
4 *
5 * @author Alexander Dreyer
6 * @date 2012-08-15
7 *
8 * This file defines reference countes interpreter objects and adds the
9 * @c blackbox operations for high-level types 'reference' and 'shared'.
10 *
11 * @note This works was supported by the "Industrial Algebra" project.
12 *
13 * @par Copyright:
14 * (c) 2012 by The Singular Team, see LICENSE file
15**/
16//*****************************************************************************
17
18
19
20
21
22#include "kernel/mod2.h"
23
24#include "ipid.h"
25
26#include "countedref.h"
27
28#include "blackbox.h"
29#include "newstruct.h"
30#include "ipshell.h"
31
32
33/// Overloading ring destruction
34inline void CountedRefPtr_kill(ring r) { rKill(r); }
35
36
37/** @class CountedRefData
38 * This class stores a reference counter as well as a Singular interpreter object.
39 * It also take care of the context, e.g. the current ring, wrap object, etc.
40 **/
42 public RefCounter {
44public:
46private:
48
49 /// Generate object linked to other reference (e.g. for subscripts)
51 base(), m_data(wrapid), m_ring(back->m_ring), m_back(back) {
52 }
53
54 /// @name Disallow copying to avoid inconsistence
55 //@{
58 //@}
59
60public:
62
63 /// Fix smart pointer type to referenced data
65
66 /// Fix smart pointer type to ring
68
69 /// Construct shared memory empty Singular object
70 explicit CountedRefData():
71 base(), m_data(), m_ring(), m_back() { }
72
73 /// Reference Singular object
74 explicit CountedRefData(leftv data):
75 base(), m_data(data), m_ring(parent(data)), m_back() { }
76
77 /// Construct reference for Singular object
79 base(), m_data(data, do_copy), m_ring(parent(data)), m_back() { }
80
81 /// Destruct
83 if (!m_back.unassigned()) {
84 if (m_back == this)
86 else
88 }
89 }
90
91 /// Generate object for indexing
92 ptr_type wrapid() { return new self(m_data.idify(root()), weakref()); }
93
94 /// Gerenate weak (but managed) reference to @c *this
96 if (m_back.unassigned())
97 m_back = this;
98 return m_back;
99 }
100 /// Replace with other Singular data
102 m_data = rhs;
103 m_ring = parent(rhs);
104 return *this;
105 }
106
107 /// Write (shallow) copy to given handle
108 BOOLEAN put(leftv res) { return broken() || m_data.put(res); }
109
110 /// Extract (shallow) copy of stored data
111 LeftvShallow operator*() const { return (broken()? LeftvShallow(): (const LeftvShallow&)m_data); }
112
113 /// Determine active ring when ring dependency changes
116 return (m_back && (m_back != this) && m_back->rering());
117 }
118
119 /// Get the current context
120 idhdl* root() { return (m_ring? &m_ring->idroot: &IDROOT); }
121
122 /// Check whether identifier became invalid
123 BOOLEAN broken() const {
124 if (!m_back.unassigned() && !m_back)
125 return complain("Back-reference broken");
126
127 if (m_ring) {
128 if (m_ring != currRing)
129 return complain("Referenced identifier not from current ring");
130
131 return m_data.isid() && m_data.brokenid(currRing->idroot) &&
132 complain("Referenced identifier not available in ring anymore");
133 }
134
135 if (!m_data.isid()) return FALSE;
136 return m_data.brokenid(IDROOT) &&
137 ((currPack == basePack) || m_data.brokenid(basePack->idroot)) &&
138 complain("Referenced identifier not available in current context");
139 }
140
141 /// Reassign actual object
143
144 if (!m_data.isid()) {
145 (*this) = arg;
146 return FALSE;
147 }
148 return put(result) || iiAssign(result, arg) || rering();
149 }
150 /// Recover additional information (e.g. subexpression) from likewise object
152
153 /// Check whether data is all-zero
154 BOOLEAN unassigned() const { return m_data.unassigned(); }
155
156private:
157 /// Raise error message and return @c TRUE
158 BOOLEAN complain(const char* text) const
159 {
160 WerrorS(text);
161 return TRUE;
162 }
163
164 /// Store ring for ring-dependent objects
165 static ring parent(leftv rhs)
166 {
167 return (rhs->RingDependend()? currRing: NULL);
168 }
169
170protected:
171 /// Singular object
173
174 /// Store namespace for ring-dependent objects
176
177 /// Reference to actual object for wrap structures
179};
180
181/// Supporting smart pointer @c CountedRefPtr
182inline void CountedRefPtr_kill(CountedRefData* data) { delete data; }
183
184
185/// blackbox support - initialization
186void* countedref_Init(blackbox*)
187{
188 return NULL;
189}
190
191/// We use the function pointer as a marker of reference types
192/// for CountedRef::is_ref(leftv), see the latter for details
193BOOLEAN countedref_CheckAssign(blackbox */*b*/, leftv /*L*/, leftv /*R*/)
194{
195 return FALSE;
196}
197
198
201
202public:
203 /// name type for identifiers
204 typedef int id_type;
205
206 /// Name type for handling referenced data
208
209 /// Fix smart pointer type to referenced data
211
212 /// Check whether argument is already a reference type
213 /// @note We check for the function pointer @c countedref_CheckAssign here,
214 /// that we (ab-)use as a unique marker. This avoids to check a bunch of
215 /// of runtime-varying @c typ IDs for identifying reference-like types.
216 static BOOLEAN is_ref(leftv arg) {
217 int typ = arg->Typ();
218 return ((typ > MAX_TOK) &&
219 (getBlackboxStuff(typ)->blackbox_CheckAssign == countedref_CheckAssign));
220 }
221
222 /// Reference given Singular data
223 explicit CountedRef(leftv arg): m_data(new data_type(arg)) { }
224
225protected:
226 /// Recover previously constructed reference
227 CountedRef(data_ptr arg): m_data(arg) { assume(arg); }
228
229public:
230 /// Construct copy
231 CountedRef(const self& rhs): m_data(rhs.m_data) { }
232
233 /// Replace reference
234 self& operator=(const self& rhs) {
235 m_data = rhs.m_data;
236 return *this;
237 }
238
240 return m_data->assign(result,arg);
241 }
242
243 /// Extract (shallow) copy of stored data
244 LeftvShallow operator*() { return m_data->operator*(); }
245
246 /// Construct reference data object marked by given identifier number
248 res->rtyp = typ;
249 return outcast(res);
250 }
251
252 /// Construct reference data object from *this
254 if (res->rtyp == IDHDL)
255 IDDATA((idhdl)res->data) = (char *)outcast();
256 else
257 res->data = (void *)outcast();
258 return FALSE;
259 }
260
261 /// Construct raw reference data
263 m_data.reclaim();
264 return m_data;
265 }
266
267 /// Kills a link to the referenced object
268 void destruct() { m_data.release(); }
269
270 /// Kills the link to the referenced object
272
273 /// Replaces argument by a shallow copy of the references data
275 m_data.reclaim();
276 BOOLEAN b= m_data->put(arg) || ((arg->next != NULL) && resolve(arg->next));
277 m_data.release();
278 return b;
279 }
280
281 /// Check whether object in valid in current context
282 BOOLEAN broken() {return m_data->broken(); }
283
284 /// Check whether (shared) data was initialized but not assigned yet.
285 BOOLEAN unassigned() const { return m_data->unassigned(); }
286
287 /// Get number of references pointing here, too
289
290 // Get internal identifier
292
293 /// Check for likewise identifiers
295 return resolve(arg) || construct(res, operator*()->data == arg->data);
296 }
297
298 /// Check for identical reference objects
300 return construct(res, m_data == arg->Data());
301 }
302
303 /// Get type of references data
305 return construct(res, Tok2Cmdname(operator*()->Typ()));
306 };
307
308 /// Get (possibly) internal identifier name
309 BOOLEAN name(leftv res) { return construct(res, operator*()->Name()); }
310
311 /// Recover the actual object from raw Singular data
312 static self cast(void* data) {
313 assume(data != NULL);
314 return self(static_cast<data_type*>(data));
315 }
316
317 /// Recover the actual object from Singular interpreter object
318 static self cast(leftv arg) {
319 assume(arg != NULL); assume(is_ref(arg));
320 return self::cast(arg->Data());
321 }
322
323 /// If necessary dereference.
324 static BOOLEAN resolve(leftv arg) {
325 assume(arg != NULL);
326 while (is_ref(arg)) { if(CountedRef::cast(arg).dereference(arg)) return TRUE; };
327 return (arg->next != NULL) && resolve(arg->next);
328 }
329
330 /// Construct integer value
331 static BOOLEAN construct(leftv res, long data) {
332 res->data = (void*) data;
333 res->rtyp = INT_CMD;
334 return FALSE;
335 }
336
337 /// Construct string
338 static BOOLEAN construct(leftv res, const char* data) {
339 res->data = (void*)omStrDup(data);
340 res->rtyp = STRING_CMD;
341 return FALSE;
342 }
343 /// Construct void-style object
345 res->data = NULL;
346 res->rtyp = NONE;
347 return FALSE;
348 }
349
350protected:
351 /// Store pointer to actual data
353};
354
355/// blackbox support - convert to string representation
356void countedref_Print(blackbox */*b*/, void* ptr)
357{
358 if (ptr) (*CountedRef::cast(ptr))->Print();
359 else PrintS("<unassigned reference or shared memory>");
360}
361
362/// blackbox support - convert to string representation
363char* countedref_String(blackbox */*b*/, void* ptr)
364{
365 if (ptr == NULL) return omStrDup(sNoName_fe);
366 return (*CountedRef::cast(ptr))->String();
367}
368
369/// blackbox support - copy element
370void* countedref_Copy(blackbox*/*b*/, void* ptr)
371{
372 if (ptr) return CountedRef::cast(ptr).outcast();
373 return NULL;
374}
375
376/// blackbox support - assign element
378{
379 // Case: replace assignment behind reference
380 if (result->Data() != NULL) {
382 return CountedRef::resolve(arg) || ref.assign(result, arg);
383 }
384
385 // Case: copy reference
386 if (result->Typ() == arg->Typ())
387 return CountedRef::cast(arg).outcast(result);
388
389 // Case: new reference
390 if ((arg->rtyp == IDHDL) || CountedRef::is_ref(arg))
391 return CountedRef(arg).outcast(result);
392
393 WerrorS("Can only take reference from identifier");
394 return TRUE;
395}
396
398{
399 if (arg->Data() != NULL) return FALSE;
400 res->rtyp = NONE;
401 WerrorS("Noninitialized access");
402 return TRUE;
403}
404
405/// blackbox support - unary operations
407{
408 if(op == TYPEOF_CMD)
409 return blackboxDefaultOp1(op, res, head);
410
411 if (countedref_CheckInit(res, head)) return TRUE;
412
413 if ((op == DEF_CMD) || (op == head->Typ()))
414 {
415 res->rtyp = head->Typ();
416 return iiAssign(res, head);
417 }
418
420 return ref.dereference(head) ||
421 iiExprArith1(res, head, op == LINK_CMD? head->Typ(): op);
422}
423
424
425
426/// blackbox support - binary operations (resolve seocnd argument)
428{
429 if (CountedRef::is_ref(arg))
430 {
431 CountedRef ref = CountedRef::cast(arg);
432 return ref.dereference(arg) || iiExprArith2(res, head, op, arg);
433 }
434 return iiExprArith2(res, head, op, arg);
435}
436
438{
439 if (countedref_CheckInit(res, head)) return TRUE;
441 {
443 return ref.dereference(head) || countedref_Op2_(op, res, head, arg);
444 }
445 return countedref_Op2_(op, res, head, arg);
446}
447
448static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2)
449{
450
451 if (CountedRef::is_ref(arg2))
452 {
453 CountedRef ref = CountedRef::cast(arg2);
454 return ref.dereference(arg2) || iiExprArith3(res, op, head, arg1, arg2);
455 }
456 return iiExprArith3(res, op, head, arg1, arg2);
457}
458
459static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2)
460{
461 if (CountedRef::is_ref(arg1))
462 {
463 CountedRef ref = CountedRef::cast(arg1);
464 return ref.dereference(arg1) || countedref_Op3__(op, res, head, arg1, arg2);
465 }
466 return countedref_Op3__(op, res, head, arg1, arg2);
467}
468
469
470/// blackbox support - ternary operations
472{
473 if (countedref_CheckInit(res, head)) return TRUE;
475 {
477 return ref.dereference(head) || countedref_Op3_(op, res, head, arg1, arg2);
478 }
479 return countedref_Op3_(op, res, head, arg1, arg2);
480}
481
482
483/// blackbox support - destruction
484void countedref_destroy(blackbox */*b*/, void* ptr)
485{
486 if (ptr) CountedRef::cast(ptr).destruct();
487}
488
489
491 public CountedRef
492 {
495
496 /// Reinterprete @c CountedRef as @c CountedRefShared
497 CountedRefShared(const base& rhs): base(rhs) { }
498
499 /// Generate from data pointer
501
502public:
503 /// Default constructor for initialized, but all-zero, shared data object
505
506 /// Construct internal copy of Singular interpreter object
507 explicit CountedRefShared(leftv arg): base(new data_type(arg, data_type::copy_tag())) { }
508
509 /// Construct new reference to internal data
510 CountedRefShared(const self& rhs): base(rhs) { }
511
512 /// Desctruct
514
515 /// Change reference to shared data
516 self& operator=(const self& rhs) {
517 return static_cast<self&>(base::operator=(rhs));
518 }
519
520 /// Recovering outcasted @c CountedRefShared object from interpreter object
521 static self cast(leftv arg) { return base::cast(arg); }
522
523 /// Recovering outcasted @c CountedRefShared object from raw data
524 static self cast(void* arg) { return base::cast(arg); }
525
526 /// Temporarily wrap with identifier for '[' and '.' operation
527 self wrapid() { return self(m_data->wrapid()); }
528
529 /// Generate weak reference (may get invalid)
531
532 /// Recover more information (e.g. subexpression data) from computed result
534 {
535 return (m_data->retrieve(res) && outcast(res, typ));
536 }
537};
538
539/// Blackbox support - generate initialized, but all-zero - shared data
540void* countedref_InitShared(blackbox*)
541{
542 return CountedRefShared().outcast();
543}
544
545/// Blackbox support - unary operation for shared data
547{
548 if(op == TYPEOF_CMD)
549 return blackboxDefaultOp1(op, res, head);
550
551 if (countedref_CheckInit(res, head)) return TRUE;
552
553 if ((op == DEF_CMD) || (op == head->Typ()))
554 {
555 res->rtyp = head->Typ();
556 return iiAssign(res, head);
557 }
558
560
561 if (op == LINK_CMD)
562 {
563 if (ref.dereference(head)) return TRUE;
564 res->Copy(head);
565 return (res->Typ() == NONE);
566 }
567
568 CountedRefShared wrap = ref.wrapid();
569 int typ = head->Typ();
570 return wrap.dereference(head) || iiExprArith1(res, head, op) ||
571 wrap.retrieve(res, typ);
572}
573
574
575/// blackbox support - binary operations
577{
578 if (countedref_CheckInit(res, head)) return TRUE;
579
581 {
583 int typ = head->Typ();
584 return wrap.dereference(head) || countedref_Op2_(op, res, head, arg) ||
585 wrap.retrieve(res, typ);
586 }
587
588 return countedref_Op2_(op, res, head, arg);
589}
590
591/// blackbox support - n-ary operations
593{
594 if (args->Data() == NULL) return FALSE;
595
596 if(op == SYSTEM_CMD)
597 {
598 if (args->next)
599 {
600 leftv next = args->next;
601 args->next = NULL;
602
603 char* name = (next->Typ() == STRING_CMD?
604 (char*) next->Data(): (char*)next->Name());
605 next = next->next;
606
607 if (strcmp(name, "help") == 0)
608 {
609 PrintS("system(<ref>, ...): extended functionality for reference/shared data <ref>\n");
610 PrintS(" system(<ref>, count) - number of references pointing to <ref>\n");
611 PrintS(" system(<ref>, enumerate) - unique number for identifying <ref>\n");
612 PrintS(" system(<ref>, undefined) - checks whether <ref> had been assigned\n");
613 PrintS(" system(<ref>, \"help\") - prints this information message\n");
614 PrintS(" system(<ref>, \"typeof\") - actual type referenced by <ref>\n");
615 PrintS(" system(<ref1>, same, <ref2>) - tests for identic reference objects\n");
617 }
618 if (strncmp(name, "undef", 5) == 0)
619 {
620 return CountedRef::construct(res, args->Data()?
621 (CountedRef::cast(args).unassigned()? 1: 2): 0);
622 }
623
624 CountedRef obj = CountedRef::cast(args);
625 if (next)
626 {
627 if (strcmp(name, "same") == 0) return obj.same(res, next);
628 // likewise may be hard to interprete, so we not not document it above
629 if (strncmp(name, "like", 4) == 0) return obj.likewise(res, next);
630 }
631 if (strncmp(name, "count", 5) == 0) return obj.count(res);
632 if (strncmp(name, "enum", 4) == 0) return obj.enumerate(res);
633 if (strcmp(name, "name") == 0) return obj.name(res); // undecumented
634 if (strncmp(name, "typ", 3) == 0) return obj.type(res);
635 }
636 return TRUE;
637 }
638 if (op == LIST_CMD)
639 {
640 res->rtyp = op;
641 return jjLIST_PL(res, args);
642 }
643 CountedRef ref = CountedRef::cast(args);
644 return ref.dereference(args) || iiExprArithM(res, args, op);
645}
646
647/// blackbox support - assign element
649{
650 /// Case: replace assignment behind reference
651 if ((result->Data() != NULL) && !CountedRefShared::cast(result).unassigned()) {
653 return CountedRef::resolve(arg) || ref.assign(result, arg);
654 }
655
656 /// Case: new reference to already shared data
657 if (result->Typ() == arg->Typ())
658 {
659 if (result->Data() != NULL)
662 }
663 if(CountedRefShared::cast(result).unassigned())
664 {
666 }
667
668 /// Case: new shared data
669 return CountedRefShared(arg).outcast(result);
670}
671
672/// blackbox support - destruction
673void countedref_destroyShared(blackbox */*b*/, void* ptr)
674{
675 if (ptr) CountedRefShared::cast(ptr).destruct();
676}
677
678
679BOOLEAN countedref_serialize(blackbox */*b*/, void *d, si_link f)
680{
681 sleftv l;
682 memset(&l,0,sizeof(l));
683 l.rtyp = STRING_CMD;
684 l.data = (void*)omStrDup("shared"); // references are converted
685 f->m->Write(f, &l);
687 f->m->Write(f, &l);
688 return FALSE;
689}
690
691BOOLEAN countedref_deserialize(blackbox **/*b*/, void **d, si_link f)
692{
693 // rtyp must be set correctly (to the blackbox id) by routine calling
694 leftv data=f->m->Read(f);
695 CountedRefShared sh(data);
696 *d = sh.outcast();
697 return FALSE;
698}
699
701{
702 int tok;
703 if (blackboxIsCmd("reference", tok) == ROOT_DECL)
704 return;
705
706 blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox));
707 bbx->blackbox_CheckAssign = countedref_CheckAssign;
708 bbx->blackbox_destroy = countedref_destroy;
709 bbx->blackbox_String = countedref_String;
710 bbx->blackbox_Print = countedref_Print;
711 bbx->blackbox_Init = countedref_Init;
712 bbx->blackbox_Copy = countedref_Copy;
713 bbx->blackbox_Assign = countedref_Assign;
714 bbx->blackbox_Op1 = countedref_Op1;
715 bbx->blackbox_Op2 = countedref_Op2;
716 bbx->blackbox_Op3 = countedref_Op3;
717 bbx->blackbox_OpM = countedref_OpM;
718 bbx->blackbox_serialize = countedref_serialize;
719 bbx->blackbox_deserialize = countedref_deserialize;
720 bbx->data = omAlloc0(newstruct_desc_size());
721 setBlackboxStuff(bbx, "reference");
722}
723
725{
726 int tok;
727 if (blackboxIsCmd("shared", tok) == ROOT_DECL)
728 return;
729
730 blackbox *bbxshared = (blackbox*)omAlloc0(sizeof(blackbox));
731 bbxshared->blackbox_String = countedref_String;
732 bbxshared->blackbox_Print = countedref_Print;
733 bbxshared->blackbox_Copy = countedref_Copy;
734 bbxshared->blackbox_Op3 = countedref_Op3;
735 bbxshared->blackbox_OpM = countedref_OpM;
736 bbxshared->blackbox_serialize = countedref_serialize;
737 bbxshared->blackbox_deserialize = countedref_deserialize;
738
739 bbxshared->blackbox_CheckAssign = countedref_CheckAssign;
740 bbxshared->blackbox_Assign = countedref_AssignShared;
741 bbxshared->blackbox_destroy = countedref_destroyShared;
742 bbxshared->blackbox_Op1 = countedref_Op1Shared;
743 bbxshared->blackbox_Op2 = countedref_Op2Shared;
744 bbxshared->blackbox_Init = countedref_InitShared;
745 bbxshared->data = omAlloc0(newstruct_desc_size());
746 setBlackboxStuff(bbxshared, "shared");
747}
748
749
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:142
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:17
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition: blackbox.cc:218
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Definition: blackbox.cc:78
CanonicalForm head(const CanonicalForm &f)
int l
Definition: cfEzgcd.cc:100
CanonicalForm b
Definition: cfModGcd.cc:4103
FILE * f
Definition: checklibs.c:9
This class stores a reference counter as well as a Singular interpreter object.
Definition: countedref.cc:42
LeftvDeep::copy_tag copy_tag
Fix smart pointer type to referenced data.
Definition: countedref.cc:61
LeftvShallow operator*() const
Extract (shallow) copy of stored data.
Definition: countedref.cc:111
CountedRefWeakPtr< self * > back_ptr
Definition: countedref.cc:45
ring_ptr m_ring
Store namespace for ring-dependent objects.
Definition: countedref.cc:175
self & operator=(leftv rhs)
Replace with other Singular data.
Definition: countedref.cc:101
static ring parent(leftv rhs)
Store ring for ring-dependent objects.
Definition: countedref.cc:165
BOOLEAN broken() const
Check whether identifier became invalid.
Definition: countedref.cc:123
~CountedRefData()
Destruct.
Definition: countedref.cc:82
LeftvDeep m_data
Singular object.
Definition: countedref.cc:172
CountedRefData(const self &)
Fix smart pointer type to referenced data.
back_ptr::ptr_type ptr_type
Fix smart pointer type to referenced data.
Definition: countedref.cc:64
idhdl * root()
Get the current context.
Definition: countedref.cc:120
CountedRefData(leftv data)
Reference Singular object.
Definition: countedref.cc:74
CountedRefData(leftv wrapid, back_ptr back)
Generate object linked to other reference (e.g. for subscripts)
Definition: countedref.cc:50
CountedRefData()
Construct shared memory empty Singular object.
Definition: countedref.cc:70
RefCounter base
Definition: countedref.cc:47
back_ptr m_back
Reference to actual object for wrap structures.
Definition: countedref.cc:178
CountedRefPtr< ring, true > ring_ptr
Fix smart pointer type to ring.
Definition: countedref.cc:67
BOOLEAN complain(const char *text) const
Raise error message and return TRUE.
Definition: countedref.cc:158
BOOLEAN rering()
Determine active ring when ring dependency changes.
Definition: countedref.cc:114
BOOLEAN retrieve(leftv res)
Recover additional information (e.g. subexpression) from likewise object.
Definition: countedref.cc:151
CountedRefData self
Definition: countedref.cc:43
BOOLEAN put(leftv res)
Write (shallow) copy to given handle.
Definition: countedref.cc:108
self & operator=(const self &)
Fix smart pointer type to referenced data.
back_ptr weakref()
Gerenate weak (but managed) reference to *this.
Definition: countedref.cc:95
BOOLEAN unassigned() const
Check whether data is all-zero.
Definition: countedref.cc:154
BOOLEAN assign(leftv result, leftv arg)
Reassign actual object.
Definition: countedref.cc:142
CountedRefData(leftv data, copy_tag do_copy)
Construct reference for Singular object.
Definition: countedref.cc:78
ptr_type wrapid()
Generate object for indexing.
Definition: countedref.cc:92
This class implements a smart pointer which handles pointer-style access to a reference-counted struc...
Definition: countedref.h:43
count_type count() const
Store actual pointer.
Definition: countedref.h:95
void release()
Store actual pointer.
Definition: countedref.h:97
void reclaim()
Store actual pointer.
Definition: countedref.h:96
~CountedRefShared()
Desctruct.
Definition: countedref.cc:513
BOOLEAN retrieve(leftv res, int typ)
Recover more information (e.g. subexpression data) from computed result.
Definition: countedref.cc:533
data_type::back_ptr weakref()
Generate weak reference (may get invalid)
Definition: countedref.cc:530
CountedRefShared(data_ptr rhs)
Generate from data pointer.
Definition: countedref.cc:500
CountedRefShared(leftv arg)
Construct internal copy of Singular interpreter object.
Definition: countedref.cc:507
self & operator=(const self &rhs)
Change reference to shared data.
Definition: countedref.cc:516
CountedRefShared()
Default constructor for initialized, but all-zero, shared data object.
Definition: countedref.cc:504
CountedRef base
Definition: countedref.cc:494
CountedRefShared(const self &rhs)
Construct new reference to internal data.
Definition: countedref.cc:510
static self cast(leftv arg)
Recovering outcasted CountedRefShared object from interpreter object.
Definition: countedref.cc:521
static self cast(void *arg)
Recovering outcasted CountedRefShared object from raw data.
Definition: countedref.cc:524
CountedRefShared self
Definition: countedref.cc:493
self wrapid()
Temporarily wrap with identifier for '[' and '.' operation.
Definition: countedref.cc:527
CountedRefShared(const base &rhs)
Reinterprete CountedRef as CountedRefShared.
Definition: countedref.cc:497
bool unassigned() const
Test whether reference was never used.
Definition: countedref.h:181
void invalidate()
Mark weak reference as invalid.
Definition: countedref.h:178
BOOLEAN type(leftv res)
Get type of references data.
Definition: countedref.cc:304
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition: countedref.cc:324
BOOLEAN dereference(leftv arg)
Replaces argument by a shallow copy of the references data.
Definition: countedref.cc:274
BOOLEAN unassigned() const
Check whether (shared) data was initialized but not assigned yet.
Definition: countedref.cc:285
LeftvShallow operator*()
Extract (shallow) copy of stored data.
Definition: countedref.cc:244
static self cast(leftv arg)
Recover the actual object from Singular interpreter object.
Definition: countedref.cc:318
BOOLEAN outcast(leftv res, int typ)
Construct reference data object marked by given identifier number.
Definition: countedref.cc:247
BOOLEAN likewise(leftv res, leftv arg)
Check for likewise identifiers.
Definition: countedref.cc:294
BOOLEAN broken()
Check whether object in valid in current context.
Definition: countedref.cc:282
int id_type
name type for identifiers
Definition: countedref.cc:204
CountedRef(const self &rhs)
Construct copy.
Definition: countedref.cc:231
BOOLEAN enumerate(leftv res)
Definition: countedref.cc:291
BOOLEAN outcast(leftv res)
Construct reference data object from *this.
Definition: countedref.cc:253
BOOLEAN assign(leftv result, leftv arg)
Definition: countedref.cc:239
~CountedRef()
Kills the link to the referenced object.
Definition: countedref.cc:271
self & operator=(const self &rhs)
Replace reference.
Definition: countedref.cc:234
void destruct()
Kills a link to the referenced object.
Definition: countedref.cc:268
static BOOLEAN construct(leftv res, const char *data)
Construct string.
Definition: countedref.cc:338
CountedRef(leftv arg)
Reference given Singular data.
Definition: countedref.cc:223
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
BOOLEAN same(leftv res, leftv arg)
Check for identical reference objects.
Definition: countedref.cc:299
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331
data_type * outcast()
Construct raw reference data.
Definition: countedref.cc:262
CountedRefPtr< CountedRefData * > data_ptr
Fix smart pointer type to referenced data.
Definition: countedref.cc:210
CountedRef(data_ptr arg)
Recover previously constructed reference.
Definition: countedref.cc:227
static BOOLEAN is_ref(leftv arg)
Check whether argument is already a reference type.
Definition: countedref.cc:216
CountedRefData data_type
Name type for handling referenced data.
Definition: countedref.cc:207
BOOLEAN name(leftv res)
Get (possibly) internal identifier name.
Definition: countedref.cc:309
CountedRef self
Definition: countedref.cc:200
static BOOLEAN construct(leftv res)
Construct void-style object.
Definition: countedref.cc:344
static self cast(void *data)
Recover the actual object from raw Singular data.
Definition: countedref.cc:312
BOOLEAN count(leftv res)
Get number of references pointing here, too.
Definition: countedref.cc:288
This class wraps leftv by taking into acount memory allocation, destruction as well as deeply copying...
Definition: countedref.h:335
void clearid(idhdl *root)
Erase identifier handles by *this.
Definition: countedref.h:442
BOOLEAN isid() const
Check for being an identifier.
Definition: countedref.h:426
BOOLEAN ringed()
Test whether we reference to ring-dependent data.
Definition: countedref.h:428
BOOLEAN brokenid(idhdl context) const
Check a given context for our identifier.
Definition: countedref.h:389
BOOLEAN unassigned() const
Check whether (all-zero) initialized data was never assigned.
Definition: countedref.h:430
BOOLEAN retrieve(leftv res)
Get additional data (e.g. subexpression data) from likewise instances.
Definition: countedref.h:414
leftv idify(idhdl *root)
Wrap data by identifier, if not done yet.
Definition: countedref.h:433
BOOLEAN put(leftv result)
Put a shallow copy to given leftv.
Definition: countedref.h:396
Construct even deeper copy: Skip identifier (if any) and take care of the data on our own.
Definition: countedref.h:357
Ths class wraps leftv by taking into acount memory allocation, destruction as well as shallowly copyi...
Definition: countedref.h:285
This class implements implements a refernce counter which we can use as a public base of objects mana...
Definition: countedref.h:112
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Typ()
Definition: subexpr.cc:1019
int rtyp
Definition: subexpr.h:91
void * Data()
Definition: subexpr.cc:1162
BOOLEAN RingDependend()
Definition: subexpr.cc:418
leftv next
Definition: subexpr.h:86
void * data
Definition: subexpr.h:88
void CountedRefPtr_kill(ring r)
Overloading ring destruction.
Definition: countedref.cc:34
char * countedref_String(blackbox *, void *ptr)
blackbox support - convert to string representation
Definition: countedref.cc:363
BOOLEAN countedref_CheckInit(leftv res, leftv arg)
Definition: countedref.cc:397
BOOLEAN countedref_Op2Shared(int op, leftv res, leftv head, leftv arg)
blackbox support - binary operations
Definition: countedref.cc:576
BOOLEAN countedref_serialize(blackbox *, void *d, si_link f)
Definition: countedref.cc:679
void countedref_destroyShared(blackbox *, void *ptr)
blackbox support - destruction
Definition: countedref.cc:673
void countedref_Print(blackbox *, void *ptr)
blackbox support - convert to string representation
Definition: countedref.cc:356
BOOLEAN countedref_deserialize(blackbox **, void **d, si_link f)
Definition: countedref.cc:691
void * countedref_InitShared(blackbox *)
Blackbox support - generate initialized, but all-zero - shared data.
Definition: countedref.cc:540
static BOOLEAN countedref_Op2_(int op, leftv res, leftv head, leftv arg)
blackbox support - binary operations (resolve seocnd argument)
Definition: countedref.cc:427
BOOLEAN countedref_AssignShared(leftv result, leftv arg)
blackbox support - assign element
Definition: countedref.cc:648
BOOLEAN countedref_OpM(int op, leftv res, leftv args)
blackbox support - n-ary operations
Definition: countedref.cc:592
BOOLEAN countedref_Op3(int op, leftv res, leftv head, leftv arg1, leftv arg2)
blackbox support - ternary operations
Definition: countedref.cc:471
static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2)
Definition: countedref.cc:448
BOOLEAN countedref_Assign(leftv result, leftv arg)
blackbox support - assign element
Definition: countedref.cc:377
BOOLEAN countedref_Op2(int op, leftv res, leftv head, leftv arg)
Definition: countedref.cc:437
void * countedref_Init(blackbox *)
blackbox support - initialization
Definition: countedref.cc:186
void countedref_destroy(blackbox *, void *ptr)
blackbox support - destruction
Definition: countedref.cc:484
BOOLEAN countedref_Op1Shared(int op, leftv res, leftv head)
Blackbox support - unary operation for shared data.
Definition: countedref.cc:546
static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2)
Definition: countedref.cc:459
void countedref_reference_load()
Initialize blackbox types 'reference' and 'shared', or both.
Definition: countedref.cc:700
BOOLEAN countedref_Op1(int op, leftv res, leftv head)
blackbox support - unary operations
Definition: countedref.cc:406
BOOLEAN countedref_CheckAssign(blackbox *, leftv, leftv)
We use the function pointer as a marker of reference types for CountedRef::is_ref(leftv),...
Definition: countedref.cc:193
void countedref_shared_load()
Definition: countedref.cc:724
void * countedref_Copy(blackbox *, void *ptr)
blackbox support - copy element
Definition: countedref.cc:370
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
#define Print
Definition: emacs.cc:80
return result
Definition: facAbsBiFact.cc:75
CanonicalForm res
Definition: facAbsFact.cc:60
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char sNoName_fe[]
Definition: fevoices.cc:57
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
@ ROOT_DECL
Definition: grammar.cc:319
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition: iparith.cc:8924
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition: iparith.cc:9113
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:9414
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition: iparith.cc:9323
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition: iparith.cc:7998
BOOLEAN iiAssign(leftv l, leftv r, BOOLEAN toplevel)
Definition: ipassign.cc:1963
VAR package basePack
Definition: ipid.cc:58
VAR package currPack
Definition: ipid.cc:57
#define IDDATA(a)
Definition: ipid.h:126
#define IDROOT
Definition: ipid.h:19
void rKill(ring r)
Definition: ipshell.cc:6180
ListNode * next
Definition: janet.h:31
#define assume(x)
Definition: mod2.h:389
int newstruct_desc_size()
Definition: newstruct.cc:42
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void PrintS(const char *s)
Definition: reporter.cc:284
int name
New type name for int.
Definition: templateForC.h:21
#define IDHDL
Definition: tok.h:31
@ LIST_CMD
Definition: tok.h:118
@ DEF_CMD
Definition: tok.h:58
@ LINK_CMD
Definition: tok.h:117
@ TYPEOF_CMD
Definition: tok.h:194
@ STRING_CMD
Definition: tok.h:185
@ INT_CMD
Definition: tok.h:96
@ SYSTEM_CMD
Definition: tok.h:187
@ MAX_TOK
Definition: tok.h:218
#define NONE
Definition: tok.h:221