- declared most native getters in Actor as const.

- made the self pointer of const functions readonly.

This seems to work fine. Both calling a non-const function and trying to assign a value to a member fail with an error message.
This commit is contained in:
Christoph Oelckers 2017-03-04 12:43:07 +01:00
commit 7dbc6939c4
3 changed files with 31 additions and 21 deletions

View file

@ -110,12 +110,13 @@ void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, TArray<FNam
if (funcflags & VARF_Method)
{
// implied self pointer
if (args != nullptr) args->Push(NewPointer(cls));
if (args != nullptr) args->Push(NewPointer(cls, !!(funcflags & VARF_ReadOnly)));
if (argflags != nullptr) argflags->Push(VARF_Implicit | VARF_ReadOnly);
if (argnames != nullptr) argnames->Push(NAME_self);
}
if (funcflags & VARF_Action)
{
assert(!(funcflags & VARF_ReadOnly));
// implied caller and callingstate pointers
if (args != nullptr)
{

View file

@ -2156,6 +2156,15 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
}
if (f->Flags & ZCC_Action)
{
if (varflags & VARF_ReadOnly)
{
Error(f, "Action functions cannot be declared const");
varflags &= ~VARF_ReadOnly;
}
if (varflags & VARF_UI)
{
Error(f, "Action functions cannot be declared UI");
}
// Non-Actors cannot have action functions.
if (!c->Type()->IsKindOf(RUNTIME_CLASS(PClassActor)))
{