#define BSIZE 256
#define PSI_T_POINTER PSI_T_ASTERISK
+#define PSI_T_LONG_DOUBLE (PSI_T_DOUBLE << 16)
+
typedef int token_t;
-/* in php_psi.h */
size_t psi_t_alignment(token_t);
size_t psi_t_size(token_t);
typedef struct PSI_Token {
token_t type;
- unsigned size, *line;
+ unsigned size, line;
char *text, *file;
char buf[1];
} PSI_Token;
uint64_t u64;
float fval;
double dval;
+#ifdef HAVE_LONG_DOUBLE
+ long double ldval;
+#endif
union {
zend_bool bval;
zend_long lval;
token_t type;
struct decl_type *real;
struct decl_struct *strct;
+ struct decl_enum *enm;
} decl_type;
static inline decl_type *init_decl_type(token_t type, const char *name) {
void *info;
size_t argc;
void **args;
- void *rval;
+ void **rval;
} decl_callinfo;
typedef struct decl {
free(decls);
}
+
typedef struct decl_struct {
PSI_Token *token;
char *name;
decl_args *args;
size_t size;
+ struct {
+ void *type;
+ void (*dtor)(void *type);
+ } engine;
} decl_struct;
static inline decl_struct *init_decl_struct(const char *name, decl_args *args) {
if (s->args) {
free_decl_args(s->args);
}
+ if (s->engine.type && s->engine.dtor) {
+ s->engine.dtor(s->engine.type);
+ }
free(s->name);
free(s);
}
char *numb;
constant *cnst;
decl_var *dvar;
+ struct decl_enum_item *enm;
} u;
token_t operator;
int (*calculator)(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res);
return exp;
}
+static inline PSI_Token *PSI_TokenCopy(PSI_Token *src);
+static inline num_exp *copy_num_exp(num_exp *exp) {
+ decl_var *dvar;
+ num_exp *num = calloc(1, sizeof(*num));
+
+ memcpy(num, exp, sizeof(*num));
+
+ if (num->token) {
+ num->token = PSI_TokenCopy(num->token);
+ }
+ if (num->operand) {
+ num->operand = copy_num_exp(num->operand);
+ }
+ switch (num->t) {
+ case PSI_T_NUMBER:
+ case PSI_T_NSNAME:
+ num->u.numb = strdup(num->u.numb);
+ break;
+ case PSI_T_NAME:
+ dvar = init_decl_var(num->u.dvar->name, num->u.dvar->pointer_level, num->u.dvar->array_size);
+ dvar->arg = num->u.dvar->arg;
+ if (num->u.dvar->token) {
+ dvar->token = PSI_TokenCopy(num->u.dvar->token);
+ }
+ num->u.dvar = dvar;
+ break;
+ }
+ return num;
+}
+
static inline void free_num_exp(num_exp *exp) {
if (exp->token) {
free(exp->token);
case PSI_T_NAME:
free_decl_var(exp->u.dvar);
break;
+ case PSI_T_ENUM:
+ break;
EMPTY_SWITCH_DEFAULT_CASE();
}
if (exp->operand) {
free(exp);
}
+typedef struct decl_enum_item {
+ PSI_Token *token;
+ char *name;
+ num_exp *num;
+ num_exp inc;
+ struct decl_enum_item *prev;
+} decl_enum_item;
+
+static inline decl_enum_item *init_decl_enum_item(const char *name, num_exp *num) {
+ decl_enum_item *i = calloc(1, sizeof(*i));
+
+ i->name = strdup(name);
+ i->num = num;
+ return i;
+}
+
+static inline void free_decl_enum_item(decl_enum_item *i) {
+ if (i->token) {
+ free(i->token);
+ }
+ if (i->num && i->num != &i->inc) {
+ free_num_exp(i->num);
+ }
+ free(i->name);
+ free(i);
+}
+
+typedef struct decl_enum_items {
+ decl_enum_item **list;
+ size_t count;
+} decl_enum_items;
+
+static inline decl_enum_items *init_decl_enum_items(decl_enum_item *i) {
+ decl_enum_items *l = calloc(1, sizeof(*l));
+
+ if (i) {
+ l->count = 1;
+ l->list = calloc(1, sizeof(*l->list));
+ l->list[0] = i;
+ }
+ return l;
+}
+
+static inline decl_enum_items *add_decl_enum_item(decl_enum_items *l, decl_enum_item *i) {
+ l->list = realloc(l->list, sizeof(*l->list) * (l->count + 1));
+ l->list[l->count] = i;
+ if (l->count) {
+ i->prev = l->list[l->count - 1];
+ }
+ ++l->count;
+ return l;
+}
+
+static inline void free_decl_enum_items(decl_enum_items *l) {
+ if (l->list) {
+ size_t j;
+
+ for (j = 0; j < l->count; ++j) {
+ free_decl_enum_item(l->list[j]);
+ }
+ free(l->list);
+ }
+ free(l);
+}
+
+typedef struct decl_enum {
+ PSI_Token *token;
+ char *name;
+ decl_enum_items *items;
+} decl_enum;
+
+static inline decl_enum *init_decl_enum(const char *name, decl_enum_items *l) {
+ decl_enum *e = calloc(1, sizeof(*e));
+
+ e->name = strdup(name);
+ e->items = l;
+ return e;
+}
+
+static inline void free_decl_enum(decl_enum *e) {
+ if (e->token) {
+ free(e->token);
+ }
+ if (e->items) {
+ free_decl_enum_items(e->items);
+ }
+ free(e->name);
+ free(e);
+}
+
+typedef struct decl_enums {
+ decl_enum **list;
+ size_t count;
+} decl_enums;
+
+static inline decl_enums* add_decl_enum(decl_enums *es, decl_enum *e) {
+ if (!es) {
+ es = calloc(1, sizeof(*es));
+ }
+ es->list = realloc(es->list, ++es->count * sizeof(*es->list));
+ es->list[es->count-1] = e;
+ return es;
+}
+
+static inline void free_decl_enums(decl_enums *es) {
+ if (es->list) {
+ size_t j;
+
+ for (j = 0; j < es->count; ++j) {
+ free_decl_enum(es->list[j]);
+ }
+ }
+ free(es->list);
+ free(es);
+}
+
typedef struct let_calloc {
num_exp *nmemb;
num_exp *size;
var->name, var->pointer_level, var->arg->var->pointer_level,
var->array_size, var->arg->var->array_size);
#endif
- if (!var->pointer_level && real_decl_type(var->arg->type)->type != PSI_T_STRUCT) {
+ if (!var->pointer_level ){//&& real_decl_type(var->arg->type)->type != PSI_T_STRUCT) {
return ptr;
}
constants *consts; \
decl_typedefs *defs; \
decl_structs *structs; \
+ decl_enums *enums; \
decls *decls; \
impls *impls; \
union { \
if (data->structs) {
free_decl_structs(data->structs);
}
+ if (data->enums) {
+ free_decl_enums(data->enums);
+ }
if (data->decls) {
free_decls(data->decls);
}
char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
} PSI_Parser;
+static inline size_t PSI_TokenAllocSize(size_t token_len, size_t fname_len) {
+ return sizeof(PSI_Token) + token_len + fname_len + 2;
+}
+
static inline PSI_Token *PSI_TokenAlloc(PSI_Parser *P) {
PSI_Token *T;
size_t token_len, fname_len;
token_len = P->cur - P->tok;
fname_len = strlen(P->psi.file.fn);
- T = calloc(1, sizeof(*T) + token_len + fname_len + sizeof(unsigned) + 2);
+ T = calloc(1, PSI_TokenAllocSize(token_len, fname_len));
T->type = token_typ;
T->size = token_len;
T->text = &T->buf[0];
T->file = &T->buf[token_len + 1];
- T->line = (void *) &T->buf[fname_len + token_len + 2];
+ T->line = P->line;
memcpy(T->text, P->tok, token_len);
memcpy(T->file, P->psi.file.fn, fname_len);
- memcpy(T->line, &P->line, sizeof(unsigned));
return T;
}
static inline PSI_Token *PSI_TokenCopy(PSI_Token *src) {
- size_t fname_len = strlen(src->file);
- size_t strct_len = sizeof(*src) + src->size + fname_len + sizeof(unsigned) + 2;
+ size_t strct_len = PSI_TokenAllocSize(src->size, strlen(src->file));
PSI_Token *ptr = malloc(strct_len);
memcpy(ptr, src, strct_len);
return ptr;
}
+static inline PSI_Token *PSI_TokenCat(unsigned argc, ...) {
+ va_list argv;
+ unsigned i;
+ PSI_Token *T = NULL;
+
+ va_start(argv, argc);
+ for (i = 0; i < argc; ++i) {
+ PSI_Token *arg = va_arg(argv, PSI_Token *);
+
+ if (T) {
+ size_t token_len = T->size, fname_len = strlen(T->file);
+
+ T = realloc(T, PSI_TokenAllocSize(T->size += arg->size + 1, fname_len));
+ T->text = &T->buf[0];
+ T->file = &T->buf[T->size + 1];
+ T->buf[token_len] = ' ';
+ memmove(&T->buf[T->size + 1], &T->buf[token_len + 1], fname_len + 1);
+ memcpy(&T->buf[token_len + 1], arg->text, arg->size + 1);
+ } else {
+ T = PSI_TokenCopy(arg);
+ T->type = PSI_T_NAME;
+ }
+ }
+ va_end(argv);
+
+ return T;
+}
+
static inline const char *PSI_TokenLocation(PSI_Token *t) {
return t ? t->file : "<builtin>:0:0";
}