]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/CodeTools/Source/Pccts/h/PCCTSAST.h
More renames for Tool Packages
[mirror_edk2.git] / Tools / CodeTools / Source / Pccts / h / PCCTSAST.h
1 /* Abstract syntax tree
2 *
3 * SOFTWARE RIGHTS
4 *
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
7 * company may do whatever they wish with source code distributed with
8 * PCCTS or the code generated by PCCTS, including the incorporation of
9 * PCCTS, or its output, into commerical software.
10 *
11 * We encourage users to develop software with PCCTS. However, we do ask
12 * that credit is given to us for developing PCCTS. By "credit",
13 * we mean that if you incorporate our source code into one of your
14 * programs (commercial product, research project, or otherwise) that you
15 * acknowledge this fact somewhere in the documentation, research report,
16 * etc... If you like PCCTS and have developed a nice tool with the
17 * output, please mention that you developed it using PCCTS. In
18 * addition, we ask that this header remain intact in our source code.
19 * As long as these guidelines are kept, we expect to continue enhancing
20 * this system and expect to make other tools available as they are
21 * completed.
22 *
23 * ANTLR 1.33
24 * Terence Parr
25 * Parr Research Corporation
26 * with Purdue University and AHPCRC, University of Minnesota
27 * 1989-2000
28 */
29
30 #ifndef PCCTSAST_H
31 #define PCCTSAST_H
32
33 #include "pcctscfg.h"
34
35 #include "pccts_stdio.h"
36 #include "pccts_stdlib.h"
37
38 PCCTS_NAMESPACE_STD
39
40 //class SList;
41
42 #define StringScanMaxText 50
43 #define MaxTreeStackDepth 400
44
45 //
46 // 7-Apr-97 133MR1 signed int not accepted by AT&T cfront
47 //
48 typedef struct stringlexer {
49 int c; // MR1
50 char *input;
51 char *p;
52 char text[StringScanMaxText];
53 } StringLexer;
54
55 /* Define the structures needed for ast_scan() */
56 typedef struct stringparser {
57 int token;
58 StringLexer *lexer;
59 int num_labels;
60 } StringParser;
61
62 typedef struct _scanast {
63 struct _scanast *_right, *_down;
64 int _token;
65 int label_num;
66 int type() { return _token; }
67 struct _scanast *right() { return _right; }
68 struct _scanast *down() { return _down; }
69 } ScanAST;
70
71 #define VALID_SCAN_TOKEN(t) (t>=__LPAREN && t<=__PERIOD)
72
73 class DllExportPCCTS PCCTS_AST {
74 protected:
75 static const char *scan_token_tbl[]; /* MR20 const */
76 enum {
77 __LPAREN=1,
78 __RPAREN=2,
79 __PERCENT=3,
80 __INT=4,
81 __COLON=5,
82 __POUND=6,
83 __PERIOD=7,
84 __StringScanEOF=-1};
85
86 protected:
87 const char *scan_token_str(int t); /* MR20 const */
88 void stringlexer_init(StringLexer *scanner, char *input);
89 void stringparser_init(StringParser *, StringLexer *);
90 ScanAST *stringparser_parse_scanast(char *templ, int *n);
91 ScanAST *stringparser_parse_tree(StringParser *parser);
92 ScanAST *stringparser_parse_element(StringParser *parser);
93 void stringscan_advance(StringLexer *scanner);
94 int stringscan_gettok(StringLexer *scanner);
95 void _push(PCCTS_AST **st, int *sp, PCCTS_AST *e);
96 PCCTS_AST *_pop(PCCTS_AST **st, int *sp);
97 int match_partial(PCCTS_AST *t, PCCTS_AST *u);
98 int scanmatch(ScanAST *t, PCCTS_AST **labels[], int *n);
99 void scanast_free(ScanAST *t);
100 ScanAST *new_scanast(int tok);
101 void stringparser_match(StringParser *parser, int type);
102 virtual PCCTS_AST *deepCopyBushy();
103
104 public:
105 PCCTS_AST() {;}
106 virtual ~PCCTS_AST() {;}
107
108 /* This group must be defined for SORCERER to work correctly */
109 virtual PCCTS_AST *right() = 0;
110 virtual PCCTS_AST *down() = 0;
111 virtual void setRight(PCCTS_AST *t) = 0;
112 virtual void setDown(PCCTS_AST *t) = 0;
113 // we define these so ANTLR doesn't have to
114 virtual int type() { return 0; }
115 virtual void setType(int /*t MR23 */) {;}
116 virtual PCCTS_AST *shallowCopy() {panic("no shallowCopy() defined"); return NULL;}
117
118 /* These are not needed by ANTLR, but are support functions */
119 virtual PCCTS_AST *deepCopy(); // used by SORCERER in transform mode
120 virtual void addChild(PCCTS_AST *t);
121 virtual void lisp_action(FILE * /*f MR23 */) {;}
122 virtual void lisp(FILE *f);
123 static PCCTS_AST *make(PCCTS_AST *rt, ...);
124 virtual PCCTS_AST *ast_find_all(PCCTS_AST *u, PCCTS_AST **cursor);
125 virtual int match(PCCTS_AST *u);
126 virtual void insert_after(PCCTS_AST *b);
127 virtual void append(PCCTS_AST *b);
128 virtual PCCTS_AST *tail();
129 virtual PCCTS_AST *bottom();
130 static PCCTS_AST *cut_between(PCCTS_AST *a, PCCTS_AST *b);
131 // virtual SList *to_slist();
132 virtual void tfree();
133 int ast_scan(char *templ, ...);
134 virtual int nsiblings();
135 virtual PCCTS_AST *sibling_index(int i);
136
137 void require(int e,const char *err){ if ( !e ) panic(err); } /* MR20 const */
138 virtual void panic(const char *err) // MR20 const
139 { /* MR23 */ printMessage(stderr, "PCCTS_AST: %s\n", err); exit(PCCTS_EXIT_FAILURE); }
140 virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
141 };
142
143 #endif /* PCCTSAST_H */