]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/CodeTools/TianoTools/Pccts/antlr/fcache.c
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / CodeTools / TianoTools / Pccts / antlr / fcache.c
CommitLineData
878ddf1f 1/*\r
2 * fcache.c\r
3 *\r
4 * SOFTWARE RIGHTS\r
5 *\r
6 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
7 * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
8 * company may do whatever they wish with source code distributed with\r
9 * PCCTS or the code generated by PCCTS, including the incorporation of\r
10 * PCCTS, or its output, into commerical software.\r
11 *\r
12 * We encourage users to develop software with PCCTS. However, we do ask\r
13 * that credit is given to us for developing PCCTS. By "credit",\r
14 * we mean that if you incorporate our source code into one of your\r
15 * programs (commercial product, research project, or otherwise) that you\r
16 * acknowledge this fact somewhere in the documentation, research report,\r
17 * etc... If you like PCCTS and have developed a nice tool with the\r
18 * output, please mention that you developed it using PCCTS. In\r
19 * addition, we ask that this header remain intact in our source code.\r
20 * As long as these guidelines are kept, we expect to continue enhancing\r
21 * this system and expect to make other tools available as they are\r
22 * completed.\r
23 *\r
24 * ANTLR 1.33MR10\r
25 *\r
26 */\r
27\r
28#include <stdio.h>\r
29#include <ctype.h>\r
30\r
31#include "pcctscfg.h"\r
32\r
33#include "set.h"\r
34#include "syn.h"\r
35#include "hash.h"\r
36#include "generic.h"\r
37\r
38#ifdef __USE_PROTOS\r
39CacheEntry *dumpFcache1(char *prev)\r
40#else\r
41CacheEntry *dumpFcache1(prev)\r
42 char *prev;\r
43#endif\r
44{\r
45 Entry **table=Fcache;\r
46\r
47 int low=0;\r
48 int hi=0;\r
49\r
50 CacheEntry *least=NULL;\r
51\r
52 Entry **p;\r
53\r
54 for (p=table; p<&(table[HashTableSize]); p++) {\r
55\r
56 CacheEntry *q =(CacheEntry *) *p;\r
57 \r
58 if ( q != NULL && low==0 ) low = p-table;\r
59 while ( q != NULL ) {\r
60 if (strcmp(q->str,prev) > 0) {\r
61 if (least == NULL) {\r
62 least=q;\r
63 } else {\r
64 if (strcmp(q->str,least->str) < 0) {\r
65 least=q;\r
66 };\r
67 };\r
68 };\r
69 q = q->next;\r
70 };\r
71\r
72 if ( *p != NULL ) hi = p-table;\r
73 }\r
74 return least;\r
75}\r
76\r
77#ifdef __USE_PROTOS\r
78void reportFcache(CacheEntry *q)\r
79#else\r
80void reportFcache(q)\r
81 CacheEntry *q;\r
82#endif\r
83{\r
84 char *qstr;\r
85\r
86 fprintf(stdout,"\nrule ");\r
87 for (qstr=q->str; *qstr != '*' ; qstr++) {\r
88 fprintf(stdout,"%c",*qstr);\r
89 };\r
90\r
91 qstr++;\r
92 if (*qstr == 'i') fprintf(stdout," First[");\r
93 if (*qstr == 'o') fprintf(stdout," Follow[");\r
94 qstr++;\r
95 fprintf(stdout,"%s]",qstr);\r
96 if (q->incomplete) fprintf(stdout," *** incomplete ***");\r
97 fprintf(stdout,"\n");\r
98 MR_dumpTokenSet(stdout,1,q->fset);\r
99}\r
100\r
101void \r
102#ifdef __USE_PROTOS\r
103DumpFcache(void) \r
104#else\r
105DumpFcache() \r
106#endif\r
107{\r
108\r
109 char *prev="";\r
110 int n=0;\r
111 CacheEntry *next;\r
112\r
113 fprintf(stdout,"\n\nDump of First/Follow Cache\n");\r
114\r
115 for(;;) {\r
116 next=dumpFcache1(prev);\r
117 if (next == NULL) break;\r
118 reportFcache(next);\r
119 ++n;\r
120 prev=next->str;\r
121 };\r
122 fprintf(stdout,"\nEnd dump of First/Follow Cache\n");\r
123}\r