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

search and open file before calling wantModule

parent 3b685fa2
/*
/*
module owner: Ronny Wichers Schreur
*/
implementation module frontend
......@@ -28,9 +28,13 @@ frontSyntaxTree cached_dcl_macros cached_dcl_mods main_dcl_module_n predef_symbo
frontEndInterface :: !FrontEndOptions !Ident !SearchPaths !{#DclModule} !*{#*{#FunDef}} !(Optional Bool) !*PredefinedSymbols !*HashTable (ModTimeFunction *Files) !*Files !*File !*File !*File !(Optional *File) !*Heaps
-> ( !Optional *FrontEndSyntaxTree,!*{#*{#FunDef}},!{#DclModule},!Int,!*PredefinedSymbols, !*HashTable, !*Files, !*File, !*File, !*File, !Optional *File, !*Heaps)
frontEndInterface options mod_ident search_paths cached_dcl_modules cached_dcl_macros list_inferred_types predef_symbols hash_table modtimefunction files error io out tcl_file heaps
// # files = trace_n ("Compiling "+++mod_ident.id_name) files
# (opt_file_dir_time,files) = fopenInSearchPaths mod_ident.id_name ".icl" search_paths FReadData modtimefunction files
| case opt_file_dir_time of No -> True; _ -> False
# error = moduleCouldNotBeImportedError True mod_ident NoPos error
= (No,{},{},0,predef_symbols, hash_table, files, error, io, out, tcl_file, heaps)
# (Yes (mod_file,mod_dir,mod_time)) = opt_file_dir_time
# (ok,dynamic_type_used,mod,hash_table,error,files)
= wantModule cWantIclFile mod_ident NoPos options.feo_generics(hash_table /* ---> ("Parsing:", mod_ident)*/) error search_paths modtimefunction files
= wantModule mod_file mod_time cWantIclFile mod_ident NoPos options.feo_generics hash_table error files
| not ok
= (No,{},{},0,predef_symbols, hash_table, files, error, io, out, tcl_file, heaps)
# cached_module_idents = [dcl_mod.dcl_name \\ dcl_mod<-:cached_dcl_modules]
......
......@@ -10,5 +10,7 @@ import syntax, hashtable, scanner, predef
cWantIclFile :== True
cWantDclFile :== False
wantModule :: !Bool !Ident !Position !Bool !*HashTable !*File !SearchPaths (ModTimeFunction *Files) !*Files
wantModule :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files
-> (!Bool,!Bool,!ParsedModule, !*HashTable, !*File, !*Files)
moduleCouldNotBeImportedError :: !Bool !Ident !Position !*File -> *File
......@@ -267,18 +267,14 @@ isGlobalOrClassOrInstanceDefsContext parseContext :== parseContext bitand (cGlob
cWantIclFile :== True
cWantDclFile :== False
wantModule :: !Bool !Ident !Position !Bool !*HashTable !*File !SearchPaths (ModTimeFunction *Files) !*Files
wantModule :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files
-> (!Bool,!Bool,!ParsedModule, !*HashTable, !*File, !*Files)
wantModule iclmodule file_id=:{id_name} import_file_position support_generics hash_table error searchPaths modtimefunction files
= case openScanner id_name file_name_extension searchPaths modtimefunction files of
(Yes (scanState, modification_time), files)
# hash_table=set_hte_mark (if iclmodule 1 0) hash_table
# (ok,dynamic_type_used,mod,hash_table,file,files) = initModule file_name modification_time scanState hash_table error files
# hash_table=set_hte_mark 0 hash_table
-> (ok,dynamic_type_used,mod,hash_table,file,files)
(No, files)
-> let mod = { mod_ident = file_id, mod_modification_time = "", mod_type = MK_None, mod_imports = [], mod_imported_objects = [],mod_foreign_exports=[],mod_defs = [] } in
(False, False, mod, hash_table, error <<< "Error " <<< import_file_position <<< ": " <<< file_name <<< " could not be imported\n", files)
wantModule file modification_time iclmodule file_id=:{id_name} import_file_position support_generics hash_table error files
# scanState = openScanner file id_name file_name_extension
# hash_table=set_hte_mark (if iclmodule 1 0) hash_table
# (ok,dynamic_type_used,mod,hash_table,file,files) = initModule file_name modification_time scanState hash_table error files
hash_table=set_hte_mark 0 hash_table
= (ok,dynamic_type_used,mod,hash_table,file,files)
where
file_name = id_name +++ file_name_extension
file_name_extension = if iclmodule ".icl" ".dcl"
......@@ -373,6 +369,13 @@ where
# pState = parseError "want definitions" (Yes token) "End of file" pState
pState = wantEndOfDefinition "definitions" pState
= want_acc_definitions acc pState
moduleCouldNotBeImportedError :: !Bool !Ident !Position !*File -> *File
moduleCouldNotBeImportedError iclmodule file_id=:{id_name} import_file_position error
# file_name_extension = if iclmodule ".icl" ".dcl"
file_name = id_name +++ file_name_extension
= error <<< "Error " <<< import_file_position <<< ": " <<< file_name <<< " could not be imported\n"
/*
[Definition] on local and global level
*/
......
......@@ -1035,7 +1035,14 @@ parseAndScanDclModule :: !Ident !Position ![ScannedModule] ![Ident] !SearchPaths
-> *(!Bool, ![ScannedModule],!*Files, !*CollectAdmin)
parseAndScanDclModule dcl_module import_file_position parsed_modules cached_modules searchPaths support_generics support_dynamics modtimefunction files ca
# {ca_error, ca_hash_table} = ca
# (parse_ok,dynamic_type_used,mod, ca_hash_table, err_file, files) = wantModule cWantDclFile dcl_module import_file_position support_generics ca_hash_table ca_error.pea_file searchPaths modtimefunction files
# (opt_file_dir_time,files) = fopenInSearchPaths dcl_module.id_name ".dcl" searchPaths FReadData modtimefunction files
| case opt_file_dir_time of No -> True; _ -> False
# err_file = moduleCouldNotBeImportedError False dcl_module import_file_position ca_error.pea_file
# ca & ca_error={pea_file=err_file,pea_ok=True}
= (False, [MakeEmptyModule dcl_module MK_None: parsed_modules],files, ca)
# (Yes (mod_file,mod_dir,mod_time)) = opt_file_dir_time
# (parse_ok,dynamic_type_used,mod, ca_hash_table, err_file, files)
= wantModule mod_file mod_time cWantDclFile dcl_module import_file_position support_generics ca_hash_table ca_error.pea_file files
# ca = {ca & ca_hash_table=ca_hash_table, ca_error={pea_file=err_file,pea_ok=True} }
| parse_ok
= scan_dcl_module dcl_module mod parsed_modules searchPaths modtimefunction files ca
......@@ -1125,7 +1132,14 @@ where
| module_n_in_cache<>NoIndex
= (True,No,module_n_in_cache,[],cached_modules,files,ca)
# {ca_error, ca_hash_table} = ca
# (parse_ok,dynamic_type_used,mod, hash_table, err_file, /*predefs,*/ files) = wantModule cWantDclFile mod_ident NoPos support_generics ca_hash_table ca_error.pea_file searchPaths modtimefunction files
# (opt_file_dir_time,files) = fopenInSearchPaths mod_ident.id_name ".dcl" searchPaths FReadData modtimefunction files
| case opt_file_dir_time of No -> True; _ -> False
# err_file = moduleCouldNotBeImportedError False mod_ident NoPos ca_error.pea_file
# ca & ca_error={pea_file=err_file,pea_ok=True}
= (False, No,NoIndex, [],cached_modules, files, ca)
# (Yes (mod_file,mod_dir,mod_time)) = opt_file_dir_time
# (parse_ok,dynamic_type_used,mod, hash_table, err_file, files)
= wantModule mod_file mod_time cWantDclFile mod_ident NoPos support_generics ca_hash_table ca_error.pea_file files
# ca = {ca & ca_hash_table=hash_table, ca_error={pea_file=err_file,pea_ok=True}}
| not parse_ok
= (False, No,NoIndex, [],cached_modules, files, ca)
......
......@@ -148,7 +148,9 @@ instance replaceToken ScanState
class getPosition state :: !*state -> (!FilePosition,!*state) // Position of current Token (or Char)
instance getPosition ScanState
openScanner :: !String !String !SearchPaths (ModTimeFunction *Files) !*Files -> (!Optional (ScanState, {#Char}), !*Files) // state, file time
fopenInSearchPaths :: !{#Char} !{#Char} !SearchPaths !Int (ModTimeFunction *Files) !*Files -> (Optional (*File, {#Char}, {#Char}),!*Files)
openScanner :: !*File !String !String -> ScanState
closeScanner :: !ScanState !*Files -> *Files
setUseLayout :: !Bool !ScanState -> ScanState
......
......@@ -1629,26 +1629,20 @@ where
toString RightAssoc = "infixr "
toString NoAssoc = "infix "
openScanner :: !String !String !SearchPaths (ModTimeFunction *Files) !*Files -> (!Optional (ScanState, {#Char}), !*Files) // state, file time
openScanner file_name file_name_extension searchPaths modtimefunction files
= case fopenInSearchPaths file_name file_name_extension searchPaths FReadData modtimefunction files of
(No, files)
-> (No, files)
(Yes (file, time), files)
-> (Yes (ScanState { ss_input = Input
{ inp_stream = InFile file
, inp_filename = file_name +++ file_name_extension
, inp_pos = {fp_line = 1, fp_col = 0}
, inp_tabsize = 4
}
, ss_offsides = [(1,False)] // to generate offsides between global definitions
, ss_scanOptions = 0
, ss_tokenBuffer = Buffer0
}, time)
, files
)
openScanner :: !*File !String !String -> ScanState
openScanner file file_name file_name_extension
= ScanState { ss_input = Input
{ inp_stream = InFile file
, inp_filename = file_name +++ file_name_extension
, inp_pos = {fp_line = 1, fp_col = 0}
, inp_tabsize = 4
}
, ss_offsides = [(1,False)] // to generate offsides between global definitions
, ss_scanOptions = 0
, ss_tokenBuffer = Buffer0
}
fopenInSearchPaths :: !{#Char} !{#Char} !SearchPaths !Int (ModTimeFunction *f) !*f -> (Optional (*File, {#Char}),!*f) | FileSystem f
fopenInSearchPaths :: !{#Char} !{#Char} !SearchPaths !Int (ModTimeFunction *Files) !*Files -> (Optional (*File, {#Char}, {#Char}),!*Files)
fopenInSearchPaths moduleName fileNameExtension searchPaths mode modtimefunction f
# fileName = replace_dots_by_directory_separators moduleName +++ fileNameExtension
= case [path \\ (moduleName,path)<-searchPaths.sp_locations | moduleName == fileName] of
......@@ -1656,25 +1650,25 @@ fopenInSearchPaths moduleName fileNameExtension searchPaths mode modtimefunction
# fullFileName = path +++ fileName
# (opened, file, f) = fopen fullFileName mode f
| opened
-> getModificationTime file fullFileName modtimefunction f
-> getModificationTime file path fullFileName modtimefunction f
-> (No, f)
[]
-> fopenAnywhereInSearchPaths fileName searchPaths.sp_paths mode modtimefunction f
where
fopenAnywhereInSearchPaths :: !{#Char} ![{#Char}] !Int (ModTimeFunction *f) *f -> (Optional (*File, {#Char}),!*f) | FileSystem f
fopenAnywhereInSearchPaths :: !{#Char} ![{#Char}] !Int (ModTimeFunction *f) *f -> (Optional (*File, {#Char}, {#Char}),!*f) | FileSystem f
fopenAnywhereInSearchPaths fileName [path : paths] mode modtimefunction f
# fullFileName = path +++ fileName
# (opened, file, f) = fopen fullFileName mode f
| opened
= getModificationTime file fullFileName modtimefunction f
= getModificationTime file path fullFileName modtimefunction f
= fopenAnywhereInSearchPaths fileName paths mode modtimefunction f
fopenAnywhereInSearchPaths fileName [] _ _ f
= (No, f)
getModificationTime :: *File {#Char} (ModTimeFunction *f) *f -> (Optional (*File, {#Char}),!*f) | FileSystem f
getModificationTime file fullFileName modtimefunction f
getModificationTime :: *File {#Char} {#Char} (ModTimeFunction *f) *f -> (Optional (*File, {#Char}, {#Char}),!*f) | FileSystem f
getModificationTime file path fullFileName modtimefunction f
# (time, f) = modtimefunction fullFileName f
= (Yes (file, time), f)
= (Yes (file, path, time), f)
replace_dots_by_directory_separators :: !{#Char} -> *{#Char}
replace_dots_by_directory_separators file_name
......
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