Implemented format() builtin call
This commit is contained in:
parent
4be0767d7b
commit
e75aa08d0a
7 changed files with 267 additions and 3 deletions
|
|
@ -7115,6 +7115,14 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
|||
}
|
||||
}
|
||||
|
||||
// [ZZ] string formatting function
|
||||
if (MethodName == NAME_Format)
|
||||
{
|
||||
FxExpression *x = new FxFormat(ArgList, ScriptPosition);
|
||||
delete this;
|
||||
return x->Resolve(ctx);
|
||||
}
|
||||
|
||||
int min, max, special;
|
||||
if (MethodName == NAME_ACS_NamedExecuteWithResult || MethodName == NAME_CallACS)
|
||||
{
|
||||
|
|
@ -8341,6 +8349,85 @@ ExpEmit FxFlopFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxFormat::FxFormat(FArgumentList &args, const FScriptPosition &pos)
|
||||
: FxExpression(EFX_FlopFunctionCall, pos)
|
||||
{
|
||||
ArgList = std::move(args);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxFormat::~FxFormat()
|
||||
{
|
||||
}
|
||||
|
||||
FxExpression *FxFormat::Resolve(FCompileContext& ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
|
||||
for (int i = 0; i < ArgList.Size(); i++)
|
||||
{
|
||||
ArgList[i] = ArgList[i]->Resolve(ctx);
|
||||
if (ArgList[i] == nullptr)
|
||||
{
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// first argument should be a string
|
||||
if (!i && ArgList[i]->ValueType != TypeString)
|
||||
{
|
||||
ScriptPosition.Message(MSG_ERROR, "String was expected for format");
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (ArgList[i]->ValueType == TypeName ||
|
||||
ArgList[i]->ValueType == TypeSound)
|
||||
{
|
||||
FxExpression* x = new FxStringCast(ArgList[i]);
|
||||
x = x->Resolve(ctx);
|
||||
if (x == nullptr)
|
||||
{
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
ArgList[i] = x;
|
||||
}
|
||||
}
|
||||
|
||||
ValueType = TypeString;
|
||||
return this;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
ExpEmit FxFormat::Emit(VMFunctionBuilder *build)
|
||||
{
|
||||
ExpEmit to = ExpEmit(build, REGT_STRING);
|
||||
for (int i = 0; i < ArgList.Size(); i++)
|
||||
{
|
||||
EmitParameter(build, ArgList[i], ScriptPosition);
|
||||
}
|
||||
|
||||
build->Emit(OP_STRFMT, to.RegNum, ArgList.Size(), 0);
|
||||
return to;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
|
|
|||
|
|
@ -255,6 +255,7 @@ enum EFxType
|
|||
EFX_MemberFunctionCall,
|
||||
EFX_ActionSpecialCall,
|
||||
EFX_FlopFunctionCall,
|
||||
EFX_FormatFunctionCall,
|
||||
EFX_VMFunctionCall,
|
||||
EFX_Sequence,
|
||||
EFX_CompoundStatement,
|
||||
|
|
@ -1532,7 +1533,25 @@ public:
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxFlopFunctionCall
|
||||
// FxFormatFunctionCall
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
class FxFormat : public FxExpression
|
||||
{
|
||||
FArgumentList ArgList;
|
||||
|
||||
public:
|
||||
|
||||
FxFormat(FArgumentList &args, const FScriptPosition &pos);
|
||||
~FxFormat();
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxVectorBuiltin
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
|
|
@ -1551,7 +1570,7 @@ public:
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxFlopFunctionCall
|
||||
// FxGetClass
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
|
|
@ -1569,7 +1588,7 @@ public:
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxFlopFunctionCall
|
||||
// FxGetDefaultByType
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue