UilP2Reslv.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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: UilP2Reslv.c /main/11 1995/07/14 09:36:35 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 contain the second pass routines for resolving forward
  49. ** references.
  50. **
  51. **--
  52. **/
  53. /*
  54. **
  55. ** INCLUDE FILES
  56. **
  57. **/
  58. #include "UilDefI.h"
  59. /*
  60. **
  61. ** DEFINE and MACRO DEFINITIONS
  62. **
  63. **/
  64. /*
  65. **
  66. ** EXTERNAL VARIABLE DECLARATIONS
  67. **
  68. **/
  69. /*
  70. **
  71. ** GLOBAL VARIABLE DECLARATIONS
  72. **
  73. **/
  74. /*
  75. **
  76. ** OWN VARIABLE DECLARATIONS
  77. **
  78. **/
  79. /*
  80. **++
  81. ** FUNCTIONAL DESCRIPTION:
  82. **
  83. ** This function processes forward references from the first pass.
  84. **
  85. ** FORMAL PARAMETERS:
  86. **
  87. ** none
  88. **
  89. ** IMPLICIT INPUTS:
  90. **
  91. ** sym_az_forward_ref_chain
  92. ** sym_az_val_forward_ref_chain
  93. **
  94. ** IMPLICIT OUTPUTS:
  95. **
  96. ** none
  97. **
  98. ** FUNCTION VALUE:
  99. **
  100. ** void
  101. **
  102. ** SIDE EFFECTS:
  103. **
  104. ** error messages may be issued for objects that are still undefined
  105. ** or of the wrong type
  106. **
  107. **--
  108. **/
  109. void sem_resolve_forward_refs()
  110. {
  111. sym_forward_ref_entry_type * fwd_entry;
  112. sym_forward_ref_entry_type * next_fwd_entry;
  113. sym_val_forward_ref_entry_type * fwd_val_entry;
  114. sym_val_forward_ref_entry_type * next_fwd_val_entry;
  115. sym_widget_entry_type ** target_obj_entry;
  116. sym_value_entry_type ** target_val_entry;
  117. sym_parent_list_type * parent_node;
  118. sym_parent_list_type * parent_ptr;
  119. int found;
  120. /*
  121. ** Forward references are placed on a chain by the first pass of
  122. ** the compiler. This routine walks the chain checking that
  123. ** 1) name is now defined
  124. ** 2) name points to the correct type of object
  125. */
  126. for (fwd_entry = sym_az_forward_ref_chain;
  127. fwd_entry != NULL;
  128. fwd_entry = next_fwd_entry)
  129. {
  130. sym_name_entry_type * name_entry;
  131. sym_widget_entry_type * object_entry;
  132. unsigned short int object_type;
  133. /*
  134. ** Save the pointer to the next forward entry so we can free the current
  135. ** entry after it is processed.
  136. */
  137. next_fwd_entry = fwd_entry->az_next_ref;
  138. /*
  139. ** Call the Status callback routine to report our progress.
  140. */
  141. /* %COMPLETE */
  142. Uil_percent_complete = 60;
  143. if (Uil_cmd_z_command.status_cb != (Uil_continue_type(*)())NULL)
  144. diag_report_status();
  145. object_type = fwd_entry->header.b_type;
  146. name_entry = fwd_entry->az_name;
  147. object_entry = (sym_widget_entry_type *) name_entry->az_object;
  148. if (object_entry == NULL)
  149. {
  150. diag_issue_diagnostic
  151. ( d_never_def,
  152. _sar_source_pos2 (fwd_entry),
  153. diag_object_text( object_type ),
  154. name_entry->c_text );
  155. continue;
  156. }
  157. /*
  158. ** Make sure object references are to correct type of object.
  159. ** A forward reference naming a widget class may be correctly
  160. ** resolved by the corresponding gadget class, and vice versa.
  161. */
  162. if ((object_entry->header.b_type!=object_type) &&
  163. (uil_gadget_variants[object_entry->header.b_type]!=object_type) &&
  164. (uil_gadget_variants[object_type]!=object_entry->header.b_type))
  165. {
  166. diag_issue_diagnostic
  167. (d_ctx_req,
  168. _sar_source_pos2(fwd_entry),
  169. diag_object_text(object_type),
  170. diag_object_text(object_entry->header.b_type));
  171. continue;
  172. }
  173. target_obj_entry =
  174. (sym_widget_entry_type * *) fwd_entry->a_update_location;
  175. *target_obj_entry = object_entry;
  176. /*
  177. ** Update objects on forward refernce chain so that their parent_lists point
  178. ** to the objects which reference them
  179. */
  180. if (fwd_entry -> parent != NULL)
  181. {
  182. found = FALSE;
  183. for (parent_ptr = object_entry -> parent_list;
  184. ((parent_ptr != NULL) && (found == FALSE));
  185. parent_ptr = parent_ptr -> next)
  186. {
  187. if (parent_ptr -> parent == fwd_entry -> parent)
  188. found = TRUE;
  189. }
  190. if (found == FALSE)
  191. {
  192. parent_node = (sym_parent_list_type *)
  193. sem_allocate_node (sym_k_parent_list_entry,
  194. sym_k_parent_list_size);
  195. parent_node -> next = object_entry -> parent_list;
  196. object_entry -> parent_list = parent_node;
  197. parent_node -> parent = fwd_entry -> parent;
  198. }
  199. }
  200. /*
  201. ** Free the Forward reference entry now that it is no longer needed
  202. */
  203. sem_free_node(( sym_entry_type *)fwd_entry);
  204. }
  205. /*
  206. ** Now resolve the forward references to values
  207. **/
  208. /*
  209. ** Forward references are placed on a chain by the first pass of
  210. ** the compiler. This routine walks the chain checking that
  211. ** 1) name is now defined
  212. ** 2) name points to the correct type of value
  213. */
  214. for (fwd_val_entry = sym_az_val_forward_ref_chain;
  215. fwd_val_entry != NULL;
  216. fwd_val_entry = next_fwd_val_entry)
  217. {
  218. sym_name_entry_type * name_entry;
  219. sym_value_entry_type * value_entry;
  220. sym_obj_entry_type * obj_entry;
  221. /*
  222. ** Save the pointer to the next forward entry so we can free the current
  223. ** entry after it is processed.
  224. */
  225. next_fwd_val_entry = fwd_val_entry->az_next_ref;
  226. /*
  227. ** Call the Status callback routine to report our progress.
  228. */
  229. /* %COMPLETE */
  230. Uil_percent_complete = 60;
  231. if (Uil_cmd_z_command.status_cb != (Uil_continue_type(*)())NULL)
  232. diag_report_status();
  233. name_entry = fwd_val_entry->az_name;
  234. value_entry = (sym_value_entry_type *) name_entry->az_object;
  235. obj_entry = (sym_obj_entry_type *) name_entry->az_object;
  236. if (value_entry == NULL)
  237. {
  238. diag_issue_diagnostic
  239. ( d_never_def,
  240. _sar_source_pos2 (fwd_val_entry),
  241. "value",
  242. name_entry->c_text );
  243. continue;
  244. }
  245. switch (fwd_val_entry->fwd_ref_flags)
  246. {
  247. case (sym_k_patch_add):
  248. case (sym_k_patch_list_add):
  249. {
  250. target_val_entry =
  251. (sym_value_entry_type * *) fwd_val_entry->a_update_location;
  252. *target_val_entry = value_entry;
  253. break;
  254. }
  255. default:
  256. _assert(FALSE, "Illegal forward reference");
  257. }
  258. /*
  259. ** Free the Forward reference entry now that it is no longer needed
  260. */
  261. sem_free_node(( sym_entry_type *)fwd_val_entry);
  262. }
  263. }