Ver código fonte

Fixed class global generation order.

woollybah 9 anos atrás
pai
commit
1a1b82132d
3 arquivos alterados com 38 adições e 9 exclusões
  1. 36 8
      ctranslator.bmx
  2. 1 0
      decl.bmx
  3. 1 1
      options.bmx

+ 36 - 8
ctranslator.bmx

@@ -5169,6 +5169,20 @@ End If
 		End If
 		End If
 	End Method
 	End Method
 
 
+	Method TransGlobalInit(decl:TGlobalDecl)
+		If TFunctionPtrType(decl.ty) Then
+			If TInvokeExpr(decl.init) And Not TInvokeExpr(decl.init).invokedWithBraces Then
+				Emit TransGlobal( decl )+"="+TInvokeExpr(decl.init).decl.munged + ";"
+			Else
+				Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
+			End If
+		Else
+			If Not decl.funcGlobal Then
+				Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
+			End If
+		End If
+	End Method
+
 	Method TransSource(app:TAppDecl)
 	Method TransSource(app:TAppDecl)
 
 
 		SetOutput("pre_source")
 		SetOutput("pre_source")
@@ -5329,17 +5343,31 @@ End If
 			' TODO : what about OnDebugStop etc, who have no init ?
 			' TODO : what about OnDebugStop etc, who have no init ?
 			If decl.init And Not (decl.attrs & DECL_INITONLY) Then
 			If decl.init And Not (decl.attrs & DECL_INITONLY) Then
 
 
-				If TFunctionPtrType(decl.ty) Then
-					If TInvokeExpr(decl.init) And Not TInvokeExpr(decl.init).invokedWithBraces Then
-						Emit TransGlobal( decl )+"="+TInvokeExpr(decl.init).decl.munged + ";"
-					Else
-						Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
+				If decl.scope And TClassDecl(decl.scope) Then
+
+					' class global inits need to be generated in the correct order.
+					' only generate global inits if the parent class hasn't already been processed,
+					' otherwise, we will skip this global as it should already have been generated.
+					If Not TClassDecl(decl.scope).globInit Then
+					
+						TClassDecl(decl.scope).globInit = True
+					
+						For Local gdecl:TGlobalDecl = EachIn decl.scope._decls
+						
+							If gdecl.declImported Continue
+							
+							gdecl.Semant
+							
+							If gdecl.init And Not (gdecl.attrs & DECL_INITONLY) Then
+								TransGlobalInit(gdecl)
+							End If
+						Next
 					End If
 					End If
+					
 				Else
 				Else
-					If Not decl.funcGlobal Then
-						Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
-					End If
+					TransGlobalInit(decl)
 				End If
 				End If
+
 			End If
 			End If
 		Next
 		Next
 
 

+ 1 - 0
decl.bmx

@@ -1843,6 +1843,7 @@ Type TClassDecl Extends TScopeDecl
 	Field instArgs:TType[]
 	Field instArgs:TType[]
 
 
 	Field objectType:TObjectType '"canned" objectType
 	Field objectType:TObjectType '"canned" objectType
+	Field globInit:Int
 
 
 	'Global nullObjectClass:TClassDecl=New TNullDecl.Create( "{NULL}",Null,Null,Null,DECL_ABSTRACT|DECL_EXTERN )
 	'Global nullObjectClass:TClassDecl=New TNullDecl.Create( "{NULL}",Null,Null,Null,DECL_ABSTRACT|DECL_EXTERN )
 	
 	

+ 1 - 1
options.bmx

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