-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.c
2128 lines (1954 loc) · 69.3 KB
/
gen.c
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 NAME: gen.c
Copyright (C) 1997-2016 Vladimir Makarov.
Written by Vladimir Makarov <[email protected]>
This file is part of the tool SHILKA.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
TITLE: generator of Shilka (keywords description translator)
DESCRIPTION: This file generates interface and implementation file of
the keywords recognizer.
SPECIAL CONSIDERATION:
The generator is to be called after Shilka semantic analyzer only
if any error was not fixed.
Defining macro `NDEBUG' (e.g. by option `-D' in C compiler
command line) during the file compilation disables to fix
some internal errors of the generator.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* #ifdef HAVE_CONFIG_H */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hashtab.h"
#include "bits.h"
#include "ticker.h"
#include "vlobject.h"
#include "errors.h"
#include "common.h"
#include "tab.h"
#include "ird.h"
#include "gen.h"
#include <limits.h>
#include <assert.h>
/* The following variable values are times of
building pruned O-trie
code output
*/
static ticker_t pruned_O_trie_time;
static ticker_t output_time;
/* This page contains functions which are used to output the keywords
recognizer. These function are used to fix output errors in time.
All output of the recognizer is made only through these
function. */
/* The following variable value is number of current line in the
description file. */
static int current_description_file_line;
/* The following variable value is number of current line in the
interface file. */
static int current_interface_file_line;
/* The following variable value is number of current line in the
implementation file. */
static int current_implementation_file_line;
/* This function outputs string onto description, interface, or
implementation file and fixes output errors. The function can
output in regime when letters are output only in lower case. */
static void
generalized_output_string (FILE *f, const char *string, int tolower_flag)
{
for (; *string != '\0'; string++)
{
if ((tolower_flag && fputc (our_tolower (*string), f) == EOF)
|| (!tolower_flag && fputc (*string, f) == EOF))
{
if (f == output_description_file)
system_error (TRUE, no_position, "fatal error -- %s: ",
output_description_file_name);
else if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else if (f == output_implementation_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
else
assert (f == stderr);
}
if (*string == '\n')
{
if (f == output_description_file)
current_description_file_line++;
else if (f == output_interface_file)
current_interface_file_line++;
else if (f == output_implementation_file)
current_implementation_file_line++;
}
}
}
/* This function outputs string onto interface or implementation file
and fixes output errors. */
static void
output_string (FILE *f, const char *string)
{
generalized_output_string (f, string, FALSE);
}
/* This function outputs character onto interface or implementation
file and fixes output errors. */
static void
output_char (int ch, FILE *f)
{
if (fputc (ch, f) == EOF)
{
if (f == output_description_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_description_file_name);
else if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else if (f == output_implementation_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
else
assert (f == stderr);
}
if (ch == '\n')
{
if (f == output_description_file)
current_description_file_line++;
else if (f == output_interface_file)
current_interface_file_line++;
else if (f == output_implementation_file)
current_implementation_file_line++;
}
}
static void
output_decimal_number (FILE *f, int number, int minimum_width)
{
char format [30];
assert (minimum_width >= 0);
sprintf (format, "%%%dd", minimum_width);
if (fprintf (f, format, number) == EOF)
{
if (f == output_description_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_description_file_name);
else if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else if (f == output_implementation_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
else
assert (f == stderr);
}
}
static void
output_octal_number (FILE *f, int number, int minimum_width)
{
char format [30];
assert (minimum_width >= 0);
sprintf (format, "%%%do", minimum_width);
if (fprintf (f, format, number) == EOF)
{
if (f == output_description_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_description_file_name);
else if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else if (f == output_implementation_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
else
assert (f == stderr);
}
}
/* ??? */
static void
initiate_output (void)
{
current_interface_file_line = 1;
current_implementation_file_line = 1;
if (v_flag)
{
current_description_file_line = 1;
output_description_file = fopen (output_description_file_name, "w");
if (output_description_file == NULL)
system_error (TRUE, no_position,
"fatal error -- %s: ", output_description_file_name);
}
if (interface_flag)
{
output_interface_file = fopen (output_interface_file_name, "w");
if (output_interface_file == NULL)
system_error (TRUE, no_position,
"fatal error -- %s: ", output_interface_file_name);
}
output_implementation_file = fopen (output_implementation_file_name, "w");
if (output_implementation_file == NULL)
system_error (TRUE, no_position,
"fatal error -- %s: ", output_implementation_file_name);
}
static void
output_character_representation (FILE *f, int char_code)
{
char representation [20];
char *str;
if (isprint (char_code) && char_code != '\\' && char_code != '\'')
{
representation[0] = '\'';
representation[1] = char_code;
representation[2] = '\'';
representation[3] = '\0';
str = representation;
}
else
{
if (char_code == '\n')
str = "'\\n'";
else if (char_code == '\t')
str = "'\\t'";
else if (char_code == '\v')
str = "'\\v'";
else if (char_code == '\b')
str = "'\\b'";
else if (char_code == '\r')
str = "'\\r'";
else if (char_code == '\f')
str = "'\\f'";
else if (char_code == '\\')
str = "'\\\\'";
else if (char_code == '\'')
str = "'\\''";
else
{
sprintf (representation, "'\\%o'", char_code);
str = representation;
}
}
output_string (f, str);
}
static void
make_the_same_name_keyword_lists (void)
{
IR_node_t current_keyword;
IR_node_t keyword_in_table;
IR_node_t next;
initiate_keyword_name_table ();
IR_set_keyword_names_number (description, 0);
for (current_keyword = IR_keyword_list (description);
current_keyword != NULL;
current_keyword = IR_next_keyword (current_keyword))
{
keyword_in_table = insert_keyword_name (current_keyword);
IR_set_first_the_same_name_keyword_flag
(current_keyword, keyword_in_table == current_keyword);
if (IR_first_the_same_name_keyword_flag (current_keyword))
{
IR_set_keyword_name_index (current_keyword, 0);
IR_set_next_the_same_name_keyword (current_keyword, NULL);
IR_set_keyword_names_number
(description, IR_keyword_names_number (description) + 1);
}
else
{
next = IR_next_the_same_name_keyword (keyword_in_table);
IR_set_keyword_name_index
(current_keyword,
(next == NULL ? 1 : IR_keyword_name_index (next) + 1));
IR_set_next_the_same_name_keyword (current_keyword, next);
IR_set_next_the_same_name_keyword (keyword_in_table,
current_keyword);
}
}
finish_keyword_name_table ();
}
static int
the_same_length_keyword_list_length (IR_node_t list)
{
int result;
IR_node_t current_keyword;
result = 0;
for (current_keyword = list;
current_keyword != NULL;
current_keyword = IR_next_the_same_length_keyword (current_keyword))
result++;
return result;
}
/* The following function makes partition of all keywords on the sets
of the same length keywords. */
static void
make_the_same_length_keyword_partition (void)
{
IR_node_t current_keyword;
IR_node_t null_value;
IR_node_t keyword_set;
int keyword_length;
int vector_length;
int i;
vlo_t the_same_length_keyword_vector;
IR_node_t list;
int keywords_number;
VLO_CREATE (the_same_length_keyword_vector, 0);
null_value = NULL;
keywords_number = 0;
for (current_keyword = IR_keyword_list (description);
current_keyword != NULL;
current_keyword = IR_next_keyword (current_keyword))
{
keywords_number++;
keyword_length = strlen (keyword_string (current_keyword));
vector_length = (VLO_LENGTH (the_same_length_keyword_vector)
/ sizeof (IR_node_t));
if (vector_length <= keyword_length)
{
/* Expand the vector */
for (i = 0; i <= keyword_length - vector_length; i++)
VLO_ADD_MEMORY (the_same_length_keyword_vector, &null_value,
sizeof (IR_node_t));
}
IR_set_next_the_same_length_keyword
(current_keyword,
((IR_node_t *) VLO_BEGIN (the_same_length_keyword_vector))
[keyword_length]);
((IR_node_t *) VLO_BEGIN (the_same_length_keyword_vector))
[keyword_length] = current_keyword;
}
IR_set_keywords_number (description, keywords_number);
IR_set_keyword_set_list (description, NULL);
for (keyword_length = (VLO_LENGTH (the_same_length_keyword_vector)
/ sizeof (IR_node_t) - 1);
keyword_length >= 0;
keyword_length--)
{
list = (((IR_node_t *) VLO_BEGIN (the_same_length_keyword_vector))
[keyword_length]);
if (list != NULL)
{
keyword_set
= IR_new_keyword_set
(keyword_length, list,
the_same_length_keyword_list_length (list),
IR_keyword_set_list (description));
IR_set_keyword_set_list (description, keyword_set);
}
}
VLO_DELETE (the_same_length_keyword_vector);
}
/* Abstract data `trie nodes'. */
static IR_node_t first_free_trie_node;
static int allocated_trie_nodes_number = 0;
static void
free_trie_node (IR_node_t trie_node)
{
IR_set_next_trie_node (trie_node, first_free_trie_node);
first_free_trie_node = trie_node;
}
static void
free_trie_list_and_below (IR_node_t trie_node_list)
{
IR_node_t current_trie_node;
IR_node_t next_trie_node;
for (current_trie_node = trie_node_list;
current_trie_node != NULL;
current_trie_node = next_trie_node)
{
next_trie_node = IR_next_trie_node (current_trie_node);
free_trie_list_and_below (IR_trie_node_list (current_trie_node));
free_trie_node (current_trie_node);
}
}
static IR_node_t
get_free_trie_node (void)
{
IR_node_t new_trie_node;
if (first_free_trie_node == NULL)
{
allocated_trie_nodes_number++;
new_trie_node = IR_new_trie_node ();
}
else
{
new_trie_node = first_free_trie_node;
first_free_trie_node = IR_next_trie_node (first_free_trie_node);
}
IR_set_next_trie_node (new_trie_node, NULL);
return new_trie_node;
}
static void
initiate_trie_nodes (void)
{
first_free_trie_node = NULL;
}
static void
finish_trie_nodes (void)
{
}
static void
swap_index (int *index_array, int i, int j)
{
int temp;
temp = index_array [i];
index_array [i] = index_array [j];
index_array [j] = temp;
}
static int key_char_index;
static int
keyword_comparison (const void *keyword_1, const void *keyword_2)
{
int char_1;
int char_2;
char_1 = keyword_string (*(IR_node_t *) keyword_1) [key_char_index];
char_2 = keyword_string (*(IR_node_t *) keyword_2) [key_char_index];
if (char_1 > char_2)
return 1;
else if (char_1 < char_2)
return -1;
else
return 0;
}
static void
make_partition (IR_node_t *keyword_array, int keyword_array_length,
vlo_t *partition, int char_index)
{
int keyword_index;
int previous_char;
assert (keyword_array_length > 1);
key_char_index = char_index;
qsort (keyword_array, keyword_array_length, sizeof (IR_node_t),
keyword_comparison);
VLO_NULLIFY (*partition);
previous_char = keyword_string (*keyword_array) [char_index];
for (keyword_index = 0;
keyword_index < keyword_array_length;
keyword_index++)
if (previous_char
!= keyword_string (keyword_array [keyword_index]) [char_index])
{
VLO_ADD_MEMORY (*partition, &keyword_index, sizeof (int));
previous_char
= keyword_string (keyword_array [keyword_index]) [char_index];
}
VLO_ADD_MEMORY (*partition, &keyword_index, sizeof (int));
}
#if 0
static void
set_the_heuristic_best_index (IR_node_t *keyword_array,
int keyword_array_length,
int *index_array, int index_array_length)
{
vlo_t partition;
int index_index;
int *current_bound_ptr;
int start;
unsigned int sum;
unsigned int minimum_sum;
int i;
int the_best_index;
VLO_CREATE (partition, 0);
minimum_sum = UINT_MAX;
for (index_index = 0; index_index < index_array_length; index_index++)
{
make_partition (keyword_array, keyword_array_length,
&partition, index_array [index_index]);
sum = 0;
for (start = 0, current_bound_ptr = VLO_BEGIN (partition);
(char *) current_bound_ptr <= (char *) VLO_END (partition);
start = *current_bound_ptr, current_bound_ptr++)
if (*current_bound_ptr - start > 1)
for (i = start; i < *current_bound_ptr; i++)
sum += IR_frequency (keyword_array [i]);
if (minimum_sum > sum)
{
minimum_sum = sum;
the_best_index = index_index;
if (sum == 0)
break;
}
}
assert (minimum_sum != UINT_MAX);
swap_index (index_array, the_best_index, index_array_length - 1);
VLO_DELETE (partition);
}
#endif
static IR_node_t
find_trie (int max_cost, int original_accumulated_cost,
IR_node_t *keyword_array, int keyword_array_length,
int *index_array, int index_array_length)
{
int *current_bound_ptr;
int start;
int minimum_recognition_cost;
int accumulated_cost;
int keyword_index;
int index_index;
int new_index_flag;
IR_node_t result;
IR_node_t trie_node;
IR_node_t first_trie_node;
IR_node_t current_trie_node;
vlo_t partition;
assert (keyword_array_length > 0);
if (keyword_array_length == 1)
{
trie_node = get_free_trie_node ();
IR_set_recognition_cost (trie_node, 0);
IR_set_keyword (trie_node, *keyword_array);
IR_set_trie_node_list (trie_node, NULL);
return trie_node;
}
assert (index_array_length > 0);
minimum_recognition_cost = 0;
for (keyword_index = 0;
keyword_index < keyword_array_length;
keyword_index++)
minimum_recognition_cost += IR_frequency (keyword_array [keyword_index]);
if (original_accumulated_cost + minimum_recognition_cost >= max_cost)
return NULL;
result = NULL;
#if 0
set_the_heuristic_best_index (keyword_array, keyword_array_length,
index_array, index_array_length);
#endif
VLO_CREATE (partition, 0);
for (index_index = 0; index_index < index_array_length; index_index++)
{
make_partition (keyword_array, keyword_array_length,
&partition, index_array [index_index]);
accumulated_cost = original_accumulated_cost + minimum_recognition_cost;
first_trie_node = NULL;
new_index_flag = FALSE;
for (start = 0, current_bound_ptr = VLO_BEGIN (partition);
(char *) current_bound_ptr <= (char *) VLO_END (partition);
start = *current_bound_ptr, current_bound_ptr++)
{
if (accumulated_cost >= max_cost)
{
new_index_flag = TRUE;
break;
}
swap_index (index_array, index_index, index_array_length - 1);
trie_node
= find_trie (max_cost, accumulated_cost,
keyword_array + start, *current_bound_ptr - start,
index_array, index_array_length - 1);
swap_index (index_array, index_index, index_array_length - 1);
if (trie_node == NULL)
{
new_index_flag = TRUE;
break;
}
IR_set_character_code
(trie_node,
keyword_string (keyword_array [start])
[index_array [index_index]]);
IR_set_next_trie_node (trie_node, first_trie_node);
first_trie_node = trie_node;
accumulated_cost += IR_recognition_cost (trie_node);
}
if (new_index_flag)
{
free_trie_list_and_below (first_trie_node);
continue;
}
trie_node = get_free_trie_node ();
IR_set_recognition_cost
(trie_node, accumulated_cost - original_accumulated_cost);
if (max_cost > accumulated_cost)
max_cost = accumulated_cost;
IR_set_keyword (trie_node, NULL);
IR_set_trie_node_list (trie_node, first_trie_node);
for (current_trie_node = IR_trie_node_list (trie_node);
current_trie_node != NULL;
current_trie_node = IR_next_trie_node (current_trie_node))
IR_set_upper_trie_node_level (current_trie_node, trie_node);
IR_set_trie_node_list_index (trie_node, index_array [index_index]);
if (result == NULL
|| IR_recognition_cost (trie_node) < IR_recognition_cost (result))
{
if (result != NULL)
free_trie_list_and_below (result);
result = trie_node;
}
else
free_trie_list_and_below (trie_node);
if (accumulated_cost
== original_accumulated_cost + minimum_recognition_cost)
break; /* The best partition is already achieved. */
}
VLO_DELETE (partition);
return result;
}
/* ??? */
static void
build_pruned_O_trie (void)
{
vlo_t keywords;
vlo_t indexes;
int i;
IR_node_t trie_node;
IR_node_t current_keyword;
IR_node_t current_keyword_set;
IR_node_t current_trie_node;
VLO_CREATE (keywords, 0);
VLO_CREATE (indexes, 0);
for (current_keyword_set = IR_keyword_set_list (description);
current_keyword_set != NULL;
current_keyword_set = IR_next_keyword_set (current_keyword_set))
{
#ifndef NDEBUG
if (debug_flag)
fprintf (stderr, "keywords of length = %d\n",
IR_length (current_keyword_set));
#endif
VLO_NULLIFY (keywords);
for (current_keyword
= IR_the_same_length_keyword_list (current_keyword_set);
current_keyword != NULL;
current_keyword = IR_next_the_same_length_keyword (current_keyword))
VLO_ADD_MEMORY (keywords, ¤t_keyword, sizeof (IR_node_t));
if (VLO_LENGTH (keywords) / sizeof (IR_node_t) <= 1)
{
IR_set_trie_node_list (current_keyword_set, NULL);
continue;
}
VLO_NULLIFY (indexes);
for (i = 0; i < IR_length (current_keyword_set); i++)
VLO_ADD_MEMORY (indexes, &i, sizeof (int));
trie_node = find_trie (INT_MAX, 0,
(IR_node_t *) VLO_BEGIN (keywords),
VLO_LENGTH (keywords) / sizeof (IR_node_t),
(int *) VLO_BEGIN (indexes),
VLO_LENGTH (indexes) / sizeof (int));
assert (trie_node != NULL);
IR_set_recognition_cost (current_keyword_set,
IR_recognition_cost (trie_node));
IR_set_trie_node_list (current_keyword_set,
IR_trie_node_list (trie_node));
IR_set_trie_node_list_index (current_keyword_set,
IR_trie_node_list_index (trie_node));
for (current_trie_node = IR_trie_node_list (current_keyword_set);
current_trie_node != NULL;
current_trie_node = IR_next_trie_node (current_trie_node))
IR_set_upper_trie_node_level (current_trie_node, current_keyword_set);
free_trie_node (trie_node);
}
VLO_DELETE (keywords);
VLO_DELETE (indexes);
}
/* ??? Is it used. */
/* This page contains functions which are used to output parameterized
names of keywords recognizer objects. Usually the parameter is
prefix given in Shilka command line (see commentaries for variable
`prefix'). */
/* Base name of debug macro parameter used to separate debug code in
keywords recognizer. Full name of the macro parameter is
`__KR_DEBUG__' (see function `output_ifdef_parameter_name'). */
#define DEBUG_PARAMETER_NAME "DEBUG"
/* This function outputs name of debug macro parameter used to
separate debug code in the keywords recognizer. The name is output
as `__<prefix><base_name>__' where prefix is value of variable
`prefix' and base name is value of the second parameter. */
static void
output_ifdef_parameter_name (FILE *f, const char *ifdef_parameter_name)
{
output_string (f, "__");
output_string (f, prefix);
output_string (f, ifdef_parameter_name);
output_string (f, "__");
}
/* Is it used? */
/* This page contains functions for output of C preprocessors lines
(`#ifdef ...', `#ifndef ', `#endif ... ', and `#line ...'). */
/* This function outputs C preprocessor line `#ifdef ...' which
contains parameter with given base name (see function
`output_ifdef_parameter_name'). */
static void
output_ifdef (FILE *f, const char *ifdef_parameter_base_name)
{
output_string (f, "#ifdef ");
output_ifdef_parameter_name (f, ifdef_parameter_base_name);
output_char ('\n', f);
}
/* This function outputs C preprocessor line `#ifndef ...' which
contains parameter with given base name (see function
`output_ifdef_parameter_name'). */
static void
output_ifndef (FILE *f, const char *ifdef_parameter_base_name)
{
output_string (f, "#ifndef ");
output_ifdef_parameter_name (f, ifdef_parameter_base_name);
output_char ('\n', f);
}
/* This function outputs C preprocessor line `#endif ...' which
contains parameter with given base name (see function
`output_ifdef_parameter_name'). */
static void
output_endif (FILE *f, const char *ifdef_parameter_base_name)
{
output_string (f, "#endif /* ");
output_ifdef_parameter_name (f, ifdef_parameter_base_name);
output_string (f, " */\n");
}
/* This function outputs C preprocessor line `#line ...' which
contains given line number and given file name as C string
constant. */
static void
output_line (FILE *f, int line_number, const char *file_name)
{
output_string (f, "\n#line ");
output_decimal_number (f, line_number, 0);
output_string (f, " \"");
output_string (f, file_name);
output_string (f, "\"\n");
}
/* ??? */
static void
output_current_line (FILE *f)
{
output_string (f, "\n#line ");
if (f == output_interface_file)
{
output_decimal_number (f, current_interface_file_line + 1, 0);
output_string (f, " \"");
output_string (f, output_interface_file_name);
}
else
{
assert (f == output_implementation_file);
output_decimal_number (f, current_implementation_file_line + 1, 0);
output_string (f, " \"");
output_string (f, output_implementation_file_name);
}
output_string (f, "\"\n");
}
/* ??? */
static void
output_interface_start_code_insertions (void)
{
IR_node_t current_declaration;
FILE *import_code_file;
if (IR_declaration_list (description) == NULL)
return;
if (interface_flag)
import_code_file = output_interface_file;
else
import_code_file = output_implementation_file;
for (current_declaration = IR_declaration_list (description);
current_declaration != NULL;
current_declaration = IR_next_declaration (current_declaration))
if (IR_IS_OF_TYPE (current_declaration, IR_NM_import_code))
{
output_line (import_code_file,
IR_position (current_declaration).line_number,
IR_position (current_declaration).file_name);
output_string (import_code_file,
IR_code_insertion_itself (IR_code_itself
(current_declaration)));
output_char ('\n', import_code_file);
output_current_line (import_code_file);
}
}
static void
output_recognizer_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "recognizer");
}
static void
output_keyword_name (FILE *f, const char *keyword_name)
{
output_string (f, prefix);
output_string (f, keyword_name);
}
static void
output_not_found_value (FILE *f)
{
output_string (f, prefix);
output_string (f, "_not_found");
}
static void
output_keyword_usage_name (FILE *f, IR_node_t keyword)
{
const char *keyword_name;
keyword_name = IR_identifier_itself (IR_name (keyword));
output_string (f, prefix);
output_string (f, keyword_name);
if (IR_keyword_name_index (keyword) != 0)
{
output_char ('_', f);
output_decimal_number (f, IR_keyword_name_index (keyword), 0);
}
output_string (f, "_usage");
}
static void
output_keyword_usage_reference (FILE *f, IR_node_t keyword)
{
if (!cpp_flag)
{
output_recognizer_name (f);
output_string (f, ".");
}
output_keyword_usage_name (f, keyword);
}
static void
output_not_found_value_usage (FILE *f)
{
output_string (f, prefix);
output_string (f, "_not_found_usage");
}
static void
output_not_found_value_usage_reference (FILE *f)
{
if (!cpp_flag)
{
output_recognizer_name (f);
output_string (f, ".");
}
output_not_found_value_usage (f);
}
static void
output_strcaseq_function_name (FILE *f)
{
output_string (f, prefix);
if (length_flag)
output_string (f, "strncaseq");
else
output_string (f, "strcaseq");
}
static void
output_find_keyword_function_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "find_keyword");
}
static void
output_reset_function_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "reset");
}
static void
output_statistics_function_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "output_statistics");
}
static void
output_constructor_function_name (FILE *f)
{
assert (cpp_flag);
output_recognizer_name (f);
}
static void
output_destructor_function_name (FILE *f)
{
assert (cpp_flag);
output_char ('~', f);
output_recognizer_name (f);
}
static void
output_keyword_parameter_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "keyword");
}
static void
output_low_string_parameter_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "tolower");
}
static void
output_length_parameter_name (FILE *f)