Skip to content

Commit

Permalink
Added module classloader and function loadClass that loads a class fr…
Browse files Browse the repository at this point in the history
…om MODELICAPATH.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@913 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Feb 4, 2003
1 parent 2f4ad24 commit 93f29e6
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 49 deletions.
59 changes: 36 additions & 23 deletions modeq/Makefile.in
Expand Up @@ -6,7 +6,7 @@
# $Id$
#


ARCH = $(shell uname)
ANTLR_HOME = @antlrhome@

ANTLR_INCP = -I@antlrinc@
Expand All @@ -19,7 +19,18 @@ RMLHOME = @rmlhome@
RML = @rmlc_bin@ -g
RMLINC = -I$(RMLHOME)/include/plain

LDFLAGS=
ifeq ($(ARCH),CYGWIN_NT-5.1)
LDFLAGS = -L$(RMLHOME)/lib/plain $(ANTLR_LIBP) -lrml -lm -lantlr
endif

ifeq ($(ARCH),CYGWIN_NT-5.0)
LDFLAGS = -L$(RMLHOME)/lib/plain $(ANTLR_LIBP) -lrml -lm -lantlr
endif

ifeq ($(strip $(LDFLAGS)),)
LDFLAGS = -L$(RMLHOME)/lib/plain $(ANTLR_LIBP) -lrml -lm -lantlr -lsocket -lnsl
endif

PROG = modeq
AST = absyn_builder/absyn_builder.a
Expand All @@ -29,6 +40,7 @@ SRCRML= absyn.rml \
algorithm.rml \
builtin.rml \
classinf.rml \
classloader.rml \
codegen.rml \
connect.rml \
dae.rml \
Expand Down Expand Up @@ -107,28 +119,29 @@ depend:
$(RM) .dep Makefile.in.save

## dependencies
absyn.o: absyn.rml debug.rml
algorithm.o: algorithm.rml exp.rml types.rml staticexp.rml explode.rml
builtin.o: builtin.rml absyn.rml explode.rml env.rml exp.rml types.rml classinf.rml
classinf.o: classinf.rml absyn.rml
codegen.o: codegen.rml dae.rml dump.rml debug.rml absyn.rml algorithm.rml classinf.rml exp.rml modutil.rml types.rml util.rml
connect.o: connect.rml exp.rml staticexp.rml dae.rml dump.rml
dae.o: dae.rml absyn.rml exp.rml explode.rml algorithm.rml types.rml staticexp.rml rtopts.rml graphviz.rml dump.rml
debug.o: debug.rml rtopts.rml dump.rml
dump.o: dump.rml absyn.rml interactive.rml debug.rml classinf.rml rtopts.rml
absyn.o: absyn.rml debug.rml dump.rml util.rml print.rml
algorithm.o: algorithm.rml exp.rml types.rml explode.rml print.rml
builtin.o: builtin.rml absyn.rml explode.rml env.rml exp.rml types.rml classinf.rml debug.rml print.rml
classinf.o: classinf.rml explode.rml print.rml absyn.rml
classloader.o: classloader.rml absyn.rml system.rml lookup.rml interactive.rml
codegen.o: codegen.rml dae.rml print.rml dump.rml debug.rml absyn.rml algorithm.rml classinf.rml exp.rml modutil.rml types.rml util.rml
connect.o: connect.rml exp.rml staticexp.rml dae.rml dump.rml print.rml
dae.o: dae.rml absyn.rml exp.rml algorithm.rml types.rml rtopts.rml graphviz.rml dump.rml print.rml util.rml
debug.o: debug.rml rtopts.rml dump.rml print.rml
dump.o: dump.rml absyn.rml interactive.rml debug.rml classinf.rml rtopts.rml print.rml util.rml
dumpgraphviz.o: dumpgraphviz.rml absyn.rml debug.rml graphviz.rml classinf.rml dump.rml
env.o: env.rml absyn.rml values.rml explode.rml types.rml classinf.rml exp.rml dump.rml graphviz.rml dae.rml
exp.o: exp.rml absyn.rml rtopts.rml util.rml
explode.o: explode.rml absyn.rml dump.rml debug.rml
env.o: env.rml absyn.rml values.rml explode.rml types.rml classinf.rml exp.rml dump.rml graphviz.rml dae.rml print.rml
exp.o: exp.rml absyn.rml rtopts.rml util.rml print.rml
explode.o: explode.rml absyn.rml dump.rml debug.rml print.rml
graphviz.o: graphviz.rml
inst.o: inst.rml classinf.rml connect.rml dae.rml debug.rml env.rml exp.rml explode.rml mod.rml prefix.rml types.rml absyn.rml algorithm.rml builtin.rml dump.rml lookup.rml modutil.rml rtopts.rml staticexp.rml values.rml
interactive.o: interactive.rml absyn.rml explode.rml dae.rml
lookup.o: lookup.rml classinf.rml types.rml absyn.rml exp.rml env.rml explode.rml parse.rml debug.rml
main.o: main.rml modutil.rml parse.rml dump.rml dumpgraphviz.rml explode.rml dae.rml inst.rml interactive.rml rtopts.rml debug.rml codegen.rml socket.rml
mod.o: mod.rml absyn.rml dae.rml env.rml exp.rml prefix.rml explode.rml types.rml staticexp.rml values.rml dump.rml
modutil.o: modutil.rml absyn.rml dae.rml exp.rml algorithm.rml rtopts.rml util.rml
prefix.o: prefix.rml absyn.rml exp.rml env.rml lookup.rml util.rml
staticexp.o: staticexp.rml absyn.rml exp.rml explode.rml types.rml env.rml values.rml classinf.rml lookup.rml debug.rml dump.rml
types.o: types.rml classinf.rml absyn.rml exp.rml values.rml explode.rml dump.rml debug.rml
inst.o: inst.rml classinf.rml connect.rml dae.rml debug.rml env.rml exp.rml explode.rml mod.rml prefix.rml types.rml util.rml interactive.rml absyn.rml algorithm.rml builtin.rml dump.rml lookup.rml modutil.rml rtopts.rml staticexp.rml values.rml print.rml
interactive.o: interactive.rml absyn.rml explode.rml dae.rml types.rml values.rml dump.rml debug.rml rtopts.rml util.rml parse.rml prefix.rml mod.rml env.rml lookup.rml classinf.rml exp.rml inst.rml staticexp.rml modutil.rml codegen.rml print.rml system.rml
lookup.o: lookup.rml classinf.rml types.rml absyn.rml exp.rml env.rml explode.rml parse.rml debug.rml dump.rml inst.rml mod.rml prefix.rml print.rml builtin.rml
main.o: main.rml absyn.rml modutil.rml parse.rml dump.rml dumpgraphviz.rml explode.rml dae.rml inst.rml interactive.rml rtopts.rml debug.rml codegen.rml socket.rml print.rml
mod.o: mod.rml absyn.rml dae.rml env.rml exp.rml prefix.rml explode.rml types.rml staticexp.rml values.rml dump.rml print.rml
modutil.o: modutil.rml absyn.rml dae.rml exp.rml algorithm.rml rtopts.rml util.rml print.rml
prefix.o: prefix.rml absyn.rml exp.rml env.rml lookup.rml util.rml print.rml
staticexp.o: staticexp.rml absyn.rml exp.rml explode.rml types.rml env.rml values.rml classinf.rml interactive.rml dump.rml print.rml system.rml lookup.rml debug.rml inst.rml codegen.rml modutil.rml dae.rml
types.o: types.rml classinf.rml absyn.rml exp.rml values.rml explode.rml dump.rml debug.rml print.rml
util.o: util.rml
values.o: values.rml
values.o: values.rml exp.rml print.rml system.rml
16 changes: 11 additions & 5 deletions modeq/absyn_builder/walker.g
Expand Up @@ -991,9 +991,10 @@ for_clause_e returns [void* ast]
void* id;
}
:
#(FOR i:IDENT
e = expression
eq = equation_list

#(FOR #(IN i:IDENT
e = expression )
eq = algorithm_list
)
{
id = to_rml_str(i);
Expand Down Expand Up @@ -1437,8 +1438,13 @@ component_reference__function_call returns [void* ast]
ast = Absyn__CREF(cref);
}
)
;

|
#(INITIAL_FUNCTION_CALL INITIAL )
{
ast = Absyn__CALL(Absyn__CREF_5fIDENT(mk_scon("initial"), mk_nil()),Absyn__FUNCTIONARGS(mk_nil(),mk_nil()));
}
;

name_path returns [void* ast]
{
void* str;
Expand Down
217 changes: 217 additions & 0 deletions modeq/classloader.rml
@@ -0,0 +1,217 @@
(*
Copyright PELAB, Linkoping University

This file is part of Open Source Modelica (OSM).

OSM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

OSM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*)

(**
** file: classloader.rml
** module: ClassLoader
** description: Loading of classes from $MODELICAPATH.
**
** RCS: $Id$
**
** This module loads classes from $MODELICAPATH.
**)

module ClassLoader:
with "absyn.rml"

relation load_class: (Absyn.Path, string) => (Absyn.Program)
end
with "system.rml"
with "lookup.rml"
with "interactive.rml"
with "util.rml"
with "parse.rml"
with "print.rml"
with "env.rml"
with "dump.rml"
(** relation: load_class
** This relation takes a 'Path' and the $MODELICAPATH as a string
** and tries to load the class from the path.
** If the classname is qualified, the complete package is loaded.
** E.g. load_class(Modelica.SIunits.Voltage) -> whole Modelica package loaded.
**)
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
-------------------------------------
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 &
Interactive.get_pathed_class_in_program(path,p)=> _
-------------------------------------
load_class(path as Absyn.QUALIFIED(pack,rest),mp) => p

rule print "load_class failed\n"
-------------------
load_class(_,_) => fail
end

relation exist_regular_file: (string) => () =

rule string_append("test -f ",filename) => cmd &
System.system_call(cmd) => 0
----------------------------
exist_regular_file(filename)
end

relation exist_directory_file: (string) => () =

rule string_append("test -d ",filename) => cmd &
System.system_call(cmd) => 0
----------------------------
exist_directory_file(filename)
end

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

rule string_append(class,".mo") => classfile &
Util.string_append_list([mp,"/",classfile])=> classfile' &
exist_regular_file(classfile') &
print "parsing " & print classfile' & print "\n" &
Parser.parse(classfile') => p
---------------------------
load_class_from_mp(class,mp) => p

rule Util.string_append_list([mp,"/",class]) => dirfile &
string_append(dirfile,"/package.mo") => packfile &
exist_directory_file dirfile &
exist_regular_file packfile &
Print.print_buf "Class is package stored in a directory, loading whole package(incl. subdir)\n" &
load_complete_package_from_mp(class,mp,Absyn.TOP,Absyn.PROGRAM([],Absyn.TOP)) => p &
Interactive.build_env_from_symboltable(Interactive.SYMBOLTABLE(p,[],[],[],[])) => env &
Lookup.lookup_class(env,Absyn.IDENT(class),true) => (_,_)
--------------------------------------
load_class_from_mp(class,mp) => p

rule print "load_class_from_mp failed\n"
--------------------
load_class_from_mp(_,_) => fail
end

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

rule Util.string_append_list([mp,"/",pack]) => mp' &
string_append(mp',"/package.mo") => packagefile &
exist_regular_file(packagefile) &
print "parsing " & print packagefile & print "\n" &
Parser.parse(packagefile) => Absyn.PROGRAM(p1,w1) &
Print.print_buf("loading ") & Print.print_buf(packagefile) & Print.print_buf "\n" &
Interactive.update_program(Absyn.PROGRAM(p1,w1),Absyn.PROGRAM(oldc,Absyn.TOP)) => p1' &
System.sub_directories(mp') => subdirs &
Util.string_delimit_list(subdirs, ", ") => subdirstr &
print "subdirs =" & print subdirstr & print "\n" &
load_complete_subdirs(subdirs,pack,mp',within,p1') => p2 &
load_complete_subfiles(pack,mp',within,p2) => p
------------------------------
load_complete_package_from_mp(pack,mp,within as Absyn.TOP,Absyn.PROGRAM(oldc,_)) => p

rule Util.string_append_list([mp,"/",pack]) => mp' &
string_append(mp',"/package.mo") => packagefile &
exist_regular_file(packagefile) &
print "parsing " & print packagefile & print "\n" &
Parser.parse(packagefile) => Absyn.PROGRAM(p1,w1) &
Print.print_buf("loading ") & Print.print_buf(packagefile) & Print.print_buf "\n" &
Interactive.update_program(Absyn.PROGRAM(p1,Absyn.WITHIN(wpath)),Absyn.PROGRAM(oldc,Absyn.TOP)) => p1' &
System.sub_directories(mp') => subdirs &
Util.string_delimit_list(subdirs, ", ") => subdirstr &
print "subdirs =" & print subdirstr & print "\n" &
load_complete_subdirs(subdirs,pack,mp',within,p1') => p2 &
Absyn.join_paths(wpath,Absyn.IDENT(pack))=> wpath' &
load_complete_subfiles(pack,mp',within,p2) => p
------------------------------
load_complete_package_from_mp(pack,mp,within as Absyn.WITHIN(wpath),Absyn.PROGRAM(oldc,_)) => p

axiom load_complete_package_from_mp(_,_,_,_) => fail
end

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

axiom load_complete_subdirs([],_,_,w,Absyn.PROGRAM(oldcls,w2)) => Absyn.PROGRAM(oldcls,w2)

rule Absyn.join_paths(pack2,Absyn.IDENT(pack1)) => pack' &
load_complete_package_from_mp(pack,mp,Absyn.WITHIN(pack'),oldp) => p &
load_complete_subdirs(packs,pack1,mp,within,p) => p'
---------------------------------------------
load_complete_subdirs(pack::packs,pack1,mp,within as Absyn.WITHIN(pack2),oldp) => p'

rule Absyn.join_paths(Absyn.IDENT(pack1),Absyn.IDENT(pack)) => pack' &
load_complete_package_from_mp(pack,mp,Absyn.WITHIN(Absyn.IDENT(pack1)),oldp) => p &
load_complete_subdirs(packs,pack1,mp,within,p) => p'
---------------------------------------------
load_complete_subdirs(pack::packs,pack1,mp,within as Absyn.TOP,oldp) => p'

rule load_complete_subdirs(packs,pack1,mp,within,p) => p'
---------------------------------------------
load_complete_subdirs(pack::packs,pack1,mp,within,p) => p'


rule print "load_complete_subdirs failed\n"
----------------
load_complete_subdirs(_,_,_,_,_) => fail
end

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

rule (* Here *.mo files in same directory as package.mo should be loaded as sub-packages*)
System.mo_files(mp)=> mofiles &
Absyn.join_paths(within,Absyn.IDENT(pack)) => within' &
load_subpackage_files(mofiles,mp,Absyn.WITHIN(within'),oldp) => p
------------------------------------------
load_complete_subfiles(pack,mp,Absyn.WITHIN(within),oldp) => p

rule (* Here *.mo files in same directory as package.mo should be loaded as sub-packages*)
System.mo_files(mp)=> mofiles &
load_subpackage_files(mofiles,mp,Absyn.WITHIN(Absyn.IDENT(pack)),oldp) => p
------------------------------------------
load_complete_subfiles(pack,mp,Absyn.TOP,oldp) => p

rule print "load_complete_subfiles failed\n"
------------------------------------------
load_complete_subfiles(_,_,_,_) => fail

end

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

axiom load_subpackage_files([],mp,within,Absyn.PROGRAM(cls,w)) => Absyn.PROGRAM(cls,w)

rule Util.string_append_list([mp,"/",f]) => f' &
print "parsing " & print f' & print "\n" &
Parser.parse(f') => Absyn.PROGRAM(cls,_) &
Print.print_buf("loading ") & Print.print_buf(f') & Print.print_buf "\n" &
Interactive.update_program(Absyn.PROGRAM(cls,within),Absyn.PROGRAM(oldc,Absyn.TOP))=> p' &
load_subpackage_files(fs, mp, within, p') => p''
-------------------------------
load_subpackage_files(f::fs,mp,within,Absyn.PROGRAM(oldc,_)) => p''

rule print "load_subpackage_files failed\n"
---------------------
load_subpackage_files(_,_,_,_) => fail
end

3 changes: 2 additions & 1 deletion modeq/dump.rml
Expand Up @@ -68,7 +68,8 @@ with "debug.rml"
relation select_string: (bool,string,string) => string
relation get_string_list : ('a list, 'a => string, string) => string
relation get_option_str: ('a option, 'a => string) => string
relation unparse_annotation_option: Absyn.Annotation option => string
relation unparse_annotation_option: Absyn.Annotation option => string
relation unparse_within: Absyn.Within => string
end


Expand Down
2 changes: 2 additions & 0 deletions modeq/inst.rml
Expand Up @@ -199,7 +199,9 @@ relation instantiate_class : (SCode.Program, SCode.Path) => DAE.DAElist =
instantiate_class(cdecls, path as Absyn.IDENT(name2)) => DAE.DAE([DAE.COMP(name2,DAE.DAE(dae))])

rule Builtin.initial_env => env &
print "calling inst_class_decls.. \n" &
inst_class_decls(env,cdecls,path)=> (env',_) &
print "done \n" &
Lookup.lookup_class(env',path,true) => (cdef, env'') &
inst_class(env'',Mod.NOMOD,Prefix.NOPRE,[],cdef,[],false) => (dae,_,_,_) &
Absyn.path_string path => pathstr
Expand Down

0 comments on commit 93f29e6

Please sign in to comment.