1 /********************************************************************/
2 /* */
3 /* s7 Seed7 interpreter */
4 /* Copyright (C) 1990 - 2015 Thomas Mertes */
5 /* */
6 /* This program is free software; you can redistribute it and/or */
7 /* modify it under the terms of the GNU General Public License as */
8 /* published by the Free Software Foundation; either version 2 of */
9 /* the License, or (at your option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public */
17 /* License along with this program; if not, write to the */
18 /* Free Software Foundation, Inc., 51 Franklin Street, */
19 /* Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* */
21 /* Module: Compiler data reflection */
22 /* File: seed7/src/ref_data.c */
23 /* Changes: 1991-1994, 2004, 2007, 2008, 2010, 2015 Thomas Mertes */
24 /* Content: Primitive actions for the reference type. */
25 /* */
26 /********************************************************************/
27
28 #define LOG_FUNCTIONS 0
29 #define VERBOSE_EXCEPTIONS 0
30
31 #include "version.h"
32
33 #include "stdlib.h"
34 #include "stdio.h"
35 #include "string.h"
36
37 #include "common.h"
38 #include "data.h"
39 #include "data_rtl.h"
40 #include "heaputl.h"
41 #include "flistutl.h"
42 #include "datautl.h"
43 #include "striutl.h"
44 #include "listutl.h"
45 #include "identutl.h"
46 #include "objutl.h"
47 #include "infile.h" /* from the compiler library */
48 #include "name.h" /* from the compiler library */
49 #include "blockutl.h" /* from the compiler library */
50 #include "syvarutl.h" /* from the compiler library */
51 #include "hsh_rtl.h"
52 #include "int_rtl.h"
53 #include "str_rtl.h"
54 #include "big_drv.h"
55 #include "pol_drv.h"
56 #include "rtl_err.h"
57 #if ANY_LOG_ACTIVE
58 #include "traceutl.h"
59 #endif
60
61 #undef EXTERN
62 #define EXTERN
63 #include "ref_data.h"
64
65
66 #define MAX_CSTRI_BUFFER_LEN 40
67
68
69
refAlloc(const const_objectType aReference)70 objectType refAlloc (const const_objectType aReference)
71
72 {
73 objectType created_object;
74
75 /* refAlloc */
76 logFunction(printf("refAlloc(");
77 trace1(aReference);
78 printf(")\n"););
79 if (unlikely(!ALLOC_OBJECT(created_object))) {
80 raise_error(MEMORY_ERROR);
81 } else {
82 created_object->type_of = aReference->type_of;
83 memcpy(&created_object->descriptor, &aReference->descriptor,
84 sizeof(descriptorUnion));
85 /* Copies the POSINFO flag (and all other flags): */
86 INIT_CATEGORY_OF_OBJ(created_object, aReference->objcategory);
87 created_object->value.objValue = NULL;
88 } /* if */
89 return created_object;
90 } /* refAlloc */
91
92
93
refAllocInt(boolType isVar,typeType aType,const intType number)94 objectType refAllocInt (boolType isVar, typeType aType,
95 const intType number)
96
97 {
98 objectType created_object;
99
100 /* refAllocInt */
101 if (unlikely(!ALLOC_OBJECT(created_object))) {
102 raise_error(MEMORY_ERROR);
103 } else {
104 created_object->type_of = aType;
105 created_object->descriptor.property = NULL;
106 INIT_CATEGORY_OF_OBJ(created_object, INTOBJECT);
107 if (isVar) {
108 SET_VAR_FLAG(created_object);
109 } /* if */
110 created_object->value.intValue = number;
111 } /* if */
112 return created_object;
113 } /* refAllocInt */
114
115
116
refAllocStri(boolType isVar,typeType aType,const const_striType stri)117 objectType refAllocStri (boolType isVar, typeType aType,
118 const const_striType stri)
119
120 {
121 objectType created_object;
122
123 /* refAllocStri */
124 if (unlikely(!ALLOC_OBJECT(created_object))) {
125 raise_error(MEMORY_ERROR);
126 } else {
127 created_object->type_of = aType;
128 created_object->descriptor.property = NULL;
129 INIT_CATEGORY_OF_OBJ(created_object, STRIOBJECT);
130 if (isVar) {
131 SET_VAR_FLAG(created_object);
132 } /* if */
133 created_object->value.striValue = strCreate(stri);
134 } /* if */
135 return created_object;
136 } /* refAllocStri */
137
138
139
refAllocVar(typeType aType,const intType aCategory)140 objectType refAllocVar (typeType aType, const intType aCategory)
141
142 {
143 objectType created_object;
144
145 /* refAllocVar */
146 if (unlikely(!ALLOC_OBJECT(created_object))) {
147 raise_error(MEMORY_ERROR);
148 } else {
149 created_object->type_of = aType;
150 created_object->descriptor.property = NULL;
151 INIT_CATEGORY_OF_OBJ(created_object, aCategory);
152 SET_VAR_FLAG(created_object);
153 created_object->value.intValue = 0;
154 } /* if */
155 return created_object;
156 } /* refAllocVar */
157
158
159
160 /**
161 * Obtain the maximum index of the array referenced by 'arrayRef'.
162 * @param arrayRef Reference to an array object.
163 * @return the maximum index of the array.
164 * @exception RANGE_ERROR If 'arrayRef' does not refer to an array.
165 */
refArrMaxIdx(const const_objectType arrayRef)166 intType refArrMaxIdx (const const_objectType arrayRef)
167
168 { /* refArrMaxIdx */
169 if (unlikely(arrayRef == NULL ||
170 CATEGORY_OF_OBJ(arrayRef) != ARRAYOBJECT)) {
171 logError(printf("refArrMaxIdx(");
172 trace1(arrayRef);
173 printf("): Category is not ARRAYOBJECT.\n"););
174 raise_error(RANGE_ERROR);
175 return 0;
176 } else {
177 return take_array(arrayRef)->max_position;
178 } /* if */
179 } /* refArrMaxIdx */
180
181
182
183 /**
184 * Obtain the minimum index of the array referenced by 'arrayRef'.
185 * @param arrayRef Reference to an array object.
186 * @return the minimum index of the array.
187 * @exception RANGE_ERROR If 'arrayRef' does not refer to an array.
188 */
refArrMinIdx(const const_objectType arrayRef)189 intType refArrMinIdx (const const_objectType arrayRef)
190
191 { /* refArrMinIdx */
192 if (unlikely(arrayRef == NULL ||
193 CATEGORY_OF_OBJ(arrayRef) != ARRAYOBJECT)) {
194 logError(printf("refArrMinIdx(");
195 trace1(arrayRef);
196 printf("): Category is not ARRAYOBJECT.\n"););
197 raise_error(RANGE_ERROR);
198 return 0;
199 } else {
200 return take_array(arrayRef)->min_position;
201 } /* if */
202 } /* refArrMinIdx */
203
204
205
refArrToList(const const_objectType arrayRef)206 listType refArrToList (const const_objectType arrayRef)
207
208 {
209 errInfoType err_info = OKAY_NO_ERROR;
210 listType result;
211
212 /* refArrToList */
213 if (unlikely(arrayRef == NULL ||
214 CATEGORY_OF_OBJ(arrayRef) != ARRAYOBJECT)) {
215 logError(printf("refArrToList(");
216 trace1(arrayRef);
217 printf("): Category is not ARRAYOBJECT.\n"););
218 raise_error(RANGE_ERROR);
219 result = NULL;
220 } else {
221 result = array_to_list(take_array(arrayRef), &err_info);
222 if (unlikely(err_info != OKAY_NO_ERROR)) {
223 raise_error(MEMORY_ERROR);
224 result = NULL;
225 } /* if */
226 } /* if */
227 return result;
228 } /* refArrToList */
229
230
231
232 /**
233 * Gets the body of the function referenced by 'funcRef'.
234 * @return the body expression of 'funcRef'.
235 * @exception RANGE_ERROR If 'funcRef' is NIL or
236 * category(funcRef) <> BLOCKOBJECT holds.
237 */
refBody(const const_objectType funcRef)238 objectType refBody (const const_objectType funcRef)
239
240 {
241 objectType result;
242
243 /* refBody */
244 if (unlikely(funcRef == NULL ||
245 CATEGORY_OF_OBJ(funcRef) != BLOCKOBJECT)) {
246 logError(printf("refBody(");
247 trace1(funcRef);
248 printf("): Category is not BLOCKOBJECT.\n"););
249 raise_error(RANGE_ERROR);
250 result = NULL;
251 } else {
252 result = funcRef->value.blockValue->body;
253 } /* if */
254 return result;
255 } /* refBody */
256
257
258
259 /**
260 * Get the category of a referenced object.
261 * @return the category of the referenced object.
262 * @exception RANGE_ERROR If 'aReference' is NIL.
263 */
refCategory(const const_objectType aReference)264 intType refCategory (const const_objectType aReference)
265
266 {
267 intType result;
268
269 /* refCategory */
270 if (unlikely(aReference == NULL)) {
271 logError(printf("refCategory(NULL): Object is NULL.\n"););
272 raise_error(RANGE_ERROR);
273 result = 0;
274 } else {
275 result = CATEGORY_OF_OBJ(aReference);
276 } /* if */
277 return result;
278 } /* refCategory */
279
280
281
282 /**
283 * Convert a [[string]] to a 'category'.
284 * @param catName Name of a category to be converted.
285 * @return the 'category' result fo the conversion.
286 * @exception RANGE_ERROR If there is no corresponding 'category'.
287 */
refCatParse(const const_striType catName)288 intType refCatParse (const const_striType catName)
289
290 {
291 char name[MAX_CSTRI_BUFFER_LEN + NULL_TERMINATION_LEN];
292 intType category;
293
294 /* refCatParse */
295 if (unlikely(catName->size > MAX_CSTRI_BUFFER_LEN)) {
296 category = -1;
297 } else {
298 if (unlikely(conv_to_cstri(name, catName) == NULL)) {
299 category = -1;
300 } else {
301 category = category_value(name);
302 } /* if */
303 } /* if */
304 if (unlikely(category == -1)) {
305 logError(printf("refCatParse(\"%s\"): No corresponding category.\n",
306 striAsUnquotedCStri(catName)););
307 raise_error(RANGE_ERROR);
308 } /* if */
309 return category;
310 } /* refCatParse */
311
312
313
314 /**
315 * Convert a category to a string.
316 * @param aCategory Category to be converted.
317 * @return the string result of the conversion.
318 * @exception MEMORY_ERROR Not enough memory to represent the result.
319 */
refCatStr(intType aCategory)320 striType refCatStr (intType aCategory)
321
322 {
323 striType result;
324
325 /* refCatStr */
326 result = cstri_to_stri(category_cstri((objectCategory) aCategory));
327 if (unlikely(result == NULL)) {
328 raise_error(MEMORY_ERROR);
329 } /* if */
330 return result;
331 } /* refCatStr */
332
333
334
335 /**
336 * Determine the file name of a referenced object.
337 * @return the file name of the referenced object.
338 * @exception RANGE_ERROR If 'aReference' is NIL.
339 * @exception MEMORY_ERROR Not enough memory to represent the result.
340 */
refFile(const const_objectType aReference)341 striType refFile (const const_objectType aReference)
342
343 {
344 fileNumType file_number;
345 striType fileName;
346
347 /* refFile */
348 if (unlikely(aReference == NULL)) {
349 logError(printf("refFile(NULL): Object is NULL.\n"););
350 raise_error(RANGE_ERROR);
351 fileName = NULL;
352 } else {
353 if (HAS_POSINFO(aReference)) {
354 file_number = GET_FILE_NUM(aReference);
355 } else if (HAS_PROPERTY(aReference)) {
356 /* trace1(aReference);
357 printf(" %u %u %u\n",
358 aReference->descriptor.property->file_number,
359 aReference->descriptor.property->line,
360 aReference->descriptor.property->syNumberInLine); */
361 file_number = aReference->descriptor.property->file_number;
362 } else {
363 file_number = 0;
364 } /* if */
365 fileName = get_file_name(file_number);
366 if (unlikely(fileName == NULL)) {
367 raise_error(MEMORY_ERROR);
368 } /* if */
369 } /* if */
370 return fileName;
371 } /* refFile */
372
373
374
refHshDataToList(const const_objectType aReference)375 listType refHshDataToList (const const_objectType aReference)
376
377 {
378 errInfoType err_info = OKAY_NO_ERROR;
379 listType result;
380
381 /* refHshDataToList */
382 if (unlikely(aReference == NULL ||
383 CATEGORY_OF_OBJ(aReference) != HASHOBJECT)) {
384 logError(printf("refHshDataToList(");
385 trace1(aReference);
386 printf("): Category is not HASHOBJECT.\n"););
387 raise_error(RANGE_ERROR);
388 result = NULL;
389 } else {
390 result = hash_data_to_list(take_hash(aReference), &err_info);
391 if (unlikely(err_info != OKAY_NO_ERROR)) {
392 raise_error(MEMORY_ERROR);
393 result = NULL;
394 } /* if */
395 } /* if */
396 return result;
397 } /* refHshDataToList */
398
399
400
refHshKeysToList(const const_objectType aReference)401 listType refHshKeysToList (const const_objectType aReference)
402
403 {
404 errInfoType err_info = OKAY_NO_ERROR;
405 listType result;
406
407 /* refHshKeysToList */
408 if (unlikely(aReference == NULL ||
409 CATEGORY_OF_OBJ(aReference) != HASHOBJECT)) {
410 logError(printf("refHshKeysToList(");
411 trace1(aReference);
412 printf("): Category is not HASHOBJECT.\n"););
413 raise_error(RANGE_ERROR);
414 result = NULL;
415 } else {
416 result = hash_keys_to_list(take_hash(aReference), &err_info);
417 if (unlikely(err_info != OKAY_NO_ERROR)) {
418 raise_error(MEMORY_ERROR);
419 result = NULL;
420 } /* if */
421 } /* if */
422 return result;
423 } /* refHshKeysToList */
424
425
426
refHshLength(const const_objectType aReference)427 intType refHshLength (const const_objectType aReference)
428
429 {
430 intType length;
431
432 /* refHshLength */
433 if (unlikely(aReference == NULL ||
434 CATEGORY_OF_OBJ(aReference) != HASHOBJECT)) {
435 logError(printf("refHshLength(");
436 trace1(aReference);
437 printf("): Category is not HASHOBJECT.\n"););
438 raise_error(RANGE_ERROR);
439 length = 0;
440 } else {
441 length = (intType) take_hash(aReference)->size;
442 } /* if */
443 return length;
444 } /* refHshLength */
445
446
447
448 /**
449 * Determine if the referenced object is temporary.
450 * @return TRUE if ''aReference'' is temporary, FALSE otherwise.
451 * @exception RANGE_ERROR If ''aReference'' is NIL.
452 */
refIsTemp(const const_objectType aReference)453 boolType refIsTemp (const const_objectType aReference)
454
455 { /* refIsTemp */
456 logFunction(printf("refIsTemp(" FMT_U_MEM ")\n",
457 (memSizeType) aReference););
458 if (unlikely(aReference == NULL)) {
459 logError(printf("refIsTemp(NULL): Object is NULL.\n"););
460 raise_error(RANGE_ERROR);
461 return FALSE;
462 } else {
463 return TEMP_OBJECT(aReference) ? TRUE : FALSE;
464 } /* if */
465 } /* refIsTemp */
466
467
468
469 /**
470 * Determine if the referenced object is variable.
471 * @return TRUE if ''aReference'' is a variable, FALSE otherwise.
472 * @exception RANGE_ERROR If ''aReference'' is NIL.
473 */
refIsVar(const const_objectType aReference)474 boolType refIsVar (const const_objectType aReference)
475
476 { /* refIsVar */
477 logFunction(printf("refIsVar(" FMT_U_MEM ")\n",
478 (memSizeType) aReference););
479 if (unlikely(aReference == NULL)) {
480 logError(printf("refIsVar(NULL): Object is NULL.\n"););
481 raise_error(RANGE_ERROR);
482 return FALSE;
483 } else {
484 return VAR_OBJECT(aReference) ? TRUE : FALSE;
485 } /* if */
486 } /* refIsVar */
487
488
489
refItfToSct(const const_objectType aReference)490 objectType refItfToSct (const const_objectType aReference)
491
492 {
493 objectType result;
494
495 /* refItfToSct */
496 logFunction(printf("refItfToSct(" FMT_U_MEM ")\n",
497 (memSizeType) aReference););
498 if (unlikely(aReference == NULL ||
499 CATEGORY_OF_OBJ(aReference) != INTERFACEOBJECT ||
500 take_reference(aReference) == NULL)) {
501 logError(printf("refItfToSct(");
502 trace1(aReference);
503 printf("): Category is not INTERFACEOBJECT.\n"););
504 raise_error(RANGE_ERROR);
505 result = NULL;
506 } else {
507 result = take_reference(aReference);
508 } /* if */
509 logFunction(printf("refItfToSct --> ");
510 trace1(result);
511 printf("\n"););
512 return result;
513 } /* refItfToSct */
514
515
516
517 /**
518 * Determine the line number of a referenced object.
519 * @return the line number of the referenced object.
520 * @exception RANGE_ERROR If 'aReference' is NIL.
521 */
refLine(const const_objectType aReference)522 intType refLine (const const_objectType aReference)
523
524 {
525 intType lineNumber;
526
527 /* refLine */
528 if (unlikely(aReference == NULL)) {
529 logError(printf("refLine(NULL): Object is NULL.\n"););
530 raise_error(RANGE_ERROR);
531 lineNumber = 0;
532 } else if (HAS_POSINFO(aReference)) {
533 /* GET_LINE_NUM delivers an unsigned integer in the range 0 to 1048575 */
534 lineNumber = (intType) GET_LINE_NUM(aReference);
535 } else if (HAS_PROPERTY(aReference)) {
536 /* trace1(aReference);
537 printf(" %s %u %u\n",
538 get_file_name_ustri(aReference->descriptor.property->file_number),
539 aReference->descriptor.property->line,
540 aReference->descriptor.property->syNumberInLine); */
541 /* Cast to intType: The line is probably in the range 0 to 2147483647 */
542 lineNumber = (intType) aReference->descriptor.property->line;
543 } else {
544 lineNumber = 0;
545 } /* if */
546 return lineNumber;
547 } /* refLine */
548
549
550
551 /**
552 * Gets the local constants of 'funcRef'.
553 * @return the local constants as ref_list.
554 * @exception RANGE_ERROR If 'funcRef' is NIL or
555 * refCategory(funcRef) <> BLOCKOBJECT holds.
556 * @exception MEMORY_ERROR An out of memory situation occurred.
557 */
refLocalConsts(const const_objectType funcRef)558 listType refLocalConsts (const const_objectType funcRef)
559
560 {
561 listType local_elem;
562 listType *list_insert_place;
563 errInfoType err_info = OKAY_NO_ERROR;
564 listType localConsts = NULL;
565
566 /* refLocalConsts */
567 if (unlikely(funcRef == NULL ||
568 CATEGORY_OF_OBJ(funcRef) != BLOCKOBJECT)) {
569 logError(printf("refLocalConsts(");
570 trace1(funcRef);
571 printf("): Category is not BLOCKOBJECT.\n"););
572 raise_error(RANGE_ERROR);
573 } else {
574 list_insert_place = &localConsts;
575 local_elem = funcRef->value.blockValue->local_consts;
576 while (local_elem != NULL) {
577 list_insert_place = append_element_to_list(list_insert_place,
578 local_elem->obj, &err_info);
579 local_elem = local_elem->next;
580 } /* while */
581 if (unlikely(err_info != OKAY_NO_ERROR)) {
582 free_list(localConsts);
583 localConsts = NULL;
584 raise_error(MEMORY_ERROR);
585 } /* if */
586 } /* if */
587 return localConsts;
588 } /* refLocalConsts */
589
590
591
592 /**
593 * Gets the local variables of 'funcRef'.
594 * @return the local variables as ref_list.
595 * @exception RANGE_ERROR If 'funcRef' is NIL or
596 * refCategory(funcRef) <> BLOCKOBJECT holds.
597 * @exception MEMORY_ERROR An out of memory situation occurred.
598 */
refLocalVars(const const_objectType funcRef)599 listType refLocalVars (const const_objectType funcRef)
600
601 {
602 locListType local_elem;
603 listType *list_insert_place;
604 errInfoType err_info = OKAY_NO_ERROR;
605 listType localVars = NULL;
606
607 /* refLocalVars */
608 if (unlikely(funcRef == NULL ||
609 CATEGORY_OF_OBJ(funcRef) != BLOCKOBJECT)) {
610 logError(printf("refLocalVars(");
611 trace1(funcRef);
612 printf("): Category is not BLOCKOBJECT.\n"););
613 raise_error(RANGE_ERROR);
614 } else {
615 list_insert_place = &localVars;
616 local_elem = funcRef->value.blockValue->local_vars;
617 while (local_elem != NULL) {
618 list_insert_place = append_element_to_list(list_insert_place,
619 local_elem->local.object, &err_info);
620 local_elem = local_elem->next;
621 } /* while */
622 if (unlikely(err_info != OKAY_NO_ERROR)) {
623 free_list(localVars);
624 localVars = NULL;
625 raise_error(MEMORY_ERROR);
626 } /* if */
627 } /* if */
628 return localVars;
629 } /* refLocalVars */
630
631
632
633 /**
634 * Delivers an unique number for each object
635 * @return a unique object number.
636 * @exception MEMORY_ERROR Not enough memory to maintain the object table.
637 */
refNum(const const_objectType aReference)638 intType refNum (const const_objectType aReference)
639
640 {
641 static rtlHashType obj_table = NULL;
642 static intType next_free_number = 1;
643 intType result;
644
645 /* refNum */
646 logFunction(printf("refNum(" FMT_U_MEM ")\n", (memSizeType) aReference););
647 if (unlikely(aReference == NULL)) {
648 result = 0;
649 } else {
650 if (unlikely(obj_table == NULL)) {
651 obj_table = hshEmpty();
652 } /* if */
653 if (unlikely(obj_table == NULL)) {
654 raise_error(MEMORY_ERROR);
655 result = 0;
656 } else {
657 result = (intType) hshIdxEnterDefault(obj_table, (genericType) (memSizeType) aReference,
658 (genericType) next_free_number,
659 (intType) (((memSizeType) aReference) >> 6));
660 if (result == next_free_number) {
661 next_free_number++;
662 } /* if */
663 } /* if */
664 } /* if */
665 logFunction(printf("refNum --> " FMT_D "\n", result););
666 return result;
667 } /* refNum */
668
669
670
671 /**
672 * Get the formal parameters of the function referenced by 'funcRef'.
673 * For objects without parameters an empty list is returned.
674 * @return the formal parameters as ref_list.
675 * @exception RANGE_ERROR If 'funcRef' is NIL.
676 */
refParams(const const_objectType funcRef)677 listType refParams (const const_objectType funcRef)
678
679 {
680 listType params;
681
682 /* refParams */
683 if (unlikely(funcRef == NULL)) {
684 logError(printf("refParams(NULL): Object is NULL.\n"););
685 raise_error(RANGE_ERROR);
686 params = NULL;
687 } else {
688 if (likely(HAS_PROPERTY(funcRef))) {
689 params = funcRef->descriptor.property->params;
690 } else {
691 params = NULL;
692 } /* if */
693 } /* if */
694 return params;
695 } /* refParams */
696
697
698
699 /**
700 * Gets the initialization value of the result variable of 'funcRef'.
701 * @return a reference to the initialization value.
702 * @exception RANGE_ERROR If 'funcRef' is NIL or
703 * refCategory(funcRef) <> BLOCKOBJECT holds.
704 */
refResini(const const_objectType funcRef)705 objectType refResini (const const_objectType funcRef)
706
707 {
708 objectType result;
709
710 /* refResini */
711 if (unlikely(funcRef == NULL ||
712 CATEGORY_OF_OBJ(funcRef) != BLOCKOBJECT)) {
713 logError(printf("refResini(");
714 trace1(funcRef);
715 printf("): Category is not BLOCKOBJECT.\n"););
716 raise_error(RANGE_ERROR);
717 result = NULL;
718 } else {
719 result = funcRef->value.blockValue->result.init_value;
720 } /* if */
721 return result;
722 } /* refResini */
723
724
725
726 /**
727 * Gets the result variable of 'funcRef'.
728 * @return a reference to the result variable.
729 * @exception RANGE_ERROR If 'funcRef' is NIL or
730 * refCategory(funcRef) <> BLOCKOBJECT holds.
731 */
refResult(const const_objectType funcRef)732 objectType refResult (const const_objectType funcRef)
733
734 {
735 objectType result;
736
737 /* refResult */
738 if (unlikely(funcRef == NULL ||
739 CATEGORY_OF_OBJ(funcRef) != BLOCKOBJECT)) {
740 logError(printf("refResult(");
741 trace1(funcRef);
742 printf("): Category is not BLOCKOBJECT.\n"););
743 raise_error(RANGE_ERROR);
744 result = NULL;
745 } else {
746 result = funcRef->value.blockValue->result.object;
747 } /* if */
748 return result;
749 } /* refResult */
750
751
752
refSctToList(const const_objectType aReference)753 listType refSctToList (const const_objectType aReference)
754
755 {
756 errInfoType err_info = OKAY_NO_ERROR;
757 listType result;
758
759 /* refSctToList */
760 if (unlikely(aReference == NULL ||
761 CATEGORY_OF_OBJ(aReference) != STRUCTOBJECT)) {
762 logError(printf("refSctToList(");
763 trace1(aReference);
764 printf("): Category is not STRUCTOBJECT.\n"););
765 raise_error(RANGE_ERROR);
766 result = NULL;
767 } else {
768 result = struct_to_list(take_struct(aReference), &err_info);
769 if (unlikely(err_info != OKAY_NO_ERROR)) {
770 raise_error(MEMORY_ERROR);
771 result = NULL;
772 } /* if */
773 } /* if */
774 return result;
775 } /* refSctToList */
776
777
778
779 /**
780 * Set the category of 'aReference' to 'aCategory'.
781 * @exception RANGE_ERROR If 'aReference' is NIL.
782 */
refSetCategory(objectType aReference,intType aCategory)783 void refSetCategory (objectType aReference, intType aCategory)
784
785 { /* refSetCategory */
786 logFunction(printf("refSetCategory(");
787 trace1(aReference);
788 printf(", " FMT_D ")\n", aCategory););
789 if (unlikely(aReference == NULL)) {
790 logError(printf("refSetCategory(NULL, " FMT_D "): Object is NULL.\n",
791 aCategory););
792 raise_error(RANGE_ERROR);
793 } else {
794 SET_CATEGORY_OF_OBJ(aReference, aCategory);
795 } /* if */
796 } /* refSetCategory */
797
798
799
800 /**
801 * Set the formal parameters of 'funcRef' to 'params'.
802 * @exception RANGE_ERROR If 'funcRef' is NIL.
803 * @exception MEMORY_ERROR An out of memory situation occurred.
804 */
refSetParams(objectType funcRef,const_listType params)805 void refSetParams (objectType funcRef, const_listType params)
806
807 {
808 errInfoType err_info = OKAY_NO_ERROR;
809
810 /* refSetParams */
811 logFunction(printf("refSetParams(");
812 trace1(funcRef);
813 printf(", ");
814 prot_list(params);
815 printf(")\n"););
816 if (unlikely(funcRef == NULL)) {
817 logError(printf("refSetParams(NULL, " FMT_U_MEM "): Object is NULL.\n",
818 (memSizeType) params););
819 raise_error(RANGE_ERROR);
820 } else {
821 if (HAS_PROPERTY(funcRef)) {
822 free_list(funcRef->descriptor.property->params);
823 funcRef->descriptor.property->params = copy_list(params, &err_info);
824 } /* if */
825 if (CATEGORY_OF_OBJ(funcRef) == BLOCKOBJECT) {
826 funcRef->value.blockValue->params =
827 get_param_list(params, &err_info);
828 } /* if */
829 if (unlikely(err_info != OKAY_NO_ERROR)) {
830 raise_error(MEMORY_ERROR);
831 } /* if */
832 } /* if */
833 } /* refSetParams */
834
835
836
837 /**
838 * Set the type of 'aReference' to 'aType'.
839 * @exception RANGE_ERROR If 'aReference' is NIL.
840 */
refSetType(objectType aReference,typeType aType)841 void refSetType (objectType aReference, typeType aType)
842
843 { /* refSetType */
844 if (unlikely(aReference == NULL)) {
845 logError(printf("refSetType(NULL, " FMT_U_MEM "): Object is NULL.\n",
846 (memSizeType) aType););
847 raise_error(RANGE_ERROR);
848 } else {
849 aReference->type_of = aType;
850 } /* if */
851 } /* refSetType */
852
853
854
855 /**
856 * Set var flag of a referenced object.
857 * @exception RANGE_ERROR If 'aReference' is NIL.
858 */
refSetVar(objectType aReference,boolType var_flag)859 void refSetVar (objectType aReference, boolType var_flag)
860
861 { /* refSetVar */
862 if (unlikely(aReference == NULL)) {
863 logError(printf("refSetVar(NULL, %s): Object is NULL.\n",
864 var_flag ? "TRUE" : "FALSE"););
865 raise_error(RANGE_ERROR);
866 } else if (var_flag) {
867 SET_VAR_FLAG(aReference);
868 } else {
869 CLEAR_VAR_FLAG(aReference);
870 } /* if */
871 } /* refSetVar */
872
873
874
refStr(const const_objectType aReference)875 striType refStr (const const_objectType aReference)
876
877 {
878 const_cstriType stri;
879 memSizeType buffer_len;
880 char *buffer;
881 listType name_elem;
882 objectType param_obj;
883 errInfoType err_info = OKAY_NO_ERROR;
884 striType result;
885
886 /* refStr */
887 buffer = NULL;
888 if (aReference == NULL) {
889 stri = " *NULL_OBJECT* ";
890 } else if (HAS_POSINFO(aReference)) {
891 stri = (const_cstriType) get_file_name_ustri(GET_FILE_NUM(aReference));
892 buffer_len = (memSizeType) strlen(stri) + 32;
893 if (unlikely(!ALLOC_CSTRI(buffer, buffer_len))) {
894 raise_error(MEMORY_ERROR);
895 return NULL;
896 } else {
897 sprintf(buffer, "%s(%u)", stri, GET_LINE_NUM(aReference));
898 stri = buffer;
899 } /* if */
900 } else if (!HAS_ENTITY(aReference)) {
901 stri = " *NULL_ENTITY_OBJECT* ";
902 } else if (GET_ENTITY(aReference)->ident != NULL) {
903 stri = id_string2(GET_ENTITY(aReference)->ident);
904 } else {
905 stri = NULL;
906 name_elem = GET_ENTITY(aReference)->fparam_list;
907 while (name_elem != NULL && stri == NULL) {
908 if (CATEGORY_OF_OBJ(name_elem->obj) == FORMPARAMOBJECT) {
909 param_obj = name_elem->obj->value.objValue;
910 if (CATEGORY_OF_OBJ(param_obj) != VALUEPARAMOBJECT &&
911 CATEGORY_OF_OBJ(param_obj) != REFPARAMOBJECT &&
912 CATEGORY_OF_OBJ(param_obj) != TYPEOBJECT) {
913 stri = id_string2(GET_ENTITY(param_obj)->ident);
914 } /* if */
915 } else {
916 stri = id_string2(GET_ENTITY(name_elem->obj)->ident);
917 } /* if */
918 name_elem = name_elem->next;
919 } /* while */
920 if (stri == NULL) {
921 stri = " *UNKNOWN_NAME* ";
922 } /* if */
923 } /* if */
924 result = cstri8_to_stri(stri, &err_info);
925 if (buffer != NULL) {
926 UNALLOC_CSTRI(buffer, buffer_len);
927 } /* if */
928 if (unlikely(result == NULL)) {
929 raise_error(MEMORY_ERROR);
930 } /* if */
931 return result;
932 } /* refStr */
933
934
935
936 /**
937 * Get the type of the referenced object.
938 * @return the type of the object referenced by 'aReference'.
939 */
refType(const const_objectType aReference)940 typeType refType (const const_objectType aReference)
941
942 {
943 typeType result;
944
945 /* refType */
946 logFunction(printf("refType(");
947 trace1(aReference);
948 printf(")\n"););
949 if (unlikely(aReference == NULL ||
950 aReference->type_of == NULL)) {
951 logError(printf("refType(NULL): Object is NULL.\n"););
952 raise_error(RANGE_ERROR);
953 result = NULL;
954 } else {
955 result = aReference->type_of;
956 } /* if */
957 logFunction(printf("refType --> " FMT_X_MEM "\n", (memSizeType) result););
958 return result;
959 } /* refType */
960
961
962
963 /**
964 * Get 'ACTION' value of the object referenced by 'aReference'.
965 * @return the 'ACTION' value of the referenced object.
966 * @exception RANGE_ERROR If 'aReference' is NIL or
967 * category(aReference) <> ACTOBJECT holds.
968 */
actValue(const const_objectType aReference)969 actType actValue (const const_objectType aReference)
970
971 { /* actValue */
972 if (unlikely(aReference == NULL ||
973 CATEGORY_OF_OBJ(aReference) != ACTOBJECT)) {
974 logError(printf("actValue(");
975 trace1(aReference);
976 printf("): Category is not ACTOBJECT.\n"););
977 raise_error(RANGE_ERROR);
978 return NULL;
979 } else {
980 return take_action(aReference);
981 } /* if */
982 } /* actValue */
983
984
985
986 /**
987 * Get 'bigInteger' value of the object referenced by 'aReference'.
988 * @return the 'bigInteger' value of the referenced object.
989 * @exception RANGE_ERROR If 'aReference' is NIL or
990 * category(aReference) <> BIGINTOBJECT holds.
991 */
bigValue(const const_objectType aReference)992 bigIntType bigValue (const const_objectType aReference)
993
994 { /* bigValue */
995 if (unlikely(aReference == NULL ||
996 CATEGORY_OF_OBJ(aReference) != BIGINTOBJECT)) {
997 logError(printf("bigValue(");
998 trace1(aReference);
999 printf("): Category is not BIGINTOBJECT.\n"););
1000 raise_error(RANGE_ERROR);
1001 return NULL;
1002 } else {
1003 return bigCreate(take_bigint(aReference));
1004 } /* if */
1005 } /* bigValue */
1006
1007
1008
1009 /**
1010 * Get 'boolean' value of the object referenced by 'aReference'.
1011 * @return the 'boolean' value of the referenced object.
1012 * @exception RANGE_ERROR If 'aReference' is NIL or
1013 * if it references neither TRUE nor FALSE.
1014 */
blnValue(const_objectType aReference)1015 boolType blnValue (const_objectType aReference)
1016
1017 { /* blnValue */
1018 if (aReference != NULL) {
1019 if (CATEGORY_OF_OBJ(aReference) == CONSTENUMOBJECT ||
1020 CATEGORY_OF_OBJ(aReference) == VARENUMOBJECT) {
1021 aReference = aReference->value.objValue;
1022 } /* if */
1023 if (aReference->type_of != NULL &&
1024 aReference->type_of->owningProg != NULL) {
1025 if (aReference == TRUE_OBJECT(aReference->type_of->owningProg)) {
1026 return TRUE;
1027 } else if (aReference == FALSE_OBJECT(aReference->type_of->owningProg)) {
1028 return FALSE;
1029 } /* if */
1030 } /* if */
1031 } /* if */
1032 logError(printf("blnValue(");
1033 trace1(aReference);
1034 printf("): Value neither TRUE nor FALSE.\n"););
1035 raise_error(RANGE_ERROR);
1036 return FALSE;
1037 } /* blnValue */
1038
1039
1040
1041 /**
1042 * Get 'bstring' value of the object referenced by 'aReference'.
1043 * @return the 'bstring' value of the referenced object.
1044 * @exception RANGE_ERROR If 'aReference' is NIL or
1045 * category(aReference) <> BSTRIOBJECT holds.
1046 */
bstValue(const const_objectType aReference)1047 bstriType bstValue (const const_objectType aReference)
1048
1049 {
1050 bstriType bstri;
1051 bstriType result;
1052
1053 /* bstValue */
1054 if (unlikely(aReference == NULL ||
1055 CATEGORY_OF_OBJ(aReference) != BSTRIOBJECT ||
1056 (bstri = take_bstri(aReference)) == NULL)) {
1057 logError(printf("bstValue(");
1058 trace1(aReference);
1059 printf("): Category is not BSTRIOBJECT.\n"););
1060 raise_error(RANGE_ERROR);
1061 result = NULL;
1062 } else {
1063 if (unlikely(!ALLOC_BSTRI_SIZE_OK(result, bstri->size))) {
1064 raise_error(MEMORY_ERROR);
1065 } else {
1066 result->size = bstri->size;
1067 memcpy(result->mem, bstri->mem, (size_t) (result->size));
1068 } /* if */
1069 } /* if */
1070 return result;
1071 } /* bstValue */
1072
1073
1074
1075 /**
1076 * Get 'char' value of the object referenced by 'aReference'.
1077 * @return the 'char' value of the referenced object.
1078 * @exception RANGE_ERROR If 'aReference' is NIL or
1079 * category(aReference) <> CHAROBJECT holds.
1080 */
chrValue(const const_objectType aReference)1081 charType chrValue (const const_objectType aReference)
1082
1083 { /* chrValue */
1084 if (unlikely(aReference == NULL ||
1085 CATEGORY_OF_OBJ(aReference) != CHAROBJECT)) {
1086 logError(printf("chrValue(");
1087 trace1(aReference);
1088 printf("): Category is not CHAROBJECT.\n"););
1089 raise_error(RANGE_ERROR);
1090 return '\0';
1091 } else {
1092 return take_char(aReference);
1093 } /* if */
1094 } /* chrValue */
1095
1096
1097
1098 /**
1099 * Get 'PRIMITIVE_WINDOW' value of the object referenced by 'aReference'.
1100 * @return the 'PRIMITIVE_WINDOW' value of the referenced object.
1101 * @exception RANGE_ERROR If 'aReference' is NIL or
1102 * category(aReference) <> WINOBJECT holds.
1103 */
drwValue(const const_objectType aReference)1104 winType drwValue (const const_objectType aReference)
1105
1106 {
1107 winType win_value;
1108
1109 /* drwValue */
1110 if (unlikely(aReference == NULL ||
1111 CATEGORY_OF_OBJ(aReference) != WINOBJECT)) {
1112 logError(printf("drwValue(");
1113 trace1(aReference);
1114 printf("): Category is not WINOBJECT.\n"););
1115 raise_error(RANGE_ERROR);
1116 return NULL;
1117 } else {
1118 win_value = take_win(aReference);
1119 if (win_value != NULL) {
1120 win_value->usage_count++;
1121 } /* if */
1122 return win_value;
1123 } /* if */
1124 } /* drwValue */
1125
1126
1127
1128 /**
1129 * Get 'clib_file' value of the object referenced by 'aReference'.
1130 * @return the 'clib_file' value of the referenced object.
1131 * @exception RANGE_ERROR If 'aReference' is NIL or
1132 * category(aReference) <> FILEOBJECT holds.
1133 */
filValue(const const_objectType aReference)1134 fileType filValue (const const_objectType aReference)
1135
1136 { /* filValue */
1137 if (unlikely(aReference == NULL ||
1138 CATEGORY_OF_OBJ(aReference) != FILEOBJECT)) {
1139 logError(printf("filValue(");
1140 trace1(aReference);
1141 printf("): Category is not FILEOBJECT.\n"););
1142 raise_error(RANGE_ERROR);
1143 return NULL;
1144 } else {
1145 return take_file(aReference);
1146 } /* if */
1147 } /* filValue */
1148
1149
1150
1151 /**
1152 * Get 'float' value of the object referenced by 'aReference'.
1153 * @return the 'float' value of the referenced object.
1154 * @exception RANGE_ERROR If 'aReference' is NIL or
1155 * category(aReference) <> FLOATOBJECT holds.
1156 */
fltValue(const const_objectType aReference)1157 floatType fltValue (const const_objectType aReference)
1158
1159 { /* fltValue */
1160 if (unlikely(aReference == NULL ||
1161 CATEGORY_OF_OBJ(aReference) != FLOATOBJECT)) {
1162 logError(printf("fltValue(");
1163 trace1(aReference);
1164 printf("): Category is not FLOATOBJECT.\n"););
1165 raise_error(RANGE_ERROR);
1166 return 0.0;
1167 } else {
1168 return take_float(aReference);
1169 } /* if */
1170 } /* fltValue */
1171
1172
1173
1174 /**
1175 * Get 'integer' value of the object referenced by 'aReference'.
1176 * @return the 'integer' value of the referenced object.
1177 * @exception RANGE_ERROR If 'aReference' is NIL or
1178 * category(aReference) <> INTOBJECT holds.
1179 */
intValue(const const_objectType aReference)1180 intType intValue (const const_objectType aReference)
1181
1182 { /* intValue */
1183 if (unlikely(aReference == NULL ||
1184 CATEGORY_OF_OBJ(aReference) != INTOBJECT)) {
1185 logError(printf("intValue(");
1186 trace1(aReference);
1187 printf("): Category is not INTOBJECT.\n"););
1188 raise_error(RANGE_ERROR);
1189 return 0;
1190 } else {
1191 return take_int(aReference);
1192 } /* if */
1193 } /* intValue */
1194
1195
1196
1197 /**
1198 * Get 'process' value of the object referenced by 'aReference'.
1199 * @return the 'process' value of the referenced object.
1200 * @exception RANGE_ERROR If 'aReference' is NIL or
1201 * category(aReference) <> PROCESSOBJECT holds.
1202 */
pcsValue(const const_objectType aReference)1203 processType pcsValue (const const_objectType aReference)
1204
1205 {
1206 processType process_value;
1207
1208 /* pcsValue */
1209 if (unlikely(aReference == NULL ||
1210 CATEGORY_OF_OBJ(aReference) != PROCESSOBJECT)) {
1211 logError(printf("pcsValue(");
1212 trace1(aReference);
1213 printf("): Category is not PROCESSOBJECT.\n"););
1214 raise_error(RANGE_ERROR);
1215 return NULL;
1216 } else {
1217 process_value = take_process(aReference);
1218 if (process_value != NULL) {
1219 process_value->usage_count++;
1220 } /* if */
1221 return process_value;
1222 } /* if */
1223 } /* pcsValue */
1224
1225
1226
1227 /**
1228 * Get 'pollData' value of the object referenced by 'aReference'.
1229 * @return the 'pollData' value of the referenced object.
1230 * @exception RANGE_ERROR If 'aReference' is NIL or
1231 * category(aReference) <> POLLOBJECT holds.
1232 */
polValue(const const_objectType aReference)1233 pollType polValue (const const_objectType aReference)
1234
1235 { /* polValue */
1236 if (unlikely(aReference == NULL ||
1237 CATEGORY_OF_OBJ(aReference) != POLLOBJECT)) {
1238 logError(printf("polValue(");
1239 trace1(aReference);
1240 printf("): Category is not POLLOBJECT.\n"););
1241 raise_error(RANGE_ERROR);
1242 return NULL;
1243 } else {
1244 return polCreate(take_poll(aReference));
1245 } /* if */
1246 } /* polValue */
1247
1248
1249
1250 /**
1251 * Get 'program' value of the object referenced by 'aReference'.
1252 * @return the 'program' value of the referenced object.
1253 * @exception RANGE_ERROR If 'aReference' is NIL or
1254 * category(aReference) <> PROGOBJECT holds.
1255 */
prgValue(const const_objectType aReference)1256 progType prgValue (const const_objectType aReference)
1257
1258 { /* prgValue */
1259 if (unlikely(aReference == NULL ||
1260 CATEGORY_OF_OBJ(aReference) != PROGOBJECT)) {
1261 logError(printf("prgValue(");
1262 trace1(aReference);
1263 printf("): Category is not PROGOBJECT.\n"););
1264 raise_error(RANGE_ERROR);
1265 return NULL;
1266 } else {
1267 return take_prog(aReference);
1268 } /* if */
1269 } /* prgValue */
1270
1271
1272
refValue(const const_objectType aReference)1273 objectType refValue (const const_objectType aReference)
1274
1275 { /* refValue */
1276 if (likely(aReference != NULL &&
1277 (CATEGORY_OF_OBJ(aReference) == FWDREFOBJECT ||
1278 CATEGORY_OF_OBJ(aReference) == REFOBJECT ||
1279 CATEGORY_OF_OBJ(aReference) == REFPARAMOBJECT ||
1280 CATEGORY_OF_OBJ(aReference) == RESULTOBJECT ||
1281 CATEGORY_OF_OBJ(aReference) == LOCALVOBJECT ||
1282 CATEGORY_OF_OBJ(aReference) == ENUMLITERALOBJECT ||
1283 CATEGORY_OF_OBJ(aReference) == CONSTENUMOBJECT ||
1284 CATEGORY_OF_OBJ(aReference) == VARENUMOBJECT))) {
1285 return take_reference(aReference);
1286 } else {
1287 logError(printf("refValue(");
1288 trace1(aReference);
1289 printf("): Category is not a reference object.\n"););
1290 raise_error(RANGE_ERROR);
1291 return NULL;
1292 } /* if */
1293 } /* refValue */
1294
1295
1296
rflValue(const const_objectType aReference)1297 listType rflValue (const const_objectType aReference)
1298
1299 {
1300 errInfoType err_info = OKAY_NO_ERROR;
1301 listType result;
1302
1303 /* rflValue */
1304 if (likely(aReference != NULL &&
1305 (CATEGORY_OF_OBJ(aReference) == MATCHOBJECT ||
1306 CATEGORY_OF_OBJ(aReference) == CALLOBJECT ||
1307 CATEGORY_OF_OBJ(aReference) == REFLISTOBJECT))) {
1308 result = copy_list(take_reflist(aReference), &err_info);
1309 if (unlikely(result == NULL && err_info != OKAY_NO_ERROR)) {
1310 raise_error(MEMORY_ERROR);
1311 result = NULL;
1312 } /* if */
1313 } else {
1314 logError(printf("rflValue(");
1315 trace1(aReference);
1316 printf("): Category is not a reference list object.\n"););
1317 raise_error(RANGE_ERROR);
1318 result = NULL;
1319 } /* if */
1320 return result;
1321 } /* rflValue */
1322
1323
1324
rflSetValue(objectType dest,listType source)1325 void rflSetValue (objectType dest, listType source)
1326
1327 {
1328 listType help_list;
1329 errInfoType err_info = OKAY_NO_ERROR;
1330
1331 /* rflSetValue */
1332 if (likely(CATEGORY_OF_OBJ(dest) == MATCHOBJECT ||
1333 CATEGORY_OF_OBJ(dest) == CALLOBJECT ||
1334 CATEGORY_OF_OBJ(dest) == REFLISTOBJECT)) {
1335 help_list = copy_list(source, &err_info);
1336 if (unlikely(err_info != OKAY_NO_ERROR)) {
1337 raise_error(MEMORY_ERROR);
1338 } else {
1339 free_list(take_reflist(dest));
1340 dest->value.listValue = help_list;
1341 } /* if */
1342 } else {
1343 logError(printf("rflSetValue(");
1344 trace1(dest);
1345 printf(", *): Category is not a reference list object.\n"););
1346 raise_error(RANGE_ERROR);
1347 } /* if */
1348 } /* rflSetValue */
1349
1350
1351
1352 /**
1353 * Get 'bitset' value of the object referenced by 'aReference'.
1354 * @return the 'bitset' value of the referenced object.
1355 * @exception RANGE_ERROR If 'aReference' is NIL or
1356 * category(aReference) <> SETOBJECT holds.
1357 */
setValue(const const_objectType aReference)1358 setType setValue (const const_objectType aReference)
1359
1360 {
1361 setType set1;
1362 memSizeType set_size;
1363 setType result;
1364
1365 /* setValue */
1366 if (unlikely(aReference == NULL ||
1367 CATEGORY_OF_OBJ(aReference) != SETOBJECT ||
1368 (set1 = take_set(aReference)) == NULL)) {
1369 logError(printf("setValue(");
1370 trace1(aReference);
1371 printf("): Category is not SETOBJECT.\n"););
1372 raise_error(RANGE_ERROR);
1373 result = NULL;
1374 } else {
1375 set_size = bitsetSize(set1);
1376 if (unlikely(!ALLOC_SET(result, set_size))) {
1377 raise_error(MEMORY_ERROR);
1378 } else {
1379 result->min_position = set1->min_position;
1380 result->max_position = set1->max_position;
1381 memcpy(result->bitset, set1->bitset, set_size * sizeof(bitSetType));
1382 } /* if */
1383 } /* if */
1384 return result;
1385 } /* setValue */
1386
1387
1388
1389 /**
1390 * Get 'string' value of the object referenced by 'aReference'.
1391 * @return the 'string' value of the referenced object.
1392 * @exception RANGE_ERROR If 'aReference' is NIL or
1393 * category(aReference) <> STRIOBJECT holds.
1394 */
strValue(const const_objectType aReference)1395 striType strValue (const const_objectType aReference)
1396
1397 {
1398 striType stri;
1399 striType result;
1400
1401 /* strValue */
1402 logFunction(printf("strValue(");
1403 trace1(aReference);
1404 printf(")\n"););
1405 if (unlikely(aReference == NULL ||
1406 CATEGORY_OF_OBJ(aReference) != STRIOBJECT ||
1407 (stri = take_stri(aReference)) == NULL)) {
1408 logError(printf("strValue(");
1409 trace1(aReference);
1410 printf("): Category is not STRIOBJECT.\n"););
1411 raise_error(RANGE_ERROR);
1412 result = NULL;
1413 } else {
1414 if (unlikely(!ALLOC_STRI_SIZE_OK(result, stri->size))) {
1415 raise_error(MEMORY_ERROR);
1416 } else {
1417 result->size = stri->size;
1418 memcpy(result->mem, stri->mem,
1419 (size_t) (result->size * sizeof(strElemType)));
1420 } /* if */
1421 } /* if */
1422 logFunction(printf("strValue --> \"%s\"\n",
1423 striAsUnquotedCStri(result)););
1424 return result;
1425 } /* strValue */
1426
1427
1428
1429 /**
1430 * Get 'string' value of the object referenced by 'aReference'.
1431 * @return the 'string' value of the referenced object.
1432 * @exception RANGE_ERROR If 'aReference' is NIL or
1433 * category(aReference) <> STRIOBJECT holds.
1434 */
strValueRef(const const_objectType aReference)1435 const_striType strValueRef (const const_objectType aReference)
1436
1437 {
1438 striType stri;
1439 striType result;
1440
1441 /* strValueRef */
1442 logFunction(printf("strValueRef(");
1443 trace1(aReference);
1444 printf(")\n"););
1445 if (unlikely(aReference == NULL ||
1446 CATEGORY_OF_OBJ(aReference) != STRIOBJECT ||
1447 (stri = take_stri(aReference)) == NULL)) {
1448 logError(printf("strValueRef(");
1449 trace1(aReference);
1450 printf("): Category is not STRIOBJECT.\n"););
1451 raise_error(RANGE_ERROR);
1452 result = NULL;
1453 } else {
1454 result = stri;
1455 } /* if */
1456 logFunction(printf("strValueRef --> \"%s\"\n",
1457 striAsUnquotedCStri(result)););
1458 return result;
1459 } /* strValueRef */
1460
1461
1462
1463 /**
1464 * Get 'type' value of the object referenced by 'aReference'.
1465 * @return the 'type' value of the referenced object.
1466 * @exception RANGE_ERROR If 'aReference' is NIL or
1467 * category(aReference) <> TYPEOBJECT holds.
1468 */
typValue(const const_objectType aReference)1469 typeType typValue (const const_objectType aReference)
1470
1471 {
1472 typeType result;
1473
1474 /* typValue */
1475 logFunction(printf("refValue(");
1476 trace1(aReference);
1477 printf(")\n"););
1478 if (unlikely(aReference == NULL ||
1479 CATEGORY_OF_OBJ(aReference) != TYPEOBJECT)) {
1480 logError(printf("typValue(");
1481 trace1(aReference);
1482 printf("): Category is not TYPEOBJECT.\n"););
1483 raise_error(RANGE_ERROR);
1484 result = NULL;
1485 } else {
1486 result = take_type(aReference);
1487 } /* if */
1488 logFunction(printf("typValue --> " FMT_X_MEM "\n", (memSizeType) result););
1489 return result;
1490 } /* typValue */
1491