Sfoglia il codice sorgente

Fixed some struct generation issues.

woollybah 6 anni fa
parent
commit
2a7a1afe17
2 ha cambiato i file con 31 aggiunte e 3 eliminazioni
  1. 13 3
      ctranslator.bmx
  2. 18 0
      expr.bmx

+ 13 - 3
ctranslator.bmx

@@ -1912,7 +1912,11 @@ t:+"NULLNULLNULL"
 						End If
 						Return Bra(Bra( Bra(Bra("BBObject*") + t )+"!= &bbNullObject" ) + " && " + Bra( t+"!= &bbEmptyArray" ) + " && " + Bra( t+"!= &bbEmptyString" ))
 					Else
-						Return Bra( Bra(Bra("BBObject*") + t )+"!= &bbNullObject" )
+						If Not TObjectType(src).classDecl.IsStruct() Then
+							Return Bra( Bra(Bra("BBObject*") + t )+"!= &bbNullObject" )
+						Else
+							Return Bra("1")
+						End If
 					End If
 				End If
 			End If
@@ -2222,7 +2226,11 @@ t:+"NULLNULLNULL"
 
 		If TVarExpr(expr.expr) Then
 			If TObjectType(TVarExpr(expr.expr).exprType) Then
-				t_expr = Bra( expr.expr.Trans() + "!= &bbNullObject")
+				If TObjectType(TVarExpr(expr.expr).exprType).classDecl.IsStruct() Then
+					t_expr = Bra( "1" )
+				Else
+					t_expr = Bra( expr.expr.Trans() + "!= &bbNullObject")
+				End If
 			Else If TStringType(TVarExpr(expr.expr).exprType)  Then
 				t_expr = Bra( expr.expr.Trans() + "!= &bbEmptyString")
 			Else
@@ -2866,7 +2874,9 @@ t:+"NULLNULLNULL"
 		Else If (TFunctionPtrType(stmt.lhs.exprType) <> Null Or IsPointerType(stmt.lhs.exprType, TType.T_BYTE)) And TInvokeExpr(stmt.rhs) And Not TInvokeExpr(stmt.rhs).invokedWithBraces Then
 			rhs = TInvokeExpr(stmt.rhs).decl.munged
 			s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
-		Else
+		Else If TObjectType(stmt.lhs.exprType) And TObjectType(stmt.lhs.exprType).classDecl.IsStruct() And rhs = "&bbNullObject" Then
+			s :+ lhs+TransAssignOp( stmt.op )+cast+"{}"
+		Else 
 			s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
 		End If
 

+ 18 - 0
expr.bmx

@@ -2069,6 +2069,24 @@ Type TBinaryCompareExpr Extends TBinaryExpr
 
 		' operator overload?
 		If TObjectType(lhs.exprType) Then
+		
+			If TNullExpr(rhs) And TObjectType(lhs.exprType).classDecl.IsStruct() Then
+				If op = "=" Then
+					ty=New TBoolType
+					exprType=New TBoolType
+					lhs = New TConstExpr.Create(New TIntType, 1).Semant()
+					rhs = New TConstExpr.Create(New TIntType, 0).Semant()
+					Return Self
+				Else
+					op = "<>"
+					ty = New TBoolType
+					exprType=New TBoolType
+					lhs = New TConstExpr.Create(New TIntType, 1).Semant()
+					rhs = New TConstExpr.Create(New TIntType, 0).Semant()
+					Return Self
+				End If
+			End If
+		
 			Local args:TExpr[] = [rhs]
 			Try
 				Local decl:TFuncDecl = TFuncDecl(TObjectType(lhs.exprType).classDecl.FindFuncDecl(op, args,,,,True,SCOPE_CLASS_HEIRARCHY))