UilSarExp.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * @OSF_COPYRIGHT@
  25. * COPYRIGHT NOTICE
  26. * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
  27. * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
  28. * the full copyright text.
  29. */
  30. /*
  31. * HISTORY
  32. */
  33. #ifdef REV_INFO
  34. #ifndef lint
  35. static char rcsid[] = "$XConsortium: UilSarExp.c /main/11 1995/07/14 09:37:03 drk $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. **++
  42. ** FACILITY:
  43. **
  44. ** User Interface Language Compiler (UIL)
  45. **
  46. ** ABSTRACT:
  47. **
  48. ** This module supports value expressions in UIL.
  49. **
  50. **--
  51. **/
  52. /*
  53. **
  54. ** INCLUDE FILES
  55. **
  56. **/
  57. #include "UilDefI.h"
  58. /*
  59. **
  60. ** DEFINE and MACRO DEFINITIONS
  61. **
  62. **/
  63. /*
  64. **
  65. ** EXTERNAL VARIABLE DECLARATIONS
  66. **
  67. **/
  68. /*
  69. **
  70. ** GLOBAL VARIABLE DECLARATIONS
  71. **
  72. **/
  73. /*
  74. **
  75. ** OWN VARIABLE DECLARATIONS
  76. **
  77. **/
  78. /*
  79. **++
  80. ** FUNCTIONAL DESCRIPTION:
  81. **
  82. ** This function processes a binary arithmetic operator in an expression
  83. **
  84. ** FORMAL PARAMETERS:
  85. **
  86. ** operator_frame: [in-out] frame holding the operator and the
  87. ** target frame
  88. ** op1_frame: [in] frame holding operand 1
  89. ** op2_frame: [in] frame holding operand 2
  90. **
  91. ** IMPLICIT INPUTS:
  92. **
  93. ** none
  94. **
  95. ** IMPLICIT OUTPUTS:
  96. **
  97. ** none
  98. **
  99. ** FUNCTION VALUE:
  100. **
  101. ** void
  102. **
  103. ** SIDE EFFECTS:
  104. **
  105. ** op1 or op2 symbol entry may be freed
  106. **
  107. **--
  108. **/
  109. void sar_binary_op(operator_frame, op1_frame, op2_frame)
  110. yystype *operator_frame;
  111. yystype *op1_frame;
  112. yystype *op2_frame;
  113. {
  114. sym_value_entry_type *res_entry;
  115. int operator;
  116. _assert( operator_frame->b_tag == sar_k_token_frame,
  117. "operator missing" );
  118. res_entry = (sym_value_entry_type *)
  119. sem_allocate_node( sym_k_value_entry,
  120. sym_k_value_entry_size );
  121. res_entry->obj_header.b_flags = sym_m_builtin | sym_m_private;
  122. res_entry->b_type = sym_k_any_value;
  123. /* res_entry->az_source_rec = op1_frame->az_source_record; */
  124. _sar_save_source_pos (&res_entry->header, op1_frame);
  125. /*
  126. ** Determine the operator from the operator frame
  127. */
  128. switch (operator_frame->b_type)
  129. {
  130. case AND:
  131. operator = sym_k_and_op;
  132. break;
  133. case PLUS:
  134. operator = sym_k_add_op;
  135. break;
  136. case MINUS:
  137. operator = sym_k_subtract_op;
  138. break;
  139. case MULTIPLY:
  140. operator = sym_k_multiply_op;
  141. break;
  142. case DIVIDE:
  143. operator = sym_k_divide_op;
  144. break;
  145. case LEFT_SHIFT:
  146. operator = sym_k_left_shift_op;
  147. break;
  148. case RIGHT_SHIFT:
  149. operator = sym_k_right_shift_op;
  150. break;
  151. case OR:
  152. operator = sym_k_or_op;
  153. break;
  154. case XOR:
  155. operator = sym_k_or_op;
  156. break;
  157. default:
  158. _assert( FALSE, "unknown binary operator" );
  159. }
  160. res_entry->b_expr_opr = operator;
  161. /*
  162. ** If the value is a forward reference, we'll patch in the
  163. ** address of the the referenced value between passes. Otherwise,
  164. ** just point to the referenced value node.
  165. */
  166. if ((op1_frame->b_flags & sym_m_forward_ref) != 0)
  167. sym_make_value_forward_ref (op1_frame,
  168. (char*)&(res_entry->az_exp_op1), sym_k_patch_add);
  169. else
  170. res_entry->az_exp_op1 =
  171. (sym_value_entry_type *) op1_frame->value.az_symbol_entry;
  172. if ((op2_frame->b_flags & sym_m_forward_ref) != 0)
  173. sym_make_value_forward_ref (op2_frame,
  174. (char*)&(res_entry->az_exp_op2), sym_k_patch_add);
  175. else
  176. res_entry->az_exp_op2 =
  177. (sym_value_entry_type *) op2_frame->value.az_symbol_entry;
  178. operator_frame->b_tag = sar_k_value_frame;
  179. operator_frame->b_type = res_entry->b_type;
  180. operator_frame->b_flags = res_entry->obj_header.b_flags;
  181. operator_frame->value.az_symbol_entry =
  182. (sym_entry_type *) res_entry;
  183. return;
  184. }
  185. /*
  186. **++
  187. ** FUNCTIONAL DESCRIPTION:
  188. **
  189. ** This function processes a unary arithmetic operator in an expression
  190. **
  191. ** FORMAL PARAMETERS:
  192. **
  193. ** operator_frame: [in-out] frame holding the operator and the
  194. ** target frame
  195. ** op1_frame: [in] frame holding operand 1
  196. **
  197. ** IMPLICIT INPUTS:
  198. **
  199. ** none
  200. **
  201. ** IMPLICIT OUTPUTS:
  202. **
  203. ** none
  204. **
  205. ** FUNCTION VALUE:
  206. **
  207. ** void
  208. **
  209. ** SIDE EFFECTS:
  210. **
  211. ** op1 symbol entry may be freed
  212. **
  213. **--
  214. **/
  215. void sar_unary_op(operator_frame, op1_frame)
  216. yystype *operator_frame;
  217. yystype *op1_frame;
  218. {
  219. sym_value_entry_type *res_entry;
  220. int operator;
  221. int res_type;
  222. _assert( operator_frame->b_tag == sar_k_token_frame,
  223. "operator missing" );
  224. /*
  225. ** Determine the operator from the operator frame
  226. */
  227. switch (operator_frame->b_type)
  228. {
  229. case PLUS:
  230. operator = sym_k_unary_plus_op;
  231. break;
  232. case MINUS:
  233. operator = sym_k_unary_minus_op;
  234. break;
  235. case NOT:
  236. operator = sym_k_not_op;
  237. break;
  238. case INTEGER:
  239. res_type = sym_k_integer_value;
  240. operator = sym_k_coerce_op;
  241. break;
  242. case FLOAT:
  243. res_type = sym_k_float_value;
  244. operator = sym_k_coerce_op;
  245. break;
  246. case SINGLE_FLOAT:
  247. res_type = sym_k_single_float_value;
  248. operator = sym_k_coerce_op;
  249. break;
  250. case KEYSYM:
  251. res_type = sym_k_keysym_value;
  252. operator = sym_k_coerce_op;
  253. break;
  254. default:
  255. _assert( FALSE, "unknown unary operator" );
  256. }
  257. /*
  258. ** Create the result
  259. */
  260. res_entry = (sym_value_entry_type *)
  261. sem_allocate_node (sym_k_value_entry, sym_k_value_entry_size);
  262. res_entry->b_expr_opr = operator;
  263. /* Begin fixing OSF CR 5691 */
  264. res_entry->b_type = operator;
  265. /* End fixing OSF CR 5691 */
  266. res_entry->az_exp_op1 =
  267. (sym_value_entry_type *) op1_frame->value.az_symbol_entry;
  268. res_entry->obj_header.b_flags = sym_m_builtin | sym_m_private;
  269. if (operator == sym_k_coerce_op)
  270. res_entry->b_type = res_type;
  271. _sar_save_source_pos (&res_entry->header, op1_frame );
  272. operator_frame->b_tag = sar_k_value_frame;
  273. operator_frame->b_type = res_entry->b_type;
  274. operator_frame->b_flags = res_entry->obj_header.b_flags;
  275. operator_frame->value.az_symbol_entry = (sym_entry_type *) res_entry;
  276. return;
  277. }