projects
/
m6w6
/
ext-psi
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
travis: update
[m6w6/ext-psi]
/
src
/
types
/
number.c
diff --git
a/src/types/number.c
b/src/types/number.c
index 840eb036ba29de8a89a9cb967f9da72ab502a028..e6edb40b342960f0177658c072accbdd90f20971 100644
(file)
--- a/
src/types/number.c
+++ b/
src/types/number.c
@@
-23,7
+23,11
@@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
-#include "php_psi_stdinc.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
#include <assert.h>
#include <math.h>
#include <assert.h>
#include <math.h>
@@
-32,6
+36,7
@@
#include "calc.h"
#include "call.h"
#include "parser.h"
#include "calc.h"
#include "call.h"
#include "parser.h"
+#include "debug.h"
#include "Zend/zend_constants.h"
#include "Zend/zend_operators.h"
#include "Zend/zend_constants.h"
#include "Zend/zend_operators.h"
@@
-292,41
+297,46
@@
struct psi_plist *psi_number_tokens(struct psi_number *exp,
return list;
}
return list;
}
-void psi_number_dump(
int fd
, struct psi_number *exp)
+void psi_number_dump(
struct psi_dump *dump
, struct psi_number *exp)
{
switch (exp->type) {
case PSI_T_DEFINED:
{
switch (exp->type) {
case PSI_T_DEFINED:
- CASE_IMPLVAL_NUM_
PRINTF(dprintf, fd, exp->data.ival)
+ CASE_IMPLVAL_NUM_
DUMP(dump, exp->data.ival, true);
case PSI_T_NULL:
case PSI_T_NULL:
-
dprintf(fd
, "NULL");
+
PSI_DUMP(dump
, "NULL");
break;
case PSI_T_NUMBER:
case PSI_T_NSNAME:
break;
case PSI_T_NUMBER:
case PSI_T_NSNAME:
- case PSI_T_DEFINE:
case PSI_T_QUOTED_CHAR:
case PSI_T_CPP_HEADER:
case PSI_T_QUOTED_CHAR:
case PSI_T_CPP_HEADER:
- dprintf(fd, "%s", exp->data.numb->val);
+ PSI_DUMP(dump, "%s", exp->data.numb->val);
+ break;
+ case PSI_T_DEFINE:
+ PSI_DUMP(dump, "%s /* DEFINE */", exp->data.numb->val);
break;
case PSI_T_FUNCTION:
break;
case PSI_T_FUNCTION:
- psi_cpp_macro_call_dump(
fd
, exp->data.call);
+ psi_cpp_macro_call_dump(
dump
, exp->data.call);
break;
case PSI_T_CONST:
break;
case PSI_T_CONST:
-
dprintf(fd
, "%s", exp->data.cnst->name->val);
+
PSI_DUMP(dump
, "%s", exp->data.cnst->name->val);
break;
case PSI_T_ENUM:
break;
case PSI_T_ENUM:
-
dprintf(fd, "%s
", exp->data.enm->name->val);
+
PSI_DUMP(dump, "%s /* ENUM */
", exp->data.enm->name->val);
break;
case PSI_T_NAME:
break;
case PSI_T_NAME:
- psi_decl_var_dump(
fd
, exp->data.dvar);
+ psi_decl_var_dump(
dump
, exp->data.dvar);
break;
case PSI_T_SIZEOF:
break;
case PSI_T_SIZEOF:
-
dprintf(fd
, "sizeof(");
- psi_decl_type_dump(
fd
, exp->data.dtyp, 0);
-
dprintf(fd
, ")");
+
PSI_DUMP(dump
, "sizeof(");
+ psi_decl_type_dump(
dump
, exp->data.dtyp, 0);
+
PSI_DUMP(dump
, ")");
break;
default:
assert(0);
}
break;
default:
assert(0);
}
+#if 0
+ PSI_DUMP(dump, "\t/* number.type=%d */ ", exp->type);
+#endif
}
static inline bool psi_number_validate_enum(struct psi_data *data,
}
static inline bool psi_number_validate_enum(struct psi_data *data,
@@
-493,7
+503,6
@@
static inline bool psi_number_validate_number(struct psi_data *data, struct psi_
case PSI_NUMBER_FLT:
switch (exp->flags & 0x0ff00) {
case PSI_NUMBER_F:
case PSI_NUMBER_FLT:
switch (exp->flags & 0x0ff00) {
case PSI_NUMBER_F:
- case PSI_NUMBER_DF:
tmp.fval = strtof(exp->data.numb->val, NULL);
zend_string_release(exp->data.numb);
exp->type = PSI_T_FLOAT;
tmp.fval = strtof(exp->data.numb->val, NULL);
zend_string_release(exp->data.numb);
exp->type = PSI_T_FLOAT;
@@
-510,6
+519,7
@@
static inline bool psi_number_validate_number(struct psi_data *data, struct psi_
#endif
case PSI_NUMBER_DD:
default:
#endif
case PSI_NUMBER_DD:
default:
+ case PSI_NUMBER_DF:
tmp.dval = strtod(exp->data.numb->val, NULL);
zend_string_release(exp->data.numb);
exp->type = PSI_T_DOUBLE;
tmp.dval = strtod(exp->data.numb->val, NULL);
zend_string_release(exp->data.numb);
exp->type = PSI_T_DOUBLE;
@@
-571,7
+581,7
@@
static inline bool psi_number_validate_number(struct psi_data *data, struct psi_
return true;
}
}
return true;
}
}
- break;
+ /* no break */
default:
zend_string_release(exp->data.numb);
exp->type = PSI_T_INT64;
default:
zend_string_release(exp->data.numb);
exp->type = PSI_T_INT64;
@@
-592,6
+602,7
@@
bool psi_number_validate(struct psi_data *data, struct psi_number *exp,
size_t i = 0;
struct psi_const *cnst;
struct psi_decl_enum *enm;
size_t i = 0;
struct psi_const *cnst;
struct psi_decl_enum *enm;
+ struct psi_decl_extvar *evar;
switch (exp->type) {
case PSI_T_NULL:
switch (exp->type) {
case PSI_T_NULL:
@@
-606,6
+617,10
@@
bool psi_number_validate(struct psi_data *data, struct psi_number *exp,
case PSI_T_UINT32:
case PSI_T_INT64:
case PSI_T_UINT64:
case PSI_T_UINT32:
case PSI_T_INT64:
case PSI_T_UINT64:
+#if HAVE_INT128
+ case PSI_T_INT128:
+ case PSI_T_UINT128:
+#endif
case PSI_T_FLOAT:
case PSI_T_DOUBLE:
#if HAVE_LONG_DOUBLE
case PSI_T_FLOAT:
case PSI_T_DOUBLE:
#if HAVE_LONG_DOUBLE
@@
-616,10
+631,10
@@
bool psi_number_validate(struct psi_data *data, struct psi_number *exp,
return true;
case PSI_T_NAME:
return true;
case PSI_T_NAME:
- if (scope && scope->cpp && zend_hash_exists(&scope->cpp->defs, exp->data.dvar->name)) {
-
exp->type = PSI_T_DEFINE;
-
goto define;
- }
+
//
if (scope && scope->cpp && zend_hash_exists(&scope->cpp->defs, exp->data.dvar->name)) {
+
//
exp->type = PSI_T_DEFINE;
+
//
goto define;
+
//
}
if (scope && scope->current_enum && psi_number_validate_enum(data, exp, scope)) {
return true;
}
if (scope && scope->current_enum && psi_number_validate_enum(data, exp, scope)) {
return true;
}
@@
-633,13
+648,21
@@
bool psi_number_validate(struct psi_data *data, struct psi_number *exp,
if (exp->data.dvar->arg) {
return true;
}
if (exp->data.dvar->arg) {
return true;
}
+ for (i = 0; psi_plist_get(data->vars, i, &evar); ++i) {
+ if (zend_string_equals(exp->data.dvar->name, evar->arg->var->name)) {
+ exp->data.dvar->arg = evar->arg;
+ return true;
+ }
+ }
if (psi_decl_var_validate(data, exp->data.dvar, scope)) {
return true;
if (psi_decl_var_validate(data, exp->data.dvar, scope)) {
return true;
+ } else {
+ data->error(data, exp->token, PSI_WARNING,
+ "Unknown variable '%s' in numeric expression",
+ exp->data.dvar->name->val);
+ return false;
}
}
- data->error(data, exp->token, PSI_WARNING,
- "Unknown variable '%s' in numeric expression",
- exp->data.dvar->name->val);
- return false;
+ break;
case PSI_T_FUNCTION:
if (scope && scope->cpp && zend_hash_exists(&scope->cpp->defs, exp->data.call->name)) {
case PSI_T_FUNCTION:
if (scope && scope->cpp && zend_hash_exists(&scope->cpp->defs, exp->data.call->name)) {
@@
-666,7
+689,6
@@
bool psi_number_validate(struct psi_data *data, struct psi_number *exp,
case PSI_T_DEFINE:
if (scope && scope->cpp && zend_hash_exists(&scope->cpp->defs, exp->data.numb)) {
case PSI_T_DEFINE:
if (scope && scope->cpp && zend_hash_exists(&scope->cpp->defs, exp->data.numb)) {
- define: ;
if (!scope->macro || !zend_string_equals(scope->macro->token->text, exp->data.numb)) {
return true;
}
if (!scope->macro || !zend_string_equals(scope->macro->token->text, exp->data.numb)) {
return true;
}
@@
-679,6
+701,7
@@
bool psi_number_validate(struct psi_data *data, struct psi_number *exp,
return true;
}
}
return true;
}
}
+ /* undefined */
return false;
case PSI_T_SIZEOF:
return false;
case PSI_T_SIZEOF:
@@
-792,10
+815,13
@@
static inline token_t psi_number_eval_decl_var(struct psi_number *exp,
var = exp->data.dvar;
real = psi_decl_type_get_real(var->arg->type);
size = psi_decl_arg_get_size(var->arg);
var = exp->data.dvar;
real = psi_decl_type_get_real(var->arg->type);
size = psi_decl_arg_get_size(var->arg);
- sym = psi_call_frame_fetch_symbol(frame, var);
- ref = deref_impl_val(sym->ptr, var);
- memcpy(res, ref, size);
+ if (frame) {
+ sym = psi_call_frame_fetch_symbol(frame, var);
+ ref = deref_impl_val(sym->ptr, var);
+
+ memcpy(res, ref, size);
+ }
if (var->arg->var->pointer_level > var->pointer_level) {
switch (SIZEOF_VOID_P) {
if (var->arg->var->pointer_level > var->pointer_level) {
switch (SIZEOF_VOID_P) {
@@
-873,7
+899,16
@@
token_t psi_number_eval(struct psi_number *exp, impl_val *res,
*res = exp->data.ival;
if (frame) PSI_DEBUG_PRINT(frame->context, " %" PRIu64, res->u64);
return PSI_T_UINT64;
*res = exp->data.ival;
if (frame) PSI_DEBUG_PRINT(frame->context, " %" PRIu64, res->u64);
return PSI_T_UINT64;
-
+#if HAVE_INT128
+ case PSI_T_INT128:
+ *res = exp->data.ival;
+ //if (frame) PSI_DEBUG_PRINT(frame->context, " %" PRIi128, res->i128);
+ return PSI_T_INT128;
+ case PSI_T_UINT128:
+ *res = exp->data.ival;
+ //if (frame) PSI_DEBUG_PRINT(frame->context, " %" PRIu128, res->u128);
+ return PSI_T_UINT128;
+#endif
case PSI_T_FLOAT:
*res = exp->data.ival;
if (frame) PSI_DEBUG_PRINT(frame->context, " %" PRIfval, res->fval);
case PSI_T_FLOAT:
*res = exp->data.ival;
if (frame) PSI_DEBUG_PRINT(frame->context, " %" PRIfval, res->fval);