UilSarProc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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: UilSarProc.c /main/12 1995/07/14 09:37:43 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 routines for processing procedures.
  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 create the procedure definition entry symbol
  83. ** node a procedure declaration.
  84. **
  85. ** FORMAL PARAMETERS:
  86. **
  87. ** id_frame ptr to token frame for the procedure name
  88. ** param_frame ptr to token frame or null frame holding the
  89. ** type of the argument
  90. ** class_frame ptr to frame whose b_flags holds private, etc. info
  91. **
  92. ** IMPLICIT INPUTS:
  93. **
  94. ** sym_az_current_section_entry the "current" section list
  95. **
  96. ** IMPLICIT OUTPUTS:
  97. **
  98. ** none
  99. **
  100. ** FUNCTION VALUE:
  101. **
  102. ** void
  103. **
  104. ** SIDE EFFECTS:
  105. **
  106. ** errors may be issued for previously defined name
  107. **
  108. **--
  109. **/
  110. void
  111. sar_create_procedure(XmConst yystype *id_frame,
  112. XmConst yystype *param_frame,
  113. XmConst yystype *class_frame,
  114. XmConst yystype *semi_frame)
  115. {
  116. sym_name_entry_type *name_entry;
  117. sym_proc_def_entry_type *proc_def_entry;
  118. sym_section_entry_type *section_entry;
  119. sym_obj_entry_type *obj_entry;
  120. /*
  121. ** Call standard routine to check name entry for id_frame.
  122. ** This routine handles font name, color names, etc used as ids
  123. */
  124. name_entry = (sym_name_entry_type *) sem_dcl_name( id_frame );
  125. if (name_entry == NULL)
  126. return;
  127. /*
  128. ** Allocate the procedure definition entry and fill it in
  129. */
  130. proc_def_entry = (sym_proc_def_entry_type *)
  131. sem_allocate_node (sym_k_proc_def_entry, sym_k_proc_def_entry_size);
  132. proc_def_entry->b_widget_type = uil_max_object + 1;
  133. proc_def_entry->obj_header.az_name = (sym_name_entry_type *) name_entry;
  134. name_entry->az_object = (sym_entry_type *) proc_def_entry;
  135. /*
  136. ** Parameter frame has 4 cases:
  137. ** 1) no argument checking desired
  138. ** syntax: PROCEDURE id
  139. ** 2) argument checking desired - no argument
  140. ** syntax: PROCEDURE id( )
  141. ** 3) argument checking desired - single argument
  142. ** syntax: PROCEDURE id( type )
  143. ** 4) argument checking desired - single typed widget argument
  144. ** syntax: PROCEDURE id( CLASS_NAME )
  145. ** These cases are distinguished as follows:
  146. ** 1) tag = null type = 0
  147. ** 2) tag = null type = sar_k_no_value
  148. ** 3) tag = token type = argument type
  149. ** 4) tag = object type = widget type
  150. */
  151. proc_def_entry->v_arg_checking = TRUE;
  152. switch (param_frame->b_tag)
  153. {
  154. case sar_k_null_frame:
  155. if (param_frame->b_type == sym_k_no_value )
  156. {
  157. proc_def_entry->b_arg_count = 0;
  158. proc_def_entry->b_arg_type = sym_k_no_value;
  159. }
  160. else
  161. proc_def_entry->v_arg_checking = FALSE;
  162. break;
  163. case sar_k_token_frame:
  164. proc_def_entry->b_arg_type = param_frame->b_type;
  165. proc_def_entry->b_arg_count = 1;
  166. break;
  167. case sar_k_object_frame:
  168. _assert((param_frame->b_type == sym_k_widget_entry),
  169. "object frame not widget entry");
  170. obj_entry =
  171. (sym_obj_entry_type *)param_frame->value.az_symbol_entry;
  172. proc_def_entry->b_arg_type = sym_k_widget_ref_value;
  173. proc_def_entry->b_arg_count = 1;
  174. proc_def_entry->b_widget_type = obj_entry->header.b_type;
  175. break;
  176. default:
  177. _assert( FALSE, "param frame in error" );
  178. }
  179. /*
  180. ** Process the class clause
  181. */
  182. switch (class_frame->b_flags)
  183. {
  184. case sym_m_exported:
  185. sym_make_external_def( name_entry );
  186. case sym_m_private:
  187. case sym_m_imported:
  188. break;
  189. default:
  190. _assert( FALSE, "class frame in error" );
  191. }
  192. proc_def_entry->obj_header.b_flags = class_frame->b_flags;
  193. /*
  194. ** save the source file info for this procedure entry
  195. */
  196. _sar_save_source_info (&proc_def_entry->header, id_frame, semi_frame );
  197. sar_assoc_comment((sym_obj_entry_type *)proc_def_entry); /* preserve comments */
  198. /*
  199. ** allocate a section entry to link the proc_def entry into the structure
  200. */
  201. section_entry = (sym_section_entry_type *) sem_allocate_node
  202. (sym_k_section_entry, sym_k_section_entry_size);
  203. /*
  204. ** Link this entry off of the current section list
  205. */
  206. section_entry->next = (sym_entry_type *) sym_az_current_section_entry->entries;
  207. sym_az_current_section_entry->entries = (sym_entry_type *) section_entry;
  208. section_entry->entries = (sym_entry_type *) proc_def_entry;
  209. }
  210. /*
  211. **++
  212. ** FUNCTIONAL DESCRIPTION:
  213. **
  214. ** This function processes a reference to a procedure.
  215. **
  216. ** FORMAL PARAMETERS:
  217. **
  218. ** id_frame ptr to token frame for the procedure name
  219. ** value_frame ptr to token frame or null frame holding the
  220. ** value of the argument to the procedure
  221. ** context value indicating how the procedure is being used
  222. **
  223. ** IMPLICIT INPUTS:
  224. **
  225. ** none
  226. **
  227. ** IMPLICIT OUTPUTS:
  228. **
  229. ** none
  230. **
  231. ** FUNCTION VALUE:
  232. **
  233. ** a procedure reference entry / NULL in case of an illegal reference
  234. **
  235. ** SIDE EFFECTS:
  236. **
  237. ** errors may be issued
  238. **
  239. **--
  240. **/
  241. sym_proc_ref_entry_type
  242. *sem_reference_procedure( yystype *id_frame,
  243. XmConst yystype *value_frame,
  244. XmConst int context )
  245. {
  246. sym_value_entry_type *value_entry;
  247. sym_proc_def_entry_type *proc_def_entry;
  248. sym_proc_ref_entry_type *proc_ref_entry;
  249. /*
  250. ** Call standard routine to check name entry for id_frame.
  251. ** This routine handles font name, color names, etc used as ids
  252. */
  253. proc_def_entry =
  254. (sym_proc_def_entry_type *)
  255. sem_ref_name( id_frame, sym_k_proc_def_entry );
  256. switch (value_frame->b_tag)
  257. {
  258. case sar_k_null_frame:
  259. value_entry = NULL;
  260. break;
  261. case sar_k_value_frame:
  262. if ((value_frame->b_flags & sym_m_forward_ref) != 0)
  263. value_entry = NULL;
  264. else
  265. value_entry = (sym_value_entry_type *)
  266. value_frame->value.az_symbol_entry;
  267. break;
  268. case sar_k_object_frame:
  269. value_entry =
  270. (sym_value_entry_type *) value_frame->value.az_symbol_entry;
  271. break;
  272. default:
  273. _assert( FALSE, "actual arg in error" );
  274. }
  275. /*
  276. ** Allocate the procedure reference entry and fill it in
  277. */
  278. proc_ref_entry = (sym_proc_ref_entry_type *)
  279. sem_allocate_node (sym_k_proc_ref_entry, sym_k_proc_ref_entry_size);
  280. if ((id_frame->b_flags & sym_m_forward_ref) != 0)
  281. sym_make_value_forward_ref (id_frame,
  282. (char*)&(proc_ref_entry->az_proc_def), sym_k_patch_list_add);
  283. else
  284. proc_ref_entry->az_proc_def = proc_def_entry;
  285. if ((value_frame->b_flags & sym_m_forward_ref) != 0)
  286. sym_make_value_forward_ref (value_frame,
  287. (char*)&(proc_ref_entry->az_arg_value), sym_k_patch_add);
  288. else
  289. proc_ref_entry->az_arg_value = value_entry;
  290. /*
  291. ** Apply context constraints
  292. **
  293. ** If this is a procedure being used as a user object,
  294. ** it should not have any arguments. The arguments to such
  295. ** a procedure are always a parent widget id and an argument list.
  296. ** This constraint is currently inforced by the grammar.
  297. **
  298. ** At this time the compiler permits all types of values for callback
  299. ** arguments. This may be limited shortly when we see if it is
  300. ** reasonable to pass fonts, colors, reasons, etc.
  301. */
  302. return proc_ref_entry;
  303. }
  304. /*
  305. **++
  306. ** FUNCTIONAL DESCRIPTION:
  307. **
  308. ** This function checks to see if a object is defined with the name
  309. ** corresponding to the id given in the first parameter.
  310. **
  311. ** FORMAL PARAMETERS:
  312. **
  313. ** id_frame ptr to a token frame on the parse stack holding the name
  314. ** tag the type of construct needed
  315. **
  316. ** IMPLICIT INPUTS:
  317. **
  318. ** none
  319. **
  320. ** IMPLICIT OUTPUTS:
  321. **
  322. ** none
  323. **
  324. ** FUNCTION VALUE:
  325. **
  326. ** ptr to a symbol entry for construct or NULL
  327. **
  328. ** SIDE EFFECTS:
  329. **
  330. ** error message if the name is undefined or for a different construct
  331. ** forward_ref bit may be turned on in id_frame
  332. **--
  333. **/
  334. sym_entry_type
  335. *sem_ref_name(yystype *id_frame,
  336. XmConst int tag)
  337. {
  338. sym_name_entry_type *name_entry;
  339. sym_entry_type *symbol_entry;
  340. _assert( id_frame->b_tag == sar_k_token_frame, "arg1 not id frame" );
  341. /*
  342. ** The id frame may hold a name or the keyword for a font name, color
  343. ** name, reason name etc. If it is one of these special name, then
  344. ** we must see if the symbol table holds a name for the special type.
  345. */
  346. if (id_frame->b_type != NAME)
  347. {
  348. name_entry =
  349. sym_find_name
  350. ( id_frame->value.az_keyword_entry->b_length,
  351. id_frame->value.az_keyword_entry->at_name );
  352. if (name_entry == NULL)
  353. {
  354. diag_issue_diagnostic
  355. ( d_undefined,
  356. _sar_source_position( id_frame ),
  357. diag_tag_text( sym_k_proc_def_entry ),
  358. id_frame->value.az_keyword_entry->at_name );
  359. return NULL;
  360. }
  361. }
  362. else
  363. name_entry =
  364. (sym_name_entry_type *) id_frame->value.az_symbol_entry;
  365. /*
  366. ** If the name entry already has no object linked from it, we are
  367. ** referencing an undefined object.
  368. */
  369. symbol_entry = name_entry->az_object;
  370. if (symbol_entry == NULL )
  371. {
  372. id_frame->b_flags |= sym_m_forward_ref;
  373. return NULL;
  374. }
  375. /*
  376. ** If the name entry has the wrong type of object, this is also
  377. ** an error.
  378. */
  379. if (symbol_entry->header.b_tag != tag )
  380. {
  381. diag_issue_diagnostic
  382. ( d_ctx_req,
  383. _sar_source_position( id_frame ),
  384. diag_tag_text( tag ),
  385. diag_tag_text( symbol_entry->header.b_tag ) );
  386. return NULL;
  387. }
  388. return symbol_entry;
  389. }