WurstScript icon indicating copy to clipboard operation
WurstScript copied to clipboard

Inliner/Init leaves behind singleline functions

Open Frotty opened this issue 8 years ago • 1 comments

After the inline phase there are many functions like this

function C1 takes nothing returns boolean
return true
endfunction

Left behind which are from packages which init's have apparently been inlined, or been empty anyways. I was able to fix this by linking all these functionm together and running the inliner step again:

    private void checkFunc(ImFunction func) {
        if (func.getParameters().size() == 0 && func.getBody().size() == 1 && func.getBody().get(0) instanceof ImReturn) {
            ImReturn imr = (ImReturn) func.getBody().get(0);
            if (imr.getReturnValue() instanceof ImBoolVal) {
                boolean bval = ((ImBoolVal) imr.getReturnValue()).getValB();
                if (bval) {
                    if (rootTrueFunc == null) {
                        rootTrueFunc = func;
                    } else {
                        imr.setReturnValue(JassIm.ImFunctionCall(imr.getTrace(), rootTrueFunc, JassIm.ImExprs(), true, CallType.NORMAL));
                    }
                }
            }
        }
    }

But I guess this is not an ideal solution

Frotty avatar Mar 02 '17 03:03 Frotty

I think the solution on this PR is too fragile with these string comparisons. My idea would be:

  1. Add another function call type to de.peeeq.wurstscript.translation.imtranslation.CallType, maybe call it INIT_FUNC
  2. Use this call type to call the init functions (adapt de.peeeq.wurstscript.translation.imtranslation.ImTranslator#callInitFunc).
  3. Before translating to Jass, transform calls with call type INIT_FUNC to TriggerEvaluate calls (same generated code as now).
  4. Optimize step 3 so that empty init functions get removed.

peq avatar Aug 20 '18 21:08 peq