}
ANN m_str get_type_name(const Env env, const Type t, const m_uint index) {
- const m_str s = t->name;
- m_str name = strstr(s, "<");
- m_uint i = 0;
+ if(!index || t->name[0] != '<')
+ return NULL;
+ m_str name = t->name + 2;
m_uint lvl = 0;
m_uint n = 1;
- const size_t len = name ? strlen(name) : 0;
- const size_t slen = strlen(s);
- const size_t tlen = slen - len + 1;
- char c[slen + 1];
- if(!name)
- return index ? NULL : s_name(insert_symbol(s));
- if(index == 0) {
- snprintf(c, tlen, "%s", s);
- return s_name(insert_symbol(c));
- }
- ++name;
- while(*name++) {
- if(*name == '<') {
- if(n == index)
- c[i++] = *name;
- lvl++;
- name++;
- } else if(*name == '~' && !lvl--)
- break;
+ const size_t slen = strlen(name);
+ char c, buf[slen + 1], *tmp = buf;
+ while((c = *name)) {
+ if(c == '<')
+ ++lvl;
+ else if(c == '>') {
+ if(!lvl-- && n == index) {
+ --tmp;
+ break;
+ }
+ } else if(c == ',') {
+ if(!lvl && n++ == index)
+ break;
+ if(!lvl)
+ ++name;
+ }
if(n == index)
- c[i++] = *name;
+ *tmp++ = *name;
+ ++name;
+
}
- c[i] = '\0';
- return strlen(c) ? s_name(insert_symbol(c)) : NULL;
+ *tmp = '\0';
+ return strlen(buf) ? s_name(insert_symbol(buf)) : NULL;
}
ANN m_uint get_depth(const Type type) {
ANN static ssize_t template_size(const Env env, struct tmpl_info* info) {
ID_List base = info->cdef->base.tmpl->list;
Type_List call = info->call;
- size_t size = tmpl_set(info, info->cdef->base.type);
+ size_t size = 0;
do {
DECL_OB(const Type, t, = known_type(env, call->td))
size += tmpl_set(info, t);
} while((call = call->next) && (base = base->next) && ++size);
+ size += tmpl_set(info, info->cdef->base.type);
return size + 16 + 3;
}
ANN static void template_name(struct tmpl_info* info, m_str s) {
m_str str = s;
- str = tmpl_get(info, str);
*str++ = '<';
*str++ = '~';
- const m_uint size = vector_size(&info->type);
- for(info->index = 1; info->index < size; ++info->index) {
+ const m_uint size = vector_size(&info->type) -1;
+ for(info->index = 0; info->index < size; ++info->index) {
str = tmpl_get(info, str);
if(info->index < size - 1)
*str++ = ',';
*str++ = '>';
}
}
+ str = tmpl_get(info, str);
*str = '\0';
}
#ifdef __AFL_HAVE_MANUAL_CONTROL
-#define BUFSIZE 128
+#define BUFSIZE 4
static void afl_run(const Gwion gwion) {
__AFL_INIT();
struct GwText_ text = { .mp=gwion->mp };
while (__AFL_LOOP(256)) {
ssize_t sz;
- memset(buf, 0, BUFSIZE);
- while((sz = read(0, buf, BUFSIZE)) > 0) {
- buf[sz] = '\0';
+ while((sz = read(0, buf, BUFSIZE-1)) > 0) {
+buf[sz] = '\0';
text_add(&text, buf);
}
if(compile_string(gwion, "afl", text.str)) {
ANN static Type op_parent(const Env env, const Type t) {
if(GET_FLAG(t, template) && GET_FLAG(t, ref)) {
const Type type = typedef_base(t);
- const m_str post = strstr(type->name, "<");
- size_t len = strlen(type->name) - strlen(post);
- char c[len + 1];
- for(size_t i = 0; i < len; i++)
- c[i] = type->name[i];
- c[len] = 0;
- return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, c));
+ const m_str post = strrchr(type->name, '>') + 1;
+ return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, post));
}
return t->e->parent;
}