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

improve "multiply defined" error, add module names of the definitions to the error message

parent 4fabf567
......@@ -1815,7 +1815,7 @@ checkDclComponent components_array components_importing_module_a expl_imp_indice
check_expl_imp_completeness_of_dcl_mod_within_non_trivial_component mod_index {si_explicit,si_qualified_explicit} (dcl_modules, macro_defs,hp_expression_heap, cs)
# ({dcl_declared}, dcl_modules) = dcl_modules![mod_index]
({dcls_local_for_import, dcls_import}) = dcl_declared
cs = addDeclarationsOfDclModToSymbolTable mod_index dcls_local_for_import dcls_import cs
(dcl_modules,cs) = addDeclarationsOfDclModToSymbolTable mod_index dcls_local_for_import dcls_import dcl_modules cs
(dcl_modules, macro_defs,hp_expression_heap, cs=:{cs_symbol_table})
= checkExplicitImportCompleteness si_explicit si_qualified_explicit dcl_modules macro_defs hp_expression_heap cs
cs_symbol_table = removeImportsAndLocalsOfModuleFromSymbolTable dcl_declared cs.cs_symbol_table
......@@ -2607,8 +2607,8 @@ check_module2 mod_ident mod_modification_time mod_imported_objects mod_imports m
(modules, heaps, cs)
= checkInstancesOfDclModule cPredefinedModuleIndex deferred_stuff (modules, heaps, cs)
({dcl_declared={dcls_import,dcls_local,dcls_local_for_import}}, modules) = modules![ste_index]
= (modules, macro_defs, heaps,
addDeclarationsOfDclModToSymbolTable ste_index dcls_local_for_import dcls_import cs)
(modules,cs) = addDeclarationsOfDclModToSymbolTable ste_index dcls_local_for_import dcls_import modules cs
= (modules, macro_defs, heaps, cs)
check_predefined_module No support_dynamics modules macro_defs heaps cs
= (modules, macro_defs, heaps, cs)
......@@ -2964,22 +2964,21 @@ addImportedSymbolsToSymbolTable importing_mod opt_macro_range modules_in_compone
# visited_modules = bitvectSet mod_index visited_modules
({ dcls_import, dcls_local_for_import }, dcl_modules)
= dcl_modules![mod_index].dcl_declared
(decls_accu, cs)
(decls_accu,dcl_modules,cs)
= foldlArraySt (add_declaration opt_macro_range importing_mod)
dcls_local_for_import (decls_accu, cs)
dcls_local_for_import (decls_accu,dcl_modules,cs)
| not (bitvectSelect mod_index modules_in_component_set)
// this module is outside of the actual component. All imported symbols are
// already known
# (decls_accu, cs)
// this module is outside of the actual component. All imported symbols are already known
# (decls_accu,dcl_modules,cs)
= foldlArraySt (add_declaration opt_macro_range importing_mod)
dcls_import (decls_accu, cs)
dcls_import (decls_accu,dcl_modules,cs)
= (decls_accu, visited_modules, dcl_modules, cs)
# {si_explicit, si_implicit} = ikhSearch` mod_index imports_ikh
(decls_accu, cs)
(decls_accu,dcl_modules,cs)
= foldSt (\(decls, _) state ->
foldSt (\decl state -> add_declaration opt_macro_range importing_mod decl state)
decls state)
si_explicit (decls_accu, cs)
si_explicit (decls_accu,dcl_modules,cs)
= foldSt (\(mod_index, _) state
-> add_impl_imported_symbols opt_macro_range importing_mod modules_in_component_set
imports_ikh mod_index state)
......@@ -2990,26 +2989,26 @@ addImportedSymbolsToSymbolTable importing_mod opt_macro_range modules_in_compone
# cs = pushErrorAdmin (newPosition import_ident position) cs
(decls_accu, dcl_modules, cs) = foldSt (add_expl_imp_declaration opt_macro_range importing_mod) decls (decls_accu, dcl_modules, cs)
= (decls_accu, dcl_modules, popErrorAdmin cs)
add_declaration :: (Optional IndexRange) Int Declaration *([Declaration],*CheckState) -> (![Declaration],!*CheckState)
add_declaration opt_dcl_macro_range importing_mod declaration (decls_accu, cs)
# (not_already_imported, cs)
= add_declaration_to_symbol_table opt_dcl_macro_range declaration importing_mod cs
add_declaration :: (Optional IndexRange) Int Declaration *([Declaration],!*{#DclModule},*CheckState) -> (![Declaration],!*{#DclModule},!*CheckState)
add_declaration opt_dcl_macro_range importing_mod declaration (decls_accu,dcl_modules,cs)
# (not_already_imported,dcl_modules,cs)
= add_declaration_to_symbol_table_ opt_dcl_macro_range declaration importing_mod dcl_modules cs
| not_already_imported
= ([declaration:decls_accu], cs)
= (decls_accu, cs)
= ([declaration:decls_accu],dcl_modules,cs)
= (decls_accu,dcl_modules,cs)
add_expl_imp_declaration opt_dcl_macro_range importing_mod declaration (decls_accu, dcl_modules, cs)
# (not_already_imported, cs)
= add_declaration_to_symbol_table opt_dcl_macro_range declaration importing_mod cs
# (not_already_imported,dcl_modules,cs)
= add_declaration_to_symbol_table_ opt_dcl_macro_range declaration importing_mod dcl_modules cs
| not_already_imported
= ([declaration:decls_accu], dcl_modules, cs)
= (decls_accu, dcl_modules, cs)
add_declaration_to_symbol_table opt_dcl_macro_range (Declaration {decl_kind=STE_FunctionOrMacro _, decl_ident, decl_index}) _ cs
= addImportedFunctionOrMacro opt_dcl_macro_range decl_ident decl_index cs
add_declaration_to_symbol_table yes_for_icl_module (Declaration {decl_kind=decl_kind=:STE_Imported def_kind def_mod, decl_ident, decl_index, decl_pos}) importing_mod cs
= addSymbol yes_for_icl_module decl_ident decl_pos decl_kind def_kind decl_index def_mod importing_mod cs
add_declaration_to_symbol_table_ opt_dcl_macro_range (Declaration {decl_kind=STE_FunctionOrMacro _, decl_ident, decl_index}) _ dcl_modules cs
= addImportedFunctionOrMacro opt_dcl_macro_range decl_ident decl_index dcl_modules cs
add_declaration_to_symbol_table_ yes_for_icl_module (Declaration {decl_kind=decl_kind=:STE_Imported def_kind def_mod, decl_ident, decl_index, decl_pos}) importing_mod dcl_modules cs
= addSymbol yes_for_icl_module decl_ident decl_pos decl_kind def_kind decl_index def_mod importing_mod dcl_modules cs
updateExplImpInfo :: [Int] Index {!Declaration} {!Declaration} u:{#DclModule} ExplImpInfos *SymbolTable
-> (u:{#DclModule},!ExplImpInfos,.SymbolTable)
......
......@@ -111,10 +111,10 @@ retrieveGlobalDefinition :: !SymbolTableEntry !STE_Kind !Index -> (!Index, !Inde
addLocalFunctionDefsToSymbolTable :: !Level !Index !Index !Bool !*{#FunDef} !*SymbolTable !*ErrorAdmin -> (!*{# FunDef}, !*SymbolTable, !*ErrorAdmin)
addLocalDclMacroDefsToSymbolTable :: !Level !Int !Index !Index !*{#*{#FunDef}} !*SymbolTable !*ErrorAdmin -> (!*{#*{#FunDef}}, !*SymbolTable, !*ErrorAdmin)
addDefToSymbolTable :: !Level !Index !Ident !STE_Kind !*SymbolTable !*ErrorAdmin -> (!* SymbolTable, !*ErrorAdmin)
addDeclarationsOfDclModToSymbolTable :: .Int !{!Declaration} !{!Declaration} !*CheckState -> .CheckState;
addDeclarationsOfDclModToSymbolTable :: Int !{!Declaration} !{!Declaration} !*{#DclModule} !*CheckState -> (!*{#DclModule},!*CheckState)
addGlobalDefinitionsToSymbolTable :: ![Declaration] !*CheckState -> .CheckState;
addSymbol :: !(Optional a) !Ident !Position !STE_Kind !STE_Kind !.Int !.Int !Int !*CheckState -> (!Bool, !.CheckState)
addImportedFunctionOrMacro :: !(Optional IndexRange) !Ident !Int !*CheckState -> (!Bool, !.CheckState)
addSymbol :: !(Optional a) !Ident !Position !STE_Kind !STE_Kind !.Int !.Int !Int !*{#DclModule} !*CheckState -> (!Bool,!*{#DclModule},!*CheckState)
addImportedFunctionOrMacro :: !(Optional IndexRange) !Ident !Int !*{#DclModule} !*CheckState -> (!Bool,!*{#DclModule},!.CheckState)
removeImportedSymbolsFromSymbolTable :: Declaration !*SymbolTable -> .SymbolTable
removeFieldFromSelectorDefinition :: !Ident .Int .Int !*(Heap SymbolTableEntry) -> .Heap SymbolTableEntry;
......
......@@ -217,66 +217,65 @@ addDefToSymbolTable level def_index def_ident=:{id_info} def_kind symbol_table e
= (symbol_table <:= (id_info,entry), error)
= (symbol_table, checkError def_ident "already defined" error)
addDeclarationsOfDclModToSymbolTable :: .Int !{!Declaration} !{!Declaration} !*CheckState -> .CheckState;
addDeclarationsOfDclModToSymbolTable ste_index locals imported cs
# cs=add_imports_in_array_to_symbol_table 0 imported cs
= addLocalSymbolsForImportToSymbolTable 0 locals ste_index cs
addDeclarationsOfDclModToSymbolTable :: Int !{!Declaration} !{!Declaration} !*{#DclModule} !*CheckState -> (!*{#DclModule},!*CheckState)
addDeclarationsOfDclModToSymbolTable ste_index locals imported dcl_modules cs
# (dcl_modules,cs) = add_imports_in_array_to_symbol_table 0 imported dcl_modules cs
= addLocalSymbolsForImportToSymbolTable 0 locals ste_index dcl_modules cs
where
add_imports_in_array_to_symbol_table symbol_index symbols cs=:{cs_x}
add_imports_in_array_to_symbol_table :: !Int !{!Declaration} !*{#DclModule} !*CheckState -> (!*{#DclModule},!*CheckState)
add_imports_in_array_to_symbol_table symbol_index symbols dcl_modules cs=:{cs_x}
| symbol_index<size symbols
#! (Declaration {decl_ident,decl_pos,decl_kind},symbols) = symbols![symbol_index]
= case decl_kind of
STE_Imported def_kind def_mod
#! declaration = symbols.[symbol_index]
# (Declaration {decl_index}) = declaration
# (_, cs)
= addSymbol No decl_ident decl_pos decl_kind
def_kind decl_index def_mod cUndef cs
-> add_imports_in_array_to_symbol_table (symbol_index+1) symbols cs
# (_,dcl_modules,cs) = addSymbol No decl_ident decl_pos decl_kind def_kind decl_index def_mod cUndef dcl_modules cs
-> add_imports_in_array_to_symbol_table (symbol_index+1) symbols dcl_modules cs
STE_FunctionOrMacro _
#! declaration = symbols.[symbol_index]
# (Declaration {decl_index}) = declaration
# (_, cs)
= addImportedFunctionOrMacro No decl_ident decl_index cs
-> add_imports_in_array_to_symbol_table (symbol_index+1) symbols cs
= cs
# (_,dcl_modules,cs) = addImportedFunctionOrMacro No decl_ident decl_index dcl_modules cs
-> add_imports_in_array_to_symbol_table (symbol_index+1) symbols dcl_modules cs
= (dcl_modules,cs)
addLocalSymbolsForImportToSymbolTable :: !Int !{!Declaration} Int !*CheckState -> .CheckState;
addLocalSymbolsForImportToSymbolTable symbol_index symbols mod_index cs
addLocalSymbolsForImportToSymbolTable :: !Int !{!Declaration} Int !*{#DclModule} !*CheckState -> (!*{#DclModule},!*CheckState)
addLocalSymbolsForImportToSymbolTable symbol_index symbols mod_index dcl_modules cs
| symbol_index<size symbols
# (Declaration {decl_ident,decl_pos,decl_kind,decl_index},symbols) = symbols![symbol_index]
= case decl_kind of
STE_FunctionOrMacro _
# (_, cs)
= addImportedFunctionOrMacro No decl_ident decl_index cs
-> addLocalSymbolsForImportToSymbolTable (symbol_index+1) symbols mod_index cs
# (_,dcl_modules,cs) = addImportedFunctionOrMacro No decl_ident decl_index dcl_modules cs
-> addLocalSymbolsForImportToSymbolTable (symbol_index+1) symbols mod_index dcl_modules cs
STE_Imported def_kind def_mod
# (_, cs)
= addSymbol No decl_ident decl_pos decl_kind
def_kind decl_index mod_index cUndef cs
-> addLocalSymbolsForImportToSymbolTable (symbol_index+1) symbols mod_index cs
= cs
addImportedFunctionOrMacro :: !(Optional IndexRange) !Ident !Int !*CheckState -> (!Bool, !.CheckState)
addImportedFunctionOrMacro opt_dcl_macro_range ident=:{id_info} def_index cs=:{cs_symbol_table}
# (_,dcl_modules,cs) = addSymbol No decl_ident decl_pos decl_kind def_kind decl_index mod_index cUndef dcl_modules cs
-> addLocalSymbolsForImportToSymbolTable (symbol_index+1) symbols mod_index dcl_modules cs
= (dcl_modules,cs)
addImportedFunctionOrMacro :: !(Optional IndexRange) !Ident !Int !*{#DclModule} !*CheckState -> (!Bool,!*{#DclModule},!.CheckState)
addImportedFunctionOrMacro opt_dcl_macro_range ident=:{id_info} def_index dcl_modules cs=:{cs_symbol_table}
# (entry, cs_symbol_table) = readPtr id_info cs_symbol_table
cs = { cs & cs_symbol_table = cs_symbol_table }
= case entry.ste_kind of
STE_Empty
-> (True, { cs & cs_symbol_table = NewEntry cs.cs_symbol_table id_info (STE_FunctionOrMacro [])
-> (True, dcl_modules, { cs & cs_symbol_table = NewEntry cs.cs_symbol_table id_info (STE_FunctionOrMacro [])
def_index cModuleScope entry})
STE_FunctionOrMacro _
| entry.ste_index == def_index || within_opt_range opt_dcl_macro_range def_index
-> (False, cs)
-> (False, dcl_modules, cs)
STE_Imported _ module_n
| module_n>=0 && module_n<size dcl_modules
# (dcl_name,dcl_modules) = dcl_modules![module_n].dcl_name
cs & cs_error = checkError ident ("multiply defined (also defined in module "+++toString dcl_name+++")") cs.cs_error
-> (False, dcl_modules, cs)
_
-> (False, { cs & cs_error = checkError ident "multiply defined" cs.cs_error})
-> (False, dcl_modules, { cs & cs_error = checkError ident "multiply defined" cs.cs_error})
where
within_opt_range (Yes {ir_from, ir_to}) i
= ir_from<=i && i<ir_to
within_opt_range No _
= False
addFieldToSelectorDefinition :: !Ident (Global .Int) !*CheckState -> .CheckState;
addFieldToSelectorDefinition {id_info} glob_field_index cs=:{cs_symbol_table}
# (entry, cs_symbol_table) = readPtr id_info cs_symbol_table
......@@ -287,32 +286,38 @@ addFieldToSelectorDefinition {id_info} glob_field_index cs=:{cs_symbol_table}
_
-> { cs & cs_symbol_table = NewEntry cs.cs_symbol_table id_info (STE_Selector [glob_field_index]) NoIndex cModuleScope entry }
addSymbol :: !(Optional a) !Ident !Position !STE_Kind !STE_Kind !.Int !.Int !Int !*CheckState -> (!Bool, !.CheckState)
addSymbol yes_for_icl_module ident pos decl_kind def_kind def_index def_mod importing_mod cs=:{cs_symbol_table}
addSymbol :: !(Optional a) !Ident !Position !STE_Kind !STE_Kind !.Int !.Int !Int !*{#DclModule} !*CheckState -> (!Bool,!*{#DclModule},!*CheckState)
addSymbol yes_for_icl_module ident pos decl_kind def_kind def_index def_mod importing_mod dcl_modules cs=:{cs_symbol_table}
# (entry, cs_symbol_table) = readPtr ident.id_info cs_symbol_table
= add_indirectly_imported_symbol yes_for_icl_module entry ident pos def_kind def_index def_mod
importing_mod { cs & cs_symbol_table = cs_symbol_table }
importing_mod dcl_modules {cs & cs_symbol_table = cs_symbol_table}
where
add_indirectly_imported_symbol _ {ste_kind = STE_Empty} {id_info} _ def_kind def_index def_mod _ cs=:{cs_symbol_table}
add_indirectly_imported_symbol _ {ste_kind = STE_Empty} {id_info} _ def_kind def_index def_mod _ dcl_modules cs=:{cs_symbol_table}
# (entry, cs_symbol_table) = readPtr id_info cs_symbol_table
cs = { cs & cs_symbol_table = NewEntry cs_symbol_table id_info decl_kind def_index cModuleScope entry}
= case def_kind of
STE_Field selector_id
-> (True, addFieldToSelectorDefinition selector_id { glob_module = def_mod, glob_object = def_index } cs)
-> (True, dcl_modules, addFieldToSelectorDefinition selector_id { glob_module = def_mod, glob_object = def_index } cs)
_
-> (True, cs)
add_indirectly_imported_symbol _ {ste_kind = STE_Imported kind mod_index, ste_index} _ _ def_kind def_index def_mod _ cs
-> (True, dcl_modules, cs)
add_indirectly_imported_symbol _ {ste_kind = STE_Imported kind mod_index, ste_index} _ _ def_kind def_index def_mod _ dcl_modules cs
| kind == def_kind && mod_index == def_mod && ste_index == def_index
= (False, cs)
add_indirectly_imported_symbol (Yes _) _ _ _ def_kind def_index def_mod _ cs
= (False, dcl_modules, cs)
add_indirectly_imported_symbol (Yes _) _ _ _ def_kind def_index def_mod _ dcl_modules cs
| def_mod == cs.cs_x.x_main_dcl_module_n
// an icl module imports one of it's definitions from the dcl module
= (False, cs)
add_indirectly_imported_symbol _ _ _ _ def_kind def_index def_mod importing_mod cs
= (False, dcl_modules, cs)
add_indirectly_imported_symbol _ _ _ _ def_kind def_index def_mod importing_mod dcl_modules cs
| importing_mod==def_mod // a dcl module imports a definition from itself (cycle)
= (False, cs)
add_indirectly_imported_symbol _ entry ident pos def_kind def_index def_mod _ cs=:{cs_error}
= (False, { cs & cs_error = checkError ident "multiply defined" cs_error})
= (False, dcl_modules, cs)
add_indirectly_imported_symbol _ {ste_kind = STE_Imported _ mod_index, ste_index} _ _ def_kind def_index def_mod _ dcl_modules cs=:{cs_error}
| mod_index>=0 && mod_index<size dcl_modules && def_mod>=0 && def_mod<size dcl_modules
# (dcl_name1,dcl_modules) = dcl_modules![def_mod].dcl_name
(dcl_name2,dcl_modules) = dcl_modules![mod_index].dcl_name
cs & cs_error = checkError ident ("multiply defined (in module "+++toString dcl_name1+++" and already in module "+++toString dcl_name2+++")") cs_error
= (False, dcl_modules, cs)
add_indirectly_imported_symbol _ entry ident pos def_kind def_index def_mod _ dcl_modules cs=:{cs_error}
= (False, dcl_modules, { cs & cs_error = checkError ident "multiply defined" cs_error})
addGlobalDefinitionsToSymbolTable :: ![Declaration] !*CheckState -> .CheckState;
addGlobalDefinitionsToSymbolTable decls cs
......
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