]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/CodeTools/Source/Pccts/antlr/globals.c
More renames for Tool Packages
[mirror_edk2.git] / Tools / CodeTools / Source / Pccts / antlr / globals.c
CommitLineData
878ddf1f 1/*\r
2 * globals.c -- File containing all variables/tables visible to all files.\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.33\r
25 * Terence Parr\r
26 * Parr Research Corporation\r
27 * with Purdue University and AHPCRC, University of Minnesota\r
28 * 1989-2001\r
29 */\r
30\r
31#include <stdio.h>\r
32\r
33#include "pcctscfg.h"\r
34\r
35#include "set.h"\r
36#include "syn.h"\r
37#include "hash.h"\r
38#include "generic.h"\r
39\r
40char Version[] = "1.33MR33" ; /* PCCTS version number */ /* MRXXX */\r
41char VersionDef[] = "13333"; /* same (except int equiv for preproc symbol) */ /* MRXXX */\r
42\r
43char LexStartSymbol[] = "START";/* Name of starting lexical class/automaton */\r
44char *RemapFileName = "remap.h";\r
45char *DlgFileName = "parser.dlg";\r
46char *DefFileName = "tokens.h";\r
47char *ErrFileName = "err.c";\r
48char *ModeFileName = "mode.h";\r
49char *StdMsgName = NULL;\r
50\r
51char *ParserName = DefaultParserName;\r
52\r
53/* list of PCCTS supplied support symbols; these are renamed when more than\r
54 * one ANTLR-generated parsers are linked together to avoid name conflicts.\r
55 * Can't use '##' ANSIC preprocessor concat operator with K&R and:\r
56 * #define zzskip zzparser ## skip\r
57 * will not work for ANSI/C++ as 'zzparserskip' is created w/o zzparser\r
58 * being substituted--ack!!!\r
59 */\r
60char *StandardSymbols[] = {\r
61/* ANTLR stuff */\r
62 "zzStackOvfMsg",\r
63 "zzasp",\r
64 "zzaStack",\r
65 "inf_tokens",\r
66 "inf_text",\r
67 "inf_text_buffer",\r
68 "inf_text_buffer_ptr",\r
69 "inf_text_buffer_size",\r
70 "inf_labase",\r
71 "inf_last",\r
72 "inf_lap",\r
73 "zztokenLA",\r
74 "zztextLA",\r
75 "zzlap",\r
76 "zzlabase",\r
77 "zztoktext",\r
78 "zztoken",\r
79 "zzdirty",\r
80 "zzguessing",\r
81 "zzguess_start",\r
82 "zzresynch",\r
83 "zzinf_tokens",\r
84 "zzinf_text",\r
85 "zzinf_text_buffer",\r
86 "zzinf_labase",\r
87 "zzinf_last",\r
88 "zzfill_inf_look",\r
89 "zzFAIL",\r
90 "zzsave_antlr_state",\r
91 "zzrestore_antlr_state",\r
92 "zzsyn",\r
93 "zzset_el",\r
94 "zzset_deg",\r
95 "zzedecode",\r
96 "_zzsetmatch",\r
97 "_zzmatch",\r
98 "_inf_zzgettok",\r
99 "zzconsumeUntil",\r
100 "zzconsumeUntilToken",\r
101 "_zzmatch_wsig",\r
102 "_zzsetmatch_wsig",\r
103 "_zzmatch_wdfltsig",\r
104 "_zzsetmatch_wdfltsig",\r
105 "zzdflthandlers",\r
106/* DLG stuff */\r
107 "zzreal_line",\r
108 "zzcharfull",\r
109 "zzerr",\r
110 "zzlextext",\r
111 "zzbegexpr",\r
112 "zzendexpr",\r
113 "zzbufsize",\r
114 "zzbegcol",\r
115 "zzendcol",\r
116 "zzline",\r
117 "zzchar",\r
118 "zzbufovf",\r
119 "zzrdstream",\r
120 "zzrdfunc",\r
121 "zzrdstr",\r
122 "zzclose_stream",\r
123 "zzsave_dlg_state",\r
124 "zzrestore_dlg_state",\r
125 "zzmode",\r
126 "zzskip",\r
127 "zzmore",\r
128 "zzreplchar",\r
129 "zzreplstr",\r
130 "zzgettok",\r
131 "zzadvance",\r
132 "zzerrstd",\r
133 "zzerr_in",\r
134 "zzconstr_attr",\r
135 "zzempty_attr",\r
136 "zzerraction",\r
137 "zztokens", /* list of token regular expressions */\r
138 "dfa",\r
139 "accepts",\r
140 "actions",\r
141 "zzTraceOptionValue", /* MR10 */\r
142 "zzTraceGuessOptionValue", /* MR10 */\r
143 "zzTraceCurrentRuleName", /* MR10 */\r
144 "zzTraceDepth", /* MR10 */\r
145 "zzGuessSeq", /* MR10 */\r
146 "zzSyntaxErrCount", /* MR11 */\r
147 "zzLexErrCount", /* MR11 */\r
148 "zzTraceGuessDone", /* MR13 - BJS */\r
149 "zzTraceGuessFail", /* MR13 - BJS */\r
150 "zzTraceGuessOption", /* MR13 - BJS */\r
151 "zzTraceIn", /* MR13 - BJS */\r
152 "zzTraceOption", /* MR13 - BJS */\r
153 "zzTraceOut", /* MR13 - BJS */\r
154 "zzTraceReset", /* MR13 - BJS */\r
155 NULL /* must be present */\r
156};\r
157\r
158/* list of PCCTS supplied support functions; these are renamed when more than\r
159 * one ANTLR-generated parsers are linked together to avoid name conflicts.\r
160 */\r
161char *ASTSymbols[] = {\r
162 "AST",\r
163 "zzast_sp",\r
164 "zzastStack",\r
165 "zzlink",\r
166 "zzastnew",\r
167 "zzsubchild",\r
168 "zzsubroot",\r
169 "zzpre_ast",\r
170 "zzfree_ast",\r
171 "zztmake",\r
172 "zzdup_ast",\r
173 "zztfree",\r
174 "zzdouble_link",\r
175 NULL /* must be present */\r
176};\r
177\r
178/* Current ambiguity examination information */\r
179int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;\r
180char *CurAmbigbtype;\r
181\r
182\r
183 /* M e t h o d T a b l e s */\r
184/*\r
185 * The following tables are used to fill syntax diagram nodes with the correct\r
186 * function pointers for computing FIRST sets and printing themselves.\r
187 */\r
188\r
189/* fpTraverse[node type] == pointer to function that calculates trees\r
190 * representing the FIRST sets for that node (maintains spatial info).\r
191 * We use 'struct _tree' not 'tree' due to a g++ 2.4.3 bug.\r
192 */\r
193#ifdef __cplusplus\r
194struct _tree *(*fpTraverse[NumNodeTypes+1])(... /* Node *, int, set * */) = {\r
195 NULL,\r
196 (struct _tree *(*)(...)) tJunc,\r
197 (struct _tree *(*)(...)) tRuleRef,\r
198 (struct _tree *(*)(...)) tToken,\r
199 (struct _tree *(*)(...)) tAction\r
200};\r
201#else\r
202Tree *(*fpTraverse[NumNodeTypes+1])() = {\r
203 NULL,\r
204 tJunc,\r
205 tRuleRef,\r
206 tToken,\r
207 tAction\r
208};\r
209#endif\r
210\r
211/* fpReach[node type] == pointer to function that calculates FIRST set for\r
212 * that node. (r stands for reach). We use 'struct _set' not 'set'\r
213 * due to a g++ 2.4.3 bug.\r
214 */\r
215#ifdef __cplusplus\r
216struct _set (*fpReach[NumNodeTypes+1])(... /* Node *, int, set * */) = {\r
217 NULL,\r
218 (struct _set (*)(...)) rJunc,\r
219 (struct _set (*)(...)) rRuleRef,\r
220 (struct _set (*)(...)) rToken,\r
221 (struct _set (*)(...)) rAction\r
222};\r
223#else\r
224set (*fpReach[NumNodeTypes+1])() = {\r
225 NULL,\r
226 rJunc,\r
227 rRuleRef,\r
228 rToken,\r
229 rAction\r
230};\r
231#endif\r
232\r
233/* fpPrint[node type] == pointer to function that knows how to print that node. */\r
234#ifdef __cplusplus\r
235void (*fpPrint[NumNodeTypes+1])(... /* Node * */) = {\r
236 NULL,\r
237 (void (*)(...)) pJunc,\r
238 (void (*)(...)) pRuleRef,\r
239 (void (*)(...)) pToken,\r
240 (void (*)(...)) pAction\r
241};\r
242#else\r
243void (*fpPrint[NumNodeTypes+1])() = {\r
244 NULL,\r
245 pJunc,\r
246 pRuleRef,\r
247 pToken,\r
248 pAction\r
249};\r
250#endif\r
251\r
252char *decodeJType[] = {\r
253 "invalid",\r
254 "aSubBlk",\r
255 "aOptBlk",\r
256 "aLoopBlk",\r
257 "EndBlk",\r
258 "RuleBlk",\r
259 "Generic",\r
260 "EndRule",\r
261 "aPlusBlk",\r
262 "aLoopBegin"\r
263};\r
264\r
265\r
266 /* H a s h T a b l e s */\r
267\r
268Entry **Tname, /* Table of all token names (maps name to tok num)*/\r
269 **Texpr, /* Table of all token expressions\r
270 (maps expr to tok num) */\r
271 **Rname, /* Table of all Rules (has ptr to start of rule) */\r
272 **Fcache, /* Cache of First/Follow Computations */\r
273 **Tcache; /* Tree cache; First/Follow for permute trees */\r
274Entry **Elabel; /* Table of all element label names */\r
275Entry **Sname; /* Signal names */\r
276Entry **Pname; /* symbolic predicate names MR11 */\r
277\r
278\r
279 /* V a r i a b l e s */\r
280\r
281int Save_argc; /* MR10 */\r
282char **Save_argv; /* MR10 */\r
283int EpToken=0; /* Imaginary Epsilon token number */\r
284int WildCardToken=0;\r
285int CurFile= -1; /* Index into FileStr table */\r
286char *CurPredName=NULL; /* MR11 */\r
287char *CurRule=NULL; /* Pointer to current rule name */\r
288int CurRuleDebug=0; /* MR13 debug flag */\r
289RuleEntry *CurRuleNode=NULL;/* Pointer to current rule node in syntax tree */\r
290char *CurRetDef=NULL; /* Pointer to current return type definition */\r
291char *CurParmDef=NULL; /* Pointer to current parameter definition */\r
292Junction *CurRuleBlk=NULL; /* Pointer to current block node for enclosing block */\r
293ListNode *CurExGroups=NULL; /* Current list of exception groups for rule/alts */\r
294ListNode *CurElementLabels=NULL;\r
295ListNode *CurAstLabelsInActions=NULL; /* MR27 */\r
296\r
297/* MR10 used by <<>>? to set "label_used_in_semantic_pred" */\r
298/* MR10 this will force LT(i) assignment even in guess mode */\r
299\r
300ListNode *CurActionLabels=NULL; /* MR10 Element Labels appearing in last action */\r
301int numericActionLabel=0 ; /* MR10 << ... $1 ... >> or << ... $1 ... >>? */\r
302ListNode *NumericPredLabels=NULL; /* MR10 << ... $1 ... >>? ONLY */\r
303ListNode *ContextGuardPredicateList=NULL; /* MR13 for re-evaluating predicates\r
304 after meta tokens are defined */\r
305\r
306int CurBlockID=0; /* Unique int for each block */\r
307int CurAltNum=0;\r
308Junction *CurAltStart = NULL; /* Junction node that starts the alt */\r
309Junction *OuterAltStart = NULL; /* For chaining exception groups MR7 */\r
310int NumRules=0; /* Rules are from 1 to n */\r
311FILE *output=NULL; /* current parser output file */\r
312FILE *input=NULL; /* current grammar input file */\r
313char *FileStr[MaxNumFiles];/* Ptr to array of file names on command-line */\r
314int NumFiles=0; /* current grammar file number */\r
315#ifdef __cplusplus\r
316void (**fpTrans)(...), /* array of ptrs to funcs that translate nodes */\r
317 (**fpJTrans)(...); /* ... that translate junctions */\r
318#else\r
319void (**fpTrans)(), /* array of ptrs to funcs that translate nodes */\r
320 (**fpJTrans)(); /* ... that translate junctions */\r
321#endif\r
322int **FoStack; /* Array of LL_k ptrs to stacks of rule numbers */\r
323int **FoTOS; /* FOLLOW stack top-of-stack pointers */\r
324Junction *SynDiag = NULL; /* Pointer to start of syntax diagram */\r
325int BlkLevel=1; /* Current block level. Set by antlr.g, used by\r
326 * scanner to translate $i.j attributes */\r
327set reserved_positions; /* set of token positions reserved by '#token T=i' cmds */\r
328set all_tokens; /* set of all token types */\r
329set imag_tokens; /* set of all imaginary token types (EpToken, errclasses...) */\r
330set tokclasses; /* set of all token class token types */\r
331ListNode *ForcedTokens = 0; /* list of token_id/token_num pairs to remap */\r
332ListNode *MetaTokenNodes=NULL; /* list of meta token refs such as token classes etc... */\r
333int *TokenInd=NULL; /* an indirection level between token num and position\r
334 * of that token def in TokenStr and ExprStr */\r
335int LastTokenCounted=0; /* ==TokenNum if no token renumbering (same as old TokenNum) */\r
336int TokenNum=TokenStart;\r
337char **TokenStr=NULL; /* map token # to token name */\r
338char **ExprStr=NULL; /* map token # to expr */\r
339Junction **RulePtr=NULL; /* map rule # to RuleBlk node of rule */\r
340ListNode *ExprOrder=NULL; /* list of exprs as they are found in grammar */\r
341ListNode *BeforeActions=NULL;/* list of grammar actions before rules */\r
342ListNode *AfterActions=NULL;/* list of grammar actions after rules */\r
343ListNode *LexActions=NULL; /* list of lexical actions */\r
344\r
345/* MR1 */\r
346/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */\r
347/* MR1 via #lexmember <<....>> */\r
348/* MR1 via #lexprefix <<....>> */\r
349/* MR1 */\r
350\r
351ListNode *LexMemberActions=NULL;/* list of lexical header member decl MR1 */\r
352ListNode *LexPrefixActions=NULL;/* list of lexical header #include decl MR1 */\r
353ListNode **Cycles=NULL; /* list of cycles (for each k) found when\r
354 doing FOLLOWs */\r
355ListNode *eclasses=NULL; /* list of error classes */\r
356ListNode *tclasses=NULL; /* list of token classes */\r
357LClass lclass[MaxLexClasses]; /* array of lex class definitions */\r
358int CurrentLexClass; /* index into lclass */\r
359int NumLexClasses=0; /* in range 1..MaxLexClasses (init 0) */\r
360\r
361char *HdrAction=NULL; /* action defined with #header */\r
362char *FirstAction=NULL; /* action defined with #first MR11 */\r
363FILE *ErrFile; /* sets and error recovery stuff */\r
364FILE *DefFile=NULL; /* list of tokens, return value structs, setwd defs */\r
365FILE *MRinfoFile=NULL; /* MR10 information file */\r
366int MRinfo=0; /* MR10 */\r
367int MRinfoSeq=0; /* MR10 */\r
368int InfoP=0; /* MR10 predicates */\r
369int InfoT=0; /* MR10 tnodes */\r
370int InfoF=0; /* MR10 first/follow sets */\r
371int InfoM=0; /* MR10 monitor progress */\r
372int InfoO=0; /* MR12 orphan rules */\r
373int TnodesInUse=0; /* MR10 */\r
374int TnodesPeak=0; /* MR10 */\r
375int TnodesAllocated=0; /* MR10 */\r
376int TnodesReportThreshold=0; /* MR11 */\r
377int PotentialSuppression=0; /* MR10 */\r
378int PotentialDummy=0; /* MR10 */\r
379int CannotContinue=FALSE;\r
380int OutputLL_k = 1; /* LL_k for parsing must be power of 2 */\r
381int action_file; /* used to track start of action */\r
382int action_line;\r
383int FoundGuessBlk=0; /* there is a (...)? block somewhere in grammar */\r
384int FoundException=0; /* there is an exception somewhere in grammar */\r
385/* MR6 Distinguish between @ operator and real exception */\r
386/* MR6 by keeping separate flags for @ operator and real exceptions */\r
387int FoundAtOperator=0; /* MR6 */\r
388int FoundExceptionGroup=0; /* MR6 */\r
389int pLevel=0; /* print Level */\r
390int pAlt1,pAlt2; /* print "==>" in front of these alts */\r
391\r
392/* C++ output stuff */\r
393FILE *Parser_h, /* where subclass of ANTLRParser goes */\r
394 *Parser_c; /* where code for subclass of ANTLRParser goes */\r
395char Parser_h_Name[MaxFileName+1] = "";\r
396char Parser_c_Name[MaxFileName+1] = "";\r
397char MRinfoFile_Name[MaxFileName+1] = ""; /* MR10 */\r
398char *ClassDeclStuff=NULL; /* MR10 */\r
399char *BaseClassName=NULL; /* MR22 */\r
400/* list of actions inside the #class {...} defs */\r
401ListNode *class_before_actions=NULL;\r
402ListNode *class_after_actions=NULL;\r
403\r
404char CurrentClassName[MaxRuleName]="";\r
405int no_classes_found=1;\r
406char *UserTokenDefsFile;\r
407int UserDefdTokens=0; /* found #tokdefs? */\r
408char *OutputDirectory=TopDirectory;\r
409ExceptionGroup *DefaultExGroup = NULL;\r
410int NumSignals = NumPredefinedSignals;\r
411int ContextGuardTRAV=0;\r
412\r
413char *MR_AmbAidRule=NULL; /* MR11 */\r
414int MR_AmbAidLine=0; /* MR11 */\r
415int MR_AmbAidDepth=0; /* MR11 */\r
416int MR_AmbAidMultiple=0; /* MR11 */\r
417int MR_skipped_e3_report=0; /* MR11 */\r
418int MR_usingPredNames=0; /* MR11 */\r
419int MR_BadExprSets=0; /* MR13 */\r
420int MR_Inhibit_Tokens_h_Gen=0; /* MR13 */\r
421int NewAST=0; /* MR13 */\r
422int tmakeInParser=0; /* MR23 */\r
423int AlphaBetaTrace=0; /* MR14 */\r
424int MR_BlkErr=0; /* MR21 */\r
425int MR_AlphaBetaMessageCount=0; /* MR14 */\r
426int MR_AlphaBetaWarning=0; /* MR14 */\r
427int MR_ErrorSetComputationActive=0; /* MR14 */\r
428int MR_MaintainBackTrace=0; /* MR14 */\r
429set MR_CompromisedRules; /* MR14 */\r
430\r
431Junction *MR_RuleBlkWithHalt; /* MR10 */\r
432\r
433 /* C m d - L i n e O p t i o n s */\r
434\r
435int LL_k=1; /* how many tokens of full lookahead */\r
436int CLL_k= -1; /* how many tokens of compressed lookahead */\r
437int PrintOut = FALSE; /* print out the grammar */\r
438int PrintAnnotate = FALSE;/* annotate printout with FIRST sets */\r
439int CodeGen=TRUE; /* Generate output code? */\r
440int LexGen=TRUE; /* Generate lexical files? (tokens.h, parser.dlg) */\r
441int GenAST=FALSE; /* Generate AST's? */\r
442int GenANSI=FALSE; /* Generate ANSI code where necessary */\r
443int GenExprSetsOpt=TRUE;/* use sets not (LA(1)==tok) expression lists */\r
444int GenCR=FALSE; /* Generate cross reference? */\r
445int GenLineInfo=FALSE; /* Generate # line "file" stuff? */\r
446int GenLineInfoMS=FALSE;/* Like -gl but replace "\" with "/" for MS C/C++ systems */\r
447int TraceGen=FALSE; /* Generate code to trace rule invocation */\r
448int elevel=1; /* error level for ambiguity messages */\r
449int GenEClasseForRules=0;/* don't generate eclass for each rule */\r
450int TreeResourceLimit= -1;/* don't limit tree resource */\r
451int DemandLookahead = 0;/* demand/delayed lookahead or not */\r
452char *RulePrefix = ""; /* prefix each generated rule with this */\r
453char *stdpccts = "stdpccts.h";/* where to generate std pccts include file */\r
454int GenStdPccts = 0; /* don't gen stdpccts.h? */\r
455int ParseWithPredicates = 1;\r
456int WarningLevel = 1;\r
457int UseStdout = 0; /* MR6 */\r
458int TabWidth = 2; /* MR6 */ /* MR27 */\r
459int HoistPredicateContext = 0;\r
460int MRhoisting = 0; /* MR9 */\r
461int MRhoistingk = 0; /* MR13 */\r
462int MR_debugGenRule=0; /* MR11 */\r
463\r
464int GenCC = 0; /* Generate C++ output */\r
465\r
466PointerStack MR_BackTraceStack={0,0,NULL}; /* MR10 */\r
467PointerStack MR_PredRuleRefStack={0,0,NULL}; /* MR10 */\r
468PointerStack MR_RuleBlkWithHaltStack={0,0,NULL}; /* MR10 */\r
469\r
470/* DontCopyTokens and Pragma_DupLabeledTokens were a bad idea. I've just\r
471 turned them off rather than backpatching the code. Who knows? We\r
472 may need them in the future.\r
473 */\r
474int DontCopyTokens = 1; /* in C++, don't copy ANTLRToken passed to ANTLR */\r
475\r
476/* Remember if LT(i), LA(i), or LATEXT(i) used in an action which is not\r
477 a predicate. If so, give a warning for novice users.\r
478*/\r
479\r
480int LTinTokenAction = 0; /* MR23 */\r
481int PURIFY = 1; /* MR23 */\r
482\r
483int CurBlockID_array[MAX_BLK_LEVEL]; /* MR23 */\r
484int CurAltNum_array[MAX_BLK_LEVEL]; /* MR23 */\r