From ced17e87f2db5440916aeeb08098bd49a2b4b80c Mon Sep 17 00:00:00 2001 From: "Achim D. Brucker" Date: Wed, 2 Nov 2005 17:59:56 +0000 Subject: [PATCH] added normalize_init git-svn-id: https://projects.brucker.ch/su4sml/svn/infsec-import/trunk/src/su4sml@3300 3260e6d1-4efc-4170-b0a7-36055960796d --- src/rep_core.sig | 1 + src/rep_core.sml | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/rep_core.sig b/src/rep_core.sig index baef25a..db8cafd 100644 --- a/src/rep_core.sig +++ b/src/rep_core.sig @@ -97,6 +97,7 @@ datatype Classifier = val OclAnyC : Classifier val normalize : Classifier -> Classifier +val normalize_init : Classifier -> Classifier val name_of : Classifier -> Rep_OclType.Path val package_of : Classifier -> Rep_OclType.Path diff --git a/src/rep_core.sml b/src/rep_core.sml index 53d8e4b..13decec 100644 --- a/src/rep_core.sml +++ b/src/rep_core.sml @@ -151,6 +151,9 @@ fun range_to_inv cls_name aend (a,b) = Rep_OclType.Boolean) end + + + (* calculate the invariants of an association end: *) (* 1. multiplicity constraints *) (* 2. consistency constraints between opposing association ends *) @@ -211,6 +214,61 @@ fun normalize (Class {name,parent,attributes,operations,associationends,invarian activity_graphs=nil}) | normalize c = c + +fun rm_init_attr (attr:attribute) = { + name = #name attr, + attr_type = #attr_type attr, + visibility = #visibility attr, + scope = #scope attr, + init = NONE +}:attribute + + +fun init_to_inv cls_name (attr:attribute) = + case (#init attr) of + NONE => (SOME ("init_"^(#name attr)), + Rep_OclTerm.Literal ("true",Rep_OclType.Boolean)) + | SOME(init) => let + val attr_name = cls_name@[#name attr] + val attr_type = #attr_type attr + val cls = Rep_OclType.Classifier cls_name + val self = Rep_OclTerm.Variable ("self",cls) + val attribute = Rep_OclTerm.AttributeCall (self,cls,attr_name,attr_type) + in + (SOME ("init_"^(#name attr)), + Rep_OclTerm.OperationCall + (Rep_OclTerm.OperationCall + (self,cls, + ["oclLib","OclAny","oclIsNew"],[],Rep_OclType.Boolean),Rep_OclType.Boolean, + ["oclLib","Boolean","implies"], + [(Rep_OclTerm.OperationCall (attribute, + attr_type,["oclLib","OclAny","="], + [(init,attr_type)],Rep_OclType.Boolean),Rep_OclType.Boolean)], + Rep_OclType.Boolean) + ) + + end + + +fun normalize_init (Class {name,parent,attributes,operations,associationends,invariant, + stereotypes,interfaces,thyname,activity_graphs}) = + Class {name = name, + parent = parent, + attributes = (map rm_init_attr attributes), + operations = operations, + associationends = nil, + invariant = append (map (init_to_inv name) attributes) + invariant, + stereotypes = stereotypes, + interfaces = interfaces, + thyname = thyname, + activity_graphs=activity_graphs} + | normalize_init c = c + + + + + val OclAnyC = Class{name=["OclAny"],parent=NONE,attributes=[], operations=[], interfaces=[], invariant=[],stereotypes=[], associationends=[],