+typedef int token_t;
+
+typedef struct PSI_Token {
+ token_t type;
+ unsigned line;
+ size_t size;
+ char text[1];
+} PSI_Token;
+
typedef struct decl_type {
- text *name;
+ char *name;
token_t type;
+ struct decl_type *real;
} decl_type;
-static inline decl_type *init_decl_type(token_t type, text *name) {
+static inline decl_type *init_decl_type(token_t type, char *name) {
decl_type *t = malloc(sizeof(*t));
t->type = type;
t->name = strdup(name);
decl_type *type;
} decl_typedef;
-static inline decl_typedef *init_decl_typedef(text *name, decl_type *type) {
+static inline decl_typedef *init_decl_typedef(char *name, decl_type *type) {
decl_typedef *t = malloc(sizeof(*t));
t->alias = strdup(name);
t->type = type;
}
typedef struct decl_var {
- text *name;
+ char *name;
unsigned pointer_level;
} decl_var;
-static inline decl_var *init_decl_var(text *name, unsigned pl) {
+static inline decl_var *init_decl_var(char *name, unsigned pl) {
decl_var *v = malloc(sizeof(*v));
- v->name = (text *) strdup((const char *) name);
+ v->name = (char *) strdup((const char *) name);
v->pointer_level = pl;
return v;
}
free(args);
}
+typedef struct decl_abi {
+ char *convention;
+} decl_abi;
+
+static inline decl_abi *init_decl_abi(char *convention) {
+ decl_abi *abi = malloc(sizeof(*abi));
+ abi->convention = strdup(convention);
+ return abi;
+}
+
+static inline void free_decl_abi(decl_abi *abi) {
+ free(abi->convention);
+ free(abi);
+}
+
typedef struct decl {
+ decl_abi *abi;
decl_arg *func;
decl_args *args;
+ void *dlptr;
} decl;
-static inline decl* init_decl(decl_arg *func, decl_args *args) {
+static inline decl* init_decl(decl_abi *abi, decl_arg *func, decl_args *args) {
decl *d = malloc(sizeof(*d));
+ d->abi = abi;
d->func = func;
d->args = args;
return d;
}
static inline void free_decl(decl *d) {
+ free_decl_abi(d->abi);
free_decl_arg(d->func);
free_decl_args(d->args);
free(d);
}
typedef struct impl_type {
- text *name;
+ char *name;
token_t type;
} impl_type;
-static inline impl_type *init_impl_type(token_t type, text *name) {
+static inline impl_type *init_impl_type(token_t type, char *name) {
impl_type *t = malloc(sizeof(*t));
t->type = type;
- t->name = (text *) strdup((const char *) name);
+ t->name = (char *) strdup((const char *) name);
return t;
}
}
typedef struct impl_var {
- text *name;
+ char *name;
unsigned reference:1;
} impl_var;
-static inline impl_var *init_impl_var(text *name, int is_reference) {
+static inline impl_var *init_impl_var(char *name, int is_reference) {
impl_var *var = malloc(sizeof(*var));
- var->name = (text *) strdup((const char *) name);
+ var->name = (char *) strdup((const char *) name);
var->reference = is_reference;
return var;
}
}
typedef struct impl_func {
- text *name;
+ char *name;
impl_args *args;
impl_type *return_type;
} impl_func;
-static inline impl_func *init_impl_func(text *name, impl_args *args, impl_type *type) {
+static inline impl_func *init_impl_func(char *name, impl_args *args, impl_type *type) {
impl_func *func = malloc(sizeof(*func));
func->name = strdup(name);
func->args = args ? args : init_impl_args(NULL);
typedef struct let_func {
token_t type;
- text *name;
+ char *name;
} let_func;
-static inline let_func *init_let_func(token_t type, text *name) {
+static inline let_func *init_let_func(token_t type, char *name) {
let_func *func = malloc(sizeof(*func));
func->type = type;
- func->name = (text *) strdup((const char *) name);
+ func->name = (char *) strdup((const char *) name);
return func;
}
typedef struct set_func {
token_t type;
- text *name;
+ char *name;
} set_func;
-static inline set_func *init_set_func(token_t type, text *name) {
+static inline set_func *init_set_func(token_t type, char *name) {
set_func *func = malloc(sizeof(*func));
func->type = type;
- func->name = (text *) strdup((const char *) name);
+ func->name = (char *) strdup((const char *) name);
return func;
}
free(impls->list);
free(impls);
}
+
+typedef struct PSI_Data {
+ decl_typedefs *defs;
+ decls *decls;
+ impls *impls;
+ char *lib;
+ char *fn;
+} PSI_Data;
+
+EXPORT static inline void PSI_DataExchange(PSI_Data *dest, PSI_Data *src) {
+ memcpy(dest, src, sizeof(*dest));
+ memset(src, 0, sizeof(*src));
+}
+
+EXPORT static inline void PSI_DataDtor(PSI_Data *data) {
+ if (data->defs) {
+ free_decl_typedefs(data->defs);
+ }
+ if (data->decls) {
+ free_decls(data->decls);
+ }
+ if (data->impls) {
+ free_impls(data->impls);
+ }
+ if (data->fn) {
+ free(data->fn);
+ }
+}