-#include "php_scandir.h"
-#include "php_psi.h"
-#include "context.h"
-#include "parser.h"
-
-#define psi_predef_count(of) ((sizeof(psi_predef ##of## s)/sizeof(psi_predef ##of))-1)
-typedef struct psi_predef_type {
- token_t type_tag;
- const char *type_name;
- const char *alias;
-} psi_predef_type;
-static const psi_predef_type psi_predef_types[] = {
- PHP_PSI_TYPES{0}
-};
-#define psi_predef_type_count() psi_predef_count(_type)
-
-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;
-static const psi_predef_const psi_predef_consts[] = {
- PHP_PSI_CONSTS{0}
-};
-#define psi_predef_const_count() psi_predef_count(_const)
-
-typedef struct psi_predef_struct_member {
- token_t type_tag;
- const char *type_name;
- const char *name;
- size_t off;
- size_t len;
- size_t pointer_level;
- size_t array_size;
-} psi_predef_struct_member;
-#define PSI_PREDEF_STRUCT_MEMBERS 32
-typedef struct psi_predef_struct {
- const char *name;
- size_t size;
- psi_predef_struct_member members[PSI_PREDEF_STRUCT_MEMBERS];
-} psi_predef_struct;
-static const psi_predef_struct psi_predef_structs[] = {
- PHP_PSI_STRUCTS{0}
-};
-#define psi_predef_struct_count() psi_predef_count(_struct)
-
-PHP_PSI_MACROS
-
-typedef struct psi_predef_func {
- const char *name;
- void (*func)(void);
-} psi_predef_func;
-static psi_predef_func psi_predef_funcs[] = {
- PHP_PSI_FUNCS{0}
-};
-#define psi_predef_func_count() psi_predef_count(_func)
-
-static int validate_lib(PSI_Data *data, void **dlopened) {
- char lib[MAXPATHLEN];
- const char *ptr = data->psi.file.ln;
- size_t len;
-
- if (!ptr) {
- /* FIXME: assume stdlib */
- return 1;
- } else if (!strchr(ptr, '/')) {
- len = snprintf(lib, MAXPATHLEN, "lib%s.%s", ptr, PHP_PSI_SHLIB_SUFFIX);
- if (MAXPATHLEN == len) {
- data->error(PSI_WARNING, "Library name too long: '%s'", ptr);
- }
- lib[len] = 0;
- ptr = lib;
- }
- if (!(*dlopened = dlopen(ptr, RTLD_LAZY|RTLD_LOCAL))) {
- data->error(PSI_WARNING, "Could not open library '%s': %s.",
- data->psi.file.ln, dlerror());
- return 0;
- }
- return 1;
-}
-
-static inline int locate_decl_type_alias(decl_typedefs *defs, decl_type *type) {
- size_t i;
-
- if (type->real) {
- return 1;
- }
- for (i = 0; i < defs->count; ++i) {
- if (!strcmp(defs->list[i]->alias, type->name)) {
- type->real = defs->list[i]->type;
- return 1;
- }
- }
- return 0;
-}
-static inline int locate_decl_type_struct(decl_structs *structs, decl_type *type) {
- size_t i;
-
- if (type->strct) {
- return 1;
- }
- for (i = 0; i < structs->count; ++i) {
- if (!strcmp(structs->list[i]->name, type->name)) {
- type->strct = structs->list[i];
- return 1;
- }
- }
- return 0;
-}
-
-static inline int validate_decl_type(PSI_Data *data, decl_type *type) {
- switch (type->type) {
- case PSI_T_NAME:
- if (!data->defs || !locate_decl_type_alias(data->defs, type)) {
- return 0;
- }
- return validate_decl_type(data, type->real);
- case PSI_T_STRUCT:
- if (!data->structs || !locate_decl_type_struct(data->structs, type)) {
- return 0;
- }
- break;
- }
- return 1;
-}
-static inline int validate_decl_typedef(PSI_Data *data, decl_typedef *def) {
- if (!validate_decl_type(data, def->type)) {
- data->error(PSI_WARNING, "Type '%s' cannot be aliased to '%s'",
- def->type->name, def->alias);
- return 0;
- }
- /* FIXME: check def->alias */
- return 1;
-}
-
-static inline int validate_constant(PSI_Data *data, constant *c) {
- /* FIXME */
- return 1;
-}