Browse Source

Fix End If processing for Else If.
Balancing types of Var type should calculate balancing on non-Var equivalent.
Allow bool to string casts.

woollybah 11 years ago
parent
commit
5134645f33
4 changed files with 46 additions and 3 deletions
  1. 9 0
      ctranslator.bmx
  2. 8 0
      expr.bmx
  3. 18 2
      parser.bmx
  4. 11 1
      type.bmx

+ 9 - 0
ctranslator.bmx

@@ -791,6 +791,7 @@ Type TCTranslator Extends TTranslator
 			If TStringType( src ) Return "bbStringToDouble" + Bra(t)
 			If TStringType( src ) Return "bbStringToDouble" + Bra(t)
 			If TPointerType( src ) Return Bra("(BBDOUBLE)"+t)
 			If TPointerType( src ) Return Bra("(BBDOUBLE)"+t)
 		Else If TStringType( dst )
 		Else If TStringType( dst )
+			If TBoolType( src ) Return "bbStringFromInt"+Bra( t )
 			If TByteType( src ) Return "bbStringFromInt"+Bra( t )
 			If TByteType( src ) Return "bbStringFromInt"+Bra( t )
 			If TShortType( src ) Return "bbStringFromInt"+Bra( t )
 			If TShortType( src ) Return "bbStringFromInt"+Bra( t )
 			If TIntType( src ) Return "bbStringFromInt"+Bra( t )
 			If TIntType( src ) Return "bbStringFromInt"+Bra( t )
@@ -881,8 +882,16 @@ Type TCTranslator Extends TTranslator
 	
 	
 	Method TransBinaryExpr$( expr:TBinaryExpr )
 	Method TransBinaryExpr$( expr:TBinaryExpr )
 		Local pri:Int=ExprPri( expr )
 		Local pri:Int=ExprPri( expr )
+
 		Local t_lhs$=TransSubExpr( expr.lhs,pri )
 		Local t_lhs$=TransSubExpr( expr.lhs,pri )
+		If TVarPtrType(expr.lhs.exprType) Then
+			t_lhs = "*" + t_lhs
+		End If
+		
 		Local t_rhs$=TransSubExpr( expr.rhs,pri-1 )
 		Local t_rhs$=TransSubExpr( expr.rhs,pri-1 )
+		If TVarPtrType(expr.rhs.exprType) Then
+			t_rhs = "*" + t_rhs
+		End If
 
 
 		If TStringType(expr.exprType) And expr.op = "+" Then
 		If TStringType(expr.exprType) And expr.op = "+" Then
 			Return "bbStringConcat(" + t_lhs + "," + t_rhs + ")"
 			Return "bbStringConcat(" + t_lhs + "," + t_rhs + ")"

+ 8 - 0
expr.bmx

@@ -126,6 +126,14 @@ Type TExpr
 	End Method
 	End Method
 
 
 	Method BalanceTypes:TType( lhs:TType,rhs:TType )
 	Method BalanceTypes:TType( lhs:TType,rhs:TType )
+		If TVarPtrType(lhs) Then
+			lhs = TType.MapVarPointerToPrim(lhs)
+		End If
+
+		If TVarPtrType(rhs) Then
+			rhs = TType.MapVarPointerToPrim(rhs)
+		End If
+
 		If TStringType( lhs ) Or TStringType( rhs ) Return TType.stringType
 		If TStringType( lhs ) Or TStringType( rhs ) Return TType.stringType
 		If TDoubleType( lhs ) Or TDoubleType( rhs ) Return TType.floatType
 		If TDoubleType( lhs ) Or TDoubleType( rhs ) Return TType.floatType
 		If TFloatType( lhs ) Or TFloatType( rhs ) Return TType.floatType
 		If TFloatType( lhs ) Or TFloatType( rhs ) Return TType.floatType

+ 18 - 2
parser.bmx

@@ -1067,7 +1067,9 @@ Type TParser
 		Return ParseOrExpr()
 		Return ParseOrExpr()
 	End Method
 	End Method
 
 
-	Method ParseIfStmt( term$ )
+	Method ParseIfStmt( term$, elseIfEndIfReadAheadCheck:Int = False )
+		Local tok:TToker
+
 		CParse "if"
 		CParse "if"
 
 
 		Local expr:TExpr=ParseExpr()
 		Local expr:TExpr=ParseExpr()
@@ -1100,11 +1102,25 @@ Type TParser
 				PopBlock
 				PopBlock
 				PushBlock elseBlock
 				PushBlock elseBlock
 				If elif Or _toke="if"
 				If elif Or _toke="if"
-					ParseIfStmt term
+					ParseIfStmt term, True
 				EndIf
 				EndIf
 			Default
 			Default
 				ParseStmt
 				ParseStmt
 
 
+				' for an elseif, it is part of the original if, insofar as the subsequent End If will close both.
+				' read ahead (without moving the parser forward) for an End If and exit if required.
+				If _toke = "end" And elseIfEndIfReadAheadCheck Then
+					tok = New TToker.Copy(_toker)
+					If tok._toke.ToLower() = "end" Then
+						NextTokeToker(tok)
+						If tok._toke.ToLower() = "if" Then
+							If term="end" Then
+								Exit
+							End If
+						End If
+					End If
+				End If
+
 				' to handle "end" statement
 				' to handle "end" statement
 				If _toke = "end" Then
 				If _toke = "end" Then
 					NextToke
 					NextToke

+ 11 - 1
type.bmx

@@ -183,6 +183,16 @@ Type TType
 		If TLongPtrPtrType(ty) Return longPointerType
 		If TLongPtrPtrType(ty) Return longPointerType
 		
 		
 	End Function
 	End Function
+
+	Function MapVarPointerToPrim:TType(ty:TType)
+		If TByteVarPtrType(ty) Return byteType
+		If TIntVarPtrType(ty) Return intType
+		If TShortVarPtrType(ty) Return shortType
+		If TFloatVarPtrType(ty) Return floatType
+		If TDoubleVarPtrType(ty) Return doubleType
+		If TLongVarPtrType(ty) Return longType
+		If TStringVarPtrType(ty) Return stringType
+	End Function
 	
 	
 	Field _arrayOf:TArrayType
 	Field _arrayOf:TArrayType
 	
 	
@@ -206,7 +216,7 @@ Type TBoolType Extends TType
 	End Method
 	End Method
 	
 	
 	Method ExtendsType:Int( ty:TType )
 	Method ExtendsType:Int( ty:TType )
-		Return TIntType( ty )<>Null Or TBoolType( ty )<>Null
+		Return TIntType( ty )<>Null Or TBoolType( ty )<>Null Or TStringType( ty )<>Null
 	End Method
 	End Method
 	
 	
 	Method ToString$()
 	Method ToString$()