WurstScript
WurstScript copied to clipboard
Inliner/Init leaves behind singleline functions
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
I think the solution on this PR is too fragile with these string comparisons. My idea would be:
- Add another function call type to
de.peeeq.wurstscript.translation.imtranslation.CallType, maybe call itINIT_FUNC - Use this call type to call the init functions (adapt
de.peeeq.wurstscript.translation.imtranslation.ImTranslator#callInitFunc). - Before translating to Jass, transform calls with call type
INIT_FUNCtoTriggerEvaluatecalls (same generated code as now). - Optimize step 3 so that empty init functions get removed.