Skip to content

Commit

Permalink
loadClass now handles several paths (separated by colon) in MODELICAPATH
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@997 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Aug 4, 2003
1 parent c82491e commit 82c02c9
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 16 deletions.
31 changes: 28 additions & 3 deletions modeq/classloader.rml
Expand Up @@ -53,14 +53,15 @@ with "dump.rml"
relation load_class: (Absyn.Path, string) => (Absyn.Program) =

(** Simple names: Just load the file if it can be found in $MODELICAPATH* *)
rule load_class_from_mp(classname,mp) => p
rule System.strtok(mp,":") => mps &
load_class_from_mps(classname,mps) => p
-------------------------------------
load_class(Absyn.IDENT(classname),mp) => p

(** Qualified names: Load the complete package and then check that **)
(** the package contains the file **)
rule Print.print_buf "Qualified name, loading complete package\n" &
load_complete_package_from_mp(pack,mp,Absyn.TOP,Absyn.PROGRAM([],Absyn.TOP)) => p &
rule System.strtok(mp,":") => mps &
load_complete_package_from_mps(pack,mps,Absyn.TOP,Absyn.PROGRAM([],Absyn.TOP)) => p &
Interactive.get_pathed_class_in_program(path,p)=> _
-------------------------------------
load_class(path as Absyn.QUALIFIED(pack,rest),mp) => p
Expand All @@ -86,6 +87,18 @@ relation exist_directory_file: (string) => () =
exist_directory_file(filename)
end


relation load_class_from_mps: (Absyn.Ident, string list) => Absyn.Program =

rule load_class_from_mp(class,mp) => p
----------------------------------
load_class_from_mps(class,mp::mps) => p

rule load_class_from_mps(class,mps) => p
----------------------------------
load_class_from_mps(class,_::mps) => p

end
relation load_class_from_mp: (Absyn.Ident, string) => Absyn.Program =

rule string_append(class,".mo") => classfile &
Expand All @@ -111,6 +124,18 @@ relation load_class_from_mp: (Absyn.Ident, string) => Absyn.Program =
load_class_from_mp(_,_) => fail
end

relation load_complete_package_from_mps: (Absyn.Ident, string list, Absyn.Within, Absyn.Program) => Absyn.Program =

rule load_complete_package_from_mp(pack,mp,within ,oldp) => p
-------------------------
load_complete_package_from_mps(pack,mp::_,within,oldp) => p

rule load_complete_package_from_mps(pack,mps,within ,oldp) => p
-------------------------
load_complete_package_from_mps(pack,_::mps,within,oldp) => p

end

relation load_complete_package_from_mp: (Absyn.Ident, string, Absyn.Within, Absyn.Program) => Absyn.Program =

rule Util.string_append_list([mp,"/",pack]) => mp' &
Expand Down
6 changes: 6 additions & 0 deletions modeq/inst.rml
Expand Up @@ -416,6 +416,12 @@ relation inst_class_in: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
=> (DAE.Element list, Env, Connect.Sets, ClassInf.State,
Types.Var list) =

rule (*print "nomod & nopre on class " & print cname & print "\n" &*)
int_eq(1,0) => true
------------
inst_class_in(env,Mod.NOMOD, Prefix.NOPRE,_,_,c as SCode.CLASS(cname,_,_,restr,d),
_,_,_,_) => ([],env,[], ClassInf.UNKNOWN("foo"), [])

rule (*For the builtin classes. no DAE for elts. E.g. unit, quantity, ... *)
Util.string_equal(cname,"Real") => r &
Util.string_equal(cname,"Integer") => i &
Expand Down
8 changes: 4 additions & 4 deletions modeq/lookup.rml
Expand Up @@ -159,12 +159,12 @@ relation lookup_class: (Env.Env, Absyn.Path, bool) => (SCode.Class, Env.Env) =
Env.get_env_path(env) => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.get_class(envpathstr,pathstr) => (c,env) (*&
print "Got cached class: " & print pathstr &
Cache.get_class(envpathstr,pathstr) => (c,env)
(* & print "Got cached class: " & print pathstr &
print "\n"*)
----------------------------------------
lookup_class(env,path,_) => (c,env)*)

lookup_class(env,path,_) => (c,env)
*)

rule Debug.fprint ("lotr","TRIES lookup_class(1)\n") &
Debug.fcall ("lotr",Dump.print_path,path) &
Expand Down
27 changes: 18 additions & 9 deletions modeq/runtime/cacheimpl.cpp
Expand Up @@ -44,13 +44,15 @@ extern "C"

RML_BEGIN_LABEL(Cache__add_5fclass)
{
//RML_TAILCALLK(rmlSC);

int *cl = (int*)rmlA0;
int *env = (int*)rmlA1;
string scope = RML_STRINGDATA(rmlA2);
string className = RML_STRINGDATA(rmlA3);
if (scope == "") scope = "$TOP$";

// cerr << " Adding class" << className <<" scope : " << scope << endl;
//cerr << " Adding class" << className <<" scope : " << scope << endl;
if (!classCache) {
cerr << "Cache is not initialized\n";
RML_TAILCALLK(rmlFC);
Expand All @@ -59,11 +61,13 @@ extern "C"
if (it == classCache->end()) {
//cerr << "Did not find " << className << "hash table.\n";
(*classCache)[className] = new CacheItem();
it = classCache->find(className);
}
else if (it->second->size() == 1 && it->second->begin()->second->cl != cl)
// Only add class if different.
if ((it->second->size() == 0 ||
it->second->size() == 1 && it->second->begin()->second->cl != cl) )
// Only add class if different or not exist before
{
cerr << "Different, adding second class." << endl;
//cerr << "Different or new, adding class." << endl;
ClassItem *newItem = new ClassItem;
newItem->cl = cl;
newItem->env = env;
Expand Down Expand Up @@ -91,31 +95,36 @@ extern "C"

RML_BEGIN_LABEL(Cache__get_5fclass)
{
RML_TAILCALLK(rmlFC);

string scope = RML_STRINGDATA(rmlA0);
string className = RML_STRINGDATA(rmlA1);
if (scope == "") scope ="$TOP$";
Cache::iterator it;
CacheItem::iterator it2;
//cerr << "Get_class " << className << " in scope " << scope << endl;
if ((it = classCache->find(className)) == classCache->end()) {
it = classCache->find(className);
if (it == classCache->end()) {
//cerr << "class " << className << " not found in cache\n";
RML_TAILCALLK(rmlFC);
} else {
if (it->second->size() == 1) {
ClassItem *item=it2->second;
//cerr << "got class, size =1" << endl;
ClassItem *item=it->second->begin()->second;
rmlA0=item->cl;
rmlA1=item->env;
RML_TAILCALLK(rmlSC);
}
it2=(it->second->find(scope));
it2 = it->second->find(scope);
if (it2 == it->second->end()) {
//cerr << "class " << className << " not found in cache, size =" << it->second->size() << endl;
RML_TAILCALLK(rmlFC);
// cerr << "class " << className << " not found in cache\n";

}
ClassItem *item=it2->second;
rmlA0=item->cl;
rmlA1=item->env;
// cerr << "Found class " << className << " in cache.\n";
//cerr << "Found class " << className << " in cache.\n";
RML_TAILCALLK(rmlSC);
}
}
Expand Down
21 changes: 21 additions & 0 deletions modeq/runtime/systemimpl.c
Expand Up @@ -95,6 +95,27 @@ void System_5finit(void)

}

RML_BEGIN_LABEL(System__strtok)
{
char *s;
char *delimit = RML_STRINGDATA(rmlA1);
char *str = RML_STRINGDATA(rmlA0);

void * res = (void*)mk_nil();
s=strtok(str,delimit);
if (s == NULL) { rmlA0=res; RML_TAILCALLK(rmlFC); }
res = (void*)mk_cons(mk_scon(s),res);
while (s=strtok(NULL,delimit)) {
res = (void*)mk_cons(mk_scon(s),res);
}
rmlA0=res;

rml_prim_once(RML__list_5freverse);

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__compile_5fc_5ffile)
{
char* str = RML_STRINGDATA(rmlA0);
Expand Down
2 changes: 2 additions & 0 deletions modeq/system.rml
Expand Up @@ -25,6 +25,8 @@ module System:
*)
with "values.rml"

relation strtok: (string,string) => string list

relation compile_c_file: (string) => ()

relation set_c_compiler: (string) => ()
Expand Down

0 comments on commit 82c02c9

Please sign in to comment.