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.

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