2
0
Эх сурвалжийг харах

Fixed static array initialisation. Fixes #522.

Brucey 5 жил өмнө
parent
commit
bac1cd0fd1
2 өөрчлөгдсөн 6 нэмэгдсэн , 4 устгасан
  1. 3 3
      ctranslator.bmx
  2. 3 1
      decl.bmx

+ 3 - 3
ctranslator.bmx

@@ -813,7 +813,7 @@ t:+"NULLNULLNULL"
 				If Not TArrayType(decl.ty) Or Not TArrayType(decl.ty).isStatic Then
 				If Not TArrayType(decl.ty) Or Not TArrayType(decl.ty).isStatic Then
 					initTrans = "=" + cast + init.Trans()
 					initTrans = "=" + cast + init.Trans()
 				Else
 				Else
-					initTrans = "[" + TArrayType(decl.ty).length + "]"
+					initTrans = "[" + TArrayType(decl.ty).length + "]=" + TransValue(decl.ty, Null, True)
 				End If
 				End If
 			End If
 			End If
 		End If
 		End If
@@ -4890,7 +4890,7 @@ End Rem
 						Else If TObjectType(decl.ty) Then
 						Else If TObjectType(decl.ty) Then
 							fld :+ "= " + Bra(TransObject(TObjectType(decl.ty).classDecl)) + decl.init.Trans() + ";"
 							fld :+ "= " + Bra(TransObject(TObjectType(decl.ty).classDecl)) + decl.init.Trans() + ";"
 						Else If TArrayType(decl.ty) And TArrayType(decl.ty).isStatic Then
 						Else If TArrayType(decl.ty) And TArrayType(decl.ty).isStatic Then
-							doEmit = False
+							fld = "for(int i=0;i<" + TArrayType(decl.ty).length + ";i++) " + TransFieldRef(decl, "o") + "[i]=" + TransValue(TArrayType(decl.ty).elemType,Null,False) + ";"
 						Else
 						Else
 							fld :+ "= " + decl.init.Trans() + ";"
 							fld :+ "= " + decl.init.Trans() + ";"
 						End If
 						End If
@@ -4910,7 +4910,7 @@ End Rem
 						fld :+ "= &bbEmptyString;"
 						fld :+ "= &bbEmptyString;"
 					Else If TArrayType(decl.ty) Then
 					Else If TArrayType(decl.ty) Then
 						If TArrayType(decl.ty).isStatic Then
 						If TArrayType(decl.ty).isStatic Then
-							doEmit = False
+							fld = "for(int i=0;i<" + TArrayType(decl.ty).length + ";i++) " + TransFieldRef(decl, "o") + "[i]=" + TransValue(TArrayType(decl.ty).elemType,Null,False) + ";"
 						Else
 						Else
 							fld :+ "= &bbEmptyArray;"
 							fld :+ "= &bbEmptyArray;"
 						End If
 						End If

+ 3 - 1
decl.bmx

@@ -529,7 +529,9 @@ Type TValDecl Extends TDecl
 				Else
 				Else
 					If TArrayType(ty) And TArrayType(ty).isStatic Then
 					If TArrayType(ty) And TArrayType(ty).isStatic Then
 						init = declInit.Copy().Semant()
 						init = declInit.Copy().Semant()
-						TArrayType(ty).length = init.Eval()
+						If Not TArrayType(ty).length Then
+							TArrayType(ty).length = init.Eval()
+						End If
 					Else
 					Else
 						If TArrayExpr(declInit) And TArrayType(ty) And TNumericType(TArrayType(ty).elemType) Then
 						If TArrayExpr(declInit) And TArrayType(ty) And TNumericType(TArrayType(ty).elemType) Then
 							TArrayExpr(declInit).toType = TArrayType(ty).elemType
 							TArrayExpr(declInit).toType = TArrayType(ty).elemType