Browse Source

Fixed getAttributeList library function and GUI for FSAs

Yentl Van Tendeloo 8 years ago
parent
commit
b69940d398

BIN
bootstrap/bootstrap.m.gz


+ 14 - 12
bootstrap/object_operations.alc

@@ -1,6 +1,7 @@
 include "primitives.alh"
 include "conformance_scd.alh"
 include "constructors.alh"
+include "modelling.alh"
 
 Element function allInstances(model : Element, type_name : String):
 	Element type_mapping
@@ -101,21 +102,22 @@ Element function getAttributeList(model : Element, element : String):
 	Element keys
 	Element type
 	Element attr_name
+	Element types
 	String attr_type
 
 	result = create_node()
-	type = dict_read_node(model["type_mapping"], model["model"][element])
-	keys = dict_keys(type)
-
-	// Add our own attributes
-	while (0 < list_len(keys)):
-		attr_name = set_pop(keys)
-		if (is_physical_string(attr_name)):
-			attr_type = reverseKeyLookup(model["metamodel"]["model"], type[attr_name])
-			dict_add(result, attr_name, attr_type)
-
-	// Go on to the metalevel
-	// TODO
+	types = get_superclasses(model["metamodel"], reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][element])))
+
+	while (read_nr_out(types) > 0):
+		type = set_pop(types)
+		keys = dict_keys(model["metamodel"]["model"][type])
+
+		// Add our own attributes
+		while (0 < list_len(keys)):
+			attr_name = set_pop(keys)
+			if (is_physical_string(attr_name)):
+				attr_type = reverseKeyLookup(model["metamodel"]["model"], type[attr_name])
+				dict_add(result, attr_name, attr_type)
 
 	return result!
 

+ 5 - 5
integration/code/fsa_semantics.alc

@@ -51,9 +51,10 @@ Element function sanitize(new_runtime_model : Element, old_runtime_model : Eleme
 	String cstate_obj
 	log("Start sanitize")
 
-	if (read_nr_out(allInstances(old_runtime_model, "CurrentState")) > 0):
+	cstate_obj = instantiate_node(new_runtime_model, "CurrentState", "")
+
+	if (read_nr_out(allInstances(old_runtime_model, "CurrentStateLink")) > 0):
 		cstate = readAssociationDestination(old_runtime_model, set_pop(allInstances(old_runtime_model, "CurrentStateLink")))
-		cstate_obj = instantiate_node(new_runtime_model, "CurrentState", "")
 		if (bool_not(dict_in(new_runtime_model["model"], cstate))):
 			// Current state removed, so fix
 			if (auto):
@@ -124,6 +125,7 @@ Void function execute_fsa(design_model : Element):
 	Float start_time
 	Boolean automatic_sanitization
 
+	automatic_sanitization = True
 	start_time = time()
 	simulation_time = 0.0
 	old_runtime_model = instantiate_model(import_node("models/FiniteStateAutomata_Runtime"))
@@ -137,7 +139,6 @@ Void function execute_fsa(design_model : Element):
 		output("CONFORMANCE_FAIL")
 
 	while (True):
-		log("Check input")
 		if (has_input()):
 			cmd = input()
 		else:
@@ -188,9 +189,7 @@ Void function execute_fsa(design_model : Element):
 
 		elif (cmd == "read_attribute"):
 			// Returns the value of an attribute
-			log("Sending attribute value for")
 			output("ATTR_VALUE " + cast_v2s(read_attribute(design_model, input(), input())))
-			log("Sending OK")
 
 		elif (bool_or(cmd == "switch_initial", bool_or(bool_or(cmd == "set_attribute", cmd == "instantiate_node"), bool_or(cmd == "delete_element", cmd == "instantiate_association")))):
 			// Modify the structure
@@ -239,6 +238,7 @@ Void function execute_fsa(design_model : Element):
 				old_runtime_model = runtime_model
 				start_time = time() - simulation_time
 				output("CONFORMANCE_OK")
+				log("Conformance became OK")
 			else:
 				// Not conforming, so stop simulation and block for input (preferably a modify to make everything consistent again)
 				output("CONFORMANCE_FAIL " + conforming)

+ 2 - 4
interface/FSA/main.py

@@ -94,6 +94,8 @@ do_color = "grey"
 def poll(address):
     simulation_time = None
     working_available_attrs = []
+    global do_color
+    global request_new_state
 
     while 1:
         returnvalue = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read())
@@ -121,14 +123,10 @@ def poll(address):
         elif (returnvalue.startswith("SIM_RAISE")):
             outp_evts.append((simulation_time, returnvalue.split(" ", 1)[1]))
         elif (returnvalue.startswith("CONFORMANCE_OK")):
-            global do_color
             do_color = "grey"
         elif (returnvalue.startswith("CONFORMANCE_FAIL")):
-            global do_color
             do_color = "red"
         elif (returnvalue.startswith("REQUEST_CURRENT_STATE")):
-            global do_color
-            global request_new_state
             do_color = "blue"
             request_new_state = True
         else: