Leaked source code of windows server 2003
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.

146 lines
4.0 KiB

  1. /***********************************************************************
  2. * Microsoft (R) Windows (R) Resource Compiler
  3. *
  4. * Copyright (c) Microsoft Corporation. All rights reserved.
  5. *
  6. * File Comments:
  7. *
  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. error(1002);
  46. return NULL;
  47. }
  48. p_tmp->te_next = *p_start;
  49. *p_start = p_tmp;
  50. p_tmp->te_type = *p_type;
  51. TY_TINDEX(&(p_tmp->te_type)) = 0;
  52. return(&(p_tmp->te_type));
  53. }
  54. /************************************************************************
  55. ** types_equal : are two types equal?
  56. ************************************************************************/
  57. int
  58. types_equal(
  59. REG ptype_t p1,
  60. REG ptype_t p2
  61. )
  62. {
  63. return((TY_BTYPE(p1) == TY_BTYPE(p2))
  64. &&
  65. (TY_DTYPE(p1) == TY_DTYPE(p2))
  66. &&
  67. TY_INDIR(p1) == TY_INDIR(p2)
  68. );
  69. }
  70. /************************************************************************
  71. ** build_const - builds and returns a pointer to a constant tree.
  72. ** Input : constant type.
  73. ** : ptr to a union containing the value of the constant
  74. ** Output : Pointer to constant tree.
  75. ************************************************************************/
  76. ptree_t
  77. build_const(
  78. REG token_t type,
  79. value_t *value
  80. )
  81. {
  82. REG ptree_t res;
  83. ptype_t p_type;
  84. btype_t btype;
  85. res = (ptree_t) MyAlloc(sizeof(tree_t));
  86. TR_SHAPE(res) = TTconstant;
  87. TR_TOKEN(res) = type;
  88. switch( type ) {
  89. case L_CINTEGER:
  90. case L_LONGINT:
  91. case L_CUNSIGNED:
  92. case L_LONGUNSIGNED:
  93. if( type == L_CUNSIGNED || type == L_LONGUNSIGNED ) {
  94. btype = (btype_t)(BT_UNSIGNED |
  95. (btype_t)((type == L_CUNSIGNED) ? BTint : BTlong));
  96. } else {
  97. btype = (btype_t)((type == L_CINTEGER) ? BTint : BTlong);
  98. }
  99. if((TR_LVALUE(res) = PV_LONG(value)) == 0) {
  100. TR_SHAPE(res) |= TTzero;
  101. }
  102. break;
  103. case L_CFLOAT:
  104. btype = BTfloat;
  105. TR_RCON(res) = PV_RCON(value);
  106. break;
  107. case L_CDOUBLE:
  108. btype = BTdouble;
  109. TR_RCON(res) = PV_RCON(value);
  110. break;
  111. case L_CLDOUBLE:
  112. btype = BTldouble;
  113. TR_RCON(res) = PV_RCON(value);
  114. break;
  115. default:
  116. break;
  117. }
  118. p_type = (ptype_t) MyAlloc(sizeof(type_t));
  119. TY_BTYPE(p_type) = (btype_t)(btype | BT_CONST);
  120. TR_P1TYPE(res) = hash_type(p_type);
  121. return(res);
  122. }