- fixed and cleaned up state index jump handling

* use the function build list instead of the function to pass the info. The function is permanent so not the best place for compile-time info.
 * pass along the current state index which is needed to calculate the target state.
This commit is contained in:
Christoph Oelckers 2016-11-06 13:14:46 +01:00
commit 2ac0046cda
9 changed files with 24 additions and 18 deletions

View file

@ -93,12 +93,14 @@ static const FLOP FxFlops[] =
//
//==========================================================================
FCompileContext::FCompileContext(PFunction *fnc, PPrototype *ret, bool fromdecorate) : ReturnProto(ret), Function(fnc), Class(nullptr), FromDecorate(fromdecorate)
FCompileContext::FCompileContext(PFunction *fnc, PPrototype *ret, bool fromdecorate, int stateindex, int statecount)
: ReturnProto(ret), Function(fnc), Class(nullptr), FromDecorate(fromdecorate), StateIndex(stateindex), StateCount(statecount)
{
if (fnc != nullptr) Class = fnc->OwningClass;
}
FCompileContext::FCompileContext(PClass *cls, bool fromdecorate) : ReturnProto(nullptr), Function(nullptr), Class(cls), FromDecorate(fromdecorate)
FCompileContext::FCompileContext(PClass *cls, bool fromdecorate)
: ReturnProto(nullptr), Function(nullptr), Class(cls), FromDecorate(fromdecorate), StateIndex(-1), StateCount(0)
{
}
@ -1426,13 +1428,13 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
}
else if (basex->IsNumeric() && basex->ValueType != TypeSound && basex->ValueType != TypeColor)
{
if (ctx.Function->SymbolName != NAME_None || !(ctx.Function->Variants[0].Flags & VARF_Action))
if (ctx.StateIndex < 0)
{
ScriptPosition.Message(MSG_ERROR, "State jumps with index can only be used in anonymous state functions.");
delete this;
return nullptr;
}
if (ctx.Function->StateCount != 1)
if (ctx.StateCount != 1)
{
ScriptPosition.Message(MSG_ERROR, "State jumps with index cannot be used on multistate definitions");
delete this;
@ -1447,7 +1449,7 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
delete this;
return nullptr;
}
FxExpression *x = new FxStateByIndex(i, ScriptPosition);
FxExpression *x = new FxStateByIndex(ctx.StateIndex + i, ScriptPosition);
x = x->Resolve(ctx);
basex = nullptr;
delete this;

View file

@ -73,10 +73,12 @@ struct FCompileContext
PPrototype *ReturnProto;
PFunction *Function; // The function that is currently being compiled (or nullptr for constant evaluation.)
PClass *Class; // The type of the owning class.
bool FromDecorate;
bool FromDecorate; // DECORATE must silence some warnings and demote some errors.
int StateIndex; // index in actor's state table for anonymous functions, otherwise -1 (not used by DECORATE which pre-resolves state indices)
int StateCount; // amount of states an anoymous function is being used on (must be 1 for state indices to be allowed.)
TDeletingArray<FxLocalVariableDeclaration *> FunctionArgs;
FCompileContext(PFunction *func, PPrototype *ret, bool fromdecorate);
FCompileContext(PFunction *func, PPrototype *ret, bool fromdecorate, int stateindex, int statecount);
FCompileContext(PClass *cls, bool fromdecorate); // only to be used to resolve constants!
PSymbol *FindInClass(FName identifier, PSymbolTable *&symt);