-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathselects.c
More file actions
1947 lines (1706 loc) · 72.1 KB
/
selects.c
File metadata and controls
1947 lines (1706 loc) · 72.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
** \file selects.c
** FedEx parser output module for generating C++ class definitions
** The functions in this file gener*ate C++ code for representing EXPRESS SELECT types.
**
** K. C. Morris
**
** Development of FedEx was funded by the United States Government,
** and is not subject to copyright.
*******************************************************************
The conventions used in this binding follow the proposed specification
for the STEP Standard Data Access Interface as defined in document
N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
*******************************************************************/
extern int multiple_inheritance;
#include <stdlib.h>
#include "classes.h"
#include "classes_type.h"
#include "classes_attribute.h"
#include "./trace_fprintf.h"
#define BASE_SELECT "SDAI_Select"
#define TYPEis_primitive(t) ( !( TYPEis_entity(t) || \
TYPEis_select (t) || \
TYPEis_aggregate(t) ) )
#define TYPEis_numeric(t) ( ((t)->u.type->body->type == real_) || \
((t)->u.type->body->type == integer_) || \
((t)->u.type->body->type == number_) )
#define PRINT_BUG_REPORT \
fprintf( f, "std::cerr << __FILE__ << \":\" << __LINE__ << \": ERROR" \
" in schema library: \\n\" \n << _POC_ << \"\\n\\n\";\n");
#define PRINT_SELECTBUG_WARNING(f) \
fprintf( (f), "\n severity( SEVERITY_WARNING );\n" ); \
fprintf( (f), " std::cerr << __FILE__ << \":\" << __LINE__ << \": "); \
fprintf( (f), "WARNING: possible misuse of\"\n << \" SELECT "); \
fprintf( (f), "TYPE from schema library.\\n\";\n"); \
fprintf( (f), " Error( \"Mismatch in underlying type.\" );\n" );
#define print_error_msg() \
fprintf( f, "\n severity( SEVERITY_BUG );\n" ); \
PRINT_BUG_REPORT \
fprintf( f, " Error( \"This 'argument' is of the incorrect type\" );\n" );
#define TRUE 1
#define FALSE 0
static void initSelItems( const Type, FILE * );
const char * SEL_ITEMget_enumtype( Type t ) {
return StrToUpper( TYPEget_name( t ) );
}
/** \returns type used to represent the underlying type in a select class
*/
const char * TYPEget_utype( Type t ) {
return ( TYPEis_entity( t ) ? "SDAI_Application_instance_ptr" : TYPEget_ctype( t ) );
}
/** determines if the given entity is a member of the list.
RETURNS the member if it is a member; otherwise 0 is returned.
*/
void *LISTmember( const Linked_List list, void *e ) {
Link node;
for( node = list->mark->next; node != list->mark; node = node->next )
if( e == node -> data ) {
return e;
}
return ( 0 );
}
/** Specialized function to catch if two enumerations, two selects, or two aggrs
of either, are of the same type. The issue is that e.g. select B may be a
rename of sel A (i.e., TYPE B = A;). Such renamed types are implemented by
exp2cxx with typedefs, so that they are in fact the same type. TYPEget_-
ctype() is used for most type comparisons and does not consider renamed types
equivalent. This function is called in instances when they should be consi-
dered equivalent. One such case is the generation of duplicate lists.
*/
static int compareOrigTypes( Type a, Type b ) {
Type t, u;
if( ( TYPEis_select( a ) && TYPEis_select( b ) )
|| ( TYPEis_enumeration( a ) && TYPEis_enumeration( b ) ) ) {
t = a;
u = b;
} else if( TYPEis_aggregate( a ) && TYPEis_aggregate( b ) ) {
t = TYPEget_base_type( a );
u = TYPEget_base_type( b );
if( !( ( TYPEis_select( t ) && TYPEis_select( u ) )
|| ( TYPEis_enumeration( t ) && TYPEis_enumeration( u ) ) ) ) {
return FALSE;
/* Only go further with 1D aggregates of sels or enums. Note that
for 2D aggrs and higher we do not continue. These are all recog-
nized to be the same type ("GenericAggregate") by TYPEget_ctype(),
and do not have to be handled specially here. */
}
} else {
return FALSE;
}
if( TYPEget_head( t ) ) {
t = TYPEget_ancestor( t );
}
if( TYPEget_head( u ) ) {
u = TYPEget_ancestor( u );
}
return ( !strcmp( TYPEget_name( t ), TYPEget_name( u ) ) );
}
/** determines if the given "link's" underlying type is a member of the list.
RETURNS the underlying type if it is a member; otherwise 0 is returned.
If "rename" is TRUE, we also consider check to match in certain cases where
list already has an item that check is a renaming of (see header comments to
compareOrigTypes() above).
*/
const char * utype_member( const Linked_List list, const Type check, int rename ) {
static char r [BUFSIZ+1];
bool checkIsEntity = TYPEis_entity( check );
LISTdo( list, t, Type ) {
if( TYPEis_entity( t ) && checkIsEntity ) {
return "SDAI_Application_instance_ptr";
}
/* string returned by TYPEget_utype isn't necessarily static so we
* need to copy between calls
* */
strncpy( r, TYPEget_ctype( t ), BUFSIZ );
if( strcmp( r, TYPEget_ctype( check ) ) == 0 || ( rename && compareOrigTypes( check, t ) ) ) {
return r;
}
}
LISTod;
return 0;
}
/** Returns a list of types which have unique underlying types
* The returned list includes all the types which have a data members
* in the select type.
*
* The list that is returned needs to be freed by the caller.
*/
Linked_List SELgetnew_dmlist( const Type type ) {
Linked_List complete = SEL_TYPEget_items( type );
Linked_List newlist = LISTcreate();
LISTdo( complete, t, Type )
/* if t\'s underlying type is not already in newlist, */
if( ! utype_member( newlist, t, 0 ) ) {
LISTadd_last( newlist, t );
}
LISTod;
return newlist;
}
const char * SEL_ITEMget_dmtype( Type t, const Linked_List l ) {
const char * r = utype_member( l, t, 0 );
return StrToLower( r ? r : TYPEget_utype( t ) );
}
/** Returns the name of the data member in the select class for the item of
* the select having the type t.
* Logical and boolean are handled as exceptions because TYPEget_utype()
* returns "PSDAI::..." for them which is not a legal variable name.
*/
const char * SEL_ITEMget_dmname( Type t ) {
Class_Of_Type class = TYPEget_type( t );
if( class == integer_ ) {
return "integer";
}
if( class == real_ ) {
return "real";
}
if( class == number_ ) {
return "real";
}
if( class == string_ ) {
return "string";
}
if( class == binary_ ) {
return "binary";
}
if( class == logical_ ) {
return "logical";
}
if( class == boolean_ ) {
return "boolean";
}
if( class == entity_ ) {
return "app_inst";
}
return ( StrToLower( TYPEget_utype( t ) ) );
}
/** determines if the given "link's" underlying type is a multiple member
of the list.
RETURNS 1 if true, else 0.
*/
int duplicate_in_express_list( const Linked_List list, const Type check ) {
if( TYPEis_entity( check ) ) {
return FALSE;
}
/* entities are never the same */
LISTdo( list, t, Type )
if( t == check ) {
; /* don't compare check to itself */
} else {
return TRUE; /* other things in the list conflict */
}
LISTod;
return FALSE;
}
/** determines if any of the types in a select type resolve to the same
underlying Express type.
RETURNS 1 if true, else 0.
*/
int unique_types( const Linked_List list ) {
LISTdo( list, t, Type )
if( duplicate_in_express_list( list, t ) ) {
return FALSE;
}
LISTod;
return TRUE;
}
/** determines if the given "link's" C++ representation is used again in the list.
RETURNS 1 if true, else 0.
*/
int duplicate_utype_member( const Linked_List list, const Type check ) {
char b [BUFSIZ+1];
if( TYPEis_entity( check ) ) {
return FALSE;
}
/* entities are never the same */
LISTdo( list, t, Type )
if( t == check ) {
;
}
/* don't compare check to itself */
else { /* continue looking */
strncpy( b, TYPEget_utype( t ), BUFSIZ );
if( ( !strcmp( b, TYPEget_utype( check ) ) )
|| ( compareOrigTypes( t, check ) ) )
/* if the underlying types are the same */
{
return TRUE;
}
if( ! strcmp( b, "SDAI_Integer" ) &&
( ! strcmp( TYPEget_utype( check ), "SDAI_Real" ) ) )
/* integer\'s and real\'s are not unique */
{
return TRUE;
}
}
LISTod;
return FALSE;
}
/** determines if any of the types in a select type resolve to the same
C++ representation for the underlying Express type.
RETURNS 1 if true, else 0.
*/
int any_duplicates_in_select( const Linked_List list ) {
LISTdo( list, t, Type )
if( duplicate_utype_member( list, t ) ) {
return TRUE;
}
LISTod;
return FALSE;
}
/** finds an instance of each kind of duplicate type found in the given list.
This list is returned as dup_list. If a duplicate exists, the function
returns TRUE, else FALSE.
list should be unbound before calling, and freed afterwards.
*/
int find_duplicate_list( const Type type, Linked_List * duplicate_list ) {
Linked_List temp; /** temporary list for comparison **/
*duplicate_list = LISTcreate();
if( any_duplicates_in_select( SEL_TYPEget_items( type ) ) ) {
/** if there is a dup somewhere **/
temp = LISTcreate();
LISTdo( SEL_TYPEget_items( type ), u, Type )
if( !utype_member( *duplicate_list, u, 1 ) ) {
/** if not already a duplicate **/
if( utype_member( temp, u, 1 ) ) {
LISTadd_first( *duplicate_list, u );
} else {
LISTadd_first( temp, u );
}
}
LISTod;
LISTfree( temp );
return TRUE;
}
return FALSE;
}
/** In the functions below, we use a vector of ints to count paths in the
select-graph to base types. The names in this enum correspond to the
indices in the vector, i.e., tvec[treal] == tvec[1], and contains the
number of paths to REAL in the graph
*/
enum __types {
tint = 0, /* INTEGER */
treal, /* REAL */
tstring, /* STRING */
tbinary, /* BINARY */
tenum, /* ENUMERATION, also LOGICAL, BOOLEAN */
tselect, /* SELECT */
tentity, /* ENTITY */
taggr, /* AGGREGATE, also ARRAY, BAG, SET, LIST */
tnumber /* NUMBER */
};
/** This function gets called recursively, to follow a select-graph to its
leaves. It passes around the vector described above, to track paths to
the leaf nodes.
*/
void non_unique_types_vector( const Type type, int * tvec ) {
LISTdo( SEL_TYPEget_items( type ), t, Type )
switch( TYPEget_body( t )->type ) {
case integer_:
tvec[tint]++;
break;
case real_:
tvec[treal]++;
break;
case string_:
tvec[tstring]++;
break;
case binary_:
tvec[tbinary]++;
break;
case enumeration_:
case logical_:
case boolean_:
tvec[tenum]++;
break;
case select_:
/* SELECT, ergo recurse! */
non_unique_types_vector( t, tvec );
break;
case entity_:
tvec[tentity]++;
break;
case aggregate_:
case array_:
case list_:
case bag_:
case set_:
tvec[taggr]++;
break;
case number_:
tvec[tnumber]++;
break;
default:
fprintf( stderr, "non_unique_types_vector: can't handle unknown type %d\n",
TYPEget_body( t )->type );
abort();
}
LISTod;
}
/** Uses non_unique_types_vector on the select to get a vector of base-type
reference counts, then uses that to make a string of types, of the form
(FOO_TYPE | BAR_TYPE | BAZ_TYPE), where FOO, BAR, and BAZ are EXPRESS
types. If all types are unique, the string (0) is generated.
*/
char * non_unique_types_string( const Type type ) {
int tvec[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
char * typestr;
int first = 1;
int i;
non_unique_types_vector( type, tvec );
/* build type string from vector */
typestr = ( char * )malloc( BUFSIZ + 1 );
typestr[0] = '\0';
strcat( typestr, ( char * )"(" );
for( i = 0; i <= tnumber; i++ ) {
if( tvec[i] < 2 ) {
continue; /* skip, this one is unique */
}
if( !first ) {
strcat( typestr, ( char * )" | " );
} else {
first = 0;
}
switch( i ) {
case tint :
strcat( typestr, ( char * )"sdaiINTEGER" );
break;
case treal :
strcat( typestr, ( char * )"sdaiREAL" );
break;
case tstring:
strcat( typestr, ( char * )"sdaiSTRING" );
break;
case tbinary:
strcat( typestr, ( char * )"sdaiBINARY" );
break;
case tenum :
strcat( typestr, ( char * )"sdaiENUMERATION" );
break;
case tentity:
strcat( typestr, ( char * )"sdaiINSTANCE" );
break;
case taggr :
strcat( typestr, ( char * )"sdaiAGGR" );
break;
case tnumber:
strcat( typestr, ( char * )"sdaiNUMBER" );
break;
}
}
if( first ) {
strcat( typestr, ( char * )"0" );
}
strcat( typestr, ( char * )")" );
return typestr;
}
/** checks to see if an attribute is a member of the list
* \returns the attribute 'check' if an attribute with the same name is on the list, 0 otherwise
*/
Variable ATTR_LISTmember( Linked_List l, Variable check ) {
char nm [BUFSIZ+1];
char cur [BUFSIZ+1];
generate_attribute_name( check, nm );
LISTdo( l, a, Variable ) {
generate_attribute_name( a, cur );
if( ! strcmp( nm, cur ) ) {
return check;
}
} LISTod;
return ( 0 );
}
/** \returns a list that is the union of all the attributes for a select type.
* Side Effects:
* The list that is returned needs to be freed by the caller.
*/
Linked_List SEL_TYPEgetnew_attribute_list( const Type type ) {
Linked_List complete = SEL_TYPEget_items( type );
Linked_List newlist = LISTcreate();
Linked_List attrs;
Entity cur;
LISTdo( complete, t, Type ) {
if( TYPEis_entity( t ) ) {
cur = ENT_TYPEget_entity( t );
attrs = ENTITYget_all_attributes( cur );
LISTdo_n( attrs, a, Variable, b ) {
if( ! ATTR_LISTmember( newlist, a ) ) {
LISTadd_first( newlist, a );
}
} LISTod
}
} LISTod
return newlist;
}
/** prints the class 'definition', that is, the objects
* and the constructor(s)/destructor for a select class.
*/
void TYPEselect_inc_print_vars( const Type type, FILE * f, Linked_List dups ) {
int size, j;
Linked_List data_members = SELgetnew_dmlist( type );
char dmname [BUFSIZ+1],
classnm [BUFSIZ+1],
tdnm [BUFSIZ+1];
strncpy( classnm, SelectName( TYPEget_name( type ) ), BUFSIZ );
classnm[BUFSIZ-1] = '\0';
strncpy( tdnm, TYPEtd_name( type ), BUFSIZ );
tdnm[BUFSIZ-1] = '\0';
size = strlen( classnm ) + 2; /* for formatting output */
fprintf( f, "\n////////// SELECT TYPE %s\n", SelectName( TYPEget_name( type ) ) );
fprintf( f, "class SC_SCHEMA_EXPORT %s : public " BASE_SELECT " {\n", classnm );
fprintf( f, " protected:\n" );
fprintf( f, " // types in SELECT \n" );
LISTdo( SEL_TYPEget_items( type ), t, Type ) {
fprintf( f, " // %s -- %s\n", SEL_ITEMget_enumtype( t ), FundamentalType( t, 0 ) );
}
LISTod;
LISTdo( data_members, t, Type ) {
strncpy( dmname, SEL_ITEMget_dmname( t ), BUFSIZ );
fprintf( f, " %s%s _%s;\n", TYPEget_utype( t ), TYPEis_aggregate( t ) ? "_ptr" : "", dmname );
}
LISTod;
fprintf( f, "\n public:\n" );
fprintf( f,
" virtual const TypeDescriptor * AssignEntity (SDAI_Application_instance * se);\n"
" virtual SDAI_Select * NewSelect ();\n"
);
fprintf( f, "\n virtual BASE_TYPE ValueType() const;\n" );
fprintf( f, "\n\n// STEP Part 21\n" );
fprintf( f, " virtual void STEPwrite_content (ostream& out =std::cout,\n"
" const char *currSch =0) const;\n" );
fprintf( f, " virtual void STEPwrite_verbose (ostream& out =std::cout,\n"
" const char *currSch =0) const;\n" );
fprintf( f, " virtual Severity STEPread_content (istream& in =cin,\n"
" InstMgrBase * instances =0, const char *utype =0,\n"
" int addFileId =0, const char *currSch =0);\n" );
/* read StrToVal_content */
fprintf( f, " virtual Severity StrToVal_content "
"(const char *,\n InstMgrBase * instances =0);\n" );
/* constructor(s) */
fprintf( f, "\n// STEP Part 22: SDAI\n" );
fprintf( f, "\n// constructors\n" );
fprintf( f, " %s( const SelectTypeDescriptor * =%s );\n",
classnm, tdnm );
fprintf( f, " // part 1\n" );
LISTdo( SEL_TYPEget_items( type ), t, Type )
if( ( TYPEis_entity( t ) )
|| ( !utype_member( dups, t, 1 ) ) ) {
/** if an entity or not in the dup list **/
fprintf( f, " %s( const %s&,\n ",
SelectName( TYPEget_name( type ) ), AccessType( t ) );
for( j = 0; j < size; j++ ) {
fprintf( f, " " );
}
fprintf( f, "const SelectTypeDescriptor * =%s );\n", tdnm );
}
LISTod;
LISTdo( dups, t, Type )
if( ! TYPEis_entity( t ) ) { /* entities were done already */
fprintf( f, " %s( const %s&,\n ",
SelectName( TYPEget_name( type ) ),
isAggregateType( t ) ? AccessType( t ) : TYPEget_utype( t ) );
for( j = 0; j < size; j++ ) {
fprintf( f, " " );
}
fprintf( f, "const SelectTypeDescriptor * =%s );\n", tdnm );
}
LISTod;
/* destructor */
fprintf( f, " virtual ~%s();\n", classnm );
LISTfree( data_members );
}
/**
* TYPEselect_inc_print prints the class member function declarations of a select
* class.
*/
void TYPEselect_inc_print( const Type type, FILE * f ) {
char n[BUFSIZ+1]; /* class name */
char tdnm [BUFSIZ+1]; /* TypeDescriptor name */
Linked_List dups;
int dup_result;
Linked_List attrs;
dup_result = find_duplicate_list( type, &dups );
strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ );
strncpy( tdnm, TYPEtd_name( type ), BUFSIZ );
TYPEselect_inc_print_vars( type, f, dups );
fprintf( f, "\n // part 2\n" );
LISTdo( SEL_TYPEget_items( type ), t, Type )
if( ( TYPEis_entity( t ) )
|| ( !utype_member( dups, t, 1 ) ) ) {
/** if an entity or not in the dup list **/
fprintf( f, " operator %s();\n", AccessType( t ) );
}
LISTod;
LISTdo( dups, t, Type )
/* do the dups once only */
if( ! TYPEis_entity( t ) ) /* entities were done already */
fprintf( f, " operator %s ();\n",
( TYPEis_aggregate( t ) || TYPEis_select( t ) ) ?
AccessType( t ) : TYPEget_utype( t ) );
LISTod;
fprintf( f, "\n // part 3\n" );
attrs = SEL_TYPEgetnew_attribute_list( type );
/* get the list of unique attributes from the entity items */
LISTdo( attrs, a, Variable )
if( VARget_initializer( a ) == EXPRESSION_NULL ) {
ATTRsign_access_methods( a, f );
}
LISTod;
LISTfree( attrs );
fprintf( f, "\n // part 4\n" );
LISTdo( SEL_TYPEget_items( type ), t, Type )
if( ( TYPEis_entity( t ) )
|| ( !utype_member( dups, t, 1 ) ) ) {
/** if an entity or not in the dup list **/
fprintf( f, " %s& operator =( const %s& );\n",
SelectName( TYPEget_name( type ) ), AccessType( t ) );
}
LISTod;
LISTdo( dups, t, Type )
if( ! TYPEis_entity( t ) ) { /* entities were done already */
fprintf( f, " %s& operator =( const %s& );\n",
SelectName( TYPEget_name( type ) ),
isAggregateType( t ) ? AccessType( t ) : TYPEget_utype( t ) );
}
LISTod;
fprintf( f, " // not in SDAI\n"
" %s& ShallowCopy ( const %s& );\n",
n, n );
fprintf( f, "\n#ifdef COMPILER_DEFINES_OPERATOR_EQ\n#else\n" );
fprintf( f, " %s& operator =( %s * const & );\n", n, n );
fprintf( f, " SDAI_Select& operator =( const SDAI_Select& );\n" );
fprintf( f, "#endif\n" );
fprintf( f, "\n // part 5\n" );
LISTdo( SEL_TYPEget_items( type ), t, Type )
fprintf( f, " Logical Is%s() const;\n",
FirstToUpper( TYPEget_name( t ) ) );
LISTod;
fprintf( f, "\n // part 6 ... UnderlyingTypeName () implemented in"
" SDAI_Select class ...\n" );
if( dup_result ) {
/** if there are duplicate underlying types **/
fprintf( f, "\n // part 7\n" );
fprintf( f, " const TypeDescriptor *"
"SetUnderlyingType ( const TypeDescriptor * td );\n" );
} else {
fprintf( f, "\n // part 7 ... NONE only for complex selects...\n" );
}
#ifdef PART8
fprintf( f, "\n // part 8\n" );
fprintf( f, " %s* operator->();\n", n );
#endif
fprintf( f, "};\n" );
fprintf( f, "\ninline SDAI_Select * create_%s () { return new %s; }\n", n, n );
/* DAR - moved from SCOPEPrint() */
fprintf( f, "typedef %s * %sH;\n", n, n );
fprintf( f, "typedef %s_ptr %s_var;\n\n", n, n );
/* print things for aggregate class */
fprintf( f, "\nclass %s_agg : public SelectAggregate {\n", n );
fprintf( f, " protected:\n" );
fprintf( f, " SelectTypeDescriptor *sel_type;\n\n" );
fprintf( f, " public:\n" );
fprintf( f, " %s_agg( SelectTypeDescriptor * =%s );\n", n, tdnm );
fprintf( f, " ~%s_agg();\n", n );
fprintf( f, " virtual SingleLinkNode * NewNode()\n" );
fprintf( f, " { return new SelectNode (new %s( sel_type )); }\n", n );
fprintf( f, "};\n" );
/* DAS creation function for select aggregate class */
fprintf( f, "inline STEPaggregate * create_%s_agg () { return new %s_agg; }\n",
n, n );
fprintf( f, "typedef %s_agg_ptr %s_agg_var;\n", n, n );
fprintf( f, "\n///// END SELECT TYPE %s\n\n", TYPEget_name( type ) );
LISTfree( dups );
}
/**
* TYPEselect_lib_print_part_one prints constructor(s)/destructor of a select
* class.
*/
void TYPEselect_lib_print_part_one( const Type type, FILE * f,
Linked_List dups, char * n ) {
#define schema_name SCHEMAget_name(schema)
char tdnm[BUFSIZ+1],
nm[BUFSIZ+1];
int size = strlen( n ) * 2 + 4, j; /* size - for formatting output */
strncpy( tdnm, TYPEtd_name( type ), BUFSIZ );
strncpy( nm, SelectName( TYPEget_name( type ) ), BUFSIZ );
/* constructor(s) */
/* null constructor */
fprintf( f, "\n// STEP Part 22: SDAI\n" );
fprintf( f, "\n // part 0\n" );
fprintf( f, "%s::%s( const SelectTypeDescriptor *typedescript )\n", n, n );
fprintf( f, " : " BASE_SELECT " (typedescript)" );
/* Initialize the select members with their correct typedescriptors: */
initSelItems( type, f );
fprintf( f, "\n{\n" );
fprintf( f, "#ifdef SC_LOGGING\n if( *logStream )\n {\n" );
fprintf( f, " *logStream << \"DAVE ERR entering %s constructor.\" << std::endl;\n", n );
fprintf( f, " }\n#endif\n" );
/* create objects for data member pointers. also in two more ctors below, and deleted in dtor which is printed at end of this function. */
LISTdo( dups, t, Type ) {
if( isAggregateType( t ) && t->u.type->body->base ) {
fprintf( f, " _%s = new %s;\n", SEL_ITEMget_dmname( t ), TYPEget_utype( t ) );
}
} LISTod
/* above misses some attr's that are initialized in part 1 ctor below.
* hopefully this won't add duplicates...
*/
LISTdo( SEL_TYPEget_items( type ), t, Type ) {
if( ( TYPEis_entity( t ) ) || ( !utype_member( dups, t, 1 ) ) ) {
if( isAggregateType( t ) && ( t->u.type->body->base ) ) {
fprintf( f, " _%s = new %s;\n", SEL_ITEMget_dmname( t ), TYPEget_utype( t ) );
} else if (TYPEis_entity(t)) {
// Per TYPEget_utype, any TYPEis_entity is an
// SDAI_Application_instance_ptr - initialize it here.
fprintf(f, " _%s = NULL;\n", SEL_ITEMget_dmname(t));
}
}
} LISTod
fprintf( f, " nullify();\n" );
fprintf( f, "#ifdef SC_LOGGING\n if( *logStream )\n {\n" );
fprintf( f, "// *logStream << \"DAVE ERR exiting %s constructor.\" << std::endl;\n", n );
fprintf( f, " }\n#endif\n" );
fprintf( f, "}\n" );
/* constructors with underlying types */
fprintf( f, "\n // part 1\n" );
LISTdo( SEL_TYPEget_items( type ), t, Type ) {
if( ( TYPEis_entity( t ) ) || ( !utype_member( dups, t, 1 ) ) ) {
/* if there is not more than one underlying type that maps to the same
* base type print out the constructor using the type from the TYPE
* statement as the underlying type. Also skip enums/sels which are
* renames of other items. That would create redundant constructors
* since renames are typedef'ed to the original type.
*/
fprintf( f, "%s::%s( const %s& o,\n", n, n, AccessType( t ) );
for( j = 0; j < size; j++ ) {
fprintf( f, " " );
}
/* Did this for the heck of it, and to show how easy it would have
been to make it all pretty - DAR. ;-) */
fprintf( f, "const SelectTypeDescriptor *typedescript )\n" );
fprintf( f, " : " BASE_SELECT " (typedescript, %s)", TYPEtd_name( t ) );
initSelItems( type, f );
fprintf( f, "\n{\n" );
fprintf( f, "#ifdef SC_LOGGING\n if( *logStream ) { " );
fprintf( f, "*logStream << \"DAVE ERR entering %s constructor.\" << std::endl; }\n", n );
fprintf( f, "#endif\n" );
if( isAggregateType( t ) ) {
if( t->u.type->body->base ) {
fprintf( f, " _%s = new %s;\n", SEL_ITEMget_dmname( t ), TYPEget_utype( t ) );
}
fprintf( f, " _%s%sShallowCopy (*o);\n", SEL_ITEMget_dmname( t ),
( ( t->u.type->body->base ) ? "->" : "." ) );
} else {
fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) );
}
fprintf( f, "#ifdef SC_LOGGING\n if( *logStream ) { " );
fprintf( f, "*logStream << \"DAVE ERR exiting %s constructor.\" << std::endl; }\n", n );
fprintf( f, "#endif\n" );
fprintf( f, "}\n\n" );
}
} LISTod
LISTdo( dups, t, Type ) {
/* if there is more than one underlying type that maps to the
* same base type, print a constructor using the base type.
*/
if( ! TYPEis_entity( t ) ) { /* entities were done already */
if( isAggregateType( t ) ) {
fprintf( f, "%s::%s( const %s& o,\n", n, n, AccessType( t ) );
for( j = 0; j < size; j++ ) {
fprintf( f, " " );
}
fprintf( f, "const SelectTypeDescriptor *typedescript )\n" );
fprintf( f, " : " BASE_SELECT " ( typedescript, %s )",
TYPEtd_name( t ) );
initSelItems( type, f );
fprintf( f, "\n{\n" );
fprintf( f, "#ifdef SC_LOGGING\n if( *logStream )\n {\n" );
fprintf( f,
" *logStream << \"DAVE ERR entering %s constructor.\""
" << std::endl;\n", n );
fprintf( f, " }\n#endif\n" );
if( t->u.type->body->base ) {
fprintf( f, " _%s = new %s;\n", SEL_ITEMget_dmname( t ), TYPEget_utype( t ) );
}
fprintf( f, " _%s%sShallowCopy (*o);\n", SEL_ITEMget_dmname( t ), ( ( t->u.type->body->base ) ? "->" : "." ) );
} else {
fprintf( f, "%s::%s( const %s& o,\n", n, n, TYPEget_utype( t ) );
for( j = 0; j < size; j++ ) {
fprintf( f, " " );
}
fprintf( f, "const SelectTypeDescriptor *typedescript )\n" );
fprintf( f, " : " BASE_SELECT " ( typedescript, %s )",
TYPEtd_name( t ) );
initSelItems( type, f );
fprintf( f, "\n{\n" );
fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) );
}
fprintf( f,
"// NOTE: Underlying type defaults to %s instead of NULL\n",
TYPEtd_name( t ) );
fprintf( f, "#ifdef SC_LOGGING\n if( *logStream )\n {\n" );
fprintf( f,
"// *logStream << \"DAVE ERR exiting %s constructor.\""
" << std::endl;\n", n );
fprintf( f, " }\n#endif\n" );
fprintf( f, "}\n\n" );
}
} LISTod
/* dtor */
fprintf( f, "%s::~%s() {\n", n, n );
/* delete objects that data members point to */
LISTdo( dups, t, Type ) {
if( isAggregateType( t ) && t->u.type->body->base ) {
fprintf( f, " if( _%s ) {\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " delete _%s;\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " _%s = 0;\n }\n", SEL_ITEMget_dmname( t ) );
}
}
LISTod;
LISTdo( SEL_TYPEget_items( type ), t, Type ) {
if( ( TYPEis_entity( t ) ) || ( !utype_member( dups, t, 1 ) ) ) {
if( isAggregateType( t ) && ( t->u.type->body->base ) ) {
fprintf( f, " if( _%s ) {\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " delete _%s;\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " _%s = 0;\n }\n", SEL_ITEMget_dmname( t ) );
}
}
} LISTod
fprintf( f, "}\n\n" );
fprintf( f, "%s_agg::%s_agg( SelectTypeDescriptor *s)\n"
" : SelectAggregate(), sel_type(s)\n{\n}\n\n", n, n );
fprintf( f, "%s_agg::~%s_agg() { }\n\n", n, n );
#undef schema_name
}
/**
* Creates initialization functions for the select items of a select. The
* selects must have their typedescriptors set properly. If a select is a
* renaming of another select ("TYPE selB = selA") its td would default to
* selA's, so it must be set specifically.
*/
static void initSelItems( const Type type, FILE * f ) {
Linked_List data_members = SELgetnew_dmlist( type );
LISTdo( data_members, t, Type )
if( TYPEis_select( t ) ) {
fprintf( f, ",\n _%s (%s)", SEL_ITEMget_dmname( t ),
TYPEtd_name( t ) );
}
LISTod;
}
Linked_List ENTITYget_expanded_entities( Entity e, Linked_List l ) {
Linked_List supers;
Entity super;
if( ! LISTmember( l, e ) ) {
LISTadd_first( l, e );
}
if( multiple_inheritance ) {
int super_cnt = 0;
supers = ENTITYget_supertypes( e );
LISTdo( supers, s, Entity )
/* ignore the more than one supertype
since multiple inheritance isn\'t implemented */
if( super_cnt == 0 ) {
ENTITYget_expanded_entities( s, l );
}
++ super_cnt;
LISTod;
} else {
/* ignore the more than one supertype
since multiple inheritance isn\'t implemented */
super = ENTITYget_superclass( e );
ENTITYget_expanded_entities( super, l );
}
return l;
}
Linked_List SELget_entity_itemlist( const Type type ) {
Linked_List complete = SEL_TYPEget_items( type );
Linked_List newlist = LISTcreate();
Entity cur;
LISTdo( complete, t, Type )
if( TYPEis_entity( t ) ) {
cur = ENT_TYPEget_entity( t );
ENTITYget_expanded_entities( cur, newlist );
}
LISTod;
return newlist;
}
/**
* Specialized function used in function TYPEselect_lib_print_part_three
* below. Calls a function to check if an attribute of an entity belongs
* to its primary path (is its own attr, that of its first super, that of
* its first super's first super etc), and does necessary housekeeping.
*/
static int memberOfEntPrimary( Entity ent, Variable uattr ) {
Linked_List attrlist = LISTcreate();
int result;
ENTITYget_first_attribs( ent, attrlist );
result = ( LISTmember( attrlist, uattr ) != 0 );
LIST_destroy( attrlist );
return result;
}
void TYPEselect_lib_part_three_getter( const Type type, const char * classnm, const char * attrnm, const char * utype, char * uent, char * funcnm,
Linked_List items, Variable a, Variable uattr, Entity ent, FILE * f, bool returnConst ) {
/* return a const value? */
const char * constStr = "const ";
const char * constReturn = ( returnConst ? constStr : "" );
/* method can be const or non-const? */
bool notAlwaysConst = attrIsObj( VARget_type( a ) );
ATTRprint_access_methods_get_head( classnm, a, f, returnConst );
/* if there will not be const and non-const getters, then this method should be const */
fprintf( f, "%s{\n", ( notAlwaysConst ? constReturn : constStr ) );
LISTdo( items, t, Type ) {
if( TYPEis_entity( t ) && ( uattr = ENTITYget_named_attribute(
( ent = ENT_TYPEget_entity( t ) ), ( char * ) StrToLower( attrnm ) ) ) ) {
/* for the select items which have the current attribute */
if( !multiple_inheritance ) {
if( !memberOfEntPrimary( ent, uattr ) ) {
/* If multiple inheritance is not supported, we must additionally check
* that uattr is a member of the entity's primary inheritance path
* (i.e., the entity, its first supertype, the super's first super,
* etc). The above `if' is commented out, because currently mult inher
* is not supported to the extent of handling accessor functions for
* non-primary supertypes. */
continue;
}
}
if( ! VARis_derived( uattr ) ) {
if( !strcmp( utype, TYPEget_ctype( VARget_type( uattr ) ) ) ) {
/* check to make sure the underlying attribute\'s type is
* the same as the current attribute. */
strncpy( uent, TYPEget_ctype( t ), BUFSIZ );
/* if the underlying type is that item's type, call the underlying_item's
* member function if it is the same attribute */
if( VARis_overrider( ENT_TYPEget_entity( t ), uattr ) ) {
/* update attribute_func_name because is has been overridden */
generate_attribute_func_name( uattr, funcnm );
} else {
generate_attribute_func_name( a, funcnm );
}
fprintf( f, " if( CurrentUnderlyingType () == %s ) \n // %s\n",
TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) ) );
fprintf( f, " return ((%s%s) _%s) ->%s();\n", constReturn, uent, SEL_ITEMget_dmname( t ), funcnm );
} else {
/* types are not the same issue a warning */
fprintf( stderr,