Browse Source

Reworked Null handling.
Added low-level debug checks.
Invocation changes for enumerators and methods.
Interface parsing fix for null object inits.

woollybah 11 years ago
parent
commit
9ccd0e18ef
2 changed files with 99 additions and 3 deletions
  1. 81 0
      translator.bmx
  2. 18 3
      type.bmx

+ 81 - 0
translator.bmx

@@ -44,6 +44,8 @@ Type TTranslator
 '	Field funcMungs:=New StringMap<FuncDeclList>
 '	Field funcMungs:=New StringMap<FuncDeclList>
 '	Field mungedFuncs:=New StringMap<FuncDecl>
 '	Field mungedFuncs:=New StringMap<FuncDecl>
 
 
+	Field debugOut:String
+
 	Method PushVarScope()
 	Method PushVarScope()
 		varStack.Push customVarStack
 		varStack.Push customVarStack
 		customVarStack = New TStack
 		customVarStack = New TStack
@@ -665,6 +667,11 @@ Rem
 End Rem
 End Rem
 			Local t$=stmt.Trans()
 			Local t$=stmt.Trans()
 			If t Emit t+";"
 			If t Emit t+";"
+
+			If DEBUG And debugOut Then
+				Emit debugOut
+				debugOut = Null
+			End If
 			
 			
 			Local v:String = String(customVarStack.Pop())
 			Local v:String = String(customVarStack.Pop())
 			While v
 			While v
@@ -866,7 +873,81 @@ End Rem
 		LINES = _lines
 		LINES = _lines
 		
 		
 	End Method
 	End Method
+
+	Method DebugPrint(text:String, func:String = Null, trans:Int = False)
+		Global count:Int
+		Global lastFunc:String
+		
+		If func Then
+			lastFunc = func
+		End If
+		
+		Local s:String = "fprintf(stderr," + "~q" + lastFunc + " : " + count + " :: " + text + "\n~q)" + ";fflush(stderr);"
+		
+		If trans Then
+			debugOut :+ indent + s + "~n"
+		Else
+			Emit s
+		End If
+		count :+ 1
+	End Method
 	
 	
+	Method DebugString(s:String, func:String = Null, trans:Int = False)
+		' bbNullObject test
+		If trans Then
+			debugOut :+ indent + "if (" + s + "==&bbNullObject) {~n"
+		Else
+			Emit "if (" + s + "==&bbNullObject) {"
+		End If
+		DebugPrint("Invalid Null String : " + s, func, trans)
+		If trans Then
+			debugOut :+ indent + "}~n"
+		Else
+			Emit "}"
+		End If
+	End Method
+
+	Method DebugArray(s:String, func:String = Null, trans:Int = False)
+		' bbNullObject test
+		If trans Then
+			debugOut :+ indent + "if (" + s + "==&bbNullObject) {~n"
+		Else
+			Emit "if (" + s + "==&bbNullObject) {"
+		End If
+		DebugPrint("Invalid Null Array : " + s, func, trans)
+		If trans Then
+			debugOut :+ indent + "}~n"
+		Else
+			Emit "}"
+		End If
+	End Method
+
+	Method DebugObject(ty:TType, id:String, func:String = Null, trans:Int = False)
+		If TObjectType(ty) Or TStringType(ty) Or TArrayType(ty) Then
+			' null test
+			If trans Then
+				debugOut :+ indent + "if (!" + id + ") {~n"
+			Else
+				Emit "if (!" + id + ") {"
+			End If
+			DebugPrint("Null Pointer : " + id, func, trans)
+			If trans Then
+				If ABORT_ON_NULL Then
+					debugOut :+ indent + "abort();~n"
+				End If
+				debugOut :+ indent + "}~n"
+			Else
+				Emit "}"
+			End If
+		End If
+		
+		If TStringType(ty) Then
+			DebugString(id, func, trans)
+		Else If TArrayType(ty) Then
+			DebugArray(id, func, trans)
+		End If
+	End Method
+		
 End Type
 End Type
 
 
 
 

+ 18 - 3
type.bmx

@@ -71,7 +71,7 @@ Type TType
 	Global stringType:TStringType=New TStringType
 	Global stringType:TStringType=New TStringType
 	Global emptyArrayType:TArrayType=New TArrayType.Create( voidType )
 	Global emptyArrayType:TArrayType=New TArrayType.Create( voidType )
 	Global objectType:TIdentType=New TIdentType.Create( "brl.classes.object" )
 	Global objectType:TIdentType=New TIdentType.Create( "brl.classes.object" )
-	Global nullObjectType:TIdentType=New TIdentType.Create( "" )
+	Global nullObjectType:TNullType=New TNullType
 	Global longType:TLongType=New TLongType ' BaH Long
 	Global longType:TLongType=New TLongType ' BaH Long
 	Global doubleType:TDoubleType=New TDoubleType
 	Global doubleType:TDoubleType=New TDoubleType
 	Global byteType:TByteType=New TByteType
 	Global byteType:TByteType=New TByteType
@@ -211,6 +211,21 @@ Type TVoidType Extends TType
 	End Method
 	End Method
 End Type
 End Type
 
 
+Type TNullType Extends TType
+
+	Method EqualsType:Int( ty:TType )
+		Return False
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		Return True
+	End Method
+	
+	Method ToString$()
+		Return "NULL"
+	End Method
+End Type
+
 Type TBoolType Extends TType
 Type TBoolType Extends TType
 
 
 	Method EqualsType:Int( ty:TType )
 	Method EqualsType:Int( ty:TType )
@@ -556,7 +571,7 @@ Type TIdentType Extends TType
 	
 	
 	
 	
 	Method Semant:TType()
 	Method Semant:TType()
-		If Not ident Return TClassDecl.nullObjectClass.objectType
+		If Not ident Return TType.nullObjectType
 
 
 		Local targs:TType[args.Length]
 		Local targs:TType[args.Length]
 		For Local i:Int=0 Until args.Length
 		For Local i:Int=0 Until args.Length
@@ -651,7 +666,7 @@ Type TIdentPtrType Extends TPointerType
 	
 	
 	
 	
 	Method Semant:TType()
 	Method Semant:TType()
-		If Not ident Return TClassDecl.nullObjectClass.objectType
+		If Not ident Return TType.nullObjectType
 
 
 		Local targs:TType[args.Length]
 		Local targs:TType[args.Length]
 		For Local i:Int=0 Until args.Length
 		For Local i:Int=0 Until args.Length