Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.5 KiB

  1. /************************************************************************/
  2. /* */
  3. /* RCPP - Resource Compiler Pre-Processor for NT system */
  4. /* */
  5. /* P1SUP.C - First pass C stuff which probably is not used */
  6. /* */
  7. /* 27-Nov-90 w-BrianM Update for NT from PM SDK RCPP */
  8. /* */
  9. /************************************************************************/
  10. #include "rc.h"
  11. /* trees */
  12. #define LEFT 1
  13. #define RIGHT 2
  14. #define MORE_CHECKING 2
  15. int TypeCount;
  16. int TreeCount;
  17. type_entry_t *Type_table[TYPE_TABLE_SIZE];
  18. /************************************************************************/
  19. /* Local Function Prototypes */
  20. /************************************************************************/
  21. ptype_t hash_type(ptype_t);
  22. int types_equal(ptype_t, ptype_t);
  23. /************************************************************************
  24. ** hash_type : returns a pointer to an already built type, if it
  25. ** exists, or builds one.
  26. ************************************************************************/
  27. ptype_t
  28. hash_type(
  29. type_t *p_type
  30. )
  31. {
  32. REG type_entry_t *p_tmp;
  33. type_entry_t **p_start;
  34. /* Try to get a unique hash value for every type...keep
  35. * type_equal in mind if changing this
  36. */
  37. p_start = &Type_table[(TY_BTYPE(p_type) + TY_DTYPE(p_type) + (INT_PTR) TY_INDIR(p_type)) & (TYPE_TABLE_SIZE - 1)];
  38. for(p_tmp = *p_start; p_tmp; p_tmp = p_tmp->te_next ) {
  39. if(types_equal(p_type,&(p_tmp->te_type))) {
  40. return(&(p_tmp->te_type));
  41. }
  42. }
  43. p_tmp = (type_entry_t *) MyAlloc(sizeof(type_entry_t));
  44. if (p_tmp == NULL) {
  45. strcpy (Msg_Text, GET_MSG (1002));
  46. error(1002);
  47. return NULL;
  48. }
  49. p_tmp->te_next = *p_start;
  50. *p_start = p_tmp;
  51. p_tmp->te_type = *p_type;
  52. TY_TINDEX(&(p_tmp->te_type)) = 0;
  53. return(&(p_tmp->te_type));
  54. }
  55. /************************************************************************
  56. ** types_equal : are two types equal?
  57. ************************************************************************/
  58. int
  59. types_equal(
  60. REG ptype_t p1,
  61. REG ptype_t p2
  62. )
  63. {
  64. return((TY_BTYPE(p1) == TY_BTYPE(p2))
  65. &&
  66. (TY_DTYPE(p1) == TY_DTYPE(p2))
  67. &&
  68. TY_INDIR(p1) == TY_INDIR(p2)
  69. );
  70. }
  71. /************************************************************************
  72. ** build_const - builds and returns a pointer to a constant tree.
  73. ** Input : constant type.
  74. ** : ptr to a union containing the value of the constant
  75. ** Output : Pointer to constant tree.
  76. ************************************************************************/
  77. ptree_t
  78. build_const(
  79. REG token_t type,
  80. value_t *value
  81. )
  82. {
  83. REG ptree_t res;
  84. ptype_t p_type;
  85. btype_t btype;
  86. res = (ptree_t) MyAlloc(sizeof(tree_t));
  87. if (res == NULL) {
  88. strcpy (Msg_Text, GET_MSG (1002));
  89. error(1002);
  90. return NULL;
  91. }
  92. TR_SHAPE(res) = TTconstant;
  93. TR_TOKEN(res) = type;
  94. switch( type ) {
  95. case L_CINTEGER:
  96. case L_LONGINT:
  97. case L_CUNSIGNED:
  98. case L_LONGUNSIGNED:
  99. if( type == L_CUNSIGNED || type == L_LONGUNSIGNED ) {
  100. btype = (btype_t)(BT_UNSIGNED |
  101. (btype_t)((type == L_CUNSIGNED) ? BTint : BTlong));
  102. } else {
  103. btype = (btype_t)((type == L_CINTEGER) ? BTint : BTlong);
  104. }
  105. if((TR_LVALUE(res) = PV_LONG(value)) == 0) {
  106. TR_SHAPE(res) |= TTzero;
  107. }
  108. break;
  109. case L_CFLOAT:
  110. btype = BTfloat;
  111. TR_RCON(res) = PV_RCON(value);
  112. break;
  113. case L_CDOUBLE:
  114. btype = BTdouble;
  115. TR_RCON(res) = PV_RCON(value);
  116. break;
  117. case L_CLDOUBLE:
  118. btype = BTldouble;
  119. TR_RCON(res) = PV_RCON(value);
  120. break;
  121. default:
  122. break;
  123. }
  124. p_type = (ptype_t) MyAlloc(sizeof(type_t));
  125. if (p_type == NULL) {
  126. strcpy (Msg_Text, GET_MSG (1002));
  127. error(1002);
  128. return NULL;
  129. }
  130. TY_BTYPE(p_type) = (btype_t)(btype | BT_CONST);
  131. TR_P1TYPE(res) = hash_type(p_type);
  132. return(res);
  133. }