- split up FxCompoundStatement into the old FxSequence and a new subclass. FxSequence is just a sequence of expressions, while FxCompoundStatement is the one that actually implements handling of local variables. The split was done so that ZCCCompiler::ConvertNode can return multiple statements as one object and for that FxCompoundStatement is not suitable.
- added conversion of local variable declarations. This is still untested
This commit is contained in:
parent
2d85efce2a
commit
ffc38d422e
3 changed files with 95 additions and 21 deletions
|
|
@ -5014,6 +5014,58 @@ ExpEmit FxFlopFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
return v;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxSequence :: Resolve
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *FxSequence::Resolve(FCompileContext &ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
for (unsigned i = 0; i < Expressions.Size(); ++i)
|
||||
{
|
||||
if (NULL == (Expressions[i] = Expressions[i]->Resolve(ctx)))
|
||||
{
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxSequence :: Emit
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
ExpEmit FxSequence::Emit(VMFunctionBuilder *build)
|
||||
{
|
||||
for (unsigned i = 0; i < Expressions.Size(); ++i)
|
||||
{
|
||||
ExpEmit v = Expressions[i]->Emit(build);
|
||||
// Throw away any result. We don't care about it.
|
||||
v.Free(build);
|
||||
}
|
||||
return ExpEmit();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxSequence :: GetDirectFunction
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
VMFunction *FxSequence::GetDirectFunction()
|
||||
{
|
||||
if (Expressions.Size() == 1)
|
||||
{
|
||||
return Expressions[0]->GetDirectFunction();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxCompoundStatement :: Resolve
|
||||
|
|
@ -5023,18 +5075,11 @@ ExpEmit FxFlopFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
FxExpression *FxCompoundStatement::Resolve(FCompileContext &ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
auto outer = ctx.Block;
|
||||
Outer = ctx.Block;
|
||||
ctx.Block = this;
|
||||
for (unsigned i = 0; i < Expressions.Size(); ++i)
|
||||
{
|
||||
if (NULL == (Expressions[i] = Expressions[i]->Resolve(ctx)))
|
||||
{
|
||||
ctx.Block = Outer;
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
ctx.Block = Outer;
|
||||
auto x = FxSequence::Resolve(ctx);
|
||||
ctx.Block = outer;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -5046,33 +5091,13 @@ FxExpression *FxCompoundStatement::Resolve(FCompileContext &ctx)
|
|||
|
||||
ExpEmit FxCompoundStatement::Emit(VMFunctionBuilder *build)
|
||||
{
|
||||
for (unsigned i = 0; i < Expressions.Size(); ++i)
|
||||
{
|
||||
ExpEmit v = Expressions[i]->Emit(build);
|
||||
// Throw away any result. We don't care about it.
|
||||
v.Free(build);
|
||||
}
|
||||
auto e = FxSequence::Emit(build);
|
||||
// Release all local variables in this block.
|
||||
for (auto l : LocalVars)
|
||||
{
|
||||
l->Release(build);
|
||||
}
|
||||
return ExpEmit();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxCompoundStatement :: GetDirectFunction
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
VMFunction *FxCompoundStatement::GetDirectFunction()
|
||||
{
|
||||
if (Expressions.Size() == 1)
|
||||
{
|
||||
return Expressions[0]->GetDirectFunction();
|
||||
}
|
||||
return NULL;
|
||||
return e;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
|||
|
|
@ -1087,25 +1087,41 @@ public:
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxCompoundStatement
|
||||
// FxSequence (a list of statements with no semantics attached - used to return multiple nodes as one)
|
||||
//
|
||||
//==========================================================================
|
||||
class FxLocalVariableDeclaration;
|
||||
|
||||
class FxCompoundStatement : public FxExpression
|
||||
class FxSequence : public FxExpression
|
||||
{
|
||||
TDeletingArray<FxExpression *> Expressions;
|
||||
|
||||
public:
|
||||
FxSequence(const FScriptPosition &pos) : FxExpression(pos) {}
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
void Add(FxExpression *expr) { if (expr != NULL) Expressions.Push(expr); }
|
||||
VMFunction *GetDirectFunction();
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxCompoundStatement (like a list but implements maintenance of local variables)
|
||||
//
|
||||
//==========================================================================
|
||||
class FxLocalVariableDeclaration;
|
||||
|
||||
class FxCompoundStatement : public FxSequence
|
||||
{
|
||||
TArray<FxLocalVariableDeclaration *> LocalVars;
|
||||
TDeletingArray<FxExpression *> Expressions;
|
||||
FxCompoundStatement *Outer = nullptr;
|
||||
|
||||
friend class FxLocalVariableDeclaration;
|
||||
|
||||
public:
|
||||
FxCompoundStatement(const FScriptPosition &pos) : FxExpression(pos) {}
|
||||
FxCompoundStatement(const FScriptPosition &pos) : FxSequence(pos) {}
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
void Add(FxExpression *expr) { if (expr != NULL) Expressions.Push(expr); }
|
||||
VMFunction *GetDirectFunction();
|
||||
FxLocalVariableDeclaration *FindLocalVariable(FName name);
|
||||
bool CheckLocalVariable(FName name);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue