cint_ast.h (9385B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: cint_ast.h 8 * Purpose: CINT AST node interfaces 9 */ 10 11 #ifndef __CINT_AST_H__ 12 #define __CINT_AST_H__ 13 14 #include "cint_config.h" 15 #include "cint_operators.h" 16 17 typedef enum cint_ast_type_e { 18 19 cintAstNone = -1, 20 21 #define CINT_AST_LIST_ENTRY(_entry) cintAst##_entry , 22 #include "cint_ast_entry.h" 23 24 cintAstLast 25 26 } cint_ast_type_t; 27 28 #define CINT_AST_TYPE_VALID(_e) (_e > cintAstNone && _e < cintAstLast) 29 30 typedef struct cint_ast_s { 31 /* Internal Use Only */ 32 struct cint_ast_s* inext; 33 34 35 struct cint_ast_s* next; 36 37 const char* file; 38 int line; 39 40 int refcount; 41 int noexec; 42 cint_ast_type_t ntype; 43 44 /* Node Types */ 45 union { 46 47 /* Constant Integer */ 48 struct { 49 long i; 50 } integer; 51 #if CINT_CONFIG_INCLUDE_LONGLONGS == 1 52 /* Constant Long Long */ 53 struct { 54 long long i; 55 } _longlong; 56 #endif 57 58 #if CINT_CONFIG_INCLUDE_DOUBLES == 1 59 /* Constant Double */ 60 struct { 61 double d; 62 } _double; 63 #endif 64 65 66 /* Constant String */ 67 struct { 68 const char* s; 69 } string; 70 71 72 /* Type */ 73 74 #define CINT_AST_TYPE_F_SIGNED 0x1 75 #define CINT_AST_TYPE_F_UNSIGNED 0x2 76 #define CINT_AST_TYPE_F_STATIC 0x4 77 #define CINT_AST_TYPE_F_EXTERN 0x8 78 #define CINT_AST_TYPE_F_CONST 0x10 79 #define CINT_AST_TYPE_F_TYPEDEF 0x20 80 #define CINT_AST_TYPE_F_VOLATILE 0x40 81 82 struct { 83 const char* s; 84 } type; 85 86 87 /* Identifier */ 88 struct { 89 const char* s; 90 } identifier; 91 92 93 /* Declaration */ 94 struct { 95 struct cint_ast_s* type; 96 int pcount; 97 int num_dimension_initializers; 98 struct cint_ast_s* 99 dimension_initializers[CINT_CONFIG_ARRAY_DIMENSION_LIMIT]; 100 struct cint_ast_s* identifier; 101 struct cint_ast_s* init; 102 } declaration; 103 104 struct { 105 struct cint_ast_s* initializers; 106 } initializer; 107 108 /* Operator */ 109 struct { 110 cint_operator_t op; 111 struct cint_ast_s* left; 112 struct cint_ast_s* right; 113 struct cint_ast_s* extra; 114 } operator; 115 116 117 /* Function Call */ 118 struct { 119 const char* name; 120 struct cint_ast_s* parameters; 121 struct cint_datatype_s* dtp; 122 } function; 123 124 /* Function Definition */ 125 struct { 126 struct cint_ast_s* declaration; 127 struct cint_ast_s* parameters; 128 struct cint_ast_s* statements; 129 } functiondef; 130 131 /* Structure Definition */ 132 struct { 133 struct cint_ast_s* name; 134 struct cint_ast_s* members; 135 } structuredef; 136 137 /* Expression List */ 138 struct { 139 struct cint_ast_s* list; 140 } elist; 141 142 /* While */ 143 struct { 144 struct cint_ast_s* condition; 145 struct cint_ast_s* statements; 146 int order; 147 } _while; 148 149 150 /* For */ 151 struct { 152 struct cint_ast_s* pre; 153 struct cint_ast_s* condition; 154 struct cint_ast_s* post; 155 struct cint_ast_s* statements; 156 } _for; 157 158 159 /* If */ 160 struct { 161 struct cint_ast_s* condition; 162 struct cint_ast_s* statements; 163 struct cint_ast_s* _else; 164 } _if; 165 166 /* Return */ 167 struct { 168 struct cint_ast_s* expression; 169 } _return; 170 171 /* Switch */ 172 struct { 173 struct cint_ast_s* expression; 174 struct cint_ast_s* statements; 175 } _switch; 176 177 /* Case */ 178 struct { 179 struct cint_ast_s* expression; 180 struct cint_ast_s* statements; 181 } _case; 182 183 /* Enumerator */ 184 struct { 185 struct cint_ast_s* identifier; 186 struct cint_ast_s* value; 187 } enumerator; 188 189 /* EnumDef */ 190 struct { 191 struct cint_ast_s* identifier; 192 struct cint_ast_s* enumerators; 193 } enumdef; 194 195 /* Print */ 196 struct { 197 struct cint_ast_s* expression; 198 } print; 199 200 /* Interpreter Commands */ 201 struct { 202 struct cint_ast_s* arguments; 203 } cint; 204 205 } utype; 206 207 208 } cint_ast_t; 209 210 typedef enum cint_ast_const_e { 211 cintAstConstHex, 212 cintAstConstOctal, 213 cintAstConstDecimal, 214 cintAstConstChar, 215 cintAstConstFloat 216 } cint_ast_const_t; 217 218 /* Return TRUE if the AST is of the indicated type */ 219 #define CINT_AST(ast, ty) (((ast) != NULL) && ((ast)->ntype == cintAst##ty)) 220 221 #define CINT_AST_PTR_VOID ((cint_ast_t*)0x1) 222 #define CINT_AST_PTR_AUTO ((cint_ast_t*)0x2) 223 224 extern cint_ast_t* cint_ast_integer(int i); 225 #if CINT_CONFIG_INCLUDE_LONGLONGS == 1 226 extern cint_ast_t* cint_ast_long_long(long long i); 227 #endif 228 #if CINT_CONFIG_INCLUDE_DOUBLES == 1 229 extern cint_ast_t* cint_ast_double(double d); 230 #endif 231 extern cint_ast_t* cint_ast_constant(const char* s, cint_ast_const_t ctype); 232 extern cint_ast_t* cint_ast_string(const char* s); 233 extern cint_ast_t* cint_ast_var(const char* s); 234 extern cint_ast_t* cint_ast_operator(cint_operator_t operator, cint_ast_t* left, cint_ast_t* right); 235 extern cint_ast_t* cint_ast_statement(cint_ast_t* s); 236 extern cint_ast_t* cint_ast_identifier(const char* s); 237 extern cint_ast_t* cint_ast_initializer(cint_ast_t* inits); 238 extern cint_ast_t* cint_ast_type(const char* s); 239 extern cint_ast_t* cint_ast_declaration(void); 240 extern cint_ast_t* cint_ast_function(cint_ast_t* expr, cint_ast_t* args); 241 extern cint_ast_t* cint_ast_function_def(void); 242 extern cint_ast_t* cint_ast_structure_def(cint_ast_t* name, cint_ast_t* members); 243 extern cint_ast_t* cint_ast_elist(cint_ast_t* first); 244 extern cint_ast_t* cint_ast_while(cint_ast_t* expr, cint_ast_t* statements, int order); 245 extern cint_ast_t* cint_ast_for(cint_ast_t* pre, cint_ast_t* cond, cint_ast_t* post, cint_ast_t* statements); 246 extern cint_ast_t* cint_ast_if(cint_ast_t* expr, cint_ast_t* statements, cint_ast_t* _else); 247 extern cint_ast_t* cint_ast_case(cint_ast_t* expr, cint_ast_t* statements); 248 extern cint_ast_t* cint_ast_switch(cint_ast_t* expr, cint_ast_t* statements); 249 extern cint_ast_t* cint_ast_print(cint_ast_t* expr); 250 extern cint_ast_t* cint_ast_cint(cint_ast_t* args); 251 extern cint_ast_t* cint_ast_continue(void); 252 extern cint_ast_t* cint_ast_break(void); 253 extern cint_ast_t* cint_ast_return(cint_ast_t* expr); 254 extern cint_ast_t* cint_ast_enumerator(cint_ast_t* identifier, cint_ast_t* value); 255 extern cint_ast_t* cint_ast_enumdef(cint_ast_t* identifier, cint_ast_t* enumerators); 256 extern cint_ast_t* cint_ast_empty(void); 257 extern cint_ast_t* cint_ast_statement_with_no_effect(cint_ast_t* args); 258 259 extern const char* (*cint_ast_get_file_f)(void); 260 extern int (*cint_ast_get_line_f)(void); 261 262 extern cint_ast_t* cint_ast_last(cint_ast_t* root); 263 extern int cint_ast_append(cint_ast_t* root, cint_ast_t* tail); 264 extern int cint_ast_count(cint_ast_t* root); 265 extern void cint_ast_dump(cint_ast_t* root, int indent); 266 extern void cint_ast_dump_single(cint_ast_t* root, int indent); 267 extern void cint_ast_free_all(void); 268 extern void cint_ast_free(cint_ast_t* ast); 269 extern void cint_ast_free_single (cint_ast_t* a); 270 271 extern int cint_ast_int(cint_ast_t* a); 272 extern const char* cint_ast_str(cint_ast_t* a); 273 extern cint_ast_t* cint_ast_ternary(cint_ast_t* expression, 274 cint_ast_t* t, cint_ast_t* f); 275 extern cint_ast_t* cint_ast_comma(cint_ast_t* left, cint_ast_t* right); 276 extern cint_ast_t* cint_ast_declaration_init(cint_ast_t* spec, 277 cint_ast_t* init); 278 extern cint_ast_t* cint_ast_declarator_init(cint_ast_t* decl, 279 cint_ast_t* init); 280 extern cint_ast_t* cint_ast_struct_declaration(cint_ast_t* qual, 281 cint_ast_t* decl); 282 extern cint_ast_t* cint_ast_pointer_declarator(cint_ast_t* ptr, 283 cint_ast_t* decl); 284 extern cint_ast_t* cint_ast_identifier_declarator(cint_ast_t* ident); 285 extern cint_ast_t* cint_ast_array_declarator(cint_ast_t* decl, 286 cint_ast_t* len); 287 extern cint_ast_t* cint_ast_function_declarator(cint_ast_t* decl, 288 cint_ast_t* param); 289 extern cint_ast_t* cint_ast_pointer_indirect(cint_ast_t* val); 290 extern cint_ast_t* cint_ast_parameter_declaration_append(cint_ast_t* spec, 291 cint_ast_t* decl); 292 extern cint_ast_t* cint_ast_parameter_declaration(cint_ast_t* decl); 293 extern cint_ast_t* cint_ast_compound_statement(cint_ast_t* stmt); 294 extern cint_ast_t* cint_ast_function_definition(cint_ast_t* ty, 295 cint_ast_t* decl, 296 cint_ast_t* stmt); 297 extern void cint_ast_touch(cint_ast_t* ast, int delta); 298 299 #endif /* __CINT_AST_H__ */