瀏覽代碼

Port source files to Python3.

Bentley James Oakes 7 年之前
父節點
當前提交
7a8db8958b

+ 9 - 3
src/python_sccd/python_sccd_compiler/generic_language_constructs.py

@@ -727,10 +727,16 @@ class NoneExpression(SimpleExpression):
 # helpers
 
 def MakeExpression(expr):
+
+	try:
+		if isinstance(expr, basestring):
+			return Literal(expr)
+	except NameError:
+		if isinstance(expr, str):
+			return Literal(expr)
+
 	if isinstance(expr, Expression):
 		return expr
-	elif isinstance(expr, basestring):
-		return Literal(expr)
 	elif expr is None:
 		return None
 	else:
@@ -764,7 +770,7 @@ def MakeDeclaration(obj):
 	if isinstance(obj, DeclarationBase):
 		return obj
 	else:
-		raise Exception("Can't turn argument of type '" + str(type(stmt)) + "' into DeclarationBase.")
+		raise Exception("Can't turn argument of type '" + str(type(obj)) + "' into DeclarationBase.")
 
 def MakeActualParameters(obj):
 	if isinstance(obj, ActualParameters):

+ 14 - 4
src/python_sccd/python_sccd_compiler/sccd_constructs.py

@@ -864,7 +864,11 @@ class Class(Visitable):
         for i in inheritances :
             self.super_classes.append((i.get("class",""),i.get("priority",1)))
 
-        self.super_classes.sort(lambda a, b: cmp(b[1], a[1])) # sort from high priority to low priority
+        try:
+            self.super_classes.sort(lambda a, b: cmp(b[1], a[1])) # sort from high priority to low priority
+        except TypeError:
+            self.super_classes = sorted(self.super_classes, key=lambda x: x[1], reverse = True)
+
         priorityChecker = {}
         for super_class, priority in self.super_classes:
             if priority in priorityChecker:
@@ -874,7 +878,8 @@ class Class(Visitable):
             if super_class not in checkIt:
                 checkIt.append(super_class)
             priorityChecker[priority] = checkIt
-        for priority, checkIt in priorityChecker.iteritems():
+
+        for priority, checkIt in priorityChecker.items():
             if len(checkIt) > 1:
                 Logger.showWarning("Class <" + self.name + "> inherits from classes <" + ", ".join(checkIt) + "> with same priority <" + str(priority) + ">. Document inheritance order is used.")
 
@@ -999,6 +1004,7 @@ class ClassDiagram(Visitable):
         # unique class names
         self.class_names = []
         substituted_xml_classes = []
+        default_substituted_xml_classes = []
         for xml_class in xml_classes :
             class_src = xml_class.get("src", "")
             class_default = xml_class.get("default", "")
@@ -1008,7 +1014,10 @@ class ClassDiagram(Visitable):
                 substituted_xml_class = ET.parse(class_src).getroot()
             else:
                 substituted_xml_class = xml_class
-            substituted_xml_class.is_default = (class_default.lower() == "true")
+
+            if class_default.lower() == "true":
+                default_substituted_xml_classes.append(substituted_xml_class)
+
             name = substituted_xml_class.get("name", "")
             if name == "" :
                 raise CompilerException("Missing or emtpy class name.")
@@ -1062,7 +1071,8 @@ class ClassDiagram(Visitable):
             # let user know this class was successfully loaded
             Logger.showInfo("Class <" + processed_class.name + "> has been successfully loaded.")
             self.classes.append(processed_class)
-            if xml_class.is_default :
+
+            if xml_class in default_substituted_xml_classes:
                 default_classes.append(processed_class)
             
         if not default_classes or len(default_classes) > 1:

+ 1 - 1
src/python_sccd/python_sccd_compiler/super_class_linker.py

@@ -27,7 +27,7 @@ class SuperClassLinker(Visitor):
 		c.abstract_method_names = getClassAbstractMethodNames(c)
 
 		# check if <super> tags exist for all inherited classes
-		for name,obj in c.super_class_objs.iteritems():
+		for name,obj in c.super_class_objs.items():
 			if obj:
 				if name not in c.constructors[0].super_class_parameters:
 					num_params = len(obj.constructors[0].parameters)

+ 1 - 1
src/python_sccd/python_sccd_runtime/statecharts_core.py

@@ -1071,7 +1071,7 @@ class RuntimeClassBase(object):
                 due = [self.events.pop()]
             is_stable = not self.bigStep(due)
             self.processBigStepOutput()
-        for index, entry in self.timers_to_add.iteritems():
+        for index, entry in self.timers_to_add.items():
             self.timers[index] = self.events.add(*entry)
         self.timers_to_add = {}
         self.__set_stable(True)