Commit ce0c5c1c authored by John van Groningen's avatar John van Groningen
Browse files

fix implicit qualified import of a module of which no (qualified) symbol is used

parent 60b1fd54
......@@ -1595,9 +1595,16 @@ checkDclModules imports_of_icl_mod dcl_modules macro_defs heaps cs=:{cs_symbol_t
get_mod_imports _ imports_of_icl_mod dcl_modules cs_symbol_table
= (imports_of_icl_mod, dcl_modules, cs_symbol_table)
get_expl_imp_symbols :: ParsedImport *([Ident],Int,[ExplicitImport],*SymbolTable) -> ([Ident],Int,[ExplicitImport],*SymbolTable)
get_expl_imp_symbols {import_module,import_symbols,import_file_position,import_qualified} (expl_imp_symbols_accu, nr_of_expl_imp_symbols, expl_imp_indices_accu, cs_symbol_table)
# (expl_imp_symbols_accu, nr_of_expl_imp_symbols, expl_imp_indices, cs_symbol_table)
= foldSt get_expl_imp_symbol import_symbols (expl_imp_symbols_accu, nr_of_expl_imp_symbols, [], cs_symbol_table)
= case import_symbols of
ImportSymbolsOnly import_symbols
# (expl_imp_symbols_accu, nr_of_expl_imp_symbols, expl_imp_indices, cs_symbol_table)
= foldSt get_expl_imp_symbol import_symbols (expl_imp_symbols_accu, nr_of_expl_imp_symbols, [], cs_symbol_table)
-> (expl_imp_symbols_accu, nr_of_expl_imp_symbols, ImportSymbolsOnly expl_imp_indices, cs_symbol_table)
ImportSymbolsAll
-> (expl_imp_symbols_accu, nr_of_expl_imp_symbols, ImportSymbolsAll, cs_symbol_table)
({ste_index}, cs_symbol_table) = readPtr import_module.id_info cs_symbol_table
explicit_import = {ei_module_n=ste_index, ei_position=import_file_position,
ei_symbols=expl_imp_indices, ei_qualified=import_qualified}
......
......@@ -10,7 +10,7 @@ import syntax, checksupport
:: ExplicitImport = ! {
ei_module_n :: !Int,
ei_position :: !Position,
ei_symbols :: ![ImportNrAndIdents],
ei_symbols :: !ImportSymbols [ImportNrAndIdents],
ei_qualified:: !ImportQualified
}
......
......@@ -112,9 +112,9 @@ solveExplicitImports :: !(IntKeyHashtable [ExplicitImport]) !{#Int} !Index
-> (!.SolvedImports,! (!v:{#DclModule},!.{#Int},!{!.ExplImpInfo},!.CheckState))
solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod (dcl_modules, visited_modules, expl_imp_info, cs)
# import_indices = ikhSearch` importing_mod expl_imp_indices_ikh
expl_imp_indices = [ imports \\ imports=:{ei_symbols=[_:_],ei_qualified=NotQualified} <- import_indices ]
qualified_expl_imp_indices = [ imports \\ imports=:{ei_symbols=[_:_],ei_qualified=Qualified} <- import_indices ]
impl_imports = [ (ei_module_n,ei_position) \\ imports=:{ei_module_n,ei_position,ei_symbols=[]} <- import_indices ]
(expl_imp_indices,qualified_expl_imp_indices,impl_imports) = split_imports import_indices
state = (dcl_modules, visited_modules, expl_imp_info, cs)
path = [importing_mod]
(expl_imports, state)
......@@ -126,8 +126,21 @@ solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod
qualified_expl_imp_indices state
= ({ si_explicit=expl_imports, si_qualified_explicit=qualified_expl_imports, si_implicit=impl_imports }, state)
where
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 []
= ([],[],[])
solve_expl_imp_from_module expl_imp_indices_ikh modules_in_component_set path
{ei_module_n=imported_mod, ei_position=position, ei_symbols=imported_symbols} (dcl_modules, visited_modules, expl_imp_info, cs)
{ei_module_n=imported_mod, ei_position=position, ei_symbols=ImportSymbolsOnly imported_symbols} (dcl_modules, visited_modules, expl_imp_info, cs)
# (not_exported_symbols,decl_accu, unsolved_belonging, visited_modules, expl_imp_info)
= search_expl_imp_symbols imported_symbols expl_imp_indices_ikh modules_in_component_set path imported_mod
([],[], [], visited_modules, expl_imp_info)
......@@ -139,7 +152,7 @@ solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod
= ((decl_accu, position), (dcl_modules, visited_modules, expl_imp_info, cs))
solve_qualified_expl_imp_from_module expl_imp_indices_ikh modules_in_component_set path
{ei_module_n=imported_mod, ei_position=position, ei_symbols=imported_symbols} (dcl_modules, visited_modules, expl_imp_info, cs)
{ei_module_n=imported_mod, ei_position=position, ei_symbols=ImportSymbolsOnly imported_symbols} (dcl_modules, visited_modules, expl_imp_info, cs)
# (not_exported_symbols,decl_accu, unsolved_belonging, visited_modules, expl_imp_info)
= search_qualified_expl_imp_symbols imported_symbols expl_imp_indices_ikh modules_in_component_set path imported_mod
([],[], [], visited_modules, expl_imp_info)
......@@ -344,22 +357,24 @@ solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod
[imported_mod:path]
eii_declaring_modules (bitvectSet imported_mod visited_modules)
try_children [{ei_module_n=imp_imp_mod,ei_symbols=imp_imp_symbols}:imports] expl_imp_indices_ikh
try_children [{ei_module_n=imp_imp_mod,ei_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
= 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
# (found, opt_belongs)
= search_imported_symbol imported_symbol imp_imp_symbols
| not (found && implies (belong_nr<>cUndef) (belong_ident_found belong_ident opt_belongs))
= 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
= case ei_symbols of
ImportSymbolsAll
-> 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
ImportSymbolsOnly imp_imp_symbols
// follow the path trough an explicit import only if the symbol is listed there
# (found, opt_belongs)
= search_imported_symbol imported_symbol imp_imp_symbols
| not (found && implies (belong_nr<>cUndef) (belong_ident_found belong_ident opt_belongs))
-> 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
where
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
......
......@@ -1176,7 +1176,7 @@ wantModuleImports scanContext ident_class pState
(first_ident, pState) = stringToIdent first_name ident_class pState
(file_name, line_nr, pState) = getFileAndLineNr pState
position = LinePos file_name line_nr
module_import = {import_module = first_ident, import_symbols = [], import_file_position = position, import_qualified = import_qualified}
module_import = {import_module = first_ident, import_symbols = ImportSymbolsAll, import_file_position = position, import_qualified = import_qualified}
(token, pState) = nextToken scanContext pState
| token == CommaToken
# (rest, pState) = wantModuleImports scanContext ident_class pState
......@@ -1193,11 +1193,11 @@ wantFromImports pState
| case token of IdentToken "qualified" -> True ; _ -> False
# (import_symbols, pState) = wantImportDeclarations pState
pState = wantEndOfDefinition "from imports" pState
= ( { import_module = mod_ident, import_symbols = import_symbols,
= ( { import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,
import_file_position = LinePos file_name line_nr, import_qualified = Qualified }, pState)
# (import_symbols, pState) = wantImportDeclarationsT token pState
pState = wantEndOfDefinition "from imports" pState
= ( { import_module = mod_ident, import_symbols = import_symbols,
= ( { import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,
import_file_position = LinePos file_name line_nr, import_qualified = NotQualified }, pState)
where
wantImportDeclarations pState
......
......@@ -1128,7 +1128,7 @@ where
= (False, No,NoIndex, [],cached_modules, files, ca)
# pdefs = mod.mod_defs
# (_, defs, imports, imported_objects,foreign_exports,ca) = reorganiseDefinitionsAndAddTypes mod_ident support_dynamics False pdefs ca
# mod = { mod & mod_imports = imports, mod_imported_objects = imported_objects, mod_defs = defs}
# mod = { mod & mod_imports = imports, mod_imported_objects = imported_objects, mod_defs = defs}
# cached_modules = [mod.mod_ident:cached_modules]
# (import_ok, parsed_modules,files, ca) = scanModules imports [] cached_modules searchPaths support_generics support_dynamics modtimefunction files ca
= (import_ok, Yes mod, NoIndex,parsed_modules, cached_modules,files, ca)
......@@ -1455,11 +1455,11 @@ determine_symbols_of_conses [{pc_cons_ident,pc_cons_arity} : conses] next_cons_i
determine_symbols_of_conses [] next_cons_index
= ([], next_cons_index)
make_implicit_qualified_imports_explicit [import_=:{import_qualified=Qualified,import_symbols=[],import_module,import_file_position}:imports] hash_table
make_implicit_qualified_imports_explicit [import_=:{import_qualified=Qualified,import_symbols=ImportSymbolsAll,import_module,import_file_position}:imports] hash_table
# (qualified_idents,hash_table) = get_qualified_idents_from_hash_table import_module hash_table
# import_declarations = qualified_idents_to_import_declarations qualified_idents
# (imports,hash_table) = make_implicit_qualified_imports_explicit imports hash_table
= ([{import_ & import_symbols=import_declarations}:imports],hash_table)
= ([{import_ & import_symbols=ImportSymbolsOnly import_declarations}:imports],hash_table)
make_implicit_qualified_imports_explicit [import_:imports] hash_table
# (imports,hash_table) = make_implicit_qualified_imports_explicit imports hash_table
= ([import_:imports],hash_table)
......@@ -1486,7 +1486,7 @@ reorganiseDefinitionsAndAddTypes mod_ident support_dynamics icl_module defs ca
= predefined_idents.[PD_CleanTypes]
# clean_types_module =
{ import_module = clean_types_module_ident
, import_symbols = []
, import_symbols = ImportSymbolsAll
, import_file_position = NoPos
, import_qualified = NotQualified
}
......
......@@ -475,11 +475,15 @@ cNameLocationDependent :== True
:: Import =
{ import_module :: !Ident
, import_symbols :: ![ImportDeclaration]
, import_symbols :: !ImportSymbols [ImportDeclaration]
, import_file_position:: !Position // for error messages
, import_qualified :: !ImportQualified
}
:: ImportSymbols import_declarations
= ImportSymbolsAll
| ImportSymbolsOnly !import_declarations
:: ImportQualified = NotQualified | Qualified
instance toString Import, AttributeVar, TypeAttribute, Annotation
......
......@@ -825,7 +825,9 @@ where
instance <<< Import
where
(<<<) file {import_module, import_symbols}
(<<<) file {import_module, import_symbols=ImportSymbolsAll}
= file <<< "import " <<< import_module
(<<<) file {import_module, import_symbols=ImportSymbolsOnly import_symbols}
= file <<< "import " <<< import_module <<< import_symbols
instance <<< ImportDeclaration
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment