فهرست منبع

Also fixed the model constructor

Yentl Van Tendeloo 8 سال پیش
والد
کامیت
3dcaa7c5d4
24فایلهای تغییر یافته به همراه46 افزوده شده و 38 حذف شده
  1. 24 15
      interface/HUTN/hutn_compiler/model_visitor.py
  2. 0 1
      interface/HUTN/hutn_compiler/primitives_visitor.py
  3. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/action
  4. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/assign
  5. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/dict_access
  6. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/factorial
  7. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci
  8. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci_smart
  9. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/funccall
  10. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/funccall_params
  11. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/funcdef_params
  12. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/global
  13. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/ifelse
  14. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/include
  15. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/multi_include
  16. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/mutual_recursion
  17. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/types
  18. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/vardecl
  19. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/while
  20. 1 1
      interface/HUTN/test/modelling_language/expected/my_petrinet
  21. 1 1
      interface/HUTN/test/modelling_language/expected/my_petrinet_with_MM
  22. 1 1
      interface/HUTN/test/modelling_language/expected/petrinets
  23. 1 1
      interface/HUTN/test/modelling_language/expected/petrinets_constraints
  24. 1 1
      interface/HUTN/test/modelling_language/expected/simpleclassdiagrams

+ 24 - 15
interface/HUTN/hutn_compiler/model_visitor.py

@@ -2,9 +2,6 @@ from visitor import Visitor
 from compiler import main as do_compile
 import os
 
-def jsonstr(s):
-    return '"%s"' % s
-
 def empty(s):
     return None
 
@@ -37,19 +34,19 @@ class ModelVisitor(Visitor):
     def visit_import(self, tree):
         url = tree.get_children("MV_URL")[0]
         target = tree.get_children("MODEL_ID")[0]
-        self.constructors.extend(['"import_node"', jsonstr(url.get_text()), jsonstr(target.get_text())])
+        self.constructors.extend(["import_node", url.get_text(), target.get_text()])
 
     def visit_export(self, tree):
         url = tree.get_children("MV_URL")[0]
         target = tree.get_children("MODEL_ID")[0]
-        self.constructors.extend(['"export_node"', jsonstr(target.get_text()), jsonstr(url.get_text())])
+        self.constructors.extend(["export_node", target.get_text(), url.get_text()])
 
     def visit_model(self, tree):
         children = tree.get_children("MODEL_ID")
         model_type = children[0].get_text()
         model_name = children[1].get_text()
-        self.constructors.extend(['"instantiate_model"', jsonstr(model_type), jsonstr(model_name)])
-        self.constructors.extend(['"define_inheritance"', jsonstr(model_name), jsonstr("Inheritance")])
+        self.constructors.extend(["instantiate_model", model_type, model_name])
+        self.constructors.extend(["define_inheritance", model_name, "Inheritance"])
         self.current_model = model_name
         for element in tree.get_children("model_element"):
             self.visit(element)
@@ -67,9 +64,9 @@ class ModelVisitor(Visitor):
             # So we have a source and target; but aren't sure which is which, because the name is optional!
             source_name = children[-2].get_text()
             target_name = children[-1].get_text()
-            self.constructors.extend(['"instantiate_link"', jsonstr(self.current_model), jsonstr(element_type), jsonstr(element_name), jsonstr(source_name), jsonstr(target_name)])
+            self.constructors.extend(["instantiate_link", self.current_model, element_type, element_name, source_name, target_name])
         else:
-            self.constructors.extend(['"instantiate_node"', jsonstr(self.current_model), jsonstr(element_type), jsonstr(element_name)])
+            self.constructors.extend(["instantiate_node", self.current_model, element_type, element_name])
         self.current_element = element_name
 
         if tree.get_children("inheritance"):
@@ -81,7 +78,7 @@ class ModelVisitor(Visitor):
     def visit_inheritance(self, tree):
         for token in tree.get_children("MODEL_ID"):
             superclass = token.get_text()
-            self.constructors.extend(['"instantiate_link"', jsonstr(self.current_model), jsonstr("Inheritance"), jsonstr("%s_inherits_from_%s" % (self.current_element, superclass)), jsonstr(self.current_element), jsonstr(superclass)])
+            self.constructors.extend(["instantiate_link", self.current_model, "Inheritance", "%s_inherits_from_%s" % (self.current_element, superclass), self.current_element, superclass])
 
     def visit_model_attribute(self, tree):
         children = tree.get_children("MODEL_ID")
@@ -92,9 +89,9 @@ class ModelVisitor(Visitor):
         if is_definition:
             attr_name = children[0].get_text()
             attr_type = children[1].get_text()
-            self.constructors.extend(['"instantiate_link"', jsonstr(self.current_model), jsonstr("Association"), jsonstr(self.current_element + "_" + attr_name), jsonstr(self.current_element), jsonstr(attr_type)])
+            self.constructors.extend(["instantiate_link", self.current_model, "Association", self.current_element + "_" + attr_name, self.current_element, attr_type])
             full_attribute_name = self.current_element + "_" + attr_name
-            self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(full_attribute_name), jsonstr("name"), jsonstr(attr_name)])
+            self.constructors.extend(["instantiate_attribute", self.current_model, full_attribute_name, "name", attr_name])
             if is_assign:
                 # There are also some attributes to set!
                 old_element = self.current_element
@@ -117,10 +114,22 @@ class ModelVisitor(Visitor):
                 f.write(constraint)
                 f.flush()
             directory = os.path.realpath(__file__).rsplit(os.sep, 1)[0]
-            self.constructors.extend(['"add_constraint"', jsonstr(self.current_model), jsonstr(self.current_element)] + do_compile(".constraint.alc", directory + "/../grammars/actionlanguage.g", "CS"))
+            self.constructors.extend(["add_constraint", self.current_model, self.current_element] + do_compile(".constraint.alc", directory + "/../grammars/actionlanguage.g", "CS"))
 
     def visit_model_attr_instance(self, tree):
         children = tree.get_children("MODEL_ID")
         attr_name = children[0].get_text()
-        attr_value = tree.get_children("value")[0]
-        self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(self.current_element), jsonstr(attr_name), jsonstr(attr_value.get_text()) if attr_value.head == "STRVALUE" else attr_value.get_text()])
+        attr_value = tree.get_children("value")[0].get_tail()[0]
+        if attr_value.head == "STRVALUE":
+            attr_value = attr_value.get_text()[1:-1]
+        elif attr_value.head == "TRUE":
+            attr_value = True
+        elif attr_value.head == "FALSE":
+            attr_value = False
+        elif attr_value.head == "DEC_NUMBER":
+            attr_value = int(attr_value.get_text())
+        elif attr_value.head == "FLOAT_NUMBER":
+            attr_value = float(attr_value.get_text())
+        else:
+            raise Exception(attr_value.head)
+        self.constructors.extend(["instantiate_attribute", self.current_model, self.current_element, attr_name, attr_value])

+ 0 - 1
interface/HUTN/hutn_compiler/primitives_visitor.py

@@ -189,7 +189,6 @@ class PrimitivesVisitor(Visitor):
             v = tree.get_text()[1:]
         else:
             v = tree.get_text()
-        print("Literal: " + str(v))
         #NOTE Wrap this in an Action, even though it might not be an action: this has to be seen directly in the Mv without additional wrapping
         n = self.value(Action(v))
         self.dict(c, "node", n)

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/action

@@ -1 +1 @@
-["\"funcdef\"", "\"test\"", "0", "\"declare\"", "\"0\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"if\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"while\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"assign\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"global\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"call\"}", "false", "false"]
+["funcdef", "test", 0, "declare", "0", true, "assign", "resolve", "0", "const", {"value": "if"}, true, "assign", "resolve", "0", "const", {"value": "while"}, true, "assign", "resolve", "0", "const", {"value": "assign"}, true, "assign", "resolve", "0", "const", {"value": "global"}, true, "assign", "resolve", "0", "const", {"value": "call"}, false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/assign

@@ -1 +1 @@
-["\"funcdef\"", "\"test\"", "0", "\"declare\"", "\"0\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "1", "false", "false"]
+["funcdef", "test", 0, "declare", "0", true, "assign", "resolve", "0", "const", 1, false, false]

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/dict_access


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/factorial


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci_smart


+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/funccall

@@ -1 +1 @@
-["\"funcdef\"", "\"test\"", "0", "\"call\"", "\"access\"", "\"resolve\"", "\"test\"", "0", "false", "false"]
+["funcdef", "test", 0, "call", "access", "resolve", "test", 0, false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/funccall_params

@@ -1 +1 @@
-["\"funcdef\"", "\"abc\"", "1", "\"0\"", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "1", "false", "true", "\"funcdef\"", "\"main\"", "0", "\"call\"", "\"access\"", "\"resolve\"", "\"abc\"", "1", "\"const\"", "2", "false", "false"]
+["funcdef", "abc", 1, "0", "assign", "resolve", "0", "const", 1, false, true, "funcdef", "main", 0, "call", "access", "resolve", "abc", 1, "const", 2, false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/funcdef_params

@@ -1 +1 @@
-["\"funcdef\"", "\"abc\"", "1", "\"0\"", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "1", "false", "false"]
+["funcdef", "abc", 1, "0", "assign", "resolve", "0", "const", 1, false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/global

@@ -1 +1 @@
-["\"global\"", "\"a\"", "\"const\"", "1", "true", "\"global\"", "\"b\"", "true", "\"funcdef\"", "\"abc\"", "0", "\"declare\"", "\"0\"", "false", "false"]
+["global", "a", "const", 1, true, "global", "b", true, "funcdef", "abc", 0, "declare", "0", false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/ifelse

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"declare\"", "\"0\"", "true", "\"if\"", "\"const\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "2", "false", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "3", "false", "false", "false"]
+["funcdef", "main", 0, "declare", "0", true, "if", "const", true, "assign", "resolve", "0", "const", 2, false, true, "assign", "resolve", "0", "const", 3, false, false, false]

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/include


+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/multi_include

@@ -1 +1 @@
-["\"global\"", "\"a\"", "true", "\"global\"", "\"b\"", "true", "\"global\"", "\"c\"", "false"]
+["global", "a", true, "global", "b", true, "global", "c", false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/mutual_recursion

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"call\"", "\"access\"", "\"resolve\"", "\"a\"", "0", "false", "true", "\"funcdef\"", "\"a\"", "0", "\"return\"", "true", "\"call\"", "\"access\"", "\"resolve\"", "\"b\"", "0", "false", "true", "\"funcdef\"", "\"b\"", "0", "\"return\"", "true", "\"call\"", "\"access\"", "\"resolve\"", "\"a\"", "0", "false", "false"]
+["funcdef", "main", 0, "call", "access", "resolve", "a", 0, false, true, "funcdef", "a", 0, "return", true, "call", "access", "resolve", "b", 0, false, true, "funcdef", "b", 0, "return", true, "call", "access", "resolve", "a", 0, false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/types

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"declare\"", "\"0\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"Integer\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"Type\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"Action\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"String\"}", "false", "false"]
+["funcdef", "main", 0, "declare", "0", true, "assign", "resolve", "0", "const", {"value": "Integer"}, true, "assign", "resolve", "0", "const", {"value": "Type"}, true, "assign", "resolve", "0", "const", {"value": "Action"}, true, "assign", "resolve", "0", "const", {"value": "String"}, false, false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/vardecl

@@ -1 +1 @@
-["\"global\"", "\"a\"", "false"]
+["global", "a", false]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/while

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"declare\"", "\"0\"", "true", "\"while\"", "\"const\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "2", "false", "false", "false"]
+["funcdef", "main", 0, "declare", "0", true, "while", "const", true, "assign", "resolve", "0", "const", 2, false, false, false]

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/modelling_language/expected/my_petrinet


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/modelling_language/expected/my_petrinet_with_MM


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/modelling_language/expected/petrinets


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/modelling_language/expected/petrinets_constraints


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
interface/HUTN/test/modelling_language/expected/simpleclassdiagrams