bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

[Regression] Functions with overridden return (array-)types generate broken C code #276

Closed GWRon closed 7 years ago

GWRon commented 7 years ago

This fails compiling / generates non-usable C code.

SuperStrict
Framework Brl.StandardIO
Import Brl.LinkedList

Type TItemBaseCollection
    Field list:TList = New TList

    Global _instance:TItemBaseCollection

    Function GetInstance:TItemBaseCollection()
        If Not _instance Then _instance = New TItemBaseCollection
        Return _instance
    End Function

    Function GetAll:TItemBase[]()
        Local items:TItemBase[]
        For Local i:TItemBase = EachIn GetInstance().list
            items :+ [i]
        Next
        Return items        
    End Function
End Type

Type TItemCollection Extends TItemBaseCollection
    Function GetInstance:TItemCollection()
        If Not _instance Or Not TItemBaseCollection(_instance)
            _instance = New TItemCollection
        ElseIf Not TItemCollection(_instance)
            Local oldInstance:TItemBaseCollection = _instance
            _instance = New TItemBaseCollection
            _instance.list = oldInstance.list
        EndIf
        Return TItemCollection(_instance)
    End Function

    Function GetAll:TItem[]()
        'call Super... so it inherits a potentially done pre-filter
        Local baseItems:TItemBase[] = Super.GetAll()
        Local items:TItem[]
        For Local i:TItem = EachIn baseItems
            items :+ [i]
        Next
        Return items        
    End Function
End Type

Type TItemBase
    Method GetName:String()
        Return ""
    End Method
End Type

Type TItem Extends TItemBase
    Field name:String

    Method GetName:String()
        Return name
    End Method
End Type

'call itemcollection
Local items:TItem[] = TItemCollection.GetInstance().GetAll()
Building ng_returntypes
[ 80%] Processing:ng_returntypes.bmx
[ 90%] Compiling:ng_returntypes.bmx.console.release.linux.x64.c
/BlitzMaxNG/test/.bmx/ng_returntypes.bmx.console.release.linux.x64.c: In function ‘_bb_main’:
/BlitzMaxNG/test/.bmx/ng_returntypes.bmx.console.release.linux.x64.c:265:151: error: ‘struct BBClass__m_ng_returntypes_TItemCollection’ has no member named ‘f_GetAll_aTTItem’
   BBARRAY bbt_items=(((struct _m_ng_returntypes_TItemCollection_obj*)(bbt_ = _m_ng_returntypes_TItemCollection_GetInstance_TTItemCollection()))->clas)->f_GetAll_aTTItem();
                                                                                                                                                       ^
Build Error: failed to compile (256) /BlitzMaxNG/test/.bmx/ng_returntypes.bmx.console.release.linux.x64.c
Process complete
GWRon commented 7 years ago

Just wanted to note down that this "of course" (in the sense of the "real code" being used for ages now) this worked before (before the changes on params, returntypes ... and strictness). Which is why I prepended [Regression] to the issue title.

HurryStarfish commented 7 years ago

Found the problem. The declaration of TItemCollection in the generated .h file lists the base method instead of the overridden one:

struct BBClass__m_untitled157_TItemCollection {
    [...]
    _m_untitled157_TItemBaseCollection_GetAll_aTTItemBase_f f_GetAll_aTTItemBase;
};

Changing this line in decl.bmx/TFuncDecl.OnSemant() from If TObjectType(retType) And TObjectType(decl.retType ) Then to If (TObjectType(retType) And TObjectType(decl.retType)) Or (TArrayType(retType) And TArrayType(decl.retType)) Then should fix it.

GWRon commented 7 years ago

Dunno if it is related - but while the previous error is now gone I get this (after a rebuild !):

./bmk makeapp -g x64 -a -r "../../../Projekte/TVTower.WorkingCopy/TVTower.git/TVTower.bmx"
[...]
[100%] Linking:TVTower
/TVTower.git/source/Dig/.bmx/base.util.event.bmx.release.linux.x64.o: In Funktion `__m_base_util_event_TEventListenerRunFunction_OnEvent_TTEventBase':
base.util.event.bmx.release.linux.x64.c:(.text+0xc75): Nicht definierter Verweis auf `__m_base_util_event_teventlistenerrunfunction__function'
/TVTower.git/source/Dig/.bmx/base.util.deltatimer.bmx.release.linux.x64.o: In Funktion `__m_base_util_deltatimer_TDeltaTimer_RunUpdate':
base.util.deltatimer.bmx.release.linux.x64.c:(.text+0x325): Nicht definierter Verweis auf `__m_base_util_deltatimer_tdeltatimer__funcupdate'
/TVTower.git/source/Dig/.bmx/base.util.deltatimer.bmx.release.linux.x64.o: In Funktion `__m_base_util_deltatimer_TDeltaTimer_RunRender':
base.util.deltatimer.bmx.release.linux.x64.c:(.text+0x57f): Nicht definierter Verweis auf `__m_base_util_deltatimer_tdeltatimer__funcrender'
/TVTower.git/source/Dig/.bmx/base.gfx.gui.bmx.release.linux.x64.o: In Funktion `__m_base_gfx_gui_TGUIobject_Draw':
base.gfx.gui.bmx.release.linux.x64.c:(.text+0x3dab): Nicht definierter Verweis auf `__m_base_gfx_gui_tguiobject__customdraw'
base.gfx.gui.bmx.release.linux.x64.c:(.text+0x3e22): Nicht definierter Verweis auf `__m_base_gfx_gui_tguiobject__customdrawbackground'
base.gfx.gui.bmx.release.linux.x64.c:(.text+0x3e40): Nicht definierter Verweis auf `__m_base_gfx_gui_tguiobject__customdrawcontent'
base.gfx.gui.bmx.release.linux.x64.c:(.text+0x3e5e): Nicht definierter Verweis auf `__m_base_gfx_gui_tguiobject__customdrawchildren'
base.gfx.gui.bmx.release.linux.x64.c:(.text+0x3e7c): Nicht definierter Verweis auf `__m_base_gfx_gui_tguiobject__customdrawoverlay'
/TVTower.git/source/Dig/.bmx/base.gfx.tooltip.base.bmx.release.linux.x64.o: In Funktion `__m_base_gfx_tooltip_base_TTooltipBase__DrawBackground_iiii':
base.gfx.tooltip.base.bmx.release.linux.x64.c:(.text+0x1c3d): Nicht definierter Verweis auf `__m_base_gfx_tooltip_base_ttooltipbase__customdrawbackground'
/TVTower.git/source/Dig/.bmx/base.gfx.tooltip.base.bmx.release.linux.x64.o: In Funktion `__m_base_gfx_tooltip_base_TTooltipBase__DrawForeground_iiii':
base.gfx.tooltip.base.bmx.release.linux.x64.c:(.text+0x1a01): Nicht definierter Verweis auf `__m_base_gfx_tooltip_base_ttooltipbase__customdrawforeground'
/TVTower.git/source/Dig/.bmx/base.gfx.tooltip.base.bmx.release.linux.x64.o: In Funktion `__m_base_gfx_tooltip_base_TTooltipBase__DrawHeader_iiii':
base.gfx.tooltip.base.bmx.release.linux.x64.c:(.text+0x1a96): Nicht definierter Verweis auf `__m_base_gfx_tooltip_base_ttooltipbase__customdrawheader'
/TVTower.git/source/Dig/.bmx/base.gfx.tooltip.base.bmx.release.linux.x64.o: In Funktion `__m_base_gfx_tooltip_base_TTooltipBase__DrawContent_iiii':
base.gfx.tooltip.base.bmx.release.linux.x64.c:(.text+0x1b58): Nicht definierter Verweis auf `__m_base_gfx_tooltip_base_ttooltipbase__customdrawcontent'
/TVTower.git/source/.bmx/basefunctions_network.bmx.release.linux.x64.o: In Funktion `__m_basefunctions_network_TNetworkClient_EvaluateEvent_iTTNetworkPacketpb':
basefunctions_network.bmx.release.linux.x64.c:(.text+0x385e): Nicht definierter Verweis auf `__m_basefunctions_network_tnetworkclient_callback'
/TVTower.git/source/.bmx/basefunctions_network.bmx.release.linux.x64.o: In Funktion `__m_basefunctions_network_TNetworkServer_EvaluateEvent_iTTNetworkPacketpb':
basefunctions_network.bmx.release.linux.x64.c:(.text+0x3be8): Nicht definierter Verweis auf `__m_basefunctions_network_tnetworkserver_callback'
basefunctions_network.bmx.release.linux.x64.c:(.text+0x43bb): Nicht definierter Verweis auf `__m_basefunctions_network_tnetworkserver_callback'
/TVTower.git/source/.bmx/common.misc.dialogue.bmx.release.linux.x64.o: In Funktion `__m_common_misc_dialogue_TDialogueAnswer_Update_TTRectangle':
common.misc.dialogue.bmx.release.linux.x64.c:(.text+0x12c6): Nicht definierter Verweis auf `__m_common_misc_dialogue_tdialogueanswer__triggerfunction'
/TVTower.git/source/Dig/.bmx/base.framework.toastmessage.bmx.release.linux.x64.o: In Funktion `__m_base_framework_toastmessage_TToastMessage_SetClosed':
base.framework.toastmessage.bmx.release.linux.x64.c:(.text+0x12ee): Nicht definierter Verweis auf `__m_base_framework_toastmessage_ttoastmessage__onclosefunction'
/TVTower.git/source/.bmx/game.newsagency.sports.bmx.release.linux.x64.o: In Funktion `__m_game_newsagency_sports_TNewsEventSportLeague_StartSeason_l':
game.newsagency.sports.bmx.release.linux.x64.c:(.text+0x38f2): Nicht definierter Verweis auf `__m_game_newsagency_sports_tnewseventsportleague__onstartseason'
/TVTower.git/source/.bmx/game.newsagency.sports.bmx.release.linux.x64.o: In Funktion `__m_game_newsagency_sports_TNewsEventSportLeague_FinishSeason':
game.newsagency.sports.bmx.release.linux.x64.c:(.text+0x3a06): Nicht definierter Verweis auf `__m_game_newsagency_sports_tnewseventsportleague__onfinishseason'
/TVTower.git/source/.bmx/game.newsagency.sports.bmx.release.linux.x64.o: In Funktion `__m_game_newsagency_sports_TNewsEventSportLeague_StartSeasonPart_i':
game.newsagency.sports.bmx.release.linux.x64.c:(.text+0x3aef): Nicht definierter Verweis auf `__m_game_newsagency_sports_tnewseventsportleague__onstartseasonpart'
/TVTower.git/source/.bmx/game.newsagency.sports.bmx.release.linux.x64.o: In Funktion `__m_game_newsagency_sports_TNewsEventSportLeague_FinishSeasonPart_i':
game.newsagency.sports.bmx.release.linux.x64.c:(.text+0x3bb4): Nicht definierter Verweis auf `__m_game_newsagency_sports_tnewseventsportleague__onfinishseasonpart'
/TVTower.git/source/.bmx/game.newsagency.sports.bmx.release.linux.x64.o: In Funktion `__m_game_newsagency_sports_TNewsEventSportLeague_RunMatch_TTNewsEventSportMatchl':
game.newsagency.sports.bmx.release.linux.x64.c:(.text+0x549f): Nicht definierter Verweis auf `__m_game_newsagency_sports_tnewseventsportleague__onrunmatch'
collect2: error: ld returned 1 exit status
Build Error: Failed to link /TVTower.git/TVTower
real    5m18.707s
user    7m22.712s
sys 0m13.192s

"Nicht definierter Verweis auf" means "Undefined reference to".

This error does not happen when using my old bcc-ng binary (before your "strictness" enhancements).

HurryStarfish commented 7 years ago

Assuming you've rebuilt everything (might have to manually delete all .bmx folders in brl.mod and any other modules you using) - do these identifiers it can't find happen belong to function-pointer-type class fields, or to something else?

GWRon commented 7 years ago

I do not understand your last phrase ("do these identifiers it can't find happen belong to function-pointer-type class fields, or to something else?")

Dunno if module rebuilding should / could help at all. The not-found-function-references are all existing in my project's source codes. And they got "rebuild" in a non "quick" mode (means compilation time is 4 times as high and it does not quick-skip assumingly unchanged files).

Nonetheless - recompiled all used modules (brl, pub, maxmod2) and recompiled code of my game... same error as above.

Edit: I am not sure whether you are speaking German (but assuming it -> blitzmax.com / fireballstarfish) so you might answer (in addition!) in German as well, just to avoid misunderstanding things.

GWRon commented 7 years ago

Ahh I think the "happen" is too much in your phrase - so you are asking whether the not found function references are used in "Fields" (function pointers) or so ?

yes

they belong to such things (that is why some of them are having "callback" in their name)

This means the problem does not belong to this issue here but a another bug with the new function pointer handling/strictness/whatever.

HurryStarfish commented 7 years ago

Yep, I believe I found the problem. Opened #279. Will look into it.

Regarding the phrase, by "Do [they] happen to belong to [...]?" I meant "Gehören [sie] zufällig zu [...]?" - just wanted to make sure.

GWRon commented 7 years ago

Ahhh ok ... it just sounded a bit "odd" but now I got it.

@ issue Glad you got it "extracted" that fast (I would have needed some more spare time to rebuild everything - not that easy with the son on the knee/lap hammering keys :-)).