explicitimports.icl 41 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
implementation module explicitimports
2
// compile with reuse unique nodes option
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
3
4
5

import StdEnv

6
import syntax, typesupport, parse, checksupport, utilities, checktypes, transform, predef,
7
		compilerSwitches//, RWSDebug
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
8

9
10
11
12
13
cUndef :== (-1)
implies a b :== not a || b

:: ImportNrAndIdents =
	{	ini_symbol_nr	:: !Index
14
	,	ini_imp_decl	:: !ImportDeclaration
15
16
17
18
19
20
21
	}

:: SolvedImports =
	{	si_explicit	:: ![([Declaration], Position)]
	,	si_implicit	:: ![(Index, Position)]	// module indices
	}

22
markExplImpSymbols :: !Int !*(!*{!*{!u:ExplImpInfo}}, !*SymbolTable) -> (!.[Ident],!(!{!{!u:ExplImpInfo}},!.SymbolTable))
Martin Wierich's avatar
Martin Wierich committed
23
markExplImpSymbols component_nr (expl_imp_info, cs_symbol_table)
24
25
	#! nr_of_expl_imp_symbols = size expl_imp_info.[component_nr]
	   (new_symbols, expl_imp_info, cs_symbol_table) = iFoldSt (mark_symbol component_nr) 0 nr_of_expl_imp_symbols ([], expl_imp_info, cs_symbol_table)
Martin Wierich's avatar
Martin Wierich committed
26
27
	= (new_symbols, (expl_imp_info, cs_symbol_table))
  where
28
29
30
31
	mark_symbol component_nr i (changed_symbols_accu, expl_imp_info, cs_symbol_table)
		# (eii_ident, expl_imp_info) = do_a_lot_just_to_read_an_array component_nr i expl_imp_info
		  (ste, cs_symbol_table) = readPtr eii_ident.id_info cs_symbol_table
		  cai = { cai_component_nr = component_nr, cai_index = i }
Martin Wierich's avatar
Martin Wierich committed
32
33
		= case ste.ste_kind of
			STE_ExplImpComponentNrs component_nrs _
34
35
				# new_ste_kind = STE_ExplImpComponentNrs [cai:component_nrs] []
				  cs_symbol_table = writePtr eii_ident.id_info { ste & ste_kind = new_ste_kind } cs_symbol_table
Martin Wierich's avatar
Martin Wierich committed
36
37
				-> (changed_symbols_accu, expl_imp_info, cs_symbol_table)
			_
38
				# new_ste = { ste & ste_kind = STE_ExplImpComponentNrs [cai] [], ste_previous = ste }
Martin Wierich's avatar
Martin Wierich committed
39
40
41
				-> ([eii_ident:changed_symbols_accu], expl_imp_info, writePtr eii_ident.id_info new_ste cs_symbol_table)

	do_a_lot_just_to_read_an_array component_nr i expl_imp_info
42
43
		# (eii, expl_imp_info) = replaceTwoDimArrElt component_nr i TemporarilyFetchedAway expl_imp_info
		  (eii_ident, eii) = get_eei_ident eii
Martin Wierich's avatar
Martin Wierich committed
44
		= (eii_ident, { expl_imp_info & [component_nr, i] = eii })
45

46
updateExplImpForMarkedSymbol :: !Index !Declaration !SymbolTableEntry !u:{#DclModule} !{!{!*ExplImpInfo}} !*SymbolTable
Martin Wierich's avatar
Martin Wierich committed
47
		-> (!u:{#DclModule}, !{!{!.ExplImpInfo}}, !.SymbolTable)
48
49
updateExplImpForMarkedSymbol mod_index decl {ste_kind=STE_ExplImpComponentNrs component_numbers inst_indices} dcl_modules expl_imp_infos cs_symbol_table
	= foldSt (addExplImpInfo mod_index decl inst_indices) component_numbers (dcl_modules, expl_imp_infos, cs_symbol_table)
Martin Wierich's avatar
Martin Wierich committed
50
51
52
53
54
55
56
57
58
59
updateExplImpForMarkedSymbol _ _ entry dcl_modules expl_imp_infos cs_symbol_table
	= (dcl_modules, expl_imp_infos, cs_symbol_table)

addExplImpInfo :: !Index Declaration ![Declaration] !ComponentNrAndIndex !(!u:{#DclModule}, !{!{!*ExplImpInfo}}, !v:SymbolTable)
			-> (!u:{#DclModule}, !{!{!.ExplImpInfo}}, !v:SymbolTable)
addExplImpInfo mod_index decl instances { cai_component_nr, cai_index } (dcl_modules, expl_imp_infos, cs_symbol_table)
	# (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_infos)
			= replaceTwoDimArrElt cai_component_nr cai_index TemporarilyFetchedAway expl_imp_infos
	  (di_belonging, dcl_modules, cs_symbol_table)
	  		= get_belonging_symbol_nrs decl dcl_modules cs_symbol_table
60
61
	  di = { di_decl = decl, di_instances = instances, di_belonging = di_belonging }
	  new_expl_imp_info = ExplImpInfo eii_ident (ikhInsert` False mod_index di eii_declaring_modules)
Martin Wierich's avatar
Martin Wierich committed
62
63
64
	= (dcl_modules, { expl_imp_infos & [cai_component_nr,cai_index] = new_expl_imp_info }, cs_symbol_table)
  where
	get_belonging_symbol_nrs :: !Declaration !v:{#DclModule} !u:(Heap SymbolTableEntry) 
65
							 -> (!.NumberSet,!v:{#DclModule},!u: Heap SymbolTableEntry)
Martin Wierich's avatar
Martin Wierich committed
66
	get_belonging_symbol_nrs decl dcl_modules cs_symbol_table
67
68
		# (all_belonging_symbols, dcl_modules) = getBelongingSymbols decl dcl_modules
		  nr_of_belongs = nrOfBelongingSymbols all_belonging_symbols
Martin Wierich's avatar
Martin Wierich committed
69
70
71
72
73
		  (_, belonging_bitvect, cs_symbol_table)
				= foldlBelongingSymbols set_bit all_belonging_symbols (0, bitvectCreate nr_of_belongs, cs_symbol_table)
		= (bitvectToNumberSet belonging_bitvect, dcl_modules, cs_symbol_table)

	set_bit {id_info} (bit_nr, bitvect, cs_symbol_table)
74
		# ({ste_kind}, cs_symbol_table) = readPtr id_info cs_symbol_table
Martin Wierich's avatar
Martin Wierich committed
75
76
77
		= ( bit_nr+1
		  , case ste_kind of
			 	STE_Empty -> bitvect
78
			 	STE_BelongingSymbolForExportedSymbol -> bitvect
Martin Wierich's avatar
Martin Wierich committed
79
80
81
82
83
84
85
86
87
				_ -> bitvectSet bit_nr bitvect
		  , cs_symbol_table
		  )

foldlBelongingSymbols f bs st
	:== case bs of
			BS_Constructors constructors
				-> foldSt (\{ds_ident} st -> f ds_ident st) constructors st 
			BS_Fields fields
88
				-> foldlArraySt (\{fs_ident} st -> f fs_ident st) fields st 
Martin Wierich's avatar
Martin Wierich committed
89
90
91
92
			BS_Members members
				-> foldlArraySt (\{ds_ident} st -> f ds_ident st) members st 
			BS_Nothing
				-> st
93
94
95
96
97
98
99
100
101
102
103
104
/*
imp_decl_to_string (ID_Function {ii_ident={id_name}}) = "ID_Function "+++toString id_name
imp_decl_to_string (ID_Class {ii_ident={id_name}} _) = "ID_Class "+++toString id_name
imp_decl_to_string (ID_Type {ii_ident={id_name}} _) = "ID_Type "+++toString id_name
imp_decl_to_string (ID_Record {ii_ident={id_name}} _) = "ID_Record "+++toString id_name
imp_decl_to_string (ID_Instance {ii_ident={id_name}} _ _ ) = "ID_Instance "+++toString id_name
imp_decl_to_string (ID_OldSyntax idents) = "ID_OldSyntax "+++idents_to_string idents
	where
		idents_to_string [] = ""
		idents_to_string [{id_name}] = toString id_name
		idents_to_string [{id_name}:l] = toString id_name+++","+++idents_to_string l
*/
Martin Wierich's avatar
Martin Wierich committed
105

106
107
108
109
110
111
getBelongingSymbolsFromID :: !ImportDeclaration -> Optional [ImportedIdent]
getBelongingSymbolsFromID (ID_Class _ x)						= x
getBelongingSymbolsFromID (ID_Type _ x)						= x
getBelongingSymbolsFromID (ID_Record _ x)						= x
getBelongingSymbolsFromID _									= No

112
solveExplicitImports :: !(IntKeyHashtable [(Int,Position,[ImportNrAndIdents])]) !{#Int} !Index 
113
114
								!*(!v:{#DclModule},!*{#Int},!{!*ExplImpInfo},!*CheckState)
			-> (!.SolvedImports,! (!v:{#DclModule},!.{#Int},!{!.ExplImpInfo},!.CheckState))
115
solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod (dcl_modules, visited_modules, expl_imp_info, cs)
116
117
118
	# import_indices = ikhSearch` importing_mod expl_imp_indices_ikh
	  expl_imp_indices = [ imports \\ imports=:(_, _, [_:_]) <- import_indices ]
	  impl_imports = [ (mod_index, position) \\ imports=:(mod_index, position, []) <- import_indices ]
119
120
121
122
	  (expl_imports, state)
	  		= mapSt (solve_expl_imp_from_module expl_imp_indices_ikh modules_in_component_set importing_mod)
					expl_imp_indices (dcl_modules, visited_modules, expl_imp_info, cs)
	= ({ si_explicit = expl_imports, si_implicit = impl_imports }, state)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
123
  where
124
125
	solve_expl_imp_from_module expl_imp_indices_ikh modules_in_component_set importing_mod
			(imported_mod, position, imported_symbols) (dcl_modules, visited_modules, expl_imp_info, cs)
Martin Wierich's avatar
Martin Wierich committed
126
		# (successes, (decl_accu, unsolved_belonging, visited_modules, expl_imp_info))
127
128
				= mapSt (search_expl_imp_symbol expl_imp_indices_ikh modules_in_component_set importing_mod imported_mod)
						imported_symbols 
Martin Wierich's avatar
Martin Wierich committed
129
						([], [], visited_modules, expl_imp_info)
130
		  (expl_imp_info, cs_error)
131
		  		= check_singles position successes imported_symbols
132
		  				(expl_imp_info, cs.cs_error)
Martin Wierich's avatar
Martin Wierich committed
133
		  (decl_accu, dcl_modules, visited_modules, expl_imp_info, cs)
134
		  		= foldSt (solve_belonging position expl_imp_indices_ikh modules_in_component_set importing_mod)
Martin Wierich's avatar
Martin Wierich committed
135
136
137
		  				unsolved_belonging
		  				(decl_accu, dcl_modules, visited_modules, expl_imp_info, { cs & cs_error = cs_error }) 
		= ((decl_accu, position), (dcl_modules, visited_modules, expl_imp_info, cs))
138
139

	solve_belonging position expl_imp_indices_ikh modules_in_component_set importing_mod
140
			(decl, {ini_symbol_nr, ini_imp_decl}, imported_mod)
141
			(decls_accu, dcl_modules, visited_modules, expl_imp_info, cs=:{cs_error, cs_symbol_table})
142
143
144
		# (Yes belongs)
				= getBelongingSymbolsFromID ini_imp_decl
		  (all_belongs, dcl_modules)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
				= get_all_belongs decl dcl_modules
		  (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_info)
				= replace expl_imp_info ini_symbol_nr TemporarilyFetchedAway
		  (need_all, belongs_set, cs_error, cs_symbol_table)
		  		= case belongs of
		  			[]
		  				// an import like ::A(..) or ::A{..} or class c{..} 
		  				-> (False, [(belong_nr, belong_ident) \\ belong_nr<-[0..] & belong_ident<-all_belongs],
		  						cs_error, cs_symbol_table)
		  			_
		  				// an import like ::A(C1, C2) or ::A{f1} or class c{m1} 
		  				# (nr_of_belongs, cs_symbol_table)
			  					= foldSt numerate_belongs all_belongs (0, cs_symbol_table)
						  belongs_bitvect
						  		= bitvectCreate nr_of_belongs
						  (belongs_set, (cs_error, cs_symbol_table))
						  		= mapFilterYesSt (get_opt_nr_and_ident position eii_ident) belongs (cs_error, cs_symbol_table)
			  			  cs_symbol_table
			  			  		= foldSt restoreHeap all_belongs cs_symbol_table
						-> (True, belongs_set, cs_error, cs_symbol_table)
		  (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
				= foldSt 
					(search_belonging need_all position eii_ident decl expl_imp_indices_ikh modules_in_component_set
							imported_mod ini_symbol_nr importing_mod)
					belongs_set (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
		  expl_imp_info
		  		= { expl_imp_info & [ini_symbol_nr] = ExplImpInfo eii_ident eii_declaring_modules }
		= (decls_accu, dcl_modules, visited_modules, expl_imp_info, { cs & cs_error = cs_error, cs_symbol_table = cs_symbol_table })
173
		
174
175
176
177
178
	search_belonging need_all position eii_ident decl expl_imp_indices_ikh modules_in_component_set imported_mod ini_symbol_nr importing_mod
						(belong_nr, belong_ident) (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
		# (found, path, eii_declaring_modules, visited_modules)
				=  depth_first_search expl_imp_indices_ikh modules_in_component_set
						imported_mod ini_symbol_nr belong_nr belong_ident [importing_mod]
Martin Wierich's avatar
Martin Wierich committed
179
						eii_declaring_modules (bitvectResetAll visited_modules)
180
181
		= case found of
			Yes _
182
183
				# eii_declaring_modules = foldSt (store_belonging belong_nr ini_symbol_nr) path eii_declaring_modules
				  (belong_decl, dcl_modules) = get_nth_belonging_decl position belong_nr decl dcl_modules
184
185
186
187
188
				-> ([belong_decl:decls_accu], dcl_modules, eii_declaring_modules, visited_modules, cs_error)
			_
				# cs_error
					= case need_all of
						True
189
190
							# cs_error = pushErrorAdmin (newPosition import_ident position) cs_error
							  cs_error = checkError belong_ident ("of "+++eii_ident.id_name+++" not exported by the specified module") cs_error
191
192
193
194
195
196
197
198
199
200
201
202
203
204
							-> popErrorAdmin cs_error
						_
							-> cs_error
				-> (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)

	store_belonging belong_nr ini_symbol_nr mod_index eii_declaring_modules
		# (Yes di=:{di_belonging}, eii_declaring_modules)
				= ikhUSearch mod_index eii_declaring_modules
		  (new, eii_declaring_modules)
		  		= ikhInsert True mod_index { di & di_belonging = addNr belong_nr di_belonging } eii_declaring_modules
		| new
			= abort "sanity check nr 2765 failed in module check"
		= eii_declaring_modules

205
206
	get_nth_belonging_decl position belong_nr decl=:(Declaration {decl_kind}) dcl_modules
		# (STE_Imported _ def_mod_index) = decl_kind
207
208
209
210
211
		  (belongin_symbols, dcl_modules)
				= getBelongingSymbols decl dcl_modules
		= case belongin_symbols of
			BS_Constructors constructors
				# {ds_ident, ds_index} = constructors!!belong_nr
212
213
214
				-> (Declaration { decl_ident = ds_ident, decl_pos = position, 
						decl_kind = STE_Imported STE_Constructor def_mod_index,
						decl_index = ds_index }, dcl_modules)
215
			BS_Fields rt_fields
216
				# {fs_ident, fs_index} = rt_fields.[belong_nr]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
217
				  ({sd_ident}, dcl_modules)
218
						= dcl_modules![def_mod_index].dcl_common.com_selector_defs.[fs_index]
219
				-> (Declaration { decl_ident = fs_ident, decl_pos = position, 
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
220
						decl_kind = STE_Imported (STE_Field sd_ident) def_mod_index,
221
						decl_index = fs_index }, dcl_modules)
222
223
			BS_Members class_members
				# {ds_ident, ds_index} = class_members.[belong_nr]
224
225
226
				-> (Declaration { decl_ident = ds_ident, decl_pos = position,
						 decl_kind = STE_Imported STE_Member def_mod_index,
						decl_index = ds_index }, dcl_modules)
227

228
	get_all_belongs decl=:(Declaration {decl_kind,decl_index}) dcl_modules
229
230
231
232
233
234
		# (belonging_symbols, dcl_modules)
				= getBelongingSymbols decl dcl_modules
		= case belonging_symbols of
			BS_Constructors constructors
				-> ([ds_ident \\ {ds_ident}<-constructors], dcl_modules)
			BS_Fields rt_fields
235
				-> ([fs_ident \\ {fs_ident}<-:rt_fields], dcl_modules)
236
			BS_Members class_members
237
				# (STE_Imported _ def_mod_index) = decl_kind
238
				  ({class_members}, dcl_modules)
239
						= dcl_modules![def_mod_index].dcl_common.com_class_defs.[decl_index]
240
241
242
243
244
				-> ([ds_ident \\ {ds_ident}<-:class_members], dcl_modules)
			BS_Nothing
				-> ([], dcl_modules)

	numerate_belongs {id_info} (i, cs_symbol_table)
245
246
		# (ste, cs_symbol_table) = readPtr id_info cs_symbol_table
		  new_ste = { ste & ste_kind = STE_BelongingSymbol i, ste_previous = ste }
247
		= (i+1, writePtr id_info new_ste cs_symbol_table)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
248
	
249
	get_opt_nr_and_ident position eii_ident {ii_ident=ii_ident=:{id_info}} (cs_error, cs_symbol_table)
250
		# ({ste_kind}, cs_symbol_table) = readPtr id_info cs_symbol_table
251
		= case ste_kind of
252
253
254
			STE_BelongingSymbol i
				-> (Yes (i, ii_ident), (cs_error, cs_symbol_table))
			_
255
256
				# cs_error = pushErrorAdmin (newPosition import_ident position) cs_error
				  cs_error = checkError ii_ident ("does not belong to "+++eii_ident.id_name) cs_error 
257
				-> (No, (popErrorAdmin cs_error, cs_symbol_table))
258
		
259
	search_expl_imp_symbol expl_imp_indices_ikh modules_in_component_set importing_mod imported_mod
Martin Wierich's avatar
Martin Wierich committed
260
			ini=:{ini_symbol_nr} (decls_accu, belonging_accu, visited_modules, expl_imp_info)
261
262
263
264
265
		# (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_info)
				= replace expl_imp_info ini_symbol_nr TemporarilyFetchedAway
		  (opt_decl, path, eii_declaring_modules, visited_modules)
				= depth_first_search expl_imp_indices_ikh modules_in_component_set imported_mod
						ini_symbol_nr cUndef stupid_ident [importing_mod]
Martin Wierich's avatar
Martin Wierich committed
266
						eii_declaring_modules (bitvectResetAll visited_modules)
267
		= case opt_decl of
Martin Wierich's avatar
Martin Wierich committed
268
			Yes di=:{di_decl, di_instances}
269
				| ( case di_decl of
Martin Wierich's avatar
Martin Wierich committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
			  			Declaration {decl_kind}
			  				-> case decl_kind of
			  					STE_Imported STE_Member _
			  						-> False
			  					STE_Member
			  						-> False
			  					_
			  						-> True
			  		)
					# new_eii_declaring_modules
					  		= foldSt (\mod_index eei_dm->ikhInsert` False mod_index 
					  					{di_decl = di_decl, di_instances = [], di_belonging=EndNumbers} eei_dm)
					  				path eii_declaring_modules
					  new_belonging_accu
					  		= case getBelongingSymbolsFromID ini.ini_imp_decl of
					  			No
					  				-> belonging_accu
					  			Yes _
					  				-> [(di_decl, ini, imported_mod):belonging_accu]
289
					  new_eii = ExplImpInfo eii_ident new_eii_declaring_modules
Martin Wierich's avatar
Martin Wierich committed
290
291
292
293
					-> (True, ([di_decl:di_instances++decls_accu], new_belonging_accu, visited_modules,
								{ expl_imp_info & [ini_symbol_nr] = new_eii }))
				// otherwise GOTO next alternative
			_
294
				# eii = ExplImpInfo eii_ident eii_declaring_modules
Martin Wierich's avatar
Martin Wierich committed
295
				-> (False, (decls_accu, belonging_accu, visited_modules, { expl_imp_info & [ini_symbol_nr] = eii }))
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

	depth_first_search expl_imp_indices_ikh modules_in_component_set
			imported_mod imported_symbol belong_nr belong_ident path eii_declaring_modules visited_modules
//		| False--->("depth_first_search imported_mod", imported_mod, "imported_symbol", imported_symbol)
//			= undef
		# (search_result, eii_declaring_modules)
				= ikhUSearch imported_mod eii_declaring_modules
		= case search_result of
			yes_di=:(Yes di)
				| belong_nr==cUndef
					-> (yes_di, path, eii_declaring_modules, visited_modules)
				| inNumberSet belong_nr di.di_belonging
					-> (yes_di, path, eii_declaring_modules, visited_modules)
			_
				| not (bitvectSelect imported_mod modules_in_component_set)
					// the eii_declaring_modules is complete for modules that are outside
					// (=beneath) the actual component=> no need to search further
					-> (No, [], eii_declaring_modules, visited_modules)
				# imports_of_imported_mod
				  		= ikhSearch` imported_mod expl_imp_indices_ikh
				-> try_children imports_of_imported_mod expl_imp_indices_ikh 
						modules_in_component_set imported_symbol belong_nr belong_ident
						[imported_mod:path]
						eii_declaring_modules (bitvectSet imported_mod visited_modules)

	try_children [(imp_imp_mod, _, imp_imp_symbols):imports] expl_imp_indices_ikh
			modules_in_component_set imported_symbol belong_nr belong_ident path eii_declaring_modules visited_modules
		| bitvectSelect imp_imp_mod visited_modules
//			| False--->"visited" = undef
			= try_children imports expl_imp_indices_ikh modules_in_component_set imported_symbol
					belong_nr belong_ident path eii_declaring_modules visited_modules
		| not (isEmpty imp_imp_symbols)
			// follow the path trough an explicit import only if the symbol is listed there
329
			# (found, opt_belongs)
330
					= search_imported_symbol imported_symbol imp_imp_symbols
331
			| not (found && implies (belong_nr<>cUndef) (belong_ident_found belong_ident opt_belongs))
332
333
334
335
336
337
				= try_children imports expl_imp_indices_ikh modules_in_component_set imported_symbol
						belong_nr belong_ident path eii_declaring_modules visited_modules
			= continue imp_imp_mod imports expl_imp_indices_ikh modules_in_component_set imported_symbol
						belong_nr belong_ident path eii_declaring_modules visited_modules
		= continue imp_imp_mod imports expl_imp_indices_ikh modules_in_component_set imported_symbol
						belong_nr belong_ident path eii_declaring_modules visited_modules
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
338
	  where
339
340
341
342
343
344
345
346
347
348
349
		continue imp_imp_mod imports expl_imp_indices_ikh modules_in_component_set imported_symbol
							belong_nr belong_ident path eii_declaring_modules visited_modules
			# (opt_decl, path, eii_declaring_modules, visited_modules)
					= depth_first_search expl_imp_indices_ikh modules_in_component_set imp_imp_mod
							imported_symbol belong_nr belong_ident path eii_declaring_modules visited_modules
			= case opt_decl of
				Yes _
					-> (opt_decl, path, eii_declaring_modules, visited_modules)
				No
					-> try_children imports expl_imp_indices_ikh modules_in_component_set
							imported_symbol belong_nr belong_ident path eii_declaring_modules visited_modules
350
	
351
352
353
354
355
356
357
	try_children [] expl_imp_indices_ikh _ imported_symbol belong_nr belong_ident path
			eii_declaring_modules visited_modules
		= (No, [], eii_declaring_modules, visited_modules)

	search_imported_symbol :: !Int ![ImportNrAndIdents] -> (!Bool, !Optional [ImportedIdent])
	search_imported_symbol imported_symbol []
		= (False, No)
358
	search_imported_symbol imported_symbol [{ini_symbol_nr, ini_imp_decl}:t]
359
		| imported_symbol==ini_symbol_nr
360
			= (True, getBelongingSymbolsFromID ini_imp_decl)
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
		= search_imported_symbol imported_symbol t

	belong_ident_found :: !Ident !(Optional [ImportedIdent]) -> Bool
	belong_ident_found belong_ident No
		// like from m import ::T
		= False
	belong_ident_found belong_ident (Yes [])
		// like from m import ::T(..)
		= True 
	belong_ident_found belong_ident (Yes import_list)
		// like from m import ::T(C1,C2)
		= is_member belong_ident import_list

	is_member :: !Ident ![ImportedIdent] -> Bool
	is_member belong_ident []
		= False
	is_member belong_ident [{ii_ident}:t]
		| belong_ident==ii_ident
			= True
		= is_member belong_ident t

Martin Wierich's avatar
Martin Wierich committed
382
	check_singles position [False: t1] [imported_symbol: t2] (expl_imp_info, cs_error)
383
384
385
386
387
388
389
390
		# (expl_imp_info, cs_error)
				= give_error position imported_symbol (expl_imp_info, cs_error)
		= check_singles position t1 t2 (expl_imp_info, cs_error)
	check_singles position [_:t1] [_:t2] (expl_imp_info, cs_error)
		= check_singles position t1 t2 (expl_imp_info, cs_error)
	check_singles position [] [] (expl_imp_info, cs_error)
		= (expl_imp_info, cs_error)
		
391
	give_error position {ini_symbol_nr, ini_imp_decl} (expl_imp_info, cs_error)
392
393
394
395
396
		# (eii_ident, expl_imp_info)
				= do_a_lot_just_to_read_an_array_2 ini_symbol_nr expl_imp_info
		  cs_error
				= pushErrorAdmin (newPosition import_ident position) cs_error
		  cs_error
397
		  		= checkError eii_ident 
398
		  			("not exported as a "+++impDeclToNameSpaceString ini_imp_decl +++" by the specified module")
399
		  			cs_error
400
401
402
		= (expl_imp_info, popErrorAdmin cs_error)

	do_a_lot_just_to_read_an_array_2 i expl_imp_info
403
404
		# (eii, expl_imp_info) = replace expl_imp_info i TemporarilyFetchedAway
		  (eii_ident, eii) = get_eei_ident eii
405
406
		= (eii_ident, { expl_imp_info & [i] = eii })

407
408
409
410
411
412
	impDeclToNameSpaceString (ID_Function _)	= "function/macro"
	impDeclToNameSpaceString (ID_Class _ _)		= "class"
	impDeclToNameSpaceString (ID_Type _ _)		= "type"
	impDeclToNameSpaceString (ID_Record _ _)	= "type"
	impDeclToNameSpaceString (ID_Instance _ _ _)= "instance"

Martin Wierich's avatar
Martin Wierich committed
413
get_eei_ident (eii=:ExplImpInfo eii_ident _) = (eii_ident, eii)
414
	
415
416
417
:: CheckCompletenessState =
	{	ccs_dcl_modules				:: !.{#DclModule}
	,	ccs_icl_functions			:: !.{#FunDef}
418
	,	ccs_macro_defs :: !.{#.{#FunDef}}
419
	,	ccs_set_of_visited_icl_funs	:: !.{#Bool}		// ccs_set_of_visited_icl_funs.[i] <=> function nr i has been considered
420
	,	ccs_set_of_visited_macros	:: !.{#.{#Bool}}
421
422
423
424
425
	,	ccs_expr_heap				:: !.ExpressionHeap
	,	ccs_symbol_table			:: !.SymbolTable
	,	ccs_error					:: !.ErrorAdmin
	,	ccs_heap_changes_accu		:: ![SymbolPtr]
	}
426

427
:: CheckCompletenessStateBox = { box_ccs :: !.CheckCompletenessState }
428
429

:: CheckCompletenessInput =
430
431
	{	cci_import_position		:: !Position
	,	cci_main_dcl_module_n	:: !Int
432
	}
433

434
435
:: CheckCompletenessInputBox = { box_cci :: !CheckCompletenessInput }

436
437
438
checkExplicitImportCompleteness :: ![([Declaration], Position)] !*{#DclModule} !*{#FunDef} !*{#*{#FunDef}} !*ExpressionHeap !*CheckState
															-> (!.{#DclModule},!.{#FunDef},!*{#*{#FunDef}},!.ExpressionHeap,!.CheckState)
checkExplicitImportCompleteness dcls_explicit dcl_modules icl_functions macro_defs expr_heap cs=:{cs_symbol_table, cs_error}
439
	#! nr_icl_functions = size icl_functions
440
441
	#! n_dcl_modules = size dcl_modules
	#  box_ccs = { ccs_dcl_modules = dcl_modules, ccs_icl_functions = icl_functions, ccs_macro_defs=macro_defs,
442
	   			ccs_set_of_visited_icl_funs = createArray nr_icl_functions False,
443
	   			ccs_set_of_visited_macros = { {} \\ module_n<-[0..n_dcl_modules-1]},
444
445
				ccs_expr_heap = expr_heap, ccs_symbol_table = cs_symbol_table,
				ccs_error = cs_error, ccs_heap_changes_accu = [] }
446
447
	   main_dcl_module_n
	   		= cs.cs_x.x_main_dcl_module_n
Martin Wierich's avatar
Martin Wierich committed
448
449
450
451
452
//	   ccs = foldSt (checkCompleteness main_dcl_module_n) dcls_explicit { box_ccs = box_ccs }
	   ccs = foldSt (\(dcls, position) ccs
	   					-> foldSt (checkCompleteness main_dcl_module_n position) dcls ccs)
	   				dcls_explicit
	   				{ box_ccs = box_ccs }
453
	   { ccs_dcl_modules, ccs_icl_functions,ccs_macro_defs,ccs_expr_heap, ccs_symbol_table, ccs_error, ccs_heap_changes_accu } = ccs.box_ccs
454
455
456
	// repair heap contents
	   ccs_symbol_table = foldSt replace_ste_with_previous ccs_heap_changes_accu ccs_symbol_table
	   cs = { cs & cs_symbol_table = ccs_symbol_table, cs_error = ccs_error }
457
	= (ccs_dcl_modules, ccs_icl_functions,ccs_macro_defs, ccs_expr_heap, cs)
458
  where
Martin Wierich's avatar
Martin Wierich committed
459
	checkCompleteness :: !Int !Position !Declaration !*CheckCompletenessStateBox -> *CheckCompletenessStateBox
460
461
462
463
464
	checkCompleteness main_dcl_module_n import_position (Declaration {decl_ident, decl_index, decl_kind=STE_FunctionOrMacro _}) ccs 
		= checkCompletenessOfMacro decl_ident decl_index main_dcl_module_n import_position ccs
	checkCompleteness main_dcl_module_n import_position (Declaration {decl_ident, decl_index, decl_kind=STE_Imported (STE_FunctionOrMacro _) mod_index}) ccs 
		= checkCompletenessOfMacro decl_ident decl_index main_dcl_module_n import_position ccs
	checkCompleteness main_dcl_module_n import_position (Declaration {decl_ident, decl_index, decl_kind=STE_Imported expl_imp_kind mod_index}) ccs
465
		#! ({dcl_common,dcl_functions}, ccs) = ccs!box_ccs.ccs_dcl_modules.[mod_index]
466
		   cci = { box_cci = { cci_import_position = import_position, cci_main_dcl_module_n=main_dcl_module_n }}
467
468
469
470
471
		= continuation expl_imp_kind dcl_common dcl_functions cci ccs
	  where
		continuation :: !STE_Kind CommonDefs !{# FunType} !CheckCompletenessInputBox !*CheckCompletenessStateBox
					-> *CheckCompletenessStateBox
		continuation STE_Type dcl_common dcl_functions cci ccs
472
			= check_completeness dcl_common.com_type_defs.[decl_index] cci ccs
473
		continuation STE_Constructor dcl_common dcl_functions cci ccs
474
			= check_completeness dcl_common.com_cons_defs.[decl_index] cci ccs
475
		continuation (STE_Field _) dcl_common dcl_functions cci ccs
476
			= check_completeness dcl_common.com_selector_defs.[decl_index] cci ccs
477
		continuation STE_Class dcl_common dcl_functions cci ccs
478
			= check_completeness dcl_common.com_class_defs.[decl_index] cci ccs
479
		continuation STE_Member dcl_common dcl_functions cci ccs
480
			= check_completeness dcl_common.com_member_defs.[decl_index] cci ccs
481
		continuation STE_Instance dcl_common dcl_functions cci ccs
482
			= check_completeness dcl_common.com_instance_defs.[decl_index] cci ccs
483
		continuation STE_DclFunction dcl_common dcl_functions cci ccs
484
			= check_completeness dcl_functions.[decl_index] cci ccs
485
486
487
		continuation (STE_DclMacroOrLocalMacroFunction _) dcl_common dcl_functions cci ccs
			# (macro,ccs) = ccs!box_ccs.ccs_macro_defs.[mod_index,decl_index]
			= check_completeness macro cci ccs
488
	
489
	checkCompletenessOfMacro :: !Ident !Index !Int !Position !*CheckCompletenessStateBox -> *CheckCompletenessStateBox
490
491
492
	checkCompletenessOfMacro decl_ident decl_index main_dcl_module_n import_position ccs
		#! ({fun_body}, ccs) = ccs!box_ccs.ccs_icl_functions.[decl_index]
		   ccs = { ccs & box_ccs.ccs_set_of_visited_icl_funs.[decl_index] = True }
493
		   cci = { box_cci = { cci_import_position = import_position, cci_main_dcl_module_n=main_dcl_module_n }}
494
		= check_completeness fun_body cci ccs
495
	
496
497
498
499
	replace_ste_with_previous :: !SymbolPtr !*SymbolTable -> .SymbolTable
	replace_ste_with_previous changed_ste_ptr symbol_table
		#! ({ste_previous}, symbol_table) = readPtr changed_ste_ptr symbol_table
		= writePtr changed_ste_ptr ste_previous symbol_table
500
	
501
502
instance toString STE_Kind where
	toString (STE_FunctionOrMacro _)	= "function/macro"
503
	toString (STE_DclMacroOrLocalMacroFunction _) = "macro"
504
505
506
507
508
	toString STE_Type 					= "type"
	toString STE_Constructor 			= "constructor"
	toString (STE_Field _) 				= "field"
	toString STE_Class 					= "class"
	toString STE_Member 				= "class member"
509
	toString STE_Generic 				= "generic"			//AA
510
	toString STE_Instance				= "instance"
511
	toString ste						= "<<unknown symbol kind>>"
512
513
514
515
516
517
518
519
520

check_whether_ident_is_imported :: !Ident !STE_Kind !CheckCompletenessInputBox !*CheckCompletenessStateBox 
								-> *CheckCompletenessStateBox
check_whether_ident_is_imported ident wanted_ste_kind cci ccs=:{box_ccs=box_ccs=:{ccs_symbol_table}}
	#! (ste=:{ste_kind}, ccs_symbol_table) = readPtr ident.id_info ccs_symbol_table
	   ccs = { ccs & box_ccs = { box_ccs & ccs_symbol_table = ccs_symbol_table } }
	| is_imported ste_kind wanted_ste_kind
		= ccs
	#! (ccs=:{box_ccs=box_ccs=:{ccs_symbol_table, ccs_error, ccs_heap_changes_accu}}) = ccs
521
522
523
	   {box_cci={cci_import_position}} = cci
	   ccs_error = checkErrorWithIdentPos (newPosition { id_name="import", id_info=nilPtr } cci_import_position)
	   				(" "+++toString wanted_ste_kind+++" "+++toString ident.id_name+++" not imported") ccs_error
524
525
526
527
	   // pretend that the unimported symbol was imported to prevent doubling error mesages
	   ccs_symbol_table = writePtr ident.id_info { ste & ste_kind = wanted_ste_kind, ste_previous = ste } ccs_symbol_table
	= { ccs & box_ccs = { box_ccs & ccs_error = ccs_error, ccs_symbol_table = ccs_symbol_table, 
									ccs_heap_changes_accu = [ident.id_info:ccs_heap_changes_accu] }}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
528
  where
529
530
531
532
	is_imported (STE_Imported ste_kind _) wanted_ste_kind
		= ste_kind==wanted_ste_kind
	is_imported ste_kind wanted_ste_kind
		= ste_kind==wanted_ste_kind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
533

534
class check_completeness x :: !x !CheckCompletenessInputBox !*CheckCompletenessStateBox -> *CheckCompletenessStateBox
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
535

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
instance check_completeness App where
	check_completeness {app_symb, app_args}	cci ccs
		= check_completeness app_symb cci
		  (check_completeness app_args cci ccs)
	
instance check_completeness AlgebraicPattern where
	check_completeness {ap_symbol, ap_expr} cci ccs
		= check_completeness ap_expr cci
		  (check_whether_ident_is_imported ap_symbol.glob_object.ds_ident STE_Constructor cci ccs)

instance check_completeness AType where
	check_completeness {at_type} cci ccs
		= check_completeness at_type cci ccs

instance check_completeness BasicPattern where
	check_completeness {bp_expr} cci ccs
		= check_completeness bp_expr cci ccs

554
555
556
instance check_completeness LetBind where
	check_completeness {lb_src} cci ccs
		= check_completeness lb_src cci ccs
557
558
559
560
561
562
563
564
565
566
567
568
569

instance check_completeness Case where
	check_completeness { case_expr, case_guards, case_default } cci ccs
		= ( (check_completeness case_expr cci)
		  o (check_completeness case_guards cci)
		  o (check_completeness case_default cci)
		  ) ccs

instance check_completeness CasePatterns where
	check_completeness (AlgebraicPatterns _ algebraicPatterns) cci ccs
		= check_completeness algebraicPatterns cci ccs
	check_completeness (BasicPatterns _ basicPatterns) cci ccs
		= check_completeness basicPatterns cci ccs
570
571
	check_completeness (OverloadedListPatterns _ _ algebraicPatterns) cci ccs
		= check_completeness algebraicPatterns cci ccs
572
573
574
575
576
	check_completeness (DynamicPatterns dynamicPatterns) cci ccs
		= check_completeness dynamicPatterns cci ccs
	check_completeness NoPattern _ ccs
		= ccs

577
578
579
580
instance check_completeness CheckedAlternative where
	check_completeness {ca_rhs} cci ccs
		= check_completeness ca_rhs cci ccs

581
582
583
584
585
586
587
instance check_completeness CheckedBody where
	check_completeness {cb_rhs} cci ccs
		= check_completeness cb_rhs cci ccs

instance check_completeness ClassDef where
	check_completeness {class_context} cci ccs
		= check_completeness class_context cci ccs
588
		
589
instance check_completeness ClassInstance where
590
591
592
	check_completeness {ins_class, ins_type} cci ccs
		= check_completeness ins_type cci
		  (check_whether_ident_is_imported ins_class.glob_object.ds_ident STE_Class cci ccs)
593
594

instance check_completeness ConsDef
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
595
  where
596
597
	check_completeness {cons_type} cci ccs
		= check_completeness cons_type cci ccs
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
598

599
600
601
instance check_completeness DynamicPattern where
	check_completeness { dp_rhs, dp_type } cci ccs
		= check_completeness dp_rhs cci
Sjaak Smetsers's avatar
Sjaak Smetsers committed
602
		  (check_completeness_of_dyn_expr_ptr cci dp_type ccs)
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
	
instance check_completeness DynamicExpr where
	check_completeness { dyn_expr, dyn_opt_type } cci ccs
		= check_completeness dyn_expr cci
		  (check_completeness dyn_opt_type cci ccs)

instance check_completeness DynamicType where
	check_completeness { dt_type } cci ccs
		= check_completeness dt_type cci ccs

instance check_completeness Expression where
	check_completeness (Var _) cci ccs
		= ccs
	check_completeness (App app) cci ccs
		= check_completeness app cci ccs
	check_completeness (expression @ expressions) cci ccs
		= check_completeness expression cci
		  (check_completeness expressions cci ccs)
	check_completeness (Let lad) cci ccs
		= check_completeness lad cci ccs
	check_completeness (Case keesje) cci ccs
		= check_completeness keesje cci ccs
	check_completeness (Selection _ expression selections) cci ccs
		= check_completeness expression cci
		  (check_completeness selections cci ccs)
	check_completeness (TupleSelect _ _ expression) cci ccs
		= check_completeness expression cci ccs
630
	check_completeness (BasicExpr _) _ ccs
631
632
633
634
635
		= ccs
	check_completeness (AnyCodeExpr _ _ _) _ ccs
		= ccs
	check_completeness (ABCCodeExpr _ _) _ ccs
		= ccs
636
	check_completeness (MatchExpr constructor expression) cci ccs
637
638
639
640
641
642
643
644
645
646
647
648
649
650
		= check_completeness expression cci
		  (check_whether_ident_is_imported constructor.glob_object.ds_ident STE_Constructor cci ccs)
	check_completeness (FreeVar _) _ ccs
		= ccs
	check_completeness (DynamicExpr dynamicExpr) cci ccs
		= check_completeness dynamicExpr cci ccs
	check_completeness EE _ ccs
		= ccs
	check_completeness (Update expr1 selections expr2) cci ccs
		= ( (check_completeness expr1 cci)
		  o (check_completeness selections cci)
		  o (check_completeness expr2) cci
		  ) ccs
	check_completeness expr _ _
651
		= abort "explicitimports:check_completeness (Expression) does not match" //<<- expr
652
653
654
655
656
657
658
659
660
661
662
663
664

instance check_completeness FunctionBody where
	check_completeness (CheckedBody body) cci ccs
		= check_completeness body cci ccs
	check_completeness (TransformedBody body) cci ccs
		= check_completeness body cci ccs
	check_completeness (RhsMacroBody body) cci ccs
		= check_completeness body cci ccs
			
instance check_completeness FunDef where
	check_completeness {fun_type, fun_body, fun_info} cci ccs
		= ( (check_completeness fun_type cci)
		  o (check_completeness fun_body cci)
Sjaak Smetsers's avatar
Sjaak Smetsers committed
665
		  o (check_completeness_of_dyn_expr_ptrs cci fun_info.fi_dynamics)
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
		  ) ccs

instance check_completeness FunType where
	check_completeness {ft_type} cci ccs
		= check_completeness ft_type cci ccs

instance check_completeness (Global x) | check_completeness x where
	check_completeness { glob_object } cci ccs
		= check_completeness glob_object cci ccs

instance check_completeness InstanceType where
	check_completeness {it_types, it_context} cci ccs
		= check_completeness it_types cci
		  (check_completeness it_context cci ccs)

instance check_completeness Let where
	check_completeness { let_strict_binds, let_lazy_binds, let_expr } cci ccs
  		= ( (check_completeness let_expr cci)
  		  o (check_completeness let_strict_binds cci)
  		  o (check_completeness let_lazy_binds cci)
  		  ) ccs

instance check_completeness MemberDef where
  	check_completeness {me_type} cci ccs 
  		= check_completeness me_type cci ccs

instance check_completeness (Optional x) | check_completeness x where
	check_completeness (Yes x) cci ccs
		= check_completeness x cci ccs
	check_completeness No _ ccs
		= ccs

instance check_completeness Selection where
	check_completeness (RecordSelection {glob_object,glob_module} _) cci ccs
		#! ({dcl_common}, ccs)	= ccs!box_ccs.ccs_dcl_modules.[glob_module]	// the selector's filed has to be looked up
		   ({sd_field}) = dcl_common.com_selector_defs.[glob_object.ds_index]
		= check_whether_ident_is_imported sd_field ste_field cci ccs
	check_completeness (ArraySelection _ _ index_expr) cci ccs
		= check_completeness index_expr cci ccs
	check_completeness (DictionarySelection _ selections _ index_expr) cci ccs
		= check_completeness selections cci
		  (check_completeness index_expr cci ccs)

instance check_completeness SelectorDef where
	check_completeness {sd_type} cci ccs
		= check_completeness sd_type cci ccs

instance check_completeness SymbIdent where
714
	check_completeness {symb_ident, symb_kind} cci ccs
715
716
		= case symb_kind of
			SK_Constructor _
717
				-> check_whether_ident_is_imported symb_ident STE_Constructor cci ccs
718
			SK_Function global_index			
719
				-> check_completeness_for_function symb_ident global_index cci ccs
720
  			SK_DclMacro global_index
721
				-> check_completeness_for_macro symb_ident global_index cci ccs
722
			SK_LocalDclMacroFunction global_index
723
				-> check_completeness_for_local_dcl_macro symb_ident global_index cci ccs
724
			SK_LocalMacroFunction function_index
725
				-> check_completeness_for_local_macro_function symb_ident function_index cci ccs
726
			SK_OverloadedFunction global_index
727
				-> check_whether_ident_is_imported symb_ident STE_Member cci ccs
728
  	  where
729
		check_completeness_for_function symb_ident {glob_object,glob_module} cci ccs
730
			| glob_module<>cci.box_cci.cci_main_dcl_module_n
731
732
				// the function that is referred from within a macro is a DclFunction
				// -> must be global -> has to be imported
733
				= check_whether_ident_is_imported symb_ident (STE_FunctionOrMacro []) cci ccs
734
735
736
			// otherwise the function was defined locally in a macro
			// it is not a consequence, but it's type and body are consequences !
			#! (already_visited, ccs) = ccs!box_ccs.ccs_set_of_visited_icl_funs.[glob_object]
737
			| /* ccs.box_ccs.ccs_set_of_visited_icl_funs.[glob_object] */ already_visited
738
				= ccs
739
740
741
742
				# ccs = { ccs & box_ccs.ccs_set_of_visited_icl_funs.[glob_object] = True }
				# (fun_def, ccs)	= ccs!box_ccs.ccs_icl_functions.[glob_object]
				= check_completeness fun_def cci ccs

743
		check_completeness_for_macro symb_ident global_index cci ccs
744
			| global_index.glob_module<>cci.box_cci.cci_main_dcl_module_n
745
746
				= check_whether_ident_is_imported symb_ident (STE_DclMacroOrLocalMacroFunction []) cci ccs
				= check_completeness_for_local_dcl_macro symb_ident global_index cci ccs
747

748
		check_completeness_for_local_dcl_macro symb_ident {glob_module,glob_object} cci ccs
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
			| size ccs.box_ccs.ccs_set_of_visited_macros.[glob_module]==0
//				#! n_macros_in_dcl_module=size ccs.box_ccs.ccs_macro_defs.[glob_module]
				# (n_macros_in_dcl_module,ccs) = get_n_macros_in_dcl_module ccs glob_module
					with
						get_n_macros_in_dcl_module :: *CheckCompletenessStateBox Int -> (!Int,!*CheckCompletenessStateBox)
						get_n_macros_in_dcl_module ccs glob_module
							#! n_macros_in_dcl_module=size ccs.box_ccs.ccs_macro_defs.[glob_module]
							= (n_macros_in_dcl_module,ccs)
				# visited_dcl_macros = {createArray n_macros_in_dcl_module False & [glob_object]=True}
				# ccs= {ccs & box_ccs.ccs_set_of_visited_macros.[glob_module]=visited_dcl_macros}
				# (macro_def, ccs) = ccs!box_ccs.ccs_macro_defs.[glob_module,glob_object]
				= check_completeness macro_def cci ccs
			| ccs.box_ccs.ccs_set_of_visited_macros.[glob_module].[glob_object]
				= ccs
				# ccs = {ccs & box_ccs.ccs_set_of_visited_macros.[glob_module].[glob_object]=True}
				# (macro_def, ccs) = ccs!box_ccs.ccs_macro_defs.[glob_module,glob_object]
				= check_completeness macro_def cci ccs
766

767
		check_completeness_for_local_macro_function symb_ident glob_object cci ccs
768
769
			// otherwise the function was defined locally in a macro
			// it is not a consequence, but it's type and body are consequences !
770
			| ccs.box_ccs.ccs_set_of_visited_icl_funs.[glob_object]
771
				= ccs
772
773
774
				# ccs = { ccs & box_ccs.ccs_set_of_visited_icl_funs.[glob_object] = True }
				# (fun_def, ccs)	= ccs!box_ccs.ccs_icl_functions.[glob_object]
				= check_completeness fun_def cci ccs
775

776
777
778
779
780
781
782
783
784
785
786
787
instance check_completeness SymbolType where
	check_completeness {st_args, st_result, st_context} cci ccs
		= ( (check_completeness st_args cci)
		  o (check_completeness st_result cci)
		  o (check_completeness st_context cci)
		  ) ccs

instance check_completeness TransformedBody where
	check_completeness {tb_rhs} cci ccs
		= check_completeness tb_rhs cci ccs

instance check_completeness Type where
788
	check_completeness (TA {type_ident} arguments) cci ccs
789
		= check_completeness arguments cci
790
791
		  (check_whether_ident_is_imported type_ident STE_Type cci ccs)
	check_completeness (TAS {type_ident} arguments _) cci ccs
792
		= check_completeness arguments cci
793
		  (check_whether_ident_is_imported type_ident STE_Type cci ccs)
794
795
796
797
798
799
800
801
802
	check_completeness (l --> r) cci ccs
		= check_completeness l cci
		  (check_completeness r cci ccs)
	check_completeness (_ :@: arguments) cci ccs
		= check_completeness arguments cci ccs
	check_completeness _ _ ccs
		= ccs

instance check_completeness TypeContext where
803
	check_completeness {tc_class=TCClass class_symb, tc_types} cci ccs
804
		= check_completeness tc_types cci
805
806
807
808
809
		  (check_whether_ident_is_imported class_symb.glob_object.ds_ident STE_Class cci ccs)
	check_completeness {tc_class=TCGeneric {gtc_generic}, tc_types} cci ccs
		= check_completeness tc_types cci
		  (check_whether_ident_is_imported gtc_generic.glob_object.ds_ident STE_Generic cci ccs)
	
810
811

instance check_completeness (TypeDef TypeRhs) where
812
	check_completeness td=:{td_rhs, td_context}	cci ccs
813
814
815
816
817
818
819
820
821
822
		= check_completeness td_rhs cci 
		  (check_completeness td_context cci ccs)

instance check_completeness TypeRhs where
	check_completeness (SynType aType) cci ccs
		= check_completeness aType cci ccs
	check_completeness _ _ ccs
		= ccs

instance check_completeness [a]	| check_completeness a
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
823
  where
824
825
826
827
828
829
	check_completeness [] _ ccs
		= ccs
	check_completeness [h:t] cci ccs
		= check_completeness h cci
		  (check_completeness t cci ccs)

Sjaak Smetsers's avatar
Sjaak Smetsers committed
830
check_completeness_of_dyn_expr_ptr :: !CheckCompletenessInputBox !ExprInfoPtr !*CheckCompletenessStateBox
831
								-> *CheckCompletenessStateBox 
Sjaak Smetsers's avatar
Sjaak Smetsers committed
832
check_completeness_of_dyn_expr_ptr cci dyn_expr_ptr ccs=:{box_ccs=box_ccs=:{ccs_expr_heap}}
833
834
835
	#! (expr_info, ccs_expr_heap) = readPtr dyn_expr_ptr ccs_expr_heap
	   ccs = { ccs & box_ccs = { box_ccs & ccs_expr_heap = ccs_expr_heap }}
 	= case expr_info of
Sjaak Smetsers's avatar
Sjaak Smetsers committed
836
837
838
839
840
841
842
843
		(EI_UnmarkedDynamic No further_dynamic_ptrs)
			-> (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
		(EI_UnmarkedDynamic (Yes dynamic_type) further_dynamic_ptrs) 
			-> check_completeness dynamic_type cci (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
		(EI_Dynamic No further_dynamic_ptrs)
			-> (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
		(EI_Dynamic (Yes dynamic_type) further_dynamic_ptrs) 
			-> check_completeness dynamic_type cci (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
844
		(EI_DynamicType dynamic_type further_dynamic_ptrs)
Sjaak Smetsers's avatar
Sjaak Smetsers committed
845
			-> check_completeness dynamic_type cci (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
846
847
		(EI_DynamicTypeWithVars _ dynamic_type further_dynamic_ptrs)
			-> check_completeness dynamic_type cci
Sjaak Smetsers's avatar
Sjaak Smetsers committed
848
849
850
851
852
853
			   	(check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)

check_completeness_of_dyn_expr_ptrs :: !CheckCompletenessInputBox ![ExprInfoPtr] !*CheckCompletenessStateBox
	-> *CheckCompletenessStateBox 
check_completeness_of_dyn_expr_ptrs cci dynamic_ptrs ccs
	= foldSt (check_completeness_of_dyn_expr_ptr cci) dynamic_ptrs ccs
854
855
856
857


// STE_Kinds just for comparision
ste_field =: STE_Field { id_name="", id_info=nilPtr }
858

859
860
861
862
stupid_ident =: { id_name = "stupid", id_info = nilPtr }

// XXX from m import :: T(..) works also if T is a record type