olety / cjass

Preserving cjass code from code.google.com/p/cjass
0 stars 0 forks source link

Remove Unused Code Doesn't Work :\ #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It doesn't remove all unused code, only some of it.

Ex-
This was still in the map even though it was never used

function GetMovingUnit takes nothing returns integer
    return UnitMovement__eu
endfunction

Library:
http://www.hiveworkshop.com/forums/submissions-414/system-unit-movement-201449/#
post1980942

sry, to actually get it running in a map requires a bit of work.

It also strangely removed only the next method operator in the structs. It kept 
first and event:

function s__StationaryUnits__get_first takes nothing returns integer
return UnitMovement__sn[0]
endfunction
function s__StationaryUnits__get_event takes nothing returns integer
return UnitMovement__es
endfunction
function s__MovingUnits__get_first takes nothing returns integer
return UnitMovement__mn[0]
endfunction
function s__MovingUnits__get_event takes nothing returns integer
return UnitMovement__em
endfunction
function s__NativelyMovingUnits__get_first takes nothing returns integer
return UnitMovement__nn[0]
endfunction
function s__NativelyMovingUnits__get_event takes nothing returns integer
return UnitMovement__en
endfunction

Original issue reported on code.google.com by mrasolo...@gmail.com on 12 Aug 2011 at 3:10

GoogleCodeExporter commented 9 years ago
This could be the reason event wasn't removed-

        private static method onInit takes nothing returns nothing
            call MovingUnits.event.register(Condition(function thistype.m))
            call StationaryUnits.event.register(Condition(function thistype.s))
            call MovementTracker.eventIndex.register(Condition(function thistype.s))
            call MovementTracker.eventDeindex.register(Condition(function thistype.d))
        endmethod

That is an onInit method inside of a module that was not implemented anywhere.

The reason why first wasn't removed is still a complete mystery (not used 
anywhere at all).

Original comment by mrasolo...@gmail.com on 12 Aug 2011 at 5:03

GoogleCodeExporter commented 9 years ago
This is not a bug. Let me explain:

Optimizer remove only "optional" functions. What is optional? It's the 
functions, which can't be called with ExecuteFunc (otherwise, if optimizer 
delete them - map may be crashed on load). Theoretically optimizer may check 
whether there are Exec with "hard" arguments like `ExecyteFunc ("some_func_" + 
GetUnitAbilityLevel(u, 'A000'))`, and if  it does'n - make all functions 
optional. But so far it does not.

Also, executing function, which takes any arguments crashed map, so this 
function can't be executed. So it optional. You also may declare function as 
optional:

{{{
    optional nothing a () {}

    private constant optional nothing b () {}

    optional function c takes nothing returns nothing
    endfunction
}}}

Got it?)

Original comment by adi...@gmail.com on 12 Aug 2011 at 8:20

GoogleCodeExporter commented 9 years ago
People only really use ExecuteFunc for onInit tho ; \. It's not advised to use 
it for anything else.

Also, if the function returns a parameter, chances are it'll never be used in 
an ExecuteFunc.

Original comment by mrasolo...@gmail.com on 12 Aug 2011 at 10:11