ast.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * File: ast.h
  3. * Purpose: definition of the abstract syntax tree ADT.
  4. * Date: September 1993
  5. * (C) Cristina Cifuentes
  6. */
  7. #pragma once
  8. #include <cstring>
  9. #include <list>
  10. #include "Enums.h"
  11. static const int operandSize=20;
  12. /* The following definitions and types define the Conditional Expression
  13. * attributed syntax tree, as defined by the following EBNF:
  14. CondExp ::= CondTerm AND CondTerm | CondTerm
  15. CondTerm ::= (CondFactor op CondFactor)
  16. CondFactor ::= Identifier | ! CondFactor
  17. Identifier ::= globalVar | register | localVar | parameter | constant
  18. op ::= <= | < | = | != | > | >=
  19. */
  20. /* High-level BOOLEAN conditions for iJB..iJNS icodes */
  21. static const condOp condOpJCond[12] = {LESS, LESS_EQUAL, GREATER_EQUAL, GREATER,
  22. EQUAL, NOT_EQUAL, LESS, GREATER_EQUAL,
  23. LESS_EQUAL, GREATER, GREATER_EQUAL, LESS};
  24. struct Function;
  25. struct STKFRAME;
  26. struct LOCAL_ID;
  27. struct ICODE;
  28. struct ID;
  29. typedef std::list<ICODE>::iterator iICODE;
  30. #include "IdentType.h"
  31. /* Expression data type */
  32. struct COND_EXPR
  33. {
  34. condNodeType type; /* Conditional Expression Node Type */
  35. union _exprNode { /* Different cond expr nodes */
  36. struct /* for BOOLEAN_OP */
  37. {
  38. condOp op;
  39. COND_EXPR *lhs;
  40. COND_EXPR *rhs;
  41. } boolExpr;
  42. COND_EXPR *unaryExp; /* for NEGATION,ADDRESSOF,DEREFERENCE*/
  43. IDENTTYPE ident; /* for IDENTIFIER */
  44. } expr;
  45. public:
  46. static COND_EXPR *idGlob(int16_t segValue, int16_t off);
  47. static COND_EXPR *idRegIdx(int idx, regType reg_type);
  48. static COND_EXPR *idKte(uint32_t kte, uint8_t size);
  49. static COND_EXPR *idLoc(int off, LOCAL_ID *localId);
  50. static COND_EXPR *idReg(uint8_t regi, uint32_t icodeFlg, LOCAL_ID *locsym);
  51. static COND_EXPR *idLongIdx(int idx);
  52. static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off);
  53. static COND_EXPR *idParam(int off, const STKFRAME *argSymtab);
  54. static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
  55. static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
  56. static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
  57. static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
  58. static COND_EXPR *id(const ICODE &pIcode, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
  59. static COND_EXPR *boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op);
  60. public:
  61. COND_EXPR *clone();
  62. void release();
  63. void changeBoolOp(condOp newOp);
  64. COND_EXPR(COND_EXPR &other)
  65. {
  66. type=other.type;
  67. expr=other.expr;
  68. }
  69. COND_EXPR(condNodeType t=UNKNOWN_OP) : type(t)
  70. {
  71. memset(&expr,0,sizeof(_exprNode));
  72. }
  73. public:
  74. COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
  75. };