Repository navigation
Expand file tree
/
Copy pathpar.cpp
More file actions
3405 lines (2796 loc) · 81.5 KB
/
Copy pathpar.cpp
File metadata and controls
3405 lines (2796 loc) · 81.5 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 preprocessor
// MODULE: par.cpp
// DESCRIPTION: Parser
//
// 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): ______________________________________.
// Revision 1.2 2000/11/27 09:26:13 fsg
// Fixed bugs in gpre to handle PYXIS forms
// and allow edit.e and fred.e to go through
// gpre without errors (and correct result).
//
// This is a partial fix until all
// PYXIS datatypes are adjusted in frm_trn.c
//
// removed some compiler warnings too
//
// TMN (Mike Nordell) 11.APR.2001 - Reduce compiler warnings
// TMN (Mike Nordell) APR-MAY.2001 - Conversion to C++
// SWB (Stepen Boyd) 2007/03/21 - Suppressed parsing of QLI keywords if -noqli
// switch given on the command line.
//
//
//____________________________________________________________
//
//
#include "firebird.h"
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include "ibase.h"
#include "../gpre/gpre.h"
#include "../gpre/cmp_proto.h"
#include "../gpre/exp_proto.h"
#include "../gpre/gpre_proto.h"
#include "../gpre/hsh_proto.h"
#include "../gpre/gpre_meta.h"
#include "../gpre/msc_proto.h"
#include "../gpre/par_proto.h"
#include "../gpre/sql_proto.h"
#include "../common/utils_proto.h"
#ifdef FTN_BLK_DATA
static void block_data_list(const gpre_dbb*);
#endif
static bool is_gpre_action_context();
static bool match_parentheses();
static act* par_any();
static act* par_array_element();
static act* par_at();
static act* par_based();
static act* par_begin();
static blb* par_blob();
static act* par_blob_action(act_t);
static act* par_blob_field();
static act* par_case();
static act* par_clear_handles();
static act* par_derived_from();
static act* par_end_block();
static act* par_end_error();
static act* par_end_fetch();
static act* par_end_for();
static act* par_end_modify();
static act* par_end_stream();
static act* par_end_store(bool);
static act* par_erase();
static act* par_fetch();
static act* par_finish();
static act* par_for();
static act* par_function();
static act* par_left_brace();
static act* par_modify();
static act* par_on();
static act* par_on_error();
static act* par_open_blob(act_t, gpre_sym*);
static bool par_options(gpre_req*, bool);
static act* par_procedure();
static act* par_ready();
static act* par_returning_values();
static act* par_right_brace();
static act* par_release();
static act* par_slice(act_t);
static act* par_store();
static act* par_start_stream();
static act* par_start_transaction();
static act* par_subroutine();
static act* par_trans(act_t);
static act* par_type();
static act* par_variable();
static act* scan_routine_header();
static void set_external_flag();
static bool terminator();
static int brace_count;
static int namespace_count;
static bool routine_decl;
static act* cur_statement;
static act* cur_item;
static gpre_lls* cur_for;
static gpre_lls* cur_store;
static gpre_lls* cur_fetch;
static gpre_lls* cur_modify;
static gpre_lls* cur_error;
static gpre_lls* routine_stack;
static gpre_fld* flag_field;
//____________________________________________________________
//
// We have a token with a symbolic meaning. If appropriate,
// parse an action segment. If not, return NULL.
//
act* PAR_action(const TEXT* base_dir)
{
gpre_sym* symbol = gpreGlob.token_global.tok_symbol;
if (!symbol)
{
cur_statement = NULL;
return NULL;
}
if (gpreGlob.token_global.tok_keyword >= KW_start_actions &&
gpreGlob.token_global.tok_keyword <= KW_end_actions)
{
const kwwords_t keyword = gpreGlob.token_global.tok_keyword;
if (!is_gpre_action_context())
{
gpreGlob.token_global.tok_symbol = NULL;
return NULL;
}
if (! gpreGlob.sw_no_qli)
{
switch (keyword)
{
case KW_READY:
case KW_START_TRANSACTION:
case KW_FINISH:
case KW_COMMIT:
case KW_PREPARE:
case KW_RELEASE_REQUESTS:
case KW_ROLLBACK:
case KW_FUNCTION:
case KW_SAVE:
case KW_SUB:
case KW_SUBROUTINE:
CPR_eol_token();
break;
case KW_EXTERNAL:
set_external_flag();
return NULL;
case KW_FOR:
// Get the next token as it is without upcasing
gpreGlob.override_case = true;
CPR_token();
break;
default:
CPR_token();
}
}
else
CPR_token();
try {
if (! gpreGlob.sw_no_qli)
{
switch (keyword)
{
case KW_INT:
case KW_LONG:
case KW_SHORT:
case KW_CHAR:
case KW_FLOAT:
case KW_DOUBLE:
//par_var_c(keyword);
return NULL;
case KW_ANY:
return par_any();
case KW_AT:
return par_at();
case KW_BASED:
return par_based();
case KW_CLEAR_HANDLES:
return par_clear_handles();
case KW_DATABASE:
return PAR_database(false, base_dir);
case KW_DERIVED_FROM:
return par_derived_from();
case KW_END_ERROR:
return par_end_error();
case KW_END_FOR:
return cur_statement = par_end_for();
case KW_END_MODIFY:
return cur_statement = par_end_modify();
case KW_END_STREAM:
return cur_statement = par_end_stream();
case KW_END_STORE:
return cur_statement = par_end_store(false);
case KW_END_STORE_SPECIAL:
return cur_statement = par_end_store(true);
case KW_ELEMENT:
return par_array_element();
case KW_ERASE:
return cur_statement = par_erase();
case KW_EVENT_INIT:
return cur_statement = PAR_event_init(false);
case KW_EVENT_WAIT:
return cur_statement = PAR_event_wait(false);
case KW_FETCH:
return cur_statement = par_fetch();
case KW_FINISH:
return cur_statement = par_finish();
case KW_FOR:
return par_for();
case KW_END_FETCH:
return cur_statement = par_end_fetch();
case KW_MODIFY:
return par_modify();
case KW_ON:
return par_on();
case KW_ON_ERROR:
return par_on_error();
case KW_READY:
return cur_statement = par_ready();
case KW_RELEASE_REQUESTS:
return cur_statement = par_release();
case KW_RETURNING_VALUES:
return par_returning_values();
case KW_START_STREAM:
return cur_statement = par_start_stream();
case KW_STORE:
return par_store();
case KW_START_TRANSACTION:
return cur_statement = par_start_transaction();
case KW_FUNCTION:
return par_function();
case KW_PROCEDURE:
return par_procedure();
case KW_PROC:
break;
case KW_SUBROUTINE:
return par_subroutine();
case KW_SUB:
break;
case KW_OPEN_BLOB:
return cur_statement = par_open_blob(ACT_blob_open, 0);
case KW_CREATE_BLOB:
return cur_statement = par_open_blob(ACT_blob_create, 0);
case KW_GET_SLICE:
return cur_statement = par_slice(ACT_get_slice);
case KW_PUT_SLICE:
return cur_statement = par_slice(ACT_put_slice);
case KW_GET_SEGMENT:
return cur_statement = par_blob_action(ACT_get_segment);
case KW_PUT_SEGMENT:
return cur_statement = par_blob_action(ACT_put_segment);
case KW_CLOSE_BLOB:
return cur_statement = par_blob_action(ACT_blob_close);
case KW_CANCEL_BLOB:
return cur_statement = par_blob_action(ACT_blob_cancel);
case KW_COMMIT:
return cur_statement = par_trans(ACT_commit);
case KW_SAVE:
return cur_statement = par_trans(ACT_commit_retain_context);
case KW_ROLLBACK:
return cur_statement = par_trans(ACT_rollback);
case KW_PREPARE:
return cur_statement = par_trans(ACT_prepare);
case KW_NAMESPACE:
if (gpreGlob.sw_language == lang_internal || gpreGlob.sw_language == lang_cxx ||
gpreGlob.sw_language == lang_cplusplus)
{
if (CPR_token())
{
if (gpreGlob.token_global.tok_keyword == KW_L_BRACE)
{
CPR_token();
++namespace_count;
++brace_count;
return NULL;
}
}
}
break;
case KW_L_BRACE:
return par_left_brace();
case KW_R_BRACE:
return par_right_brace();
case KW_END:
return par_end_block();
case KW_BEGIN:
return par_begin();
case KW_CASE:
return par_case();
case KW_EXEC:
{
if (!MSC_match(KW_SQL))
break;
gpreGlob.sw_sql = true;
act* action = SQL_action(base_dir);
gpreGlob.sw_sql = false;
return action;
}
default:
break;
}
}
else
{
switch (keyword)
{
case KW_BASED:
return par_based();
case KW_EXEC:
{
if (!MSC_match(KW_SQL))
break;
gpreGlob.sw_sql = true;
act* action = SQL_action(base_dir);
gpreGlob.sw_sql = false;
return action;
}
default:
break;
}
}
} // try
catch (const gpre_exception&) {
throw;
}
catch (const Firebird::fatal_exception&)
{
// CVC: a fatal exception should be propagated.
// For example, a failure in our runtime.
throw;
}
catch (const Firebird::Exception&)
{
gpreGlob.sw_sql = false;
// This is to force GPRE to get the next symbol. Fix for bug #274. DROOT
gpreGlob.token_global.tok_symbol = NULL;
return NULL;
}
cur_statement = NULL;
return NULL;
}
if (! gpreGlob.sw_no_qli)
{
for (; symbol; symbol = symbol->sym_homonym)
{
switch (symbol->sym_type)
{
case SYM_context:
try {
cur_statement = NULL;
return par_variable();
}
catch (const gpre_exception&) {
throw;
}
catch (const Firebird::fatal_exception&)
{
// CVC: a fatal exception should be propagated.
throw;
}
catch (const Firebird::Exception&) {
return 0;
}
case SYM_blob:
try {
cur_statement = NULL;
return par_blob_field();
}
catch (const gpre_exception&) {
throw;
}
catch (const Firebird::fatal_exception&)
{
// CVC: a fatal exception should be propagated.
throw;
}
catch (const Firebird::Exception&) {
return 0;
}
case SYM_relation:
try {
cur_statement = NULL;
return par_type();
}
catch (const gpre_exception&) {
throw;
}
catch (const Firebird::fatal_exception&)
{
// CVC: a fatal exception should be propagated.
throw;
}
catch (const Firebird::Exception&) {
return 0;
}
default:
break;
}
}
}
cur_statement = NULL;
CPR_token();
return NULL;
}
//____________________________________________________________
//
// Parse a blob subtype -- either a signed number or a symbolic name.
//
SSHORT PAR_blob_subtype(gpre_dbb* db)
{
// Check for symbol type name
if (gpreGlob.token_global.tok_type == tok_ident)
{
gpre_fld* field = NULL;
gpre_rel* relation = MET_get_relation(db, "RDB$FIELDS", "");
if (!relation || !(field = MET_field(relation, "RDB$FIELD_SUB_TYPE")))
{
PAR_error("error during BLOB SUB_TYPE lookup");
}
SSHORT const_subtype;
if (!MET_type(field, gpreGlob.token_global.tok_string, &const_subtype))
CPR_s_error("blob sub_type");
PAR_get_token();
return const_subtype;
}
return EXP_SSHORT_ordinal(true);
}
//____________________________________________________________
//
// Parse a DATABASE declaration. If successful, return
// an action block.
//
act* PAR_database(bool sql, const TEXT* base_directory)
{
if (gpreGlob.token_global.tok_length >= NAME_SIZE)
PAR_error("Database alias too long");
TEXT s[MAXPATHLEN << 1];
act* action = MSC_action(0, ACT_database);
gpre_dbb* db = (gpre_dbb*) MSC_alloc(DBB_LEN);
// Get handle name token, make symbol for handle, and
// insert symbol into hash table
gpre_sym* symbol = PAR_symbol(SYM_dummy);
db->dbb_name = symbol;
symbol->sym_type = SYM_database;
symbol->sym_object = (gpre_ctx*) db;
if (!MSC_match(KW_EQUALS))
CPR_s_error("\"=\" in database declaration");
if (MSC_match(KW_STATIC))
db->dbb_scope = DBB_STATIC;
else if (MSC_match(KW_EXTERN))
db->dbb_scope = DBB_EXTERN;
MSC_match(KW_COMPILETIME);
// parse the compiletime options
TEXT* string;
for (;;)
{
if (MSC_match(KW_FILENAME) && !isQuoted(gpreGlob.token_global.tok_type))
CPR_s_error("quoted file name");
tok& token = gpreGlob.token_global;
if (isQuoted(token.tok_type))
{
if (base_directory)
{
db->dbb_filename = string =
(TEXT*) MSC_alloc(token.tok_length + static_cast<int>(strlen(base_directory)) + 1);
MSC_copy_cat(base_directory, static_cast<int>(strlen(base_directory)),
token.tok_string, token.tok_length, string);
}
else
{
db->dbb_filename = string = (TEXT *) MSC_alloc(token.tok_length + 1);
MSC_copy(token.tok_string, token.tok_length, string);
}
token.tok_length += 2;
}
else if (MSC_match(KW_PASSWORD))
{
if (!isQuoted(token.tok_type))
CPR_s_error("quoted password");
db->dbb_c_password = string = (TEXT *) MSC_alloc(token.tok_length + 1);
MSC_copy(token.tok_string, token.tok_length, string);
}
else if (MSC_match(KW_USER))
{
if (!isQuoted(token.tok_type))
CPR_s_error("quoted user name");
db->dbb_c_user = string = (TEXT *) MSC_alloc(token.tok_length + 1);
MSC_copy(token.tok_string, token.tok_length, string);
}
else if (MSC_match(KW_LC_MESSAGES))
{
if (!isQuoted(token.tok_type))
CPR_s_error("quoted language name");
db->dbb_c_lc_messages = string = (TEXT *) MSC_alloc(token.tok_length + 1);
MSC_copy(token.tok_string, token.tok_length, string);
}
else if (!sql && MSC_match(KW_LC_CTYPE))
{
if (!isQuoted(token.tok_type))
CPR_s_error("quoted character set name");
db->dbb_c_lc_ctype = string = (TEXT *) MSC_alloc(token.tok_length + 1);
MSC_copy(token.tok_string, token.tok_length, string);
}
else
break;
PAR_get_token();
}
if ((gpreGlob.sw_auto) && (db->dbb_c_password || db->dbb_c_user || db->dbb_c_lc_ctype ||
db->dbb_c_lc_messages))
{
CPR_warn("PASSWORD, USER and NAMES options require -manual switch to gpre.");
}
if (!db->dbb_filename)
CPR_s_error("quoted file name");
if (gpreGlob.default_user && !db->dbb_c_user)
db->dbb_c_user = gpreGlob.default_user;
if (gpreGlob.default_password && !db->dbb_c_password)
db->dbb_c_password = gpreGlob.default_password;
if (gpreGlob.module_lc_ctype && !db->dbb_c_lc_ctype)
db->dbb_c_lc_ctype = gpreGlob.module_lc_ctype;
if (gpreGlob.default_lc_ctype && !db->dbb_c_lc_ctype)
db->dbb_c_lc_ctype = gpreGlob.default_lc_ctype;
// parse the runtime options
if (MSC_match(KW_RUNTIME))
{
if (MSC_match(KW_FILENAME))
db->dbb_runtime = sql ? SQL_var_or_string(false) : PAR_native_value(false, false);
else if (MSC_match(KW_PASSWORD))
db->dbb_r_password = sql ? SQL_var_or_string(false) : PAR_native_value(false, false);
else if (MSC_match(KW_USER))
db->dbb_r_user = sql ? SQL_var_or_string(false) : PAR_native_value(false, false);
else if (MSC_match(KW_LC_MESSAGES))
db->dbb_r_lc_messages = sql ? SQL_var_or_string(false) : PAR_native_value(false, false);
else if (!sql && MSC_match(KW_LC_CTYPE))
db->dbb_r_lc_ctype = sql ? SQL_var_or_string(false) : PAR_native_value(false, false);
else
db->dbb_runtime = sql ? SQL_var_or_string(false) : PAR_native_value(false, false);
}
#ifdef GPRE_ADA
if ((gpreGlob.sw_language == lang_ada) && (gpreGlob.token_global.tok_keyword == KW_HANDLES))
{
PAR_get_token();
if (isQuoted(gpreGlob.token_global.tok_type))
CPR_s_error("quoted file name");
int len = gpreGlob.token_global.tok_length;
if (len > MAXPATHLEN - 2)
len = MAXPATHLEN - 2;
MSC_copy(gpreGlob.token_global.tok_string, len, s);
s[len] = 0;
strcat(s, ".");
if (!gpreGlob.ada_package[0] || !strcmp(gpreGlob.ada_package, s))
{
fb_utils::copy_terminate(gpreGlob.ada_package, s, MAXPATHLEN);
}
else
{
fb_utils::snprintf(s, sizeof(s),
"Ada handle package \"%s\" already in use, ignoring package %s",
gpreGlob.ada_package, gpreGlob.token_global.tok_string);
CPR_warn(s);
}
PAR_get_token();
}
#endif
if (gpreGlob.sw_language != lang_fortran)
MSC_match(KW_SEMI_COLON);
bool found_error = false;
try {
if (!MET_database(db, true))
found_error = true;
}
// CVC: It avoids countless errors if the db can't be loaded.
catch (const Firebird::Exception& exc)
{
found_error = true;
// CVC: Print the low level error. The lack of this caused me a lot of problems.
// Granted, status_exception doesn't help, but fatal_exception carries a
// meaningful message.
CPR_error(exc.what());
}
if (found_error)
{
fb_utils::snprintf(s, sizeof(s), "Couldn't access database %s = '%s'",
db->dbb_name->sym_string, db->dbb_filename);
CPR_error(s);
CPR_abort();
}
db->dbb_next = gpreGlob.isc_databases;
gpreGlob.isc_databases = db;
HSH_insert(symbol);
// Load up the symbol (hash) table with relation names from this databases.
MET_load_hash_table(db);
#ifdef FTN_BLK_DATA
if ((gpreGlob.sw_language == lang_fortran) && (db->dbb_scope != DBB_EXTERN))
block_data_list(db);
#endif
// Since we have a real DATABASE statement, get rid of any artificial
// databases that were created because of an INCLUDE SQLCA statement.
for (gpre_dbb** db_ptr = &gpreGlob.isc_databases; *db_ptr;)
{
if ((*db_ptr)->dbb_flags & DBB_sqlca)
*db_ptr = (*db_ptr)->dbb_next;
else
db_ptr = &(*db_ptr)->dbb_next;
}
return action;
}
//____________________________________________________________
//
// Parse end of statement. All languages except ADA leave
// the trailing semi-colon dangling. ADA, however, must
// eat the semi-colon as part of the statement. In any case,
// return true is a semi-colon is/was there, otherwise return false.
//
bool PAR_end()
{
if ((gpreGlob.sw_language == lang_ada) || (gpreGlob.sw_language == lang_c) ||
(isLangCpp(gpreGlob.sw_language))
#ifdef GPRE_COBOL
||
(gpreGlob.sw_language == lang_cobol && isAnsiCobol(gpreGlob.sw_cob_dialect))
#endif
)
{
return (MSC_match(KW_SEMI_COLON));
}
return (gpreGlob.token_global.tok_keyword == KW_SEMI_COLON);
}
//____________________________________________________________
//
// Report an error during parse and unwind.
//
[[noreturn]] void PAR_error(const TEXT* string)
{
CPR_error(string);
PAR_unwind();
}
//____________________________________________________________
//
// Parse an event init statement, preparing
// to wait on a number of named gpreGlob.events.
//
act* PAR_event_init(bool sql)
{
//char req_name[128];
// make up statement node
SQL_resolve_identifier("<identifier>", NULL, MAX_EVENT_SIZE);
//SQL_resolve_identifier("<identifier>", req_name, sizeof(req_name));
//strcpy(gpreGlob.token_global.tok_string, req_name); Why? It's already done.
gpre_nod* init = MSC_node(nod_event_init, 4);
init->nod_arg[0] = (gpre_nod*) PAR_symbol(SYM_dummy);
init->nod_arg[3] = (gpre_nod*) gpreGlob.isc_databases;
act* action = MSC_action(0, ACT_event_init);
action->act_object = (ref*) init;
// parse optional database handle
if (!MSC_match(KW_LEFT_PAREN))
{
gpre_sym* symbol = gpreGlob.token_global.tok_symbol;
if (symbol && (symbol->sym_type == SYM_database))
init->nod_arg[3] = (gpre_nod*) symbol->sym_object;
else
CPR_s_error("left parenthesis or database handle");
PAR_get_token();
if (!MSC_match(KW_LEFT_PAREN))
CPR_s_error("left parenthesis");
}
// eat any number of event strings until a right paren is found,
// pushing the gpreGlob.events onto a stack
gpre_nod* node;
gpre_lls* stack = NULL;
int count = 0;
while (true)
{
if (MSC_match(KW_RIGHT_PAREN))
break;
const gpre_sym* symbol;
if (!sql && (symbol = gpreGlob.token_global.tok_symbol) && symbol->sym_type == SYM_context)
{
gpre_ctx* context;
gpre_fld* field = EXP_field(&context);
ref* reference = EXP_post_field(field, context, false);
node = MSC_node(nod_field, 1);
node->nod_arg[0] = (gpre_nod*) reference;
}
else
{
node = MSC_node(nod_null, 1);
if (sql)
node->nod_arg[0] = (gpre_nod*) SQL_var_or_string(false);
else
node->nod_arg[0] = (gpre_nod*) PAR_native_value(false, false);
}
MSC_push(node, &stack);
count++;
MSC_match(KW_COMMA);
}
// pop the event strings off the stack
gpre_nod* event_list = init->nod_arg[1] = MSC_node(nod_list, (SSHORT) count);
gpre_nod** ptr = event_list->nod_arg + count;
while (stack)
*--ptr = (gpre_nod*) MSC_pop(&stack);
MSC_push((gpre_nod*) action, &gpreGlob.events);
if (!sql)
PAR_end();
return action;
}
//____________________________________________________________
//
// Parse an event wait statement, preparing
// to wait on a number of named gpreGlob.events.
//
act* PAR_event_wait(bool sql)
{
//char req_name[132];
// this is a simple statement, just add a handle
act* action = MSC_action(0, ACT_event_wait);
SQL_resolve_identifier("<identifier>", NULL, MAX_EVENT_SIZE);
//SQL_resolve_identifier("<identifier>", req_name, sizeof(req_name));
//strcpy(gpreGlob.token_global.tok_string, req_name); redundant
action->act_object = (ref*) PAR_symbol(SYM_dummy);
if (!sql)
PAR_end();
return action;
}
//____________________________________________________________
//
// Perform any last minute stuff necessary at the end of pass1.
//
void PAR_fini()
{
if (cur_for)
CPR_error("unterminated FOR statement");
if (cur_modify)
CPR_error("unterminated MODIFY statement");
if (cur_store)
CPR_error("unterminated STORE statement");
if (cur_error)
CPR_error("unterminated ON_ERROR clause");
if (cur_item)
CPR_error("unterminated ITEM statement");
}
//____________________________________________________________
//
// Get a token or unwind the parse
// if we hit end of file
//
void PAR_get_token()
{
if (CPR_token() == NULL)
{
CPR_error("unexpected EOF");
PAR_unwind();
}
//return NULL;
}
//____________________________________________________________
//
// Do any initialization necessary.
// For one thing, set all current indicators
// to null, since nothing is current. Also,
// set up a block to hold the current routine,
//
// (The 'routine' indicator tells the code
// generator where to put ports to support
// recursive routines and Fortran's strange idea
// of separate sub-modules. For PASCAL only, we
// keep a stack of routines, and pay special attention
// to the main routine.)
//
void PAR_init()
{
SQL_init();
cur_error = cur_fetch = cur_for = cur_modify = cur_store = NULL;
cur_statement = cur_item = NULL;
gpreGlob.cur_routine = MSC_action(0, ACT_routine);
gpreGlob.cur_routine->act_flags |= ACT_main;
MSC_push((gpre_nod*) gpreGlob.cur_routine, &routine_stack);
routine_decl = true;
flag_field = NULL;
brace_count = 0;
namespace_count = 0;
}
static inline void gobble(SCHAR*& string)
{
const SCHAR* s1 = gpreGlob.token_global.tok_string;
while (*s1)
*string++ = *s1++;
PAR_get_token();
}
//____________________________________________________________
//
// Parse a native expression as a string.
//
TEXT* PAR_native_value(bool array_ref, bool handle_ref)
{
SCHAR buffer[512];
SCHAR* string = buffer;
while (true)
{
// PAR_native_values copies the string constants. These are
// passed to api calls. Make sure to enclose these with
// double quotes.
if (gpreGlob.sw_sql_dialect == 1)
{
if (isQuoted(gpreGlob.token_global.tok_type))
{
//const tok_t typ = gpreGlob.token_global.tok_type;
gpreGlob.token_global.tok_length += 2;
*string++ = '\"';
gobble(string);
*string++ = '\"';
break;
}
}
else if (gpreGlob.sw_sql_dialect == 2)
{
if (gpreGlob.token_global.tok_type == tok_dblquoted)
PAR_error("Ambiguous use of double quotes in dialect 2");
else if (gpreGlob.token_global.tok_type == tok_sglquoted)
{
gpreGlob.token_global.tok_length += 2;
*string++ = '\"';
gobble(string);
*string++ = '\"';
break;
}
}
else if (gpreGlob.sw_sql_dialect == 3)
{
if (gpreGlob.token_global.tok_type == tok_sglquoted)
{
gpreGlob.token_global.tok_length += 2;
*string++ = '\"';
gobble(string);
*string++ = '\"';
break;
}
}
if (gpreGlob.token_global.tok_keyword == KW_AMPERSAND || gpreGlob.token_global.tok_keyword == KW_ASTERISK)
gobble(string);
if (gpreGlob.token_global.tok_type != tok_ident)
CPR_s_error("identifier");
gobble(string);
// For ADA, gobble '<attribute>
if ((gpreGlob.sw_language == lang_ada) && (gpreGlob.token_global.tok_string[0] == '\'')) {
gobble(string);
}
kwwords_t keyword = gpreGlob.token_global.tok_keyword;
if (keyword == KW_LEFT_PAREN)
{
int parens = 1;
while (parens)
{
const tok_t typ = gpreGlob.token_global.tok_type;
if (isQuoted(typ))
*string++ = (typ == tok_sglquoted) ? '\'' : '\"';
gobble(string);
if (isQuoted(typ))
*string++ = (typ == tok_sglquoted) ? '\'' : '\"';
keyword = gpreGlob.token_global.tok_keyword;