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
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, [
$3
fi
])
-
+
PSI_TYPE(char, int)
PSI_TYPE(short, int)
PSI_TYPE(int, int)
PSI_TYPE(float)
PSI_TYPE(double)
PSI_TYPE(void *)
-
+
dnl stddef.h
PSI_TYPE(ptrdiff_t, int)
PSI_TYPE(size_t, uint)
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)
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)
#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));
}
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;
}
*C = NULL;
}
}
-
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;
}
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;
}
void PSI_ParserFree(PSI_Parser **P);
#endif
-
'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);}
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);
}
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);
}
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);
}
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);
}
%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);
}