C4AulFunc: Improve const correctness

stable-5.4
Nicolas Hake 2013-11-02 13:38:26 +01:00
parent c0f76f691b
commit 003f897cbe
4 changed files with 27 additions and 21 deletions

View File

@ -196,14 +196,20 @@ protected:
C4AulBCC *GetLastCode() { return Code.empty() ? NULL : &Code.back(); }
std::vector<C4AulBCC> Code;
std::vector<const char *> PosForCode;
int ParCount;
C4V_Type ParType[C4AUL_MAX_Par]; // parameter types
public:
const char *Script; // script pos
C4ValueMapNames VarNamed; // list of named vars in this function
C4ValueMapNames ParNamed; // list of named pars in this function
int ParCount;
C4V_Type ParType[C4AUL_MAX_Par]; // parameter types
void AddPar(const char * Idtf) { ParNamed.AddName(Idtf); ++ParCount; }
void AddPar(const char * Idtf)
{
assert(ParCount < C4AUL_MAX_Par);
assert(ParCount == ParNamed.iSize);
ParNamed.AddName(Idtf);
++ParCount;
}
C4ScriptHost *pOrgScript; // the orginal script (!= Owner if included or appended)
C4AulScriptFunc(C4AulScript *pOwner, C4ScriptHost *pOrgScript, const char *pName, const char *Script);
@ -212,10 +218,10 @@ public:
void ParseFn(C4AulScriptContext* context = NULL);
virtual bool GetPublic() { return true; }
virtual int GetParCount() { return ParCount; }
virtual C4V_Type *GetParType() { return ParType; }
virtual C4V_Type GetRetType() { return C4V_Any; }
virtual bool GetPublic() const { return true; }
virtual int GetParCount() const { return ParCount; }
virtual const C4V_Type *GetParType() const { return ParType; }
virtual C4V_Type GetRetType() const { return C4V_Any; }
virtual C4Value Exec(C4PropList * p, C4Value pPars[], bool fPassErrors=false); // execute func
int GetLineOfCode(C4AulBCC * bcc);

View File

@ -241,8 +241,8 @@ public:
~C4AulDefFuncHelper()
{
}
virtual C4V_Type* GetParType() { return ParType; }
virtual bool GetPublic() { return Public; }
virtual const C4V_Type* GetParType() const { return ParType; }
virtual bool GetPublic() const { return Public; }
protected:
C4V_Type ParType[10];// type of the parameters
bool Public;
@ -280,8 +280,8 @@ public C4AulDefFuncHelper { \
public: \
/* A pointer to the function which this class wraps */ \
typedef RType (*Func)(C4PropList * LIST(N, PARS)); \
virtual int GetParCount() { return N; } \
virtual C4V_Type GetRetType() \
virtual int GetParCount() const { return N; } \
virtual C4V_Type GetRetType() const \
{ return C4ValueConv<RType>::Type(); } \
/* Constructor, using the base class to create the ParType array */ \
C4AulDefFunc##N(C4AulScript *pOwner, const char *pName, Func pFunc, bool Public): \
@ -298,8 +298,8 @@ public C4AulDefFuncHelper { \
public: \
/* A pointer to the function which this class wraps */ \
typedef RType (*Func)(C4Object * LIST(N, PARS)); \
virtual int GetParCount() { return N; } \
virtual C4V_Type GetRetType() \
virtual int GetParCount() const { return N; } \
virtual C4V_Type GetRetType() const \
{ return C4ValueConv<RType>::Type(); } \
/* Constructor, using the base class to create the ParType array */ \
C4AulDefObjectFunc##N(C4AulScript *pOwner, const char *pName, Func pFunc, bool Public): \
@ -376,9 +376,9 @@ public:
C4AulDefFunc(C4AulScript *pOwner, C4ScriptFnDef* pDef);
~C4AulDefFunc();
virtual bool GetPublic() { return !!Def->Public; }
virtual C4V_Type* GetParType() { return Def->ParType; }
virtual C4V_Type GetRetType() { return Def->RetType; }
virtual bool GetPublic() const { return !!Def->Public; }
virtual const C4V_Type* GetParType() const { return Def->ParType; }
virtual C4V_Type GetRetType() const { return Def->RetType; }
virtual C4Value Exec(C4PropList * p, C4Value pPars[], bool fPassErrors=false);
};

View File

@ -838,7 +838,7 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4
}
// Convert parameters (typecheck)
C4V_Type *pTypes = pFunc->GetParType();
const C4V_Type *pTypes = pFunc->GetParType();
for (int i = 0; i < pFunc->GetParCount(); i++)
if (!pPars[i].CheckParConversion(pTypes[i]))
throw new C4AulExecError(FormatString("call to \"%s\" parameter %d: passed %s, but expected %s",

View File

@ -77,10 +77,10 @@ public:
virtual C4AulScriptFunc *SFunc() { return NULL; } // type check func...
// Wether this function should be visible to players
virtual bool GetPublic() { return false; }
virtual int GetParCount() { return C4AUL_MAX_Par; }
virtual C4V_Type* GetParType() = 0;
virtual C4V_Type GetRetType() = 0;
virtual bool GetPublic() const { return false; }
virtual int GetParCount() const { return C4AUL_MAX_Par; }
virtual const C4V_Type* GetParType() const = 0;
virtual C4V_Type GetRetType() const = 0;
C4Value Exec(C4PropList * p = NULL, C4AulParSet *pPars = NULL, bool fPassErrors=false)
{
return Exec(p, pPars->Par, fPassErrors);