git-svn-id: https://projects.brucker.ch/su4sml/svn/su4sml/trunk@7506 3260e6d1-4efc-4170-b0a7-36055960796d

This commit is contained in:
Manuel Krucker 2008-03-26 17:14:30 +00:00
parent 0412a30328
commit 5056c47cd0
5 changed files with 190 additions and 128 deletions

View File

@ -47,19 +47,51 @@ fun (x |> f) = f x;
(* minimal tracing support (modifed version of ocl_parser tracing *)
val log_level = ref 6
fun trace lev s = if (lev <= !log_level ) then print(s) else ()
val line_offset = ref 4
fun get_spaces 0 = ""
| get_spaces x = (" ")^(get_spaces (x-1))
fun init_offset () = line_offset:=4
fun get_offset () = get_spaces (!line_offset)
fun inc_offset () = line_offset := (!line_offset)+1
fun dec_offset () = line_offset := (!line_offset)-1
(* debugging-levels *)
val zero = 0
val exce = 0
val function_calls = 5
val function_arguments = 6
val high = 10
val medium = 20
val function_calls = 25
val function_ends = 26
val function_arguments = 27
val low = 100
val development = 200
val wgen = 50
fun trace lev s =
case lev of
25 =>
let
val _ = if (lev <= !log_level ) then print((get_offset())^s) else ()
in
inc_offset()
end
| 26 =>
let
val x = dec_offset()
in
if (lev <= !log_level ) then print((get_offset())^s) else ()
end
| x =>
if x < 50
then (if (lev <= !log_level ) then print(s) else ())
else (if (lev <= !log_level ) then print((get_offset())^s) else ())
(* HOLOCL_HOME resp. SU4SML_HOME should point to the top-level directory *)
(* of the corresponding library. The semantics of UML2CDL_HOME should *)

View File

@ -7,7 +7,7 @@ open ModelImport
open Rep_Core
val _ = init_offset()
(* set debugging settings *)
val _ = Control.Print.printDepth:=20
@ -18,7 +18,7 @@ val ocl = ""
*)
val zargo = "../../examples/SimpleChair/SimpleChair.zargo"
val ocl = "../../examples/SimpleChair/test.ocl"
val ocl = "../../examples/SimpleChair/test.ocl"
val remP = ["AbstractSimpleChair02", "AbstractSimpleChair03","AbstractSimpleChair04","ConcreteSimpleChair01","ConcreteSimpleChair02"] ;
@ -29,7 +29,7 @@ val zargo = "../../examples/ebank/ebank.zargo"
val ocl="../../examples/ebank/ebank.ocl"
*)
(** import model *)
val i_model = import zargo "" []
val i_model = import zargo ocl []
val (clist,alist) = normalize_ext i_model
val model = ((clist@oclLib),(alist))
val classifiers = removeOclLibrary clist

View File

@ -271,19 +271,24 @@ fun import xmifile oclfile excludePackages =
val model = case ocl of
[] => xmi_cls
| ocl => let
val _ = init_offset()
val _ = trace high "### Preprocess Context List ###\n"
val fixed_ocl = Preprocessor.preprocess_context_list ocl ((OclLibrary.oclLib)@xmi_cls)
val _ = trace high "### Finished Preprocess Context List ###\n\n"
val _ = init_offset()
val _ = trace high "### Type Checking ###\n"
val typed_cl = TypeChecker.check_context_list fixed_ocl (((OclLibrary.oclLib)@xmi_cls),xmi_assocs);
val _ = trace high "### Finished Type Checking ###\n\n"
val _ = init_offset()
val _ = print"### Updating Classifier List ###\n"
val model = Update_Model.gen_updated_classifier_list typed_cl ((OclLibrary.oclLib)@xmi_cls);
val _ = trace high ("### Finished Updating Classifier List "
^(Int.toString(length model))
^ " Classifiers found (11 from 'oclLib') ###\n")
val _ = init_offset()
val _ = trace high "### Fixing Types ###\n"
val model = removeOclLibrary model

View File

@ -185,43 +185,48 @@ fun FromSet_desugarator rterm path attr_or_meth rargs (model as (cls,assocs):Rep
(* RETURN: OclTerm (OperationCall/AttributeCall) *)
fun AsSet_desugarator rterm path attr_or_meth rargs (model as (cls,assocs)) =
(trace function_calls ("AsSet_desugarator class= " ^ (string_of_OclType (type_of_term rterm)) ^ " , attr\n");
if (attr_or_meth = 0)
then (* OperationCall *)
let
val _ = trace low ("\n==> AsSet-desugarator: operation ... \n")
val rtyp = Set(type_of_term rterm)
val _ = trace low ("Type of source term " ^ string_of_OclType rtyp ^ " ---> try Set(" ^ string_of_OclType rtyp ^ ")\n")
val class = class_of_term (Variable ("anonIterVar_" ^ (varcounter.nextStr()),rtyp)) model
val ops = get_overloaded_methods class (List.last path) model
val new_rterm = CollectionLiteral([CollectionItem(rterm,type_of_term rterm)],rtyp)
in
if (List.length ops = 0)
then
raise NoSuchOperationError ("interefere_methods: No operation signature matches given types (source: "^(Ocl2String.ocl2string false rterm)^").")
else
upcast_op ops new_rterm rargs model
end
else (* AttributeCall *)
let
val _ = trace low ("\n==> AsSet-desugarator: attribute/assocend\n")
val rtyp = Set(type_of_term rterm)
val _ = trace low (string_of_OclType rtyp ^ "\n")
val class = class_of_term (Variable ("anonIterVar_" ^ (varcounter.nextStr()),Set(rtyp))) model
val attrs = get_overloaded_attrs_or_assocends class (List.last path) model
(* source term is a dummy-Term *)
val new_rterm = CollectionLiteral([CollectionItem(rterm,type_of_term rterm)],rtyp)
val _ = trace low ("'AsSetError' ... \n")
in
if (List.length attrs = 0)
then
raise NoSuchAttributeError ("Attriubte '" ^ (List.last path) ^ "' does not exist ... \n")
else
upcast_att_aend attrs new_rterm model
end)
let
val _ = (trace function_calls ("AsSet_desugarator class= " ^ (string_of_OclType (type_of_term rterm)) ^ " , attr\n"))
val res = if (attr_or_meth = 0)
then (* OperationCall *)
let
val _ = trace low ("\n==> AsSet-desugarator: operation ... \n")
val rtyp = Set(type_of_term rterm)
val _ = trace low ("Type of source term " ^ string_of_OclType rtyp ^ " ---> try Set(" ^ string_of_OclType rtyp ^ ")\n")
val class = class_of_term (Variable ("anonIterVar_" ^ (varcounter.nextStr()),rtyp)) model
val ops = get_overloaded_methods class (List.last path) model
val new_rterm = CollectionLiteral([CollectionItem(rterm,type_of_term rterm)],rtyp)
in
if (List.length ops = 0)
then
raise NoSuchOperationError ("interefere_methods: No operation signature matches given types (source: "^(Ocl2String.ocl2string false rterm)^").")
else
upcast_op ops new_rterm rargs model
end
else (* AttributeCall *)
let
val _ = trace low ("\n==> AsSet-desugarator: attribute/assocend\n")
val rtyp = Set(type_of_term rterm)
val _ = trace low (string_of_OclType rtyp ^ "\n")
val class = class_of_term (Variable ("anonIterVar_" ^ (varcounter.nextStr()),Set(rtyp))) model
val attrs = get_overloaded_attrs_or_assocends class (List.last path) model
(* source term is a dummy-Term *)
val new_rterm = CollectionLiteral([CollectionItem(rterm,type_of_term rterm)],rtyp)
val _ = trace low ("'AsSetError' ... \n")
in
if (List.length attrs = 0)
then
raise NoSuchAttributeError ("Attriubte '" ^ (List.last path) ^ "' does not exist ... \n")
else
upcast_att_aend attrs new_rterm model
end
val _ = trace function_ends ("AsSet_desugarator class= " ^ (string_of_OclType (type_of_term rterm)) ^ " , attr\n")
in
res
end
(* RETURN: OclTerm (OperationCall/AttributeCall) *)
fun desugarator rterm path attr_or_meth rargs model =
fun desugarator rterm path attr_or_meth rargs model =
FromSet_desugarator rterm path attr_or_meth rargs model
handle UpcastingError s => AsSet_desugarator rterm path attr_or_meth rargs model
@ -297,11 +302,12 @@ and resolve_OclTerm (Literal (s,typ)) model =
end
| resolve_OclTerm (AttributeCall (term,_,attr_path,_)) (model as (cls,assocs)) =
let
val _ = trace medium ("RESOLVE AttributeCall: attribute name: " ^ (List.last attr_path) ^ "\n")
val _ = trace wgen ("RESOLVE AttributeCall: attribute name: " ^ (List.last attr_path) ^ "\n")
(* resolve source term *)
val rterm = resolve_OclTerm term model
val _ = trace low ("res AttCall (" ^ (List.last attr_path) ^ ") : rterm = " ^ Ocl2String.ocl2string false rterm ^ "\n")
val _ = trace low ("res AttCall (" ^ (List.last attr_path) ^ ") : rtype = " ^ string_of_OclType (type_of_term rterm) ^ "\n")
val _ = trace wgen ("res AttCall : arrow or not " ^ List.hd (attr_path) ^ "\n")
val _ = trace wgen ("res AttCall (" ^ (List.last attr_path) ^ ") : rterm = " ^ Ocl2String.ocl2string false rterm ^ "\n")
val _ = trace wgen ("res AttCall (" ^ (List.last attr_path) ^ ") : rtype = " ^ string_of_OclType (type_of_term rterm) ^ "\n")
in
let
in

View File

@ -408,7 +408,7 @@ fun transform_classifier t (XMI.Class {xmiid,name,isActive,visibility,isLeaf,
classifierInState,activity_graphs,
state_machines}) =
let
val _ = trace function_calls "transform_classifier: Class\n"
val _ = trace function_calls ("RepParser.transform_classifier: Class\n")
val _ = trace function_arguments ("class name: "^ name ^"\n")
val assocs = find_classifier_associations t xmiid
val _ = trace high ("number of associations added: "^(Int.toString (List.length assocs))^"\n")
@ -426,23 +426,26 @@ fun transform_classifier t (XMI.Class {xmiid,name,isActive,visibility,isLeaf,
(* val navigable_aends = filter #isNavigable (find_aends t xmiid)*)
val class_type = find_classifier_type t xmiid
val _ = print ("transform_classifier: adding "^name^"\n")
val res =
Rep.Class {name = (* type_of_classifier *) class_type,
parent = case filtered_parents
of [] => NONE
| xs => SOME ((* path_of_classifier *) (hd xs)),
attributes = map (transform_attribute t) attributes,
operations = map (transform_operation t) operations,
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
(* associationends = map (transform_aend t) navigable_aends, *)
associations = assocs,
stereotypes = map (find_stereotype t) stereotype,
interfaces = nil, (* FIX *)
visibility = visibility:Rep_Core.Visibility,
activity_graphs = List.concat [map (transform_activitygraph t) activity_graphs,
map (transform_statemachine t) state_machines],
thyname = NONE}
val _ = trace function_ends ("RepParser.transform_classifier\n")
in
Rep.Class {name = (* type_of_classifier *) class_type,
parent = case filtered_parents
of [] => NONE
| xs => SOME ((* path_of_classifier *) (hd xs)),
attributes = map (transform_attribute t) attributes,
operations = map (transform_operation t) operations,
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
(* associationends = map (transform_aend t) navigable_aends, *)
associations = assocs,
stereotypes = map (find_stereotype t) stereotype,
interfaces = nil, (* FIX *)
visibility = visibility:Rep_Core.Visibility,
activity_graphs = List.concat [map (transform_activitygraph t) activity_graphs,
map (transform_statemachine t) state_machines],
thyname = NONE}
res
end
| transform_classifier t (XMI.AssociationClass {xmiid,name,isActive,visibility,
isLeaf,generalizations,attributes,
@ -450,7 +453,7 @@ fun transform_classifier t (XMI.Class {xmiid,name,isActive,visibility,isLeaf,
clientDependency,connection,
supplierDependency,taggedValue}) =
let
val _ = trace function_calls "transform_classifier: AssociationClass\n"
val _ = trace function_calls ("RepParser.transform_classifier: AssociationClass\n")
val _ = trace function_arguments ("associationclass name: "^ name ^"\n")
val (_,assocs,assoc,_,_) = find_classifier_entries t xmiid
val _ = trace high ("number of associations added: "^(Int.toString (List.length assocs))^"\n")
@ -465,77 +468,88 @@ fun transform_classifier t (XMI.Class {xmiid,name,isActive,visibility,isLeaf,
(*val navigable_aends = filter #isNavigable connection *)
val class_type = find_classifier_type t xmiid
val _ = print ("transform_classifier: adding "^name^"\n")
val res =
Rep.AssociationClass {name = (* type_of_classifier *)class_type,
parent = case filtered_parents
of [] => NONE
| xs => SOME ((*path_of_classifier *) (hd xs)),
attributes = map (transform_attribute t) attributes,
operations = map (transform_operation t) operations,
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
stereotypes = map (find_stereotype t) stereotype,
interfaces = nil (* FIX *),
thyname = NONE,
activity_graphs = [] (* FIXME *),
associations = assocs,
visibility = visibility,
association = assoc}
val _ = trace function_ends ("RepParser.transform_classifier\n")
in
Rep.AssociationClass {name = (* type_of_classifier *)class_type,
parent = case filtered_parents
of [] => NONE
| xs => SOME ((*path_of_classifier *) (hd xs)),
attributes = map (transform_attribute t) attributes,
operations = map (transform_operation t) operations,
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
stereotypes = map (find_stereotype t) stereotype,
interfaces = nil (* FIX *),
thyname = NONE,
activity_graphs = [] (* FIXME *),
associations = assocs,
visibility = visibility,
association = assoc}
res
end
| transform_classifier t (XMI.Primitive {xmiid,name,generalizations,operations,invariant,taggedValue}) =
let
val _ = trace function_calls "transform_classifier: Primitive\n"
val _ = trace function_calls ("RepParser.transform_classifier: Primitive\n")
val _ = trace function_arguments ("primitive name: "^ name ^"\n")
val (_,assocs,_,_,_) = find_classifier_entries t xmiid
val _ = trace high ("number of associations added: "^(Int.toString (List.length assocs))^"\n")
val checked_invariants = filter_exists t invariant
in
Rep.Primitive {name = (* case *) find_classifier_type t xmiid (*of Rep_OclType.Classifier x => x
| _ => raise Option*) ,
parent = NONE (* FIX *),
operations = map (transform_operation t) operations,
associations = assocs
(*associations = map (transform_aend t)
(find_aends t xmiid), *),
val res =
Rep.Primitive {name = (* case *) find_classifier_type t xmiid (*of Rep_OclType.Classifier x => x
| _ => raise Option*) ,
parent = NONE (* FIX *),
operations = map (transform_operation t) operations,
associations = assocs
(*associations = map (transform_aend t)
(find_aends t xmiid), *),
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
stereotypes = nil (*FIX *),
interfaces = nil (* FIX *),
thyname = NONE}
(find_constraint t)) checked_invariants,
stereotypes = nil (*FIX *),
interfaces = nil (* FIX *),
thyname = NONE}
val _ = trace function_ends ("RepParser.transform_classifier\n")
in
res
end
| transform_classifier t (XMI.Enumeration {xmiid,name,generalizations,
operations,literals,invariant}) =
let
val _ = trace function_calls "transform_classifier: Enumeration\n"
val _ = trace function_calls ("RepParser.transform_classifier: Enumeration\n")
val checked_invariants = filter_exists t invariant
val res =
Rep.Enumeration {name = (* case *) find_classifier_type t xmiid (* of Rep_OclType.Classifier x => x
| _ => raise Option *),
parent = NONE, (* FIX *)
literals = literals,
operations = map (transform_operation t) operations,
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
stereotypes = nil, (* FIX *)
interfaces = nil, (* FIX *)
thyname = NONE}
val _ = trace function_ends ("RepParser.transform_classifier\n")
in
Rep.Enumeration {name = (* case *) find_classifier_type t xmiid (* of Rep_OclType.Classifier x => x
| _ => raise Option *),
parent = NONE, (* FIX *)
literals = literals,
operations = map (transform_operation t) operations,
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
stereotypes = nil, (* FIX *)
interfaces = nil, (* FIX *)
thyname = NONE}
res
end
| transform_classifier t (XMI.Interface { xmiid, name, generalizations, operations, invariant,
...}) =
let
val _ = trace function_calls "transform_classifier: Interface\n"
val _ = trace function_calls ("RepParser.transform_classifier: Interface\n")
val checked_invariants = filter_exists t invariant
in
Rep.Interface { name = find_classifier_type t xmiid,
parents = map ((find_classifier_type t) o (find_parent t))
generalizations,
operations = map (transform_operation t) operations,
stereotypes = [], (* map (find_stereotype t) stereotype,*)
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
thyname = NONE
}
val res =
Rep.Interface { name = find_classifier_type t xmiid,
parents = map ((find_classifier_type t) o (find_parent t))
generalizations,
operations = map (transform_operation t) operations,
stereotypes = [], (* map (find_stereotype t) stereotype,*)
invariant = map ((transform_constraint t) o
(find_constraint t)) checked_invariants,
thyname = NONE
}
val _ = trace function_ends ("RepParser.transform_classifier\n")
in
res
end
| transform_classifier t (_) = error "Not supported Classifier type found."
@ -544,7 +558,7 @@ fun transform_classifier t (XMI.Class {xmiid,name,isActive,visibility,isLeaf,
fun transform_association t ({xmiid,name,connection}:XMI.Association):
Rep.association =
let
val _ = trace function_calls "transform_association\n"
val _ = trace function_calls ("RepParser.transform_association\n")
val _ = trace function_arguments ("transform_association xmiid: "
^xmiid^"\n")
val associationPath = find_association_path t xmiid
@ -555,19 +569,21 @@ fun transform_association t ({xmiid,name,connection}:XMI.Association):
(Int.toString (List.length associationPath)) ^"\n")
val (associationEnds,qualifierPairs) =
ListPair.unzip (map (transform_aend t associationPath) connection)
val res =
{name = associationPath (* path_of_association *),
aends = associationEnds,
qualifiers = qualifierPairs,
aclass = NONE (* regular association *)}
val _ = trace function_ends ("RepParser.transform_association\n")
in
{name = associationPath (* path_of_association *),
aends = associationEnds,
qualifiers = qualifierPairs,
aclass = NONE (* regular association *)}
res
end
fun transformAssociationFromAssociationClass t (XMI.AssociationClass
{xmiid,connection,...}):
Rep.association =
let
val _ = trace function_calls "transformAssociationFromAassociation\
\Class\n"
val _ = trace function_calls ("RepParser.transformAssociationFromAassociation Class\n")
val id = xmiid^"_association"
val associationPath = find_association_path t id
val _ = trace low ("transform_association path: "^
@ -577,6 +593,7 @@ fun transformAssociationFromAssociationClass t (XMI.AssociationClass
val (associationEnds,qualifierPairs) =
ListPair.unzip (map (transform_aend t associationPath) connection)
val aClass = SOME (path_of_OclType (find_classifier_type t xmiid))
val _ = trace function_ends ("RepParser.transformAssociationFromAssociationClass\n")
in
{name = associationPath (* path_of_association *),
aends = associationEnds,
@ -588,7 +605,7 @@ fun transformAssociationFromAssociationClass t (XMI.AssociationClass
fun transform_package t (XMI.Package p) :transform_model =
let
(* we do not transform the ocl library *)
val _ = trace function_calls "transform_package\n"
val _ = trace function_calls ("RepParser.transform_package\n")
val filteredPackages =
filter (fn (XMI.Package x) =>
((#name x <> "oclLib") andalso (#name x <> "UML_OCL")))
@ -603,8 +620,10 @@ fun transform_package t (XMI.Package p) :transform_model =
ListPair.unzip (map (transform_package t) filteredPackages)
val associations = local_associations @ (List.concat res_associations)
val classifiers =local_classifiers @ (List.concat res_classifiers)
in
(classifiers, associations )
val res = (classifiers, associations )
val _ = trace function_ends ("RepParser.transform_package\n")
in
res
end
@ -676,15 +695,15 @@ fun transformXMI_ext ({classifiers,constraints,packages,stereotypes,
end
val _ = map printClassifier classifiers
in
trace function_calls "\n### transformXMI_ext done\n\n";
trace 27 "\n### transformXMI_ext done\n\n";
(classifiers,associations)
end
in
trace function_calls "### transformXMI: populate hash table\n";
trace 27 "### transformXMI: populate hash table\n";
insert_model xmiid_table model (* fill xmi.id table *);
trace function_calls "### transformXMI: fix associations\n";
trace 27 "### transformXMI: fix associations\n";
fix_associations xmiid_table model (* handle associations *);
trace function_calls "### transformXMI: transform XMI into Rep\n";
trace 27 "### transformXMI: transform XMI into Rep\n";
test2 (transform_package xmiid_table model) (* transform classifiers *)
end