2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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.
35 static char rcsid[] = "$XConsortium: UilSarProc.c /main/12 1995/07/14 09:37:43 drk $"
40 * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
46 ** User Interface Language Compiler (UIL)
50 ** This module contain the routines for processing procedures.
67 ** DEFINE and MACRO DEFINITIONS
75 ** EXTERNAL VARIABLE DECLARATIONS
82 ** GLOBAL VARIABLE DECLARATIONS
89 ** OWN VARIABLE DECLARATIONS
96 ** FUNCTIONAL DESCRIPTION:
98 ** This function create the procedure definition entry symbol
99 ** node a procedure declaration.
101 ** FORMAL PARAMETERS:
103 ** id_frame ptr to token frame for the procedure name
104 ** param_frame ptr to token frame or null frame holding the
105 ** type of the argument
106 ** class_frame ptr to frame whose b_flags holds private, etc. info
110 ** sym_az_current_section_entry the "current" section list
122 ** errors may be issued for previously defined name
128 sar_create_procedure(XmConst yystype *id_frame,
129 XmConst yystype *param_frame,
130 XmConst yystype *class_frame,
131 XmConst yystype *semi_frame)
133 sym_name_entry_type *name_entry;
134 sym_proc_def_entry_type *proc_def_entry;
135 sym_section_entry_type *section_entry;
136 sym_obj_entry_type *obj_entry;
139 ** Call standard routine to check name entry for id_frame.
140 ** This routine handles font name, color names, etc used as ids
143 name_entry = (sym_name_entry_type *) sem_dcl_name( id_frame );
145 if (name_entry == NULL)
149 ** Allocate the procedure definition entry and fill it in
152 proc_def_entry = (sym_proc_def_entry_type *)
153 sem_allocate_node (sym_k_proc_def_entry, sym_k_proc_def_entry_size);
155 proc_def_entry->b_widget_type = uil_max_object + 1;
156 proc_def_entry->obj_header.az_name = (sym_name_entry_type *) name_entry;
157 name_entry->az_object = (sym_entry_type *) proc_def_entry;
160 ** Parameter frame has 4 cases:
161 ** 1) no argument checking desired
162 ** syntax: PROCEDURE id
163 ** 2) argument checking desired - no argument
164 ** syntax: PROCEDURE id( )
165 ** 3) argument checking desired - single argument
166 ** syntax: PROCEDURE id( type )
167 ** 4) argument checking desired - single typed widget argument
168 ** syntax: PROCEDURE id( CLASS_NAME )
169 ** These cases are distinguished as follows:
170 ** 1) tag = null type = 0
171 ** 2) tag = null type = sar_k_no_value
172 ** 3) tag = token type = argument type
173 ** 4) tag = object type = widget type
176 proc_def_entry->v_arg_checking = TRUE;
178 switch (param_frame->b_tag)
180 case sar_k_null_frame:
181 if (param_frame->b_type == sym_k_no_value )
183 proc_def_entry->b_arg_count = 0;
184 proc_def_entry->b_arg_type = sym_k_no_value;
187 proc_def_entry->v_arg_checking = FALSE;
191 case sar_k_token_frame:
192 proc_def_entry->b_arg_type = param_frame->b_type;
193 proc_def_entry->b_arg_count = 1;
196 case sar_k_object_frame:
197 _assert((param_frame->b_type == sym_k_widget_entry),
198 "object frame not widget entry");
201 (sym_obj_entry_type *)param_frame->value.az_symbol_entry;
203 proc_def_entry->b_arg_type = sym_k_widget_ref_value;
204 proc_def_entry->b_arg_count = 1;
205 proc_def_entry->b_widget_type = obj_entry->header.b_type;
209 _assert( FALSE, "param frame in error" );
214 ** Process the class clause
217 switch (class_frame->b_flags)
220 sym_make_external_def( name_entry );
227 _assert( FALSE, "class frame in error" );
231 proc_def_entry->obj_header.b_flags = class_frame->b_flags;
234 ** save the source file info for this procedure entry
236 _sar_save_source_info (&proc_def_entry->header, id_frame, semi_frame );
237 sar_assoc_comment((sym_obj_entry_type *)proc_def_entry); /* preserve comments */
240 ** allocate a section entry to link the proc_def entry into the structure
242 section_entry = (sym_section_entry_type *) sem_allocate_node
243 (sym_k_section_entry, sym_k_section_entry_size);
246 ** Link this entry off of the current section list
248 section_entry->next = (sym_entry_type *) sym_az_current_section_entry->entries;
249 sym_az_current_section_entry->entries = (sym_entry_type *) section_entry;
251 section_entry->entries = (sym_entry_type *) proc_def_entry;
257 ** FUNCTIONAL DESCRIPTION:
259 ** This function processes a reference to a procedure.
261 ** FORMAL PARAMETERS:
263 ** id_frame ptr to token frame for the procedure name
264 ** value_frame ptr to token frame or null frame holding the
265 ** value of the argument to the procedure
266 ** context value indicating how the procedure is being used
278 ** a procedure reference entry / NULL in case of an illegal reference
282 ** errors may be issued
287 sym_proc_ref_entry_type
288 *sem_reference_procedure( yystype *id_frame,
289 XmConst yystype *value_frame,
290 XmConst int context )
292 sym_value_entry_type *value_entry;
293 sym_proc_def_entry_type *proc_def_entry;
294 sym_proc_ref_entry_type *proc_ref_entry;
297 ** Call standard routine to check name entry for id_frame.
298 ** This routine handles font name, color names, etc used as ids
302 (sym_proc_def_entry_type *)
303 sem_ref_name( id_frame, sym_k_proc_def_entry );
305 switch (value_frame->b_tag)
307 case sar_k_null_frame:
311 case sar_k_value_frame:
312 if ((value_frame->b_flags & sym_m_forward_ref) != 0)
315 value_entry = (sym_value_entry_type *)
316 value_frame->value.az_symbol_entry;
319 case sar_k_object_frame:
321 (sym_value_entry_type *) value_frame->value.az_symbol_entry;
325 _assert( FALSE, "actual arg in error" );
329 ** Allocate the procedure reference entry and fill it in
332 proc_ref_entry = (sym_proc_ref_entry_type *)
333 sem_allocate_node (sym_k_proc_ref_entry, sym_k_proc_ref_entry_size);
335 if ((id_frame->b_flags & sym_m_forward_ref) != 0)
336 sym_make_value_forward_ref (id_frame,
337 (char*)&(proc_ref_entry->az_proc_def), sym_k_patch_list_add);
339 proc_ref_entry->az_proc_def = proc_def_entry;
341 if ((value_frame->b_flags & sym_m_forward_ref) != 0)
342 sym_make_value_forward_ref (value_frame,
343 (char*)&(proc_ref_entry->az_arg_value), sym_k_patch_add);
345 proc_ref_entry->az_arg_value = value_entry;
348 ** Apply context constraints
350 ** If this is a procedure being used as a user object,
351 ** it should not have any arguments. The arguments to such
352 ** a procedure are always a parent widget id and an argument list.
353 ** This constraint is currently inforced by the grammar.
355 ** At this time the compiler permits all types of values for callback
356 ** arguments. This may be limited shortly when we see if it is
357 ** reasonable to pass fonts, colors, reasons, etc.
360 return proc_ref_entry;
367 ** FUNCTIONAL DESCRIPTION:
369 ** This function checks to see if a object is defined with the name
370 ** corresponding to the id given in the first parameter.
372 ** FORMAL PARAMETERS:
374 ** id_frame ptr to a token frame on the parse stack holding the name
375 ** tag the type of construct needed
387 ** ptr to a symbol entry for construct or NULL
391 ** error message if the name is undefined or for a different construct
392 ** forward_ref bit may be turned on in id_frame
397 *sem_ref_name(yystype *id_frame,
400 sym_name_entry_type *name_entry;
401 sym_entry_type *symbol_entry;
403 _assert( id_frame->b_tag == sar_k_token_frame, "arg1 not id frame" );
406 ** The id frame may hold a name or the keyword for a font name, color
407 ** name, reason name etc. If it is one of these special name, then
408 ** we must see if the symbol table holds a name for the special type.
411 if (id_frame->b_type != NAME)
415 ( id_frame->value.az_keyword_entry->b_length,
416 id_frame->value.az_keyword_entry->at_name );
418 if (name_entry == NULL)
420 diag_issue_diagnostic
422 _sar_source_position( id_frame ),
423 diag_tag_text( sym_k_proc_def_entry ),
424 id_frame->value.az_keyword_entry->at_name );
432 (sym_name_entry_type *) id_frame->value.az_symbol_entry;
435 ** If the name entry already has no object linked from it, we are
436 ** referencing an undefined object.
439 symbol_entry = name_entry->az_object;
441 if (symbol_entry == NULL )
443 id_frame->b_flags |= sym_m_forward_ref;
447 ** If the name entry has the wrong type of object, this is also
451 if (symbol_entry->header.b_tag != tag )
453 diag_issue_diagnostic
455 _sar_source_position( id_frame ),
456 diag_tag_text( tag ),
457 diag_tag_text( symbol_entry->header.b_tag ) );