diff -r 1dcf7bcfaf04 src/abstract_project.li --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/abstract_project.li Sun Aug 31 13:13:22 2008 +0200 @@ -0,0 +1,252 @@ +Section Header + + + name := ABSTRACT_PROJECT; + + - author := "Mildred Ki'Lya "; + - copyright := "2008 Mildred Ki'Lya"; + - comment := ""; + + // Copyright (c) 2008 Mildred Ki'Lya + // + // Permission is hereby granted, free of charge, to any person + // obtaining a copy of this software and associated documentation + // files (the "Software"), to deal in the Software without + // restriction, including without limitation the rights to use, + // copy, modify, merge, publish, distribute, sublicense, and/or sell + // copies of the Software, and to permit persons to whom the + // Software is furnished to do so, subject to the following + // conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + // OTHER DEALINGS IN THE SOFTWARE. + +Section Inherit + + + parent :Expanded ANY; + +Section Public + +Section Private + + - all_projects :HASHED_SET[ABSTRACT_PROJECT] := + HASHED_SET[ABSTRACT_PROJECT].create; + // Contains All the projects ever created + + + projects :HASHED_DICTIONNARY[ABSTRACT_PROJECT,STRING_CONSTANT] := + HASHED_DICTIONNARY[ABSTRACT_PROJECT,STRING_CONSTANT].create; + // Contains the projects this prototype import indexed by their name + + + postponed_errors :HASHED_DICTIONNARY[ABSTRACT_STRING,STRING_CONSTANT] := + HASHED_DICTIONNARY[ABSTRACT_STRING,STRING_CONSTANT].create; + +Section Public + + + name :STRING_CONSTANT; + // Project name: all in uppercase. Special project names include: + // SELF The current project + // ROOT The root project + // BUILTIN A project containing builtin prototypes + + - get_project project_name:STRING_CONSTANT :ABSTRACT_PROJECT <- + // Given a project name and the context in which it was found (Self), return + // the corresponding project or NULL if the project is not found. + [ + -? { Self != ABSTRACT_PROJECT }; // TODO: not true in TYPE + -? { project_name != ALIAS_STR.project_self }; + // SELF project should have been removed in the get_fully_qualified_name + // slot. It shouldn't appear here any more. + ] + ( + projects.fast_reference_at project_name; + ); + + - safe_get_fully_qualified_name n:STRING_CONSTANT + from proto:PROTOTYPE :(STRING_CONSTANT,ABSTRACT_PROJECT) <- + ( + project_name :STRING_CONSTANT; + + project :ABSTRACT_PROJECT; + + search_paths :ABSTRACT_STRING; + + (project_name, project, search_paths) := + get_fully_qualified_name n from proto; + + (project = NULL).if { + // not found + // pospone error. Here there may be an error but on dead code + // report the error only on living code + postponed_errors.put search_paths to n; + }; + + project_name, project + ); + + - send_error n:STRING_CONSTANT <- + ( + search_paths :ABSTRACT_STRING; + + search_paths := postponed_errors.fast_at n; + + string_tmp.copy n; + (search_paths = NULL).if { + string_tmp.append " is not found. (Error while looking for the paths)\n"; + } else { + string_tmp.append " is not found in:\n"; + string_tmp.append search_paths; + }; + POSITION.put_error semantic text string_tmp; + (list_current != NULL).if { + list_current.position.put_position; + }; + POSITION.send_error; + ); + + - get_fully_qualified_name n:STRING_CONSTANT + from proto:PROTOTYPE :(STRING_CONSTANT,ABSTRACT_PROJECT,ABSTRACT_STRING) <- + // THIS IS THE LOOKUP ALGORITHM + // Return a fully qualified name given a partial name and the prototype in + // which it was found. + // Return three values: + // * The fully qualified name + // * The project in which it was found or NULL if it was not found + // * The list of paths where the prototype was searched separated by \n + // It is necessary to store the project in the items because a project name + // may not be unique. + // Imagine a library A depends on MYLIB version 1 and waswritten before this + // library was updated. The library A uses internally MYLIB for all + // prototypes coming from the library. Now imagine someone else write the + // library B depending on MYLIB version 2. on hos system, he only uses the + // version two and therefore prefers to use MYLIB in his source code instead + // of MYLIB2. Now imagine a project P who wants to use both A and B. How is + // that possible ? + // Probably by installing MYLIB_1 and MYLIB_2 on his computer, and in the + // project A renaming MYLIB_1 into MYLIB, in project B, renaming MYLIB_2 + // into MYLIB + // In this case we see that the project name MYLIB is used for two different + // projects + ( + i:INTEGER; + + project_name :STRING_CONSTANT; + + project :ABSTRACT_PROJECT; + + is_fully_qualified, has_wildcard :BOOLEAN; + + result :STRING_CONSTANT; + + result_project :ABSTRACT_PROJECT; + + search_paths, result_buffer, remainder :STRING; + + i := n.index_of ':'; + has_wildcard := n.has_substring "::"; + + // if the name contains separators and no wildcard, chances are that it is + // already fully qualified. It is considered as fully qualified if the first + // member matches a project name + ((n.valid_index i) && { ! has_wildcard }).if { + project_name := ALIAS_STR.get (n.substring (n.lower) to (i - 1)); + (project_name = ALIAS_STR.project_self).if { + project_name := not_yet_implemented; + is_fully_qualified := TRUE; + } else { + is_fully_qualified := projects.fast_has project_name; + } + }; + + is_fully_qualified.if { + result := n; + } else { + has_wildcard.if { + project_name := ALIAS_STR.get (n.substring (n.lower) to (i - 1)); + (project_name = ALIAS_STR.project_self).if { + project_name := not_yet_implemented; + project := not_yet_implemented; + } else { + project := projects.fast_get project_name; + }; + result_buffer.copy project_name; + result_buffer.add_last ':'; + (project = NULL).if_false { + remainder := n.substring (i+1) to (n.upper); + project.expand_prototype remainder append_in result_buffer; + result := ALIAS_STR.get result_buffer; + }; + } else { + not_yet_implemented; + /* + path := n.replace ":" by "/".to_lower + ".li"; + basepath := proto.fully_qualified_name.replace ":" by "/".to_lower.dirname; + file_exists (basepath + "/" + path) in Self.if { + result := (basepath + ":" + path).replace ":" by "/".to_upper; + }.elseif { file_exists path in Self } then { + result := path.replace "/" by ":".to_upper; + }; + */ + }; + }; + + (result = NULL).if { + result := n; + result_project := NULL; + }; + + result, result_project, search_paths + ); + + - safe_get_prototype fully_qualified_name:STRING_CONSTANT + :(PROTOTYPE,ABSTRACT_PROJECT) <- + // Get a prototype corresponding to a fully qualified name + ( + result :PROTOTYPE; + + result := get_prototype fully_qualified_name; + + (result = NULL).if { + string_tmp.copy fully_qualified_name; + string_tmp.append " is not found.\nBut somehow it was found earlier\n"; + POSITION.put_error semantic text string_tmp; + (list_current != NULL).if { + list_current.position.put_position; + }; + POSITION.send_error; + }; + ); + + - get_prototype fully_qualified_name:STRING_CONSTANT :PROTOTYPE <- deferred; + +Section SELF + + - create_prototype n:STRING_CONSTANT file f:STRING_CONSTANT generic_count gen_count:INTEGER :PROTOTYPE <- + ( + entry :POINTER; + + result :PROTOTYPE; + result := PROTOTYPE.create (ALIAS_STR.get f) name n project Self generic_count gen_count; + PARSER.go_on result; + result + ); + +Section Public + + // + // Fully Qualified Name - utilities + // + + - fqn_get_project_name fqn:ABSTRACT_STRING :STRING_CONSTANT <- + ( + i :INTEGER; + i := fqn.index_of ':' since (fqn.lower); + ALIAS_STR.get (fqn.substring (fqn.lower) to (i - 1)) + ); + + - fqn_get_proto_name fqn:ABSTRACT_STRING :STRING_CONSTANT <- + ( + i :INTEGER; + i := fqn.index_of ':' since (fqn.lower); + ALIAS_STR.get (fqn.substring (i+1) to (fqn.upper)) + ); + + - fqn_get_last_name fqn:ABSTRACT_STRING :STRING_CONSTANT <- + ( + i :INTEGER; + i := fqn.last_index_of ':' since (fqn.upper); + ALIAS_STR.get (fqn.substring (i+1) to (fqn.upper)) + ); + +// kate: hl Lisaac v0.2; indent-width 2; space-indent on; replace-tabs off; +// kate: tab-width 8; remove-trailing-space on; diff -r 1dcf7bcfaf04 src/item/itm_type_generic.li --- a/src/item/itm_type_generic.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/item/itm_type_generic.li Sun Aug 31 13:13:22 2008 +0200 @@ -35,17 +35,18 @@ - dico:FAST_ARRAY[ITM_TYPE_GENERIC] := FAST_ARRAY[ITM_TYPE_GENERIC].create_with_capacity 32; - - create n:STRING_CONSTANT style s:STRING_CONSTANT with lt:FAST_ARRAY[ITM_TYPE_MONO] :SELF <- + - create n:STRING_CONSTANT project p:ABSTRACT_PROJECT style s:STRING_CONSTANT with lt:FAST_ARRAY[ITM_TYPE_MONO] :SELF <- ( + result:SELF; result := clone; - result.make n style s with lt; + result.make n project p style s with lt; result ); - - make n:STRING_CONSTANT style s:STRING_CONSTANT with lt:FAST_ARRAY[ITM_TYPE_MONO] <- + - make n:STRING_CONSTANT project p:ABSTRACT_PROJECT style s:STRING_CONSTANT with lt:FAST_ARRAY[ITM_TYPE_MONO] <- ( name := n; + project := p; style := s; list_type := lt; ); @@ -56,17 +57,22 @@ + list_type:FAST_ARRAY[ITM_TYPE_MONO]; - - get n:STRING_CONSTANT style s:STRING_CONSTANT + - get n_:STRING_CONSTANT context p:PROTOTYPE style s:STRING_CONSTANT with lt:FAST_ARRAY[ITM_TYPE_MONO] :SELF <- ( + result:SELF; + idx:INTEGER; + + n:STRING_CONSTANT; + + prj:ABSTRACT_PROJECT; + + (n, prj) := ABSTRACT_PROJECT.safe_get_fully_qualified_name n_ from p; idx := dico.lower; { (idx <= dico.upper) && { - (dico.item idx.name != n ) || - {dico.item idx.style != s } || - {dico.item idx.list_type != lt} + (dico.item idx.name != n ) || + {dico.item idx.project != prj } || + {dico.item idx.style != s } || + {dico.item idx.list_type != lt } } }.while_do { idx := idx + 1; @@ -74,7 +80,7 @@ (idx <= dico.upper).if { result ?= dico.item idx; } else { - result := create n style s with lt; + result := create n project prj style s with lt; dico.add_last result; }; result diff -r 1dcf7bcfaf04 src/item/itm_type_simple.li --- a/src/item/itm_type_simple.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/item/itm_type_simple.li Sun Aug 31 13:13:22 2008 +0200 @@ -34,23 +34,22 @@ Section ITM_TYPE_SIMPLE, ITM_TYPE_SELF - - dico:HASHED_DICTIONARY[ITM_TYPE_SIMPLE,STRING_CONSTANT] := - HASHED_DICTIONARY[ITM_TYPE_SIMPLE,STRING_CONSTANT].create; + - dico:FAST_ARRAY[ITM_TYPE_SIMPLE] := FAST_ARRAY[ITM_TYPE_SIMPLE].create; Section ITM_TYPE_SIMPLE - - create n:STRING_CONSTANT :SELF <- + - create n:STRING_CONSTANT project p:ABSTRACT_PROJECT :SELF <- ( + result:SELF; result := clone; - result.make n; + result.make n project p; result ); - - make n:STRING_CONSTANT <- + - make n:STRING_CONSTANT project p:ABSTRACT_PROJECT <- ( - name := n; - dico.fast_put Self to n; + name := n; + project := p; ); Section Public @@ -62,18 +61,36 @@ - hash_code:INTEGER <- name.hash_code; + name:STRING_CONSTANT; + + + project:ABSTRACT_PROJECT; - style:STRING_CONSTANT; // NULL - - get n:STRING_CONSTANT :ITM_TYPE_SIMPLE <- + - get n_:STRING_CONSTANT context p:PROTOTYPE :ITM_TYPE_SIMPLE <- [ -? {n != NULL}; ] ( + result:ITM_TYPE_SIMPLE; + + idx:INTEGER; + + n:STRING_CONSTANT; + + prj:ABSTRACT_PROJECT; + + (n, prj) := ABSTRACT_PROJECT.safe_get_fully_qualified_name n_ from p; - result := dico.fast_reference_at n; - (result = NULL).if { - result := create n; + idx := dico.lower; + { + (idx <= dico.upper) && { + (dico.item idx.name != n ) || + {dico.item idx.project != prj } + } + }.while_do { + idx := idx + 1; + }; + (idx <= dico.upper).if { + result := dico.item idx; + } else { + result := create n project prj style s; + dico.add_last result; }; result diff -r 1dcf7bcfaf04 src/item/itm_type_style.li --- a/src/item/itm_type_style.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/item/itm_type_style.li Sun Aug 31 13:13:22 2008 +0200 @@ -36,33 +36,39 @@ - dico:FAST_ARRAY[ITM_TYPE_STYLE] := FAST_ARRAY[ITM_TYPE_STYLE].create_with_capacity 32; - - create n:STRING_CONSTANT style s:STRING_CONSTANT :SELF <- + - create n:STRING_CONSTANT project p:ABSTRACT_PROJECT style s:STRING_CONSTANT :SELF <- ( + result:SELF; result := clone; - result.make n style s; + result.make n project p style s; result ); - - make n:STRING_CONSTANT style s:STRING_CONSTANT <- + - make n:STRING_CONSTANT project p:ABSTRACT_PROJECT style s:STRING_CONSTANT <- ( - name := n; - style := s; + name := n; + project := p; + style := s; ); Section Public + style:STRING_CONSTANT; - - get n:STRING_CONSTANT style s:STRING_CONSTANT :SELF <- + - get n_:STRING_CONSTANT context p:PROTOTYPE style s:STRING_CONSTANT :SELF <- ( + result:SELF; + idx:INTEGER; + + n:STRING_CONSTANT; + + prj:ABSTRACT_PROJECT; + + (n, prj) := ABSTRACT_PROJECT.safe_get_fully_qualified_name n_ from p; idx := dico.lower; { (idx <= dico.upper) && { - (dico.item idx.name != n) || - {dico.item idx.style != s} + (dico.item idx.name != n ) || + {dico.item idx.project != prj } || + {dico.item idx.style != s } } }.while_do { idx := idx + 1; @@ -70,7 +76,7 @@ (idx <= dico.upper).if { result ?= dico.item idx; } else { - result := create n style s; + result := create n project prj style s; dico.add_last result; }; result diff -r 1dcf7bcfaf04 src/parser.li --- a/src/parser.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/parser.li Sun Aug 31 13:13:22 2008 +0200 @@ -1482,7 +1482,7 @@ (lst.count = 1).if { typ_res := lst.first; } else { - typ_res := ITM_TYPE_MULTI.get lst; + typ_res := ITM_TYPE_MULTI.get lst context object; }; }; (! read_character '}').if { @@ -1549,7 +1549,7 @@ }.do_while {continue}; genericity := ALIAS_ARRAY[ITM_TYPE_MONO].alias genericity; - result := ITM_TYPE_GENERIC.get name style style with genericity; + result := ITM_TYPE_GENERIC.get name context object style style with genericity; (! read_character ']').if { warning_error (current_position,"Added ']'."); }; // if @@ -1562,9 +1562,9 @@ string_tmp.append "' for parameter type is ignored."; warning_error (current_position,string_tmp); }; - result := ITM_TYPE_PARAMETER.get name; + result := ITM_TYPE_PARAMETER.get name context object; }.elseif {style = NULL} then { - result := ITM_TYPE_SIMPLE.get name; + result := ITM_TYPE_SIMPLE.get name context object; } else { (name = ALIAS_STR.prototype_self).if { string_tmp.copy "Style `"; @@ -1573,7 +1573,7 @@ warning_error (current_position,string_tmp); result := ITM_TYPE_SIMPLE.type_self; } else { - result := ITM_TYPE_STYLE.get name style style; + result := ITM_TYPE_STYLE.get name context object style style; }; }; (is_shorter).if { diff -r 1dcf7bcfaf04 src/tools/alias_str.li --- a/src/tools/alias_str.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/tools/alias_str.li Sun Aug 31 13:13:22 2008 +0200 @@ -72,7 +72,7 @@ - section_default :STRING_CONSTANT := "DEFAULT"; - section_common :STRING_CONSTANT := "Common"; - + - prototype_integer :STRING_CONSTANT := "INTEGER"; - prototype_real :STRING_CONSTANT := "REAL"; - prototype_character :STRING_CONSTANT := "CHARACTER"; @@ -101,6 +101,11 @@ - prototype_n_a_n_a_character:STRING_CONSTANT := "NATIVE_ARRAY__NATIVE_ARRAY__CHARACTER"; + - project_self :STRING_CONSTANT := prototype_self; + - project_root :STRING_CONSTANT := "ROOT"; + - project_builtin :STRING_CONSTANT := "BUILTIN"; + - project_error :STRING_CONSTANT := "_ERROR"; + - variable_self :STRING_CONSTANT := "Self"; - variable_context :STRING_CONSTANT := "__pos"; - variable_null :STRING_CONSTANT := "NULL"; @@ -327,8 +332,12 @@ list.add prototype_integer_16; list.add prototype_integer_8; list.add prototype_n_a_character; - list.add prototype_n_a_n_a_character; - + list.add prototype_n_a_n_a_character; + + list.add project_root; + list.add project_builtin; + list_add project_error; + // Les variables de base : list.add variable_self; list.add variable_context; diff -r 1dcf7bcfaf04 src/type/prototype.li --- a/src/type/prototype.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/type/prototype.li Sun Aug 31 13:13:22 2008 +0200 @@ -44,6 +44,8 @@ Section Public + index:INTEGER; // in `prototype_list', for POSITION. + + + project :ABSTRACT_PROJECT; // // Slots @@ -167,14 +169,14 @@ // Creation. // - - create f:STRING_CONSTANT name n:STRING_CONSTANT generic_count c:INTEGER :SELF <- + - create f:STRING_CONSTANT name n:STRING_CONSTANT project p:ABSTRACT_PROJECT generic_count c:INTEGER :SELF <- ( + result:SELF; result := clone; - result.make f name n generic_count c; + result.make f name n project p generic_count c; result ); - - make f:STRING_CONSTANT name n:STRING_CONSTANT generic_count c:INTEGER <- + - make f:STRING_CONSTANT name n:STRING_CONSTANT project p:ABSTRACT_PROJECT generic_count c:INTEGER <- ( //+ file:STD_FILE; //+ entry:ENTRY; + file:POINTER; @@ -183,7 +185,8 @@ ? {n != NULL}; filename := f; - name := n; + name := n; + projet := p; generic_count := c; idf_generic_list := FAST_ARRAY[ITM_TYPE_PARAMETER].create_with_capacity c; diff -r 1dcf7bcfaf04 src/type/type.li --- a/src/type/type.li Sat Aug 30 17:53:54 2008 +0200 +++ b/src/type/type.li Sun Aug 31 13:13:22 2008 +0200 @@ -682,34 +682,39 @@ Section TYPE - - load_prototype n:STRING_CONSTANT generic_count gen_count:INTEGER :PROTOTYPE <- - ( + j:INTEGER; - + entry:POINTER; //ENTRY; + - load_prototype n:STRING_CONSTANT from_project prj:ABSTRACT_PROJECT generic_count gen_count:INTEGER :PROTOTYPE <- + ( //+ j:INTEGER; + //+ entry:POINTER; //ENTRY; + result:PROTOTYPE; result := PROTOTYPE.prototype_dico.fast_reference_at n; (result = NULL).if { - // Search directory. - j := path_directory.lower; - string_tmp2.clear; - {(j > path_directory.upper) || {result != NULL}}.until_do { - string_tmp.copy (path_directory.item j); - (n.lower).to (n.upper) do { i:INTEGER; - string_tmp.add_last (n.item i.to_lower); - }; - string_tmp.append ".li"; - string_tmp2.append string_tmp; - string_tmp2.add_last '\n'; - - entry := FS_MIN.open_read string_tmp; - ((entry != NULL) /*&& {entry.is_file}*/).if { - // Load prototype. - FS_MIN.close entry; - result := PROTOTYPE.create (ALIAS_STR.get string_tmp) name n generic_count gen_count; - PARSER.go_on result; - }; - j := j + 1; + (prj = NULL).if { + ABSTRACT_PROJECT.send_error n + } else { + result := prj.safe_get_prototype n; }; +// // Search directory. +// j := path_directory.lower; +// string_tmp2.clear; +// {(j > path_directory.upper) || {result != NULL}}.until_do { +// string_tmp.copy (path_directory.item j); +// (n.lower).to (n.upper) do { i:INTEGER; +// string_tmp.add_last (n.item i.to_lower); +// }; +// string_tmp.append ".li"; +// string_tmp2.append string_tmp; +// string_tmp2.add_last '\n'; +// +// entry := FS_MIN.open_read string_tmp; +// ((entry != NULL) /*&& {entry.is_file}*/).if { +// // Load prototype. +// FS_MIN.close entry; +// result := PROTOTYPE.create (ALIAS_STR.get string_tmp) name n generic_count gen_count; +// PARSER.go_on result; +// }; +// j := j + 1; +// }; (result = NULL).if { string_tmp.copy n; string_tmp.append " is not found in\n"; @@ -720,19 +725,18 @@ }; POSITION.send_error; }; - } else { - (result.generic_count != gen_count).if { - crash; - gen_count.print; '/'.print; result.generic_count.print; '\n'.print; - POSITION.put_error semantic text "Incorrect genericity definition."; - result.position.put_position; - (last_position.code != 0).if { - last_position.put_position; - } else { - ? {crash; TRUE}; - }; - POSITION.send_error; + }; + (result.generic_count != gen_count).if { + crash; + gen_count.print; '/'.print; result.generic_count.print; '\n'.print; + POSITION.put_error semantic text "Incorrect genericity definition."; + result.position.put_position; + (last_position.code != 0).if { + last_position.put_position; + } else { + ? {crash; TRUE}; }; + POSITION.send_error; }; result ); @@ -742,7 +746,7 @@ index := index_count; index_count := index_count + 1; - prototype := load_prototype (itm_typ.name) generic_count 0; + prototype := load_prototype (itm_typ.name) from_project (itm_typ.project) generic_count 0; itm_type := itm_typ; slot_run := FAST_ARRAY[SLOT].create_with_capacity 10; // BSBS: A voir. (prototype.type_style = ALIAS_STR.keyword_expanded).if {