| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef TCPRS_H |
| 21 |
#define TCPRS_H |
| 22 |
|
| 23 |
#include <assert.h> |
| 24 |
|
| 25 |
#include "vmtype.h" |
| 26 |
#include "t3std.h" |
| 27 |
#include "tcglob.h" |
| 28 |
#include "tctok.h" |
| 29 |
#include "tctargty.h" |
| 30 |
#include "tcprstyp.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
typedef ulong tc_obj_id; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
typedef uint tc_prop_id; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
struct tcprs_scope_t |
| 50 |
{ |
| 51 |
|
| 52 |
class CTcPrsSymtab *local_symtab; |
| 53 |
|
| 54 |
|
| 55 |
class CTcPrsSymtab *enclosing_symtab; |
| 56 |
|
| 57 |
|
| 58 |
int local_cnt; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
enum tcprs_codebodytype |
| 68 |
{ |
| 69 |
|
| 70 |
TCPRS_CB_NORMAL, |
| 71 |
|
| 72 |
|
| 73 |
TCPRS_CB_ANON_FN, |
| 74 |
|
| 75 |
|
| 76 |
TCPRS_CB_ANON_METHOD, |
| 77 |
|
| 78 |
|
| 79 |
TCPRS_CB_SHORT_ANON_FN |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
#define TCPRS_LOCAL_CTX_METHODCTX 1 |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
class CTcParser |
| 96 |
{ |
| 97 |
public: |
| 98 |
CTcParser(); |
| 99 |
~CTcParser(); |
| 100 |
|
| 101 |
|
| 102 |
void init(); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
void reset() |
| 109 |
{ |
| 110 |
|
| 111 |
local_symtab_ = 0; |
| 112 |
|
| 113 |
|
| 114 |
nested_stm_head_ = nested_stm_tail_ = 0; |
| 115 |
anon_obj_head_ = anon_obj_tail_ = 0; |
| 116 |
nonsym_obj_head_ = nonsym_obj_tail_ = 0; |
| 117 |
exp_head_ = exp_tail_ = 0; |
| 118 |
enclosing_stm_ = 0; |
| 119 |
dict_cur_ = dict_head_ = dict_tail_ = 0; |
| 120 |
dict_prop_head_ = 0; |
| 121 |
gramprod_head_ = gramprod_tail_ = 0; |
| 122 |
template_head_ = template_tail_ = 0; |
| 123 |
cur_code_body_ = 0; |
| 124 |
|
| 125 |
|
| 126 |
local_symtab_ = 0; |
| 127 |
enclosing_local_symtab_ = 0; |
| 128 |
goto_symtab_ = 0; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
class CTcSymProp *def_special_prop(int def, const char *name, |
| 136 |
tc_prop_id *idp = 0); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
void set_module_info(const char *name, int seqno); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
void write_symbol_file(class CVmFile *fp, class CTcMake *make_obj); |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
static ulong seek_sym_file_build_config_info(class CVmFile *fp); |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
void write_to_object_file(class CVmFile *fp); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
int load_object_file(class CVmFile *fp, |
| 191 |
const textchar_t *fname, |
| 192 |
tctarg_obj_id_t *obj_xlat, |
| 193 |
tctarg_prop_id_t *prop_xlat, |
| 194 |
ulong *enum_xlat); |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
void apply_internal_fixups(); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
int read_symbol_file(class CVmFile *fp); |
| 219 |
|
| 220 |
|
| 221 |
class CTcPrsSymtab *get_global_symtab() const { return global_symtab_; } |
| 222 |
|
| 223 |
|
| 224 |
class CTcPrsSymtab *set_global_symtab(class CTcPrsSymtab *t) |
| 225 |
{ |
| 226 |
|
| 227 |
class CTcPrsSymtab *old = global_symtab_; |
| 228 |
|
| 229 |
|
| 230 |
global_symtab_ = t; |
| 231 |
|
| 232 |
|
| 233 |
cache_special_props(FALSE); |
| 234 |
|
| 235 |
|
| 236 |
return old; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
class CTcPrsSymtab *get_local_symtab() const { return local_symtab_; } |
| 241 |
|
| 242 |
|
| 243 |
class CTcPrsSymtab *get_goto_symtab() const { return goto_symtab_; } |
| 244 |
|
| 245 |
|
| 246 |
void set_pragma_c(int mode); |
| 247 |
|
| 248 |
|
| 249 |
void set_pp_expr_mode(int f) { pp_expr_mode_ = f; } |
| 250 |
|
| 251 |
|
| 252 |
int get_pp_expr_mode() const { return pp_expr_mode_; } |
| 253 |
|
| 254 |
|
| 255 |
void set_source_text_group_mode(int f); |
| 256 |
int get_source_text_group_mode() const { return src_group_mode_; } |
| 257 |
|
| 258 |
|
| 259 |
int get_syntax_only() const { return syntax_only_; } |
| 260 |
void set_syntax_only(int f) { syntax_only_ = f; } |
| 261 |
|
| 262 |
|
| 263 |
int is_debug_expr() const { return debug_expr_; } |
| 264 |
void set_debug_expr(int f) { debug_expr_ = f; } |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
tc_prop_id get_constructor_prop() const { return constructor_prop_; } |
| 271 |
tc_prop_id get_finalize_prop() const { return finalize_prop_; } |
| 272 |
|
| 273 |
|
| 274 |
class CTcSymProp *get_constructor_sym() const { return constructor_sym_; } |
| 275 |
|
| 276 |
|
| 277 |
tc_prop_id get_grammarTag_prop() const; |
| 278 |
tc_prop_id get_grammarInfo_prop() const; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
int check_unresolved_externs(); |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
void build_dictionaries(); |
| 293 |
|
| 294 |
|
| 295 |
void build_grammar_productions(); |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
class CTPNStmProg *parse_top(); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
static int parse_req_sem(); |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
static int skip_to_sem(); |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
class CTcPrsNode *parse_expr(); |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
class CTcPrsNode *parse_cond_expr(); |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
class CTcPrsNode *parse_expr_or_dstr(int allow_comma_expr); |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
class CTcPrsNode *parse_asi_expr(); |
| 360 |
|
| 361 |
|
| 362 |
void parse_enum(int *err); |
| 363 |
|
| 364 |
|
| 365 |
class CTPNStmTop *parse_dict(int *err); |
| 366 |
|
| 367 |
|
| 368 |
class CTPNStmTop *parse_grammar(int *err, int replace, int modify); |
| 369 |
|
| 370 |
|
| 371 |
void parse_gram_alts(int *err, class CTcSymObj *gram_obj, |
| 372 |
class CTcGramProdEntry *prod, |
| 373 |
struct CTcGramPropArrows *arrows, |
| 374 |
class CTcGramAltFuncs *funcs); |
| 375 |
|
| 376 |
|
| 377 |
class CTcPrsGramNode *flatten_gram_rule(int *err); |
| 378 |
|
| 379 |
|
| 380 |
class CTcPrsGramNode *parse_gram_or(int *err, int level); |
| 381 |
|
| 382 |
|
| 383 |
class CTcPrsGramNode *parse_gram_cat(int *err, int level); |
| 384 |
|
| 385 |
|
| 386 |
int parse_gram_qual_int(int *err, const char *qual_name, int *stm_end); |
| 387 |
|
| 388 |
|
| 389 |
void parse_gram_qual_skip(int *err, int *stm_end); |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
class CTPNStmTop *parse_function(int *err, int is_extern, |
| 403 |
int replace, int modify, |
| 404 |
int func_kw_present); |
| 405 |
|
| 406 |
|
| 407 |
class CTPNStmTop *parse_intrinsic(int *err); |
| 408 |
|
| 409 |
|
| 410 |
class CTPNStmTop *parse_intrinsic_class(int *err); |
| 411 |
|
| 412 |
|
| 413 |
void parse_extern(int *err); |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
class CTPNStmTop *parse_object_or_func(int *err, int replace, |
| 421 |
int suppress_error, |
| 422 |
int *suppress_next_error); |
| 423 |
|
| 424 |
|
| 425 |
class CTPNStmTop *parse_template_def(int *err, |
| 426 |
const class CTcToken *class_tok); |
| 427 |
|
| 428 |
|
| 429 |
class CTPNStmTop *parse_string_template_def(int *err); |
| 430 |
|
| 431 |
|
| 432 |
void add_template_def(class CTcSymObj *class_sym, |
| 433 |
class CTcObjTemplateItem *item_head, |
| 434 |
size_t item_cnt); |
| 435 |
|
| 436 |
|
| 437 |
void add_inherited_templates(class CTcSymObj *sc_sym, |
| 438 |
class CTcObjTemplateItem *item_head, |
| 439 |
size_t item_cnt); |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
void expand_and_add_inherited_template(class CTcSymObj *sc_sym, |
| 447 |
class CTcObjTemplateItem *items, |
| 448 |
class CTcObjTemplate *sc_tpl); |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
void build_super_template_list(struct inh_tpl_entry **list_head, |
| 455 |
struct inh_tpl_entry **list_tail, |
| 456 |
class CTcSymObj *sc_sym); |
| 457 |
|
| 458 |
|
| 459 |
class CTPNStmTop *parse_object_stm(int *err, int is_transient); |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
class CTPNStmTop *parse_plus_object(int *err); |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
class CTPNStmTop *parse_object(int *err, int replace, int modify, |
| 479 |
int is_class, int plus_cnt, |
| 480 |
int is_transient); |
| 481 |
|
| 482 |
|
| 483 |
CTcSymObj *find_or_def_obj(const char *tok_txt, size_t tok_len, |
| 484 |
int replace, int modify, int *is_class, |
| 485 |
class CTcSymObj **mod_orig_sym, |
| 486 |
class CTcSymMetaclass **meta_sym, |
| 487 |
int *is_transient); |
| 488 |
|
| 489 |
|
| 490 |
class CTPNStmObject *parse_anon_object(int *err, int plus_cnt, |
| 491 |
int is_nested, |
| 492 |
struct tcprs_term_info *term_info, |
| 493 |
int is_transient); |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
class CTPNStmObject *parse_object_body( |
| 516 |
int *err, class CTcSymObj *obj_sym, |
| 517 |
int is_class, int is_anon, int is_grammar, int is_nested, |
| 518 |
int modify, class CTcSymObj *mod_orig_sym, |
| 519 |
int plus_cnt, class CTcSymMetaclass *meta_sym, |
| 520 |
struct tcprs_term_info *term_info, int is_transient); |
| 521 |
|
| 522 |
|
| 523 |
void parse_superclass_list( |
| 524 |
class CTcSymObj *obj_sym, class CTPNSuperclassList &sclist); |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
class CTcSymObj *add_gen_obj(const char *clsname); |
| 534 |
class CTcSymObj *add_gen_obj(class CTcSymObj *cls); |
| 535 |
class CTcSymObj *add_gen_obj() |
| 536 |
{ return add_gen_obj((class CTcSymObj *)0); } |
| 537 |
|
| 538 |
|
| 539 |
void add_gen_obj_prop(class CTcSymObj *obj, const char *prop, int val); |
| 540 |
void add_gen_obj_prop(class CTcSymObj *obj, const char *prop, |
| 541 |
const char *val); |
| 542 |
void add_gen_obj_prop(class CTcSymObj *obj, const char *prop, |
| 543 |
const CTcConstVal *val); |
| 544 |
|
| 545 |
|
| 546 |
void parse_obj_template(int *err, class CTPNObjDef *objdef, int is_inline); |
| 547 |
|
| 548 |
|
| 549 |
const class CTcObjTemplate |
| 550 |
*find_class_template(const class CTPNSuperclass *first_sc, |
| 551 |
class CTcObjTemplateInst *src, |
| 552 |
size_t src_cnt, const CTPNSuperclass **def_sc, |
| 553 |
int *undescribed_class); |
| 554 |
|
| 555 |
|
| 556 |
const class CTcObjTemplate |
| 557 |
*find_template_match(const class CTcObjTemplate *first_tpl, |
| 558 |
class CTcObjTemplateInst *src, |
| 559 |
size_t src_cnt); |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
int match_template(const class CTcObjTemplateItem *tpl_head, |
| 568 |
class CTcObjTemplateInst *src, size_t src_cnt); |
| 569 |
|
| 570 |
|
| 571 |
class CTcStrTemplate *get_str_template_head() const |
| 572 |
{ return str_template_head_; } |
| 573 |
|
| 574 |
|
| 575 |
int parse_obj_prop_list( |
| 576 |
int *err, class CTPNObjDef *objdef, class CTcSymMetaclass *meta_sym, |
| 577 |
int modify, int is_nested, int braces, int is_inline, |
| 578 |
struct tcprs_term_info *outer_term_info, |
| 579 |
struct tcprs_term_info *term_info); |
| 580 |
|
| 581 |
|
| 582 |
void parse_obj_prop( |
| 583 |
int *err, class CTPNObjDef *objdef, int replace, |
| 584 |
class CTcSymMetaclass *meta_sym, struct tcprs_term_info *term_info, |
| 585 |
struct propset_def *propset_stack, int propset_depth, |
| 586 |
int enclosing_obj_is_nested, int is_inline); |
| 587 |
|
| 588 |
|
| 589 |
class CTPNStmTop *parse_class(int *err); |
| 590 |
|
| 591 |
|
| 592 |
class CTPNStmTop *parse_modify(int *err); |
| 593 |
|
| 594 |
|
| 595 |
class CTPNStmTop *parse_replace(int *err); |
| 596 |
|
| 597 |
|
| 598 |
void parse_property(int *err); |
| 599 |
|
| 600 |
|
| 601 |
void parse_export(int *err); |
| 602 |
|
| 603 |
|
| 604 |
class CTcPrsExport *add_export(const char *sym, size_t sym_len); |
| 605 |
|
| 606 |
|
| 607 |
void add_export_to_list(class CTcPrsExport *exp); |
| 608 |
|
| 609 |
|
| 610 |
class CTcPrsExport *get_exp_head() const { return exp_head_; } |
| 611 |
|
| 612 |
|
| 613 |
void set_local_symtab(class CTcPrsSymtab *local_symtab); |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
class CTPNCodeBody *parse_code_body(int eq_before_brace, int is_obj_prop, |
| 625 |
int self_valid, |
| 626 |
int *p_argc, int *p_opt_argc, |
| 627 |
int *p_varargs, int *p_varargs_list, |
| 628 |
class CTcSymLocal ** |
| 629 |
p_varargs_list_local, |
| 630 |
int *has_retval, int *err, |
| 631 |
class CTcPrsSymtab *local_symtab, |
| 632 |
tcprs_codebodytype cb_type, |
| 633 |
struct propset_def *propset_stack, |
| 634 |
int propset_depth, |
| 635 |
struct CTcCodeBodyRef *enclosing, |
| 636 |
class CTcFormalTypeList **type_list); |
| 637 |
|
| 638 |
|
| 639 |
class CTPNCodeBody *parse_nested_code_body( |
| 640 |
int eq_before_brace, |
| 641 |
int self_valid, |
| 642 |
int *p_argc, int *p_opt_argc, int *p_varargs, |
| 643 |
int *p_varargs_list, class CTcSymLocal **p_varargs_list_local, |
| 644 |
int *has_retval, int *err, |
| 645 |
class CTcPrsSymtab *local_symtab, |
| 646 |
tcprs_codebodytype cb_type); |
| 647 |
|
| 648 |
|
| 649 |
void insert_propset_expansion(struct propset_def *propset_stack, |
| 650 |
int propset_depth); |
| 651 |
|
| 652 |
|
| 653 |
void parse_formal_list(int count_only, int opt_allowed, |
| 654 |
int *argc, int *opt_argc, int *varargs, |
| 655 |
int *varargs_list, |
| 656 |
class CTcSymLocal **varargs_list_local, |
| 657 |
int *err, int base_formal_num, |
| 658 |
int for_short_anon_func, |
| 659 |
class CTcFormalTypeList **type_list); |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
class CTPNStmComp *parse_compound(int *err, |
| 679 |
int skip_lbrace, int need_rbrace, |
| 680 |
class CTPNStmSwitch *enclosing_switch, |
| 681 |
int use_enclosing_scope); |
| 682 |
|
| 683 |
|
| 684 |
class CTPNStm *parse_local(int *err); |
| 685 |
|
| 686 |
|
| 687 |
class CTcPrsNode *parse_local_initializer(class CTcSymLocal *lcl, |
| 688 |
int *err); |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
class CTPNStm *parse_stm(int *err, class CTPNStmSwitch *enclosing_switch, |
| 706 |
int compound_use_enclosing_scope); |
| 707 |
|
| 708 |
|
| 709 |
class CTPNStm *parse_case(int *err, |
| 710 |
class CTPNStmSwitch *enclosing_switch); |
| 711 |
|
| 712 |
|
| 713 |
class CTPNStm *parse_default(int *err, |
| 714 |
class CTPNStmSwitch *enclosing_switch); |
| 715 |
|
| 716 |
|
| 717 |
class CTPNStm *parse_if(int *err); |
| 718 |
|
| 719 |
|
| 720 |
class CTPNStm *parse_return(int *err); |
| 721 |
|
| 722 |
|
| 723 |
class CTPNStm *parse_for(int *err); |
| 724 |
|
| 725 |
|
| 726 |
class CTcPrsNode *parse_for_in_clause( |
| 727 |
class CTcPrsNode *lval, |
| 728 |
class CTPNForIn *&head, class CTPNForIn *&tail); |
| 729 |
|
| 730 |
|
| 731 |
class CTPNStm *parse_foreach(int *err); |
| 732 |
|
| 733 |
|
| 734 |
class CTPNStm *parse_break(int *err); |
| 735 |
|
| 736 |
|
| 737 |
class CTPNStm *parse_continue(int *err); |
| 738 |
|
| 739 |
|
| 740 |
class CTPNStm *parse_while(int *err); |
| 741 |
|
| 742 |
|
| 743 |
class CTPNStm *parse_do_while(int *err); |
| 744 |
|
| 745 |
|
| 746 |
class CTPNStm *parse_switch(int *err); |
| 747 |
|
| 748 |
|
| 749 |
class CTPNStm *parse_goto(int *err); |
| 750 |
|
| 751 |
|
| 752 |
class CTPNStm *parse_try(int *err); |
| 753 |
|
| 754 |
|
| 755 |
class CTPNStm *parse_throw(int *err); |
| 756 |
|
| 757 |
|
| 758 |
int parse_op_name(class CTcToken *tok, int *op_argp = 0); |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
class CTcPrsNode *create_sym_node(const textchar_t *sym, size_t sym_len); |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
class CTcTokFileDesc *get_cur_desc() const { return cur_desc_; } |
| 777 |
long get_cur_linenum() const { return cur_linenum_; } |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
class CTPNStmEnclosing *get_enclosing_stm() const |
| 790 |
{ return enclosing_stm_; } |
| 791 |
class CTPNStmEnclosing *set_enclosing_stm(class CTPNStmEnclosing *stm) |
| 792 |
{ |
| 793 |
class CTPNStmEnclosing *old_enclosing; |
| 794 |
|
| 795 |
|
| 796 |
old_enclosing = enclosing_stm_; |
| 797 |
|
| 798 |
|
| 799 |
enclosing_stm_ = stm; |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
return old_enclosing; |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
struct CTcCodeBodyRef *get_cur_code_body() const |
| 812 |
{ return cur_code_body_; } |
| 813 |
|
| 814 |
|
| 815 |
int is_self_valid() const { return self_valid_; } |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
int self_referenced() const { return self_referenced_; } |
| 824 |
void set_self_referenced(int f) { self_referenced_ = f; } |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
int full_method_ctx_referenced() const |
| 833 |
{ return full_method_ctx_referenced_; } |
| 834 |
void set_full_method_ctx_referenced(int f) |
| 835 |
{ full_method_ctx_referenced_ = f; } |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
int local_ctx_needs_self() const { return local_ctx_needs_self_; } |
| 844 |
void set_local_ctx_needs_self(int f) { local_ctx_needs_self_ = f; } |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
int local_ctx_needs_full_method_ctx() const |
| 855 |
{ return local_ctx_needs_full_method_ctx_; } |
| 856 |
void set_local_ctx_needs_full_method_ctx(int f) |
| 857 |
{ local_ctx_needs_full_method_ctx_ = f; } |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
class CTcSymLabel *add_code_label(const class CTcToken *tok); |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
class CTcPrsDbgSymtab *set_debug_symtab(class CTcPrsDbgSymtab *tab) |
| 870 |
{ |
| 871 |
class CTcPrsDbgSymtab *old_tab; |
| 872 |
|
| 873 |
|
| 874 |
old_tab = debug_symtab_; |
| 875 |
|
| 876 |
|
| 877 |
debug_symtab_ = tab; |
| 878 |
|
| 879 |
|
| 880 |
return old_tab; |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
class CTcSymbol *get_objfile_sym(uint idx) |
| 887 |
{ return (idx == 0 ? 0 : obj_sym_list_[idx - 1]); } |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
class CTcSymObj *get_objfile_objsym(uint idx); |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
class CTcDictEntry *get_obj_dict(uint idx) |
| 900 |
{ return (idx == 0 ? 0 : obj_dict_list_[idx - 1]); } |
| 901 |
|
| 902 |
|
| 903 |
void add_dict_from_obj_file(class CTcSymObj *sym); |
| 904 |
|
| 905 |
|
| 906 |
void add_sym_from_obj_file(uint idx, class CTcSymbol *sym); |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
uint get_next_obj_file_sym_idx() |
| 915 |
{ |
| 916 |
|
| 917 |
return obj_file_sym_idx_++; |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
uint get_next_obj_file_dict_idx() |
| 924 |
{ |
| 925 |
|
| 926 |
return obj_file_dict_idx_++; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
void add_nested_stm(class CTPNStmTop *stm); |
| 934 |
|
| 935 |
|
| 936 |
class CTPNStmTop *get_first_nested_stm() const |
| 937 |
{ return nested_stm_head_; } |
| 938 |
|
| 939 |
|
| 940 |
void add_anon_obj(class CTcSymObj *obj); |
| 941 |
|
| 942 |
|
| 943 |
void add_nonsym_obj(tctarg_obj_id_t id); |
| 944 |
|
| 945 |
|
| 946 |
int has_local_ctx() const { return has_local_ctx_ != 0; } |
| 947 |
|
| 948 |
|
| 949 |
int get_local_ctx_var() const { return local_ctx_var_num_; } |
| 950 |
|
| 951 |
|
| 952 |
void init_local_ctx(); |
| 953 |
|
| 954 |
|
| 955 |
void finish_local_ctx(CTPNCodeBody *cb, class CTcPrsSymtab *local_symtab); |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
int alloc_ctx_arr_idx(); |
| 963 |
|
| 964 |
|
| 965 |
int alloc_ctx_holder_var() { return alloc_local(); } |
| 966 |
|
| 967 |
|
| 968 |
int get_max_local_cnt() const { return max_local_cnt_; } |
| 969 |
|
| 970 |
|
| 971 |
class CTcSymProp *get_lexical_parent_sym() const |
| 972 |
{ return lexical_parent_sym_; } |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
class CTcGramProdEntry *declare_gramprod(const char *sym, size_t len); |
| 979 |
|
| 980 |
|
| 981 |
class CTcGramProdEntry *get_gramprod_entry(class CTcSymObj *sym); |
| 982 |
|
| 983 |
|
| 984 |
class CTcSymObj *find_or_def_gramprod(const char *txt, size_t len, |
| 985 |
class CTcGramProdEntry **entryp); |
| 986 |
|
| 987 |
|
| 988 |
ulong new_enum_id() { return next_enum_id_++; } |
| 989 |
|
| 990 |
|
| 991 |
ulong get_enum_count() const { return next_enum_id_; } |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
CTcSymProp *look_up_prop(const class CTcToken *tok, int show_err); |
| 999 |
|
| 1000 |
|
| 1001 |
CTcSymProp *get_plus_prop() const { return plus_prop_; } |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
static const char *read_len_prefix_str |
| 1018 |
(CVmFile *fp, char *tmp_buf, size_t tmp_buf_len, size_t *ret_len, |
| 1019 |
int err_if_too_long); |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
static int read_len_prefix_str(CVmFile *fp, char *buf, size_t buf_len, |
| 1028 |
int err_if_too_long); |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
tctarg_prop_id_t get_miscvocab_prop() const { return miscvocab_prop_; } |
| 1033 |
|
| 1034 |
|
| 1035 |
class CTcSymProp *ov_op_add_; |
| 1036 |
class CTcSymProp *ov_op_sub_; |
| 1037 |
class CTcSymProp *ov_op_mul_; |
| 1038 |
class CTcSymProp *ov_op_div_; |
| 1039 |
class CTcSymProp *ov_op_mod_; |
| 1040 |
class CTcSymProp *ov_op_xor_; |
| 1041 |
class CTcSymProp *ov_op_shl_; |
| 1042 |
class CTcSymProp *ov_op_ashr_; |
| 1043 |
class CTcSymProp *ov_op_lshr_; |
| 1044 |
class CTcSymProp *ov_op_bnot_; |
| 1045 |
class CTcSymProp *ov_op_bor_; |
| 1046 |
class CTcSymProp *ov_op_band_; |
| 1047 |
class CTcSymProp *ov_op_neg_; |
| 1048 |
class CTcSymProp *ov_op_idx_; |
| 1049 |
class CTcSymProp *ov_op_setidx_; |
| 1050 |
|
| 1051 |
|
| 1052 |
class CTcEmbedTokenList *embed_toks_; |
| 1053 |
|
| 1054 |
private: |
| 1055 |
|
| 1056 |
void cache_special_props(int def); |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
CTcSymObj *add_gen_obj_stat(class CTcSymObj *cls); |
| 1065 |
void add_gen_obj_prop_stat(class CTcSymObj *obj, class CTcSymProp *prop, |
| 1066 |
const CTcConstVal *val); |
| 1067 |
|
| 1068 |
|
| 1069 |
void clear_local_ctx(); |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
void begin_prop_expr( |
| 1076 |
class CTcPrsPropExprSave *save_info, int is_static, int is_inline); |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
void finish_prop_expr( |
| 1087 |
class CTcPrsPropExprSave *save_info, class CTcPrsNode* &expr, |
| 1088 |
class CTPNCodeBody* &code_body, class CTPNAnonFunc* &inline_method, |
| 1089 |
int is_static, int is_inline, class CTcSymProp *prop_sym); |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
static void write_sym_cb(void *ctx, class CTcSymbol *sym); |
| 1096 |
|
| 1097 |
|
| 1098 |
static void write_obj_cb(void *ctx, class CTcSymbol *sym); |
| 1099 |
|
| 1100 |
|
| 1101 |
static void write_obj_ref_cb(void *ctx, class CTcSymbol *sym); |
| 1102 |
|
| 1103 |
|
| 1104 |
static void write_obj_gram_cb(void *ctx, class CTcSymbol *sym); |
| 1105 |
|
| 1106 |
|
| 1107 |
static void build_grammar_cb(void *ctx, class CTcSymbol *sym); |
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
void enter_scope(struct tcprs_scope_t *info) |
| 1115 |
{ |
| 1116 |
|
| 1117 |
info->local_symtab = local_symtab_; |
| 1118 |
info->enclosing_symtab = enclosing_local_symtab_; |
| 1119 |
info->local_cnt = local_cnt_; |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
enclosing_local_symtab_ = local_symtab_; |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
void leave_scope(struct tcprs_scope_t *info) |
| 1135 |
{ |
| 1136 |
|
| 1137 |
local_symtab_ = info->local_symtab; |
| 1138 |
enclosing_local_symtab_ = info->enclosing_symtab; |
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
} |
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
void create_scope_local_symtab(); |
| 1159 |
|
| 1160 |
|
| 1161 |
int alloc_local() |
| 1162 |
{ |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if (local_cnt_ + 1 > max_local_cnt_) |
| 1168 |
max_local_cnt_ = local_cnt_ + 1; |
| 1169 |
|
| 1170 |
|
| 1171 |
return local_cnt_++; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
class CTcDictEntry *declare_dict(const char *sym, size_t len); |
| 1176 |
|
| 1177 |
|
| 1178 |
class CTcDictEntry *create_dict_entry(class CTcSymObj *sym); |
| 1179 |
|
| 1180 |
|
| 1181 |
class CTcDictEntry *get_dict_entry(class CTcSymObj *sym); |
| 1182 |
|
| 1183 |
|
| 1184 |
class CTcGramProdEntry *create_gramprod_entry(class CTcSymObj *sym); |
| 1185 |
|
| 1186 |
|
| 1187 |
static void enum_sym_extref(void *ctx, class CTcSymbol *sym); |
| 1188 |
|
| 1189 |
|
| 1190 |
static void enum_sym_internal_fixup(void *ctx, class CTcSymbol *sym); |
| 1191 |
|
| 1192 |
|
| 1193 |
static void enum_sym_dict(void *ctx, class CTcSymbol *sym); |
| 1194 |
|
| 1195 |
|
| 1196 |
static void enum_for_ctx_locals(void *ctx, class CTcSymbol *sym); |
| 1197 |
|
| 1198 |
|
| 1199 |
class CTcPrsSymtab *global_symtab_; |
| 1200 |
|
| 1201 |
|
| 1202 |
tc_prop_id constructor_prop_; |
| 1203 |
class CTcSymProp *constructor_sym_; |
| 1204 |
|
| 1205 |
|
| 1206 |
tc_prop_id finalize_prop_; |
| 1207 |
|
| 1208 |
|
| 1209 |
class CTcSymProp *graminfo_prop_; |
| 1210 |
|
| 1211 |
|
| 1212 |
class CTcSymProp *gramtag_prop_; |
| 1213 |
|
| 1214 |
|
| 1215 |
tctarg_prop_id_t miscvocab_prop_; |
| 1216 |
|
| 1217 |
|
| 1218 |
class CTcSymProp *lexical_parent_sym_; |
| 1219 |
|
| 1220 |
|
| 1221 |
class CTcSymProp *src_order_sym_; |
| 1222 |
|
| 1223 |
|
| 1224 |
class CTcSymProp *src_group_sym_; |
| 1225 |
|
| 1226 |
|
| 1227 |
class CTcSymProp *src_group_mod_sym_; |
| 1228 |
class CTcSymProp *src_group_seq_sym_; |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
long src_order_idx_; |
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
tctarg_obj_id_t src_group_id_; |
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
uint pp_expr_mode_ : 1; |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
uint src_group_mode_ : 1; |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
uint syntax_only_ : 1; |
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
uint debug_expr_ : 1; |
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
class CTcPrsSymtab *goto_symtab_; |
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
class CTcPrsSymtab *local_symtab_; |
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
class CTcPrsSymtab *enclosing_local_symtab_; |
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
class CTcPrsDbgSymtab *debug_symtab_; |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
int local_cnt_; |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
int max_local_cnt_; |
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
class CTPNStmEnclosing *enclosing_stm_; |
| 1332 |
|
| 1333 |
|
| 1334 |
class CTcTokFileDesc *cur_desc_; |
| 1335 |
long cur_linenum_; |
| 1336 |
|
| 1337 |
|
| 1338 |
class CTcDictEntry *dict_cur_; |
| 1339 |
|
| 1340 |
|
| 1341 |
class CTcDictEntry *dict_head_; |
| 1342 |
class CTcDictEntry *dict_tail_; |
| 1343 |
|
| 1344 |
|
| 1345 |
class CTcGramProdEntry *gramprod_head_; |
| 1346 |
class CTcGramProdEntry *gramprod_tail_; |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
class CTcSymbol **obj_sym_list_; |
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
class CTcDictEntry **obj_dict_list_; |
| 1363 |
|
| 1364 |
|
| 1365 |
uint obj_file_dict_idx_; |
| 1366 |
|
| 1367 |
|
| 1368 |
uint obj_file_sym_idx_; |
| 1369 |
|
| 1370 |
|
| 1371 |
class CTcDictPropEntry *dict_prop_head_; |
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
class CTPNStmTop *nested_stm_head_; |
| 1385 |
class CTPNStmTop *nested_stm_tail_; |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
class CTcSymObj *anon_obj_head_; |
| 1392 |
class CTcSymObj *anon_obj_tail_; |
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
struct tcprs_nonsym_obj *nonsym_obj_head_; |
| 1399 |
struct tcprs_nonsym_obj *nonsym_obj_tail_; |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
class CTcObjTemplate *template_head_; |
| 1406 |
class CTcObjTemplate *template_tail_; |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
class CTcObjTemplateInst *template_expr_; |
| 1418 |
size_t template_expr_max_; |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
class CTcStrTemplate *str_template_head_; |
| 1426 |
class CTcStrTemplate *str_template_tail_; |
| 1427 |
|
| 1428 |
|
| 1429 |
class CTcPrsExport *exp_head_; |
| 1430 |
class CTcPrsExport *exp_tail_; |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
unsigned int has_local_ctx_ : 1; |
| 1438 |
|
| 1439 |
|
| 1440 |
int local_ctx_var_num_; |
| 1441 |
|
| 1442 |
|
| 1443 |
tctarg_prop_id_t *ctx_var_props_; |
| 1444 |
|
| 1445 |
|
| 1446 |
size_t ctx_var_props_size_; |
| 1447 |
|
| 1448 |
|
| 1449 |
size_t ctx_var_props_cnt_; |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
size_t ctx_var_props_used_; |
| 1456 |
|
| 1457 |
|
| 1458 |
int next_ctx_arr_idx_; |
| 1459 |
|
| 1460 |
|
| 1461 |
CTcCodeBodyRef *cur_code_body_; |
| 1462 |
|
| 1463 |
|
| 1464 |
int self_valid_; |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
int self_referenced_; |
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
int full_method_ctx_referenced_; |
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
int local_ctx_needs_self_; |
| 1484 |
int local_ctx_needs_full_method_ctx_; |
| 1485 |
|
| 1486 |
|
| 1487 |
ulong next_enum_id_; |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
class CTcSymProp *plus_prop_; |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
class CTPNStmObject **plus_stack_; |
| 1504 |
size_t plus_stack_alloc_; |
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
char *module_name_; |
| 1514 |
int module_seqno_; |
| 1515 |
}; |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
struct CTcGramPropArrows |
| 1523 |
{ |
| 1524 |
CTcGramPropArrows() { cnt = 0; } |
| 1525 |
|
| 1526 |
|
| 1527 |
static const size_t max_arrows = 100; |
| 1528 |
|
| 1529 |
|
| 1530 |
class CTcSymProp *prop[max_arrows]; |
| 1531 |
|
| 1532 |
|
| 1533 |
size_t cnt; |
| 1534 |
}; |
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
class CTcGramAltFuncs |
| 1544 |
{ |
| 1545 |
public: |
| 1546 |
|
| 1547 |
virtual class CTcSymProp *look_up_prop( |
| 1548 |
const class CTcToken *tok, int show_err) = 0; |
| 1549 |
|
| 1550 |
|
| 1551 |
virtual class CTcGramProdEntry *declare_gramprod( |
| 1552 |
const char *txt, size_t len) = 0; |
| 1553 |
|
| 1554 |
|
| 1555 |
virtual void check_enum_tok(class CTcSymEnum *enumsym) = 0; |
| 1556 |
|
| 1557 |
|
| 1558 |
virtual void on_eof(int *err) = 0; |
| 1559 |
}; |
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
class CTcPrsGramNode: public CTcTokenSource |
| 1567 |
{ |
| 1568 |
public: |
| 1569 |
CTcPrsGramNode() |
| 1570 |
{ |
| 1571 |
|
| 1572 |
next_ = 0; |
| 1573 |
} |
| 1574 |
|
| 1575 |
|
| 1576 |
virtual const CTcToken *get_next_token() { return 0; } |
| 1577 |
|
| 1578 |
|
| 1579 |
virtual CTcPrsGramNode *consolidate_or() = 0; |
| 1580 |
|
| 1581 |
|
| 1582 |
virtual void flatten_cat() { } |
| 1583 |
|
| 1584 |
|
| 1585 |
virtual int is_or() { return FALSE; } |
| 1586 |
|
| 1587 |
|
| 1588 |
virtual int is_cat() { return FALSE; } |
| 1589 |
|
| 1590 |
|
| 1591 |
virtual const CTcToken *get_tok() const { return 0; } |
| 1592 |
|
| 1593 |
|
| 1594 |
virtual void init_expansion() { } |
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
virtual int advance_expansion() { return TRUE; } |
| 1607 |
|
| 1608 |
|
| 1609 |
virtual CTcPrsGramNode *clone_expansion() const = 0; |
| 1610 |
|
| 1611 |
|
| 1612 |
CTcPrsGramNode *next_; |
| 1613 |
}; |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
struct tcprs_term_info |
| 1625 |
{ |
| 1626 |
|
| 1627 |
void init(class CTcTokFileDesc *desc, long linenum) |
| 1628 |
{ |
| 1629 |
|
| 1630 |
desc_ = desc; |
| 1631 |
linenum_ = linenum; |
| 1632 |
|
| 1633 |
|
| 1634 |
unterm_ = FALSE; |
| 1635 |
} |
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
class CTcTokFileDesc *desc_; |
| 1644 |
long linenum_; |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
int unterm_; |
| 1651 |
}; |
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
class CTcObjTemplate |
| 1658 |
{ |
| 1659 |
public: |
| 1660 |
CTcObjTemplate(class CTcObjTemplateItem *item_head, size_t item_cnt) |
| 1661 |
{ |
| 1662 |
|
| 1663 |
items_ = item_head; |
| 1664 |
item_cnt_ = item_cnt; |
| 1665 |
|
| 1666 |
|
| 1667 |
nxt_ = 0; |
| 1668 |
} |
| 1669 |
|
| 1670 |
|
| 1671 |
class CTcObjTemplateItem *items_; |
| 1672 |
|
| 1673 |
|
| 1674 |
size_t item_cnt_; |
| 1675 |
|
| 1676 |
|
| 1677 |
CTcObjTemplate *nxt_; |
| 1678 |
}; |
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
class CTcObjTemplateItem |
| 1684 |
{ |
| 1685 |
public: |
| 1686 |
CTcObjTemplateItem(class CTcSymProp *prop, tc_toktyp_t tok_type, |
| 1687 |
int is_alt, int is_opt) |
| 1688 |
{ |
| 1689 |
|
| 1690 |
prop_ = prop; |
| 1691 |
tok_type_ = tok_type; |
| 1692 |
is_alt_ = is_alt; |
| 1693 |
is_opt_ = is_opt; |
| 1694 |
|
| 1695 |
|
| 1696 |
nxt_ = 0; |
| 1697 |
} |
| 1698 |
|
| 1699 |
|
| 1700 |
class CTcSymProp *prop_; |
| 1701 |
|
| 1702 |
|
| 1703 |
tc_toktyp_t tok_type_; |
| 1704 |
|
| 1705 |
|
| 1706 |
CTcObjTemplateItem *nxt_; |
| 1707 |
|
| 1708 |
|
| 1709 |
unsigned int is_alt_ : 1; |
| 1710 |
|
| 1711 |
|
| 1712 |
unsigned int is_opt_ : 1; |
| 1713 |
}; |
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
class CTcObjTemplateInst |
| 1720 |
{ |
| 1721 |
public: |
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
class CTcPrsNode *expr_; |
| 1728 |
class CTPNCodeBody *code_body_; |
| 1729 |
class CTPNAnonFunc *inline_method_; |
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
tc_toktyp_t def_tok_; |
| 1737 |
|
| 1738 |
|
| 1739 |
CTcToken expr_tok_; |
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
class CTcSymProp *prop_; |
| 1748 |
}; |
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
struct propset_def |
| 1757 |
{ |
| 1758 |
|
| 1759 |
const char *prop_pattern; |
| 1760 |
size_t prop_pattern_len; |
| 1761 |
|
| 1762 |
|
| 1763 |
struct propset_tok *param_tok_head; |
| 1764 |
}; |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
struct propset_tok |
| 1770 |
{ |
| 1771 |
propset_tok(const CTcToken *t) |
| 1772 |
{ |
| 1773 |
|
| 1774 |
this->tok = *t; |
| 1775 |
|
| 1776 |
|
| 1777 |
nxt = 0; |
| 1778 |
} |
| 1779 |
|
| 1780 |
|
| 1781 |
CTcToken tok; |
| 1782 |
|
| 1783 |
|
| 1784 |
propset_tok *nxt; |
| 1785 |
}; |
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
class propset_token_source: public CTcTokenSource |
| 1792 |
{ |
| 1793 |
public: |
| 1794 |
propset_token_source() |
| 1795 |
{ |
| 1796 |
|
| 1797 |
nxt_tok = last_tok = 0; |
| 1798 |
} |
| 1799 |
|
| 1800 |
|
| 1801 |
virtual const CTcToken *get_next_token() |
| 1802 |
{ |
| 1803 |
|
| 1804 |
if (nxt_tok != 0) |
| 1805 |
{ |
| 1806 |
|
| 1807 |
CTcToken *ret = &nxt_tok->tok; |
| 1808 |
|
| 1809 |
|
| 1810 |
nxt_tok = nxt_tok->nxt; |
| 1811 |
|
| 1812 |
|
| 1813 |
return ret; |
| 1814 |
} |
| 1815 |
else |
| 1816 |
{ |
| 1817 |
|
| 1818 |
return 0; |
| 1819 |
} |
| 1820 |
} |
| 1821 |
|
| 1822 |
|
| 1823 |
void insert_token(const CTcToken *tok); |
| 1824 |
|
| 1825 |
|
| 1826 |
void insert_token(tc_toktyp_t typ, const char *txt, size_t len); |
| 1827 |
|
| 1828 |
|
| 1829 |
propset_tok *nxt_tok; |
| 1830 |
|
| 1831 |
|
| 1832 |
propset_tok *last_tok; |
| 1833 |
}; |
| 1834 |
|
| 1835 |
|
| 1836 |
const size_t MAX_PROPSET_DEPTH = 10; |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
class CTcStrTemplate |
| 1846 |
{ |
| 1847 |
public: |
| 1848 |
CTcStrTemplate() |
| 1849 |
{ |
| 1850 |
|
| 1851 |
head = tail = 0; |
| 1852 |
cnt = 0; |
| 1853 |
star = FALSE; |
| 1854 |
|
| 1855 |
|
| 1856 |
func = 0; |
| 1857 |
|
| 1858 |
|
| 1859 |
nxt = 0; |
| 1860 |
} |
| 1861 |
|
| 1862 |
|
| 1863 |
void append_tok(const CTcToken *tok); |
| 1864 |
|
| 1865 |
|
| 1866 |
CTcTokenEle *head, *tail; |
| 1867 |
|
| 1868 |
|
| 1869 |
int cnt; |
| 1870 |
|
| 1871 |
|
| 1872 |
int star; |
| 1873 |
|
| 1874 |
|
| 1875 |
class CTcSymFunc *func; |
| 1876 |
|
| 1877 |
|
| 1878 |
CTcStrTemplate *nxt; |
| 1879 |
}; |
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
struct tcprs_nonsym_obj |
| 1886 |
{ |
| 1887 |
tcprs_nonsym_obj(tctarg_obj_id_t id) |
| 1888 |
{ |
| 1889 |
|
| 1890 |
id_ = id; |
| 1891 |
|
| 1892 |
|
| 1893 |
nxt_ = 0; |
| 1894 |
} |
| 1895 |
|
| 1896 |
|
| 1897 |
tctarg_obj_id_t id_; |
| 1898 |
|
| 1899 |
|
| 1900 |
tcprs_nonsym_obj *nxt_; |
| 1901 |
}; |
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
class CTcDictPropEntry |
| 1909 |
{ |
| 1910 |
public: |
| 1911 |
CTcDictPropEntry(class CTcSymProp *prop) |
| 1912 |
{ |
| 1913 |
|
| 1914 |
prop_ = prop; |
| 1915 |
|
| 1916 |
|
| 1917 |
nxt_ = 0; |
| 1918 |
|
| 1919 |
|
| 1920 |
defined_ = FALSE; |
| 1921 |
} |
| 1922 |
|
| 1923 |
|
| 1924 |
class CTcSymProp *prop_; |
| 1925 |
|
| 1926 |
|
| 1927 |
CTcDictPropEntry *nxt_; |
| 1928 |
|
| 1929 |
|
| 1930 |
unsigned int defined_ : 1; |
| 1931 |
}; |
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
class CTcDictEntry |
| 1939 |
{ |
| 1940 |
public: |
| 1941 |
CTcDictEntry(class CTcSymObj *sym); |
| 1942 |
|
| 1943 |
|
| 1944 |
uint get_obj_idx() const { return obj_idx_; } |
| 1945 |
void set_obj_idx(uint idx) { obj_idx_ = idx; } |
| 1946 |
|
| 1947 |
|
| 1948 |
class CTcSymObj *get_sym() const { return sym_; } |
| 1949 |
|
| 1950 |
|
| 1951 |
CTcDictEntry *get_next() const { return nxt_; } |
| 1952 |
void set_next(CTcDictEntry *nxt) { nxt_ = nxt; } |
| 1953 |
|
| 1954 |
|
| 1955 |
void add_word(const char *txt, size_t len, int copy, |
| 1956 |
tc_obj_id obj, tc_prop_id prop); |
| 1957 |
|
| 1958 |
|
| 1959 |
void write_sym_to_obj_file(CVmFile *fp); |
| 1960 |
|
| 1961 |
|
| 1962 |
class CVmHashTable *get_hash_table() const { return hashtab_; } |
| 1963 |
|
| 1964 |
protected: |
| 1965 |
|
| 1966 |
static void enum_cb_writeobj(void *ctx, class CVmHashEntry *entry); |
| 1967 |
|
| 1968 |
|
| 1969 |
class CTcSymObj *sym_; |
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
uint obj_idx_; |
| 1976 |
|
| 1977 |
|
| 1978 |
CTcDictEntry *nxt_; |
| 1979 |
|
| 1980 |
|
| 1981 |
class CVmHashTable *hashtab_; |
| 1982 |
}; |
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
struct CTcPrsDictItem |
| 1989 |
{ |
| 1990 |
CTcPrsDictItem(tc_obj_id obj, tc_prop_id prop) |
| 1991 |
{ |
| 1992 |
obj_ = obj; |
| 1993 |
prop_ = prop; |
| 1994 |
nxt_ = 0; |
| 1995 |
} |
| 1996 |
|
| 1997 |
|
| 1998 |
tc_obj_id obj_; |
| 1999 |
|
| 2000 |
|
| 2001 |
tc_prop_id prop_; |
| 2002 |
|
| 2003 |
|
| 2004 |
CTcPrsDictItem *nxt_; |
| 2005 |
}; |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
class CVmHashEntryPrsDict: public CVmHashEntryCS |
| 2011 |
{ |
| 2012 |
public: |
| 2013 |
CVmHashEntryPrsDict(const char *txt, size_t len, int copy) |
| 2014 |
: CVmHashEntryCS(txt, len, copy) |
| 2015 |
{ |
| 2016 |
|
| 2017 |
list_ = 0; |
| 2018 |
} |
| 2019 |
|
| 2020 |
|
| 2021 |
void add_item(tc_obj_id obj, tc_prop_id prop); |
| 2022 |
|
| 2023 |
|
| 2024 |
struct CTcPrsDictItem *get_list() const { return list_; } |
| 2025 |
|
| 2026 |
protected: |
| 2027 |
|
| 2028 |
struct CTcPrsDictItem *list_; |
| 2029 |
}; |
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
class CTcGramProdEntry |
| 2036 |
{ |
| 2037 |
public: |
| 2038 |
CTcGramProdEntry(class CTcSymObj *prod_obj); |
| 2039 |
|
| 2040 |
|
| 2041 |
class CTcSymObj *get_prod_sym() const { return prod_sym_; } |
| 2042 |
|
| 2043 |
|
| 2044 |
CTcGramProdEntry *get_next() const { return nxt_; } |
| 2045 |
void set_next(CTcGramProdEntry *nxt) { nxt_ = nxt; } |
| 2046 |
|
| 2047 |
|
| 2048 |
void add_alt(class CTcGramProdAlt *alt); |
| 2049 |
|
| 2050 |
|
| 2051 |
class CTcGramProdAlt *get_alt_head() const { return alt_head_; } |
| 2052 |
|
| 2053 |
|
| 2054 |
void write_to_obj_file(class CVmFile *fp); |
| 2055 |
|
| 2056 |
|
| 2057 |
static void load_from_obj_file(class CVmFile *fp, |
| 2058 |
const tctarg_prop_id_t *prop_xlat, |
| 2059 |
const ulong *enum_xlat, |
| 2060 |
class CTcSymObj *private_owner); |
| 2061 |
|
| 2062 |
|
| 2063 |
void move_alts_to(CTcGramProdEntry *new_entry); |
| 2064 |
|
| 2065 |
|
| 2066 |
int is_declared() const { return is_declared_; } |
| 2067 |
void set_declared(int f) { is_declared_ = f; } |
| 2068 |
|
| 2069 |
protected: |
| 2070 |
|
| 2071 |
class CTcSymObj *prod_sym_; |
| 2072 |
|
| 2073 |
|
| 2074 |
CTcGramProdEntry *nxt_; |
| 2075 |
|
| 2076 |
|
| 2077 |
class CTcGramProdAlt *alt_head_; |
| 2078 |
class CTcGramProdAlt *alt_tail_; |
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
unsigned int is_declared_ : 1; |
| 2086 |
}; |
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
class CTcGramProdAlt |
| 2093 |
{ |
| 2094 |
public: |
| 2095 |
CTcGramProdAlt(class CTcSymObj *obj_sym, class CTcDictEntry *dict); |
| 2096 |
|
| 2097 |
|
| 2098 |
int get_score() const { return score_; } |
| 2099 |
void set_score(int score) { score_ = score; } |
| 2100 |
|
| 2101 |
|
| 2102 |
int get_badness() const { return badness_; } |
| 2103 |
void set_badness(int badness) { badness_ = badness; } |
| 2104 |
|
| 2105 |
|
| 2106 |
class CTcSymObj *get_processor_obj() const { return obj_sym_; } |
| 2107 |
|
| 2108 |
|
| 2109 |
CTcGramProdAlt *get_next() const { return nxt_; } |
| 2110 |
void set_next(CTcGramProdAlt *nxt) { nxt_ = nxt; } |
| 2111 |
|
| 2112 |
|
| 2113 |
void add_tok(class CTcGramProdTok *tok); |
| 2114 |
|
| 2115 |
|
| 2116 |
class CTcGramProdTok *get_tok_head() const { return tok_head_; } |
| 2117 |
|
| 2118 |
|
| 2119 |
void write_to_obj_file(class CVmFile *fp); |
| 2120 |
|
| 2121 |
|
| 2122 |
static CTcGramProdAlt * |
| 2123 |
load_from_obj_file(class CVmFile *fp, |
| 2124 |
const tctarg_prop_id_t *prop_xlat, |
| 2125 |
const ulong *enum_xlat); |
| 2126 |
|
| 2127 |
|
| 2128 |
class CTcDictEntry *get_dict() const { return dict_; } |
| 2129 |
|
| 2130 |
protected: |
| 2131 |
|
| 2132 |
class CTcGramProdTok *tok_head_; |
| 2133 |
class CTcGramProdTok *tok_tail_; |
| 2134 |
|
| 2135 |
|
| 2136 |
class CTcDictEntry *dict_; |
| 2137 |
|
| 2138 |
|
| 2139 |
class CTcSymObj *obj_sym_; |
| 2140 |
|
| 2141 |
|
| 2142 |
CTcGramProdAlt *nxt_; |
| 2143 |
|
| 2144 |
|
| 2145 |
int score_; |
| 2146 |
|
| 2147 |
|
| 2148 |
int badness_; |
| 2149 |
}; |
| 2150 |
|
| 2151 |
|
| 2152 |
enum tcgram_tok_type |
| 2153 |
{ |
| 2154 |
|
| 2155 |
TCGRAM_UNKNOWN, |
| 2156 |
|
| 2157 |
|
| 2158 |
TCGRAM_PROD, |
| 2159 |
|
| 2160 |
|
| 2161 |
TCGRAM_PART_OF_SPEECH, |
| 2162 |
|
| 2163 |
|
| 2164 |
TCGRAM_LITERAL, |
| 2165 |
|
| 2166 |
|
| 2167 |
TCGRAM_TOKEN_TYPE, |
| 2168 |
|
| 2169 |
|
| 2170 |
TCGRAM_STAR, |
| 2171 |
|
| 2172 |
|
| 2173 |
TCGRAM_PART_OF_SPEECH_LIST |
| 2174 |
}; |
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
class CTcGramProdTok |
| 2180 |
{ |
| 2181 |
public: |
| 2182 |
CTcGramProdTok() |
| 2183 |
{ |
| 2184 |
|
| 2185 |
nxt_ = 0; |
| 2186 |
|
| 2187 |
|
| 2188 |
typ_ = TCGRAM_UNKNOWN; |
| 2189 |
|
| 2190 |
|
| 2191 |
prop_assoc_ = TCTARG_INVALID_PROP; |
| 2192 |
} |
| 2193 |
|
| 2194 |
|
| 2195 |
CTcGramProdTok *get_next() const { return nxt_; } |
| 2196 |
void set_next(CTcGramProdTok *nxt) { nxt_ = nxt; } |
| 2197 |
|
| 2198 |
|
| 2199 |
void set_match_prod(class CTcSymObj *obj) |
| 2200 |
{ |
| 2201 |
|
| 2202 |
typ_ = TCGRAM_PROD; |
| 2203 |
val_.obj_ = obj; |
| 2204 |
} |
| 2205 |
|
| 2206 |
|
| 2207 |
void set_match_token_type(ulong enum_id) |
| 2208 |
{ |
| 2209 |
|
| 2210 |
typ_ = TCGRAM_TOKEN_TYPE; |
| 2211 |
val_.enum_id_ = enum_id; |
| 2212 |
} |
| 2213 |
|
| 2214 |
|
| 2215 |
void set_match_part_of_speech(tctarg_prop_id_t prop) |
| 2216 |
{ |
| 2217 |
|
| 2218 |
typ_ = TCGRAM_PART_OF_SPEECH; |
| 2219 |
val_.prop_ = prop; |
| 2220 |
} |
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
void set_match_part_list(); |
| 2227 |
|
| 2228 |
|
| 2229 |
void add_match_part_ele(tctarg_prop_id_t prop); |
| 2230 |
|
| 2231 |
|
| 2232 |
void set_match_literal(const char *txt, size_t len) |
| 2233 |
{ |
| 2234 |
|
| 2235 |
typ_ = TCGRAM_LITERAL; |
| 2236 |
val_.str_.txt_ = txt; |
| 2237 |
val_.str_.len_ = len; |
| 2238 |
} |
| 2239 |
|
| 2240 |
|
| 2241 |
void set_match_star() |
| 2242 |
{ |
| 2243 |
|
| 2244 |
typ_ = TCGRAM_STAR; |
| 2245 |
} |
| 2246 |
|
| 2247 |
|
| 2248 |
tcgram_tok_type get_type() const { return typ_; } |
| 2249 |
|
| 2250 |
|
| 2251 |
class CTcSymObj *getval_prod() const { return val_.obj_; } |
| 2252 |
tctarg_prop_id_t getval_part_of_speech() const { return val_.prop_; } |
| 2253 |
const char *getval_literal_txt() const { return val_.str_.txt_; } |
| 2254 |
const size_t getval_literal_len() const { return val_.str_.len_; } |
| 2255 |
ulong getval_token_type() const { return val_.enum_id_; } |
| 2256 |
size_t getval_part_list_len() const { return val_.prop_list_.len_; } |
| 2257 |
tctarg_prop_id_t getval_part_list_ele(size_t idx) const |
| 2258 |
{ return val_.prop_list_.arr_[idx]; } |
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
tctarg_prop_id_t get_prop_assoc() const { return prop_assoc_; } |
| 2265 |
void set_prop_assoc(tctarg_prop_id_t prop) { prop_assoc_ = prop; } |
| 2266 |
|
| 2267 |
|
| 2268 |
void write_to_obj_file(class CVmFile *fp); |
| 2269 |
|
| 2270 |
|
| 2271 |
static CTcGramProdTok * |
| 2272 |
load_from_obj_file(class CVmFile *fp, |
| 2273 |
const tctarg_prop_id_t *prop_xlat, |
| 2274 |
const ulong *enum_xlat); |
| 2275 |
|
| 2276 |
protected: |
| 2277 |
|
| 2278 |
CTcGramProdTok *nxt_; |
| 2279 |
|
| 2280 |
|
| 2281 |
tcgram_tok_type typ_; |
| 2282 |
|
| 2283 |
|
| 2284 |
union |
| 2285 |
{ |
| 2286 |
|
| 2287 |
class CTcSymObj *obj_; |
| 2288 |
|
| 2289 |
|
| 2290 |
tctarg_prop_id_t prop_; |
| 2291 |
|
| 2292 |
|
| 2293 |
ulong enum_id_; |
| 2294 |
|
| 2295 |
|
| 2296 |
struct |
| 2297 |
{ |
| 2298 |
const char *txt_; |
| 2299 |
size_t len_; |
| 2300 |
} str_; |
| 2301 |
|
| 2302 |
|
| 2303 |
struct |
| 2304 |
{ |
| 2305 |
|
| 2306 |
size_t alo_; |
| 2307 |
|
| 2308 |
|
| 2309 |
size_t len_; |
| 2310 |
|
| 2311 |
|
| 2312 |
tctarg_prop_id_t *arr_; |
| 2313 |
} prop_list_; |
| 2314 |
} val_; |
| 2315 |
|
| 2316 |
|
| 2317 |
tctarg_prop_id_t prop_assoc_; |
| 2318 |
}; |
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
class CTcPrsExport |
| 2325 |
{ |
| 2326 |
public: |
| 2327 |
|
| 2328 |
CTcPrsExport(const char *sym, size_t sym_len) |
| 2329 |
{ |
| 2330 |
|
| 2331 |
sym_ = sym; |
| 2332 |
sym_len_ = sym_len; |
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
ext_name_ = sym; |
| 2339 |
ext_len_ = sym_len; |
| 2340 |
|
| 2341 |
|
| 2342 |
nxt_ = 0; |
| 2343 |
} |
| 2344 |
|
| 2345 |
|
| 2346 |
void set_extern_name(const char *txt, size_t len) |
| 2347 |
{ |
| 2348 |
ext_name_ = txt; |
| 2349 |
ext_len_ = len; |
| 2350 |
} |
| 2351 |
|
| 2352 |
|
| 2353 |
const char *get_sym() const { return sym_; } |
| 2354 |
size_t get_sym_len() const { return sym_len_; } |
| 2355 |
|
| 2356 |
|
| 2357 |
const char *get_ext_name() const { return ext_name_; } |
| 2358 |
size_t get_ext_len() const { return ext_len_; } |
| 2359 |
|
| 2360 |
|
| 2361 |
CTcPrsExport *get_next() const { return nxt_; } |
| 2362 |
void set_next(CTcPrsExport *nxt) { nxt_ = nxt; } |
| 2363 |
|
| 2364 |
|
| 2365 |
void write_to_obj_file(class CVmFile *fp); |
| 2366 |
|
| 2367 |
|
| 2368 |
static CTcPrsExport *read_from_obj_file(class CVmFile *fp); |
| 2369 |
|
| 2370 |
|
| 2371 |
int ext_name_matches(const CTcPrsExport *exp) const |
| 2372 |
{ |
| 2373 |
return (exp->get_ext_len() == get_ext_len() |
| 2374 |
&& memcmp(exp->get_ext_name(), get_ext_name(), |
| 2375 |
get_ext_len()) == 0); |
| 2376 |
} |
| 2377 |
|
| 2378 |
|
| 2379 |
int ext_name_matches(const char *txt) const |
| 2380 |
{ |
| 2381 |
return (get_ext_len() == get_strlen(txt) |
| 2382 |
&& memcmp(get_ext_name(), txt, get_ext_len()) == 0); |
| 2383 |
} |
| 2384 |
|
| 2385 |
|
| 2386 |
int ext_name_starts_with(const char *txt) const |
| 2387 |
{ |
| 2388 |
return (get_ext_len() >= get_strlen(txt) |
| 2389 |
&& memcmp(get_ext_name(), txt, get_strlen(txt)) == 0); |
| 2390 |
} |
| 2391 |
|
| 2392 |
|
| 2393 |
int sym_matches(const CTcPrsExport *exp) const |
| 2394 |
{ |
| 2395 |
return (exp->get_sym_len() == get_sym_len() |
| 2396 |
&& memcmp(exp->get_sym(), get_sym(), get_sym_len()) == 0); |
| 2397 |
} |
| 2398 |
|
| 2399 |
protected: |
| 2400 |
|
| 2401 |
const char *sym_; |
| 2402 |
size_t sym_len_; |
| 2403 |
|
| 2404 |
|
| 2405 |
const char *ext_name_; |
| 2406 |
size_t ext_len_; |
| 2407 |
|
| 2408 |
|
| 2409 |
CTcPrsExport *nxt_; |
| 2410 |
}; |
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
enum tcprs_undef_action |
| 2424 |
{ |
| 2425 |
|
| 2426 |
TCPRS_UNDEF_ADD_UNDEF, |
| 2427 |
|
| 2428 |
|
| 2429 |
TCPRS_UNDEF_ADD_PROP, |
| 2430 |
|
| 2431 |
|
| 2432 |
TCPRS_UNDEF_ADD_PROP_NO_WARNING, |
| 2433 |
|
| 2434 |
|
| 2435 |
TCPRS_UNDEF_ADD_PROP_WEAK |
| 2436 |
}; |
| 2437 |
|
| 2438 |
|
| 2439 |
class CTcPrsSymtab |
| 2440 |
{ |
| 2441 |
public: |
| 2442 |
CTcPrsSymtab(CTcPrsSymtab *parent_scope); |
| 2443 |
virtual ~CTcPrsSymtab(); |
| 2444 |
|
| 2445 |
|
| 2446 |
void *operator new(size_t siz); |
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
static void s_init(); |
| 2453 |
static void s_terminate(); |
| 2454 |
|
| 2455 |
|
| 2456 |
CTcPrsSymtab *get_parent() const { return parent_; } |
| 2457 |
|
| 2458 |
|
| 2459 |
class CTcSymbol *find(const textchar_t *sym, size_t len) |
| 2460 |
{ return find(sym, len, 0); } |
| 2461 |
|
| 2462 |
class CTcSymbol *find(const textchar_t *sym) |
| 2463 |
{ return find(sym, strlen(sym), 0); } |
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
class CTcSymbol *find(const textchar_t *sym, size_t len, |
| 2472 |
CTcPrsSymtab **symtab); |
| 2473 |
|
| 2474 |
|
| 2475 |
class CTcSymbol *find_noref(const textchar_t *sym, size_t len, |
| 2476 |
CTcPrsSymtab **symtab); |
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
class CTcSymbol *find_or_def_undef(const char *sym, size_t len, |
| 2485 |
int copy_str) |
| 2486 |
{ |
| 2487 |
return find_or_def(sym, len, copy_str, TCPRS_UNDEF_ADD_UNDEF); |
| 2488 |
} |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
class CTcSymbol *find_or_def_prop(const char *sym, size_t len, |
| 2497 |
int copy_str) |
| 2498 |
{ |
| 2499 |
return find_or_def(sym, len, copy_str, TCPRS_UNDEF_ADD_PROP); |
| 2500 |
} |
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
class CTcSymbol *find_or_def_prop_explicit( |
| 2510 |
const char *sym, size_t len, int copy_str) |
| 2511 |
{ |
| 2512 |
return find_or_def(sym, len, copy_str, |
| 2513 |
TCPRS_UNDEF_ADD_PROP_NO_WARNING); |
| 2514 |
} |
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
class CTcSymbol *find_or_def_prop_weak( |
| 2521 |
const char *sym, size_t len, int copy_str) |
| 2522 |
{ |
| 2523 |
return find_or_def(sym, len, copy_str, TCPRS_UNDEF_ADD_PROP_WEAK); |
| 2524 |
} |
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
class CTcSymbol *find_or_def_prop_implied(const char *sym, size_t len, |
| 2533 |
int copy_str, int is_self_avail) |
| 2534 |
{ |
| 2535 |
return find_or_def(sym, len, copy_str, |
| 2536 |
is_self_avail |
| 2537 |
? TCPRS_UNDEF_ADD_PROP : TCPRS_UNDEF_ADD_UNDEF); |
| 2538 |
} |
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
class CTcSymbol *find_delete_weak(const char *sym, size_t len); |
| 2545 |
|
| 2546 |
|
| 2547 |
class CTcSymLocal *add_formal(const textchar_t *sym, size_t len, |
| 2548 |
int formal_num, int copy_str); |
| 2549 |
|
| 2550 |
|
| 2551 |
class CTcSymLocal *add_local(const textchar_t *sym, size_t len, |
| 2552 |
int local_num, int copy_str, |
| 2553 |
int init_assigned, int init_referenced); |
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
class CTcSymLocal *add_local(int local_num); |
| 2560 |
|
| 2561 |
|
| 2562 |
class CTcSymLabel *add_code_label(const textchar_t *sym, size_t len, |
| 2563 |
int copy_str); |
| 2564 |
|
| 2565 |
|
| 2566 |
void enum_entries(void (*func)(void *, class CTcSymbol *), void *ctx); |
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
void check_unreferenced_locals(); |
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
int get_list_index() const { return list_index_; } |
| 2581 |
void set_list_index(int n) { list_index_ = n; } |
| 2582 |
|
| 2583 |
|
| 2584 |
CTcPrsSymtab *get_list_next() const { return list_next_; } |
| 2585 |
void set_list_next(CTcPrsSymtab *nxt) { list_next_ = nxt; } |
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
virtual class CTcSymbol *find_direct(const textchar_t *sym, size_t len); |
| 2601 |
|
| 2602 |
|
| 2603 |
virtual void add_entry(class CTcSymbol *sym); |
| 2604 |
|
| 2605 |
|
| 2606 |
virtual void remove_entry(class CTcSymbol *sym); |
| 2607 |
|
| 2608 |
|
| 2609 |
void add_to_range(int ofs) |
| 2610 |
{ |
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
if (start_ofs_ == 0 || ofs < start_ofs_) |
| 2616 |
start_ofs_ = ofs; |
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
if (ofs > end_ofs_) |
| 2623 |
end_ofs_ = ofs; |
| 2624 |
} |
| 2625 |
|
| 2626 |
|
| 2627 |
int get_start_ofs() const { return start_ofs_; } |
| 2628 |
int get_end_ofs() const { return end_ofs_; } |
| 2629 |
|
| 2630 |
protected: |
| 2631 |
|
| 2632 |
static void add_to_global_symtab(CTcPrsSymtab *tab, CTcSymbol *entry); |
| 2633 |
|
| 2634 |
|
| 2635 |
class CVmHashTable *get_hashtab() const { return hashtab_; } |
| 2636 |
|
| 2637 |
|
| 2638 |
static void unref_local_cb(void *ctx, class CTcSymbol *sym); |
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
class CTcSymbol *find_or_def(const textchar_t *sym, size_t len, |
| 2645 |
int copy_str, tcprs_undef_action action); |
| 2646 |
|
| 2647 |
|
| 2648 |
CTcPrsSymtab *parent_; |
| 2649 |
|
| 2650 |
|
| 2651 |
class CVmHashTable *hashtab_; |
| 2652 |
|
| 2653 |
|
| 2654 |
static class CVmHashFunc *hash_func_; |
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
int start_ofs_; |
| 2662 |
int end_ofs_; |
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
CTcPrsSymtab *list_next_; |
| 2672 |
int list_index_; |
| 2673 |
}; |
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
class CTcPrsDbgSymtab |
| 2691 |
{ |
| 2692 |
public: |
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
virtual int find_symbol(const textchar_t *sym, size_t len, |
| 2699 |
struct tcprsdbg_sym_info *info) = 0; |
| 2700 |
}; |
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
struct tcprsdbg_sym_info |
| 2706 |
{ |
| 2707 |
|
| 2708 |
enum tc_symtype_t sym_type; |
| 2709 |
|
| 2710 |
|
| 2711 |
uint var_id; |
| 2712 |
|
| 2713 |
|
| 2714 |
int ctx_arr_idx; |
| 2715 |
|
| 2716 |
|
| 2717 |
uint frame_idx; |
| 2718 |
}; |
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
class CTcPrsMem |
| 2745 |
{ |
| 2746 |
public: |
| 2747 |
CTcPrsMem(); |
| 2748 |
~CTcPrsMem(); |
| 2749 |
|
| 2750 |
|
| 2751 |
void *alloc(size_t siz); |
| 2752 |
|
| 2753 |
|
| 2754 |
void save_state(struct tcprsmem_state_t *state); |
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
void reset(const struct tcprsmem_state_t *state); |
| 2761 |
|
| 2762 |
|
| 2763 |
void reset(); |
| 2764 |
|
| 2765 |
private: |
| 2766 |
|
| 2767 |
void delete_all(); |
| 2768 |
|
| 2769 |
|
| 2770 |
void alloc_block(); |
| 2771 |
|
| 2772 |
|
| 2773 |
struct tcprsmem_blk_t *head_; |
| 2774 |
|
| 2775 |
|
| 2776 |
struct tcprsmem_blk_t *tail_; |
| 2777 |
|
| 2778 |
|
| 2779 |
char *free_ptr_; |
| 2780 |
|
| 2781 |
|
| 2782 |
size_t rem_; |
| 2783 |
}; |
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
struct tcprsmem_state_t |
| 2789 |
{ |
| 2790 |
|
| 2791 |
struct tcprsmem_blk_t *tail; |
| 2792 |
|
| 2793 |
|
| 2794 |
char *free_ptr; |
| 2795 |
|
| 2796 |
|
| 2797 |
size_t rem; |
| 2798 |
}; |
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
inline void *operator new(size_t siz, CTcPrsMem *pool) |
| 2806 |
{ |
| 2807 |
return pool->alloc(siz); |
| 2808 |
} |
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
inline void *operator new[](size_t siz, CTcPrsMem *pool) |
| 2814 |
{ |
| 2815 |
return pool->alloc(siz); |
| 2816 |
} |
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
struct tcprsmem_blk_t |
| 2823 |
{ |
| 2824 |
|
| 2825 |
tcprsmem_blk_t *next_; |
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
char buf_[1]; |
| 2832 |
}; |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
class CPrsArrayList: public CArrayList |
| 2839 |
{ |
| 2840 |
protected: |
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
virtual void *alloc_mem(size_t siz) |
| 2846 |
{ |
| 2847 |
|
| 2848 |
return G_prsmem->alloc(siz); |
| 2849 |
} |
| 2850 |
|
| 2851 |
virtual void *realloc_mem(void *p, size_t oldsiz, size_t newsiz) |
| 2852 |
{ |
| 2853 |
void *pnew; |
| 2854 |
|
| 2855 |
|
| 2856 |
pnew = G_prsmem->alloc(newsiz); |
| 2857 |
|
| 2858 |
|
| 2859 |
memcpy(pnew, p, oldsiz); |
| 2860 |
|
| 2861 |
|
| 2862 |
return pnew; |
| 2863 |
} |
| 2864 |
|
| 2865 |
virtual void free_mem(void *p) |
| 2866 |
{ |
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
} |
| 2872 |
}; |
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
class CTcConstVal |
| 2881 |
{ |
| 2882 |
public: |
| 2883 |
CTcConstVal() |
| 2884 |
{ |
| 2885 |
|
| 2886 |
typ_ = TC_CVT_UNK; |
| 2887 |
|
| 2888 |
|
| 2889 |
ctc_ = FALSE; |
| 2890 |
} |
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
int is_const() const { return (typ_ != TC_CVT_UNK); } |
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
void set_unknown() { typ_ = TC_CVT_UNK; } |
| 2904 |
|
| 2905 |
|
| 2906 |
void set(const CTcConstVal *val) |
| 2907 |
{ |
| 2908 |
|
| 2909 |
typ_ = val->typ_; |
| 2910 |
|
| 2911 |
|
| 2912 |
val_ = val->val_; |
| 2913 |
} |
| 2914 |
|
| 2915 |
|
| 2916 |
void set_int(long val) { typ_ = TC_CVT_INT; val_.intval_ = val; } |
| 2917 |
|
| 2918 |
|
| 2919 |
void set_float(const char *val, size_t len, int promoted); |
| 2920 |
|
| 2921 |
|
| 2922 |
void set_float(const class vbignum_t *val, int promoted); |
| 2923 |
|
| 2924 |
|
| 2925 |
void set_float(ulong i); |
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
void demote_float(); |
| 2938 |
|
| 2939 |
|
| 2940 |
void set_enum(ulong val) { typ_ = TC_CVT_ENUM; val_.enumval_ = val; } |
| 2941 |
|
| 2942 |
|
| 2943 |
void set_sstr(const char *val, size_t len); |
| 2944 |
void set_sstr(const CTcToken *tok); |
| 2945 |
|
| 2946 |
|
| 2947 |
void set_restr(const CTcToken *tok); |
| 2948 |
|
| 2949 |
|
| 2950 |
void set_list(class CTPNList *lst); |
| 2951 |
|
| 2952 |
|
| 2953 |
void set_sstr(uint32_t ofs); |
| 2954 |
void set_list(uint32_t ofs); |
| 2955 |
|
| 2956 |
|
| 2957 |
void set_obj(ulong obj, enum tc_metaclass_t meta) |
| 2958 |
{ |
| 2959 |
typ_ = TC_CVT_OBJ; |
| 2960 |
val_.objval_.id_ = obj; |
| 2961 |
val_.objval_.meta_ = meta; |
| 2962 |
} |
| 2963 |
|
| 2964 |
|
| 2965 |
void set_prop(uint prop) |
| 2966 |
{ |
| 2967 |
typ_ = TC_CVT_PROP; |
| 2968 |
val_.propval_ = prop; |
| 2969 |
} |
| 2970 |
|
| 2971 |
|
| 2972 |
void set_funcptr(class CTcSymFunc *sym) |
| 2973 |
{ |
| 2974 |
typ_ = TC_CVT_FUNCPTR; |
| 2975 |
val_.funcptrval_ = sym; |
| 2976 |
} |
| 2977 |
|
| 2978 |
|
| 2979 |
void set_anon_funcptr(class CTPNCodeBody *code_body) |
| 2980 |
{ |
| 2981 |
typ_ = TC_CVT_ANONFUNCPTR; |
| 2982 |
val_.codebodyval_ = code_body; |
| 2983 |
} |
| 2984 |
|
| 2985 |
|
| 2986 |
void set_bifptr(class CTcSymBif *sym) |
| 2987 |
{ |
| 2988 |
typ_ = TC_CVT_BIFPTR; |
| 2989 |
val_.bifptrval_ = sym; |
| 2990 |
} |
| 2991 |
|
| 2992 |
|
| 2993 |
void set_nil() { typ_ = TC_CVT_NIL; } |
| 2994 |
void set_true() { typ_ = TC_CVT_TRUE; } |
| 2995 |
|
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
void set_vocab_list() { typ_ = TC_CVT_VOCAB_LIST; } |
| 3003 |
|
| 3004 |
|
| 3005 |
void set_bool(int val) |
| 3006 |
{ |
| 3007 |
typ_ = (val ? TC_CVT_TRUE : TC_CVT_NIL); |
| 3008 |
} |
| 3009 |
|
| 3010 |
|
| 3011 |
int is_bool() const { return typ_ == TC_CVT_NIL || typ_ == TC_CVT_TRUE; } |
| 3012 |
|
| 3013 |
|
| 3014 |
tc_constval_type_t get_type() const { return typ_; } |
| 3015 |
|
| 3016 |
|
| 3017 |
long get_val_int() const { return val_.intval_; } |
| 3018 |
|
| 3019 |
|
| 3020 |
const char *get_val_float() const { return val_.floatval_.txt_; } |
| 3021 |
size_t get_val_float_len() const { return val_.floatval_.len_; } |
| 3022 |
|
| 3023 |
|
| 3024 |
int is_promoted() const { return promoted_; } |
| 3025 |
|
| 3026 |
|
| 3027 |
ulong get_val_enum() const { return val_.enumval_; } |
| 3028 |
|
| 3029 |
|
| 3030 |
const char *get_val_str() const { return val_.strval_.strval_; } |
| 3031 |
size_t get_val_str_len() const { return val_.strval_.strval_len_; } |
| 3032 |
|
| 3033 |
|
| 3034 |
class CTPNList *get_val_list() const { return val_.listval_.l_; } |
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
uint32_t get_val_str_ofs() const { return val_.strval_.pool_ofs_; } |
| 3041 |
uint32_t get_val_list_ofs() const { return val_.listval_.pool_ofs_; } |
| 3042 |
|
| 3043 |
|
| 3044 |
ulong get_val_obj() const |
| 3045 |
{ return val_.objval_.id_; } |
| 3046 |
enum tc_metaclass_t get_val_obj_meta() const |
| 3047 |
{ return val_.objval_.meta_; } |
| 3048 |
|
| 3049 |
|
| 3050 |
uint get_val_prop() const { return val_.propval_; } |
| 3051 |
|
| 3052 |
|
| 3053 |
class CTcSymFunc *get_val_funcptr_sym() const |
| 3054 |
{ return val_.funcptrval_; } |
| 3055 |
|
| 3056 |
|
| 3057 |
class CTPNCodeBody *get_val_anon_func_ptr() const |
| 3058 |
{ return val_.codebodyval_; } |
| 3059 |
|
| 3060 |
|
| 3061 |
class CTcSymBif *get_val_bifptr_sym() const |
| 3062 |
{ return val_.bifptrval_; } |
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
int is_equal_to(const CTcConstVal *val) const; |
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
const char *cvt_to_str(char *buf, size_t bufl, size_t *result_len); |
| 3080 |
|
| 3081 |
|
| 3082 |
|
| 3083 |
|
| 3084 |
|
| 3085 |
int get_val_bool() const |
| 3086 |
{ |
| 3087 |
return !(typ_ == TC_CVT_NIL || equals_zero()); |
| 3088 |
} |
| 3089 |
|
| 3090 |
|
| 3091 |
int equals_zero() const; |
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
void set_ctc(int f) { ctc_ = f; } |
| 3100 |
int is_ctc() const { return ctc_; } |
| 3101 |
|
| 3102 |
private: |
| 3103 |
|
| 3104 |
tc_constval_type_t typ_; |
| 3105 |
|
| 3106 |
union |
| 3107 |
{ |
| 3108 |
|
| 3109 |
long intval_; |
| 3110 |
|
| 3111 |
|
| 3112 |
struct |
| 3113 |
{ |
| 3114 |
const char *txt_; |
| 3115 |
size_t len_; |
| 3116 |
} |
| 3117 |
floatval_; |
| 3118 |
|
| 3119 |
|
| 3120 |
ulong enumval_; |
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
struct |
| 3128 |
{ |
| 3129 |
const char *strval_; |
| 3130 |
size_t strval_len_; |
| 3131 |
|
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
uint32_t pool_ofs_; |
| 3140 |
} |
| 3141 |
strval_; |
| 3142 |
|
| 3143 |
|
| 3144 |
struct |
| 3145 |
{ |
| 3146 |
class CTPNList *l_; |
| 3147 |
|
| 3148 |
|
| 3149 |
uint32_t pool_ofs_; |
| 3150 |
} |
| 3151 |
listval_; |
| 3152 |
|
| 3153 |
|
| 3154 |
uint propval_; |
| 3155 |
|
| 3156 |
|
| 3157 |
struct |
| 3158 |
{ |
| 3159 |
ulong id_; |
| 3160 |
enum tc_metaclass_t meta_; |
| 3161 |
} |
| 3162 |
objval_; |
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
class CTcSymFunc *funcptrval_; |
| 3170 |
|
| 3171 |
|
| 3172 |
class CTcSymBif *bifptrval_; |
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
class CTPNCodeBody *codebodyval_; |
| 3179 |
} val_; |
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
|
| 3199 |
uint ctc_ : 1; |
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
uint promoted_ : 1; |
| 3208 |
}; |
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
enum tc_asitype_t |
| 3217 |
{ |
| 3218 |
|
| 3219 |
TC_ASI_SIMPLE, |
| 3220 |
|
| 3221 |
|
| 3222 |
TC_ASI_ADD, |
| 3223 |
|
| 3224 |
|
| 3225 |
TC_ASI_SUB, |
| 3226 |
|
| 3227 |
|
| 3228 |
TC_ASI_MUL, |
| 3229 |
|
| 3230 |
|
| 3231 |
TC_ASI_DIV, |
| 3232 |
|
| 3233 |
|
| 3234 |
TC_ASI_MOD, |
| 3235 |
|
| 3236 |
|
| 3237 |
TC_ASI_BAND, |
| 3238 |
|
| 3239 |
|
| 3240 |
TC_ASI_BOR, |
| 3241 |
|
| 3242 |
|
| 3243 |
TC_ASI_BXOR, |
| 3244 |
|
| 3245 |
|
| 3246 |
TC_ASI_SHL, |
| 3247 |
|
| 3248 |
|
| 3249 |
TC_ASI_ASHR, |
| 3250 |
|
| 3251 |
|
| 3252 |
TC_ASI_LSHR, |
| 3253 |
|
| 3254 |
|
| 3255 |
TC_ASI_PREINC, |
| 3256 |
|
| 3257 |
|
| 3258 |
TC_ASI_PREDEC, |
| 3259 |
|
| 3260 |
|
| 3261 |
TC_ASI_POSTINC, |
| 3262 |
|
| 3263 |
|
| 3264 |
TC_ASI_POSTDEC, |
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
TC_ASI_IDX |
| 3275 |
}; |
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
class CTcFormalTypeList |
| 3285 |
{ |
| 3286 |
public: |
| 3287 |
CTcFormalTypeList() |
| 3288 |
{ |
| 3289 |
|
| 3290 |
head_ = tail_ = 0; |
| 3291 |
|
| 3292 |
|
| 3293 |
varargs_ = FALSE; |
| 3294 |
} |
| 3295 |
|
| 3296 |
~CTcFormalTypeList() { } |
| 3297 |
|
| 3298 |
|
| 3299 |
void decorate_name(CTcToken *decorated_name, |
| 3300 |
const CTcToken *func_base_name); |
| 3301 |
|
| 3302 |
|
| 3303 |
class CTcFormalTypeEle *get_first() const { return head_; } |
| 3304 |
|
| 3305 |
|
| 3306 |
void add_typed_param(const CTcToken *tok); |
| 3307 |
|
| 3308 |
|
| 3309 |
void add_untyped_param(); |
| 3310 |
|
| 3311 |
|
| 3312 |
void add_untyped_params(int n) |
| 3313 |
{ |
| 3314 |
while (n-- > 0) |
| 3315 |
add_untyped_param(); |
| 3316 |
} |
| 3317 |
|
| 3318 |
|
| 3319 |
void add_ellipsis() { varargs_ = TRUE; } |
| 3320 |
|
| 3321 |
protected: |
| 3322 |
|
| 3323 |
void add(class CTcFormalTypeEle *ele); |
| 3324 |
|
| 3325 |
|
| 3326 |
class CTcFormalTypeEle *head_, *tail_; |
| 3327 |
|
| 3328 |
|
| 3329 |
int varargs_; |
| 3330 |
}; |
| 3331 |
|
| 3332 |
|
| 3333 |
class CTcFormalTypeEle |
| 3334 |
{ |
| 3335 |
public: |
| 3336 |
CTcFormalTypeEle() { name_ = 0; } |
| 3337 |
CTcFormalTypeEle(const char *name, size_t len); |
| 3338 |
~CTcFormalTypeEle() |
| 3339 |
{ |
| 3340 |
} |
| 3341 |
|
| 3342 |
|
| 3343 |
CTcFormalTypeEle *nxt_; |
| 3344 |
|
| 3345 |
|
| 3346 |
char *name_; |
| 3347 |
size_t name_len_; |
| 3348 |
}; |
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
class CTcPrsOp |
| 3362 |
{ |
| 3363 |
public: |
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
virtual class CTcPrsNode *parse() const = 0; |
| 3378 |
}; |
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
class CTcPrsOpBin: public CTcPrsOp |
| 3384 |
{ |
| 3385 |
public: |
| 3386 |
CTcPrsOpBin() |
| 3387 |
{ |
| 3388 |
|
| 3389 |
left_ = right_ = 0; |
| 3390 |
|
| 3391 |
|
| 3392 |
op_tok_ = TOKT_INVALID; |
| 3393 |
} |
| 3394 |
|
| 3395 |
CTcPrsOpBin(tc_toktyp_t typ) |
| 3396 |
{ |
| 3397 |
|
| 3398 |
op_tok_ = typ; |
| 3399 |
} |
| 3400 |
|
| 3401 |
CTcPrsOpBin(const CTcPrsOp *left, const CTcPrsOp *right, tc_toktyp_t typ) |
| 3402 |
{ |
| 3403 |
|
| 3404 |
left_ = left; |
| 3405 |
right_ = right; |
| 3406 |
|
| 3407 |
|
| 3408 |
op_tok_ = typ; |
| 3409 |
} |
| 3410 |
|
| 3411 |
|
| 3412 |
class CTcPrsNode *parse() const; |
| 3413 |
|
| 3414 |
|
| 3415 |
virtual class CTcPrsNode |
| 3416 |
*build_tree(class CTcPrsNode *left, |
| 3417 |
class CTcPrsNode *right) const = 0; |
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
virtual class CTcPrsNode |
| 3430 |
*eval_constant(class CTcPrsNode *left, |
| 3431 |
class CTcPrsNode *right) const |
| 3432 |
{ |
| 3433 |
|
| 3434 |
return 0; |
| 3435 |
} |
| 3436 |
|
| 3437 |
|
| 3438 |
tc_toktyp_t get_op_tok() const { return op_tok_; } |
| 3439 |
void set_op_tok(tc_toktyp_t tok) { op_tok_ = tok; } |
| 3440 |
|
| 3441 |
protected: |
| 3442 |
|
| 3443 |
const CTcPrsOp *left_; |
| 3444 |
|
| 3445 |
|
| 3446 |
const CTcPrsOp *right_; |
| 3447 |
|
| 3448 |
|
| 3449 |
tc_toktyp_t op_tok_; |
| 3450 |
}; |
| 3451 |
|
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
|
| 3456 |
|
| 3457 |
|
| 3458 |
|
| 3459 |
class CTcPrsOpBinGroup: public CTcPrsOp |
| 3460 |
{ |
| 3461 |
public: |
| 3462 |
CTcPrsOpBinGroup(const CTcPrsOp *left, const CTcPrsOp *right, |
| 3463 |
const class CTcPrsOpBin *const *ops) |
| 3464 |
{ |
| 3465 |
|
| 3466 |
left_ = left; |
| 3467 |
right_ = right; |
| 3468 |
|
| 3469 |
|
| 3470 |
ops_ = ops; |
| 3471 |
} |
| 3472 |
|
| 3473 |
|
| 3474 |
class CTcPrsNode *parse() const; |
| 3475 |
|
| 3476 |
protected: |
| 3477 |
|
| 3478 |
int find_and_apply_op(CTcPrsNode **lhs) const; |
| 3479 |
|
| 3480 |
|
| 3481 |
const CTcPrsOp *left_; |
| 3482 |
const CTcPrsOp *right_; |
| 3483 |
|
| 3484 |
|
| 3485 |
const class CTcPrsOpBin *const *ops_; |
| 3486 |
}; |
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
class CTcPrsOpBinGroupCompare: public CTcPrsOpBinGroup |
| 3494 |
{ |
| 3495 |
public: |
| 3496 |
CTcPrsOpBinGroupCompare(const class CTcPrsOp *left, |
| 3497 |
const class CTcPrsOp *right, |
| 3498 |
const class CTcPrsOpBin *const *ops) |
| 3499 |
: CTcPrsOpBinGroup(left, right, ops) |
| 3500 |
{ |
| 3501 |
} |
| 3502 |
|
| 3503 |
class CTcPrsNode *parse() const; |
| 3504 |
|
| 3505 |
protected: |
| 3506 |
|
| 3507 |
class CTPNArglist *parse_inlist() const; |
| 3508 |
}; |
| 3509 |
|
| 3510 |
|
| 3511 |
class CTcPrsOpComma: public CTcPrsOpBin |
| 3512 |
{ |
| 3513 |
public: |
| 3514 |
CTcPrsOpComma(const CTcPrsOp *left, const CTcPrsOp *right) |
| 3515 |
: CTcPrsOpBin(left, right, TOKT_COMMA) { } |
| 3516 |
|
| 3517 |
|
| 3518 |
class CTcPrsNode |
| 3519 |
*eval_constant(class CTcPrsNode *left, |
| 3520 |
class CTcPrsNode *right) const; |
| 3521 |
|
| 3522 |
|
| 3523 |
class CTcPrsNode |
| 3524 |
*build_tree(class CTcPrsNode *left, |
| 3525 |
class CTcPrsNode *right) const; |
| 3526 |
}; |
| 3527 |
|
| 3528 |
|
| 3529 |
class CTcPrsOpOr: public CTcPrsOpBin |
| 3530 |
{ |
| 3531 |
public: |
| 3532 |
CTcPrsOpOr(const CTcPrsOp *left, const CTcPrsOp *right) |
| 3533 |
: CTcPrsOpBin(left, right, TOKT_OROR) { } |
| 3534 |
|
| 3535 |
|
| 3536 |
class CTcPrsNode |
| 3537 |
*eval_constant(class CTcPrsNode *left, |
| 3538 |
class CTcPrsNode *right) const; |
| 3539 |
|
| 3540 |
|
| 3541 |
class CTcPrsNode |
| 3542 |
*build_tree(class CTcPrsNode *left, |
| 3543 |
class CTcPrsNode *right) const; |
| 3544 |
}; |
| 3545 |
|
| 3546 |
|
| 3547 |
class CTcPrsOpAnd: public CTcPrsOpBin |
| 3548 |
{ |
| 3549 |
public: |
| 3550 |
CTcPrsOpAnd(const CTcPrsOp *left, const CTcPrsOp *right) |
| 3551 |
: CTcPrsOpBin(left, right, TOKT_ANDAND) { } |
| 3552 |
|
| 3553 |
|
| 3554 |
class CTcPrsNode |
| 3555 |
*eval_constant(class CTcPrsNode *left, |
| 3556 |
class CTcPrsNode *right) const; |
| 3557 |
|
| 3558 |
|
| 3559 |
class CTcPrsNode |
| 3560 |
*build_tree(class CTcPrsNode *left, |
| 3561 |
class CTcPrsNode *right) const; |
| 3562 |
}; |
| 3563 |
|
| 3564 |
|
| 3565 |
class CTcPrsOpRel: public CTcPrsOpBin |
| 3566 |
{ |
| 3567 |
public: |
| 3568 |
CTcPrsOpRel(tc_toktyp_t typ) : CTcPrsOpBin(typ) { } |
| 3569 |
|
| 3570 |
|
| 3571 |
class CTcPrsNode |
| 3572 |
*eval_constant(class CTcPrsNode *left, |
| 3573 |
class CTcPrsNode *right) const; |
| 3574 |
|
| 3575 |
protected: |
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
virtual int get_bool_val(int comparison_value) const = 0; |
| 3582 |
}; |
| 3583 |
|
| 3584 |
|
| 3585 |
class CTcPrsOpGt: public CTcPrsOpRel |
| 3586 |
{ |
| 3587 |
public: |
| 3588 |
CTcPrsOpGt() : CTcPrsOpRel(TOKT_GT) { } |
| 3589 |
|
| 3590 |
|
| 3591 |
int get_bool_val(int comp) const { return comp > 0; } |
| 3592 |
|
| 3593 |
|
| 3594 |
class CTcPrsNode |
| 3595 |
*build_tree(class CTcPrsNode *left, |
| 3596 |
class CTcPrsNode *right) const; |
| 3597 |
}; |
| 3598 |
|
| 3599 |
|
| 3600 |
class CTcPrsOpGe: public CTcPrsOpRel |
| 3601 |
{ |
| 3602 |
public: |
| 3603 |
CTcPrsOpGe() : CTcPrsOpRel(TOKT_GE) { } |
| 3604 |
|
| 3605 |
|
| 3606 |
int get_bool_val(int comp) const { return comp >= 0; } |
| 3607 |
|
| 3608 |
|
| 3609 |
class CTcPrsNode |
| 3610 |
*build_tree(class CTcPrsNode *left, |
| 3611 |
class CTcPrsNode *right) const; |
| 3612 |
}; |
| 3613 |
|
| 3614 |
|
| 3615 |
class CTcPrsOpLt: public CTcPrsOpRel |
| 3616 |
{ |
| 3617 |
public: |
| 3618 |
CTcPrsOpLt() : CTcPrsOpRel(TOKT_LT) { } |
| 3619 |
|
| 3620 |
|
| 3621 |
int get_bool_val(int comp) const { return comp < 0; } |
| 3622 |
|
| 3623 |
|
| 3624 |
class CTcPrsNode |
| 3625 |
*build_tree(class CTcPrsNode *left, |
| 3626 |
class CTcPrsNode *right) const; |
| 3627 |
}; |
| 3628 |
|
| 3629 |
|
| 3630 |
class CTcPrsOpLe: public CTcPrsOpRel |
| 3631 |
{ |
| 3632 |
public: |
| 3633 |
CTcPrsOpLe() : CTcPrsOpRel(TOKT_LE) { } |
| 3634 |
|
| 3635 |
|
| 3636 |
int get_bool_val(int comp) const { return comp <= 0; } |
| 3637 |
|
| 3638 |
|
| 3639 |
class CTcPrsNode |
| 3640 |
*build_tree(class CTcPrsNode *left, |
| 3641 |
class CTcPrsNode *right) const; |
| 3642 |
}; |
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
class CTcPrsOpEqComp: public CTcPrsOpBin |
| 3648 |
{ |
| 3649 |
public: |
| 3650 |
CTcPrsOpEqComp(tc_toktyp_t typ) : CTcPrsOpBin(typ) { } |
| 3651 |
|
| 3652 |
|
| 3653 |
class CTcPrsNode |
| 3654 |
*eval_constant(class CTcPrsNode *left, |
| 3655 |
class CTcPrsNode *right) const; |
| 3656 |
|
| 3657 |
protected: |
| 3658 |
|
| 3659 |
virtual int get_bool_val(int ops_equal) const = 0; |
| 3660 |
}; |
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
class CTcPrsOpEq: public CTcPrsOpEqComp |
| 3667 |
{ |
| 3668 |
public: |
| 3669 |
|
| 3670 |
CTcPrsOpEq() |
| 3671 |
: CTcPrsOpEqComp(TOKT_EQEQ) { } |
| 3672 |
|
| 3673 |
|
| 3674 |
void set_eq_op(tc_toktyp_t op) { op_tok_ = op; } |
| 3675 |
|
| 3676 |
|
| 3677 |
class CTcPrsNode |
| 3678 |
*build_tree(class CTcPrsNode *left, |
| 3679 |
class CTcPrsNode *right) const; |
| 3680 |
|
| 3681 |
|
| 3682 |
virtual int get_bool_val(int ops_equal) const { return ops_equal; } |
| 3683 |
}; |
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
class CTcPrsOpNe: public CTcPrsOpEqComp |
| 3689 |
{ |
| 3690 |
public: |
| 3691 |
CTcPrsOpNe() : CTcPrsOpEqComp(TOKT_NE) { } |
| 3692 |
|
| 3693 |
|
| 3694 |
class CTcPrsNode |
| 3695 |
*build_tree(class CTcPrsNode *left, |
| 3696 |
class CTcPrsNode *right) const; |
| 3697 |
|
| 3698 |
|
| 3699 |
virtual int get_bool_val(int ops_equal) const { return !ops_equal; } |
| 3700 |
}; |
| 3701 |
|
| 3702 |
|
| 3703 |
|
| 3704 |
|
| 3705 |
class CTcPrsOpArith: public CTcPrsOpBin |
| 3706 |
{ |
| 3707 |
public: |
| 3708 |
CTcPrsOpArith(tc_toktyp_t typ) |
| 3709 |
: CTcPrsOpBin(typ) { } |
| 3710 |
|
| 3711 |
CTcPrsOpArith(const CTcPrsOp *left, const CTcPrsOp *right, |
| 3712 |
tc_toktyp_t typ) |
| 3713 |
: CTcPrsOpBin(left, right, typ) { } |
| 3714 |
|
| 3715 |
|
| 3716 |
class CTcPrsNode |
| 3717 |
*eval_constant(class CTcPrsNode *left, |
| 3718 |
class CTcPrsNode *right) const; |
| 3719 |
|
| 3720 |
protected: |
| 3721 |
|
| 3722 |
virtual long calc_result(long val1, long val2, int &ov) const = 0; |
| 3723 |
|
| 3724 |
|
| 3725 |
virtual class vbignum_t *calc_result( |
| 3726 |
const class vbignum_t &a, const class vbignum_t &b) const = 0; |
| 3727 |
}; |
| 3728 |
|
| 3729 |
|
| 3730 |
class CTcPrsOpBOr: public CTcPrsOpArith |
| 3731 |
{ |
| 3732 |
public: |
| 3733 |
CTcPrsOpBOr(const CTcPrsOp *left, const CTcPrsOp *right) |
| 3734 |
: CTcPrsOpArith(left, right, TOKT_OR) { } |
| 3735 |
|
| 3736 |
|
| 3737 |
class CTcPrsNode |
| 3738 |
*build_tree(class CTcPrsNode *left, |
| 3739 |
class CTcPrsNode *right) const; |
| 3740 |
|
| 3741 |
protected: |
| 3742 |
|
| 3743 |
virtual long calc_result(long val1, long val2, int &ov) const |
| 3744 |
{ |
| 3745 |
ov = FALSE; |
| 3746 |
return val1 | val2; |
| 3747 |
} |
| 3748 |
|
| 3749 |
|
| 3750 |
virtual class vbignum_t *calc_result( |
| 3751 |
const class vbignum_t &a, const class vbignum_t &b) const |
| 3752 |
{ |
| 3753 |
G_tok->log_error(TCERR_BAD_OP_FOR_FLOAT); |
| 3754 |
return 0; |
| 3755 |
} |
| 3756 |
}; |
| 3757 |
|
| 3758 |
|
| 3759 |
class CTcPrsOpBXor: public CTcPrsOpArith |
| 3760 |
{ |
| 3761 |
public: |
| 3762 |
CTcPrsOpBXor(const CTcPrsOp *left, const CTcPrsOp *right) |
| 3763 |
: CTcPrsOpArith(left, right, TOKT_XOR) { } |
| 3764 |
|
| 3765 |
|
| 3766 |
class CTcPrsNode |
| 3767 |
*build_tree(class CTcPrsNode *left, |
| 3768 |
class CTcPrsNode *right) const; |
| 3769 |
|
| 3770 |
protected: |
| 3771 |
|
| 3772 |
virtual long calc_result(long val1, long val2, int &ov) const |
| 3773 |
{ |
| 3774 |
ov = FALSE; |
| 3775 |
return val1 ^ val2; |
| 3776 |
} |
| 3777 |
|
| 3778 |
|
| 3779 |
virtual class vbignum_t *calc_result( |
| 3780 |
const class vbignum_t &a, const class vbignum_t &b) const |
| 3781 |
{ |
| 3782 |
G_tok->log_error(TCERR_BAD_OP_FOR_FLOAT); |
| 3783 |
return 0; |
| 3784 |
} |
| 3785 |
}; |
| 3786 |
|
| 3787 |
|
| 3788 |
class CTcPrsOpBAnd: public CTcPrsOpArith |
| 3789 |
{ |
| 3790 |
public: |
| 3791 |
CTcPrsOpBAnd(const CTcPrsOp *left, const CTcPrsOp *right) |
| 3792 |
: CTcPrsOpArith(left, right, TOKT_AND) { } |
| 3793 |
|
| 3794 |
|
| 3795 |
class CTcPrsNode |
| 3796 |
*build_tree(class CTcPrsNode *left, |
| 3797 |
class CTcPrsNode *right) const; |
| 3798 |
|
| 3799 |
protected: |
| 3800 |
|
| 3801 |
virtual long calc_result(long val1, long val2, int &ov) const |
| 3802 |
{ |
| 3803 |
ov = FALSE; |
| 3804 |
return val1 & val2; |
| 3805 |
} |
| 3806 |
|
| 3807 |
|
| 3808 |
virtual class vbignum_t *calc_result( |
| 3809 |
const class vbignum_t &a, const class vbignum_t &b) const |
| 3810 |
{ |
| 3811 |
G_tok->log_error(TCERR_BAD_OP_FOR_FLOAT); |
| 3812 |
return 0; |
| 3813 |
} |
| 3814 |
}; |
| 3815 |
|
| 3816 |
|
| 3817 |
|
| 3818 |
|
| 3819 |
class CTcPrsOpShl: public CTcPrsOpArith |
| 3820 |
{ |
| 3821 |
public: |
| 3822 |
CTcPrsOpShl() : CTcPrsOpArith(TOKT_SHL) { } |
| 3823 |
|
| 3824 |
|
| 3825 |
class CTcPrsNode |
| 3826 |
*build_tree(class CTcPrsNode *left, |
| 3827 |
class CTcPrsNode *right) const; |
| 3828 |
|
| 3829 |
protected: |
| 3830 |
long calc_result(long a, long b, int &ov) const |
| 3831 |
{ |
| 3832 |
ov = FALSE; |
| 3833 |
return a << b; |
| 3834 |
} |
| 3835 |
|
| 3836 |
|
| 3837 |
virtual class vbignum_t *calc_result( |
| 3838 |
const class vbignum_t &a, const class vbignum_t &b) const |
| 3839 |
{ |
| 3840 |
G_tok->log_error(TCERR_BAD_OP_FOR_FLOAT); |
| 3841 |
return 0; |
| 3842 |
} |
| 3843 |
}; |
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
class CTcPrsOpAShr: public CTcPrsOpArith |
| 3849 |
{ |
| 3850 |
public: |
| 3851 |
CTcPrsOpAShr() : CTcPrsOpArith(TOKT_ASHR) { } |
| 3852 |
|
| 3853 |
|
| 3854 |
class CTcPrsNode |
| 3855 |
*build_tree(class CTcPrsNode *left, |
| 3856 |
class CTcPrsNode *right) const; |
| 3857 |
|
| 3858 |
protected: |
| 3859 |
long calc_result(long a, long b, int &ov) const |
| 3860 |
{ |
| 3861 |
ov = FALSE; |
| 3862 |
return t3_ashr(a, b); |
| 3863 |
} |
| 3864 |
|
| 3865 |
|
| 3866 |
virtual class vbignum_t *calc_result( |
| 3867 |
const class vbignum_t &a, const class vbignum_t &b) const |
| 3868 |
{ |
| 3869 |
G_tok->log_error(TCERR_BAD_OP_FOR_FLOAT); |
| 3870 |
return 0; |
| 3871 |
} |
| 3872 |
}; |
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
class CTcPrsOpLShr: public CTcPrsOpArith |
| 3878 |
{ |
| 3879 |
public: |
| 3880 |
CTcPrsOpLShr() : CTcPrsOpArith(TOKT_LSHR) { } |
| 3881 |
|
| 3882 |
|
| 3883 |
class CTcPrsNode |
| 3884 |
*build_tree(class CTcPrsNode *left, |
| 3885 |
class CTcPrsNode *right) const; |
| 3886 |
|
| 3887 |
protected: |
| 3888 |
|
| 3889 |
long calc_result(long a, long b, int &ov) const |
| 3890 |
{ |
| 3891 |
ov = FALSE; |
| 3892 |
return t3_lshr(a, b); |
| 3893 |
} |
| 3894 |
|
| 3895 |
|
| 3896 |
virtual class vbignum_t *calc_result( |
| 3897 |
const class vbignum_t &a, const class vbignum_t &b) const |
| 3898 |
{ |
| 3899 |
G_tok->log_error(TCERR_BAD_OP_FOR_FLOAT); |
| 3900 |
return 0; |
| 3901 |
} |
| 3902 |
}; |
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
class CTcPrsOpMul: public CTcPrsOpArith |
| 3908 |
{ |
| 3909 |
public: |
| 3910 |
CTcPrsOpMul() : CTcPrsOpArith(TOKT_TIMES) { } |
| 3911 |
|
| 3912 |
|
| 3913 |
class CTcPrsNode |
| 3914 |
*build_tree(class CTcPrsNode *left, |
| 3915 |
class CTcPrsNode *right) const; |
| 3916 |
|
| 3917 |
protected: |
| 3918 |
|
| 3919 |
long calc_result(long a, long b, int &ov) const |
| 3920 |
{ |
| 3921 |
int64_t prod = a * b; |
| 3922 |
ov = (prod > (int64_t)INT32MAXVAL || prod < (int64_t)INT32MINVAL); |
| 3923 |
return (long)prod; |
| 3924 |
} |
| 3925 |
|
| 3926 |
|
| 3927 |
virtual class vbignum_t *calc_result( |
| 3928 |
const class vbignum_t &a, const class vbignum_t &b) const; |
| 3929 |
}; |
| 3930 |
|
| 3931 |
|
| 3932 |
|
| 3933 |
|
| 3934 |
class CTcPrsOpDiv: public CTcPrsOpArith |
| 3935 |
{ |
| 3936 |
public: |
| 3937 |
CTcPrsOpDiv() |
| 3938 |
: CTcPrsOpArith(TOKT_DIV) { } |
| 3939 |
|
| 3940 |
CTcPrsOpDiv(tc_toktyp_t tok) |
| 3941 |
: CTcPrsOpArith(tok) { } |
| 3942 |
|
| 3943 |
|
| 3944 |
class CTcPrsNode |
| 3945 |
*build_tree(class CTcPrsNode *left, |
| 3946 |
class CTcPrsNode *right) const; |
| 3947 |
|
| 3948 |
protected: |
| 3949 |
|
| 3950 |
long calc_result(long a, long b, int &ov) const; |
| 3951 |
|
| 3952 |
|
| 3953 |
virtual class vbignum_t *calc_result( |
| 3954 |
const class vbignum_t &a, const class vbignum_t &b) const; |
| 3955 |
}; |
| 3956 |
|
| 3957 |
|
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
class CTcPrsOpMod: public CTcPrsOpDiv |
| 3962 |
{ |
| 3963 |
public: |
| 3964 |
CTcPrsOpMod() : CTcPrsOpDiv(TOKT_MOD) { } |
| 3965 |
|
| 3966 |
|
| 3967 |
class CTcPrsNode |
| 3968 |
*build_tree(class CTcPrsNode *left, |
| 3969 |
class CTcPrsNode *right) const; |
| 3970 |
|
| 3971 |
protected: |
| 3972 |
|
| 3973 |
long calc_result(long a, long b, int &ov) const; |
| 3974 |
|
| 3975 |
|
| 3976 |
virtual class vbignum_t *calc_result( |
| 3977 |
const class vbignum_t &a, const class vbignum_t &b) const; |
| 3978 |
}; |
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
class CTcPrsOpAdd: public CTcPrsOpArith |
| 3984 |
{ |
| 3985 |
public: |
| 3986 |
CTcPrsOpAdd() : CTcPrsOpArith(TOKT_PLUS) { } |
| 3987 |
|
| 3988 |
|
| 3989 |
class CTcPrsNode |
| 3990 |
*build_tree(class CTcPrsNode *left, |
| 3991 |
class CTcPrsNode *right) const; |
| 3992 |
|
| 3993 |
|
| 3994 |
class CTcPrsNode |
| 3995 |
*eval_constant(class CTcPrsNode *left, |
| 3996 |
class CTcPrsNode *right) const; |
| 3997 |
|
| 3998 |
protected: |
| 3999 |
|
| 4000 |
long calc_result(long a, long b, int &ov) const |
| 4001 |
{ |
| 4002 |
int32_t sum = (int32_t)(a + b); |
| 4003 |
ov = (a >= 0 ? b > 0 && sum < a : b < 0 && sum > a); |
| 4004 |
return sum; |
| 4005 |
} |
| 4006 |
|
| 4007 |
|
| 4008 |
virtual class vbignum_t *calc_result( |
| 4009 |
const class vbignum_t &a, const class vbignum_t &b) const; |
| 4010 |
}; |
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
class CTcPrsOpSub: public CTcPrsOpArith |
| 4016 |
{ |
| 4017 |
public: |
| 4018 |
CTcPrsOpSub() : CTcPrsOpArith(TOKT_MINUS) { } |
| 4019 |
|
| 4020 |
|
| 4021 |
class CTcPrsNode |
| 4022 |
*build_tree(class CTcPrsNode *left, |
| 4023 |
class CTcPrsNode *right) const; |
| 4024 |
|
| 4025 |
|
| 4026 |
class CTcPrsNode |
| 4027 |
*eval_constant(class CTcPrsNode *left, |
| 4028 |
class CTcPrsNode *right) const; |
| 4029 |
|
| 4030 |
protected: |
| 4031 |
|
| 4032 |
long calc_result(long a, long b, int &ov) const |
| 4033 |
{ |
| 4034 |
int32_t diff = (int32_t)(a - b); |
| 4035 |
ov = (a >= 0 ? b < 0 && diff < a : b > 0 && diff > a); |
| 4036 |
return diff; |
| 4037 |
} |
| 4038 |
|
| 4039 |
|
| 4040 |
virtual class vbignum_t *calc_result( |
| 4041 |
const class vbignum_t &a, const class vbignum_t &b) const; |
| 4042 |
}; |
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
|
| 4047 |
class CTcPrsOpUnary: public CTcPrsOp |
| 4048 |
{ |
| 4049 |
public: |
| 4050 |
class CTcPrsNode *parse() const; |
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
static class CTcPrsNode |
| 4058 |
*eval_const_subscript(class CTcPrsNode *lhs, |
| 4059 |
class CTcPrsNode *subscript); |
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
static class CTcPrsNode *eval_const_not(class CTcPrsNode *lhs); |
| 4067 |
|
| 4068 |
|
| 4069 |
static class CTcPrsNode *parse_embedding(struct CTcEmbedBuilder *builder); |
| 4070 |
|
| 4071 |
|
| 4072 |
static class CTcPrsNode *parse_list(); |
| 4073 |
|
| 4074 |
|
| 4075 |
static class CTcPrsNode *parse_primary(); |
| 4076 |
|
| 4077 |
|
| 4078 |
static class CTPNAnonFunc *parse_anon_func(int short_form, int is_method); |
| 4079 |
|
| 4080 |
|
| 4081 |
static class CTPNInlineObject *parse_inline_object(int has_colon); |
| 4082 |
|
| 4083 |
protected: |
| 4084 |
|
| 4085 |
static CTcPrsNode *parse_embedding_list( |
| 4086 |
struct CTcEmbedBuilder *b, int &eos, struct CTcEmbedLevel *parent); |
| 4087 |
|
| 4088 |
|
| 4089 |
static CTcPrsNode *parse_embedded_if( |
| 4090 |
struct CTcEmbedBuilder *b, int unless, |
| 4091 |
int &eos, struct CTcEmbedLevel *parent); |
| 4092 |
|
| 4093 |
|
| 4094 |
static CTcPrsNode *parse_embedded_expr( |
| 4095 |
struct CTcEmbedBuilder *b, class CTcEmbedTokenList *tl); |
| 4096 |
|
| 4097 |
|
| 4098 |
static CTcPrsNode *parse_embedded_oneof( |
| 4099 |
struct CTcEmbedBuilder *b, int &eos, struct CTcEmbedLevel *parent); |
| 4100 |
|
| 4101 |
|
| 4102 |
static CTcPrsNode *parse_embedded_firsttime( |
| 4103 |
struct CTcEmbedBuilder *b, int &eos, struct CTcEmbedLevel *parent); |
| 4104 |
|
| 4105 |
|
| 4106 |
static CTcPrsNode *create_oneof_node( |
| 4107 |
struct CTcEmbedBuilder *b, class CTPNList *lst, const char *attrs); |
| 4108 |
|
| 4109 |
|
| 4110 |
static void capture_embedded(struct CTcEmbedBuilder *b, |
| 4111 |
class CTcEmbedTokenList *tl); |
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
static int parse_embedded_end_tok(class CTcEmbedTokenList *tl, |
| 4118 |
struct CTcEmbedLevel *parent, |
| 4119 |
const char **open_kw); |
| 4120 |
|
| 4121 |
|
| 4122 |
static int parse_embedded_end_tok(struct CTcEmbedBuilder *b, |
| 4123 |
struct CTcEmbedLevel *parent, |
| 4124 |
const char **open_kw); |
| 4125 |
|
| 4126 |
|
| 4127 |
static class CTcPrsNode *parse_not(CTcPrsNode *sub); |
| 4128 |
|
| 4129 |
|
| 4130 |
static class CTcPrsNode *parse_bnot(CTcPrsNode *sub); |
| 4131 |
|
| 4132 |
|
| 4133 |
class CTcPrsNode *parse_addr() const; |
| 4134 |
|
| 4135 |
|
| 4136 |
static class CTcPrsNode *parse_pos(CTcPrsNode *sub); |
| 4137 |
|
| 4138 |
|
| 4139 |
static class CTcPrsNode *parse_neg(CTcPrsNode *sub); |
| 4140 |
|
| 4141 |
|
| 4142 |
static class CTcPrsNode *parse_inc(int pre, CTcPrsNode *sub); |
| 4143 |
|
| 4144 |
|
| 4145 |
static class CTcPrsNode *parse_dec(int pre, CTcPrsNode *sub); |
| 4146 |
|
| 4147 |
|
| 4148 |
static class CTcPrsNode *parse_new(CTcPrsNode *sub, int is_transient); |
| 4149 |
|
| 4150 |
|
| 4151 |
static class CTcPrsNode *parse_delete(CTcPrsNode *sub); |
| 4152 |
|
| 4153 |
|
| 4154 |
static class CTcPrsNode *parse_postfix(int allow_member_expr, |
| 4155 |
int allow_call_expr); |
| 4156 |
|
| 4157 |
|
| 4158 |
static class CTcPrsNode *parse_call(CTcPrsNode *lhs); |
| 4159 |
|
| 4160 |
|
| 4161 |
static class CTPNArglist *parse_arg_list(); |
| 4162 |
|
| 4163 |
|
| 4164 |
static class CTcPrsNode *parse_subscript(CTcPrsNode *lhs); |
| 4165 |
|
| 4166 |
|
| 4167 |
static class CTcPrsNode *parse_member(CTcPrsNode *lhs); |
| 4168 |
|
| 4169 |
|
| 4170 |
static class CTcPrsNode *parse_inherited(); |
| 4171 |
|
| 4172 |
|
| 4173 |
static class CTcPrsNode *parse_delegated(); |
| 4174 |
}; |
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
class CTcPrsOpIfnil: public CTcPrsOp |
| 4180 |
{ |
| 4181 |
public: |
| 4182 |
CTcPrsOpIfnil() { } |
| 4183 |
class CTcPrsNode *parse() const; |
| 4184 |
}; |
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
class CTcPrsOpIf: public CTcPrsOp |
| 4190 |
{ |
| 4191 |
public: |
| 4192 |
CTcPrsOpIf() { } |
| 4193 |
class CTcPrsNode *parse() const; |
| 4194 |
}; |
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
class CTcPrsOpAsi: public CTcPrsOp |
| 4201 |
{ |
| 4202 |
public: |
| 4203 |
CTcPrsOpAsi() |
| 4204 |
{ |
| 4205 |
|
| 4206 |
asi_op_ = TOKT_EQ; |
| 4207 |
} |
| 4208 |
|
| 4209 |
|
| 4210 |
class CTcPrsNode *parse() const; |
| 4211 |
|
| 4212 |
|
| 4213 |
void set_asi_op(tc_toktyp_t tok) { asi_op_ = tok; } |
| 4214 |
|
| 4215 |
private: |
| 4216 |
|
| 4217 |
tc_toktyp_t asi_op_; |
| 4218 |
}; |
| 4219 |
|
| 4220 |
#endif |
| 4221 |
|