#define PSI_STD_TYPES
#include "php_psi_posix.h"
-struct psi_decl_type *psi_decl_type_init(token_t type, const char *name)
+struct psi_decl_type *psi_decl_type_init(token_t type, zend_string *name)
{
struct psi_decl_type *t = calloc(1, sizeof(*t));
t->type = type;
- t->name = strdup(name);
+ t->name = zend_string_copy(name);
return t;
}
struct psi_decl_type *type = *type_ptr;
*type_ptr = NULL;
- if (type->token) {
- free(type->token);
- }
+ psi_token_free(&type->token);
if (type->type == PSI_T_FUNCTION) {
psi_decl_free(&type->real.func);
}
- free(type->name);
+ zend_string_release(type->name);
free(type);
}
}
dst->type = src->type;
if (src->name) {
- dst->name = strdup(src->name);
+ dst->name = zend_string_copy(src->name);
}
if (src->token) {
dst->token = psi_token_copy(src->token);
}
if (defs) {
while (psi_plist_get(defs, i++, &def)) {
- if (def->type->type != type->type
- && !strcmp(def->var->name, type->name)) {
+ if (zend_string_equals(def->var->name, type->name)) {
type->real.def = def;
return true;
}
}
}
for (stdtyp = &psi_std_types[0]; stdtyp->type_tag; ++stdtyp) {
- if (!strcmp(type->name, stdtyp->alias ?: stdtyp->type_name)) {
+ if (!strcmp(type->name->val, stdtyp->alias ?: stdtyp->type_name)) {
type->type = stdtyp->type_tag;
return true;
}
}
if (structs) {
while (psi_plist_get(structs, i++, &s)) {
- if (!strcmp(s->name, type->name)) {
+ if (zend_string_equals(s->name, type->name)) {
type->real.strct = s;
return true;
}
}
if (unions) {
while (psi_plist_get(unions, i++, &u)) {
- if (!strcmp(u->name, type->name)) {
+ if (zend_string_equals(u->name, type->name)) {
type->real.unn = u;
return true;
}
}
if (enums) {
while (psi_plist_get(enums, i++, &e)) {
- if (!strcmp(e->name, type->name)) {
+ if (zend_string_equals(e->name, type->name)) {
type->real.enm = e;
return true;
}
}
if (decls) {
while (psi_plist_get(decls, i++, &decl)) {
- if (!strcmp(decl->func->var->name, type->name)) {
+ if (zend_string_equals(decl->func->var->name, type->name)) {
type->real.func = decl;
return true;
}
}
bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
- bool is_pointer, struct psi_validate_stack *type_stack)
+ struct psi_decl_arg *def, struct psi_validate_scope *scope)
{
if (psi_decl_type_is_weak(type)) {
if (!psi_decl_type_get_alias(type, data->types)) {
- if (!psi_validate_stack_has_type(type_stack, type->name)) {
+ if (!psi_validate_scope_has_type(scope, type->name)) {
return false;
}
- type->real.def = psi_validate_stack_get_type(type_stack, type->name);
+ type->real.def = psi_validate_scope_get_type(scope, type->name);
}
if (type->real.def) {
- return psi_decl_type_validate(data, type->real.def->type,
- is_pointer, type_stack);
+ if (!psi_decl_type_validate(data, type->real.def->type,
+ type->real.def, scope)) {
+ return false;
+ }
+ if (def) {
+ def->var->pointer_level += type->real.def->var->pointer_level;
+ }
}
return true;
}
switch (type->type) {
case PSI_T_STRUCT:
if (!psi_decl_type_get_struct(type, data->structs)) {
- if (psi_validate_stack_has_struct(type_stack, type->name)) {
- type->real.strct = psi_validate_stack_get_struct(type_stack, type->name);
- } else if (is_pointer) {
+ if (psi_validate_scope_has_struct(scope, type->name)) {
+ type->real.strct = psi_validate_scope_get_struct(scope, type->name);
+ } else if (def && def->var->pointer_level) {
return true;
} else {
data->error(data, type->token, PSI_WARNING,
- "Unknown struct '%s'", type->name);
+ "Unknown struct '%s'", type->name->val);
return false;
}
}
- if (!psi_decl_struct_validate(data, type->real.strct, type_stack)) {
+ if (!psi_decl_struct_validate(data, type->real.strct, scope)) {
return false;
}
break;
case PSI_T_UNION:
if (!psi_decl_type_get_union(type, data->unions)) {
- if (psi_validate_stack_has_union(type_stack, type->name)) {
- type->real.unn = psi_validate_stack_get_union(type_stack, type->name);
- } else if (is_pointer) {
+ if (psi_validate_scope_has_union(scope, type->name)) {
+ type->real.unn = psi_validate_scope_get_union(scope, type->name);
+ } else if (def && def->var->pointer_level) {
return true;
} else {
data->error(data, type->token, PSI_WARNING,
- "Unknown union '%s'", type->name);
+ "Unknown union '%s'", type->name->val);
return false;
}
}
- if (!psi_decl_union_validate(data, type->real.unn, type_stack)) {
+ if (!psi_decl_union_validate(data, type->real.unn, scope)) {
return false;
}
break;
case PSI_T_ENUM:
if (!psi_decl_type_get_enum(type, data->enums)) {
data->error(data, type->token, PSI_WARNING,
- "Unknown enum '%s'", type->name);
+ "Unknown enum '%s'", type->name->val);
return false;
}
break;
case PSI_T_FUNCTION:
if (!psi_decl_type_get_decl(type, data->decls)) {
data->error(data, type->token, PSI_WARNING,
- "Unknown decl '%s'", type->name);
+ "Unknown decl '%s'", type->name->val);
return false;
}
- if (!psi_decl_validate_nodl(data, type->real.func, type_stack)) {
+ if (!psi_decl_validate_nodl(data, type->real.func, scope)) {
return false;
}
break;
while (psi_plist_get(args, i++, &sarg)) {
dprintf(fd, "%s", psi_t_indent(level));
psi_decl_arg_dump(fd, sarg, level);
- if (sarg->layout->bfw) {
- dprintf(fd, ":%zu", sarg->layout->bfw->len);
+ if (sarg->layout) {
+ if (sarg->layout->bfw) {
+ dprintf(fd, ":%zu", sarg->layout->bfw->len);
+ }
+ dprintf(fd, "::(%zu, %zu);\n", sarg->layout->pos,
+ sarg->layout->len);
+ } else {
+ dprintf(fd, ";\n");
}
- dprintf(fd, "::(%zu, %zu);\n", sarg->layout->pos,
- sarg->layout->len);
}
--level;
}
{
switch (t->type) {
case PSI_T_POINTER:
- dprintf(fd, "%s *", t->name);
+ dprintf(fd, "%s *", t->name->val);
return;
case PSI_T_ENUM:
return;
}
break;
+
+ case PSI_T_FUNCTION:
+ psi_decl_type_dump(fd, t->real.func->func->type, level);
+ return;
+
+ default:
+ break;
}
- dprintf(fd, "%s", t->name);
+
+ dprintf(fd, "%s", t->name->val);
}
int psi_decl_type_is_weak(struct psi_decl_type *type)
case PSI_T_ENUM:
default:
align = psi_t_alignment(real->type);
+ break;
}
return align;