- give PFunction a bit more information:
* explicitly require passing the owning class when creating it. * extract self pointer class when adding a variant. * put the flags on the single variants, we can not fully rule out that they will be 100% identical, if variants ever get allowed.
This commit is contained in:
parent
091da92819
commit
db8ab1bc4a
10 changed files with 196 additions and 33 deletions
|
|
@ -3898,7 +3898,7 @@ VMFunction *FxVMFunctionCall::GetDirectFunction()
|
|||
// then it can be a "direct" function. That is, the DECORATE
|
||||
// definition can call that function directly without wrapping
|
||||
// it inside VM code.
|
||||
if ((ArgList ? ArgList->Size() : 0) == 0 && (Function->Flags & VARF_Action))
|
||||
if ((ArgList ? ArgList->Size() : 0) == 0 && (Function->Variants[0].Flags & VARF_Action))
|
||||
{
|
||||
return Function->Variants[0].Implementation;
|
||||
}
|
||||
|
|
@ -3920,8 +3920,8 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx)
|
|||
auto argtypes = proto->ArgumentTypes;
|
||||
|
||||
int implicit;
|
||||
if (Function->Flags & VARF_Action) implicit = 3;
|
||||
else if (Function->Flags & VARF_Method) implicit = 1;
|
||||
if (Function->Variants[0].Flags & VARF_Action) implicit = 3;
|
||||
else if (Function->Variants[0].Flags & VARF_Method) implicit = 1;
|
||||
else implicit = 0;
|
||||
|
||||
if (ArgList != NULL)
|
||||
|
|
@ -4014,15 +4014,15 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
// For ZSCRIPT 'self' is properly used for the state's owning actor, meaning we have to pass the second argument here.
|
||||
|
||||
// If both functions are non-action or both are action, there is no need for special treatment.
|
||||
if (!OwnerIsSelf || (!!(Function->Flags & VARF_Action) == build->IsActionFunc))
|
||||
if (!OwnerIsSelf || (!!(Function->Variants[0].Flags & VARF_Action) == build->IsActionFunc))
|
||||
{
|
||||
// Emit code to pass implied parameters
|
||||
if (Function->Flags & VARF_Method)
|
||||
if (Function->Variants[0].Flags & VARF_Method)
|
||||
{
|
||||
build->Emit(OP_PARAM, 0, REGT_POINTER, 0);
|
||||
count += 1;
|
||||
}
|
||||
if (Function->Flags & VARF_Action)
|
||||
if (Function->Variants[0].Flags & VARF_Action)
|
||||
{
|
||||
static_assert(NAP == 3, "This code needs to be updated if NAP changes");
|
||||
if (build->IsActionFunc)
|
||||
|
|
@ -4041,17 +4041,14 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
}
|
||||
else
|
||||
{
|
||||
// There are two possibilities here:
|
||||
// Calling a non-action function from an action function.
|
||||
// In that case the 'stateowner' pointer needs to be used as self.
|
||||
if (build->IsActionFunc && (Function->Flags & VARF_Method))
|
||||
if (build->IsActionFunc && (Function->Variants[0].Flags & VARF_Method))
|
||||
{
|
||||
build->Emit(OP_PARAM, 0, REGT_POINTER, 1);
|
||||
build->Emit(OP_PARAM, 0, REGT_POINTER, 0);
|
||||
count += 1;
|
||||
}
|
||||
// and calling an action function from a non-action function.
|
||||
// This must be blocked because it lacks crucial information.
|
||||
if (!build->IsActionFunc && (Function->Flags & VARF_Action))
|
||||
if (!build->IsActionFunc && (Function->Variants[0].Flags & VARF_Action))
|
||||
{
|
||||
// This case should be eliminated in the analyzing stage.
|
||||
I_Error("Cannot call action function from non-action functions.");
|
||||
|
|
|
|||
153
src/scripting/codegeneration/functioncalls.cpp
Normal file
153
src/scripting/codegeneration/functioncalls.cpp
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
#if 0
|
||||
/*
|
||||
** cg_functioncall.cpp
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2016 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "codegen.h"
|
||||
#include "thingdef.h"
|
||||
#include "zscript/zcc_parser.h"
|
||||
|
||||
// just some rough concepts for now...
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FindClassMemberFunction
|
||||
//
|
||||
// Looks for a name in a class's
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
PFunction *FindClassMemberFunction(PClass *cls, FName name, FScriptPosition &sc)
|
||||
{
|
||||
PSymbolTable *symtable;
|
||||
auto symbol = cls->Symbols.FindSymbolInTable(name, symtable);
|
||||
auto funcsym = dyn_cast<PFunction>(symbol);
|
||||
|
||||
if (symbol != nullptr)
|
||||
{
|
||||
if (funcsym == nullptr)
|
||||
{
|
||||
sc.Message(MSG_ERROR, "%s is not a member function of %s", name.GetChars(), cls->TypeName.GetChars());
|
||||
}
|
||||
else if (funcsym->Flags & VARF_Private && symtable != &cls->Symbols)
|
||||
{
|
||||
sc.Message(MSG_ERROR, "%s is declared private and not accessible", symbol->SymbolName.GetChars());
|
||||
}
|
||||
else if (funcsym->Flags & VARF_Deprecated)
|
||||
{
|
||||
sc.Message(MSG_WARNING, "Call to deprecated function %s", symbol->SymbolName.GetChars());
|
||||
}
|
||||
}
|
||||
return funcsym;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// let's save some work down the line by analyzing the type of function
|
||||
// that's being called right here and create appropriate nodes.
|
||||
// A simple function call expression must be immediately resolvable in
|
||||
// the context it gets compiled in, if the function name cannot be
|
||||
// resolved here, it will never.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *ConvertSimpleFunctionCall(ZCC_ExprID *function, FArgumentList *args, PClass *cls, FScriptPosition &sc)
|
||||
{
|
||||
// Priority is as follows:
|
||||
//1. member functions of the containing class.
|
||||
//2. action specials.
|
||||
//3. floating point operations
|
||||
//4. global builtins
|
||||
|
||||
if (cls != nullptr)
|
||||
{
|
||||
// There is an action function ACS_NamedExecuteWithResult which must be ignored here for this to work.
|
||||
if (function->Identifier != NAME_ACS_NamedExecuteWithResult)
|
||||
{
|
||||
{
|
||||
args = ConvertNodeList(fcall->Parameters);
|
||||
if (args->Size() == 0)
|
||||
{
|
||||
delete args;
|
||||
args = nullptr;
|
||||
}
|
||||
|
||||
return new FxMemberunctionCall(new FxSelf(), new FxInvoker(), func, args, sc, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *ConvertFunctionCall(ZCC_Expression *function, FArgumentList *args, PClass *cls, FScriptPosition &sc)
|
||||
{
|
||||
// function names can either be
|
||||
// - plain identifiers
|
||||
// - class members
|
||||
// - array syntax for random() calls.
|
||||
|
||||
switch(function->NodeType)
|
||||
{
|
||||
case AST_ExprID:
|
||||
return ConvertSimpleFunctionCall(static_cast<ZCC_ExprID *>(function), args, cls, sc);
|
||||
|
||||
case AST_ExprMemberAccess:
|
||||
return ConvertMemberCall(fcall);
|
||||
|
||||
case AST_ExprBinary:
|
||||
// Array access syntax is wrapped into a ZCC_ExprBinary object.
|
||||
if (fcall->Function->Operation == PEX_ArrayAccess)
|
||||
{
|
||||
return ConvertArrayFunctionCall(fcall);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Error(fcall, "Invalid function identifier");
|
||||
return new FxNop(*fcall); // return something so that we can continue
|
||||
}
|
||||
|
||||
|
||||
assert(fcall->Function->NodeType == AST_ExprID); // of course this cannot remain. Right now nothing more complex can come along but later this will have to be decomposed into 'self' and the actual function name.
|
||||
auto fname = static_cast<ZCC_ExprID *>(fcall->Function)->Identifier;
|
||||
return new FxFunctionCall(nullptr, fname, ConvertNodeList(fcall->Parameters), *ast);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue