From 0aa69939e1a89ad7647ee853a742b8b7cc37f75f Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 9 Nov 2015 08:34:49 +0100 Subject: [PATCH] flush --- config.m4 | 27 ++++++++++++++------------- src/context.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/parser.h | 9 ++++----- src/parser.re | 20 ++++++++------------ src/parser_proc.y | 18 +++++++++--------- 5 files changed, 77 insertions(+), 40 deletions(-) diff --git a/config.m4 b/config.m4 index f6f43ce..f9d9318 100644 --- a/config.m4 +++ b/config.m4 @@ -79,19 +79,19 @@ if test "$PHP_PSI" != "no"; then else AC_MSG_WARN([Could not find libjit, please provide the base install path]) fi - + PHP_SUBST(PSI_SHARED_LIBADD) - + PSI_TYPES="" AC_DEFUN(PSI_TYPE, [ AC_CHECK_SIZEOF($1) AC_CHECK_ALIGNOF($1) if test "$2" && test "$ac_cv_sizeof_[]$1" -gt 0; then psi_type_bits=`expr ${AS_TR_SH(ac_cv_sizeof_[]$1)} \* 8` - PSI_TYPES="{\""$2[]${psi_type_bits}[]_t"\", \""$1"\"}, $PSI_TYPES" - fi + PSI_TYPES="{PSI_T_[]translit($2,a-z,A-Z)[]${psi_type_bits}, \""$2[]${psi_type_bits}[]_t"\", \""$1"\"}, $PSI_TYPES" + fi ]) - + PSI_CONSTS="" AC_DEFUN(PSI_COMPUTE_STR, [ var=$1 @@ -109,22 +109,23 @@ if test "$PHP_PSI" != "no"; then AC_DEFUN(PSI_CONST, [ AC_MSG_CHECKING(value of $1) case $2 in - str*) + str*|quoted_str*) PSI_COMPUTE_STR(psi_const_val, $1, AC_INCLUDES_DEFAULT($3)) if test "$psi_const_val"; then - PSI_CONSTS="{\"$1\", IS_STRING, $psi_const_val, 0}, $PSI_CONSTS" + PSI_CONSTS="{PSI_T_STRING, \"string\", \"$1\", $psi_const_val, PSI_T_QUOTED_STRING}, $PSI_CONSTS" fi ;; *) AC_COMPUTE_INT(psi_const_val, $1, AC_INCLUDES_DEFAULT($3)) if test "$psi_const_val"; then - PSI_CONSTS="{\"$1\", IS_LONG, NULL, $psi_const_val}, $PSI_CONSTS" + PSI_CONSTS="{PSI_T_INT, \"int\", \"$1\", \"$psi_const_val\", PSI_T_NUMBER}, $PSI_CONSTS" fi ;; esac + AC_MSG_RESULT($psi_const_val) ]) - + AC_DEFUN([AX_CHECK_SIGN], [ typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"` AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [ @@ -139,7 +140,7 @@ if test "$PHP_PSI" != "no"; then $3 fi ]) - + PSI_TYPE(char, int) PSI_TYPE(short, int) PSI_TYPE(int, int) @@ -147,7 +148,7 @@ if test "$PHP_PSI" != "no"; then PSI_TYPE(float) PSI_TYPE(double) PSI_TYPE(void *) - + dnl stddef.h PSI_TYPE(ptrdiff_t, int) PSI_TYPE(size_t, uint) @@ -155,7 +156,7 @@ if test "$PHP_PSI" != "no"; then AX_CHECK_SIGN(wchar_t, psi_wchar_t=int, psi_wchar_t=uint) PSI_TYPE(wchar_t, $psi_wchar_t) ]) - + dnl stdio.h PSI_TYPE(fpos_t, int) PSI_CONST(BUFSIZ, int) @@ -203,7 +204,7 @@ if test "$PHP_PSI" != "no"; then AC_DEFINE_UNQUOTED(PHP_PSI_TYPES, $PSI_TYPES, Predefined types) AC_DEFINE_UNQUOTED(PHP_PSI_CONSTS, $PSI_CONSTS, Predefined constants) - + PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi) PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi) diff --git a/src/context.c b/src/context.c index 4939130..f31c1e1 100644 --- a/src/context.c +++ b/src/context.c @@ -9,8 +9,34 @@ #include "parser.h" #include "validator.h" +#define psi_predef_count(s) (sizeof(psi_predef_ ##s## s)/sizeof(psi_predef ##s)) +typedef struct psi_predef_type { + token_t type_tag; + const char *type_name; + const char *alias; +} psi_predef_type; +#define psi_predef_type_count() psi_predef_count(type) +static const psi_predef_types[] = { + PHP_PSI_TYPES +}; + +typedef struct psi_predef_const { + token_t type_tag; + const char *type_name; + const char *name; + const char *val_text; + token_t val_type_tag; +} psi_predef_const; +#define psi_predef_const_count() psi_predef_count(const) +static const psi_predef_consts[] = { + PHP_PSI_CONSTS +}; + PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErrorFunc error) { + size_t i; + PSI_Data data; + if (!C) { C = malloc(sizeof(*C)); } @@ -20,6 +46,22 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr C->ops = ops; ops->init(C); + memset(&data, 0, sizeof(data)); + for (i = 0; i < psi_predef_type_count(); ++i) { + psi_predef_type *pre = &psi_predef_types[i]; + decl_type *type = init_decl_type(pre->type_tag, pre->type_name); + decl_typedef *def = init_decl_typedef(pre->alias, type); + + data.defs = add_decl_typedef(data.defs, def); + } + for (i = 0; i < psi_predef_const_count(); ++i) { + psi_predef_const *pre = psi_predef_const[i]; + impl_def_val *val = init_impl_def_val(pre->val_type_tag, pre->val_text); + const_type *type = init_const_type(pre->type_tag, pre->type_name); + constant *constant = init_constant(type, pre->name, val); + + data.consts = add_constant(data.consts, constant); + } return C; } @@ -155,4 +197,3 @@ void PSI_ContextFree(PSI_Context **C) *C = NULL; } } - diff --git a/src/parser.h b/src/parser.h index cd1e0d4..9ec15b9 100644 --- a/src/parser.h +++ b/src/parser.h @@ -367,7 +367,7 @@ typedef struct impl_var { static inline impl_var *init_impl_var(char *name, int is_reference) { impl_var *var = calloc(1, sizeof(*var)); - var->name = (char *) strdup((const char *) name); + var->name = strdup(name); var->reference = is_reference; return var; } @@ -382,10 +382,10 @@ typedef struct impl_def_val { char *text; } impl_def_val; -static inline impl_def_val *init_impl_def_val(PSI_Token *T) { +static inline impl_def_val *init_impl_def_val(token_t t, char *text) { impl_def_val *def = calloc(1, sizeof(*def)); - def->type = T->type; - def->text = strdup(T->text); + def->type = t; + def->text = strdup(text); return def; } @@ -950,4 +950,3 @@ void PSI_ParserDtor(PSI_Parser *P); void PSI_ParserFree(PSI_Parser **P); #endif - diff --git a/src/parser.re b/src/parser.re index 58deda2..0782b8f 100644 --- a/src/parser.re +++ b/src/parser.re @@ -201,21 +201,17 @@ token_t PSI_ParserScan(PSI_Parser *P) 'MIXED' {RETURN(PSI_T_MIXED);} 'VOID' {RETURN(PSI_T_VOID);} 'BOOL' {RETURN(PSI_T_BOOL);} - 'CHAR' {RETURN(PSI_T_CHAR);} - 'SHORT' {RETURN(PSI_T_SHORT);} 'INT' {RETURN(PSI_T_INT);} - 'LONG' {RETURN(PSI_T_LONG);} 'FLOAT' {RETURN(PSI_T_FLOAT);} 'DOUBLE' {RETURN(PSI_T_DOUBLE);} - 'SIZE_T' {RETURN(PSI_T_SIZE_T);} - 'SINT8' {RETURN(PSI_T_SINT8);} - 'UINT8' {RETURN(PSI_T_UINT8);} - 'SINT16' {RETURN(PSI_T_SINT16);} - 'UINT16' {RETURN(PSI_T_UINT16);} - 'SINT32' {RETURN(PSI_T_SINT32);} - 'UINT32' {RETURN(PSI_T_UINT32);} - 'SINT64' {RETURN(PSI_T_SINT64);} - 'UINT64' {RETURN(PSI_T_UINT64);} + 'INT8_T' {RETURN(PSI_T_SINT8);} + 'UINT8_T' {RETURN(PSI_T_UINT8);} + 'INT16_T' {RETURN(PSI_T_SINT16);} + 'UINT16_T' {RETURN(PSI_T_UINT16);} + 'INT32_T' {RETURN(PSI_T_SINT32);} + 'UINT32_T' {RETURN(PSI_T_UINT32);} + 'INT64_T' {RETURN(PSI_T_SINT64);} + 'UINT64_T' {RETURN(PSI_T_UINT64);} 'STRING' {RETURN(PSI_T_STRING);} 'ARRAY' {RETURN(PSI_T_ARRAY);} 'FUNCTION' {RETURN(PSI_T_FUNCTION);} diff --git a/src/parser_proc.y b/src/parser_proc.y index 62e8011..b606cf0 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -207,7 +207,7 @@ decl_type(type_) ::= SIZE_T(T). { type_ = init_decl_type(T->type, T->text); free(T); } -decl_type(type_) ::= SINT8(T). { +decl_type(type_) ::= INT8(T). { type_ = init_decl_type(T->type, T->text); free(T); } @@ -215,7 +215,7 @@ decl_type(type_) ::= UINT8(T). { type_ = init_decl_type(T->type, T->text); free(T); } -decl_type(type_) ::= SINT16(T). { +decl_type(type_) ::= INT16(T). { type_ = init_decl_type(T->type, T->text); free(T); } @@ -223,7 +223,7 @@ decl_type(type_) ::= UINT16(T). { type_ = init_decl_type(T->type, T->text); free(T); } -decl_type(type_) ::= SINT32(T). { +decl_type(type_) ::= INT32(T). { type_ = init_decl_type(T->type, T->text); free(T); } @@ -231,7 +231,7 @@ decl_type(type_) ::= UINT32(T). { type_ = init_decl_type(T->type, T->text); free(T); } -decl_type(type_) ::= SINT64(T). { +decl_type(type_) ::= INT64(T). { type_ = init_decl_type(T->type, T->text); free(T); } @@ -269,23 +269,23 @@ impl_func(func) ::= FUNCTION REFERENCE NSNAME(NAME) impl_args(args) COLON impl_t %type impl_def_val {impl_def_val*} %destructor impl_def_val {free_impl_def_val($$);} impl_def_val(def) ::= NULL(T). { - def = init_impl_def_val(T); + def = init_impl_def_val(T->type, T->text); free(T); } impl_def_val(def) ::= NUMBER(T). { - def = init_impl_def_val(T); + def = init_impl_def_val(T->type, T->text); free(T); } impl_def_val(def) ::= TRUE(T). { - def = init_impl_def_val(T); + def = init_impl_def_val(T->type, T->text); free(T); } impl_def_val(def) ::= FALSE(T). { - def = init_impl_def_val(T); + def = init_impl_def_val(T->type, T->text); free(T); } impl_def_val(def) ::= QUOTED_STRING(T). { - def = init_impl_def_val(T); + def = init_impl_def_val(T->type, T->text); free(T); } -- 2.30.2