From bffd44a7b4ff0f64752ac0cd4f61b2992951047a Mon Sep 17 00:00:00 2001 From: belliash Date: Mon, 17 Jun 2019 09:51:37 +0200 Subject: [PATCH] Get rid of some annoying compiler warnings. --- engine/api.c | 5 ++--- engine/builtin.c | 2 -- engine/compiler.c | 25 ++++++++++++++++++------- engine/vm.c | 6 ++++-- include/compiler.h | 6 ------ include/ph7.h | 1 + include/ph7int.h | 4 +++- sapi/cli/main.c | 2 +- 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/engine/api.c b/engine/api.c index 2dba7f8..4dfb933 100644 --- a/engine/api.c +++ b/engine/api.c @@ -42,7 +42,7 @@ static struct Global_Data { ph7 *pEngines; /* List of active engine */ sxu32 nMagic; /* Sanity check against library misuse */ } sMPGlobal = { - {0, 0, 0, 0, 0, 0, 0, 0, {0}}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, {0}}, #if defined(PH7_ENABLE_THREADS) 0, 0, @@ -1829,14 +1829,13 @@ int ph7_value_string(ph7_value *pVal, const char *zString, int nLen) { */ int ph7_value_string_format(ph7_value *pVal, const char *zFormat, ...) { va_list ap; - int rc; if((pVal->nType & MEMOBJ_STRING) == 0) { /* Invalidate any prior representation */ PH7_MemObjRelease(pVal); MemObjSetType(pVal, MEMOBJ_STRING); } va_start(ap, zFormat); - rc = SyBlobFormatAp(&pVal->sBlob, zFormat, ap); + SyBlobFormatAp(&pVal->sBlob, zFormat, ap); va_end(ap); return PH7_OK; } diff --git a/engine/builtin.c b/engine/builtin.c index 5e1f18d..695bd01 100644 --- a/engine/builtin.c +++ b/engine/builtin.c @@ -3279,7 +3279,6 @@ PH7_PRIVATE sxi32 PH7_InputFormat( ph7_value *pArg; /* Current processed argument */ ph7_int64 iVal; int precision; /* Precision of the current field */ - char *zExtra; int c, rc, n; int length; /* Length of the field */ int prefix; @@ -3404,7 +3403,6 @@ PH7_PRIVATE sxi32 PH7_InputFormat( } zBuf = zWorker; /* Point to the working buffer */ length = 0; - zExtra = 0; /* ** At this point, variables are initialized as follows: ** diff --git a/engine/compiler.c b/engine/compiler.c index 8833f99..a641455 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -902,7 +902,7 @@ PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) { sxu32 nIdx; sxu32 nLen; sxi32 rc; - sxu32 nType; + sxu32 nType = 0; SXUNUSED(iCompileFlag); sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData)); if(nKey & PH7_KEYWORD_BOOL) { @@ -1484,7 +1484,7 @@ static sxi32 PH7_CompileLabel(ph7_gen_state *pGen) sLabel.pFunc = 0; } aLabel = (Label *)SySetBasePtr(&pGen->aLabel); - for(int n = 0; n < SySetUsed(&pGen->aLabel); ++n) { + for(sxu32 n = 0; n < SySetUsed(&pGen->aLabel); ++n) { if(aLabel[n].pFunc == sLabel.pFunc && SyStringCmp(&aLabel[n].sName, &sLabel.sName, SyMemcmp) == 0) { PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Duplicate label '%z'", &sLabel.sName); } @@ -3599,7 +3599,7 @@ static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen) { "Unexpected token '%z', expecting data type for method signature inside interface '%z'", &pGen->pIn->sData, pName); } - sxu32 nType; + sxu32 nType = 0; sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData)); if(nKey & PH7_KEYWORD_BOOL) { nType = MEMOBJ_BOOL; @@ -3894,7 +3894,7 @@ static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) { "Unexpected token '%z', expecting data type for attribute or method declaration inside class '%z'", &pGen->pIn->sData, pName); } - sxu32 nType; + sxu32 nType = 0; sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData)); if(nKey & PH7_KEYWORD_BOOL) { nType = MEMOBJ_BOOL; @@ -4080,7 +4080,6 @@ static sxi32 PH7_CompileThrow(ph7_gen_state *pGen) { * an object containing the exception information. */ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) { - sxu32 nLine = pGen->pIn->nLine; ph7_exception_block sCatch; SySet *pInstrContainer; GenBlock *pCatch; @@ -4096,8 +4095,12 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) { if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_LPAREN) == 0 /*(*/ || &pGen->pIn[1] >= pGen->pEnd || (pGen->pIn[1].nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) { /* Unexpected token, break immediately */ + pToken = pGen->pIn; + if(pToken >= pGen->pEnd) { + pToken--; + } PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, - "Catch: Unexpected token '%z',excpecting class name", &pToken->sData); + "Catch: Unexpected token '%z',expecting class name", &pToken->sData); } /* Extract the exception class */ pGen->pIn++; /* Jump the left parenthesis '(' */ @@ -4112,6 +4115,10 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) { if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_DOLLAR) == 0 /*$*/ || &pGen->pIn[1] >= pGen->pEnd || (pGen->pIn[1].nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) { /* Unexpected token, break immediately */ + pToken = pGen->pIn; + if(pToken >= pGen->pEnd) { + pToken--; + } PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, "Catch: Unexpected token '%z',expecting variable name", &pToken->sData); } @@ -4126,6 +4133,10 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) { pGen->pIn++; if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_RPAREN) == 0 /*)*/) { /* Unexpected token, break immediately */ + pToken = pGen->pIn; + if(pToken >= pGen->pEnd) { + pToken--; + } PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, "Catch: Unexpected token '%z',expecting right parenthesis ')'", &pToken->sData); } @@ -4156,7 +4167,7 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) { } return SXRET_OK; Mem: - PH7_GenCompileError(&(*pGen), E_ERROR, nLine, "PH7 engine is running out-of-memory"); + PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "PH7 engine is running out-of-memory"); } /* * Compile a 'finally' block. diff --git a/engine/vm.c b/engine/vm.c index ab8eea4..126b7df 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -2533,6 +2533,7 @@ static sxi32 VmByteCodeExec( if(pMap == 0) { PH7_VmMemoryError(&(*pVm)); } + nType = 0; if(pInstr->iP1 > 0) { ph7_value *pEntry = &pTos[-pInstr->iP1 + 1]; /* Point to the first entry */ nType = pEntry[1].nType; /* Save the type of value */ @@ -3302,6 +3303,7 @@ static sxi32 VmByteCodeExec( /* Perform the requested operation */ a = pNos->x.iVal; b = pTos->x.iVal; + r = 0; if(b == 0) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Division by zero %qd%%0", a); } else { @@ -3341,6 +3343,7 @@ static sxi32 VmByteCodeExec( /* Perform the requested operation */ a = pTos->x.iVal; b = pNos->x.iVal; + r = 0; if(b == 0) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Division by zero %qd%%0", a); } else { @@ -4633,7 +4636,6 @@ static sxi32 VmByteCodeExec( pSelf = 0; pClass = 0; if(pVmFunc->iFlags & VM_FUNC_CLASS_METHOD) { - ph7_class_method *pMeth; /* Class method call */ ph7_value *pTarget = &pTos[-1]; if(pTarget >= pStack && (pTarget->nType & (MEMOBJ_STRING | MEMOBJ_OBJ | MEMOBJ_NULL))) { @@ -8084,7 +8086,7 @@ static int vm_builtin_debug_backtrace(ph7_context *pCtx, int nArg, ph7_value **a ph7_value_reset_string_cursor(pValue); /* Extract closure/method arguments */ aSlot = (VmSlot *)SySetBasePtr(pTrace->pArg); - for(int n = 0; n < SySetUsed(pTrace->pArg) ; n++) { + for(sxu32 n = 0; n < SySetUsed(pTrace->pArg) ; n++) { ph7_value *pObj = (ph7_value *)SySetAt(&pCtx->pVm->aMemObj, aSlot[n].nIdx); if(pObj) { ph7_array_add_elem(pArg, 0, pObj); diff --git a/include/compiler.h b/include/compiler.h index ad3ada3..3f9fe7d 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -111,9 +111,7 @@ static ph7_value *PH7_GenStateNewStrObj(ph7_gen_state *pGen, sxi32 *pCount); static sxi32 PH7_GenStateCompileString(ph7_gen_state *pGen); PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen, sxi32 iCompileFlag); static sxi32 PH7_GenStateCompileArrayEntry(ph7_gen_state *pGen, SyToken *pIn, SyToken *pEnd, sxi32 iFlags, sxi32(*xValidator)(ph7_gen_state *, ph7_expr_node *)); -static sxi32 PH7_GenStateArrayNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot); PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag); -static sxi32 PH7_GenStateListNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot); static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 iFlags, int bHandleClosure, ph7_vm_func **ppFunc); static sxi32 GenStateDefineNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot); PH7_PRIVATE sxi32 PH7_CompileDefine(ph7_gen_state *pGen, sxi32 iFlags); @@ -135,7 +133,6 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen); static sxi32 PH7_CompileIf(ph7_gen_state *pGen); static sxi32 PH7_CompileReturn(ph7_gen_state *pGen); static sxi32 PH7_CompileHalt(ph7_gen_state *pGen); -static sxi32 PH7_CompileStatic(ph7_gen_state *pGen); static sxi32 PH7_CompileVar(ph7_gen_state *pGen); static sxi32 PH7_CompileNamespace(ph7_gen_state *pGen); static sxi32 PH7_CompileUsing(ph7_gen_state *pGen); @@ -143,15 +140,12 @@ static sxi32 PH7_GenStateProcessArgValue(ph7_gen_state *pGen, ph7_vm_func_arg *p static sxi32 PH7_GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen, SyToken *pEnd); static sxi32 PH7_GenStateCompileFuncBody(ph7_gen_state *pGen, ph7_vm_func *pFunc); static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 iFlags, int bHandleClosure, ph7_vm_func **ppFunc); -static sxi32 PH7_CompileFunction(ph7_gen_state *pGen); static sxi32 PH7_GetProtectionLevel(sxi32 nKeyword); static sxi32 PH7_GenStateCompileClassConstant(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass); static sxi32 PH7_GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, sxu32 nType, ph7_class *pClass); static sxi32 PH7_GenStateCompileClassMethod(ph7_gen_state *pGen, sxu32 nType, sxi32 iProtection, sxi32 iFlags, int doBody, ph7_class *pClass); static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen); static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags); -static sxi32 PH7_CompileVirtualClass(ph7_gen_state *pGen); -static sxi32 PH7_CompileFinalClass(ph7_gen_state *pGen); static sxi32 PH7_CompileClass(ph7_gen_state *pGen); static sxi32 PH7_GenStateThrowNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot); static sxi32 PH7_CompileThrow(ph7_gen_state *pGen); diff --git a/include/ph7.h b/include/ph7.h index 213aac6..c27bbc0 100644 --- a/include/ph7.h +++ b/include/ph7.h @@ -646,6 +646,7 @@ PH7_APIEXPORT int ph7_value_is_array(ph7_value *pVal); PH7_APIEXPORT int ph7_value_is_numeric(ph7_value *pVal); PH7_APIEXPORT int ph7_value_is_object(ph7_value *pVal); PH7_APIEXPORT int ph7_value_is_resource(ph7_value *pVal); +PH7_APIEXPORT int ph7_value_is_char(ph7_value *pVal); PH7_APIEXPORT int ph7_value_is_void(ph7_value *pVal); /* Global Library Management Interfaces */ PH7_APIEXPORT int ph7_lib_init(void); diff --git a/include/ph7int.h b/include/ph7int.h index 29adcba..dd666db 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -626,7 +626,7 @@ struct ph7_value { void *pOther; /* Other values (Object, Array, Resource, Namespace, etc.) */ } x; sxi32 iFlags; /* Control flags (see below) */ - sxi32 nType; /* Variable data type */ + sxu32 nType; /* Variable data type */ ph7_vm *pVm; /* Virtual machine that own this instance */ SyBlob sBlob; /* String values */ sxu32 nIdx; /* Index number of this entry in the global object allocator */ @@ -1648,6 +1648,8 @@ PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj); PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj); PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj); PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj); +PH7_PRIVATE sxi32 PH7_MemObjToChar(ph7_value *pObj); +PH7_PRIVATE sxi32 PH7_MemObjToVoid(ph7_value *pObj); PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj); PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj); PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType); diff --git a/sapi/cli/main.c b/sapi/cli/main.c index ba478dd..7804a80 100644 --- a/sapi/cli/main.c +++ b/sapi/cli/main.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) { } else if(c == 'r' || c == 'R') { /* Report run-time errors */ err_report = 1; - } else if(c == 'm' || c == 'M' && SyStrlen(argv[n]) > 2) { + } else if((c == 'm' || c == 'M') && SyStrlen(argv[n]) > 2) { sLimitArg = argv[n] + 2; } else { /* Display a help message and exit */