Forráskód Böngészése

Fixed string_substr and also all uses of it (e.g., user_manager)

Yentl Van Tendeloo 8 éve
szülő
commit
a2fc45e463

BIN
bootstrap/bootstrap.m.gz


+ 1 - 0
bootstrap/bootstrap.py

@@ -66,6 +66,7 @@ def bootstrap():
                     "list_len": ["Integer", "Element"],
                     "dict_add": ["Element", "Element", "Element", "Element"],
                     "dict_delete": ["Element", "Element", "Element"],
+                    "dict_delete_node": ["Element", "Element", "Element"],
                     "dict_read": ["Element", "Element", "Element"],
                     "dict_read_edge": ["Element", "Element", "Element"],
                     "dict_read_node": ["Element", "Element", "Element"],

BIN
bootstrap/minimal.m.gz


+ 6 - 9
bootstrap/modelling.alc

@@ -83,7 +83,7 @@ Void function retype(model : Element, element : String, type : String):
 	// Retype a model, deleting any previous type the element had
 	// The type string is evaluated in the metamodel previously specified
 	if (dict_in_node(model["type_mapping"], model["model"][element])):
-		dict_delete(model["type_mapping"], model["model"][element])
+		dict_delete_node(model["type_mapping"], model["model"][element])
 	dict_add(model["type_mapping"], model["model"][element], model["metamodel"]["model"][type])
 
 	return!
@@ -165,7 +165,6 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 	// Actually a bit more difficult than all the rest, as we need to find the attribute to instantiate
 	String attr_type
 	String attr_name
-	log("Add attribute")
 
 	attr_type = find_attribute_type(model, element, attribute_name)
 
@@ -175,13 +174,10 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 		
 	if (set_in_node(model["model"], value)):
 		attr_name = reverseKeyLookup(model["model"], value)
-		log("Reuse attribute " + attr_name)
 	else:
 		attr_name = model_add_value(model, (element + ".") + attribute_name, value)
 		retype(model, attr_name, reverseKeyLookup(model["metamodel"]["model"], read_edge_dst(model["metamodel"]["model"][attr_type])))
-		log("Added attribute " + attr_name)
 	instantiate_link(model, attr_type, "", element, attr_name)
-	log("instantiated link OK")
 
 	return!
 
@@ -203,7 +199,7 @@ Void function define_inheritance(model : Element, inheritance_name : String):
 Void function model_delete_element(model : Element, name : String):
 	// Remove the link
 	// 1) from the type mapping
-	dict_delete(model["type_mapping"], model["model"][name])
+	dict_delete_node(model["type_mapping"], model["model"][name])
 
 	// 2) from the model
 	delete_element(model["model"][name])
@@ -238,15 +234,16 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
 	String attr_type
 	Element attr_links
 	String attr_link
+	log((("Unsetting attribute " + attribute) + " of element ") + element)
 	
 	attr_type = find_attribute_type(model, element, attribute)
 	attr_links = allOutgoingAssociationInstances(model, element, attr_type)
 
 	while (list_len(attr_links) > 0):
 		attr_link = set_pop(attr_links)
-		dict_delete(model["type_mapping"], read_edge_dst(model["model"][attr_link]))
-		dict_delete(model["type_mapping"], model["model"][attr_link])
-		dict_delete(model["model"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
+		dict_delete_node(model["type_mapping"], read_edge_dst(model["model"][attr_link]))
+		dict_delete_node(model["type_mapping"], model["model"][attr_link])
+		dict_delete_node(model["model"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
 		delete_element(model["model"][attr_link])
 
 	return!

+ 2 - 1
bootstrap/primitives.alc

@@ -34,6 +34,7 @@ String function cast_v2s(a: Element) = ?primitives/cast_v2s
 String function cast_id2s(a: Element) = ?primitives/cast_id2s
 Element function dict_add(a: Element, b: Element, c: Element) = ?primitives/dict_add
 Element function dict_delete(a: Element, b: Element) = ?primitives/dict_delete
+Element function dict_delete_node(a: Element, b: Element) = ?primitives/dict_delete_node
 Element function dict_read(a: Element, b: Element) = ?primitives/dict_read
 Element function dict_read_edge(a: Element, b: Element) = ?primitives/dict_read_edge
 Element function dict_read_node(a: Element, b: Element) = ?primitives/dict_read_node
@@ -149,7 +150,7 @@ String function string_substr(a: String, b: Integer, c: Integer):
 	i = 0
 	result = ""
 	while (i < string_len(a)):
-		if (bool_and(i >= b, i < c)):
+		if (bool_and(i >= b, i <= c)):
 			result = result + string_get(a, i)
 
 		if (i > c):