فهرست منبع

Fixed merge...

woollybah 8 سال پیش
والد
کامیت
0fcab643b3
2فایلهای تغییر یافته به همراه110 افزوده شده و 21 حذف شده
  1. 53 21
      ctranslator.bmx
  2. 57 0
      decl.bmx

+ 53 - 21
ctranslator.bmx

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

+ 57 - 0
decl.bmx

@@ -2482,6 +2482,63 @@ End Rem
 		Return funcs
 		Return funcs
 	End Method
 	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 )
 	Method ExtendsClass:Int( cdecl:TClassDecl )
 		'If Self=nullObjectClass Return True
 		'If Self=nullObjectClass Return True