-
-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathobj_cxx.cpp
More file actions
4041 lines (3365 loc) · 105 KB
/
obj_cxx.cpp
File metadata and controls
4041 lines (3365 loc) · 105 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
//____________________________________________________________
//
// PROGRAM: C preprocess
// MODULE: c_cxx.cpp
// DESCRIPTION: C and C++ code generator
//
// The contents of this file are subject to the Interbase Public
// License Version 1.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.Inprise.com/IPL.html
//
// Software distributed under the License is distributed on an
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
// or implied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Original Code was created by Inprise Corporation
// and its predecessors. Portions created by Inprise Corporation are
// Copyright (C) Inprise Corporation.
//
// All Rights Reserved.
// Contributor(s): ______________________________________.16/09/2003
// TMN (Mike Nordell) 11.APR.2001 - Reduce compiler warnings
//
// 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
//
//
//____________________________________________________________
//
//
#include "firebird.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "ibase.h"
#include "../gpre/gpre.h"
#include "../gpre/pat.h"
#include "../gpre/msc_proto.h"
#include "../gpre/cmp_proto.h"
#include "../gpre/gpre_proto.h"
#include "../gpre/lang_proto.h"
#include "../gpre/pat_proto.h"
#include "../common/prett_proto.h"
#include "../yvalve/gds_proto.h"
#include "../common/utils_proto.h"
static void align(int);
static void asgn_from(const act*, ref*, int);
static void asgn_to(const act*, ref*, int);
static void asgn_to_proc(const ref*, int);
static void gen_any(const act*, int);
static void gen_at_end(const act*, int);
static void gen_based(const act*, int);
static void gen_blob_close(const act*, USHORT);
static void gen_blob_end(const act*, USHORT);
static void gen_blob_for(const act*, USHORT);
static void gen_blob_open(const act*, USHORT);
static void gen_blr(void*, SSHORT, const char*);
static void gen_clear_handles(int);
//static void gen_compatibility_symbol(const TEXT*, const TEXT*, const TEXT*);
static void gen_compile(const act*, int);
static void gen_create_database(const act*, int);
static int gen_cursor_close(const act*, const gpre_req*, int);
static void gen_cursor_init(const act*, int);
static int gen_cursor_open(const act*, const gpre_req*, int);
static void gen_database(int);
static void gen_ddl(const act*, int);
static void gen_drop_database(const act*, int);
static void gen_dyn_close(const act*, int);
static void gen_dyn_declare(const act*, int);
static void gen_dyn_describe(const act*, int, bool);
static void gen_dyn_execute(const act*, int);
static void gen_dyn_fetch(const act*, int);
static void gen_dyn_immediate(const act*, int);
static void gen_dyn_insert(const act*, int);
static void gen_dyn_open(const act*, int);
static void gen_dyn_prepare(const act*, int);
static void gen_emodify(const act*, int);
static void gen_estore(const act*, int);
static void gen_endfor(const act*, int);
static void gen_erase(const act*, int);
static SSHORT gen_event_block(act*);
static void gen_event_init(const act*, int);
static void gen_event_wait(const act*, int);
static void gen_fetch(const act*, int);
static void gen_finish(const act*, int);
static void gen_for(const act*, int);
static void gen_function(const act*, int);
static void gen_get_or_put_slice(const act*, const ref*, bool, int);
static void gen_get_segment(const act*, int);
static void gen_loop(const act*, int);
static TEXT* gen_name(char* const, const ref*, bool);
static void gen_on_error(const act*, USHORT);
static void gen_procedure(const act*, int);
static void gen_put_segment(const act*, int);
static void gen_raw(const UCHAR*, int);
static void gen_ready(const act*, int);
static void gen_receive(const act*, int, const gpre_port*);
static void gen_release(const act*, int);
static void gen_request(const gpre_req*);
static void gen_return_value(const act*, int);
static void gen_routine(const act*, int);
static void gen_s_end(const act*, int);
static void gen_s_fetch(const act*, int);
static void gen_s_start(const act*, int);
static void gen_segment(const act*, int);
static void gen_select(const act*, int);
static void gen_send(const act*, const gpre_port*, int);
static void gen_slice(const act*, const ref*, int);
static void gen_start(const act*, const gpre_port*, int, bool);
static void gen_store(const act*, int);
static void gen_t_start(const act*, int);
static void gen_tpb(const tpb*, int);
static void gen_trans(const act*, int);
static void gen_type(const act*, int);
static void gen_update(const act*, int);
static void gen_variable(const act*, int);
static void gen_whenever(const swe*, int);
static void make_array_declaration(ref*);
static TEXT* make_name(TEXT* const, const gpre_sym*);
static void make_ok_test(const act*, const gpre_req*, int);
static void make_port(const gpre_port*, int);
static void make_ready(const gpre_dbb*, const TEXT*, const TEXT*, USHORT, const gpre_req*);
static void printa(int, const char*, ...) ATTRIBUTE_FORMAT(2,3);
static void printb(const TEXT*, ...) ATTRIBUTE_FORMAT(1,2);
static const TEXT* request_trans(const act*, const gpre_req*);
static const TEXT* status_vector(const act*);
static void t_start_auto(const act*, const gpre_req*, const TEXT*, int, bool);
static bool global_first_flag = false;
static const TEXT* global_status_name = 0;
constexpr int INDENT = 3;
static constexpr const char* NULL_STRING = "NULL";
static constexpr const char* NULL_STATUS = "NULL";
static constexpr const char* NULL_SQLDA = "NULL";
static constexpr const char* GDS_INCLUDE = "<ibase.h>";
static constexpr const char* DCL_LONG = "ISC_LONG";
static constexpr const char* DCL_QUAD = "ISC_QUAD";
static inline void begin(const int column)
{
printa(column, "{");
}
static inline void endp(const int column)
{
printa(column, "}");
}
static inline void success(const int column, bool ok, const char* status_name, const char* post = "")
{
printa(column, "if (%s%s->getState() & Firebird::IStatus::STATE_ERRORS%s)%s",
ok ? "!(" : "", global_status_name, ok ? ")" : "", post);
}
static inline void set_sqlcode(const act* action, const int column)
{
if (action->act_flags & ACT_sql)
printa(column, "SQLCODE = isc_sqlcode(%s->getErrors());", global_status_name);
}
static inline void ObjectNotImplemented()
{
CPR_error("Feature is not implemented for object API");
throw Firebird::LongJump();
}
//____________________________________________________________
//
//
void OBJ_CXX_action(const act* action, int column)
{
global_status_name = "fbStatus";
// Put leading braces where required
switch (action->act_type)
{
case ACT_alter_database:
case ACT_alter_domain:
case ACT_alter_index:
case ACT_alter_table:
case ACT_blob_close:
case ACT_blob_create:
case ACT_blob_for:
case ACT_blob_open:
case ACT_clear_handles:
case ACT_close:
case ACT_commit:
case ACT_commit_retain_context:
case ACT_create_database:
case ACT_create_domain:
case ACT_create_generator:
case ACT_create_index:
case ACT_create_shadow:
case ACT_create_table:
case ACT_create_view:
case ACT_declare_filter:
case ACT_declare_udf:
case ACT_disconnect:
case ACT_drop_database:
case ACT_drop_domain:
case ACT_drop_filter:
case ACT_drop_index:
case ACT_drop_shadow:
case ACT_drop_table:
case ACT_drop_udf:
case ACT_drop_view:
case ACT_dyn_close:
case ACT_dyn_cursor:
case ACT_dyn_describe:
case ACT_dyn_describe_input:
case ACT_dyn_execute:
case ACT_dyn_fetch:
case ACT_dyn_grant:
case ACT_dyn_immediate:
case ACT_dyn_insert:
case ACT_dyn_open:
case ACT_dyn_prepare:
case ACT_dyn_revoke:
case ACT_fetch:
case ACT_finish:
case ACT_for:
case ACT_get_segment:
case ACT_get_slice:
case ACT_insert:
case ACT_loop:
case ACT_modify:
case ACT_open:
case ACT_prepare:
case ACT_procedure:
case ACT_put_slice:
case ACT_ready:
case ACT_release:
case ACT_rfinish:
case ACT_rollback:
case ACT_rollback_retain_context:
case ACT_s_fetch:
case ACT_s_start:
case ACT_select:
case ACT_store:
case ACT_start:
case ACT_update:
case ACT_statistics:
begin(column);
break;
default:
// no leading brace needed
break;
}
switch (action->act_type)
{
case ACT_alter_database:
case ACT_alter_domain:
case ACT_alter_index:
case ACT_alter_table:
gen_ddl(action, column);
break;
case ACT_any:
gen_any(action, column);
return;
case ACT_at_end:
gen_at_end(action, column);
return;
case ACT_b_declare:
gen_database(column);
gen_routine(action, column);
return;
case ACT_basedon:
gen_based(action, column);
return;
case ACT_blob_cancel:
gen_blob_close(action, (USHORT) column);
return;
case ACT_blob_close:
gen_blob_close(action, (USHORT) column);
break;
case ACT_blob_create:
gen_blob_open(action, (USHORT) column);
break;
case ACT_blob_for:
gen_blob_for(action, (USHORT) column);
return;
case ACT_blob_handle:
gen_segment(action, column);
return;
case ACT_blob_open:
gen_blob_open(action, (USHORT) column);
break;
case ACT_clear_handles:
gen_clear_handles(column);
break;
case ACT_close:
gen_s_end(action, column);
break;
case ACT_commit:
gen_trans(action, column);
break;
case ACT_commit_retain_context:
gen_trans(action, column);
break;
case ACT_create_database:
gen_create_database(action, column);
break;
case ACT_create_domain:
case ACT_create_generator:
case ACT_create_index:
case ACT_create_shadow:
case ACT_create_table:
case ACT_create_view:
gen_ddl(action, column);
break;
case ACT_cursor:
gen_cursor_init(action, column);
return;
case ACT_database:
gen_database(column);
return;
case ACT_declare_filter:
case ACT_declare_udf:
gen_ddl(action, column);
break;
case ACT_disconnect:
gen_finish(action, column);
break;
case ACT_drop_database:
gen_drop_database(action, column);
break;
case ACT_drop_domain:
case ACT_drop_filter:
case ACT_drop_index:
case ACT_drop_shadow:
case ACT_drop_table:
case ACT_drop_udf:
case ACT_drop_view:
gen_ddl(action, column);
break;
case ACT_dyn_close:
gen_dyn_close(action, column);
break;
case ACT_dyn_cursor:
gen_dyn_declare(action, column);
break;
case ACT_dyn_describe:
gen_dyn_describe(action, column, false);
break;
case ACT_dyn_describe_input:
gen_dyn_describe(action, column, true);
break;
case ACT_dyn_execute:
gen_dyn_execute(action, column);
break;
case ACT_dyn_fetch:
gen_dyn_fetch(action, column);
break;
case ACT_dyn_grant:
gen_ddl(action, column);
break;
case ACT_dyn_immediate:
gen_dyn_immediate(action, column);
break;
case ACT_dyn_insert:
gen_dyn_insert(action, column);
break;
case ACT_dyn_open:
gen_dyn_open(action, column);
break;
case ACT_dyn_prepare:
gen_dyn_prepare(action, column);
break;
case ACT_dyn_revoke:
gen_ddl(action, column);
break;
case ACT_endblob:
gen_blob_end(action, (USHORT) column);
return;
case ACT_enderror:
column += INDENT;
endp(column);
column -= INDENT;
break;
case ACT_endfor:
gen_endfor(action, column);
break;
case ACT_endmodify:
gen_emodify(action, column);
break;
case ACT_endstore:
gen_estore(action, column);
break;
case ACT_erase:
gen_erase(action, column);
return;
case ACT_event_init:
gen_event_init(action, column);
break;
case ACT_event_wait:
gen_event_wait(action, column);
break;
case ACT_fetch:
gen_fetch(action, column);
break;
case ACT_finish:
gen_finish(action, column);
break;
case ACT_for:
gen_for(action, column);
return;
case ACT_function:
gen_function(action, column);
return;
case ACT_get_segment:
gen_get_segment(action, column);
break;
case ACT_get_slice:
gen_slice(action, 0, column);
break;
case ACT_hctef:
endp(column);
break;
case ACT_insert:
gen_s_start(action, column);
break;
case ACT_loop:
gen_loop(action, column);
break;
case ACT_on_error:
gen_on_error(action, (USHORT) column);
return;
case ACT_open:
gen_s_start(action, column);
break;
case ACT_prepare:
gen_trans(action, column);
break;
case ACT_procedure:
gen_procedure(action, column);
break;
case ACT_put_segment:
gen_put_segment(action, column);
break;
case ACT_put_slice:
gen_slice(action, 0, column);
break;
case ACT_ready:
gen_ready(action, column);
break;
case ACT_release:
gen_release(action, column);
break;
case ACT_rfinish:
gen_finish(action, column);
break;
case ACT_rollback:
gen_trans(action, column);
break;
case ACT_rollback_retain_context:
gen_trans(action, column);
break;
case ACT_routine:
gen_routine(action, column);
return;
case ACT_s_end:
gen_s_end(action, column);
return;
case ACT_s_fetch:
gen_s_fetch(action, column);
return;
case ACT_s_start:
gen_s_start(action, column);
break;
case ACT_segment:
gen_segment(action, column);
return;
case ACT_segment_length:
gen_segment(action, column);
return;
case ACT_select:
gen_select(action, column);
break;
case ACT_sql_dialect:
gpreGlob.sw_sql_dialect = ((set_dialect*) action->act_object)->sdt_dialect;
return;
case ACT_start:
gen_t_start(action, column);
break;
case ACT_statistics:
gen_ddl(action, column);
break;
case ACT_store:
gen_store(action, column);
return;
case ACT_store2:
gen_return_value(action, column);
return;
case ACT_type_number:
gen_type(action, column);
return;
case ACT_update:
gen_update(action, column);
break;
case ACT_variable:
gen_variable(action, column);
return;
default:
return;
}
// Put in a trailing brace for those actions still with us
if (action->act_flags & ACT_sql)
gen_whenever(action->act_whenever, column);
if (action->act_error)
fprintf(gpreGlob.out_file, ";");
else
endp(column);
}
//____________________________________________________________
//
// Align output to a specific column for output. If the
// column is negative, don't do anything.
//
static void align( int column)
{
if (column < 0)
return;
putc('\n', gpreGlob.out_file);
for (int i = column / 8; i; --i)
putc('\t', gpreGlob.out_file);
for (int i = column % 8; i; --i)
putc(' ', gpreGlob.out_file);
}
//____________________________________________________________
//
// Build an assignment from a host language variable to
// a port variable. The string assignments are a little
// hairy because the normal mode is varying (null
// terminated) strings, but the fixed subtype makes the
// string a byte stream. Furthering the complication, a
// single character byte stream is handled as a single byte,
// meaining that it is the byte, not the address of the
// byte.
//
static void asgn_from( const act* action, ref* reference, int column)
{
TEXT name[MAX_REF_SIZE], variable[MAX_REF_SIZE], temp[MAX_REF_SIZE];
for (; reference; reference = reference->ref_next)
{
bool slice_flag = false;
const gpre_fld* field = reference->ref_field;
if (field->fld_array_info)
{
act* slice_action;
ref* source = reference->ref_friend;
if (source && (slice_action = (act*) source->ref_slice) && slice_action->act_object)
{
slice_flag = true;
slice_action->act_type = ACT_put_slice;
gen_slice(slice_action, 0, column);
}
else if (!(reference->ref_flags & REF_array_elem))
{
printa(column, "%s = fbBlobNull;", gen_name(name, reference, true));
gen_get_or_put_slice(action, reference, false, column);
continue;
}
}
if (!reference->ref_source && !reference->ref_value && !slice_flag)
continue;
align(column);
gen_name(variable, reference, true);
const TEXT* value;
if (slice_flag)
value = gen_name(temp, reference->ref_friend, true);
else if (reference->ref_source)
value = gen_name(temp, reference->ref_source, true);
else
value = reference->ref_value;
if (!slice_flag && reference->ref_value && (reference->ref_flags & REF_array_elem))
{
field = field->fld_array;
}
if (field && field->fld_dtype <= dtype_cstring)
{
if (field->fld_sub_type == 1)
if (field->fld_length == 1)
fprintf(gpreGlob.out_file, "%s = %s;", variable, value);
else
fprintf(gpreGlob.out_file, "isc_ftof (%s, sizeof(%s), %s, %d);", value,
value, variable, field->fld_length);
else if (field->fld_flags & FLD_dbkey)
fprintf(gpreGlob.out_file, "isc_ftof (%s, %d, %s, %d);", value,
field->fld_length, variable, field->fld_length);
else if (gpreGlob.sw_cstring)
fprintf(gpreGlob.out_file, isLangCpp(gpreGlob.sw_language) ?
"isc_vtov ((const char*) %s, (char*) %s, %d);" :
"isc_vtov ((char*) %s, (char*) %s, %d);",
value, variable, field->fld_length);
else if (reference->ref_source)
fprintf(gpreGlob.out_file, "isc_ftof (%s, sizeof(%s), %s, %d);",
value, value, variable, field->fld_length);
else
fprintf(gpreGlob.out_file, "isc_vtof (%s, %s, %d);",
value, variable, field->fld_length);
}
else if (!reference->ref_master || (reference->ref_flags & REF_literal))
{
fprintf(gpreGlob.out_file, "%s = %s;", variable, value);
}
else
{
fprintf(gpreGlob.out_file, "if (%s < 0)", value);
align(column + 4);
fprintf(gpreGlob.out_file, "%s = -1;", variable);
align(column);
fprintf(gpreGlob.out_file, "else");
align(column + 4);
fprintf(gpreGlob.out_file, "%s = 0;", variable);
}
}
}
//____________________________________________________________
//
// Build an assignment to a host language variable from
// a port variable.
//
static void asgn_to( const act* action, ref* reference, int column)
{
char s[MAX_REF_SIZE];
ref* source = reference->ref_friend;
const gpre_fld* field = source->ref_field;
if (field)
{
act* slice_action;
if (field->fld_array_info && (slice_action = (act*) source->ref_slice))
{
source->ref_value = reference->ref_value;
if (slice_action->act_object)
{
slice_action->act_type = ACT_get_slice;
gen_slice(slice_action, source, column);
}
else
gen_get_or_put_slice(action, source, true, column);
// Pick up NULL value if one is there
if ((reference = reference->ref_null))
{
align(column);
fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value,
gen_name(s, reference, true));
}
return;
}
gen_name(s, source, true);
if (field->fld_dtype > dtype_cstring)
fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value, s);
else if (field->fld_sub_type == 1 && field->fld_length == 1)
fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value, s);
else if (field->fld_flags & FLD_dbkey)
fprintf(gpreGlob.out_file, "isc_ftof (%s, %d, %s, %d);",
s, field->fld_length, reference->ref_value, field->fld_length);
else if (!gpreGlob.sw_cstring || field->fld_sub_type == 1)
fprintf(gpreGlob.out_file, "isc_ftof (%s, %d, %s, sizeof(%s));",
s, field->fld_length, reference->ref_value, reference->ref_value);
else
fprintf(gpreGlob.out_file, isLangCpp(gpreGlob.sw_language) ?
"isc_vtov ((const char*) %s, (char*) %s, sizeof(%s));" :
"isc_vtov ((char*) %s, (char*) %s, sizeof(%s));",
s, reference->ref_value, reference->ref_value);
}
// Pick up NULL value if one is there
if ((reference = reference->ref_null))
{
align(column);
fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value, gen_name(s, reference, true));
}
}
//____________________________________________________________
//
// Build an assignment to a host language variable from
// a port variable.
//
static void asgn_to_proc(const ref* reference, int column)
{
char s[MAX_REF_SIZE];
for (; reference; reference = reference->ref_next)
{
if (!reference->ref_value)
continue;
const gpre_fld* field = reference->ref_field;
gen_name(s, reference, true);
align(column);
if (field->fld_dtype > dtype_cstring)
fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value, s);
else if (field->fld_sub_type == 1 && field->fld_length == 1)
fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value, s);
else if (field->fld_flags & FLD_dbkey)
fprintf(gpreGlob.out_file, "isc_ftof (%s, %d, %s, %d);",
s, field->fld_length, reference->ref_value, field->fld_length);
else if (!gpreGlob.sw_cstring || field->fld_sub_type == 1)
fprintf(gpreGlob.out_file, "isc_ftof (%s, %d, %s, sizeof(%s));",
s, field->fld_length, reference->ref_value, reference->ref_value);
else
fprintf(gpreGlob.out_file, isLangCpp(gpreGlob.sw_language) ?
"isc_vtov ((const char*) %s, (char*) %s, sizeof(%s));" :
"isc_vtov ((char*) %s, (char*) %s, sizeof(%s));",
s, reference->ref_value, reference->ref_value);
}
}
//____________________________________________________________
//
// Generate a function call for free standing ANY. Somebody else
// will need to generate the actual function.
//
static void gen_any( const act* action, int column)
{
align(column);
gpre_req* request = action->act_request;
fprintf(gpreGlob.out_file, "%s_r (&%s, &%s",
request->req_handle, request->req_handle, request->req_trans);
gpre_port* port = request->req_vport;
if (port)
for (ref* reference = port->por_references; reference; reference = reference->ref_next)
{
fprintf(gpreGlob.out_file, ", %s", reference->ref_value);
}
fprintf(gpreGlob.out_file, ")");
}
//____________________________________________________________
//
// Generate code for AT END clause of FETCH.
//
static void gen_at_end( const act* action, int column)
{
char s[MAX_REF_SIZE];
const gpre_req* request = action->act_request;
printa(column, "if (!%s) {", gen_name(s, request->req_eof, true));
}
//____________________________________________________________
//
// Substitute for a BASED ON <field name> clause.
//
static void gen_based( const act* action, int column)
{
USHORT datatype;
SLONG length = -1;
align(column);
bas* based_on = (bas*) action->act_object;
const gpre_fld* field = based_on->bas_field;
if (based_on->bas_flags & BAS_segment)
{
datatype = gpreGlob.sw_cstring ? dtype_cstring : dtype_text;
if (!(length = field->fld_seg_length))
length = 256;
if (datatype == dtype_cstring)
length++;
}
else if (field->fld_array_info)
datatype = field->fld_array_info->ary_dtype;
else
datatype = field->fld_dtype;
switch (datatype)
{
case dtype_short:
fprintf(gpreGlob.out_file, "short");
break;
case dtype_long:
fprintf(gpreGlob.out_file, DCL_LONG);
break;
case dtype_quad:
fprintf(gpreGlob.out_file, DCL_QUAD);
break;
// Begin date/time/timestamp
case dtype_sql_date:
fprintf(gpreGlob.out_file, "ISC_DATE");
break;
case dtype_sql_time:
fprintf(gpreGlob.out_file, "ISC_TIME");
break;
case dtype_timestamp:
fprintf(gpreGlob.out_file, "ISC_TIMESTAMP");
break;
// End date/time/timestamp
case dtype_int64:
fprintf(gpreGlob.out_file, "ISC_INT64");
break;
case dtype_blob:
fprintf(gpreGlob.out_file, "ISC_QUAD");
break;
case dtype_cstring:
case dtype_text:
case dtype_varying:
fprintf(gpreGlob.out_file, "char");
break;
case dtype_real:
fprintf(gpreGlob.out_file, "float");
break;
case dtype_double:
fprintf(gpreGlob.out_file, "double");
break;
default:
{
TEXT s[MAX_CURSOR_SIZE];
snprintf(s, sizeof(s), "datatype %d unknown\n", field->fld_dtype);
CPR_error(s);
return;
}
}
// print the first variable, then precede the rest with commas
column += INDENT;
// Notice this variable was named first_flag, same than the global variable.
bool first = true;
while (based_on->bas_variables)
{
const TEXT* variable = (TEXT*) MSC_pop(&based_on->bas_variables);
if (!first)
fprintf(gpreGlob.out_file, ",");
first = false;
align(column);
fprintf(gpreGlob.out_file, "%s", variable);
if (based_on->bas_flags & BAS_segment)
{
if (*variable != '*')
fprintf(gpreGlob.out_file, "[%" SLONGFORMAT"]", length);
}
else if (field->fld_array_info)
{
// Print out the dimension part of the declaration
for (const dim* dimension = field->fld_array_info->ary_dimension;
dimension; dimension = dimension->dim_next)
{
fprintf(gpreGlob.out_file, " [%" SLONGFORMAT"]", dimension->dim_upper - dimension->dim_lower + 1);
}
if (field->fld_array_info->ary_dtype <= dtype_varying && field->fld_length > 1)
{
fprintf(gpreGlob.out_file, " [%d]", field->fld_array->fld_length);
}
}
else
if (*variable != '*' && field->fld_dtype <= dtype_varying &&
(field->fld_sub_type != 1 || field->fld_length > 1))
{
// *???????
//if (*variable != '*' && field->fld_dtype <= dtype_varying &&
// field->fld_length > 1)
//
fprintf(gpreGlob.out_file, "[%d]", field->fld_length);
}
}
fprintf(gpreGlob.out_file, "%s\n", based_on->bas_terminator);
}
//____________________________________________________________
//
// Make a blob FOR loop.
//
static void gen_blob_close( const act* action, USHORT column)
{
const TEXT* pattern1 = "fb_%IFcancel%ELclose%EN_blob (%V1, &%BH);";
if (action->act_error)
begin(column);
const blb* blob;
if (action->act_flags & ACT_sql)
{
column = gen_cursor_close(action, action->act_request, column);
blob = (blb*) action->act_request->req_blobs;
}
else
blob = (blb*) action->act_object;
PAT args;
args.pat_blob = blob;
args.pat_vector1 = status_vector(action);
args.pat_condition = (action->act_type == ACT_blob_cancel);
PATTERN_expand(column, pattern1, &args);
if (action->act_flags & ACT_sql)
{
endp(column);
column -= INDENT;
}
set_sqlcode(action, column);
}
//____________________________________________________________
//
// End a blob FOR loop.
//
static void gen_blob_end( const act* action, USHORT column)
{
PAT args;
TEXT s1[32];
const TEXT* pattern1 = "}\n\
&%BH->close(%V1);\n\
}";
args.pat_blob = (const blb*) action->act_object;
if (action->act_error)
{
snprintf(s1, sizeof(s1), "%s2", global_status_name);
args.pat_vector1 = s1;
}
else
args.pat_vector1 = status_vector(0);
args.pat_condition = (action->act_type == ACT_blob_cancel);
PATTERN_expand(column, pattern1, &args);
}
//____________________________________________________________
//
// Make a blob FOR loop.
//
static void gen_blob_for( const act* action, USHORT column)
{
PAT args;
const TEXT* pattern1 = "%IFif (!(%S1->getState() & Firebird::IStatus::STATE_ERRORS)) {\n\
%ENwhile (1)\n\
{";
gen_blob_open(action, column);
args.pat_condition = (action->act_error != NULL);
args.pat_string1 = global_status_name;