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