浏览代码

added support for returning enumeration from procedure (added test in compilation test)

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7588 8c9fc860-2736-0410-a75d-ab315db34111
felixf 7 年之前
父节点
当前提交
2bc31288e1
共有 2 个文件被更改,包括 18 次插入1 次删除
  1. 1 1
      source/FoxIntermediateBackend.Mod
  2. 17 0
      source/Oberon.Compilation.Test

+ 1 - 1
source/FoxIntermediateBackend.Mod

@@ -10673,7 +10673,7 @@ TYPE
 					IF locked THEN Lock(FALSE) END;
 					IF ~backend.cooperative & profile THEN ProfilerEnterExit(numberProcedures,FALSE) END;
 					(* "RETURN RESULT" -> no assignment, it is assumed that result has been written to return parameter via structured return type *)
-				ELSIF (type IS SyntaxTree.BasicType) & ~(type IS SyntaxTree.RangeType) & ~(type IS SyntaxTree.ComplexType) & ~type.IsPointer() OR (procedureType.callingConvention # SyntaxTree.OberonCallingConvention) THEN
+				ELSIF (type IS SyntaxTree.BasicType) & ~(type IS SyntaxTree.RangeType) & ~(type IS SyntaxTree.ComplexType) & ~type.IsPointer() OR (type IS SyntaxTree.EnumerationType) OR (procedureType.callingConvention # SyntaxTree.OberonCallingConvention) THEN
 					(* return without structured return parameter *)
 					Evaluate(expression,res);
 					delegate := (type IS SyntaxTree.ProcedureType) & (type(SyntaxTree.ProcedureType).isDelegate);

+ 17 - 0
source/Oberon.Compilation.Test

@@ -8984,6 +8984,23 @@ negative: passing enumeration extension on extended type as var parameter
 		P1(fineColor);
 	END Test.
 
+positive: returning enumeration type
+
+	MODULE Test;
+
+	TYPE
+	Enumeration = ENUM 
+		red, green, blue
+	END;
+
+	PROCEDURE Test(): Enumeration;
+	BEGIN
+		RETURN Enumeration.green;
+	END Test;
+
+	BEGIN
+		ASSERT(Test() = Enumeration.green);
+	END Test.
 
 # variables