SCF_OP_DEREFERENCE, // * pointer dereference
SCF_OP_ARRAY_INDEX, // [] array index
+ // 45
SCF_OP_Q_MASK, // ?
SCF_OP_COLON, // :
SCF_OP_COMMA, // , comma operator
assert(child->op->nb_operands > child->nb_nodes);
child->parent = parent->parent;
- if (scf_node_add_child(child, parent) < 0)
+ if (scf_node_add_child(child, parent) < 0) {
+ scf_loge("\n");
return -1;
+ }
*pparent = child;
return 0;
}
// parent->priority == child->priority
- scf_logi("parent: %p, parent->type: %d, FOR: %d, SCF_VAR_INT: %d\n", parent, parent->type, SCF_OP_FOR, SCF_VAR_INT);
+ scf_logd("parent: %p, parent->type: %d, FOR: %d, SCF_VAR_INT: %d\n", parent, parent->type, SCF_OP_FOR, SCF_VAR_INT);
assert(parent->op);
assert(child->op);
assert(parent->nb_nodes >= 1);
if (SCF_OP_COLON == child->type && parent->nb_nodes > 1) {
- if (SCF_OP_Q_MASK != parent->type)
- return -EINVAL;
+
+ switch (parent->type)
+ {
+ case SCF_OP_Q_MASK:
+ case SCF_OP_COLON:
+ scf_logd("parent->type: %d, child->type: %d\n", parent->type, child->type);
+ break;
+
+ default:
+ scf_loge("parent->type: %d, %d\n", parent->type, SCF_OP_COLON);
+ return -EINVAL;
+ break;
+ };
scf_node_t* right = parent->nodes[1];
+ scf_logd("parent: %d, child: %d, right: %d\n", parent->type, child->type, right->type);
+
if (SCF_OP_Q_MASK == right->type
&& right->nb_nodes > 1
&& SCF_OP_COLON == right->nodes[1]->type) {
return -1;
}
- if (__expr_node_add_node(&(e->nodes[0]), node) < 0)
+ if (__expr_node_add_node(&(e->nodes[0]), node) < 0) {
+ scf_loge("\n");
return -1;
+ }
e->nodes[0]->parent = e;
e->nb_nodes = 1;
SCF_LEX_WORD_KEY_FLOAT, // float
SCF_LEX_WORD_KEY_DOUBLE, // double
- SCF_LEX_WORD_KEY_INT8, // int8_t
SCF_LEX_WORD_KEY_INT1, // int1_t
SCF_LEX_WORD_KEY_INT2, // int2_t
SCF_LEX_WORD_KEY_INT3, // int3_t
SCF_LEX_WORD_KEY_INT4, // int4_t
- SCF_LEX_WORD_KEY_INT16, // int16_t
- SCF_LEX_WORD_KEY_INT32, // int32_t
- SCF_LEX_WORD_KEY_INT64, // int64_t
- SCF_LEX_WORD_KEY_UINT8, // uint8_t
SCF_LEX_WORD_KEY_BIT, // bit
SCF_LEX_WORD_KEY_BIT2, // bit2_t
SCF_LEX_WORD_KEY_BIT3, // bit3_t
SCF_LEX_WORD_KEY_BIT4, // bit4_t
+#if 0
+ SCF_LEX_WORD_KEY_INT8, // int8_t
+ SCF_LEX_WORD_KEY_INT16, // int16_t
+ SCF_LEX_WORD_KEY_INT32, // int32_t
+ SCF_LEX_WORD_KEY_INT64, // int64_t
+
+ SCF_LEX_WORD_KEY_UINT8, // uint8_t
SCF_LEX_WORD_KEY_UINT16, // uint16_t
SCF_LEX_WORD_KEY_UINT32, // uint32_t
SCF_LEX_WORD_KEY_UINT64, // uint64_t
SCF_LEX_WORD_KEY_INTPTR, // intptr_t
SCF_LEX_WORD_KEY_UINTPTR, // uintptr_t
-
+#endif
SCF_LEX_WORD_KEY_VOID, // void
SCF_LEX_WORD_KEY_VA_START, // va_start
// const literal value
SCF_LEX_WORD_CONST_CHAR,
+ SCF_LEX_WORD_CONST_WCHAR,
SCF_LEX_WORD_CONST_INT,
SCF_LEX_WORD_CONST_U32,
SCF_LEX_WORD_CONST_DOUBLE,
SCF_LEX_WORD_CONST_COMPLEX,
+ SCF_LEX_WORD_CONST_WSTRING,
SCF_LEX_WORD_CONST_STRING,
SCF_LEX_WORD_ID, // identity, start of _, a-z, A-Z, may include 0-9
uint32_t _3ac_done :1; // set when node's 3ac code is made
uint32_t semi_flag :1; // set when followed by a ';'
- uint32_t call_flag :1; // set when followed by a '(' of function call()
+ uint32_t pause_flag :1; // set when followed by a '(' of function call(), sizeof(), etc... only for expr.
};
struct scf_label_s {
int j;
for (i = 0; i < nb_nodes; i++) {
node = nodes[i];
- op = node->op;
+
+ if (scf_type_is_var(node->type))
+ continue;
+
+ op = node->op;
if (!op) {
op = scf_find_base_operator_by_type(node->type);
dst = c ->dsts->data[i];
v = _scf_operand_get(dst->node);
- dst->node->type = v->type;
- dst->node->var = v;
- dst->node->result = NULL;
+// dst->node->type = v->type;
+// dst->node->var = v;
+// dst->node->result = NULL;
dst->node->split_flag = 0;
c3 = scf_3ac_code_NN(SCF_OP_ASSIGN, &dst->node, 1, &src->node, 1);
v->refs = 1;
v->type = t->node.type;
+ v->t = t;
v->const_flag = t->node.const_flag;
v->nb_pointers = t->nb_pointers;
memcpy(&v2->data, &v->data, sizeof(v->data));
v2->type = v->type;
+ v2->t = v->t;
v2->const_literal_flag = v->const_literal_flag;
v2->const_flag = v->const_flag;
int type; // type
scf_lex_word_t* w; // lex word
+ scf_type_t* t;
+
int nb_pointers; // Multiple pointer count
scf_function_t* func_ptr;
return SCF_VAR_CHAR == v->type && 1 == v->nb_pointers + v->nb_dimentions;
}
+static inline int scf_variable_void(scf_variable_t* v)
+{
+ return SCF_VAR_VOID == v->type && 0 == v->nb_pointers && 0 == v->nb_dimentions;
+}
+
static inline int scf_variable_float(scf_variable_t* v)
{
return scf_type_is_float(v->type) && 0 == v->nb_pointers && 0 == v->nb_dimentions;
--- /dev/null
+struct A
+{
+ long x;
+ int :8;
+};
+
+int main()
+{
+ return 0;
+}
#include<assert.h>
#include<errno.h>
#include<stdarg.h>
+#include<stdint.h>
+#include<time.h>
+#include<math.h>
int main()
{
--- /dev/null
+#include<stdio.h>
+#include<math.h>
+
+int main()
+{
+ double angle = M_PI / 3.0;
+
+ printf("hello, sin(%lg): %lg, isnan(0.0/0.0): %d\n", angle, sin(angle), isnan(0.0/0.0));
+ return 0;
+}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<stddef.h>
+#include<string.h>
+#include<assert.h>
+#include<errno.h>
+#include<stdarg.h>
+#include<stdint.h>
+#include<time.h>
+
+int main()
+{
+ time_t t = 0;
+
+ time(&t);
+
+ printf("hello, time: %ld\n", t);
+ return 0;
+}
{SCF_CSTR("bit3_t"), SCF_LEX_WORD_KEY_BIT3},
{SCF_CSTR("bit4_t"), SCF_LEX_WORD_KEY_BIT4},
- {SCF_CSTR("int8_t"), SCF_LEX_WORD_KEY_INT8},
{SCF_CSTR("int1_t"), SCF_LEX_WORD_KEY_INT1},
{SCF_CSTR("int2_t"), SCF_LEX_WORD_KEY_INT2},
{SCF_CSTR("int3_t"), SCF_LEX_WORD_KEY_INT3},
{SCF_CSTR("int4_t"), SCF_LEX_WORD_KEY_INT4},
+#if 0
+ {SCF_CSTR("int8_t"), SCF_LEX_WORD_KEY_INT8},
{SCF_CSTR("int16_t"), SCF_LEX_WORD_KEY_INT16},
{SCF_CSTR("int32_t"), SCF_LEX_WORD_KEY_INT32},
{SCF_CSTR("int64_t"), SCF_LEX_WORD_KEY_INT64},
{SCF_CSTR("intptr_t"), SCF_LEX_WORD_KEY_INTPTR},
{SCF_CSTR("uintptr_t"), SCF_LEX_WORD_KEY_UINTPTR},
-
+#endif
{SCF_CSTR("void"), SCF_LEX_WORD_KEY_VOID},
{SCF_CSTR("container"), SCF_LEX_WORD_KEY_CONTAINER},
scf_lex_word_t* w = NULL;
- if (SCF_CSTR_CMP(s, "NULL")) {
+ if (SCF_CSTR_EQ(s, "NULL")) {
w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_U64);
if (w)
w->data.u64 = 0;
- } else if (SCF_CSTR_CMP(s, "__LINE__")) {
+ } else if (SCF_CSTR_EQ(s, "__LINE__")) {
w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_U64);
if (w)
w->data.u64 = lex->nb_lines;
- } else if (SCF_CSTR_CMP(s, "__FILE__")) {
+ } else if (SCF_CSTR_EQ(s, "__FILE__")) {
w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_STRING);
if (w)
w->data.s = scf_string_clone(lex->file);
- } else if (SCF_CSTR_CMP(s, "__func__")) {
+ } else if (SCF_CSTR_EQ(s, "__func__")) {
w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_STRING);
return -1;
}
-static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
+static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s, scf_char_t* c0)
{
- scf_string_t* s = NULL;
scf_lex_word_t* w = NULL;
scf_char_t* c1 = _lex_pop_char(lex);
scf_char_t* c2 = _lex_pop_char(lex);
c3 = _lex_pop_char(lex);
if ('\'' == c3->c) {
- s = scf_string_cstr_len(c0->utf8, 1);
+ if (!s)
+ s = scf_string_cstr_len(c0->utf8, 1);
+ else
+ scf_string_cat_cstr_len(s, c0->utf8, 1);
scf_string_cat_cstr_len(s, c1->utf8, 1);
scf_string_cat_cstr_len(s, c2->utf8, c2->len);
c3 = NULL;
} else if ('\'' == c2->c) {
- s = scf_string_cstr_len(c0->utf8, 1);
+ if (!s)
+ s = scf_string_cstr_len(c0->utf8, 1);
+ else
+ scf_string_cat_cstr_len(s, c0->utf8, 1);
scf_string_cat_cstr_len(s, c1->utf8, c1->len);
scf_string_cat_cstr_len(s, c2->utf8, 1);
free(c1);
free(c2);
- if (!w)
+ if (!w) {
+ scf_string_free(s);
return -1;
+ }
w->text = s;
*pword = w;
return 0;
}
+static int _lex_wchar(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0, scf_char_t* c1)
+{
+ scf_string_t* s = scf_string_cstr_len(c0->utf8, 1);
+
+ free(c0);
+ c0 = NULL;
+
+ if (!s) {
+ free(c1);
+ return -ENOMEM;
+ }
+
+ int ret = _lex_char(lex, pword, s, c1);
+ if (ret < 0)
+ return ret;
+
+ (*pword)->type = SCF_LEX_WORD_CONST_WCHAR;
+ return 0;
+}
+
static int _lex_string(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
{
scf_lex_word_t* w = NULL;
return _lex_dot(lex, pword, c);
if ('\'' == c->c)
- return _lex_char(lex, pword, c);
+ return _lex_char(lex, pword, NULL, c);
if ('\"' == c->c) {
scf_lex_word_t* w0 = NULL;
if ('0' <= c->c && '9' >= c->c)
return _lex_number(lex, pword, c);
+ if ('L' == c->c || 'l' == c->c)
+ {
+ scf_char_t* c1 = _lex_pop_char(lex);
+ if (!c1) {
+ free(c);
+ return -ENOMEM;
+ }
+
+ if ('\'' == c1->c)
+ return _lex_wchar(lex, pword, c, c1);
+
+ _lex_push_char(lex, c1);
+ c1 = NULL;
+ }
+
if ('_' == c->c
|| ('a' <= c->c && 'z' >= c->c)
|| ('A' <= c->c && 'Z' >= c->c)
scf_lex_word_t* w1 = NULL;
int ret = __lex_drop_space(lex, &w);
- if (ret < 0)
+ if (ret < 0) {
+ scf_loge("\n");
return ret;
+ }
// parse macro
while (SCF_LEX_WORD_HASH == w->type) {
ret = __lex_drop_space(lex, &w1);
if (ret < 0) {
+ scf_loge("\n");
scf_lex_word_free(w);
return ret;
}
w = NULL;
w1 = NULL;
- if (ret < 0)
+ if (ret < 0) {
+ scf_loge("\n");
return ret;
+ }
ret = __lex_drop_space(lex, &w);
- if (ret < 0)
+ if (ret < 0) {
+ scf_loge("\n");
return ret;
+ }
}
// use macro to pre-process source code
ret = __lex_use_macro(lex, &w);
- if (ret < 0)
+ if (ret < 0) {
+ scf_loge("\n");
return ret;
+ }
end:
if (SCF_C99 == lex->c_version
&& SCF_LEX_WORD_ID == w->type
- && (SCF_CSTR_CMP(w->text, "restrict")
- || SCF_CSTR_CMP(w->text, "__restrict")
- || SCF_CSTR_CMP(w->text, "__restrict__"))) {
+ && (SCF_CSTR_EQ(w->text, "restrict")
+ || SCF_CSTR_EQ(w->text, "__restrict")
+ || SCF_CSTR_EQ(w->text, "__restrict__"))) {
scf_lex_word_free(w);
w = NULL;
} scf_key_word_t;
#define SCF_CSTR(_cstr) (_cstr), (sizeof(_cstr) - 1)
-#define SCF_CSTR_CMP(_s, _cstr) (sizeof(_cstr) - 1 == (_s)->len && !memcmp((_s)->data, (_cstr), sizeof(_cstr) - 1))
+#define SCF_CSTR_EQ(_s, _cstr) (sizeof(_cstr) - 1 == (_s)->len && !memcmp((_s)->data, (_cstr), sizeof(_cstr) - 1))
+#define SCF_CSTR_NE(_s, _cstr) (sizeof(_cstr) - 1 != (_s)->len || memcmp((_s)->data, (_cstr), sizeof(_cstr) - 1))
typedef struct {
int origin;
} else if ('-' == tmp) {
if (0 == exp || ++neg > 1) {
- scf_loge("\n");
- goto error;
+
+ _lex_push_char(lex, c2);
+ c2 = NULL;
+ break;
}
} else if ('_' == c2->c) {
if (ret < 0)
return ret;
- if (SCF_LEX_WORD_ID == w0->type && !strcmp(w0->text->data, "defined"))
+ if (SCF_LEX_WORD_ID == w0->type && SCF_CSTR_NE(w0->text, "defined")) {
+
+ ret = __lex_use_macro(lex, &w0);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (SCF_LEX_WORD_ID == w0->type && SCF_CSTR_EQ(w0->text, "defined"))
w0->type = SCF_LEX_WORD_KEY_DEFINED;
switch (w0->type)
return ret;
break;
- case SCF_LEX_WORD_ID:
- ret = __lex_use_macro(lex, &w0);
- if (ret < 0)
- return ret;
-
default:
- scf_logd("w0: %s, w0->data.u64: %ld\n", w0->text->data, w0->data.u64);
+ scf_logi("w0: %s, w0->data.u64: %ld\n", w0->text->data, w0->data.u64);
*operand = w0;
if (ret < 0) \
return ret; \
\
- if (!scf_lex_is_const_integer(w0) && !scf_lex_is_identity(w0)) \
+ if (!scf_lex_is_const_integer(w0) && !scf_lex_is_identity(w0)) { \
+ scf_loge("#1 op: %s, w0: %s, line: %d, pos: %d\n\n", w_op->text->data, w0->text->data, w_op->line, w_op->pos); \
return -EINVAL; \
- \
- if (!scf_lex_is_const_integer(w1) && !scf_lex_is_identity(w1)) \
+ } \
+ if (!scf_lex_is_const_integer(w1) && !scf_lex_is_identity(w1)) { \
+ scf_loge("#2 op: %s, w1: %s:%ld, line: %d, pos: %d\n\n", w_op->text->data, w1->text->data, w1->data.i64, w_op->line, w_op->pos); \
return -EINVAL; \
- \
+ } \
w0->data.i64 = w0->data.i64 op w1->data.i64; \
scf_logd("op: %s, result: %ld, line: %d, pos: %d\n\n", w_op->text->data, w0->data.i64, w_op->line, w_op->pos); \
\
if (!scf_lex_is_const_integer(w0) && !scf_lex_is_identity(w0))
return -EINVAL;
+ scf_logw("%s:%d:%d, w0: '%s':%ld\n", w_op->file->data, w_op->line, w_op->pos, w0->text->data, w0->data.i64);
+
ret = __lex_drop_space(lex, &op2);
if (ret < 0)
return ret;
{
int ret;
+ if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_NE(w->text, "defined")) {
+
+ ret = __lex_use_macro(lex, &w);
+ if (ret < 0)
+ return ret;
+ }
+
if (SCF_LEX_WORD_EOF == w->type) {
scf_loge("\n");
return -EINVAL;
}
- if (SCF_LEX_WORD_ID == w->type && !strcmp(w->text->data, "defined"))
+ if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_EQ(w->text, "defined"))
w->type = SCF_LEX_WORD_KEY_DEFINED;
if (scf_lex_is_operator(w)) {
return f(lex, ctx, w, n_consts, operand);
}
- if (SCF_LEX_WORD_ID == w->type) {
-
- ret = __lex_use_macro(lex, &w);
- if (ret < 0)
- return ret;
- }
-
*operand = w;
w->next = NULL;
if (ret < 0)
goto error;
+ if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_NE(w->text, "defined")) {
+
+ ret = __lex_use_macro(lex, &w);
+ if (ret < 0)
+ goto error;
+ }
+
if (SCF_LEX_WORD_LF == w->type) {
scf_lex_word_free(w);
w = NULL;
goto error;
}
- if (SCF_LEX_WORD_ID == w->type && !strcmp(w->text->data, "defined"))
+ if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_EQ(w->text, "defined"))
w->type = SCF_LEX_WORD_KEY_DEFINED;
if (scf_lex_is_operator(w)) {
*ctx.pp = w;
ctx.pp = &w->next;
+ scf_logi("%s:%d:%d, w->text: %s, operand: %p\n", w->file->data, w->line, w->pos, w->text->data, operand);
+
if (operand)
ret = f(lex, &ctx, w, 2, &operand);
else
ret = f(lex, &ctx, w, 1, &operand);
w = NULL;
- if (ret < 0)
+ if (ret < 0) {
+ scf_loge("\n");
goto error;
+ }
continue;
}
- if (SCF_LEX_WORD_ID == w->type) {
-
- ret = __lex_use_macro(lex, &w);
- if (ret < 0)
- goto error;
- }
-
if (!scf_lex_is_const_integer(w) && !scf_lex_is_identity(w)) {
scf_loge("operand '%s' is NOT CONST in macro expr, file: %s, line: %d\n",
if (!dst || !dst->dag_node)
return -EINVAL;
+ scf_variable_t* vd = dst->dag_node->var;
+ scf_variable_t* vs = src->dag_node->var;
+
+ if (scf_variable_void(vs) || scf_variable_void(vd))
+ return 0;
+
if (0 == dst->dag_node->color)
return -EINVAL;
return -ENOMEM;
}
- scf_x64_OpCode_t* lea;
- scf_instruction_t* inst;
-
- scf_register_t* rd = NULL;
- scf_rela_t* rela = NULL;
-
- scf_variable_t* vd = dst->dag_node->var;
- scf_variable_t* vs = src->dag_node->var;
-
int src_size = x64_variable_size(vs);
int dst_size = x64_variable_size(vd);
scf_logw("src_size: %d, dst_size: %d\n", src_size, dst_size);
- if (src->dag_node->var->nb_dimentions > 0)
+ if (vs->nb_dimentions > 0)
return x64_inst_op2(SCF_X64_LEA, dst->dag_node, src->dag_node, c, f);
return x64_inst_op2(SCF_X64_MOV, dst->dag_node, src->dag_node, c, f);
{
"/lib64/ld-linux-x86-64.so.2",
"libc.so.6",
+ "libm.so.6",
};
static char* __arm64_objs[] =
scf_expr_t* grand = scf_stack_top(d->lp_exprs);
if (grand) {
- grand->call_flag = 1;
+ grand->pause_flag = 1;
- scf_logi("grand: %p, grand->call_flag: %d\n", grand, grand->call_flag);
+ scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag);
}
cd->func = node_pf;
scf_expr_t* grand = scf_stack_top(d->lp_exprs);
if (grand) {
- grand->call_flag = 0;
+ grand->pause_flag = 0;
- scf_logi("grand: %p, grand->call_flag: %d\n", grand, grand->call_flag);
+ scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag);
}
free(cd);
continue;
}
- t = scf_scope_find_type_type(s->scope, v->type);
+ t = v->t;
assert(t);
if (t->scope->vars->size <= 0) {
size = v->offset + v->size;
}
- scf_logi("class '%s', member: '%s', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n",
- s->name->data, v->w->text->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size);
+ if (v->w)
+ scf_logi("class '%s', member: '%s', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n",
+ s->name->data, v->w->text->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size);
+ else
+ scf_logi("class '%s', member: 'anonymous', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n",
+ s->name->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size);
}
switch (size) {
scf_expr_t* parent = scf_stack_top(d->lp_exprs);
if (parent) {
- scf_logi("d->expr: %p, parent: %p, parent->call_flag: %d\n\n", d->expr, parent, parent->call_flag);
+ scf_logi("d->expr: %p, parent: %p, parent->pause_flag: %d\n\n", d->expr, parent, parent->pause_flag);
- if (!parent->call_flag) {
+ if (!parent->pause_flag) {
scf_stack_pop(d->lp_exprs);
scf_expr_add_node(parent, d->expr);
SCF_DFA_GET_MODULE_NODE(dfa, function, pf_rp, pf_rp);
SCF_DFA_GET_MODULE_NODE(dfa, type, _const, _const);
+ SCF_DFA_GET_MODULE_NODE(dfa, type, _struct, _struct);
SCF_DFA_GET_MODULE_NODE(dfa, type, base_type, base_type);
SCF_DFA_GET_MODULE_NODE(dfa, identity, identity, type_name);
// function args
scf_dfa_node_add_child(lp, _const);
+ scf_dfa_node_add_child(lp, _struct);
scf_dfa_node_add_child(lp, base_type);
scf_dfa_node_add_child(lp, type_name);
scf_dfa_node_add_child(lp, rp);
scf_dfa_node_add_child(star, rp);
scf_dfa_node_add_child(comma, _const);
+ scf_dfa_node_add_child(comma, _struct);
scf_dfa_node_add_child(comma, base_type);
scf_dfa_node_add_child(comma, type_name);
scf_dfa_node_add_child(comma, vargs);
t = md->current_type;
if (!t) {
- int ret = scf_ast_find_type_type(&t, parse->ast, d->current_var->type);
- if (ret < 0)
- return ret;
+ t = d->current_var->t;
if (!t->scope) {
scf_loge("base type '%s' has no member var '%s', file: %s, line: %d\n",
return SCF_DFA_ERROR;
}
- if (v->type >= SCF_STRUCT) {
- t = scf_scope_find_type_type(t->scope, v->type);
-
- if (!t) {
- int ret = scf_ast_find_type_type(&t, parse->ast, v->type);
- if (ret < 0)
- return ret;
- if (!t)
- return SCF_DFA_ERROR;
- }
-
- md->current_type = t;
- }
+ if (v->type >= SCF_STRUCT)
+ md->current_type = v->t;
md->current_index[md->current_dim].w = w;
scf_logd("d->expr: %p\n", d->expr);
+ scf_expr_t* grand = scf_stack_top(d->lp_exprs);
+ if (grand) {
+ grand->pause_flag = 1;
+
+ scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag);
+ }
+
sd->_sizeof = _sizeof;
sd->parent_expr = d->expr;
d->expr = NULL;
d->expr_local_flag--;
d->nb_sizeofs--;
- scf_logi("d->expr: %p, d->nb_sizeofs: %d\n", d->expr, d->nb_sizeofs);
+ scf_logd("d->expr: %p, d->nb_sizeofs: %d\n", d->expr, d->nb_sizeofs);
+
+ scf_expr_t* grand = scf_stack_top(d->lp_exprs);
+ if (grand) {
+ grand->pause_flag = 0;
+
+ scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag);
+ }
free(sd);
sd = NULL;
ap = scf_block_find_variable(parse->ast->current_block, w->text->data);
if (!ap) {
- scf_loge("va_list variable %s not found\n", w->text->data);
- return SCF_DFA_ERROR;
+ scf_logw("'%s' not a va_list variable\n", w->text->data);
+ return SCF_DFA_NEXT_SYNTAX;
}
if (scf_ast_find_type(&t, parse->ast, "__builtin_va_list") < 0) {
fmt = scf_block_find_variable(parse->ast->current_block, w->text->data);
if (!fmt) {
- scf_loge("format string %s not found\n", w->text->data);
- return SCF_DFA_ERROR;
+ scf_logw("'%s' not a format string\n", w->text->data);
+ return SCF_DFA_NEXT_SYNTAX;
}
if (SCF_VAR_CHAR != fmt->type
// va_arg(ap, type)
scf_dfa_node_add_child(arg, lp);
- scf_dfa_node_add_child(ap, type);
+ scf_dfa_node_add_child(comma, type);
scf_dfa_node_add_child(base_type, rp);
scf_dfa_node_add_child(identity, rp);
}
}
- // anonymous var only used in function args!!
- if (!w && !d->arg_flag)
+ // anonymous var only used in function args or bit fields
+ if (!w && !d->arg_flag && !d->bit_field_flag) {
+ scf_logi("\n");
return 0;
+ }
assert(d->current_identities->size >= 1);
id0 = d->current_identities->data[0];
scf_parse_t* parse = dfa->priv;
dfa_data_t* d = data;
+ d->bit_field_flag = 1;
+
if (_var_add_var(dfa, d) < 0) {
scf_loge("add var error\n");
return SCF_DFA_ERROR;
return SCF_DFA_ERROR;
}
+ d->expr_local_flag++;
+
+ SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "var_semi_bits"), SCF_DFA_HOOK_POST);
+
return SCF_DFA_NEXT_WORD;
}
-static int _var_action_bits(scf_dfa_t* dfa, scf_vector_t* words, void* data)
+static int _var_action_semi_bits(scf_dfa_t* dfa, scf_vector_t* words, void* data)
{
scf_parse_t* parse = dfa->priv;
dfa_data_t* d = data;
scf_lex_word_t* w = words->data[words->size - 1];
+ scf_variable_t* r = NULL;
+
+ while (d->current_identities->size > 0)
+ {
+ dfa_identity_t* id = scf_stack_pop(d->current_identities);
+
+ assert(id && id->type);
+
+ free(id);
+ id = NULL;
+ }
if (!d->current_var) {
scf_loge("\n");
}
if (!d->current_var->member_flag) {
- scf_loge("bits var '%s' must be a member of struct, file: %s, line: %d\n",
- d->current_var->w->text->data, d->current_var->w->file->data, d->current_var->w->line);
+ scf_loge("%s:%d:%d, bits var must be a member of struct\n", w->file->data, w->line, w->pos);
return SCF_DFA_ERROR;
}
- d->current_var->bit_size = w->data.u32;
- return SCF_DFA_NEXT_WORD;
+ if (!d->expr) {
+ scf_loge("%s:%d:%d, NOT found expr for bit-fields\n", w->file->data, w->line, w->pos);
+ return SCF_DFA_ERROR;
+ }
+
+ int ret = scf_expr_calculate(parse->ast, d->expr, &r);
+
+ scf_expr_free(d->expr);
+ d->expr = NULL;
+ if (ret < 0)
+ return ret;
+
+ if (!scf_variable_const_integer(r)) {
+ scf_loge("%s:%d:%d, expr for bit-fields NOT const\n", w->file->data, w->line, w->pos);
+
+ scf_variable_free(r);
+ return SCF_DFA_ERROR;
+ }
+
+ if (r->data.i < 0) {
+ scf_loge("%s:%d:%d, expr for bit-fields MUST >= 0\n", w->file->data, w->line, w->pos);
+
+ scf_variable_free(r);
+ return SCF_DFA_ERROR;
+ }
+
+ d->current_var->bit_size = r->data.i;
+
+ d->bit_field_flag = 0;
+
+ d->expr_local_flag--;
+
+ scf_variable_free(r);
+ r = NULL;
+ return SCF_DFA_OK;
}
static int _var_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data)
SCF_DFA_MODULE_NODE(dfa, var, assign, scf_dfa_is_assign, _var_action_assign);
SCF_DFA_MODULE_NODE(dfa, var, colon, scf_dfa_is_colon, _var_action_colon);
- SCF_DFA_MODULE_NODE(dfa, var, bits, scf_dfa_is_const_integer, _var_action_bits);
+ SCF_DFA_MODULE_NODE(dfa, var, semi_bits, scf_dfa_is_semicolon, _var_action_semi_bits);
return SCF_DFA_OK;
}
SCF_DFA_GET_MODULE_NODE(dfa, var, assign, assign);
SCF_DFA_GET_MODULE_NODE(dfa, var, colon, colon);
- SCF_DFA_GET_MODULE_NODE(dfa, var, bits, bits);
+ SCF_DFA_GET_MODULE_NODE(dfa, var, semi_bits, semi_bits);
SCF_DFA_GET_MODULE_NODE(dfa, type, star, star);
SCF_DFA_GET_MODULE_NODE(dfa, type, identity, identity);
scf_dfa_node_add_child(star, ls);
// bits
+ scf_dfa_node_add_child(base_type, colon); // anonymous bit-fields
scf_dfa_node_add_child(identity, colon);
- scf_dfa_node_add_child(colon, bits);
- scf_dfa_node_add_child(bits, semicolon);
+ scf_dfa_node_add_child(colon, expr);
+ scf_dfa_node_add_child(expr, semi_bits);
// var init
scf_dfa_node_add_child(rs, assign);
if (!op) {
op = scf_find_base_operator_by_type(node->type);
if (!op) {
- scf_loge("\n");
+ scf_loge("node->type: %d\n", node->type);
return -1;
}
}
for (i = 0; i < nb_nodes; i++) {
scf_node_t* node = nodes[i];
+ if (scf_type_is_var(node->type)) {
+ scf_logw("node->union_flag: %d\n", node->union_flag);
+ continue;
+ }
+
if (SCF_FUNCTION == node->type)
ret = __scf_op_const_call(ast, (scf_function_t*)node, data);
else
return -1;
}
- if (parent->result)
+ scf_variable_t* v = _scf_operand_get(node);
+
+ if (parent->result != v)
scf_variable_free(parent->result);
- scf_variable_t* v = _scf_operand_get(node);
if (v)
parent->result = scf_variable_ref(v);
else
return -1;
}
+static int _scf_const_rename(scf_variable_t* v)
+{
+ char buf[256];
+ int n = snprintf(buf, sizeof(buf) - 1, "c%d_%d_%lx", v->w->line, v->w->pos, (uintptr_t)v);
+
+ return scf_string_cat_cstr_len(v->w->text, buf, n);
+}
+
static int _scf_op_const_unary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
assert(1 == nb_nodes);
parent->type = r->type;
parent->var = r;
+ return _scf_const_rename(r);
} else {
scf_loge("type %d not support\n", v0->type);
return -1;
scf_node_free_data(parent);
parent->type = r->type;
parent->var = r;
+
+ return _scf_const_rename(r);
}
return 0;
}
assert(i < parent->nb_nodes);
- j = !!scf_zero_extend(v0->data.u64, v0->size);
+ j = !scf_zero_extend(v0->data.u64, v0->size);
+
+ scf_logd("v0->data.u64: %ld, j: %d\n", v0->data.u64, j);
colon ->nodes[j]->parent = parent;
parent->nodes[i] = colon->nodes[j];
return -EINVAL;
scf_variable_t* v_src = _scf_operand_get(src);
+ scf_type_t* t = v_src->t;
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v_src->type);
- if (ret < 0)
- return ret;
assert(t);
scf_variable_t* v = SCF_VAR_ALLOC_BY_TYPE(v_src->w, t, v_src->const_flag, v_src->nb_pointers + 1, v_src->func_ptr);
return -ENOMEM;
}
- ret = scf_node_add_child(address_of, src);
+ int ret = scf_node_add_child(address_of, src);
if (ret < 0) {
scf_variable_free(v);
scf_node_free(address_of);
static int _semantic_add_type_cast(scf_ast_t* ast, scf_node_t** pp, scf_variable_t* v_dst, scf_node_t* src)
{
scf_node_t* parent = src->parent;
+ scf_type_t* t = v_dst->t;
+
+ assert(t);
scf_operator_t* op = scf_find_base_operator_by_type(SCF_OP_TYPE_CAST);
if (!op)
return -EINVAL;
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v_dst->type);
- if (ret < 0)
- return ret;
- assert(t);
-
scf_variable_t* v_src = _scf_operand_get(src);
scf_variable_t* v = SCF_VAR_ALLOC_BY_TYPE(NULL, t, v_src->const_flag, v_dst->nb_pointers, v_dst->func_ptr);
if (!v)
return -ENOMEM;
}
- ret = scf_node_add_child(cast, dst);
+ int ret = scf_node_add_child(cast, dst);
if (ret < 0) {
scf_node_free(dst);
scf_node_free(cast);
for (i = 0; i < f->rets->size; i++) {
fret = f->rets->data[i];
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, fret->type);
- if (ret < 0)
- return ret;
+ t = fret->t;
assert(t);
r = SCF_VAR_ALLOC_BY_TYPE(parent->w, t, fret->const_flag, fret->nb_pointers, fret->func_ptr);
v = _scf_operand_get(nodes[i]);
if (!t && scf_variable_is_struct_pointer(v)) {
-
- t = NULL;
- ret = scf_ast_find_type_type(&t, ast, v->type);
- if (ret < 0)
- return ret;
+ t = v->t;
assert(t->scope);
}
if (scf_variable_is_struct(v)) {
if (!t) {
- t = NULL;
- ret = scf_ast_find_type_type(&t, ast, v->type);
- if (ret < 0)
- return ret;
+ t = v->t;
assert(t->scope);
}
scf_node_t* node_pf = NULL;
v0 = _scf_operand_get(nodes[0]);
-
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
+ t = v0->t;
pt = scf_block_find_type_type(ast->current_block, SCF_FUNCTION_PTR);
assert(t);
if (!node_pf)
return -ENOMEM;
- ret = scf_node_add_child(new, node_pf);
+ int ret = scf_node_add_child(new, node_pf);
if (ret < 0)
return ret;
assert(v1);
assert(v0->type >= SCF_STRUCT);
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v1->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v1->t;
scf_lex_word_t* w = nodes[0]->parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v1->const_flag, v1->nb_pointers, v1->func_ptr);
if (!r)
return -1;
}
- scf_type_t* t = NULL;
- ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v0->t;
scf_lex_word_t* w = nodes[0]->parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, nb_pointers, v0->func_ptr);
if (!r)
if (scf_variable_integer(v0) || scf_variable_float(v0)) {
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v0->t;
scf_lex_word_t* w = nodes[0]->parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr);
if (!r)
if (scf_variable_integer(v0) || scf_variable_float(v0)) {
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v0->t;
scf_lex_word_t* w = nodes[0]->parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr);
if (!r)
return -EINVAL;
}
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v0->t;
scf_lex_word_t* w = nodes[0]->parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, v0->nb_pointers - 1, v0->func_ptr);
if (!r)
return -EINVAL;
}
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v0->t;
scf_lex_word_t* w = nodes[0]->parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers + 1, v0->func_ptr);
if (!r)
scf_type_t* t;
- if (v0->nb_pointers + v0->nb_dimentions > 0) {
+ if (v0->nb_pointers + v0->nb_dimentions > 0)
t = scf_block_find_type_type(ast->current_block, SCF_VAR_UINTPTR);
- } else if (scf_type_is_integer(v0->type)) {
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
- } else {
+ else if (scf_type_is_integer(v0->type))
+ t = v0->t;
+ else {
scf_loge("\n");
return -1;
}
{
scf_variable_t* r;
scf_variable_t* v = _scf_operand_get(pointer);
- scf_type_t* t = NULL;
+ scf_type_t* t = v->t;
scf_node_t* add;
scf_node_t* neg;
- int ret = scf_ast_find_type_type(&t, ast, v->type);
- if (ret < 0)
- return ret;
-
add = scf_node_alloc(parent->w, SCF_OP_ARRAY_INDEX, NULL);
if (!add)
return -ENOMEM;
add->result = r;
r = NULL;
- ret = scf_node_add_child(add, pointer);
+ int ret = scf_node_add_child(add, pointer);
if (ret < 0) {
scf_node_free(add);
return ret;
}
v = _scf_operand_get(index);
-
- ret = scf_ast_find_type_type(&t, ast, v->type);
- if (ret < 0)
- goto error;
+ t = v->t;
r = SCF_VAR_ALLOC_BY_TYPE(parent->w, t, v->const_flag, 0, NULL);
if (!r) {
{
scf_variable_t* v = _scf_operand_get(pointer);
scf_variable_t* r = NULL;
- scf_type_t* t = NULL;
+ scf_type_t* t = v->t;
scf_node_t* p2;
scf_node_t* add;
- int ret = scf_ast_find_type_type(&t, ast, v->type);
- if (ret < 0)
- return ret;
+ int ret;
if (SCF_OP_ADD_ASSIGN == parent->type)
add = scf_node_alloc(parent->w, SCF_OP_ADD, NULL);
}
}
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
+ t = v0->t;
assert(t);
scf_lex_word_t* w = nodes[0]->parent->w;
}
}
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ t = v0->t;
const_flag = v0->const_flag;
nb_pointers = nb_pointers0;
func_ptr = v0->func_ptr;
}
}
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v1->type);
- if (ret < 0)
- return ret;
-
+ t = v1->t;
const_flag = v1->const_flag;
nb_pointers = nb_pointers1;
func_ptr = v1->func_ptr;
} else if (v0->type == v1->type) { // from here v0 & v1 are normal var
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ t = v0->t;
const_flag = v0->const_flag && v1->const_flag;
nb_pointers = 0;
func_ptr = NULL;
}
v0 = _scf_operand_get(nodes[0]);
-
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
+ t = v0->t;
r = SCF_VAR_ALLOC_BY_TYPE(w, t, const_flag, v0->nb_pointers, v0->func_ptr);
if (!r) {
if (scf_variable_is_struct_pointer(v0) && v1->w && strcmp(v1->w->text->data, "NULL")) {
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
+ scf_type_t* t = v0->t;
assert(t);
if (scf_scope_find_function(t->scope, "__init")) {
}
}
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
-
+ scf_type_t* t = v0->t;
scf_lex_word_t* w = parent->w;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr);
if (!r) {
}
}
- t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
+ t = v0->t;
assert(t);
r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr);
scf_handler_data_t* d = data;
- scf_type_t* t = NULL;
scf_variable_t* v0 = _scf_operand_get(nodes[0]);
scf_variable_t* v1 = _scf_operand_get(nodes[1]);
-
- int ret = scf_ast_find_type_type(&t, ast, v1->type);
- if (ret < 0)
- return ret;
+ scf_type_t* t = v1->t;
int const_flag = v0->const_flag && v1->const_flag;
scf_handler_data_t* d = data;
- scf_type_t* t = NULL;
scf_variable_t* v0 = _scf_operand_get(nodes[0]);
scf_variable_t* v1 = _scf_operand_get(nodes[1]);
+ scf_type_t* t = v1->t;
if (!scf_variable_integer(v0)) {
scf_loge("\n");
return -EINVAL;
}
- int ret = scf_ast_find_type_type(&t, ast, v1->type);
- if (ret < 0)
- return ret;
-
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(nodes[0]->parent->w, t, v1->const_flag, v1->nb_pointers, v1->func_ptr);
if (!r)
return -ENOMEM;
}
v0 = _scf_operand_get(nodes[0]);
-
- int ret = scf_ast_find_type_type(&t, ast, v0->type);
- if (ret < 0)
- return ret;
+ t = v0->t;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, v0->nb_pointers, v0->func_ptr);
if (!r)
if (d->pret) {
scf_variable_t* v = _scf_operand_get(nodes[1]);
-
- scf_type_t* t = NULL;
- int ret = scf_ast_find_type_type(&t, ast, v->type);
- if (ret < 0)
- return ret;
- assert(t);
-
+ scf_type_t* t = v->t;
scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(nodes[0]->parent->w, t, 0, v->nb_pointers, v->func_ptr);
if (!r)
return -ENOMEM;
if (t->scope) {
for (i = 0; i < t->scope->vars->size; i++) {
v_member = t->scope->vars->data[i];
- t_member = NULL;
-
- ret = scf_ast_find_type_type(&t_member, parse->ast, v_member->type);
- if (ret < 0)
- return ret;
+ t_member = v_member->t;
ie_member = _debug_find_type(parse, t_member, v_member->nb_pointers);
if (!ie_member) {
static int _debug_add_var(scf_parse_t* parse, scf_node_t* node)
{
scf_variable_t* var = node->var;
- scf_type_t* t = NULL;
+ scf_type_t* t = var->t;
- int ret = scf_ast_find_type_type(&t, parse->ast, var->type);
- if (ret < 0)
- return ret;
+ assert(t);
scf_dwarf_abbrev_declaration_t* d;
scf_dwarf_abbrev_declaration_t* d2;
scf_dwarf_info_entry_t* ie2;
scf_dwarf_info_attr_t* iattr;
+ int ret;
int i;
int j;
ie = _debug_find_type(parse, t, var->nb_pointers);
if (!ie) {
-
ret = _debug_add_type(&ie, parse, t, var->nb_pointers);
+
if (ret < 0) {
scf_loge("\n");
return -1;
uint32_t type = 0;
scf_variable_t* v = f->rets->data[0];
- scf_type_t* t = NULL;
-
- ret = scf_ast_find_type_type(&t, parse->ast, v->type);
- if (ret < 0)
- return ret;
+ scf_type_t* t = v->t;
ie2 = _debug_find_type(parse, t, v->nb_pointers);
if (!ie2) {
-
ret = _debug_add_type(&ie2, parse, t, v->nb_pointers);
+
if (ret < 0) {
scf_loge("\n");
return ret;
uint32_t inline_flag:1;
uint32_t arg_flag:1;
+ uint32_t bit_field_flag:1;
+
uint32_t op_comma_flag:1;
uint32_t var_semicolon_flag:1;
}
// 'v' is not a base type var or a pointer, it's a struct
- // first, find the type in this struct scope, then find in global
- scf_type_t* type_v = NULL;
-
- while (t) {
- type_v = scf_scope_find_type_type(t->scope, v->type);
- if (type_v)
- break;
-
- // only can use types in this scope, or parent scope
- // can't use types in children scope
- t = t->parent;
- }
-
- if (!type_v) {
- type_v = scf_block_find_type_type(ast->current_block, v->type);
-
- if (!type_v) {
- scf_loge("\n");
- return -1;
- }
- }
-
- t = type_v;
+ t = v->t;
}
scf_loge("number of indexes less than needed, struct member: %s->%s, file: %s, line: %d\n",
--- /dev/null
+typedef int32_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef uint32_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+
+#define INT_FAST16_MIN INT32_MIN
+#define INT_FAST32_MIN INT32_MIN
+
+#define INT_FAST16_MAX INT32_MAX
+#define INT_FAST32_MAX INT32_MAX
+
+#define UINT_FAST16_MAX UINT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#if __LONG_MAX == 0x7fffffffL
+#define INTPTR_MIN INT32_MIN
+#define INTPTR_MAX INT32_MAX
+#define UINTPTR_MAX UINT32_MAX
+#define PTRDIFF_MIN INT32_MIN
+#define PTRDIFF_MAX INT32_MAX
+#define SIZE_MAX UINT32_MAX
+#else
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+#define UINTPTR_MAX UINT64_MAX
+#define PTRDIFF_MIN INT64_MIN
+#define PTRDIFF_MAX INT64_MAX
+#define SIZE_MAX UINT64_MAX
+#endif
--- /dev/null
+#ifndef _MATH_H
+#define _MATH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <features.h>
+
+#define __NEED_float_t
+#define __NEED_double_t
+#include <bits/alltypes.h>
+
+#if 100*__GNUC__+__GNUC_MINOR__ >= 303
+#define NAN __builtin_nanf("")
+#define INFINITY __builtin_inff()
+#else
+#define NAN (0.0f/0.0f)
+#define INFINITY 1e5000f
+#endif
+
+#define HUGE_VALF INFINITY
+#define HUGE_VAL ((double)INFINITY)
+#define HUGE_VALL ((long double)INFINITY)
+
+#define MATH_ERRNO 1
+#define MATH_ERREXCEPT 2
+#define math_errhandling 2
+
+#define FP_ILOGBNAN (-1-0x7fffffff)
+#define FP_ILOGB0 FP_ILOGBNAN
+
+#define FP_NAN 0
+#define FP_INFINITE 1
+#define FP_ZERO 2
+#define FP_SUBNORMAL 3
+#define FP_NORMAL 4
+
+#ifdef __FP_FAST_FMA
+#define FP_FAST_FMA 1
+#endif
+
+#ifdef __FP_FAST_FMAF
+#define FP_FAST_FMAF 1
+#endif
+
+#ifdef __FP_FAST_FMAL
+#define FP_FAST_FMAL 1
+#endif
+
+int __fpclassify(double);
+int __fpclassifyf(float);
+int __fpclassifyl(long double);
+
+static __inline unsigned __FLOAT_BITS(float __f)
+{
+ union {float __f; unsigned __i;} __u;
+ __u.__f = __f;
+ return __u.__i;
+}
+static __inline unsigned long long __DOUBLE_BITS(double __f)
+{
+ union {double __f; unsigned long long __i;} __u;
+ __u.__f = __f;
+ return __u.__i;
+}
+
+#define fpclassify(x) ( \
+ sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
+ sizeof(x) == sizeof(double) ? __fpclassify(x) : \
+ __fpclassifyl(x) )
+
+#define isinf(x) ( \
+ sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \
+ sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \
+ __fpclassifyl(x) == FP_INFINITE)
+
+#define isnan(x) ( \
+ sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
+ sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
+ __fpclassifyl(x) == FP_NAN)
+
+#define isnormal(x) ( \
+ sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \
+ sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \
+ __fpclassifyl(x) == FP_NORMAL)
+
+#define isfinite(x) ( \
+ sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \
+ sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \
+ __fpclassifyl(x) > FP_INFINITE)
+
+int __signbit(double);
+int __signbitf(float);
+int __signbitl(long double);
+
+#define signbit(x) ( \
+ sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \
+ sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \
+ __signbitl(x) )
+
+#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y)))
+
+#define __ISREL_DEF(rel, op, type) \
+static __inline int __is##rel(type __x, type __y) \
+{ return !isunordered(__x,__y) && __x op __y; }
+
+__ISREL_DEF(lessf, <, float_t)
+__ISREL_DEF(less, <, double_t)
+__ISREL_DEF(lessl, <, long double)
+__ISREL_DEF(lessequalf, <=, float_t)
+__ISREL_DEF(lessequal, <=, double_t)
+__ISREL_DEF(lessequall, <=, long double)
+__ISREL_DEF(lessgreaterf, !=, float_t)
+__ISREL_DEF(lessgreater, !=, double_t)
+__ISREL_DEF(lessgreaterl, !=, long double)
+__ISREL_DEF(greaterf, >, float_t)
+__ISREL_DEF(greater, >, double_t)
+__ISREL_DEF(greaterl, >, long double)
+__ISREL_DEF(greaterequalf, >=, float_t)
+__ISREL_DEF(greaterequal, >=, double_t)
+__ISREL_DEF(greaterequall, >=, long double)
+
+#define __tg_pred_2(x, y, p) ( \
+ sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \
+ sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \
+ p##l(x, y) )
+
+#define isless(x, y) __tg_pred_2(x, y, __isless)
+#define islessequal(x, y) __tg_pred_2(x, y, __islessequal)
+#define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater)
+#define isgreater(x, y) __tg_pred_2(x, y, __isgreater)
+#define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal)
+
+double acos(double);
+float acosf(float);
+long double acosl(long double);
+
+double acosh(double);
+float acoshf(float);
+long double acoshl(long double);
+
+double asin(double);
+float asinf(float);
+long double asinl(long double);
+
+double asinh(double);
+float asinhf(float);
+long double asinhl(long double);
+
+double atan(double);
+float atanf(float);
+long double atanl(long double);
+
+double atan2(double, double);
+float atan2f(float, float);
+long double atan2l(long double, long double);
+
+double atanh(double);
+float atanhf(float);
+long double atanhl(long double);
+
+double cbrt(double);
+float cbrtf(float);
+long double cbrtl(long double);
+
+double ceil(double);
+float ceilf(float);
+long double ceill(long double);
+
+double copysign(double, double);
+float copysignf(float, float);
+long double copysignl(long double, long double);
+
+double cos(double);
+float cosf(float);
+long double cosl(long double);
+
+double cosh(double);
+float coshf(float);
+long double coshl(long double);
+
+double erf(double);
+float erff(float);
+long double erfl(long double);
+
+double erfc(double);
+float erfcf(float);
+long double erfcl(long double);
+
+double exp(double);
+float expf(float);
+long double expl(long double);
+
+double exp2(double);
+float exp2f(float);
+long double exp2l(long double);
+
+double expm1(double);
+float expm1f(float);
+long double expm1l(long double);
+
+double fabs(double);
+float fabsf(float);
+long double fabsl(long double);
+
+double fdim(double, double);
+float fdimf(float, float);
+long double fdiml(long double, long double);
+
+double floor(double);
+float floorf(float);
+long double floorl(long double);
+
+double fma(double, double, double);
+float fmaf(float, float, float);
+long double fmal(long double, long double, long double);
+
+double fmax(double, double);
+float fmaxf(float, float);
+long double fmaxl(long double, long double);
+
+double fmin(double, double);
+float fminf(float, float);
+long double fminl(long double, long double);
+
+double fmod(double, double);
+float fmodf(float, float);
+long double fmodl(long double, long double);
+
+double frexp(double, int *);
+float frexpf(float, int *);
+long double frexpl(long double, int *);
+
+double hypot(double, double);
+float hypotf(float, float);
+long double hypotl(long double, long double);
+
+int ilogb(double);
+int ilogbf(float);
+int ilogbl(long double);
+
+double ldexp(double, int);
+float ldexpf(float, int);
+long double ldexpl(long double, int);
+
+double lgamma(double);
+float lgammaf(float);
+long double lgammal(long double);
+
+long long llrint(double);
+long long llrintf(float);
+long long llrintl(long double);
+
+long long llround(double);
+long long llroundf(float);
+long long llroundl(long double);
+
+double log(double);
+float logf(float);
+long double logl(long double);
+
+double log10(double);
+float log10f(float);
+long double log10l(long double);
+
+double log1p(double);
+float log1pf(float);
+long double log1pl(long double);
+
+double log2(double);
+float log2f(float);
+long double log2l(long double);
+
+double logb(double);
+float logbf(float);
+long double logbl(long double);
+
+long lrint(double);
+long lrintf(float);
+long lrintl(long double);
+
+long lround(double);
+long lroundf(float);
+long lroundl(long double);
+
+double modf(double, double *);
+float modff(float, float *);
+long double modfl(long double, long double *);
+
+double nan(const char *);
+float nanf(const char *);
+long double nanl(const char *);
+
+double nearbyint(double);
+float nearbyintf(float);
+long double nearbyintl(long double);
+
+double nextafter(double, double);
+float nextafterf(float, float);
+long double nextafterl(long double, long double);
+
+double nexttoward(double, long double);
+float nexttowardf(float, long double);
+long double nexttowardl(long double, long double);
+
+double pow(double, double);
+float powf(float, float);
+long double powl(long double, long double);
+
+double remainder(double, double);
+float remainderf(float, float);
+long double remainderl(long double, long double);
+
+double remquo(double, double, int *);
+float remquof(float, float, int *);
+long double remquol(long double, long double, int *);
+
+double rint(double);
+float rintf(float);
+long double rintl(long double);
+
+double round(double);
+float roundf(float);
+long double roundl(long double);
+
+double scalbln(double, long);
+float scalblnf(float, long);
+long double scalblnl(long double, long);
+
+double scalbn(double, int);
+float scalbnf(float, int);
+long double scalbnl(long double, int);
+
+double sin(double);
+float sinf(float);
+long double sinl(long double);
+
+double sinh(double);
+float sinhf(float);
+long double sinhl(long double);
+
+double sqrt(double);
+float sqrtf(float);
+long double sqrtl(long double);
+
+double tan(double);
+float tanf(float);
+long double tanl(long double);
+
+double tanh(double);
+float tanhf(float);
+long double tanhl(long double);
+
+double tgamma(double);
+float tgammaf(float);
+long double tgammal(long double);
+
+double trunc(double);
+float truncf(float);
+long double truncl(long double);
+
+
+#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE)
+#undef MAXFLOAT
+#define MAXFLOAT 3.40282346638528859812e+38F
+#endif
+
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define M_E 2.7182818284590452354 /* e */
+#define M_LOG2E 1.4426950408889634074 /* log_2 e */
+#define M_LOG10E 0.43429448190325182765 /* log_10 e */
+#define M_LN2 0.69314718055994530942 /* log_e 2 */
+#define M_LN10 2.30258509299404568402 /* log_e 10 */
+#define M_PI 3.14159265358979323846 /* pi */
+#define M_PI_2 1.57079632679489661923 /* pi/2 */
+#define M_PI_4 0.78539816339744830962 /* pi/4 */
+#define M_1_PI 0.31830988618379067154 /* 1/pi */
+#define M_2_PI 0.63661977236758134308 /* 2/pi */
+#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
+#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
+#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
+
+extern int signgam;
+
+double j0(double);
+double j1(double);
+double jn(int, double);
+
+double y0(double);
+double y1(double);
+double yn(int, double);
+#endif
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define HUGE 3.40282346638528859812e+38F
+
+double drem(double, double);
+float dremf(float, float);
+
+int finite(double);
+int finitef(float);
+
+double scalb(double, double);
+float scalbf(float, float);
+
+double significand(double);
+float significandf(float);
+
+double lgamma_r(double, int*);
+float lgammaf_r(float, int*);
+
+float j0f(float);
+float j1f(float);
+float jnf(int, float);
+
+float y0f(float);
+float y1f(float);
+float ynf(int, float);
+#endif
+
+#ifdef _GNU_SOURCE
+long double lgammal_r(long double, int*);
+
+void sincos(double, double*, double*);
+void sincosf(float, float*, float*);
+void sincosl(long double, long double*, long double*);
+
+double exp10(double);
+float exp10f(float);
+long double exp10l(long double);
+
+double pow10(double);
+float pow10f(float);
+long double pow10l(long double);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+#ifndef _STDINT_H
+#define _STDINT_H
+
+#define __NEED_int8_t
+#define __NEED_int16_t
+#define __NEED_int32_t
+#define __NEED_int64_t
+
+#define __NEED_uint8_t
+#define __NEED_uint16_t
+#define __NEED_uint32_t
+#define __NEED_uint64_t
+
+#define __NEED_intptr_t
+#define __NEED_uintptr_t
+
+#define __NEED_intmax_t
+#define __NEED_uintmax_t
+
+#include <bits/alltypes.h>
+
+typedef int8_t int_fast8_t;
+typedef int64_t int_fast64_t;
+
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+
+typedef uint8_t uint_fast8_t;
+typedef uint64_t uint_fast64_t;
+
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+#define INT8_MIN (-1-0x7f)
+#define INT16_MIN (-1-0x7fff)
+#define INT32_MIN (-1-0x7fffffff)
+#define INT64_MIN (-1-0x7fffffffffffffff)
+
+#define INT8_MAX (0x7f)
+#define INT16_MAX (0x7fff)
+#define INT32_MAX (0x7fffffff)
+#define INT64_MAX (0x7fffffffffffffff)
+
+#define UINT8_MAX (0xff)
+#define UINT16_MAX (0xffff)
+#define UINT32_MAX (0xffffffffu)
+#define UINT64_MAX (0xffffffffffffffffu)
+
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST64_MIN INT64_MIN
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST64_MIN INT64_MIN
+
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST64_MAX INT64_MAX
+
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MAX INT64_MAX
+
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define WINT_MIN 0U
+#define WINT_MAX UINT32_MAX
+
+#if L'\0'-1 > 0
+#define WCHAR_MAX (0xffffffffu+L'\0')
+#define WCHAR_MIN (0+L'\0')
+#else
+#define WCHAR_MAX (0x7fffffff+L'\0')
+#define WCHAR_MIN (-1-0x7fffffff+L'\0')
+#endif
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#include <bits/stdint.h>
+
+#define INT8_C(c) c
+#define INT16_C(c) c
+#define INT32_C(c) c
+
+#define UINT8_C(c) c
+#define UINT16_C(c) c
+#define UINT32_C(c) c ## U
+
+#if UINTPTR_MAX == UINT64_MAX
+#define INT64_C(c) c ## L
+#define UINT64_C(c) c ## UL
+#define INTMAX_C(c) c ## L
+#define UINTMAX_C(c) c ## UL
+#else
+#define INT64_C(c) c ## LL
+#define UINT64_C(c) c ## ULL
+#define INTMAX_C(c) c ## LL
+#define UINTMAX_C(c) c ## ULL
+#endif
+
+#endif
--- /dev/null
+#ifndef _TIME_H
+#define _TIME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <features.h>
+
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
+#define NULL 0L
+#else
+//#define NULL ((void*)0)
+#endif
+
+
+#define __NEED_size_t
+#define __NEED_time_t
+#define __NEED_clock_t
+#define __NEED_struct_timespec
+
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
+#define __NEED_clockid_t
+#define __NEED_timer_t
+#define __NEED_pid_t
+#define __NEED_locale_t
+#endif
+
+#include <bits/alltypes.h>
+
+#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+#define __tm_gmtoff tm_gmtoff
+#define __tm_zone tm_zone
+#endif
+
+struct tm {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+ int tm_wday;
+ int tm_yday;
+ int tm_isdst;
+ long __tm_gmtoff;
+ const char *__tm_zone;
+};
+
+clock_t clock (void);
+time_t time (time_t *);
+double difftime (time_t, time_t);
+time_t mktime (struct tm *);
+size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
+struct tm *gmtime (const time_t *);
+struct tm *localtime (const time_t *);
+char *asctime (const struct tm *);
+char *ctime (const time_t *);
+int timespec_get(struct timespec *, int);
+
+#define CLOCKS_PER_SEC 1000000L
+
+#define TIME_UTC 1
+
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
+
+size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t);
+
+struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
+struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
+char *asctime_r (const struct tm *__restrict, char *__restrict);
+char *ctime_r (const time_t *, char *);
+
+void tzset (void);
+
+struct itimerspec {
+ struct timespec it_interval;
+ struct timespec it_value;
+};
+
+#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_THREAD_CPUTIME_ID 3
+#define CLOCK_MONOTONIC_RAW 4
+#define CLOCK_REALTIME_COARSE 5
+#define CLOCK_MONOTONIC_COARSE 6
+#define CLOCK_BOOTTIME 7
+#define CLOCK_REALTIME_ALARM 8
+#define CLOCK_BOOTTIME_ALARM 9
+#define CLOCK_SGI_CYCLE 10
+#define CLOCK_TAI 11
+
+#define TIMER_ABSTIME 1
+
+int nanosleep (const struct timespec *, struct timespec *);
+int clock_getres (clockid_t, struct timespec *);
+int clock_gettime (clockid_t, struct timespec *);
+int clock_settime (clockid_t, const struct timespec *);
+int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
+int clock_getcpuclockid (pid_t, clockid_t *);
+
+struct sigevent;
+int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
+int timer_delete (timer_t);
+int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
+int timer_gettime (timer_t, struct itimerspec *);
+int timer_getoverrun (timer_t);
+
+extern char *tzname[2];
+
+#endif
+
+
+#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
+extern int daylight;
+extern long timezone;
+extern int getdate_err;
+struct tm *getdate (const char *);
+#endif
+
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+int stime(const time_t *);
+time_t timegm(struct tm *);
+#endif
+
+#if _REDIR_TIME64
+__REDIR(time, __time64);
+__REDIR(difftime, __difftime64);
+__REDIR(mktime, __mktime64);
+__REDIR(gmtime, __gmtime64);
+__REDIR(localtime, __localtime64);
+__REDIR(ctime, __ctime64);
+__REDIR(timespec_get, __timespec_get_time64);
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
+__REDIR(gmtime_r, __gmtime64_r);
+__REDIR(localtime_r, __localtime64_r);
+__REDIR(ctime_r, __ctime64_r);
+__REDIR(nanosleep, __nanosleep_time64);
+__REDIR(clock_getres, __clock_getres_time64);
+__REDIR(clock_gettime, __clock_gettime64);
+__REDIR(clock_settime, __clock_settime64);
+__REDIR(clock_nanosleep, __clock_nanosleep_time64);
+__REDIR(timer_settime, __timer_settime64);
+__REDIR(timer_gettime, __timer_gettime64);
+#endif
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+__REDIR(stime, __stime64);
+__REDIR(timegm, __timegm_time64);
+#endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif