ast.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include "icode.h"
  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. static const condOp invCondOpJCond[12] = {GREATER_EQUAL, GREATER, LESS, LESS_EQUAL,
  25. NOT_EQUAL, EQUAL, GREATER_EQUAL, LESS,
  26. GREATER, LESS_EQUAL, LESS, GREATER_EQUAL};
  27. struct Function;
  28. struct STKFRAME;
  29. struct LOCAL_ID;
  30. struct ICODE;
  31. struct ID;
  32. #include "IdentType.h"
  33. //enum opLoc;
  34. //enum hlFirst;
  35. //enum operDu;
  36. /* Expression data type */
  37. struct COND_EXPR
  38. {
  39. condNodeType type; /* Conditional Expression Node Type */
  40. union _exprNode { /* Different cond expr nodes */
  41. struct /* for BOOLEAN_OP */
  42. {
  43. condOp op;
  44. COND_EXPR *lhs;
  45. COND_EXPR *rhs;
  46. } boolExpr;
  47. COND_EXPR *unaryExp; /* for NEGATION,ADDRESSOF,DEREFERENCE*/
  48. IDENTTYPE ident; /* for IDENTIFIER */
  49. } expr;
  50. public:
  51. static COND_EXPR *idGlob(int16 segValue, int16 off);
  52. static COND_EXPR *idRegIdx(Int idx, regType reg_type);
  53. static COND_EXPR *idKte(dword kte, byte size);
  54. static COND_EXPR *idLoc(Int off, LOCAL_ID *localId);
  55. static COND_EXPR *idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym);
  56. static COND_EXPR *idLongIdx(Int idx);
  57. static COND_EXPR *idOther(byte seg, byte regi, int16 off);
  58. static COND_EXPR *idParam(Int off, const STKFRAME *argSymtab);
  59. static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
  60. static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, Int ix, operDu du, Int off);
  61. static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
  62. static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, Int ix);
  63. static COND_EXPR *id(const ICODE &pIcode, opLoc sd, Function *pProc, Int i, ICODE &duIcode, operDu du);
  64. static COND_EXPR *boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op);
  65. public:
  66. COND_EXPR *clone();
  67. void release();
  68. void changeBoolOp(condOp newOp);
  69. COND_EXPR(COND_EXPR &other)
  70. {
  71. type=other.type;
  72. expr=other.expr;
  73. }
  74. COND_EXPR(condNodeType t=UNKNOWN_OP) : type(t)
  75. {
  76. memset(&expr,0,sizeof(_exprNode));
  77. }
  78. public:
  79. };
  80. /* Sequence of conditional expression data type */
  81. /*** NOTE: not used at present ****/
  82. //struct SEQ_COND_EXPR
  83. //{
  84. // COND_EXPR *expr;
  85. // struct _condExpSeq *neccxt;
  86. //};