浏览代码

Add example for multi conformance

Yentl Van Tendeloo 7 年之前
父节点
当前提交
06e1f2bd6e
共有 2 个文件被更改,包括 82 次插入0 次删除
  1. 64 0
      examples/multi_conformance.py
  2. 18 0
      models/Conformance/AToMPM.alc

+ 64 - 0
examples/multi_conformance.py

@@ -0,0 +1,64 @@
+import sys
+sys.path.append("wrappers")
+from modelverse import *
+
+init()
+login("admin", "admin")
+
+mm = \
+"""
+include "primitives.alh"
+
+SimpleAttribute integer {
+    constraint = $
+        Boolean function constraint(value : Element):
+            return is_physical_int(value)!
+        $
+}
+SimpleAttribute string {
+    constraint = $
+        Boolean function constraint(value : Element):
+            return is_physical_string(value)!
+        $
+}
+
+Class A {
+    d : integer
+}
+Class B {
+    d : string
+}
+Class C {}
+
+Inheritance (C, A) {}
+Inheritance (C, B) {}
+"""
+
+model_string = \
+"""
+C {
+    d = "a"
+}
+"""
+
+model_integer = \
+"""
+C {
+    d = 1
+}
+"""
+
+model_add("formalisms/simple_mm", "formalisms/SimpleClassDiagrams", mm)
+model_add("models/model_string", "formalisms/simple_mm", model_string)
+model_add("models/model_integer", "formalisms/simple_mm", model_integer)
+
+transformation_add_AL({"model": "formalisms/simple_mm", "metamodel": "formalisms/SimpleClassDiagrams", "type_mapping": "formalisms/TypeMapping"}, {}, "models/conformance_AToMPM", open("models/Conformance/AToMPM.alc", 'r').read())
+#transformation_add_AL({"model": "formalisms/simple_mm", "metamodel": "formalisms/SimpleClassDiagrams", "type_mapping": "formalisms/TypeMapping"}, {}, "models/conformance_MetaDepth", open("models/Conformance/MetaDepth.alc", 'r').read())
+
+print(model_types("models/model_string"))
+
+#print(verify("models/model_string", "formalisms/simple_mm", "models/conformance_AToMPM"))
+transformation_execute_AL("models/conformance_AToMPM", {"model": "models/model_integer", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_integer").pop()[1]}, {})
+#print(verify("models/model_integer", "formalisms/simple_mm", "models/conformance_AToMPM"))
+#print(verify("models/model_string", "formalisms/simple_mm", "models/conformance_MetaDepth"))
+#print(verify("models/model_integer", "formalisms/simple_mm", "models/conformance_MetaDepth"))

+ 18 - 0
models/Conformance/AToMPM.alc

@@ -0,0 +1,18 @@
+include "primitives.alh"
+
+Boolean function main(model : Element):
+	// Contains three types of models: model, metamodel, and type_mapping.
+	// Each with the obvious meanings.
+
+	// Note that this is only a placeholder that serves as a proof of concept.
+	// Thus only the check for multiple inheritance is being done, which checks for attributes.
+	// A full example is given in the Modelverse's internal conformance relation.
+
+	// Find all instances of classes
+
+	// Figure out the set of required attributes
+
+	// Check if each attribute is there, and satisfies the constraints
+	log("Performing conformance check!")
+
+	return True!