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[] = "$TOG: UilSarMod.c /main/13 1997/03/12 15:21:36 dbl $"
40 * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
46 ** User Interface Language Compiler (UIL)
50 ** This module contain the routines for processing the module construct.
72 ** DEFINE and MACRO DEFINITIONS
80 ** EXTERNAL VARIABLE DECLARATIONS
84 extern yystype yylval;
89 ** GLOBAL VARIABLE DECLARATIONS
93 externaldef(uil_comp_glbl) src_source_record_type
94 *src_az_module_source_record;
95 externaldef(uil_comp_glbl) unsigned short int
96 *uil_urm_variant = NULL;
97 externaldef(uil_comp_glbl) unsigned short int
98 *uil_arg_compr = NULL;
99 externaldef(uil_comp_glbl) unsigned short int
100 *uil_reas_compr = NULL;
101 externaldef(uil_comp_glbl) unsigned short int
102 *uil_widget_compr = NULL;
103 externaldef(uil_comp_glbl) unsigned short int
104 *uil_child_compr = NULL;
108 ** OWN VARIABLE DECLARATIONS
112 unsigned int module_clauses;
114 #define m_version_clause (1<<0)
115 #define m_names_clause (1<<1)
116 #define m_charset_clause (1<<2)
117 #define m_objects_clause (1<<3)
119 #define m_after_names (m_charset_clause)
124 ** FUNCTIONAL DESCRIPTION:
126 ** This function initializes all static data structure for the semantic
129 ** FORMAL PARAMETERS:
147 ** global variables are initialized
152 void sar_initialize ()
155 int i; /* loop index */
157 /* BEGIN OSF Fix CR 5443 */
158 /* Initialize uil_sym_default_charset based on XmFALLBACK_CHARSET */
159 if (strcmp(XmFALLBACK_CHARSET, "ISO8859-1") != 0) /* Most common case. */
160 for (i = 0; i < (int)charset_lang_table_max; i++)
161 if (strcmp(XmFALLBACK_CHARSET, charset_lang_names_table[i]) == 0)
163 uil_sym_default_charset = charset_lang_codes_table[i];
166 /* END OSF Fix CR 5443 */
169 * Allocate vectors for the variant and usage vectors if they are NULL,
171 if ( uil_urm_variant == NULL )
172 uil_urm_variant = (unsigned short int *)
173 XtMalloc(sizeof(unsigned short int)*(uil_max_object+1));
174 if ( uil_arg_compr == NULL )
175 uil_arg_compr = (unsigned short int *)
176 XtMalloc(sizeof(unsigned short int)*(uil_max_arg+1));
177 if ( uil_reas_compr == NULL )
178 uil_reas_compr = (unsigned short int *)
179 XtMalloc(sizeof(unsigned short int)*(uil_max_reason+1));
180 if ( uil_widget_compr == NULL )
181 uil_widget_compr = (unsigned short int *)
182 XtMalloc(sizeof(unsigned short int)*(uil_max_object+1));
183 if ( uil_child_compr == NULL )
184 uil_child_compr = (unsigned short int *)
185 XtMalloc(sizeof(unsigned short int)*(uil_max_child+1));
187 ** Loop throught the array of object variants and set them all to NULL.
189 for (i = 0; i<uil_max_object+1; i++)
190 uil_urm_variant[i] = 0;
193 ** Initialize all compression vectors
195 for ( i=0 ; i<uil_max_arg+1 ; i++ )
196 uil_arg_compr[i] = 0;
197 for ( i=0 ; i<uil_max_reason+1 ; i++ )
198 uil_reas_compr[i] = 0;
199 for ( i=0 ; i<uil_max_object+1 ; i++ )
200 uil_widget_compr[i] = 0;
201 for ( i=0 ; i<uil_max_child+1 ; i++ )
202 uil_child_compr[i] = 0;
208 ** FUNCTIONAL DESCRIPTION:
210 ** This function creates the root entry node for the compilation.
211 ** The "root" entry is the root node of the symbol tree and is
212 ** what's passed back to the caller of the compiler.
214 ** FORMAL PARAMETERS:
216 ** root_frame ptr to root frame that will remain on the stack
217 ** throughout the compilation
225 ** sym_az_root_entry global pointer used thoughout the compilation
226 ** sym_az_curent_section_entry global pointer used thoughout the compilation
227 ** src_az_first_source_record global pointer to the source record list
240 void sar_create_root (root_frame)
246 ** Allocate the symbol nodes
249 sym_az_root_entry = (sym_root_entry_type *)
250 sem_allocate_node (sym_k_root_entry, sym_k_root_entry_size);
253 ** Create a place holder entry (tail) and change the "current" section list to it.
256 sym_az_current_section_entry = (sym_section_entry_type *) sem_allocate_node
257 ( sym_k_section_entry, sym_k_section_entry_size );
259 sym_az_current_section_entry->header.b_type = sym_k_section_tail;
261 sym_az_root_entry->sections = sym_az_current_section_entry;
262 sym_az_root_entry->src_record_list = src_az_first_source_record;
265 ** Save the file name and the expanded version of it.
268 strcpy (sym_az_root_entry->file_name, Uil_cmd_z_command.ac_source_file);
269 strcpy (sym_az_root_entry->full_file_name, src_az_source_file_table[0]->expanded_name);
272 ** Save the symbol node in the root frame.
275 root_frame->b_tag = sar_k_root_frame;
276 root_frame->b_type = sym_k_root_entry;
277 root_frame->value.az_symbol_entry = (sym_entry_type *)sym_az_root_entry;
284 ** FUNCTIONAL DESCRIPTION:
286 ** This function create the module entry symbol node for the compilation.
288 ** FORMAL PARAMETERS:
290 ** target_frame ptr to module frame that will remain on the stack
291 ** throughout the compilation
292 ** id_frame ptr to token frame for the module name
296 ** sym_az_root_entry global that points to the root entry
300 ** sym_az_module_entry global that points to module entry
308 ** set second line of the listing title
313 void sar_create_module(target_frame, id_frame, module_frame)
315 yystype *target_frame;
317 yystype *module_frame;
320 sym_name_entry_type *name_entry;
323 ** Call standard routine to check name entry for id_frame.
324 ** This routine handles font name, color names, etc used as ids
327 name_entry = (sym_name_entry_type *) sem_dcl_name( id_frame );
330 ** Allocate the module entry and fill it in
333 sym_az_module_entry = (sym_module_entry_type *)
334 sem_allocate_node (sym_k_module_entry, sym_k_module_entry_size);
335 sym_az_module_entry->obj_header.az_name = name_entry;
336 _sar_save_source_pos (&sym_az_module_entry->header, module_frame);
338 /* preserve module header comments */
339 sar_assoc_comment ((sym_obj_entry_type *)sym_az_module_entry);
342 ** Hang the module entry off the root entry
345 sym_az_root_entry->module_hdr = sym_az_module_entry;
348 ** Have name entry point to the module entry too. This stops the
349 ** name from being reused to name another construct.
352 name_entry->az_object = (sym_entry_type *) sym_az_module_entry;
355 ** Save the source information about module name identifier
358 _sar_save_source_info ( &name_entry->header , module_frame , id_frame );
361 ** Set up target frame
364 target_frame->b_tag = sar_k_module_frame;
367 ** Set up listing title
370 if (Uil_cmd_z_command.v_listing_file)
371 sprintf(Uil_lst_c_title2,
373 name_entry->c_text );
376 ** Set mask to no clauses seen
384 ** FUNCTIONAL DESCRIPTION:
386 ** This function sets a version string for the module.
388 ** FORMAL PARAMETERS:
390 ** value_frame ptr to value frame for version string
398 ** sym_az_module_entry global that point to module entry
406 ** set up second line of the listing title
411 void sar_process_module_version (value_frame, start_frame)
413 yystype *value_frame;
414 yystype *start_frame;
417 sym_value_entry_type *value_entry;
419 _assert( value_frame->b_tag == sar_k_value_frame, "value frame missing" );
421 if ((module_clauses & m_version_clause) != 0)
422 diag_issue_diagnostic
424 _sar_source_position( value_frame ),
425 "UIL", "module", "version", "clause"
429 ** FORWARD REFERENCING OF VERSION NO LONGER ALLOWED
430 ** If it's not a forward reference, verify its length and stick a pointer
431 ** to the value node of the version in the module entry.
434 if ((value_frame->b_flags & sym_m_forward_ref) != 0)
435 diag_issue_diagnostic(d_illegal_forward_ref,
436 _sar_source_position(value_frame),
442 value_entry = (sym_value_entry_type *)
443 value_frame->value.az_symbol_entry;
445 if (value_entry->w_length > 31)
447 diag_issue_diagnostic
449 _sar_source_position( value_frame ),
454 value_entry->w_length = 31;
457 sym_az_module_entry->az_version = value_entry;
464 _sar_save_source_info ( &sym_az_module_entry->az_version->header , start_frame , value_frame);
467 ** Set up listing title
470 if (Uil_cmd_z_command.v_listing_file)
471 sprintf(Uil_lst_c_title2,
472 "Module: %s \t Version: %s",
473 sym_az_module_entry->obj_header.az_name->c_text,
474 value_entry->value.c_value );
476 module_clauses |= m_version_clause;
481 ** FUNCTIONAL DESCRIPTION:
483 ** This function sets the case sensitivity of names for the module.
485 ** FORMAL PARAMETERS:
487 ** token_frame ptr to token frame for keyword sensitive or insensitive
491 ** sym_az_module_entry global which points to module entry
495 ** uil_v_case_sensitive global which control case sensitivity of names
508 void sar_process_module_sensitivity (token_frame, start_frame)
510 yystype *token_frame;
511 yystype *start_frame;
514 _assert( token_frame->b_tag == sar_k_token_frame, "token frame missing" );
516 if ((module_clauses & m_names_clause) != 0)
517 diag_issue_diagnostic
519 _sar_source_position( token_frame ),
520 "UIL", "module", "names", "clause"
523 if ((module_clauses & m_after_names) != 0)
524 diag_issue_diagnostic
526 _sar_source_position( token_frame )
529 uil_v_case_sensitive = (token_frame->b_type == CASE_SENSITIVE);
531 sym_az_module_entry->az_case_sense = (sym_value_entry_type *)
532 sem_allocate_node (sym_k_value_entry, sym_k_value_entry_size);
534 sym_az_module_entry->az_case_sense->header.b_type = uil_v_case_sensitive;
540 _sar_save_source_info ( &sym_az_module_entry->az_case_sense->header , start_frame , token_frame);
542 /* let the keyword table know of the sensitivity change */
548 ** The default for name sensitivity is SENSITIVE.
549 ** At the point that this semantic routine is called, the only valid
550 ** name seen so far is the module name.
553 module_clauses |= m_names_clause;
558 ** FUNCTIONAL DESCRIPTION:
560 ** This function sets the default charset for the module.
562 ** FORMAL PARAMETERS:
564 ** token_frame ptr to token frame for charset
568 ** sym_az_module_entry global pointer to the module entry
572 ** Uil_lex_l_user_default_charset
573 ** Uil_lex_az_charset_entry
586 void sar_process_module_charset(token_frame , start_frame)
588 yystype *token_frame;
589 yystype *start_frame;
592 sym_value_entry_type *value_entry;
594 _assert( (token_frame->b_tag == sar_k_token_frame) ||
595 (token_frame->b_tag == sar_k_value_frame), "token or value frame missing" );
597 if ((module_clauses & m_charset_clause) != 0)
598 diag_issue_diagnostic
600 _sar_source_position( token_frame ),
601 "UIL", "module", "character_set", "clause"
605 ** There are two different ways that the charset info may be specified.
606 ** If the charset_frame is a token frame, then we can just grab the
607 ** token class and map it into a charset value. If it is a value frame
608 ** the it is the result of the CHARACTER_SET function and is a string
609 ** value representing the character set.
611 switch (token_frame->b_tag)
613 case sar_k_token_frame:
615 key_keytable_entry_type *az_keyword_entry;
616 az_keyword_entry = token_frame->value.az_keyword_entry;
618 Uil_lex_l_user_default_charset = az_keyword_entry->b_subclass;
620 value_entry = sem_create_value_entry (
621 token_frame->value.az_keyword_entry->at_name,
622 token_frame->value.az_keyword_entry->b_length, sym_k_char_8_value );
626 case sar_k_value_frame:
628 Uil_lex_l_user_default_charset = lex_k_userdefined_charset;
629 Uil_lex_az_charset_entry = (sym_value_entry_type *)token_frame->value.az_symbol_entry;
630 value_entry = (sym_value_entry_type *)token_frame->value.az_symbol_entry;
635 /* If charset specified for module, then localized strings not allowed */
636 Uil_lex_l_localized = FALSE;
638 module_clauses |= m_charset_clause;
639 sym_az_module_entry->az_character_set = value_entry;
645 _sar_save_source_info ( &value_entry->header , start_frame , token_frame);
651 ** FUNCTIONAL DESCRIPTION:
653 ** This function saves the source record for the module header
654 ** for possible later use in the machine code listing.
656 ** FORMAL PARAMETERS:
662 ** yylval Current token information from the lexical analyzer
666 ** src_az_module_source_record source record for the module header
679 void sar_save_module_source ()
683 src_az_module_source_record = yylval.az_source_record;
690 ** FUNCTIONAL DESCRIPTION:
692 ** This routine creates and saves a default object specification
693 ** for the module entry itself.
695 ** FORMAL PARAMETERS:
697 ** object_frame ptr to token frame for "OBJECT"
705 ** sym_az_module_entry global pointer to the module entry
718 void sar_make_def_obj (object_frame)
720 yystype *object_frame;
723 sym_def_obj_entry_type *def_obj_entry;
726 * Make def_obj entry and link into the chain headed in the module
728 def_obj_entry = (sym_def_obj_entry_type *) sem_allocate_node
729 (sym_k_def_obj_entry, sym_k_def_obj_entry_size);
730 _sar_save_source_pos (&def_obj_entry->header, object_frame);
731 def_obj_entry->next = sym_az_module_entry->az_def_obj;
732 sym_az_module_entry->az_def_obj = def_obj_entry;
739 ** FUNCTIONAL DESCRIPTION:
741 ** This function sets the default variants for objects which
742 ** are defined in the module.
744 ** FORMAL PARAMETERS:
746 ** type_frame ptr to token frame for object type
747 ** variant_frame ptr to token frame for variant
751 ** uil_gadget_variants table to see if the gadget variant is supported
752 ** uil_urm_variant table to see if the object type has been
753 ** specified previously
754 ** sym_az_module_entry global pointing to the module entry
758 ** uil_urm_variant table to contain the default variant for this
772 void sar_process_module_variant (obj_type_frame, variant_frame)
774 yystype *obj_type_frame;
775 yystype *variant_frame;
779 unsigned int obj_type, obj_variant;
780 yystype *source_frame;
781 sym_def_obj_entry_type *def_obj_entry;
783 source_frame = & yylval;
785 obj_type = obj_type_frame->value.az_keyword_entry->b_subclass;
786 obj_variant = variant_frame->b_type;
788 /* See if this object type has been specified before. */
790 if ( uil_urm_variant[obj_type] != 0 )
792 diag_issue_diagnostic
794 _sar_source_position ( source_frame ),
795 diag_object_text (obj_type),
796 diag_tag_text (obj_variant),
797 diag_tag_text (sym_k_module_entry),
801 /* See if this object type supports gadgets. */
803 if ( obj_variant == sym_k_gadget_entry )
805 if ( uil_gadget_variants[obj_type] == 0 )
807 diag_issue_diagnostic
809 _sar_source_position ( source_frame ),
810 diag_object_text (obj_type),
811 diag_object_text (obj_type) );
812 obj_variant = sym_k_widget_entry;
816 /* Save the default variant information */
817 uil_urm_variant[obj_type] = obj_variant;
820 ** get the latest def_obj entry and fill in
822 def_obj_entry = sym_az_module_entry->az_def_obj->next;
823 def_obj_entry->b_object_info = obj_type;
824 def_obj_entry->b_variant_info = obj_variant;
830 ** FUNCTIONAL DESCRIPTION:
832 ** This procedure saves source info for the various sections declaration
833 ** lists in the Uil file (i.e. value, identifier, procedure, object, and
836 ** FORMAL PARAMETERS:
838 ** header_frame ptr to token frame for the section declaration
839 ** section_type integer describing what section this is
847 ** sym_az_root_entry global pointer to the root entry
860 void sar_save_section_source (header_frame, section_type)
862 yystype *header_frame;
866 sym_section_entry_type *section_entry;
868 section_entry = (sym_section_entry_type *) sem_allocate_node
869 ( sym_k_section_entry, sym_k_section_entry_size );
871 section_entry->header.b_type = section_type;
877 _sar_save_source_info ( §ion_entry->header , header_frame, header_frame);
880 ** Link this section into the current section list.
883 section_entry->next = (sym_entry_type *) sym_az_current_section_entry;
884 section_entry->prev_section = sym_az_current_section_entry->prev_section;
885 sym_az_current_section_entry = section_entry;