Browse Source

Fixed order of code generation for def data. Fixes #560.

Brucey 4 years ago
parent
commit
f1f2949cd9
3 changed files with 19 additions and 7 deletions
  1. 7 1
      bcc.bmx
  2. 7 3
      ctranslator.bmx
  3. 5 3
      translator.bmx

+ 7 - 1
bcc.bmx

@@ -147,9 +147,15 @@ Function SaveSource(file:String, trans:TCTranslator, mung:String)
 	Local path:String = OutputFilePath(file, mung, "c")
 	Local path:String = OutputFilePath(file, mung, "c")
 
 
 	Local pre:String = trans.JoinLines("pre_source")
 	Local pre:String = trans.JoinLines("pre_source")
+	Local def_data:String = trans.JoinLines("def_data")
 	Local src:String = trans.JoinLines("source")
 	Local src:String = trans.JoinLines("source")
 
 
-	SaveText(pre + "~n" + src, path)
+	Local txt:String = pre + "~n"
+	If def_data Then
+		txt :+ def_data + "~n"
+	End If
+	txt :+ src
+	SaveText(txt, path)
 
 
 End Function
 End Function
 
 

+ 7 - 3
ctranslator.bmx

@@ -6584,6 +6584,13 @@ End If
 		Emit "return 0;"
 		Emit "return 0;"
 		Emit "}"
 		Emit "}"
 
 
+
+		' redirect string generation to the def data section of the source
+		SetOutput("def_data")
+
+		' defdata
+		EmitDefDataArray(app)
+		
 		' redirect string generation to the top of the source
 		' redirect string generation to the top of the source
 		SetOutput("pre_source")
 		SetOutput("pre_source")
 
 
@@ -6635,9 +6642,6 @@ End If
 			End If
 			End If
 		Next
 		Next
 		
 		
-		' defdata
-		EmitDefDataArray(app)
-		
 		' scope defs
 		' scope defs
 		If Not app.scopedefs.IsEmpty() Then
 		If Not app.scopedefs.IsEmpty() Then
 			For Local val:String = EachIn app.scopedefs.Keys()
 			For Local val:String = EachIn app.scopedefs.Keys()

+ 5 - 3
translator.bmx

@@ -1419,9 +1419,11 @@ End Rem
 	Method JoinLines$( file:String )
 	Method JoinLines$( file:String )
 		Local _lines:TStringList = TStringList(outputFiles.ValueForKey(file))
 		Local _lines:TStringList = TStringList(outputFiles.ValueForKey(file))
 		
 		
-		Local code$=_lines.Join( "~n" )
-		_lines.Clear
-		Return code
+		If _lines Then
+			Local code$=_lines.Join( "~n" )
+			_lines.Clear
+			Return code
+		End If
 	End Method
 	End Method
 	
 	
 	'returns and resets unreachable status
 	'returns and resets unreachable status