ast.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. static const int operandSize=20;
  9. #include <cstring>
  10. #include "Enums.h"
  11. /* The following definitions and types define the Conditional Expression
  12. * attributed syntax tree, as defined by the following EBNF:
  13. CondExp ::= CondTerm AND CondTerm | CondTerm
  14. CondTerm ::= (CondFactor op CondFactor)
  15. CondFactor ::= Identifier | ! CondFactor
  16. Identifier ::= globalVar | register | localVar | parameter | constant
  17. op ::= <= | < | = | != | > | >=
  18. */
  19. /* High-level BOOLEAN conditions for iJB..iJNS icodes */
  20. static const condOp condOpJCond[12] = {LESS, LESS_EQUAL, GREATER_EQUAL, GREATER,
  21. EQUAL, NOT_EQUAL, LESS, GREATER_EQUAL,
  22. LESS_EQUAL, GREATER, GREATER_EQUAL, LESS};
  23. static const condOp invCondOpJCond[12] = {GREATER_EQUAL, GREATER, LESS, LESS_EQUAL,
  24. NOT_EQUAL, EQUAL, GREATER_EQUAL, LESS,
  25. GREATER, LESS_EQUAL, LESS, GREATER_EQUAL};
  26. struct Function;
  27. struct STKFRAME;
  28. struct LOCAL_ID;
  29. struct ICODE;
  30. struct ID;
  31. #include "IdentType.h"
  32. //enum opLoc;
  33. //enum hlFirst;
  34. //enum operDu;
  35. /* Expression data type */
  36. struct COND_EXPR
  37. {
  38. condNodeType type; /* Conditional Expression Node Type */
  39. union _exprNode { /* Different cond expr nodes */
  40. struct /* for BOOLEAN_OP */
  41. {
  42. condOp op;
  43. COND_EXPR *lhs;
  44. COND_EXPR *rhs;
  45. } boolExpr;
  46. COND_EXPR *unaryExp; /* for NEGATION,ADDRESSOF,DEREFERENCE*/
  47. IDENTTYPE ident; /* for IDENTIFIER */
  48. } expr;
  49. public:
  50. static COND_EXPR *idGlob(int16 segValue, int16 off);
  51. static COND_EXPR *idRegIdx(Int idx, regType reg_type);
  52. static COND_EXPR *idKte(dword kte, byte size);
  53. static COND_EXPR *idLoc(Int off, LOCAL_ID *localId);
  54. static COND_EXPR *idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym);
  55. static COND_EXPR *idLongIdx(Int idx);
  56. static COND_EXPR *idOther(byte seg, byte regi, int16 off);
  57. static COND_EXPR *idParam(Int off, const STKFRAME *argSymtab);
  58. static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
  59. static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, ICODE *pIcode, hlFirst f, Int ix, operDu du, Int off);
  60. static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
  61. static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, Int ix);
  62. static COND_EXPR *id(ICODE *pIcode, opLoc sd, Function *pProc, Int i, ICODE *duIcode, operDu du);
  63. static COND_EXPR *boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op);
  64. public:
  65. COND_EXPR *clone();
  66. void release();
  67. void changeBoolOp(condOp newOp);
  68. COND_EXPR(COND_EXPR &other)
  69. {
  70. type=other.type;
  71. expr=other.expr;
  72. }
  73. COND_EXPR()
  74. {
  75. type=UNKNOWN_OP;
  76. memset(&expr,0,sizeof(_exprNode));
  77. }
  78. };
  79. /* Sequence of conditional expression data type */
  80. /*** NOTE: not used at present ****/
  81. //struct SEQ_COND_EXPR
  82. //{
  83. // COND_EXPR *expr;
  84. // struct _condExpSeq *neccxt;
  85. //};