%code {
#include <assert.h>
#include <stdarg.h>
-#include <fnmatch.h>
-
-#include "php_psi.h"
#include "plist.h"
#include "parser.h"
}
P->enums = psi_plist_add(P->enums, &e);
}
+static inline void psi_parser_proc_deanon_typedef(struct psi_decl_arg *def)
+{
+ switch (def->type->type) {
+ case PSI_T_STRUCT:
+ if (!psi_decl_type_is_anon(def->type->name, "struct")) {
+ return;
+ }
+ break;
+ case PSI_T_UNION:
+ if (!psi_decl_type_is_anon(def->type->name, "union")) {
+ return;
+ }
+ break;
+ case PSI_T_ENUM:
+ if (!psi_decl_type_is_anon(def->type->name, "enum")) {
+ return;
+ }
+ break;
+ default:
+ return;
+ }
+ free(def->type->name);
+ def->type->name = strdup(def->var->name);
+}
static inline void psi_parser_proc_add_typedef(struct psi_parser *P, struct psi_decl_arg *def)
{
assert(def);
if (!P->types) {
P->types = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
}
+ //psi_parser_proc_deanon_typedef(def);
P->types = psi_plist_add(P->types, &def);
}
static inline void psi_parser_proc_add_const(struct psi_parser *P, struct psi_const *cnst) {
}
static inline void psi_parser_proc_add_decl(struct psi_parser *P, struct psi_decl *decl) {
- char *blacklisted;
- size_t i = 0;
-
assert(decl);
-
- while (psi_plist_get(PSI_G(blacklist).decls, i++, &blacklisted)) {
- if (!fnmatch(blacklisted, decl->func->var->name, 0)) {
- psi_decl_free(&decl);
- return;
- }
+
+ if (psi_decl_is_blacklisted(decl->func->var->name)) {
+ psi_decl_free(&decl);
+ return;
}
if (!P->decls) {
}
P->decls = psi_plist_add(P->decls, &decl);
}
+static inline void psi_parser_proc_add_decl_extvars(struct psi_parser *P, struct psi_plist *list) {
+ assert(list);
+ if (!P->vars) {
+ P->vars = psi_plist_init((psi_plist_dtor) psi_decl_extvar_free);
+ }
+ P->vars = psi_plist_add_r(P->vars, psi_plist_count(list), psi_plist_eles(list));
+ free(list);
+}
static inline void psi_parser_proc_add_impl(struct psi_parser *P, struct psi_impl *impl) {
assert(impl);
if (!P->impls) {
#include "plist.h"
#include "types/layout.h"
+#define yytokentype psi_token_type
+
+#define PSI_T_CAST PSI_T_EQUALS
+#define PSI_T_POINTER PSI_T_ASTERISK
+
struct psi_parser;
}
%token <struct psi_token *> CALLABLE
%token <struct psi_token *> VOID
%token <struct psi_token *> ZVAL
-%token <struct psi_token *> INT8
-%token <struct psi_token *> UINT8
-%token <struct psi_token *> INT16
-%token <struct psi_token *> UINT16
-%token <struct psi_token *> INT32
-%token <struct psi_token *> UINT32
-%token <struct psi_token *> INT64
-%token <struct psi_token *> UINT64
%token <struct psi_token *> NULL
%token <struct psi_token *> TRUE
%token <struct psi_token *> FALSE
%token <struct psi_token *> TEMP
%token <struct psi_token *> FREE
%token <struct psi_token *> RETURN
+%token <struct psi_token *> AS
%token <struct psi_token *> PRE_ASSERT
%token <struct psi_token *> POST_ASSERT
%token <struct psi_token *> BOOLVAL
%token <struct psi_token *> CPP_RESTRICT
%token <struct psi_token *> CPP_ASM
+/* virtual tokens */
+%token <struct psi_token *> BSLASH
+%token <struct psi_token *> LONG_DOUBLE
+%token <struct psi_token *> INT8
+%token <struct psi_token *> UINT8
+%token <struct psi_token *> INT16
+%token <struct psi_token *> UINT16
+%token <struct psi_token *> INT32
+%token <struct psi_token *> UINT32
+%token <struct psi_token *> INT64
+%token <struct psi_token *> UINT64
+%token <struct psi_token *> INT128
+%token <struct psi_token *> UINT128
+
+
%precedence IIF COLON
%precedence OR
%precedence AND
%type <struct psi_token *> lib optional_name enum_name struct_name union_name
%destructor {psi_token_free(&$$);} lib optional_name enum_name struct_name union_name
-%type <struct psi_token *> cpp_message_token cpp_include_token cpp_header_token cpp_no_arg_token cpp_name_arg_token cpp_exp_arg_token cpp_special_name_token
-%destructor {} cpp_message_token cpp_include_token cpp_header_token cpp_no_arg_token cpp_name_arg_token cpp_exp_arg_token cpp_special_name_token
+%type <struct psi_token *> cpp_message_token cpp_include_token cpp_header_token cpp_no_arg_token cpp_name_arg_token cpp_exp_arg_token
+%destructor {} cpp_message_token cpp_include_token cpp_header_token cpp_no_arg_token cpp_name_arg_token cpp_exp_arg_token
%type <struct psi_token *> name_token any_noeol_token binary_op_token unary_op_token
%destructor {} name_token any_noeol_token binary_op_token unary_op_token
%type <struct psi_num_exp *> cpp_macro_exp
%destructor {psi_num_exp_free(&$$);} cpp_macro_exp
-%type <struct psi_token *> constant_type_token impl_def_val_token
-%destructor {} constant_type_token impl_def_val_token
+%type <struct psi_token *> impl_def_val_token
+%destructor {} impl_def_val_token
%type <struct psi_const *> constant
%destructor {psi_const_free(&$$);} constant
-%type <struct psi_const_type *> constant_type
-%destructor {psi_const_type_free(&$$);} constant_type
%type <struct psi_impl_def_val *> impl_def_val
%destructor {psi_impl_def_val_free(&$$);} impl_def_val
%type <struct psi_token *> decl_real_type decl_int_type decl_type_simple
%destructor {psi_token_free(&$$);} decl_real_type decl_int_type decl_type_simple
-%type <struct psi_token *> decl_stdint_type
-%destructor {} decl_stdint_type
+%type <struct psi_token *> decl_asm quoted_strings
+%destructor {psi_token_free(&$$);} decl_asm quoted_strings
%type <struct psi_decl_type *> decl_type qualified_decl_type decl_type_complex
%destructor {psi_decl_type_free(&$$);} decl_type qualified_decl_type decl_type_complex
-%type <struct psi_decl *> decl_stmt decl decl_body decl_func_body decl_functor_body
-%destructor {psi_decl_free(&$$);} decl_stmt decl decl_body decl_func_body decl_functor_body
-%type <struct psi_decl_arg *> decl_typedef decl_func decl_functor decl_arg decl_anon_arg typedef typedef_decl typedef_anon typedef_anon_decl
-%destructor {psi_decl_arg_free(&$$);} decl_typedef decl_func decl_functor decl_arg decl_anon_arg typedef typedef_decl typedef_anon typedef_anon_decl
+%type <struct psi_decl *> decl_stmt decl decl_body decl_func_body decl_functor_body decl_anon_functor_body ignored_decl
+%destructor {psi_decl_free(&$$);} decl_stmt decl decl_body decl_func_body decl_functor_body decl_anon_functor_body ignored_decl
+%type <struct psi_decl_arg *> decl_typedef decl_func decl_functor decl_anon_functor decl_arg decl_anon_arg typedef typedef_decl typedef_anon typedef_anon_decl
+%destructor {psi_decl_arg_free(&$$);} decl_typedef decl_func decl_functor decl_anon_functor decl_arg decl_anon_arg typedef typedef_decl typedef_anon typedef_anon_decl
%type <struct psi_decl_var *> decl_var
%destructor {psi_decl_var_free(&$$);} decl_var
%type <struct psi_decl_struct *> decl_struct
%destructor {psi_decl_enum_free(&$$);} decl_enum
%type <struct psi_decl_enum_item *> decl_enum_item
%destructor {psi_decl_enum_item_free(&$$);} decl_enum_item
-%type <struct psi_plist *> decl_args decl_struct_args struct_args_block struct_args struct_arg_var_list decl_enum_items decl_vars decl_vars_with_layout
-%destructor {psi_plist_free($$);} decl_args decl_struct_args struct_args_block struct_args struct_arg_var_list decl_enum_items decl_vars decl_vars_with_layout
+%type <struct psi_plist *> decl_args decl_arg_list decl_struct_args struct_args_block struct_args struct_arg_var_list decl_enum_items decl_vars decl_vars_with_layout call_decl_vars decl_extvar_stmt decl_extvar_list
+%destructor {psi_plist_free($$);} decl_args decl_arg_list decl_struct_args struct_args_block struct_args struct_arg_var_list decl_enum_items decl_vars decl_vars_with_layout call_decl_vars decl_extvar_stmt decl_extvar_list
%type <struct psi_layout> align_and_size
%destructor {} align_and_size
%destructor {psi_impl_func_free(&$$);} impl_func
%type <struct psi_impl_arg *> impl_arg
%destructor {psi_impl_arg_free(&$$);} impl_arg
-%type <struct psi_impl_type *> impl_type
-%destructor {psi_impl_type_free(&$$);} impl_type
+%type <struct psi_impl_type *> impl_type impl_type_restricted
+%destructor {psi_impl_type_free(&$$);} impl_type impl_type_restricted
%type <struct psi_impl_var *> impl_var
%destructor {psi_impl_var_free(&$$);} impl_var
%destructor {psi_assert_stmt_free(&$$);} assert_stmt
%type <struct psi_return_stmt *> return_stmt
%destructor {psi_return_stmt_free(&$$);} return_stmt
+%type <struct psi_return_exp *> return_exp
+%destructor {psi_return_exp_free(&$$);} return_exp
%type <struct psi_free_stmt *> free_stmt
%destructor {psi_free_stmt_free(&$$);} free_stmt
%type <struct psi_free_exp *> free_exp
%type <struct psi_token **> impl_stmt
%destructor {psi_impl_stmt_free(&$$);} impl_stmt
-%type <struct psi_token *> impl_type_token callback_rval let_func_token set_func_token assert_stmt_token
-%destructor {psi_token_free(&$$);} impl_type_token callback_rval let_func_token set_func_token assert_stmt_token
+%type <struct psi_token *> impl_type_token impl_type_restricted_token impl_type_extended_token callback_rval let_func_token set_func_token assert_stmt_token
+%destructor {psi_token_free(&$$);} impl_type_token impl_type_restricted_token impl_type_extended_token callback_rval let_func_token set_func_token assert_stmt_token
%type <struct psi_plist *> impl_args impl_stmts let_exps let_func_exps callback_arg_list callback_args set_exps set_func_exps free_exps
%destructor {psi_plist_free($$);} impl_args impl_stmts let_exps let_func_exps callback_arg_list callback_args set_exps set_func_exps free_exps
binary_op_token: PIPE | CARET | AMPERSAND | LSHIFT | RSHIFT | PLUS | MINUS | ASTERISK | SLASH | MODULO | RCHEVR | LCHEVR | CMP_GE | CMP_LE | OR | AND | CMP_EQ | CMP_NE ;
unary_op_token: TILDE | NOT | PLUS | MINUS ;
-name_token: NAME | FUNCTION | TEMP | FREE | SET | LET | CALLOC | CALLBACK | LIB | BOOL | STRING | ERROR | WARNING | LINE | PRAGMA_ONCE | PRAGMA | let_func_token | set_func_token;
-any_noeol_token: BOOL | CHAR | SHORT | INT | SIGNED | UNSIGNED | LONG | FLOAT | DOUBLE | STRING | MIXED | ARRAY | OBJECT | CALLABLE | VOID | ZVAL | INT8 | UINT8 | INT16 | UINT16 | INT32 | UINT32 | INT64 | UINT64 | NULL | TRUE | FALSE | NAME | NSNAME | DOLLAR_NAME | NUMBER | QUOTED_STRING | QUOTED_CHAR | EOF | EOS | LPAREN | RPAREN | COMMA | COLON | LBRACE | RBRACE | LBRACKET | RBRACKET | EQUALS | HASH | PIPE | CARET | AMPERSAND | LSHIFT | RSHIFT | PLUS | MINUS | ASTERISK | SLASH | MODULO | LCHEVR | RCHEVR | CMP_GE | CMP_LE | OR | AND | CMP_EQ | CMP_NE | TILDE | NOT | PERIOD | BACKSLASH | ELLIPSIS | ERROR | WARNING | LINE | PRAGMA | PRAGMA_ONCE | IIF | IF | IFDEF | IFNDEF | ELSE | ELIF | ENDIF | DEFINE | DEFINED | UNDEF | INCLUDE | TYPEDEF | STRUCT | UNION | ENUM | CONST | LIB | STATIC | CALLBACK | FUNCTION | LET | SET | TEMP | FREE | RETURN | PRE_ASSERT | POST_ASSERT | BOOLVAL | INTVAL | STRVAL | PATHVAL | STRLEN | FLOATVAL | ARRVAL | OBJVAL | COUNT | CALLOC | TO_BOOL | TO_INT | TO_STRING | TO_FLOAT | TO_ARRAY | TO_OBJECT | COMMENT | CPP_HEADER | CPP_PASTE | CPP_INLINE | CPP_RESTRICT | CPP_EXTENSION | CPP_ASM | SIZEOF | VOLATILE;
-any_nobrace_token: BOOL | CHAR | SHORT | INT | SIGNED | UNSIGNED | LONG | FLOAT | DOUBLE | STRING | MIXED | ARRAY | OBJECT | CALLABLE | VOID | ZVAL | INT8 | UINT8 | INT16 | UINT16 | INT32 | UINT32 | INT64 | UINT64 | NULL | TRUE | FALSE | NAME | NSNAME | DOLLAR_NAME | NUMBER | QUOTED_STRING | QUOTED_CHAR | EOF | EOS | LPAREN | RPAREN | COMMA | COLON | LBRACKET | RBRACKET | EQUALS | HASH | PIPE | CARET | AMPERSAND | LSHIFT | RSHIFT | PLUS | MINUS | ASTERISK | SLASH | MODULO | LCHEVR | RCHEVR | CMP_GE | CMP_LE | OR | AND | CMP_EQ | CMP_NE | TILDE | NOT | PERIOD | BACKSLASH | ELLIPSIS | ERROR | WARNING | LINE | PRAGMA | PRAGMA_ONCE | IIF | IF | IFDEF | IFNDEF | ELSE | ELIF | ENDIF | DEFINE | DEFINED | UNDEF | INCLUDE | TYPEDEF | STRUCT | UNION | ENUM | CONST | LIB | STATIC | CALLBACK | FUNCTION | LET | SET | TEMP | FREE | RETURN | PRE_ASSERT | POST_ASSERT | BOOLVAL | INTVAL | STRVAL | PATHVAL | STRLEN | FLOATVAL | ARRVAL | OBJVAL | COUNT | CALLOC | TO_BOOL | TO_INT | TO_STRING | TO_FLOAT | TO_ARRAY | TO_OBJECT | COMMENT | CPP_HEADER | CPP_PASTE | CPP_INLINE | CPP_RESTRICT | CPP_EXTENSION | CPP_ASM | SIZEOF | VOLATILE;
+name_token: NAME | FUNCTION | TEMP | FREE | SET | LET | CALLOC | CALLBACK | LIB | BOOL | STRING | ERROR | WARNING | LINE | PRAGMA_ONCE | PRAGMA | AS | let_func_token | set_func_token;
+any_noeol_token: BOOL | CHAR | SHORT | INT | SIGNED | UNSIGNED | LONG | FLOAT | DOUBLE | STRING | MIXED | ARRAY | OBJECT | CALLABLE | VOID | ZVAL | NULL | TRUE | FALSE | NAME | NSNAME | DOLLAR_NAME | NUMBER | QUOTED_STRING | QUOTED_CHAR | EOF | EOS | LPAREN | RPAREN | COMMA | COLON | LBRACE | RBRACE | LBRACKET | RBRACKET | EQUALS | HASH | PIPE | CARET | AMPERSAND | LSHIFT | RSHIFT | PLUS | MINUS | ASTERISK | SLASH | MODULO | LCHEVR | RCHEVR | CMP_GE | CMP_LE | OR | AND | CMP_EQ | CMP_NE | TILDE | NOT | PERIOD | BACKSLASH | ELLIPSIS | ERROR | WARNING | LINE | PRAGMA | PRAGMA_ONCE | IIF | IF | IFDEF | IFNDEF | ELSE | ELIF | ENDIF | DEFINE | DEFINED | UNDEF | INCLUDE | TYPEDEF | STRUCT | UNION | ENUM | CONST | LIB | STATIC | CALLBACK | FUNCTION | LET | SET | TEMP | FREE | RETURN | PRE_ASSERT | POST_ASSERT | BOOLVAL | INTVAL | STRVAL | PATHVAL | STRLEN | FLOATVAL | ARRVAL | OBJVAL | COUNT | CALLOC | TO_BOOL | TO_INT | TO_STRING | TO_FLOAT | TO_ARRAY | TO_OBJECT | COMMENT | CPP_HEADER | CPP_PASTE | CPP_INLINE | CPP_RESTRICT | CPP_EXTENSION | CPP_ASM | SIZEOF | VOLATILE | AS;
+any_nobrace_token: BOOL | CHAR | SHORT | INT | SIGNED | UNSIGNED | LONG | FLOAT | DOUBLE | STRING | MIXED | ARRAY | OBJECT | CALLABLE | VOID | ZVAL | NULL | TRUE | FALSE | NAME | NSNAME | DOLLAR_NAME | NUMBER | QUOTED_STRING | QUOTED_CHAR | EOF | EOS | LPAREN | RPAREN | COMMA | COLON | LBRACKET | RBRACKET | EQUALS | HASH | PIPE | CARET | AMPERSAND | LSHIFT | RSHIFT | PLUS | MINUS | ASTERISK | SLASH | MODULO | LCHEVR | RCHEVR | CMP_GE | CMP_LE | OR | AND | CMP_EQ | CMP_NE | TILDE | NOT | PERIOD | BACKSLASH | ELLIPSIS | ERROR | WARNING | LINE | PRAGMA | PRAGMA_ONCE | IIF | IF | IFDEF | IFNDEF | ELSE | ELIF | ENDIF | DEFINE | DEFINED | UNDEF | INCLUDE | TYPEDEF | STRUCT | UNION | ENUM | CONST | LIB | STATIC | CALLBACK | FUNCTION | LET | SET | TEMP | FREE | RETURN | PRE_ASSERT | POST_ASSERT | BOOLVAL | INTVAL | STRVAL | PATHVAL | STRLEN | FLOATVAL | ARRVAL | OBJVAL | COUNT | CALLOC | TO_BOOL | TO_INT | TO_STRING | TO_FLOAT | TO_ARRAY | TO_OBJECT | COMMENT | CPP_HEADER | CPP_PASTE | CPP_INLINE | CPP_RESTRICT | CPP_EXTENSION | CPP_ASM | SIZEOF | VOLATILE | AS;
file:
}
}
| lib {
- if (P->file.ln) {
- P->error(PSI_DATA(P), $lib, PSI_WARNING,
- "Extra 'lib \"%s\"' statement has no effect", $lib->text);
- } else {
- P->file.ln = strndup($lib->text, $lib->size);
- }
+ char *libname = strdup($lib->text);
+ P->file.libnames = psi_plist_add(P->file.libnames, &libname);
}
| constant {
psi_parser_proc_add_const(P, $constant);
| decl_stmt {
psi_parser_proc_add_decl(P, $decl_stmt);
}
-| ignored_decl
-| decl_ext_var_stmt
+| decl_extvar_stmt[list] {
+ psi_parser_proc_add_decl_extvars(P, $list);
+}
+| ignored_decl {
+ if (P->flags & PSI_DEBUG) {
+ P->error(PSI_DATA(P), $ignored_decl->func->token, PSI_NOTICE, "Ignored decl: %s", $ignored_decl->func->var->name);
+ }
+ psi_decl_free(&$ignored_decl);
+}
| decl_typedef[def] {
psi_parser_proc_add_typedef(P, $def);
}
$exp = psi_cpp_exp_init($cpp_no_arg_token->type, NULL);
$exp->token = psi_token_copy($cpp_no_arg_token);
}
-| cpp_name_arg_token cpp_special_name_token[name_token] {
+| cpp_name_arg_token any_noeol_token[name_token] {
$name_token->type = PSI_T_NAME;
$exp = psi_cpp_exp_init($cpp_name_arg_token->type, psi_token_copy($name_token));
$exp->token = psi_token_copy($cpp_name_arg_token);
| ELIF
;
-cpp_special_name_token:
- name_token
-| NULL
-| TRUE
-| FALSE
-| CPP_RESTRICT
-| CPP_EXTENSION
-| CPP_INLINE
-;
-
cpp_macro_decl[macro]:
- name_token NO_WHITESPACE LPAREN cpp_macro_sig RPAREN cpp_macro_decl_tokens {
+ any_noeol_token[name_token] cpp_macro_decl_tokens %dprec 1 {
+ $name_token->type = PSI_T_NAME;
+ $macro = psi_cpp_macro_decl_init(NULL, $cpp_macro_decl_tokens, NULL);
+ $macro->token = psi_token_copy($name_token);
+}
+| name_token NO_WHITESPACE LPAREN cpp_macro_sig RPAREN cpp_macro_decl_tokens %dprec 2 {
$name_token->type = PSI_T_NAME;
$macro = psi_cpp_macro_decl_init($cpp_macro_sig, $cpp_macro_decl_tokens, NULL);
$macro->token = psi_token_copy($name_token);
}
-| cpp_special_name_token[name_token] cpp_macro_decl_tokens {
+| name_token cpp_macro_exp[num_exp] %dprec 2 {
$name_token->type = PSI_T_NAME;
- $macro = psi_cpp_macro_decl_init(NULL, $cpp_macro_decl_tokens, NULL);
+ $macro = psi_cpp_macro_decl_init(NULL, psi_num_exp_tokens($num_exp, NULL), $num_exp);
+ $macro->token = psi_token_copy($name_token);
+}
+| name_token quoted_strings[strings] %dprec 2 {
+ struct psi_plist *list = psi_plist_init((psi_plist_dtor) psi_token_free);
+ $name_token->type = PSI_T_NAME;
+ $macro = psi_cpp_macro_decl_init(NULL, psi_plist_add(list, &$strings), NULL);
$macro->token = psi_token_copy($name_token);
}
;
$name_token->type = PSI_T_NAME;
exists = psi_cpp_defined(P->preproc, $name_token);
$exp = psi_num_exp_init_num(psi_number_init(PSI_T_UINT8, &exists, 0));
- $exp->token = psi_token_copy($name_token);
+ $exp->token = psi_token_copy($DEFINED);
+ $exp->data.n->token = psi_token_copy($name_token);
}
}
| DEFINED LPAREN name_token RPAREN {
$name_token->type = PSI_T_NAME;
exists = psi_cpp_defined(P->preproc, $name_token);
$exp = psi_num_exp_init_num(psi_number_init(PSI_T_UINT8, &exists, 0));
- $exp->token = psi_token_copy($name_token);
+ $exp->token = psi_token_copy($DEFINED);
+ $exp->data.n->token = psi_token_copy($name_token);
}
}
| NUMBER {
$exp = psi_num_exp_init_num(psi_number_init(PSI_T_FUNCTION,
psi_cpp_macro_call_init($name_token->text, $cpp_macro_call_args), 0));
$exp->token = psi_token_copy($name_token);
+ $exp->data.n->token = psi_token_copy($name_token);
}
;
;
constant[const]:
- CONST constant_type NSNAME EQUALS impl_def_val EOS {
- $const = psi_const_init($constant_type, $NSNAME->text, $impl_def_val);
+ CONST impl_type_restricted[type] NSNAME EQUALS impl_def_val EOS {
+ $const = psi_const_init($type, $NSNAME->text, $impl_def_val);
$const->token = psi_token_copy($NSNAME);
}
;
-constant_type[type]:
- constant_type_token[token] {
- $type = psi_const_type_init($token->type, $token->text);
-}
-;
-
-constant_type_token:
- BOOL
-| INT
-| FLOAT
-| STRING
-;
-
impl_def_val[val]:
- %empty {
- $val = NULL;
+ impl_def_val_token[token] %dprec 2 {
+ $val = psi_impl_def_val_init($token->type, $token->text);
+ $val->token = psi_token_copy($token);
}
-| num_exp[num] {
- if (psi_num_exp_validate(PSI_DATA(P), $num, NULL, NULL, NULL, NULL, NULL)) {
- impl_val res = {0};
- token_t type = psi_num_exp_exec($num, &res, NULL, &P->preproc->defs);
-
- if (type == PSI_T_FLOAT || type == PSI_T_DOUBLE) {
- $val = psi_impl_def_val_init(type, NULL);
- } else {
- $val = psi_impl_def_val_init(PSI_T_INT, NULL);
- }
-
- switch (type) {
- case PSI_T_UINT8: $val->ival.zend.lval = res.u8; break;
- case PSI_T_UINT16: $val->ival.zend.lval = res.u16; break;
- case PSI_T_UINT32: $val->ival.zend.lval = res.u32; break;
- case PSI_T_UINT64: $val->ival.zend.lval = res.u64; break; /* FIXME */
- case PSI_T_INT8: $val->ival.zend.lval = res.i8; break;
- case PSI_T_INT16: $val->ival.zend.lval = res.i16; break;
- case PSI_T_INT32: $val->ival.zend.lval = res.i32; break;
- case PSI_T_INT64: $val->ival.zend.lval = res.i64; break;
- case PSI_T_FLOAT: $val->ival.dval = res.fval; break;
- case PSI_T_DOUBLE: $val->ival.dval = res.dval; break;
- default:
- assert(0);
-
- }
- } else {
- $val = NULL;
- }
- psi_num_exp_free(&$num);
+| num_exp[num] %dprec 1 {
+ $val = psi_impl_def_val_init(PSI_T_NUMBER, $num);
+ $val->token = psi_token_copy($num->token);
}
-| impl_def_val_token[token] {
+| quoted_strings[token] {
$val = psi_impl_def_val_init($token->type, $token->text);
$val->token = psi_token_copy($token);
}
NULL
| TRUE
| FALSE
-| QUOTED_STRING
;
decl_typedef[def]:
TYPEDEF typedef[def_] EOS {
$def = $def_;
}
+/*
| TYPEDEF VOID name_token EOS {
$def = psi_decl_arg_init(
psi_decl_type_init(PSI_T_VOID, $VOID->text),
$def->type->token = psi_token_copy($VOID);
$def->var->token = psi_token_copy($name_token);
}
+*/
| CPP_EXTENSION TYPEDEF typedef[def_] EOS {
$def = $def_;
}
$def->type->real.unn->size = $as.len;
psi_parser_proc_add_union(P, $def->type->real.unn);
}
-| qualified_decl_type[type] decl_stdint_type[stdint] {
- $stdint->type = PSI_T_NAME;
- $def = psi_decl_arg_init($type, psi_decl_var_init($stdint->text, 0, 0));
- $def->var->token = psi_token_copy($stdint);
-}
;
typedef_anon_decl[def]:
- typedef_decl
-| qualified_decl_type[type] {
+ typedef_decl %dprec 2
+| qualified_decl_type[type] %dprec 1 {
$def = psi_decl_arg_init($type, psi_decl_var_init(NULL, 0, 0));
$def->var->token = psi_token_copy($type->token);
}
;
qualified_decl_type[type]:
- CONST decl_type[type_] {
+ decl_type
+| decl_type_qualifier_token decl_type[type_] {
$type = $type_;
}
-| VOLATILE decl_type[type_] {
+| qualified_decl_type[type_] decl_type_qualifier_token {
$type = $type_;
}
-| decl_type
+;
+
+decl_type_qualifier_token:
+ CONST
+| VOLATILE
;
decl_type[type]:
decl_type_simple[type]:
decl_int_type
| decl_real_type
-| decl_stdint_type[type_] {
+| NAME[type_] {
$type = psi_token_copy($type_);
}
-| NAME[type_] {
+| VOID[type_] {
$type = psi_token_copy($type_);
}
;
}
;
-decl_stdint_type[type]:
- INT8
-| UINT8
-| INT16
-| UINT16
-| INT32
-| UINT32
-| INT64
-| UINT64
-;
-
int_signed[i]:
SIGNED
| UNSIGNED
%empty {
$type = NULL;
}
+| NAME {
+ $type = psi_token_copy($NAME);
+}
| CHAR {
$type = psi_token_copy($CHAR);
}
decl_stmt:
decl decl_asm EOS {
$decl_stmt = $decl;
+ if ($decl_asm) {
+ $decl->redir = strdup($decl_asm->text);
+ free($decl_asm);
+ }
}
| CPP_EXTENSION decl decl_asm EOS {
$decl_stmt = $decl;
+ if ($decl_asm) {
+ $decl->redir = strdup($decl_asm->text);
+ free($decl_asm);
+ }
}
;
decl_asm:
- %empty
-| CPP_ASM LPAREN ignored_quoted_strings RPAREN
-;
-
-ignored_quoted_strings:
- QUOTED_STRING
-| ignored_quoted_strings QUOTED_STRING
+ %empty {
+ $decl_asm = NULL;
+}
+| CPP_ASM LPAREN quoted_strings RPAREN {
+ $decl_asm = $quoted_strings;
+}
;
-decl_ext_var_stmt:
- decl_ext_var EOS
+quoted_strings[strings]:
+ QUOTED_STRING {
+ $strings = psi_token_copy($QUOTED_STRING);
+}
+| quoted_strings[strings_] QUOTED_STRING {
+ $strings = psi_token_cat("", 2, $strings_, $QUOTED_STRING);
+ free($strings_);
+}
;
-decl_ext_var:
- NAME decl_arg decl_ext_var_list {
- psi_decl_arg_free(&$decl_arg);
+decl_extvar_stmt[list]:
+ NAME decl_arg decl_extvar_list[vars] EOS {
+ struct psi_plist *list = psi_plist_init((psi_plist_dtor) psi_decl_extvar_free);
+
+ if ($vars) {
+ size_t i = 0;
+ struct psi_decl_var *var;
+
+ while (psi_plist_get($vars, i++, &var)) {
+ if (psi_decl_extvar_is_blacklisted(var->name)) {
+ psi_decl_var_free(&var);
+ } else {
+ struct psi_decl_extvar *evar = psi_decl_extvar_init(
+ psi_decl_arg_init(psi_decl_type_copy($decl_arg->type), var));
+ list = psi_plist_add(list, &evar);
+ }
+ }
+ free($vars);
+ }
+
+ if (psi_decl_extvar_is_blacklisted($decl_arg->var->name)) {
+ psi_decl_arg_free(&$decl_arg);
+ } else {
+ struct psi_decl_extvar *evar = psi_decl_extvar_init($decl_arg);
+ list = psi_plist_add(list, &evar);
+ }
+
+ $list = list;
}
;
-decl_ext_var_list:
- %empty
+decl_extvar_list[list]:
+ %empty {
+ $list = NULL;
+}
| COMMA decl_vars {
- psi_plist_free($decl_vars);
+ $list = $decl_vars;
}
;
ignored_decl:
STATIC decl_body ignored_decl_body {
- psi_decl_free(&$decl_body);
+ $ignored_decl = $decl_body;
+}
+| STATIC CPP_INLINE decl_body ignored_decl_body {
+ $ignored_decl = $decl_body;
}
| CPP_INLINE decl_body ignored_decl_body {
- psi_decl_free(&$decl_body);
+ $ignored_decl = $decl_body;
}
-| STATIC CPP_INLINE decl_body ignored_decl_body {
- psi_decl_free(&$decl_body);
+| NAME CPP_INLINE decl_body ignored_decl_body {
+ $ignored_decl = $decl_body;
}
;
$decl->func->var->array_size = $as;
}
}
+| qualified_decl_type[rval_type] indirection[i] LPAREN indirection[unused1] name_token[NAME] LPAREN decl_args[args] RPAREN RPAREN LPAREN decl_args[rval_args] RPAREN array_size[as] {
+ (void) $unused1;
+ $NAME->type = PSI_T_NAME;
+
+ struct psi_token *type_token = psi_token_append("@", psi_token_copy($NAME), 1, "rval");
+ struct psi_decl_arg *rval_func = psi_decl_arg_init($rval_type, psi_decl_var_init(type_token->text, $i, 0));
+ struct psi_decl *rval_decl = psi_decl_init(rval_func, $rval_args);
+
+ rval_func->var->token = psi_token_copy(type_token);
+ rval_func->token = psi_token_copy(type_token);
+ if ($as) {
+ rval_func->var->pointer_level += 1;
+ rval_func->var->array_size = $as;
+ }
+
+ struct psi_decl_type *type = psi_decl_type_init(PSI_T_FUNCTION, type_token->text);
+ struct psi_decl_arg *func = psi_decl_arg_init(type, psi_decl_var_init($NAME->text, 1, 0));
+
+ type->real.func = rval_decl;
+ func->var->token = psi_token_copy($NAME);
+ func->token = psi_token_copy($NAME);
+
+ $decl = psi_decl_init(func, $args);
+}
+| qualified_decl_type[rval_type] indirection[i] LPAREN indirection[unused1] LPAREN indirection[unused2] name_token[NAME] RPAREN LPAREN decl_args[args] RPAREN RPAREN LPAREN decl_args[rval_args] RPAREN array_size[as] {
+ (void) $unused1;
+ (void) $unused2;
+ $NAME->type = PSI_T_NAME;
+
+ struct psi_token *type_token = psi_token_append("@", psi_token_copy($NAME), 1, "rval");
+ struct psi_decl_arg *rval_func = psi_decl_arg_init($rval_type, psi_decl_var_init(type_token->text, $i, 0));
+ struct psi_decl *rval_decl = psi_decl_init(rval_func, $rval_args);
+
+ rval_func->var->token = psi_token_copy(type_token);
+ rval_func->token = psi_token_copy(type_token);
+ if ($as) {
+ rval_func->var->pointer_level += 1;
+ rval_func->var->array_size = $as;
+ }
+
+ struct psi_decl_type *type = psi_decl_type_init(PSI_T_FUNCTION, type_token->text);
+ struct psi_decl_arg *func = psi_decl_arg_init(type, psi_decl_var_init($NAME->text, 1, 0));
+
+ type->real.func = rval_decl;
+ func->var->token = psi_token_copy($NAME);
+ func->token = psi_token_copy($NAME);
+
+ $decl = psi_decl_init(func, $args);
+}
+;
+
+decl_anon_functor_body[decl]:
+ decl_anon_functor[func] LPAREN decl_args[args] RPAREN array_size[as] {
+ $decl = psi_decl_init($func, $args);
+ if ($as) {
+ $decl->func->var->pointer_level += 1;
+ $decl->func->var->array_size = $as;
+ }
+}
+| decl_anon_functor[func] LPAREN decl_args[args] COMMA ELLIPSIS RPAREN array_size[as] {
+ $decl = psi_decl_init($func, $args);
+ $decl->varargs = 1;
+ if ($as) {
+ $decl->func->var->pointer_level += 1;
+ $decl->func->var->array_size = $as;
+ }
+}
;
decl_functor[arg]:
$arg->var->token = psi_token_copy($NAME);
$arg->token = psi_token_copy($NAME);
}
+
+/*
| CONST VOID pointers LPAREN indirection[unused1] name_token[NAME] RPAREN {
(void) $unused1;
$NAME->type = PSI_T_NAME;
$arg->var->token = psi_token_copy($NAME);
$arg->token = psi_token_copy($NAME);
}
+*/
+;
+
+decl_anon_functor[arg]:
+ qualified_decl_type[type] indirection[i] LPAREN indirection[unused1] RPAREN {
+ (void) $unused1;
+ $arg = psi_decl_arg_init($type, psi_decl_var_init(NULL, $i, 0));
+ $arg->var->token = psi_token_copy($LPAREN);
+ $arg->token = psi_token_copy($LPAREN);
+}
+/*
+| CONST VOID pointers LPAREN indirection[unused1] RPAREN {
+ (void) $unused1;
+ $arg = psi_decl_arg_init(
+ psi_decl_type_init($VOID->type, $VOID->text),
+ psi_decl_var_init(NULL, $pointers, 0)
+ );
+ $arg->type->token = psi_token_copy($VOID);
+ $arg->var->token = psi_token_copy($VOID);
+ $arg->token = psi_token_copy($VOID);
+}
+| VOID pointers LPAREN indirection[unused1] RPAREN {
+ (void) $unused1;
+ $arg = psi_decl_arg_init(
+ psi_decl_type_init($VOID->type, $VOID->text),
+ psi_decl_var_init(NULL, $pointers, 0)
+ );
+ $arg->type->token = psi_token_copy($VOID);
+ $arg->var->token = psi_token_copy($VOID);
+ $arg->token = psi_token_copy($VOID);
+}
+| VOID LPAREN indirection[unused1] RPAREN {
+ (void) $unused1;
+ $arg = psi_decl_arg_init(
+ psi_decl_type_init($VOID->type, $VOID->text),
+ psi_decl_var_init(NULL, 0, 0)
+ );
+ $arg->type->token = psi_token_copy($VOID);
+ $arg->var->token = psi_token_copy($VOID);
+ $arg->token = psi_token_copy($VOID);
+}
+*/
;
decl_func[func]:
decl_arg
+ /*
| VOID name_token[NAME] {
$func = psi_decl_arg_init(
psi_decl_type_init($VOID->type, $VOID->text),
$func->var->token = psi_token_copy($NAME);
$func->token = psi_token_copy($NAME);
}
+*/
;
decl_args[args]:
%empty {
$args = NULL;
}
-| VOID {
+| VOID %dprec 2 {
$args = NULL;
}
-| decl_anon_arg[arg] {
+| decl_arg_list[args_] %dprec 1 {
+ $args = $args_;
+}
+;
+
+decl_arg_list[args]:
+ decl_anon_arg[arg] {
$args = psi_plist_add(psi_plist_init((psi_plist_dtor) psi_decl_arg_free), &$arg);
}
-| decl_args[args_] COMMA decl_anon_arg[arg] {
+| decl_arg_list[args_] COMMA decl_anon_arg[arg] {
$args = psi_plist_add($args_, &$arg);
}
;
decl_anon_arg[arg]:
-/* FIXME decl_functor_body_anon */
- decl_arg {
+ decl_anon_functor_body[decl] {
+ char digest[17];
+ struct psi_token *name;
+
+ psi_token_hash($decl->func ->token, digest);
+ name = psi_token_append("@", psi_token_copy($decl->func->token), 2, "funct", digest);
+
+ $arg = psi_decl_arg_init(
+ psi_decl_type_init(PSI_T_FUNCTION, name->text),
+ psi_decl_var_copy($decl->func->var)
+ );
+ $arg->token = name;
+ $arg->type->token = psi_token_copy($decl->func->token);
+ $arg->type->real.func = $decl;
+}
+| decl_arg %dprec 2 {
$arg = $decl_arg;
}
-| qualified_decl_type[type] indirection {
+| qualified_decl_type[type] indirection %dprec 1 {
$arg = psi_decl_arg_init(
$type,
psi_decl_var_init(NULL, $indirection, 0)
);
}
+/*
| CONST VOID pointers {
$arg = psi_decl_arg_init(
psi_decl_type_init($VOID->type, $VOID->text),
$arg->var->token = psi_token_copy($VOID);
$arg->token = psi_token_copy($VOID);
}
+*/
;
decl_arg[arg]:
| qualified_decl_type[type] decl_var[var] {
$arg = psi_decl_arg_init($type, $var);
}
+/*
| CONST VOID pointers name_token[NAME] {
$NAME->type = PSI_T_NAME;
$arg = psi_decl_arg_init(
$arg->var->token = psi_token_copy($NAME);
$arg->token = psi_token_copy($NAME);
}
+*/
;
decl_var[var]:
;
decl_enum[enum]:
- enum_name LBRACE decl_enum_items[list] RBRACE {
+ enum_name LBRACE decl_enum_items[list] optional_comma RBRACE {
$enum = psi_decl_enum_init($enum_name->text, $list);
$enum->token = $enum_name;
}
$num = psi_number_init($token->type, $token->text, 0);
$num->token = psi_token_copy($token);
}
+| NULL[token] {
+ $num = psi_number_init($token->type, $token->text, 0);
+ $num->token = psi_token_copy($token);
+}
| decl_var {
$num = psi_number_init(PSI_T_NAME, $decl_var, 0);
$num->token = psi_token_copy($decl_var->token);
if ($indirection) {
int8_t sizeof_void_p = sizeof(void *);
$sizeof = psi_number_init(PSI_T_INT8, &sizeof_void_p, 0);
+ psi_decl_type_free(&$decl_type);
} else {
$sizeof = psi_number_init(PSI_T_SIZEOF, $decl_type, 0);
}
$sizeof = psi_number_init(PSI_T_INT8, &sizeof_a, 0);
}
| QUOTED_STRING {
- $sizeof = psi_number_init(PSI_T_INT64, &$QUOTED_STRING->size, 0);
+ uint64_t len = $QUOTED_STRING->size + 1;
+ $sizeof = psi_number_init(PSI_T_UINT64, &len, 0);
}
;
}
;
+optional_comma:
+ %empty
+| COMMA
+;
+
decl_layout[l]:
%empty {
$l = NULL;
%empty {
$as = 0;
}
-| LBRACKET RBRACKET {
+| LBRACKET array_qualifier_token RBRACKET {
$as = 0;
}
| LBRACKET num_exp RBRACKET {
- if (psi_num_exp_validate(PSI_DATA(P), $num_exp, NULL, NULL, NULL, NULL, NULL)) {
- $as = psi_long_num_exp($num_exp, NULL, &P->preproc->defs);
+ struct psi_validate_scope scope = {0};
+ psi_validate_scope_ctor(&scope);
+ scope.defs = &P->preproc->defs;
+ if (psi_num_exp_validate(PSI_DATA(P), $num_exp, &scope)) {
+ $as = psi_num_exp_get_long($num_exp, NULL, &P->preproc->defs);
} else {
$as = 0;
}
+ psi_num_exp_free(&$num_exp);
+ psi_validate_scope_dtor(&scope);
}
;
+array_qualifier_token:
+ %empty
+| CPP_RESTRICT
+| VOLATILE
+| CONST
+;
+
indirection[i]:
%empty {
$i = 0;
asterisk:
ASTERISK
-| ASTERISK CONST
+| ASTERISK pointer_qualifier_token
+;
+
+pointer_qualifier_token:
+ CONST
+| VOLATILE
;
/*
}
;
+impl_type_restricted[type]:
+ impl_type_restricted_token[token] {
+ $type = psi_impl_type_init($token->type, $token->text);
+ $type->token = psi_token_copy($token);
+}
+;
+
impl_type_token:
- VOID
-| MIXED
-| BOOL
+ impl_type_restricted_token
+| impl_type_extended_token
+;
+
+impl_type_restricted_token:
+ BOOL
| INT
| FLOAT
| STRING
+;
+
+impl_type_extended_token:
+ VOID
+| MIXED
| ARRAY
| OBJECT
| CALLABLE
;
let_exp_byref[exp]:
- NULL {
+ NULL %dprec 2 {
$exp = psi_let_exp_init(PSI_LET_NULL, NULL);
}
+| num_exp[num] %dprec 1 {
+ $exp = psi_let_exp_init_ex(NULL, PSI_LET_NUMEXP, $num);
+}
| let_calloc[calloc] {
$exp = psi_let_exp_init(PSI_LET_CALLOC, $calloc);
}
| let_func[func] {
$exp = psi_let_exp_init_ex(NULL, PSI_LET_FUNC, $func);
}
-| num_exp[num] {
- $exp = psi_let_exp_init_ex(NULL, PSI_LET_NUMEXP, $num);
-}
;
let_exp_assign[exp]:
let_callback[callback]:
CALLBACK callback_rval[func] LPAREN impl_var[var] LPAREN callback_arg_list[args] RPAREN RPAREN {
- $callback = psi_let_callback_init(psi_let_func_init($func->type, $func->text, $var), $args);
+ $callback = psi_let_callback_init(psi_let_func_init($func->type, $func->text, $var), $args, NULL);
+ $callback->func->token = psi_token_copy($func);
+ $callback->token = psi_token_copy($CALLBACK);
+}
+| CALLBACK LPAREN call_decl_vars[cb_args] RPAREN AS callback_rval[func] LPAREN impl_var[var] LPAREN callback_arg_list[args] RPAREN RPAREN {
+ $callback = psi_let_callback_init(psi_let_func_init($func->type, $func->text, $var), $args, $cb_args);
$callback->func->token = psi_token_copy($func);
$callback->token = psi_token_copy($CALLBACK);
}
;
return_stmt[return]:
- RETURN set_func[func] EOS {
- $return = psi_return_stmt_init(psi_set_exp_init(PSI_SET_FUNC, $func));
+ RETURN return_exp EOS {
+ $return = psi_return_stmt_init($return_exp);
$return->token = psi_token_copy($RETURN);
}
;
+return_exp:
+ decl_var[func] LPAREN call_decl_vars[args] RPAREN AS set_func {
+ $return_exp = psi_return_exp_init($func, $args, psi_set_exp_init(PSI_SET_FUNC, $set_func));
+ $return_exp->token = psi_token_copy($func->token);
+}
+| set_func {
+ $return_exp = psi_return_exp_init(NULL, NULL, psi_set_exp_init(PSI_SET_FUNC, $set_func));
+ $return_exp->token = psi_token_copy($set_func->token);
+}
+;
+
+call_decl_vars[args]:
+ %empty {
+ $args = NULL;
+}
+| VOID {
+ $args = NULL;
+}
+| decl_vars[vars] {
+ $args = $vars;
+}
+;
+
set_stmt[set]:
SET set_exp[exp] EOS {
$set = psi_set_stmt_init($exp);