2
0
Эх сурвалжийг харах

Improved function pointer handling.
Fixes #80.

woollybah 10 жил өмнө
parent
commit
542fbe4f02
2 өөрчлөгдсөн 21 нэмэгдсэн , 5 устгасан
  1. 9 5
      ctranslator.bmx
  2. 12 0
      expr.bmx

+ 9 - 5
ctranslator.bmx

@@ -324,16 +324,20 @@ Type TCTranslator Extends TTranslator
 						Else
 						Else
 							' need to test scopes to see if we need to use the current instance's function or not
 							' need to test scopes to see if we need to use the current instance's function or not
 							Local fdecl:TFuncDecl = TInvokeExpr(args[i]).decl
 							Local fdecl:TFuncDecl = TInvokeExpr(args[i]).decl
+							mungdecl fdecl
 
 
 							If TClassDecl(fdecl.scope) Then
 							If TClassDecl(fdecl.scope) Then
 								' current scope is related to function scope?
 								' current scope is related to function scope?
 								If TClassDecl(_env.scope) And TFuncDecl(_env) And TFuncDecl(_env).IsMethod() Then
 								If TClassDecl(_env.scope) And TFuncDecl(_env) And TFuncDecl(_env).IsMethod() Then
-									'If TClassDecl(decl.scope).ExtendsClass(TClassDecl(fdecl.scope)) Then
-									Local scope:TScopeDecl = _env.scope
-									Local obj:String = Bra("struct " + scope.munged + "_obj*")
-									Local class:String = "(" + obj + "o)->clas"
+									If TClassDecl(decl.scope).ExtendsClass(TClassDecl(fdecl.scope)) Then
+										Local scope:TScopeDecl = _env.scope
+										Local obj:String = Bra("struct " + scope.munged + "_obj*")
+										Local class:String = "(" + obj + "o)->clas"
 				
 				
-									t:+ class + "->fn_" + fdecl.ident
+										t:+ class + "->fn_" + fdecl.ident
+									Else
+										t:+ fdecl.munged
+									End If
 								Else
 								Else
 									t:+ fdecl.munged
 									t:+ fdecl.munged
 								End If
 								End If

+ 12 - 0
expr.bmx

@@ -97,6 +97,18 @@ Type TExpr
 					TIdentExpr(args[i]).isArg = True
 					TIdentExpr(args[i]).isArg = True
 				End If
 				End If
 				args[i]=args[i].Semant()
 				args[i]=args[i].Semant()
+
+				' if an arg is a invocation without braces, it is *probably* a function pointer.
+				If TInvokeExpr(args[i]) And Not TInvokeExpr(args[i]).invokedWithBraces Then
+					TInvokeExpr(args[i]).exprType = New TFunctionPtrType
+					Local cp:TDecl = TInvokeExpr(args[i]).decl
+					TInvokeExpr(args[i]).decl = TFuncDecl(TInvokeExpr(args[i]).decl.Copy())
+					TInvokeExpr(args[i]).decl.actual = cp
+					TInvokeExpr(args[i]).decl.attrs :| FUNC_PTR
+					TFunctionPtrType(TInvokeExpr(args[i]).exprType).func = TInvokeExpr(args[i]).decl
+
+					TInvokeExpr(args[i]).decl.semant()
+				End If
 			End If
 			End If
 		Next
 		Next
 		Return args
 		Return args