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