Просмотр исходного кода

Fixed local init issue in subclass New() reimp.

woollybah 8 лет назад
Родитель
Сommit
1a2bb9b064
4 измененных файлов с 90 добавлено и 8 удалено
  1. 6 1
      ctranslator.bmx
  2. 53 3
      decl.bmx
  3. 12 3
      parser.bmx
  4. 19 1
      stmt.bmx

+ 6 - 1
ctranslator.bmx

@@ -4289,7 +4289,12 @@ End Rem
 		
 		For Local fdecl:TFuncDecl = EachIn newDecls
 		
-			EmitClassDeclNew(classDecl, fdecl)
+			If fdecl.scope <> classDecl Then
+				fdecl.Clear()
+				EmitClassDeclNew(classDecl, fdecl)
+			Else
+				EmitClassDeclNew(classDecl, fdecl)
+			End If
 
 			' generate "objectNew" function if required
 			If (fdecl.argDecls And fdecl.argDecls.length) Or classDecl.IsStruct() Then

+ 53 - 3
decl.bmx

@@ -303,6 +303,9 @@ Type TDecl
 	End Method
 	
 	Method OnSemant() Abstract
+	
+	Method Clear()
+	End Method
 
 End Type
 
@@ -493,6 +496,9 @@ Type TValDecl Extends TDecl
 		End If
 	End Method
 	
+	Method Clear()
+	End Method
+	
 End Type
 
 Type TConstDecl Extends TValDecl
@@ -556,7 +562,9 @@ Type TLocalDecl Extends TVarDecl
 	End Method
 	
 	Method OnCopy:TDecl(deep:Int = True)
-		Return New TLocalDecl.Create( ident,ty,CopyInit(),attrs, generated, volatile )
+		Local decl:TLocalDecl = New TLocalDecl.Create( ident,ty,CopyInit(),attrs &~ DECL_SEMANTED, generated, volatile )
+		decl.scope = scope
+		Return decl
 	End Method
 
 	Method GetDeclPrefix:String()
@@ -567,6 +575,10 @@ Type TLocalDecl Extends TVarDecl
 		Return GetDeclPrefix() + Super.ToString()
 	End Method
 
+	Method Clear()
+		done = False
+	End Method
+
 End Type
 
 Type TArgDecl Extends TLocalDecl
@@ -718,6 +730,9 @@ Type TAliasDecl Extends TDecl
 	Method OnSemant()
 	End Method
 	
+	Method Clear()
+	End Method
+	
 End Type
 
 Type TScopeDecl Extends TDecl
@@ -1500,6 +1515,9 @@ End Rem
 	Method OnSemant()
 	End Method
 	
+	Method Clear()
+	End Method
+
 End Type
 
 Type TBlockDecl Extends TScopeDecl
@@ -1521,6 +1539,7 @@ Type TBlockDecl Extends TScopeDecl
 	
 	Method OnCopy:TDecl(deep:Int = True)
 		Local t:TBlockDecl=New TBlockDecl
+		t.scope = scope
 		If deep Then
 			For Local stmt:TStmt=EachIn stmts
 				t.AddStmt stmt.Copy( t )
@@ -1545,6 +1564,12 @@ Type TBlockDecl Extends TScopeDecl
 		Return t
 	End Method
 
+	Method Clear()
+		For Local stmt:TStmt=EachIn stmts
+			stmt.Clear
+		Next
+	End Method
+
 End Type
 
 Const FUNC_METHOD:Int=   $0001			'mutually exclusive with ctor
@@ -1800,7 +1825,7 @@ Type TFuncDecl Extends TBlockDecl
 		'check for duplicate decl
 		If ident Then
 			For Local decl:TFuncDecl=EachIn scope.SemantedFuncs( ident )
-				If decl<>Self And EqualsArgs( decl )
+				If decl<>Self And EqualsArgs( decl ) And Not decl.IsCTOR()
 					Err "Duplicate declaration "+ToString()
 				EndIf
 				If noMangle Then
@@ -1983,7 +2008,32 @@ Type TNewDecl Extends TFuncDecl
 
 	Field chainedCtor:TNewExpr
 	
-	
+	Method OnCopy:TDecl(deep:Int = True)
+		Local args:TArgDecl[]=argDecls[..]
+		For Local i:Int=0 Until args.Length
+			args[i]=TArgDecl( args[i].Copy() )
+		Next
+		Local t:TNewDecl = TNewDecl(New TNewDecl.CreateF( ident,retType,args,attrs &~DECL_SEMANTED ))
+		If deep Then
+			For Local stmt:TStmt=EachIn stmts
+				t.AddStmt stmt.Copy( t )
+			Next
+		End If
+		t.retType = retType
+		t.scope = scope
+		t.overrides = overrides
+		t.superCtor = superCtor
+		t.castTo = castTo
+		t.noCastGen = noCastGen
+		t.munged = munged
+		t.metadata = metadata
+		t.mangled = mangled
+		t.noMangle = noMangle
+		t.chainedCtor = chainedCtor
+
+		Return  t
+	End Method
+
 
 End Type
 

+ 12 - 3
parser.bmx

@@ -35,11 +35,8 @@ Type TForEachinStmt Extends TLoopStmt
 	Field varty:TType
 	Field varlocal:Int
 	Field expr:TExpr
-	Field block:TBlockDecl
 	Field varExpr:TExpr
 	
-	Field stmts:TList=New TList
-
 	Method Create:TForEachinStmt( varid$,varty:TType,varlocal:Int,expr:TExpr,block:TBlockDecl,loopLabel:TLoopLabelDecl,varExpr:TExpr )
 		Self.varid=varid
 		Self.varty=varty
@@ -53,7 +50,19 @@ Type TForEachinStmt Extends TLoopStmt
 	End Method
 
 	Method OnCopy:TStmt( scope:TScopeDecl )
+		If loopLabel Then
+			If varExpr Then
 		Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), varExpr.Copy() )
+			Else
+				Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), Null )
+			End If
+		Else
+			If varExpr Then
+				Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),Null, varExpr.Copy() )
+			Else
+				Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),Null, Null )
+			End If
+		End If
 	End Method
 
 	Method OnSemant()

+ 19 - 1
stmt.bmx

@@ -49,6 +49,9 @@ Type TStmt
 
 	Method Trans$() Abstract
 
+	Method Clear()
+	End Method
+	
 End Type
 
 Type TDeclStmt Extends TStmt
@@ -66,6 +69,9 @@ Type TDeclStmt Extends TStmt
 	End Method
 
 	Method OnCopy:TStmt( scope:TScopeDecl )
+		If Not decl.scope Then
+			decl.scope = scope
+		End If
 		Return New TDeclStmt.Create( decl.Copy(), generated )
 	End Method
 	
@@ -80,6 +86,11 @@ Type TDeclStmt Extends TStmt
 	Method Trans$()
 		Return _trans.TransDeclStmt( Self )
 	End Method
+	
+	Method Clear()
+		decl.Clear()
+	End Method
+	
 End Type
 
 Type TAssignStmt Extends TStmt
@@ -442,6 +453,9 @@ Type TLoopStmt Extends TStmt
 	Field loopLabel:TLoopLabelDecl
 	Field block:TBlockDecl
 
+	Method Clear()
+		block.Clear()
+	End Method
 End Type
 
 Type TWhileStmt Extends TLoopStmt
@@ -459,7 +473,11 @@ Type TWhileStmt Extends TLoopStmt
 	End Method
 
 	Method OnCopy:TStmt( scope:TScopeDecl )
-		Return New TWhileStmt.Create( expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), generated )
+		If loopLabel Then
+			Return New TWhileStmt.Create( expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), generated )
+		Else
+			Return New TWhileStmt.Create( expr.Copy(),block.CopyBlock( scope ),Null, generated )
+		End If
 	End Method
 	
 	Method OnSemant()