瀏覽代碼

Added basics of FTG code

Yentl Van Tendeloo 8 年之前
父節點
當前提交
77b1ec2eb1

二進制
bootstrap/bootstrap.m.gz


+ 45 - 3
bootstrap/ftg.alc

@@ -1,8 +1,50 @@
 include "primitives.alh"
+include "modelling.alh"
+include "library.alh"
+
+Void function visit_ftg(ftg : Element, root : Element, path : Element, current : Element):
+	if (dict_in(current, "source")):
+		// Is a transformation, and therefore an edge for the FTG
+		if (bool_not(dict_in(ftg["model"], path))):
+			if (bool_not(dict_in(ftg["model"], current["source"]))):
+				visit_ftg(ftg, root, current["source"], root[current["source"]])
+
+			if (bool_not(dict_in(ftg["model"], current["target"]))):
+				visit_ftg(ftg, root, current["target"], root[current["source"]])
+
+			instantiate_link(ftg, "Transformation", path, current["source"], current["target"])
+			instantiate_attribute(ftg, path, "location", path)
+	else:
+		// Is a model, and therefore a node for the FTG
+		if (bool_not(dict_in(ftg["model"], path))):
+			instantiate_node(ftg, "Formalism", path)
+			instantiate_attribute(ftg, path, "location", path)
+
+	return !
 
 Element function create_ftg(root : Element):
-	Element result
+	Element queue
+	Element current
+	Element submodels
+	Element ftg
+	String path
+	String submodel
+
+	queue = create_node()
+	set_add(queue, create_tuple("", root))
+	ftg = instantiate_model(import_node("models/FTG"))
 
-	result = create_node()
+	while (read_nr_out(queue) > 0):
+		current = set_pop(queue)
+		path = current[0]
+		current = current[1]
+		if (dict_in(current, "__kind" )):
+			visit_ftg(ftg, root, path, current)
+		else:
+			submodels = dict_keys(current)
+			// Is a browser structure, and therefore not part of the FTG
+			while (read_nr_out(submodels) > 0):
+				submodel = set_pop(submodels)
+				set_add(queue, create_tuple((path + "/") + submodel, current[submodel]))
 
-	return result!
+	return ftg!

+ 1 - 0
bootstrap/modelling.alc

@@ -24,6 +24,7 @@ Element function instantiate_bottom():
 	// Add an empty model and empty type mapping
 	dict_add(new_model, "model", create_node())
 	dict_add(new_model, "type_mapping", create_node())
+	dict_add(new_model, "__kind", "formalism")
 
 	// Return the created model
 	return new_model!

+ 9 - 0
bootstrap/primitives.alc

@@ -225,6 +225,15 @@ String function list_to_string(s : Element):
 
 	return result!
 
+Element function create_tuple(a : Element, b : Element):
+	Element tuple
+
+	tuple = create_node()
+	list_append(tuple, a)
+	list_append(tuple, b)
+
+	return tuple!
+
 String function dict_to_string(d : Element):
 	String result
 	Element keys

+ 5 - 0
integration/code/pn_interface.alc

@@ -10,6 +10,7 @@ include "compilation_manager.alh"
 include "ramify.alh"
 include "transform.alh"
 include "model_management.alh"
+include "ftg.alh"
 
 Element function model_loaded(model : Element):
 	String cmd
@@ -476,6 +477,10 @@ Void function main():
 					output("Unknown transformation selected!")
 			else:
 				output("Unknown host model selected!")
+		elif (command == "generate_ftg"):
+			Element ftg
+			ftg = create_ftg(root)
+			dict_add(root, "FTG", ftg)
 		else:
 			output("Command not recognized, use 'help' for a list of possible commands")
 

+ 1 - 0
interface/HUTN/includes/ftg.alh

@@ -0,0 +1 @@
+Element function create_ftg(root : Element)

+ 1 - 0
interface/HUTN/includes/primitives.alh

@@ -103,3 +103,4 @@ String function dict_to_string(dict : Element)
 Element function set_overlap(sa : Element, sb : Element)
 Element function dict_copy(dict : Element)
 Element function set_to_list(s : Element)
+Element function create_tuple(a : Element, b : Element)