explicitimports.icl 62.1 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
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
7

8
9
10
11
12
13
14
15
16
17
18
:: *ExplImpInfos :== *{#*{!*ExplImpInfo}}

:: ExplImpInfo = ExplImpInfo Ident !.DeclaringModulesSet

:: DeclaringModulesSet :== IntKeyHashtable DeclarationInfo

:: DeclarationInfo =
	{	di_decl			::	!Declaration
	,	di_belonging	::	!NumberSet
	}

19
20
:: ImportNrAndIdents =
	{	ini_symbol_nr	:: !Index
21
	,	ini_imp_decl	:: !ImportDeclaration
22
23
24
	}

:: SolvedImports =
25
	{	si_explicit				:: ![([Declaration], Position)]
26
	,	si_qualified_explicit	:: ![([Declaration], ModuleN)]
27
	,	si_implicit				:: ![(ModuleN, Position)]
28
29
	}

30
31
32
33
34
35
36
37
38
39
40
41
idents_to_empty_ExplImpInfo_array :: ![Ident] -> *{!*ExplImpInfo}
idents_to_empty_ExplImpInfo_array expl_imp_symbols_in_component
	= {ExplImpInfo expl_imp_symbol ikhEmpty \\ expl_imp_symbol <- expl_imp_symbols_in_component}

addDeclarationWithAllBelongingsToExplImpInfo :: !Declaration !BelongingSymbols !Index !ComponentNrAndIndex !ExplImpInfos -> ExplImpInfos
addDeclarationWithAllBelongingsToExplImpInfo decl all_belong_s mod_index {cai_component_nr,cai_index} expl_imp_infos
	# (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_infos) = expl_imp_infos![cai_component_nr,cai_index]
	  di_belonging = nsFromTo (nrOfBelongingSymbols all_belong_s)
	  di = {di_decl=decl, di_belonging=di_belonging}
	  eii_declaring_modules = ikhInsert` False mod_index di eii_declaring_modules
	= {expl_imp_infos & [cai_component_nr,cai_index] = ExplImpInfo eii_ident eii_declaring_modules}

42
markExplImpSymbols :: !Int !*(!*ExplImpInfos,!*SymbolTable) -> (!.[Ident],!(!*ExplImpInfos,!*SymbolTable))
Martin Wierich's avatar
Martin Wierich committed
43
markExplImpSymbols component_nr (expl_imp_info, cs_symbol_table)
44
	#  (expl_imp_info_from_component,expl_imp_info) = expl_imp_info![component_nr]
45
46
47
	#! nr_of_expl_imp_symbols = size expl_imp_info_from_component
	#  (new_symbols, expl_imp_info_from_component, cs_symbol_table) = iFoldSt (mark_symbol component_nr) 0 nr_of_expl_imp_symbols ([], expl_imp_info_from_component, cs_symbol_table)
	   expl_imp_info = {expl_imp_info & [component_nr] = expl_imp_info_from_component}
Martin Wierich's avatar
Martin Wierich committed
48
49
	= (new_symbols, (expl_imp_info, cs_symbol_table))
  where
50
	mark_symbol component_nr i (changed_symbols_accu, expl_imp_info_from_component, cs_symbol_table)
51
		# (eii, expl_imp_info_from_component) = expl_imp_info_from_component![i]
52
		  (eii_ident, eii) = get_eei_ident eii
53
		  expl_imp_info_from_component = {expl_imp_info_from_component & [i] = eii}
54
55
		  (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
56
		= case ste.ste_kind of
57
58
			STE_ExplImpComponentNrs component_nrs
				# new_ste_kind = STE_ExplImpComponentNrs [cai:component_nrs]
59
				  cs_symbol_table = writePtr eii_ident.id_info { ste & ste_kind = new_ste_kind } cs_symbol_table
60
				-> (changed_symbols_accu, expl_imp_info_from_component, cs_symbol_table)
Martin Wierich's avatar
Martin Wierich committed
61
			_
62
				# new_ste = { ste & ste_kind = STE_ExplImpComponentNrs [cai], ste_previous = ste }
63
				-> ([eii_ident:changed_symbols_accu], expl_imp_info_from_component, writePtr eii_ident.id_info new_ste cs_symbol_table)
64

65
66
updateExplImpForMarkedSymbol :: !Index !Declaration !SymbolTableEntry !u:{#DclModule} !*ExplImpInfos !*SymbolTable
																  -> (!u:{#DclModule},!*ExplImpInfos,!*SymbolTable)
67
updateExplImpForMarkedSymbol mod_index decl {ste_kind=STE_ExplImpComponentNrs component_numbers} dcl_modules expl_imp_infos cs_symbol_table
68
	= foldSt (addExplImpInfo mod_index decl) component_numbers (dcl_modules, expl_imp_infos, cs_symbol_table)
Martin Wierich's avatar
Martin Wierich committed
69
70
71
updateExplImpForMarkedSymbol _ _ entry dcl_modules expl_imp_infos cs_symbol_table
	= (dcl_modules, expl_imp_infos, cs_symbol_table)

72
73
addExplImpInfo :: !Index Declaration !ComponentNrAndIndex !(!u:{#DclModule},!*ExplImpInfos,!*SymbolTable)
														-> (!u:{#DclModule},!*ExplImpInfos,!*SymbolTable)
74
addExplImpInfo mod_index decl { cai_component_nr, cai_index } (dcl_modules, expl_imp_infos, cs_symbol_table)
75
	# (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_infos) = expl_imp_infos![cai_component_nr,cai_index]
Martin Wierich's avatar
Martin Wierich committed
76
77
	  (di_belonging, dcl_modules, cs_symbol_table)
	  		= get_belonging_symbol_nrs decl dcl_modules cs_symbol_table
78
	  di = { di_decl = decl, di_belonging = di_belonging }
79
	  new_expl_imp_info = ExplImpInfo eii_ident (ikhInsert` False mod_index di eii_declaring_modules)
Martin Wierich's avatar
Martin Wierich committed
80
81
	= (dcl_modules, { expl_imp_infos & [cai_component_nr,cai_index] = new_expl_imp_info }, cs_symbol_table)
  where
82
83
	get_belonging_symbol_nrs :: !Declaration !v:{#DclModule} !*SymbolTable
							 -> (!.NumberSet,!v:{#DclModule},!*SymbolTable)
Martin Wierich's avatar
Martin Wierich committed
84
	get_belonging_symbol_nrs decl dcl_modules cs_symbol_table
85
86
		# (all_belonging_symbols, dcl_modules) = getBelongingSymbols decl dcl_modules
		  nr_of_belongs = nrOfBelongingSymbols all_belonging_symbols
Martin Wierich's avatar
Martin Wierich committed
87
88
89
90
91
		  (_, 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)
92
		# ({ste_kind}, cs_symbol_table) = readPtr id_info cs_symbol_table
Martin Wierich's avatar
Martin Wierich committed
93
94
95
		= ( bit_nr+1
		  , case ste_kind of
			 	STE_Empty -> bitvect
96
			 	STE_BelongingSymbolForExportedSymbol -> bitvect
Martin Wierich's avatar
Martin Wierich committed
97
98
99
100
101
102
103
104
105
				_ -> 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
106
				-> foldlArraySt (\{fs_ident} st -> f fs_ident st) fields st 
Martin Wierich's avatar
Martin Wierich committed
107
108
			BS_Members members
				-> foldlArraySt (\{ds_ident} st -> f ds_ident st) members st 
109
110
111
112
			BS_MembersAndMacros members macro_members _ default_macros
				# st = foldlArraySt (\{ds_ident} st -> f ds_ident st) members st
				# st = foldlArraySt (\{mm_ident} st -> f mm_ident st) macro_members st
				-> foldlArraySt (\{mm_ident} st -> f mm_ident st) default_macros st
Martin Wierich's avatar
Martin Wierich committed
113
114
			BS_Nothing
				-> st
115
116
117
118
119

FoldSt op l st :== fold_st l st
	where
		fold_st [|] st		= st
		fold_st [|a:x] st	= fold_st x (op a st)
Martin Wierich's avatar
Martin Wierich committed
120

121
122
123
124
125
getBelongingSymbolsFromImportDeclaration :: !ImportDeclaration -> Optional [Ident]
getBelongingSymbolsFromImportDeclaration (ID_Class _ x) = x
getBelongingSymbolsFromImportDeclaration (ID_Type _ x) = x
getBelongingSymbolsFromImportDeclaration (ID_Record _ x) = x
getBelongingSymbolsFromImportDeclaration _ = No
126

127
128
129
130
131
132
:: ExplicitImportsModuleInfo = {
	eimi_module_path :: ![Int],
	eimi_modules_explicit_imports :: !IntKeyHashtable [ExplicitImport],
	eimi_component_mods :: !{#Int}
   }

133
134
135
136
137
138
:: Belonging = {
	belonging_declaration :: !Declaration,
	belonging_import_n_and_idents :: !ImportNrAndIdents,
	belonging_imported_mod :: !Int
   }

139
solveExplicitImports :: !(IntKeyHashtable [ExplicitImport]) !{#Int} !Index
140
141
								!*(!v:{#DclModule},!*{#Int},!{!*ExplImpInfo},!*CheckState)
			-> (!.SolvedImports,! (!v:{#DclModule},!.{#Int},!{!.ExplImpInfo},!.CheckState))
142
solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod (dcl_modules, visited_modules, expl_imp_info, cs)
143
	# import_indices = ikhSearch` importing_mod expl_imp_indices_ikh
144
	  (expl_imp_indices,qualified_expl_imp_indices,impl_imports) = split_imports import_indices
145
	  state = (dcl_modules, visited_modules, expl_imp_info, cs)
146
147
148
149
	  eimi = {eimi_module_path=[importing_mod],eimi_modules_explicit_imports=expl_imp_indices_ikh,eimi_component_mods=modules_in_component_set}
	  (expl_imports, state) = mapSt (solve_expl_imp_from_module eimi) expl_imp_indices state
	  eimi = {eimi_module_path=[],eimi_modules_explicit_imports=expl_imp_indices_ikh,eimi_component_mods=modules_in_component_set}
	  (qualified_expl_imports, state) = mapSt (solve_qualified_expl_imp_from_module eimi) qualified_expl_imp_indices state
150
	= ({ si_explicit=expl_imports, si_qualified_explicit=qualified_expl_imports, si_implicit=impl_imports }, state)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
151
  where
152
153
154
155
156
157
158
159
160
161
162
163
164
	split_imports :: [ExplicitImport] -> (![ExplicitImport],![ExplicitImport],![(Int,Position)])
	split_imports [imports:import_indices]
		# (expl_imp_indices,qualified_expl_imp_indices,impl_imports) = split_imports import_indices
		= case imports of
			{ei_symbols=ImportSymbolsOnly _,ei_qualified=NotQualified}
				-> ([imports:expl_imp_indices],qualified_expl_imp_indices,impl_imports)
			{ei_symbols=ImportSymbolsOnly _}
				-> (expl_imp_indices,[imports:qualified_expl_imp_indices],impl_imports)
			{ei_symbols=ImportSymbolsAll,ei_module_n,ei_position}
				-> (expl_imp_indices,qualified_expl_imp_indices,[(ei_module_n,ei_position):impl_imports])
	split_imports []
		= ([],[],[])

John van Groningen's avatar
John van Groningen committed
165
166
167
	solve_expl_imp_from_module :: ExplicitImportsModuleInfo ExplicitImport
															*(v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState)
								-> (([Declaration],Position),(v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState))
168
169
	solve_expl_imp_from_module eimi
			{ei_symbols=ImportSymbolsOnly imported_symbols, ei_module_n=imported_mod, ei_position=position} (dcl_modules, visited_modules, expl_imp_info, cs)
John van Groningen's avatar
John van Groningen committed
170
171
		# (not_exported_symbols,decl_accu, unsolved_belongings, visited_modules, expl_imp_info)
				= search_expl_imp_symbols imported_symbols eimi imported_mod visited_modules expl_imp_info
172
173
		  (expl_imp_info,dcl_modules,cs_error)
		  		= report_not_exported_symbol_errors not_exported_symbols position expl_imp_info imported_mod dcl_modules cs.cs_error
Martin Wierich's avatar
Martin Wierich committed
174
		  (decl_accu, dcl_modules, visited_modules, expl_imp_info, cs)
John van Groningen's avatar
John van Groningen committed
175
		  		= solve_belongings unsolved_belongings position eimi (decl_accu,dcl_modules,visited_modules,expl_imp_info,{cs & cs_error=cs_error})
Martin Wierich's avatar
Martin Wierich committed
176
		= ((decl_accu, position), (dcl_modules, visited_modules, expl_imp_info, cs))
177

John van Groningen's avatar
John van Groningen committed
178
179
180
	solve_qualified_expl_imp_from_module :: ExplicitImportsModuleInfo ExplicitImport
																   *(v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState)
											-> (([Declaration],Int),(v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState))
181
	solve_qualified_expl_imp_from_module eimi
182
			{ei_symbols=ImportSymbolsOnly imported_symbols, ei_module_n=imported_mod, ei_position=position} (dcl_modules, visited_modules, expl_imp_info, cs)
John van Groningen's avatar
John van Groningen committed
183
184
		# (not_exported_symbols,decl_accu, unsolved_belongings, visited_modules, expl_imp_info)
				= search_qualified_expl_imp_symbols imported_symbols eimi imported_mod visited_modules expl_imp_info
185
186
		  (expl_imp_info,dcl_modules,cs_error)
		  		= report_not_exported_symbol_errors not_exported_symbols position expl_imp_info imported_mod dcl_modules cs.cs_error
187
		  (decl_accu, dcl_modules, visited_modules, expl_imp_info, cs)
John van Groningen's avatar
John van Groningen committed
188
				= solve_belongings unsolved_belongings position eimi (decl_accu,dcl_modules,visited_modules,expl_imp_info,{cs & cs_error=cs_error})
189
		= ((decl_accu, imported_mod), (dcl_modules, visited_modules, expl_imp_info, cs))
190

John van Groningen's avatar
John van Groningen committed
191
192
193
194
	search_expl_imp_symbols :: [ImportNrAndIdents] ExplicitImportsModuleInfo Int *{#Int} *{!*ExplImpInfo}
							   -> ([ImportNrAndIdents],[Declaration],[Belonging],*{#Int},*{!*ExplImpInfo})
	search_expl_imp_symbols imported_symbols eimi imported_mod visited_modules expl_imp_info
		= foldSt (search_expl_imp_symbol eimi imported_mod) imported_symbols ([],[],[],visited_modules,expl_imp_info)
195

John van Groningen's avatar
John van Groningen committed
196
197
198
199
	search_qualified_expl_imp_symbols :: [ImportNrAndIdents] ExplicitImportsModuleInfo Int *{#Int} *{!*ExplImpInfo}
										 -> ([ImportNrAndIdents],[Declaration],[Belonging],*{#Int},*{!*ExplImpInfo})
	search_qualified_expl_imp_symbols imported_symbols eimi imported_mod visited_modules expl_imp_info
		= foldSt (search_qualified_expl_imp_symbol eimi imported_mod) imported_symbols ([],[],[],visited_modules,expl_imp_info)
200

John van Groningen's avatar
John van Groningen committed
201
202
	solve_belongings :: [Belonging] Position ExplicitImportsModuleInfo *([Declaration],v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState)
																	 -> ([Declaration],v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState)
203
204
	solve_belongings unsolved_belonging position eimi state
		= foldSt (solve_belonging position eimi) unsolved_belonging state
205

John van Groningen's avatar
John van Groningen committed
206
207
	solve_belonging :: Position ExplicitImportsModuleInfo Belonging *([Declaration],v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState)
																  -> ([Declaration],v:{#DclModule},*{#Int},*{!*ExplImpInfo},*CheckState)
208
	solve_belonging position eimi
209
			{belonging_declaration,belonging_import_n_and_idents={ini_symbol_nr, ini_imp_decl},belonging_imported_mod}
210
			(decls_accu, dcl_modules, visited_modules, expl_imp_info, cs=:{cs_error, cs_symbol_table})
211
		# (Yes belongs) = getBelongingSymbolsFromImportDeclaration ini_imp_decl
John van Groningen's avatar
John van Groningen committed
212
		  (all_belongs,belonging_symbols,dcl_modules) = get_all_belongs belonging_declaration dcl_modules
213
		  (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_info) = expl_imp_info![ini_symbol_nr]
214
215
216
217
		  (need_all, belongs_set, cs_error, cs_symbol_table)
		  		= case belongs of
		  			[]
		  				// an import like ::A(..) or ::A{..} or class c{..} 
John van Groningen's avatar
John van Groningen committed
218
219
						# belongs_set = [(belong_nr, belong_ident) \\ belong_nr<-[0..] & belong_ident<-all_belongs]
						-> (False, belongs_set, cs_error, cs_symbol_table)
220
221
222
223
		  			_
		  				// 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)
224
						  belongs_bitvect = bitvectCreate nr_of_belongs
225
226
						  (belongs_set, (cs_error, cs_symbol_table))
						  		= mapFilterYesSt (get_opt_nr_and_ident position eii_ident) belongs (cs_error, cs_symbol_table)
227
			  			  cs_symbol_table = restoreIdentsSymbolPtrs all_belongs cs_symbol_table
228
229
						-> (True, belongs_set, cs_error, cs_symbol_table)
		  (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
230
				= foldSt
John van Groningen's avatar
John van Groningen committed
231
					(search_belonging need_all position eii_ident belonging_declaration belonging_symbols belonging_imported_mod ini_symbol_nr eimi)
232
					belongs_set (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
233
		  expl_imp_info = { expl_imp_info & [ini_symbol_nr] = ExplImpInfo eii_ident eii_declaring_modules }
234
		= (decls_accu, dcl_modules, visited_modules, expl_imp_info, { cs & cs_error = cs_error, cs_symbol_table = cs_symbol_table })
235

John van Groningen's avatar
John van Groningen committed
236
	search_belonging need_all position eii_ident belonging_declaration belonging_symbols imported_mod ini_symbol_nr eimi
237
238
						(belong_nr, belong_ident) (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
		# (found, path, eii_declaring_modules, visited_modules)
John van Groningen's avatar
John van Groningen committed
239
			= search_belonging_symbol eii_declaring_modules ini_symbol_nr belong_nr belong_ident imported_mod
240
										eimi (bitvectResetAll visited_modules)
241
		| found
242
			# eii_declaring_modules = foldSt (store_belonging belong_nr) path eii_declaring_modules
243
244
			  (decls_accu, dcl_modules) = add_nth_belonging_decls position belong_nr belonging_declaration decls_accu dcl_modules
			= (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
245
246
247
248
249
250
251
		| need_all
			# (module_name,dcl_modules)=dcl_modules![imported_mod].dcl_name.id_name
			  cs_error = pushErrorAdmin (newPosition import_ident position) cs_error
			  cs_error = checkError belong_ident ("of "+++eii_ident.id_name+++" not exported by module "+++module_name) cs_error
			  cs_error = popErrorAdmin cs_error
			= (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
			= (decls_accu, dcl_modules, eii_declaring_modules, visited_modules, cs_error)
252

John van Groningen's avatar
John van Groningen committed
253
	store_belonging :: Int Int *DeclaringModulesSet -> *DeclaringModulesSet
254
	store_belonging belong_nr mod_index eii_declaring_modules
255
256
		# (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
257
		| new
258
			= abort "sanity check failed in module explicitimports"
259
260
		= eii_declaring_modules

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
	add_nth_belonging_decls position belong_nr decl=:(Declaration {decl_kind,decl_ident}) decls_accu dcl_modules
		# (STE_Imported _ def_mod_index) = decl_kind
		  (belongin_symbols, dcl_modules) = getBelongingSymbols decl dcl_modules
		= case belongin_symbols of
			BS_Constructors constructors
				# {ds_ident, ds_index} = constructors!!belong_nr
				-> ([Declaration { decl_ident = ds_ident, decl_pos = position, 
						decl_kind = STE_Imported STE_Constructor def_mod_index,
						decl_index = ds_index } : decls_accu], dcl_modules)
			BS_Fields rt_fields
				# {fs_ident, fs_index} = rt_fields.[belong_nr]
				  ({sd_ident}, dcl_modules)
						= dcl_modules![def_mod_index].dcl_common.com_selector_defs.[fs_index]
				-> ([Declaration { decl_ident = fs_ident, decl_pos = position, 
						decl_kind = STE_Imported (STE_Field sd_ident) def_mod_index,
						decl_index = fs_index } : decls_accu], dcl_modules)
			BS_Members class_members
				# {ds_ident, ds_index} = class_members.[belong_nr]
				-> ([Declaration { decl_ident = ds_ident, decl_pos = position,
						decl_kind = STE_Imported STE_Member def_mod_index,
						decl_index = ds_index } : decls_accu], dcl_modules)
			BS_MembersAndMacros class_members macro_members default_member_indexes default_macros
				| belong_nr<size class_members
					# {ds_ident, ds_index} = class_members.[belong_nr]
					# decl = Declaration { decl_ident = ds_ident, decl_pos = position,
										   decl_kind = STE_Imported STE_Member def_mod_index,
										   decl_index = ds_index }
					| belong_nr>=size default_member_indexes
						-> ([decl : decls_accu], dcl_modules)
					# default_macros_index = default_member_indexes.[belong_nr]
					| default_macros_index<0
						-> ([decl : decls_accu], dcl_modules)
						#! {mm_ident,mm_index} = default_macros.[default_macros_index]
						# macro_decl = Declaration { decl_ident = mm_ident, decl_pos = position,
													 decl_kind = STE_Imported (STE_DclMacroOrLocalMacroFunction []) def_mod_index,
													 decl_index = mm_index }
						-> ([decl,macro_decl : decls_accu], dcl_modules)
				| belong_nr<size class_members+size macro_members
					# {mm_ident,mm_index} = macro_members.[belong_nr-size class_members]
					-> ([Declaration { decl_ident = mm_ident, decl_pos = position,
							decl_kind = STE_Imported (STE_DclMacroOrLocalMacroFunction []) def_mod_index,
							decl_index = mm_index } : decls_accu], dcl_modules)
					# {mm_ident,mm_index} = default_macros.[belong_nr-(size class_members+size macro_members)]
					-> ([Declaration { decl_ident = mm_ident, decl_pos = position,
							decl_kind = STE_Imported (STE_DclMacroOrLocalMacroFunction []) def_mod_index,
							decl_index = mm_index } : decls_accu], dcl_modules)
John van Groningen's avatar
John van Groningen committed
307
308

	get_all_belongs :: Declaration v:{#DclModule} -> (![Ident],!BelongingSymbols,!v:{#DclModule})
309
	get_all_belongs decl=:(Declaration {decl_kind,decl_index}) dcl_modules
310
		# (belonging_symbols, dcl_modules) = getBelongingSymbols decl dcl_modules
311
312
		= case belonging_symbols of
			BS_Constructors constructors
John van Groningen's avatar
John van Groningen committed
313
				-> ([ds_ident \\ {ds_ident}<-constructors], belonging_symbols, dcl_modules)
314
			BS_Fields rt_fields
John van Groningen's avatar
John van Groningen committed
315
				-> ([fs_ident \\ {fs_ident}<-:rt_fields], belonging_symbols, dcl_modules)
316
			BS_Members class_members
John van Groningen's avatar
John van Groningen committed
317
				-> ([ds_ident \\ {ds_ident}<-:class_members], belonging_symbols, dcl_modules)
318
319
320
321
			BS_MembersAndMacros class_members macro_members _ default_macros
				-> ([ds_ident \\ {ds_ident}<-:class_members]
					++[mm_ident\\{mm_ident}<-:macro_members]
					++[mm_ident\\{mm_ident}<-:default_macros], belonging_symbols, dcl_modules)
322
			BS_Nothing
John van Groningen's avatar
John van Groningen committed
323
				-> ([], belonging_symbols, dcl_modules)
324

John van Groningen's avatar
John van Groningen committed
325
	numerate_belongs :: Ident *(Int,*SymbolTable) -> (!Int,!*SymbolTable)
326
	numerate_belongs {id_info} (i, cs_symbol_table)
327
328
		# (ste, cs_symbol_table) = readPtr id_info cs_symbol_table
		  new_ste = { ste & ste_kind = STE_BelongingSymbol i, ste_previous = ste }
329
		= (i+1, writePtr id_info new_ste cs_symbol_table)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
330
	
John van Groningen's avatar
John van Groningen committed
331
	get_opt_nr_and_ident :: Position Ident Ident !*(*ErrorAdmin,!*SymbolTable) -> (!Optional (Int,Ident),!*(!*ErrorAdmin,!*SymbolTable))
332
	get_opt_nr_and_ident position eii_ident ii_ident=:{id_info} (cs_error, cs_symbol_table)
333
		# ({ste_kind}, cs_symbol_table) = readPtr id_info cs_symbol_table
334
		= case ste_kind of
335
336
337
			STE_BelongingSymbol i
				-> (Yes (i, ii_ident), (cs_error, cs_symbol_table))
			_
338
339
				# cs_error = pushErrorAdmin (newPosition import_ident position) cs_error
				  cs_error = checkError ii_ident ("does not belong to "+++eii_ident.id_name) cs_error 
340
				-> (No, (popErrorAdmin cs_error, cs_symbol_table))
341

342
	search_expl_imp_symbol :: ExplicitImportsModuleInfo Int ImportNrAndIdents
343
344
							  *([ImportNrAndIdents],[Declaration],[Belonging],*{#Int},*{!*ExplImpInfo})
							-> ([ImportNrAndIdents],[Declaration],[Belonging],*{#Int},*{!*ExplImpInfo})
345
346
	search_expl_imp_symbol eimi imported_mod ini=:{ini_symbol_nr}
			(not_exported_symbols,decls_accu, belonging_accu, visited_modules, expl_imp_info)
347
348
		# (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_info) = expl_imp_info![ini_symbol_nr]
		  (opt_decl, path, eii_declaring_modules, visited_modules)
John van Groningen's avatar
John van Groningen committed
349
			= search_symbol eii_declaring_modules ini_symbol_nr imported_mod eimi (bitvectResetAll visited_modules)
350
351
352
353
354
355
356
357
358
359
360
		= case opt_decl of
			Yes di=:{di_decl=di_decl=:Declaration {decl_kind}}
				| is_not_STE_member decl_kind
					# new_eii_declaring_modules = update_declaring_modules di_decl path eii_declaring_modules
					  expl_imp_info = {expl_imp_info & [ini_symbol_nr] = ExplImpInfo eii_ident new_eii_declaring_modules}
					  new_belonging_accu = update_belonging_accu di_decl ini imported_mod belonging_accu
					-> (not_exported_symbols,[di_decl:decls_accu], new_belonging_accu, visited_modules, expl_imp_info)
			_
				# expl_imp_info = {expl_imp_info & [ini_symbol_nr] = ExplImpInfo eii_ident eii_declaring_modules}
				-> ([ini:not_exported_symbols],decls_accu, belonging_accu, visited_modules, expl_imp_info)

361
	search_qualified_expl_imp_symbol :: ExplicitImportsModuleInfo Int ImportNrAndIdents
362
363
							  *([ImportNrAndIdents],[Declaration],[Belonging],*{#Int},*{!*ExplImpInfo})
							-> ([ImportNrAndIdents],[Declaration],[Belonging],*{#Int},*{!*ExplImpInfo})
364
365
	search_qualified_expl_imp_symbol eimi imported_mod ini=:{ini_symbol_nr}
			(not_exported_symbols,decls_accu, belonging_accu, visited_modules, expl_imp_info)
366
		# (ExplImpInfo eii_ident eii_declaring_modules, expl_imp_info) = expl_imp_info![ini_symbol_nr]
367
		  (opt_decl, path, eii_declaring_modules, visited_modules)
John van Groningen's avatar
John van Groningen committed
368
			= search_symbol eii_declaring_modules ini_symbol_nr imported_mod eimi (bitvectResetAll visited_modules)
369
		= case opt_decl of
370
			Yes {di_decl}
371
372
373
374
				# new_eii_declaring_modules = update_declaring_modules di_decl path eii_declaring_modules
				  expl_imp_info = {expl_imp_info & [ini_symbol_nr] = ExplImpInfo eii_ident new_eii_declaring_modules}
				  new_belonging_accu = update_belonging_accu di_decl ini imported_mod belonging_accu
				-> (not_exported_symbols,[di_decl:decls_accu], new_belonging_accu, visited_modules, expl_imp_info)
Martin Wierich's avatar
Martin Wierich committed
375
			_
376
377
378
379
380
381
382
				# expl_imp_info = {expl_imp_info & [ini_symbol_nr] = ExplImpInfo eii_ident eii_declaring_modules}
				-> ([ini:not_exported_symbols],decls_accu, belonging_accu, visited_modules, expl_imp_info)

	is_not_STE_member (STE_Imported STE_Member _) = False
	is_not_STE_member STE_Member = False
	is_not_STE_member _ = True

383
	update_declaring_modules :: Declaration [Int] *DeclaringModulesSet -> *DeclaringModulesSet
384
385
386
	update_declaring_modules di_decl path eii_declaring_modules
		= foldSt (\mod_index eei_dm->ikhInsert` False mod_index {di_decl = di_decl, di_belonging=EndNumbers} eei_dm) path eii_declaring_modules

387
	update_belonging_accu :: Declaration ImportNrAndIdents Int [Belonging] -> [Belonging]
388
	update_belonging_accu di_decl ini imported_mod belonging_accu
389
		= case getBelongingSymbolsFromImportDeclaration ini.ini_imp_decl of
390
			No		-> belonging_accu
391
			Yes _	-> [{belonging_declaration=di_decl, belonging_import_n_and_idents=ini, belonging_imported_mod=imported_mod}:belonging_accu]
392

John van Groningen's avatar
John van Groningen committed
393
394
	search_symbol :: *DeclaringModulesSet Int Int ExplicitImportsModuleInfo *{#Int} -> *(!Optional DeclarationInfo,![Int],!*DeclaringModulesSet,!*{#Int})
	search_symbol eii_declaring_modules imported_symbol_n imported_mod eimi=:{eimi_modules_explicit_imports,eimi_component_mods,eimi_module_path} visited_modules
395
396
		# (opt_declaration_info_of_symbol_in_mod, eii_declaring_modules) = ikhUSearch imported_mod eii_declaring_modules
		= case opt_declaration_info_of_symbol_in_mod of
397
			yes_di=:(Yes di)
398
				-> (yes_di, eimi_module_path, eii_declaring_modules, visited_modules)
399
			_
400
				| not (bitvectSelect imported_mod eimi_component_mods)
401
402
403
					// 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)
404
405
406
				# imports_of_imported_mod = ikhSearch` imported_mod eimi_modules_explicit_imports
				  visited_modules = bitvectSet imported_mod visited_modules
				  eimi & eimi_module_path = [imported_mod:eimi_module_path]
John van Groningen's avatar
John van Groningen committed
407
				-> search_symbol_in_imports imports_of_imported_mod eii_declaring_modules imported_symbol_n eimi visited_modules
408
	where
John van Groningen's avatar
John van Groningen committed
409
410
		search_symbol_in_imports :: [ExplicitImport] *DeclaringModulesSet Int !ExplicitImportsModuleInfo *{#Int} -> *(!Optional DeclarationInfo,![Int],!*DeclaringModulesSet,!*{#Int})
		search_symbol_in_imports [{ei_module_n=imp_imp_mod,ei_symbols}:imports] eii_declaring_modules imported_symbol_n eimi visited_modules
411
			| bitvectSelect imp_imp_mod visited_modules
John van Groningen's avatar
John van Groningen committed
412
				= search_symbol_in_imports imports eii_declaring_modules imported_symbol_n eimi visited_modules
413
414
			= case ei_symbols of
				ImportSymbolsOnly imp_imp_symbols
John van Groningen's avatar
John van Groningen committed
415
416
					| not (search_imported_symbol imported_symbol_n imp_imp_symbols)
						-> search_symbol_in_imports imports eii_declaring_modules imported_symbol_n eimi visited_modules
417
418
				_
					# (opt_decl, path, eii_declaring_modules, visited_modules)
John van Groningen's avatar
John van Groningen committed
419
						= search_symbol eii_declaring_modules imported_symbol_n imp_imp_mod eimi visited_modules
420
421
422
423
					-> case opt_decl of
						Yes _
							-> (opt_decl, path, eii_declaring_modules, visited_modules)
						No
John van Groningen's avatar
John van Groningen committed
424
425
							-> search_symbol_in_imports imports eii_declaring_modules imported_symbol_n eimi visited_modules
		search_symbol_in_imports [] eii_declaring_modules imported_symbol_n eimi visited_modules
426
			= (No, [], eii_declaring_modules, visited_modules)
427

John van Groningen's avatar
John van Groningen committed
428
429
	search_belonging_symbol :: !*DeclaringModulesSet Int Int Ident !Int !ExplicitImportsModuleInfo !*{#Int} -> *(!Bool,![Int],!*DeclaringModulesSet,!*{#Int})
	search_belonging_symbol eii_declaring_modules imported_symbol_n belong_nr belong_ident imported_mod
430
431
432
433
434
435
			eimi=:{eimi_modules_explicit_imports,eimi_component_mods,eimi_module_path} visited_modules
		# (opt_declaration_info_of_symbol_in_mod, eii_declaring_modules) = ikhUSearch imported_mod eii_declaring_modules
		= case opt_declaration_info_of_symbol_in_mod of
			Yes di=:{di_belonging}
				| inNumberSet belong_nr di_belonging
					-> (True, eimi_module_path, eii_declaring_modules, visited_modules)
436
			_
437
				| not (bitvectSelect imported_mod eimi_component_mods)
438
439
440
					// the eii_declaring_modules is complete for modules that are outside
					// (=beneath) the actual component=> no need to search further
					-> (False, [], eii_declaring_modules, visited_modules)
441
				# imports_of_imported_mod = ikhSearch` imported_mod eimi_modules_explicit_imports
John van Groningen's avatar
John van Groningen committed
442
				  visited_modules = bitvectSet imported_mod visited_modules
443
				  eimi & eimi_module_path = [imported_mod:eimi_module_path]
John van Groningen's avatar
John van Groningen committed
444
445
				-> search_belonging_symbol_in_imports imports_of_imported_mod eii_declaring_modules imported_symbol_n belong_nr belong_ident
														eimi visited_modules
446
	where
John van Groningen's avatar
John van Groningen committed
447
448
449
450
		search_belonging_symbol_in_imports :: [ExplicitImport] *DeclaringModulesSet Int Int Ident
												!ExplicitImportsModuleInfo *{#Int} -> *(!Bool,![Int],!*DeclaringModulesSet,!*{#Int})
		search_belonging_symbol_in_imports [{ei_module_n=imp_imp_mod,ei_symbols}:imports] eii_declaring_modules imported_symbol_n belong_nr belong_ident
				eimi visited_modules
451
			| bitvectSelect imp_imp_mod visited_modules
John van Groningen's avatar
John van Groningen committed
452
				= search_belonging_symbol_in_imports imports eii_declaring_modules imported_symbol_n belong_nr belong_ident
453
														eimi visited_modules
454
455
			= case ei_symbols of
				ImportSymbolsOnly imp_imp_symbols
John van Groningen's avatar
John van Groningen committed
456
					# (found, opt_belongs) = search_imported_symbol_and_belongings imported_symbol_n imp_imp_symbols
457
					| not (found && belong_ident_found belong_ident opt_belongs)
John van Groningen's avatar
John van Groningen committed
458
						-> search_belonging_symbol_in_imports imports eii_declaring_modules imported_symbol_n belong_nr belong_ident
459
																eimi visited_modules
460
461
				_
					# (found, path, eii_declaring_modules, visited_modules)
John van Groningen's avatar
John van Groningen committed
462
						= search_belonging_symbol eii_declaring_modules imported_symbol_n belong_nr belong_ident imp_imp_mod
463
													eimi visited_modules
464
465
					| found
						-> (True, path, eii_declaring_modules, visited_modules)
John van Groningen's avatar
John van Groningen committed
466
						-> search_belonging_symbol_in_imports imports eii_declaring_modules imported_symbol_n belong_nr belong_ident
467
																eimi visited_modules
John van Groningen's avatar
John van Groningen committed
468
		search_belonging_symbol_in_imports [] eii_declaring_modules imported_symbol_n belong_nr belong_ident eimi visited_modules
469
470
471
			= (False, [], eii_declaring_modules, visited_modules)

	search_imported_symbol :: !Int ![ImportNrAndIdents] -> Bool
472
	search_imported_symbol imported_symbol_n []
473
		= False
474
475
	search_imported_symbol imported_symbol_n [{ini_symbol_nr, ini_imp_decl}:t]
		= imported_symbol_n==ini_symbol_nr || search_imported_symbol imported_symbol_n t
476
477

	search_imported_symbol_and_belongings :: !Int ![ImportNrAndIdents] -> (!Bool, !Optional [Ident])
478
	search_imported_symbol_and_belongings imported_symbol_n []
479
		= (False, No)
480
481
	search_imported_symbol_and_belongings imported_symbol_n [{ini_symbol_nr, ini_imp_decl}:t]
		| imported_symbol_n==ini_symbol_nr
482
			= (True, getBelongingSymbolsFromImportDeclaration ini_imp_decl)
483
		= search_imported_symbol_and_belongings imported_symbol_n t
484

485
	belong_ident_found :: !Ident !(Optional [Ident]) -> Bool
486
487
488
489
490
491
492
493
494
495
	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

496
	is_member :: !Ident ![Ident] -> Bool
497
498
	is_member belong_ident []
		= False
499
	is_member belong_ident [ii_ident:t]
500
501
502
503
		| belong_ident==ii_ident
			= True
		= is_member belong_ident t

John van Groningen's avatar
John van Groningen committed
504
	report_not_exported_symbol_errors :: ![ImportNrAndIdents] Position *{!*ExplImpInfo} Int v:{#DclModule} *ErrorAdmin -> (*{!*ExplImpInfo},v:{#DclModule},*ErrorAdmin)
505
	report_not_exported_symbol_errors [{ini_symbol_nr,ini_imp_decl}:not_exported_symbols] position expl_imp_info imported_mod dcl_modules cs_error
506
507
508
		# (eii, expl_imp_info) = expl_imp_info![ini_symbol_nr]
		  (eii_ident, eii) = get_eei_ident eii
		  expl_imp_info = {expl_imp_info & [ini_symbol_nr] = eii}
509
510
511
		  (module_name,dcl_modules)=dcl_modules![imported_mod].dcl_name.id_name
		  cs_error = popErrorAdmin (checkError eii_ident
									("not exported as a "+++impDeclToNameSpaceString ini_imp_decl +++" by module "+++module_name)
512
									(pushErrorAdmin (newPosition import_ident position) cs_error))
513
514
515
		= report_not_exported_symbol_errors not_exported_symbols position expl_imp_info imported_mod dcl_modules cs_error
	report_not_exported_symbol_errors [] position expl_imp_info imported_mod dcl_modules cs_error
		= (expl_imp_info,dcl_modules,cs_error)
516

517
	impDeclToNameSpaceString :: !ImportDeclaration -> {#Char}
518
519
520
521
522
523
	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
524
get_eei_ident (eii=:ExplImpInfo eii_ident _) = (eii_ident, eii)
525
	
526
527
:: CheckCompletenessState =
	{	ccs_dcl_modules				:: !.{#DclModule}
528
529
	,	ccs_macro_defs :: !.{#.{#FunDef}}
	,	ccs_set_of_visited_macros	:: !.{#.{#Bool}}
530
531
532
533
534
	,	ccs_expr_heap				:: !.ExpressionHeap
	,	ccs_symbol_table			:: !.SymbolTable
	,	ccs_error					:: !.ErrorAdmin
	,	ccs_heap_changes_accu		:: ![SymbolPtr]
	}
535

536
:: CheckCompletenessStateBox = { box_ccs :: !.CheckCompletenessState }
537
538

:: CheckCompletenessInput =
539
540
	{	cci_import_position		:: !Position
	,	cci_main_dcl_module_n	:: !Int
541
	}
542

543
544
:: CheckCompletenessInputBox = { box_cci :: !CheckCompletenessInput }

545
checkExplicitImportCompleteness :: ![([Declaration], Position)] ![([Declaration], Int)]
546
547
548
										!*{#DclModule} !*{#*{#FunDef}} !*ExpressionHeap !*CheckState
									-> (!.{#DclModule},!*{#*{#FunDef}},!.ExpressionHeap,!.CheckState)
checkExplicitImportCompleteness dcls_explicit explicit_qualified_imports dcl_modules macro_defs expr_heap cs=:{cs_symbol_table, cs_error}
549
	#! n_dcl_modules = size dcl_modules
550
551
552

	# (modified_symbol_ptrs,cs_symbol_table) = store_qualified_explicitly_imported_symbols_in_symbol_table explicit_qualified_imports [] cs_symbol_table

553
	  box_ccs = { ccs_dcl_modules = dcl_modules, ccs_macro_defs=macro_defs,
554
	   			ccs_set_of_visited_macros = { {} \\ module_n<-[0..n_dcl_modules-1]},
555
				ccs_expr_heap = expr_heap, ccs_symbol_table = cs_symbol_table,
556
557
558
559
				ccs_error = cs_error, ccs_heap_changes_accu = modified_symbol_ptrs }
	  main_dcl_module_n = cs.cs_x.x_main_dcl_module_n

	  ccs = foldSt (\(dcls, position) ccs
Martin Wierich's avatar
Martin Wierich committed
560
561
562
	   					-> foldSt (checkCompleteness main_dcl_module_n position) dcls ccs)
	   				dcls_explicit
	   				{ box_ccs = box_ccs }
563
	  { ccs_dcl_modules, ccs_macro_defs,ccs_expr_heap, ccs_symbol_table, ccs_error, ccs_heap_changes_accu } = ccs.box_ccs
564
	// repair heap contents
565
	  ccs_symbol_table = restore_symbol_table_after_checking_completeness ccs_heap_changes_accu ccs_symbol_table
566
567

	  cs = { cs & cs_symbol_table = ccs_symbol_table, cs_error = ccs_error }
568
	= (ccs_dcl_modules, ccs_macro_defs, ccs_expr_heap, cs)
569
  where
Martin Wierich's avatar
Martin Wierich committed
570
	checkCompleteness :: !Int !Position !Declaration !*CheckCompletenessStateBox -> *CheckCompletenessStateBox
571
	checkCompleteness main_dcl_module_n import_position (Declaration {decl_ident, decl_index, decl_kind=STE_Imported expl_imp_kind mod_index}) ccs
572
		#! ({dcl_common,dcl_functions}, ccs) = ccs!box_ccs.ccs_dcl_modules.[mod_index]
573
		   cci = { box_cci = { cci_import_position = import_position, cci_main_dcl_module_n=main_dcl_module_n }}
574
575
576
577
578
		= 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
579
			= check_completeness dcl_common.com_type_defs.[decl_index] cci ccs
580
		continuation STE_Constructor dcl_common dcl_functions cci ccs
581
			= check_completeness dcl_common.com_cons_defs.[decl_index] cci ccs
582
		continuation (STE_Field _) dcl_common dcl_functions cci ccs
583
			= check_completeness dcl_common.com_selector_defs.[decl_index] cci ccs
584
		continuation STE_Class dcl_common dcl_functions cci ccs
585
			= check_completeness dcl_common.com_class_defs.[decl_index] cci ccs
586
		continuation STE_Member dcl_common dcl_functions cci ccs
587
			= check_completeness dcl_common.com_member_defs.[decl_index] cci ccs
588
		continuation STE_Instance dcl_common dcl_functions cci ccs
589
			= check_completeness dcl_common.com_instance_defs.[decl_index] cci ccs
590
		continuation STE_DclFunction dcl_common dcl_functions cci ccs
591
			= check_completeness dcl_functions.[decl_index] cci ccs
592
593
594
		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
595
		continuation STE_Generic dcl_common dcl_functions cci ccs
596
			= check_completeness dcl_common.com_generic_defs.[decl_index] cci ccs
597

598
599
instance toString STE_Kind where
	toString (STE_FunctionOrMacro _)	= "function/macro"
600
	toString (STE_DclMacroOrLocalMacroFunction _) = "macro"
601
602
603
604
605
	toString STE_Type 					= "type"
	toString STE_Constructor 			= "constructor"
	toString (STE_Field _) 				= "field"
	toString STE_Class 					= "class"
	toString STE_Member 				= "class member"
606
	toString STE_Generic 				= "generic"
607
	toString STE_Instance				= "instance"
608
	toString ste						= "<<unknown symbol kind>>"
609

610
check_whether_ident_is_imported :: !Ident !Int !Int !STE_Kind !CheckCompletenessInputBox !*CheckCompletenessStateBox 
611
								-> *CheckCompletenessStateBox
612
613
614
check_whether_ident_is_imported ident module_n symbol_index wanted_ste_kind cci ccs=:{box_ccs=box_ccs=:{ccs_symbol_table}}
	#! (ste=:{ste_kind,ste_index}, ccs_symbol_table) = readPtr ident.id_info ccs_symbol_table
	   ccs = { ccs & box_ccs = {box_ccs & ccs_symbol_table = ccs_symbol_table } }
615
	| is_imported ste_kind wanted_ste_kind symbol_index module_n ste_index
616
		= ccs
617
618
619
620
621
622
623
624
625
626
627
628
629
630
		#! (ccs=:{box_ccs=box_ccs=:{ccs_symbol_table, ccs_error, ccs_heap_changes_accu}}) = ccs
		#  {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
		   // pretend that the unimported symbol was imported to prevent doubling error mesages
		   ccs_symbol_table = writePtr ident.id_info { ste & ste_kind = STE_ExplImpSymbolNotImported module_n ste_kind } ccs_symbol_table
		   ccs_heap_changes_accu = case ste_kind of
		   								STE_ExplImpSymbolNotImported _ _
		   									-> ccs_heap_changes_accu
		   								STE_ImportedQualified _ _
		   									-> ccs_heap_changes_accu
		   								_
		   									-> [ident.id_info:ccs_heap_changes_accu]
		= { ccs & box_ccs = { box_ccs & ccs_error = ccs_error, ccs_symbol_table = ccs_symbol_table, ccs_heap_changes_accu = ccs_heap_changes_accu }}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
631
  where
632
633
634
635
636
637
638
639
640
641
642
643
644
	is_imported :: !STE_Kind !STE_Kind !Int !Int !Int -> Bool
	is_imported (STE_Imported ste_kind ste_module_n) wanted_ste_kind symbol_index module_n ste_index
		= ste_module_n==module_n && ste_index==symbol_index && ste_kind==wanted_ste_kind
	is_imported (STE_ImportedQualified (Declaration {decl_index,decl_kind=STE_Imported decl_kind decl_module_n}) ste_kind) wanted_ste_kind symbol_index module_n ste_index
		| decl_module_n==module_n && decl_index==symbol_index && decl_kind==wanted_ste_kind
			= True
			= is_imported ste_kind wanted_ste_kind symbol_index module_n ste_index
	is_imported (STE_ExplImpSymbolNotImported ste_module_n ste_kind) wanted_ste_kind symbol_index module_n ste_index
		| module_n==ste_module_n
			= True
			= is_imported ste_kind wanted_ste_kind symbol_index module_n ste_index
	is_imported ste_kind wanted_ste_kind symbol_index module_n ste_index
		= cci.box_cci.cci_main_dcl_module_n==module_n && ste_index==symbol_index && ste_kind==wanted_ste_kind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
645

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

648
649
650
651
652
653
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
654
	check_completeness {ap_symbol={glob_module,glob_object={ds_ident,ds_index}}, ap_expr} cci ccs
655
		= check_completeness ap_expr cci
656
		  (check_whether_ident_is_imported ds_ident glob_module ds_index STE_Constructor cci ccs)
657
658
659
660
661
662
663
664
665

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

666
667
668
instance check_completeness LetBind where
	check_completeness {lb_src} cci ccs
		= check_completeness lb_src cci ccs
669
670
671
672
673
674
675
676
677
678
679
680
681

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
682
683
	check_completeness (OverloadedListPatterns _ _ algebraicPatterns) cci ccs
		= check_completeness algebraicPatterns cci ccs
684
685
686
687
688
	check_completeness (DynamicPatterns dynamicPatterns) cci ccs
		= check_completeness dynamicPatterns cci ccs
	check_completeness NoPattern _ ccs
		= ccs

689
690
691
692
instance check_completeness CheckedAlternative where
	check_completeness {ca_rhs} cci ccs
		= check_completeness ca_rhs cci ccs

693
694
695
696
697
698
699
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
700
		
701
instance check_completeness ClassInstance where
702
	check_completeness {ins_class_index={gi_module,gi_index},ins_class_ident={ci_ident=Ident class_ident},ins_type} cci ccs
703
		= check_completeness ins_type cci
704
		  (check_whether_ident_is_imported class_ident gi_module gi_index STE_Class cci ccs)
705
706

instance check_completeness ConsDef
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
707
  where
708
709
	check_completeness {cons_type} cci ccs
		= check_completeness cons_type cci ccs
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
710

711
712
713
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
714
		  (check_completeness_of_dyn_expr_ptr cci dp_type ccs)
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
	
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
742
	check_completeness (BasicExpr _) _ ccs
743
744
745
746
747
		= ccs
	check_completeness (AnyCodeExpr _ _ _) _ ccs
		= ccs
	check_completeness (ABCCodeExpr _ _) _ ccs
		= ccs
748
749
750
751
752
	check_completeness (Update expr1 selections expr2) cci ccs
		= ( (check_completeness expr1 cci)
		  o (check_completeness selections cci)
		  o (check_completeness expr2) cci
		  ) ccs
753
	check_completeness (MatchExpr {glob_module,glob_object={ds_ident,ds_index}} expression) cci ccs
754
		= check_completeness expression cci
755
		  (check_whether_ident_is_imported ds_ident glob_module ds_index STE_Constructor cci ccs)
756
757
758
	check_completeness (IsConstructor expr {glob_module,glob_object={ds_ident,ds_index}} _ _ _ _) cci ccs
		= check_completeness expr cci
		  (check_whether_ident_is_imported ds_ident glob_module ds_index STE_Constructor cci ccs)
759
760
761
762
763
764
765
	check_completeness (FreeVar _) _ ccs
		= ccs
	check_completeness (DynamicExpr dynamicExpr) cci ccs
		= check_completeness dynamicExpr cci ccs
	check_completeness EE _ ccs
		= ccs
	check_completeness expr _ _
766
		= abort "explicitimports:check_completeness (Expression) does not match" //<<- expr
767
768
769
770
771
772
773
774
775
776
777
778
779

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
780
		  o (check_completeness_of_dyn_expr_ptrs cci fun_info.fi_dynamics)
781
782
783
784
785
786
		  ) ccs

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

787
instance check_completeness GenericDef where
788
789
790
791
792
793
	check_completeness {gen_ident, gen_type, gen_deps} cci ccs
		= (check_completeness gen_type cci o foldSt (flip check_completeness cci) gen_deps) ccs

instance check_completeness GenericDependency where
	check_completeness {gd_ident=Ident ident, gd_index={gi_module, gi_index}} cci ccs
		= check_whether_ident_is_imported ident gi_module gi_index STE_Generic cci ccs
794

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810