Browse Source

Create default ctors in subclasses. Resolves #595.

Brucey 2 năm trước cách đây
mục cha
commit
1f2f921e43
3 tập tin đã thay đổi với 36 bổ sung16 xóa
  1. 9 4
      ctranslator.bmx
  2. 26 11
      decl.bmx
  3. 1 1
      options.bmx

+ 9 - 4
ctranslator.bmx

@@ -5017,12 +5017,17 @@ End Rem
 		Else
 			t :+ classid + "_New"
 		End If
-		
+
 		'Find decl we override
 		Local odecl:TFuncDecl=fdecl
-		While odecl.overrides
-			odecl=odecl.overrides
-		Wend
+
+		If odecl.overrides And odecl.generated Then
+			fdecl = odecl.overrides
+		Else
+			While odecl.overrides
+				odecl=odecl.overrides
+			Wend
+		End If
 
 		Local args:String = TransObject(classdecl, True) + " o"
 

+ 26 - 11
decl.bmx

@@ -2863,7 +2863,7 @@ End Rem
 		Return Super.FindFuncDecl( ident,args,explicit,,isIdentExpr,0,0 )
 	End Method
 	
-	Method GetAllFuncDecls:TFuncDecl[](funcs:TFuncDecl[] = Null, includeSuper:Int = True)
+	Method GetAllFuncDecls:TFuncDecl[](funcs:TFuncDecl[] = Null, includeSuper:Int = True, onlyCtors:Int = False)
 
 		If Not funcs Then
 			funcs = New TFuncDecl[0]
@@ -2879,7 +2879,11 @@ End Rem
 		Next
 		
 		For Local func:TFuncDecl = EachIn _decls
-		
+
+			If onlyCtors And Not func.IsCtor() Then
+				Continue
+			End If
+
 			Local matched:Int = False
 			
 			For Local i:Int = 0 Until funcs.length
@@ -3127,18 +3131,29 @@ End Rem
 
 		If Not IsExtern() And Not IsInterface()
 			Local fdecl:TFuncDecl
-			For Local decl:TFuncDecl=EachIn FuncDecls()
+			For Local decl:TFuncDecl=EachIn GetAllFuncDecls(Null, True, True)
 				If Not decl.IsCtor() Continue
-				Local nargs:Int
-				For Local arg:TArgDecl=EachIn decl.argDecls
-					If Not arg.init nargs:+1
-				Next
-				If nargs Continue
-				fdecl=decl
-				Exit
+
+				' only non default ctors
+				If decl.argDecls.Length > 0 Then
+
+					' method belongs to super? implement default
+					If decl.Scope <> Self Then
+
+						fdecl = TFuncDecl(decl.OnCopy(False))
+						fdecl.generated = True
+						fdecl.scope = Null
+						fdecl.overrides = decl
+						TNewDecl(fdecl).cdecl = Self
+						InsertDecl(fdecl)
+
+					End If
+
+				End If
+
 			Next
 			
-			
+
 			' Don't need default new?
 			'If Not fdecl
 			'	fdecl=New TFuncDecl.CreateF( "new",New TObjectType.Create( Self ),Null,FUNC_CTOR )

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.134"
+Const version:String = "0.135"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1