definition module ReadObject;

import StdEnv;
	
import SymbolTable;	

//1.3
from lib import read_static_lib_files, ReadStaticLibState, ImportLibrary, read_static_lib_files_new;
from Redirections import PrefixSet,ConstructorInfo,RedirectionState, RedirectionTable, LabelNameTable, ModuleNameTable, RedirectionInfo, /*LabelPrefixes,*/ Maybe, List, LabelName, BitSet;
//3.1
/*2.0
import BitSet;
from Redirections import ::RedirectionState;
import StdMaybe;
0.2*/

//ReadXcoffM :: !Bool !String !Int !NamesTable !Bool !Int !*Files -> ((!Bool,![String],![*Xcoff],!NamesTable),!Files);  
ReadXcoffM :: !Bool !String !Int !NamesTable !Bool !Int !*RedirectionState !*Files  -> ((!Bool,![String],![*Xcoff],!NamesTable,!*RedirectionState),!Files);  

read_xcoff_files :: !Bool ![String] !NamesTable !Bool !Files !Int !*RedirectionState -> (!Bool,![String],!Sections,!Int,![*Xcoff],!NamesTable,!Files,!*RedirectionState);
//read_xcoff_files :: !Bool ![String] !NamesTable !Bool !Files !Int -> (!Bool,![String],!Sections,!Int,![*Xcoff],!NamesTable,!Files);
// 	NEW read_library_files :: ![String] !Int !Int !*Files !NamesTable -> (![String],!LibraryList,!Int,!*Files,!NamesTable);
//read_library_files :: ![String] !Int !Int !*f !*NamesTable -> *(![String],!LibraryList,!Int,!*f,!*NamesTable) | FileSystem f;

//read_xcoff_file :: !String !Int !NamesTable !Bool !*File !Int -> (!Bool,![String],!*String,!*String,!*Xcoff,!NamesTable,!*File);
//read_xcoff_file :: !String !Int !NamesTable !Bool !*File !Int !RedirectionState -> (!Bool,![String],!*String,!*String,!*Xcoff,!NamesTable,!*File,!RedirectionState);
read_xcoff_file :: !String !Int !NamesTable !Bool !*File !Int !*RedirectionState -> (!Bool,![String],!*String,!*String,!*Xcoff,!NamesTable,!*File,!*RedirectionState);

// this function does the reading of an object file		
read_xcoff_fileI :: !String !String !Int !NamesTable !Bool !*File !Int !*RedirectionState -> (!Bool,![String],!*String,!*String,!*Xcoff,!NamesTable,!*File,!*RedirectionState);

//ReadXcoff :: !String !Int !NamesTable !Bool !*Files !Int -> (![String],!*String,!*String,!*Xcoff,!NamesTable,!Files);  

// NEW read_library_file :: !String !Int !*Files !NamesTable -> (!Bool,!String,!LibrarySymbolsList,!Int,!*Files,!NamesTable);
//read_library_file :: !String !Int !*f !*NamesTable -> *(!Bool,!String,!LibrarySymbolsList,!Int,!*f,!*NamesTable) | FileSystem f;

/*
	This function extracts all external symbols from an object file.
	
	Result (n th component):
	1	= list of errors
	2	= # external symbols
	3 	= list of names for each external defined symbol
	4 	= list of names for each external referenced symbol (inter object reference)
	5	= files 	
*/	
//read_external_symbol_names_from_xcoff_file :: !String !*Files -> (![!String], !Int, !Int, ![!String], ![!String], !*Files);
read_external_symbol_names_from_xcoff_file :: !String !*Files ->  ([String], !Int, !Int, [String],[String],!*Files);
read_coff_header :: !*File -> !(!Bool,!Int,!Int,!Int,!*File);

// NEW ...
class ExtFileSystem f
where {
	rlf_fopen :: !{#Char} !Int !*f -> (!Bool,!*File,!*f);
	rlf_fclose :: !*File !*f -> (!Bool,!*f);
	rlf_freadline :: !*File !*f -> (!*{#Char},!*File,!*f)
};

instance ExtFileSystem Files;
//read_library_files :: ![String] !Int !Int !*a !*NamesTable -> *(![String],!LibraryList,!Int,!*a,!*NamesTable) | ExtFileSystem a;
read_library_files list library_n n_library_symbols0 files0 names_table0 :== read_library_files_new True list library_n n_library_symbols0 files0 names_table0;

//read_library_files :: ![String] !Int !Int !*Files !NamesTable -> (![String],!LibraryList,!Int,!*Files,!NamesTable);
read_library_files_new :: !Bool ![String] !Int !Int !*a !*NamesTable -> *(![String],!LibraryList,!Int,!*a,!*NamesTable) | ExtFileSystem a;



//read_library_file :: !String !Int !*a !*NamesTable -> *(!Bool,!String,!LibrarySymbolsList,!Int,!*a,!*NamesTable) | ExtFileSystem a;
read_library_file library_file_name library_n files names_table :== read_library_file_new True library_file_name library_n files names_table;

// old; should be removed
//read_library_file :: !String !Int !*Files !NamesTable -> (!Bool,!String,!LibrarySymbolsList,!Int,!*Files,!NamesTable);
read_library_file_new :: !Bool !String !Int !*a !*NamesTable -> *(!Bool,!String,!LibrarySymbolsList,!Int,!*a,!*NamesTable) | ExtFileSystem a;

// ... NEW


// *****************************************************************************************************************************
read_library_files2 :: [[String]] !Int !Int !*{!NamesTableElement} -> *(!LibraryList,!Int,!*{!NamesTableElement});

/*
// TEMP ...
:: *RedirectionState = 
	 RedirectionState;

create_redirection_state :: !RedirectionState;	 
// ... TEMP
*/

class ImportDynamicLibrarySymbols a :: a !Int !Int !*NamesTable -> (!Int,!Int,!*NamesTable);

instance ImportDynamicLibrarySymbols LibraryList;

decode_line_from_library_file :: String -> Maybe String;
