浏览代码

Fixed return statment in Delete() issues.
Fixed strict function pointers defaulting to return void instead of int.

woollybah 9 年之前
父节点
当前提交
f39a45e43c
共有 4 个文件被更改,包括 39 次插入7 次删除
  1. 9 3
      ctranslator.bmx
  2. 13 2
      decl.bmx
  3. 5 2
      parser.bmx
  4. 12 0
      translator.bmx

+ 9 - 3
ctranslator.bmx

@@ -3641,14 +3641,20 @@ End Rem
 		Next
 
 		' finally, call super delete
+		EmitClassDeclDeleteDtor(classDecl)
+
+		'
+		Emit "}"
+	End Method
+	
+	Method EmitClassDeclDeleteDtor( classDecl:TClassDecl )
+		Local superid$=classDecl.superClass.actual.munged
+		
 		If classDecl.superClass.ident = "Object" Or Not classHierarchyHasFunction(classDecl.superClass, "Delete") Then
 			Emit "bbObjectDtor(o);"
 		Else
 			Emit "_" + superid + "_Delete(o);"
 		End If
-
-		'
-		Emit "}"
 	End Method
 
 	Method TransFieldRef:String(decl:TFieldDecl, variable:String, exprType:TType = Null)

+ 13 - 2
decl.bmx

@@ -1074,6 +1074,7 @@ End Type
 Const FUNC_METHOD:Int=   $0001			'mutually exclusive with ctor
 Const FUNC_CTOR:Int=     $0002
 Const FUNC_PROPERTY:Int= $0004
+Const FUNC_DTOR:Int=     $0008
 Const FUNC_PTR:Int=      $0100
 Const FUNC_BUILTIN:Int = $0080
 Const FUNC_INIT:Int =    $0200
@@ -1194,6 +1195,10 @@ Type TFuncDecl Extends TBlockDecl
 		Return (attrs & FUNC_CTOR)<>0
 	End Method
 
+	Method IsDtor:Int()
+		Return (attrs & FUNC_DTOR)<>0
+	End Method
+
 	Method IsMethod:Int()
 		Return (attrs & FUNC_METHOD)<>0
 	End Method
@@ -1228,12 +1233,18 @@ Type TFuncDecl Extends TBlockDecl
 				retType = TType.voidType
 			Else If TIdentType(retType)
 				retType = retType.Semant()
+			Else
+				' for Strict code, a void return type becomes Int
+				If TVoidType(retType) And Not ModuleScope().IsSuperStrict() Then
+					strictVoidToInt = True
+					retType = New TIntType
+				End If
 			End If
 		Else
 			retType=retTypeExpr.Semant()
 			
 			' for Strict code, a void return type becomes Int
-			If TVoidType(retType) And Not ModuleScope().IsSuperStrict() Then
+			If TVoidType(retType) And Not ModuleScope().IsSuperStrict() And Not IsDTor() Then
 				strictVoidToInt = True
 				retType = New TIntType
 			End If
@@ -1361,7 +1372,7 @@ Type TFuncDecl Extends TBlockDecl
 
 		'append a return statement if necessary
 		If Not IsExtern() And Not TVoidType( retType ) And Not TReturnStmt( stmts.Last() )
-			If Not isCtor() And Not (isMethod() And IdentLower() = "delete") 
+			If Not isCtor() And Not isDtor()
 				Local stmt:TReturnStmt
 
 				stmt=New TReturnStmt.Create( New TConstExpr.Create( retType,"" ) )

+ 5 - 2
parser.bmx

@@ -2525,8 +2525,11 @@ End Rem
 				End If
 
 				' Delete() return type should always be Void
-				If id.ToLower() = "delete" And TIntType(ty) Then
-					ty = New TVoidType
+				If id.ToLower() = "delete" Then
+					attrs:|FUNC_DTOR
+					If TIntType(ty) Then
+						ty = New TVoidType
+					End If
 				End If
 			EndIf
 		Else

+ 12 - 0
translator.bmx

@@ -789,6 +789,15 @@ End Rem
 
 		FreeVarsIfRequired()
 		
+		' if this is a Delete() method, we need to call the dtor first
+		Local funcScope:TFuncDecl = _env.FuncScope()
+		If funcScope And funcScope.IdentLower() = "delete" Then
+			Local classScope:TClassDecl = funcScope.ClassScope()
+			If classScope Then
+				EmitClassDeclDeleteDtor(classScope)
+			End If
+		End If
+		
 		Return t
 	End Method
 	
@@ -1582,6 +1591,9 @@ End Rem
 		End If
 	End Method
 	
+	Method EmitClassDeclDeleteDtor( classDecl:TClassDecl )
+	End Method
+	
 End Type
 
 Type TTryBreakCheck