Bläddra i källkod

Fixed merge...

woollybah 8 år sedan
förälder
incheckning
0fcab643b3
2 ändrade filer med 110 tillägg och 21 borttagningar
  1. 53 21
      ctranslator.bmx
  2. 57 0
      decl.bmx

+ 53 - 21
ctranslator.bmx

@@ -452,10 +452,14 @@ Type TCTranslator Extends TTranslator
 	End Method
 	
 	Method TransArgs$( args:TExpr[],decl:TFuncDecl, objParam:String = Null )
-'If decl.ident="AddS" DebugStop
+'If decl.ident="AddS" DebugStop
 
 		Local t$
 		If objParam And (decl.IsMethod() Or decl.isCtor()) And ((Not decl.IsExtern()) Or (decl.IsExtern() And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct())) Then
+			' object cast to match param type
+			If TClassDecl(decl.scope) Then
+				t :+ Bra(TransObject(TClassDecl(decl.scope).GetOriginalFuncDecl(decl).scope))
+			End If
 			t:+ objParam
 		End If
 		For Local i:Int=0 Until decl.argDecls.Length
@@ -465,6 +469,15 @@ Type TCTranslator Extends TTranslator
 			If i < args.length
 				Local arg:TExpr = args[i]
 				
+				' object cast to match param type
+				If TObjectType(ty) Then
+					Local fdecl:TFuncDecl = decl
+					If TClassDecl(decl.scope) Then
+						fdecl = TClassDecl(decl.scope).GetOriginalFuncDecl(decl)
+					End If
+					t :+ Bra(TransObject(TObjectType(TArgDecl(fdecl.argDecls[i].actual).ty).classDecl))
+				End If
+				
 				If TNullExpr(arg) Then
 					t :+ TransValue(ty, Null)
 					Continue
@@ -629,7 +642,7 @@ t:+"NULLNULLNULL"
 			'If TNullDecl(TObjectType(src).classDecl) Then
 			'	Return "&bbEmptyString"
 			'End If
-			Return Bra("(BBString *)bbObjectDowncast" + Bra(expr + ",&" + TStringType(ty).cDecl.munged))
+			Return Bra("(BBString *)bbObjectDowncast" + Bra("(BBOBJECT)" + expr + ",(BBClass*)&" + TStringType(ty).cDecl.munged))
 		End If
 
 		'If TArrayType(ty) And TObjectType(src) Then
@@ -669,7 +682,7 @@ t:+"NULLNULLNULL"
 		'upcast?
 		If src.GetClass().ExtendsClass( ty.GetClass() ) Return expr
 		If TObjectType(ty) Then
-			Return Bra(Bra(TransObject(TObjectType(ty).classDecl)) + "bbObjectDowncast" + Bra(expr + ",&" + TObjectType(ty).classDecl.munged))
+			Return Bra(Bra(TransObject(TObjectType(ty).classDecl)) + "bbObjectDowncast" + Bra("(BBOBJECT)" + expr + ",(BBClass*)&" + TObjectType(ty).classDecl.munged))
 		End If
 
 		Return cast+"_cast<"+TransType(ty, "TODO: TransPtrCast")+">"+Bra( expr )
@@ -1259,6 +1272,8 @@ t:+"NULLNULLNULL"
 	Method TransObject:String(decl:TScopeDecl, this:Int = False)
 		If decl.ident = "Object"
 			Return "BBOBJECT"
+		Else If decl.ident = "String" Then
+			Return "BBSTRING"
 		Else
 			If TClassDecl(decl) And TClassDecl(decl).IsStruct() Then
 				Local t:String = "struct "
@@ -1536,9 +1551,9 @@ t:+"NULLNULLNULL"
 				t = "bbObjectNew(" + Bra(expr.instanceExpr.Trans()) + "->clas)"
 			Else
 				If ClassHasObjectField(expr.classDecl) Then
-					t = "bbObjectNew(&" + expr.classDecl.actual.munged + ")"
+					t = "bbObjectNew((BBClass *)&" + expr.classDecl.actual.munged + ")"
 				Else
-					t = "bbObjectAtomicNew(&" + expr.classDecl.actual.munged + ")"
+					t = "bbObjectAtomicNew((BBClass *)&" + expr.classDecl.actual.munged + ")"
 				End If
 			End If
 		Else
@@ -1770,7 +1785,7 @@ t:+"NULLNULLNULL"
 						Return Bra("1")
 					End If
 				Else
-					Return Bra( t+"!= &bbNullObject" )
+					Return Bra( Bra(Bra("BBObject*") + t )+"!= &bbNullObject" )
 				End If
 			End If
 		Else If TIntType( dst )
@@ -2028,7 +2043,7 @@ t:+"NULLNULLNULL"
 					If TObjectType( dst ).classDecl.ident = "Object" Then
 						Return t
 					Else
-						Return Bra(Bra(TransObject(TObjectType(dst).classDecl)) + "bbObjectDowncast" + Bra(t + ",&" + TObjectType(dst).classDecl.munged))
+						Return Bra(Bra(TransObject(TObjectType(dst).classDecl)) + "bbObjectDowncast" + Bra("(BBOBJECT)" + t + ",(BBClass*)&" + TObjectType(dst).classDecl.munged))
 					End If
 				End If
 			Else
@@ -2358,16 +2373,16 @@ t:+"NULLNULLNULL"
 		For Local c:TCatchStmt=EachIn stmt.catches
 			MungDecl c.init
 			If TStringType(c.init.ty) Then
-				Emit s + "if (bbObjectDowncast(ex,&bbStringClass) != &bbEmptyString) {"
+				Emit s + "if (bbObjectDowncast((BBOBJECT)ex,(BBClass*)&bbStringClass) != &bbEmptyString) {"
 				Emit TransType( c.init.ty, c.init.munged )+" "+ c.init.munged + "=(BBSTRING)ex;" 
 			Else If TArrayType(c.init.ty) Then
-				Emit s + "if (bbObjectDowncast(ex,&bbArrayClass) != &bbEmptyArray) {"
+				Emit s + "if (bbObjectDowncast((BBOBJECT)ex,(BBClass*)&bbArrayClass) != &bbEmptyArray) {"
 				Emit TransType( c.init.ty, c.init.munged )+" "+ c.init.munged + "=(BBARRAY)ex;" 
 			Else If TObjectType(c.init.ty) Then
 				If TObjectType(c.init.ty).classDecl.IsInterface() Then
 					Emit s + "if (bbInterfaceDowncast(ex,&"+TObjectType(c.init.ty).classDecl.munged+"_ifc) != &bbNullObject) {"
 				Else
-					Emit s + "if (bbObjectDowncast(ex,&"+TObjectType(c.init.ty).classDecl.munged+") != &bbNullObject) {"
+					Emit s + "if (bbObjectDowncast((BBOBJECT)ex,(BBClass*)&"+TObjectType(c.init.ty).classDecl.munged+") != &bbNullObject) {"
 				End If
 				Emit TransType( c.init.ty, c.init.munged )+" "+ c.init.munged + "=" + Bra(TransType( c.init.ty, c.init.munged )) + "ex;" 
 			Else
@@ -2594,7 +2609,7 @@ t:+"NULLNULLNULL"
 	End Method
 
 	Method TransThrowStmt:String( stmt:TThrowStmt )
-		Local s:String = "bbExThrow("
+		Local s:String = "bbExThrow((BBObject *)"
 
 		s:+ stmt.expr.Trans()
 
@@ -3585,7 +3600,7 @@ End Rem
 			Emit "BBDEBUGDECL_TYPEMETHOD,"
 			Emit Enquote(ident) + ","
 			Emit Enquote(ty) + ","
-			Emit "&" + munged
+			Emit ".var_address=(void*)&" + munged
 			Emit "},"
 	End Method
 	
@@ -3622,9 +3637,9 @@ End Rem
 
 			Emit Enquote(s) + ","
 			If decl.IsMethod() Or decl.IsCTor() Then 
-				Emit "&_" + decl.munged
+				Emit ".var_address=(void*)&_" + decl.munged
 			Else
-				Emit "&" + decl.munged
+				Emit ".var_address=(void*)&" + decl.munged
 			End If
 			Emit "},"
 	End Method
@@ -4110,19 +4125,36 @@ End Rem
 	
 			' methods/funcs
 			'reserved = "New,Delete,ToString,ObjectCompare,SendMessage".ToLower()
-	
+
 			'For Local decl:TFuncDecl = EachIn classDecl.Decls()
 			For Local decl:TFuncDecl = EachIn fdecls
-	
+	
 				If Not equalsBuiltInFunc(classDecl, decl) And Not equalsTorFunc(classDecl, decl) Then
 	
+					Local fdecl:TFuncDecl = classDecl.GetOriginalFuncDecl(decl)
+	
 					MungDecl decl
+					
+					Local t:String = ","
+
+					If fdecl <> decl Then
+
+						MungDecl fdecl
+						
+						If decl.IsMethod() Then
+							t :+ Bra(fdecl.munged + "_m")
+						Else
+							t :+ Bra(fdecl.munged + "_f")
+						End If
+					End If
 	
 					If decl.IsMethod() Then
-						Emit ",_" + decl.munged
-					Else
-						Emit "," + decl.munged
+						t:+ "_"
 					End If
+					
+					t :+ decl.munged
+					
+					Emit t
 				End If
 			Next
 	
@@ -4216,7 +4248,7 @@ End Rem
 				Emit "_" + newDecl.chainedCtor.ctor.ClassScope().munged + "_" + newDecl.chainedCtor.ctor.ident + MangleMethod(newDecl.chainedCtor.ctor) + TransArgs(newDecl.chainedCtor.args, newDecl.chainedCtor.ctor, "o") + ";"
 			Else
 				If classDecl.superClass.ident = "Object" Then
-					Emit "bbObjectCtor(o);"
+					Emit "bbObjectCtor((BBOBJECT)o);"
 				Else
 					Emit "_" + superid + "_New(o);"
 				End If
@@ -5534,7 +5566,7 @@ End If
 			If cdecl And Not cdecl.IsExtern() And Not cdecl.args
 				If Not cdecl.IsInterface() Then
 					If Not cdecl.IsStruct() Then
-						Emit "bbObjectRegisterType(&" + cdecl.munged + ");"
+						Emit "bbObjectRegisterType((BBCLASS)&" + cdecl.munged + ");"
 					Else
 						Emit "bbObjectRegisterStruct(&" + cdecl.munged + "_scope);"
 					End If

+ 57 - 0
decl.bmx

@@ -2482,6 +2482,63 @@ End Rem
 		Return funcs
 	End Method
 
+	Method GetOriginalFuncDecl:TFuncDecl(fdecl:TFuncDecl)
+		If Not TClassDecl(Self) Then
+			Return fdecl
+		End If
+		
+		If superClass Then
+			Local decl:TFuncDecl = superClass.GetOriginalFuncDecl(fdecl)
+			If decl <> fdecl Then
+				Return decl
+			End If
+		End If
+		' interface methods
+'		For Local iface:TClassDecl=EachIn implmentsAll
+'			For Local func:TFuncDecl=EachIn iface._decls
+'				Local matched:Int = False
+'
+'				For Local i:Int = 0 Until funcs.length
+'					' found a match - we are overriding it
+'					If func.IdentLower() = funcs[i].IdentLower() Then
+'						matched = True
+'						Exit
+'					End If
+'				Next
+'				
+'				If Not matched Then
+'					funcs :+ [func]
+'				End If
+'			Next
+'		Next
+		'Local found:TFuncDecl = fdecl
+		
+		For Local func:TFuncDecl = EachIn _decls
+		
+			Local matched:Int = False
+			
+			' dont count any that are already in the funcs list
+			'For Local i:Int = 0 Until funcs.length
+				' found a match - we are overriding it
+				If func.IdentLower() = fdecl.IdentLower() And func.EqualsArgs(fdecl) Then
+					Return func
+					' set this to our own func
+					'funcs[i] = func
+					'Exit
+				End If
+			'Next
+			
+			'If Not matched Then
+			'	funcs :+ [func]
+			'End If
+		
+		Next
+		
+		'Return funcs
+		Return fdecl
+	End Method
+
+	
 	Method ExtendsClass:Int( cdecl:TClassDecl )
 		'If Self=nullObjectClass Return True