return c;
}
-scf_3ac_code_t* scf_3ac_jmp_code(int type, scf_label_t* l, scf_node_t* err)
+scf_3ac_code_t* scf_3ac_jmp_code(int type, scf_lex_word_t* label)
{
scf_3ac_operand_t* dst;
scf_3ac_code_t* c;
return NULL;
c->op = scf_3ac_find_operator(type);
- c->label = l;
+ c->label = label;
- c->dsts = scf_vector_alloc();
+ c->dsts = scf_vector_alloc();
if (!c->dsts) {
scf_3ac_code_free(c);
return NULL;
scf_vector_t* dsts; // dst operands, maybe only used for function return value
scf_vector_t* srcs; // src operands, usually 2
- scf_label_t* label; // only for 'goto' to find the destination to go
+ scf_lex_word_t* label; // only for 'goto' to find the destination
scf_3ac_code_t* origin;
void scf_3ac_list_print(scf_list_t* h);
-scf_3ac_code_t* scf_3ac_jmp_code(int type, scf_label_t* l, scf_node_t* err);
+scf_3ac_code_t* scf_3ac_jmp_code(int type, scf_lex_word_t* label);
scf_3ac_operator_t* scf_3ac_find_operator(const int type);
scf_type_t* t = (scf_type_t*)node;
- if (t->type == (intptr_t)arg) {
+ if (t->node.type == (intptr_t)arg) {
int ret = scf_vector_add(vec, t);
if (ret < 0)
scf_string_t* scf_variable_type_name(scf_ast_t* ast, scf_variable_t* v);
-static inline void scf_ast_push_block(scf_ast_t* ast, scf_block_t* b)
-{
- scf_node_add_child((scf_node_t*)ast->current_block, (scf_node_t*)b);
- ast->current_block = b;
-}
-
-static inline void scf_ast_pop_block(scf_ast_t* ast)
-{
- ast->current_block = (scf_block_t*)(ast->current_block->node.parent);
-}
-
-static inline scf_block_t* scf_ast_parent_block(scf_ast_t* ast)
-{
- scf_node_t* parent = ast->current_block->node.parent;
-
- while (parent && parent->type != SCF_OP_BLOCK && parent->type != SCF_FUNCTION)
- parent = parent->parent;
-
- return (scf_block_t*)parent;
-}
-
-static inline scf_scope_t* scf_ast_current_scope(scf_ast_t* ast)
-{
- return ast->current_block->scope;
-}
-
int scf_ast_find_proper_function (scf_function_t** pf, scf_ast_t* ast, scf_vector_t* fvec, scf_vector_t* argv);
int scf_ast_find_global_function (scf_function_t** pf, scf_ast_t* ast, char* name);
int scf_ast_find_global_variable (scf_variable_t** pv, scf_ast_t* ast, char* name);
if (!bb)
return NULL;
- c = scf_3ac_jmp_code(jcc, NULL, NULL);
+ c = scf_3ac_jmp_code(jcc, NULL);
if (!c) {
scf_basic_block_free(bb);
return NULL;
return NULL;
}
- l->refs = 1;
l->type = SCF_LABEL;
return l;
}
void scf_label_free(scf_label_t* l)
{
if (l) {
- if (--l->refs > 0)
- return;
-
if (l->w) {
scf_lex_word_free(l->w);
l->w = NULL;
if (!dst->var)
goto failed;
- } else if (SCF_LABEL == node->type)
- dst->label = node->label;
- else {
+ } else {
if (node->w) {
dst->w = scf_lex_word_clone(node->w);
if (!dst->w)
return NULL;
}
-scf_node_t* scf_node_alloc_label(scf_label_t* l)
-{
- scf_node_t* node = calloc(1, sizeof(scf_node_t));
- if (!node) {
- scf_loge("node alloc failed\n");
- return NULL;
- }
-
- node->type = SCF_LABEL;
- node->label = l;
- return node;
-}
-
int scf_node_add_child(scf_node_t* parent, scf_node_t* child)
{
if (!parent)
scf_variable_free(node->var);
node->var = NULL;
}
- } else if (SCF_LABEL == node->type) {
- if (node->label) {
- scf_label_free(node->label);
- node->label = NULL;
- }
} else {
if (node->w) {
scf_lex_word_free(node->w);
if (node) {
scf_logw("node: %p, type: %d", node, node->type);
- if (SCF_LABEL == node->type) {
- if (node->label && node->label->w)
- printf(", w: %s, line: %d", node->label->w->text->data, node->label->w->line);
-
- } else if (scf_type_is_var(node->type)) {
+ if (scf_type_is_var(node->type)) {
if (node->var && node->var->w)
printf(", w: %s, line: %d", node->var->w->text->data, node->var->w->line);
scf_node_t** nodes; // children nodes
union {
- scf_variable_t* var;
- scf_lex_word_t* w;
- scf_label_t* label;
+ scf_variable_t* var;
+ scf_lex_word_t* w;
};
scf_lex_word_t* debug_w;
};
scf_node_t* scf_node_alloc(scf_lex_word_t* w, int type, scf_variable_t* var);
-scf_node_t* scf_node_alloc_label(scf_label_t* l);
-
-scf_node_t* scf_node_clone(scf_node_t* node);
int scf_node_add_child(scf_node_t* parent, scf_node_t* child);
void scf_node_del_child(scf_node_t* parent, scf_node_t* child);
void scf_node_free_data(scf_node_t* node);
void scf_node_move_data(scf_node_t* dst, scf_node_t* src);
+scf_node_t* scf_node_clone(scf_node_t* node);
void scf_node_print(scf_node_t* node);
scf_variable_t* _scf_operand_get(const scf_node_t* node);
int i;
int j;
-
for (i = 0; i < nb_nodes; i++) {
-
node = nodes[i];
op = node->op;
// for goto
if (SCF_LABEL == node->type) {
- scf_label_t* l = node->label;
scf_list_t* tail = scf_list_tail(d->_3ac_list_head);
scf_3ac_code_t* end = scf_list_data(tail, scf_3ac_code_t, list);
scf_3ac_code_t* c;
scf_loge("\n");
return -1;
}
- end->label = l;
+ end->label = node->w;
int j;
for (j = 0; j < d->branch_ops->_gotos->size; j++) {
if (!c)
continue;
- assert(l->w);
- assert(c->label->w);
+ assert(c->label);
- if (!strcmp(l->w->text->data, c->label->w->text->data)) {
+ if (!strcmp(node->w->text->data, c->label->text->data)) {
dst = c->dsts->data[0];
dst->code = end;
}
return -1;
}
- scf_3ac_code_t* end = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ scf_3ac_code_t* end = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &end->list);
return -1;
}
- scf_3ac_code_t* jmp = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ scf_3ac_code_t* jmp = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp->list);
return -1;
}
- scf_3ac_code_t* jmp = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ scf_3ac_code_t* jmp = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp->list);
scf_handler_data_t* d = data;
scf_node_t* nl = nodes[0];
- scf_label_t* l = nl->label;
assert(SCF_LABEL == nl->type);
- assert(l->w);
scf_3ac_operand_t* dst;
scf_3ac_code_t* c;
- scf_3ac_code_t* jmp = scf_3ac_jmp_code(SCF_OP_GOTO, l, NULL);
+ scf_3ac_code_t* jmp = scf_3ac_jmp_code(SCF_OP_GOTO, nl->w);
scf_list_add_tail(d->_3ac_list_head, &jmp->list);
for (i = 0; i < d->branch_ops->_labels->size; i++) {
c = d->branch_ops->_labels->data[i];
- if (!strcmp(l->w->text->data, c->label->w->text->data)) {
+ assert(c->label);
+
+ if (!strcmp(nl->w->text->data, c->label->text->data)) {
dst = jmp->dsts->data[0];
dst->code = c;
break;
}
scf_3ac_operand_t* dst;
- scf_3ac_code_t* jmp_else = scf_3ac_jmp_code(jmp_op, NULL, NULL);
+ scf_3ac_code_t* jmp_else = scf_3ac_jmp_code(jmp_op, NULL);
scf_3ac_code_t* jmp_endif = NULL;
scf_list_t* l;
if (1 == i) {
if (3 == nb_nodes) {
- jmp_endif = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ jmp_endif = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp_endif->list);
}
if (jmp_end) {
// add loop when true
- loop = scf_3ac_jmp_code(jmp_op, NULL, NULL);
+ loop = scf_3ac_jmp_code(jmp_op, NULL);
scf_list_add_tail(d->_3ac_list_head, &loop->list);
// should get the real start here,
start = scf_list_data(scf_list_next(&jmp_end->list), scf_3ac_code_t, list);
} else {
- loop = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ loop = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &loop->list);
start = scf_list_data(scf_list_next(start_prev), scf_3ac_code_t, list);
scf_list_t* l;
scf_3ac_code_t* c;
- scf_3ac_code_t* jmp_end = scf_3ac_jmp_code(jmp_op, NULL, NULL);
+ scf_3ac_code_t* jmp_end = scf_3ac_jmp_code(jmp_op, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp_end->list);
return -1;
}
- scf_3ac_code_t* jmp_end = scf_3ac_jmp_code(jmp_op, NULL, NULL);
+ scf_3ac_code_t* jmp_end = scf_3ac_jmp_code(jmp_op, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp_end->list);
scf_branch_ops_t* local_branch_ops = scf_branch_ops_alloc();
if (!cmp)
return -ENOMEM;
- jgt = scf_3ac_jmp_code(SCF_OP_3AC_JGT, NULL, NULL);
+ jgt = scf_3ac_jmp_code(SCF_OP_3AC_JGT, NULL);
if (!jgt) {
scf_3ac_code_free(cmp);
return -ENOMEM;
if (SCF_OP_CASE == child->type || SCF_OP_DEFAULT == child->type) {
if (jnot) {
- jnext = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ jnext = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &jnext->list);
scf_vector_add(up_branch_ops->_breaks, jnext);
else
cmp = scf_3ac_code_NN(SCF_OP_3AC_TEQ, NULL, 0, &e2, 1);
- jnot = scf_3ac_jmp_code(SCF_OP_3AC_JNZ, NULL, NULL);
+ jnot = scf_3ac_jmp_code(SCF_OP_3AC_JNZ, NULL);
scf_list_add_tail(d->_3ac_list_head, &cmp->list);
scf_list_add_tail(d->_3ac_list_head, &jnot->list);
return -1;
}
- jmp_end = scf_3ac_jmp_code(jmp_op, NULL, NULL);
+ jmp_end = scf_3ac_jmp_code(jmp_op, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp_end->list);
}
}
return ret;
}
- jz = scf_3ac_jmp_code(SCF_OP_3AC_JZ, NULL, NULL);
+ jz = scf_3ac_jmp_code(SCF_OP_3AC_JZ, NULL);
scf_list_add_tail(d->_3ac_list_head, &jz->list);
for (i = 3; i < nb_nodes; i++) {
return ret;
}
- jmp = scf_3ac_jmp_code(SCF_OP_GOTO, NULL, NULL);
+ jmp = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
scf_list_add_tail(d->_3ac_list_head, &jmp->list);
scf_vector_add(d->branch_ops->_breaks, jz);
if (jmp_op < 0) \
return -1; \
\
- scf_3ac_code_t* jmp = scf_3ac_jmp_code(jmp_op, NULL, NULL); \
+ scf_3ac_code_t* jmp = scf_3ac_jmp_code(jmp_op, NULL); \
if (!jmp) \
return -ENOMEM; \
\
#include"scf_ast.h"
-scf_scope_t* scf_scope_alloc(scf_lex_word_t* w, const char* name)
+scf_scope_t* scf_scope_alloc()
{
scf_scope_t* scope = calloc(1, sizeof(scf_scope_t));
if (!scope)
return NULL;
- scope->name = scf_string_cstr(name);
- if (!scope->name) {
- free(scope);
- return NULL;
- }
-
scope->vars = scf_vector_alloc();
if (!scope->vars) {
- scf_string_free(scope->name);
free(scope);
return NULL;
}
- if (w) {
- scope->w = scf_lex_word_clone(w);
-
- if (!scope->w) {
- scf_vector_free(scope->vars);
- scf_string_free(scope->name);
- free(scope);
- return NULL;
- }
- }
-
scf_list_init(&scope->list);
- scf_list_init(&scope->type_list_head);
- scf_list_init(&scope->operator_list_head);
- scf_list_init(&scope->function_list_head);
- scf_list_init(&scope->label_list_head);
+ scf_list_init(&scope->types);
+ scf_list_init(&scope->operators);
+ scf_list_init(&scope->functions);
+ scf_list_init(&scope->labels);
return scope;
}
void scf_scope_push_var(scf_scope_t* scope, scf_variable_t* var)
{
- assert(scope);
- assert(var);
scf_vector_add(scope->vars, var);
}
void scf_scope_push_type(scf_scope_t* scope, scf_type_t* t)
{
- assert(scope);
- assert(t);
- scf_list_add_front(&scope->type_list_head, &t->list);
+ scf_list_add_front(&scope->types, &t->list);
}
void scf_scope_push_operator(scf_scope_t* scope, scf_function_t* op)
{
- assert(scope);
- assert(op);
- scf_list_add_front(&scope->operator_list_head, &op->list);
+ scf_list_add_front(&scope->operators, &op->list);
}
void scf_scope_push_function(scf_scope_t* scope, scf_function_t* f)
{
- assert(scope);
- assert(f);
- scf_list_add_front(&scope->function_list_head, &f->list);
+ scf_list_add_front(&scope->functions, &f->list);
}
void scf_scope_push_label(scf_scope_t* scope, scf_label_t* l)
{
- assert(scope);
- assert(l);
- scf_list_add_front(&scope->label_list_head, &l->list);
+ scf_list_add_front(&scope->labels, &l->list);
}
void scf_scope_free(scf_scope_t* scope)
{
if (scope) {
- scf_string_free(scope->name);
- scope->name = NULL;
-
- if (scope->w)
- scf_lex_word_free(scope->w);
-
scf_vector_clear(scope->vars, (void (*)(void*))scf_variable_free);
scf_vector_free(scope->vars);
scope->vars = NULL;
- scf_list_clear(&scope->type_list_head, scf_type_t, list, scf_type_free);
- scf_list_clear(&scope->function_list_head, scf_function_t, list, scf_function_free);
+ scf_list_clear(&scope->labels, scf_label_t, list, scf_label_free);
free(scope);
}
scf_type_t* t;
scf_list_t* l;
- for (l = scf_list_head(&scope->type_list_head); l != scf_list_sentinel(&scope->type_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->types); l != scf_list_sentinel(&scope->types); l = scf_list_next(l)) {
t = scf_list_data(l, scf_type_t, list);
if (!strcmp(name, t->name->data)) {
scf_type_t* t;
scf_list_t* l;
- for (l = scf_list_head(&scope->type_list_head); l != scf_list_sentinel(&scope->type_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->types); l != scf_list_sentinel(&scope->types); l = scf_list_next(l)) {
t = scf_list_data(l, scf_type_t, list);
- if (type == t->type)
+ if (type == t->node.type)
return t;
}
return NULL;
scf_label_t* label;
scf_list_t* l;
- for (l = scf_list_head(&scope->label_list_head); l != scf_list_sentinel(&scope->label_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->labels); l != scf_list_sentinel(&scope->labels); l = scf_list_next(l)) {
label = scf_list_data(l, scf_label_t, list);
if (!strcmp(name, label->w->text->data))
scf_function_t* f;
scf_list_t* l;
- for (l = scf_list_head(&scope->function_list_head); l != scf_list_sentinel(&scope->function_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->functions); l != scf_list_sentinel(&scope->functions); l = scf_list_next(l)) {
f = scf_list_data(l, scf_function_t, list);
if (!strcmp(name, f->node.w->text->data))
scf_function_t* f1;
scf_list_t* l;
- for (l = scf_list_head(&scope->function_list_head); l != scf_list_sentinel(&scope->function_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->functions); l != scf_list_sentinel(&scope->functions); l = scf_list_next(l)) {
f1 = scf_list_data(l, scf_function_t, list);
if (scf_function_same(f0, f1))
if (!vec)
return -ENOMEM;
- for (l = scf_list_head(&scope->function_list_head); l != scf_list_sentinel(&scope->function_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->functions); l != scf_list_sentinel(&scope->functions); l = scf_list_next(l)) {
f = scf_list_data(l, scf_function_t, list);
if (strcmp(f->node.w->text->data, name))
if (!vec)
return -ENOMEM;
- for (l = scf_list_head(&scope->operator_list_head); l != scf_list_sentinel(&scope->operator_list_head); l = scf_list_next(l)) {
+ for (l = scf_list_head(&scope->operators); l != scf_list_sentinel(&scope->operators); l = scf_list_next(l)) {
f = scf_list_data(l, scf_function_t, list);
if (op_type != f->op_type)
#include"scf_lex_word.h"
#include"scf_core_types.h"
-struct scf_scope_s {
- scf_list_t list; // scope list
- scf_string_t* name; // scope name
-
- scf_lex_word_t* w; // scope name
-
- scf_vector_t* vars; // vars in this scope, should not have the same name
- scf_list_t type_list_head; // type list in this scope, not define the same type
- scf_list_t operator_list_head; // operator list in this scope
- scf_list_t function_list_head; // function list in this scope
- scf_list_t label_list_head; // label list in this scope
+struct scf_scope_s
+{
+ scf_list_t list; // scope list
+
+ scf_vector_t* vars; // vars in this scope, should not have the same name
+ scf_list_t types; // type list in this scope, not define the same type
+ scf_list_t operators; // operator list in this scope
+ scf_list_t functions; // function list in this scope
+ scf_list_t labels; // label list in this scope
};
-scf_scope_t* scf_scope_alloc(scf_lex_word_t* w, const char* name);
-void scf_scope_free( scf_scope_t* scope);
+scf_scope_t* scf_scope_alloc();
+void scf_scope_free(scf_scope_t* scope);
-void scf_scope_push_var(scf_scope_t* scope, scf_variable_t* var);
-
-void scf_scope_push_type(scf_scope_t* scope, scf_type_t* t);
+void scf_scope_push_var (scf_scope_t* scope, scf_variable_t* var);
+void scf_scope_push_type(scf_scope_t* scope, scf_type_t* t);
void scf_scope_push_operator(scf_scope_t* scope, scf_function_t* op);
-
void scf_scope_push_function(scf_scope_t* scope, scf_function_t* f);
-scf_type_t* scf_scope_find_type(scf_scope_t* scope, const char* name);
-
-scf_type_t* scf_scope_find_type_type(scf_scope_t* scope, const int type);
-
-scf_variable_t* scf_scope_find_variable(scf_scope_t* scope, const char* name);
-
-scf_function_t* scf_scope_find_function(scf_scope_t* scope, const char* name);
+scf_type_t* scf_scope_find_type (scf_scope_t* scope, const char* name);
+scf_type_t* scf_scope_find_type_type(scf_scope_t* scope, const int type);
+scf_variable_t* scf_scope_find_variable (scf_scope_t* scope, const char* name);
+scf_function_t* scf_scope_find_function (scf_scope_t* scope, const char* name);
scf_function_t* scf_scope_find_same_function(scf_scope_t* scope, scf_function_t* f0);
if (!t)
return NULL;
- t->type = type;
t->node.type = type;
t->name = scf_string_cstr(name);
}
if (w) {
- t->w = scf_lex_word_clone(w);
- if (!t->w) {
+ t->node.w = scf_lex_word_clone(w);
+ if (!t->node.w) {
scf_string_free(t->name);
free(t);
return NULL;
scf_string_free(t->name);
t->name = NULL;
- if (t->w) {
- scf_lex_word_free(t->w);
- t->w = NULL;
- }
-
if (t->scope) {
scf_scope_free(t->scope);
t->scope = NULL;
}
- free(t);
- t = NULL;
+ scf_node_free((scf_node_t*)t);
}
}
{
{"int", "i"},
{"void", "v"},
+ {"bool", "B"},
{"char", "c"},
{"float", "f"},
#include"scf_node.h"
typedef struct {
- int type;
const char* name;
+ int type;
int size;
} scf_base_type_t;
const char* abbrev;
} scf_type_abbrev_t;
-struct scf_type_s {
+struct scf_type_s
+{
// same as block, only used for class type
scf_node_t node;
-
scf_scope_t* scope;
-
scf_string_t* name;
// list for scope's type_list_head
scf_list_t list;
- int type;
- scf_lex_word_t* w;
-
int nb_pointers;
// int array_capacity;
const char* scf_type_find_abbrev(const char* name);
#endif
-
return NULL;
v->refs = 1;
- v->type = t->type;
+ v->type = t->node.type;
v->const_flag = t->node.const_flag;
v->nb_pointers = t->nb_pointers;
md->parent_block = parse->ast->current_block;
SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "class_end"), SCF_DFA_HOOK_END);
- scf_logi("\033[31m t: %p, t->type: %d\033[0m\n", t, t->type);
+ scf_logi("\033[31m t: %p, t->type: %d\033[0m\n", t, t->node.type);
return SCF_DFA_NEXT_WORD;
}
return SCF_DFA_ERROR;
}
- if (id->type->type < SCF_STRUCT) {
+ if (id->type->node.type < SCF_STRUCT) {
scf_loge("'%s' is not a class or struct\n", w->text->data);
free(id);
return SCF_DFA_ERROR;
return SCF_DFA_ERROR;
}
- if (SCF_VAR_VOID == id->type->type && 0 == id->nb_pointers)
+ if (SCF_VAR_VOID == id->type->node.type && 0 == id->nb_pointers)
void_flag = 1;
f->extern_flag |= id->extern_flag;
if (v && v->identity)
w = v->identity;
- if (SCF_VAR_VOID == t->type->type && 0 == t->nb_pointers) {
+ if (SCF_VAR_VOID == t->type->node.type && 0 == t->nb_pointers) {
scf_loge("\n");
return SCF_DFA_ERROR;
}
scf_parse_t* parse = dfa->priv;
dfa_data_t* d = data;
scf_lex_word_t* w = words->data[words->size - 1];
+ scf_node_t* node = scf_node_alloc(w, SCF_LABEL, NULL);
- scf_label_t* l = scf_label_alloc(w);
- scf_node_t* n = scf_node_alloc_label(l);
-
- scf_node_add_child(d->current_goto, n);
+ scf_node_add_child(d->current_goto, node);
return SCF_DFA_NEXT_WORD;
}
}
scf_label_t* l = scf_label_alloc(id->identity);
- scf_node_t* n = scf_node_alloc_label(l);
+ scf_node_t* n = scf_node_alloc(l->w, SCF_LABEL, NULL);
scf_stack_pop(d->current_identities);
free(id);
scf_node_add_child((scf_node_t*)parse->ast->current_block, n);
+ l->node = n;
scf_scope_push_label(parse->ast->current_block->scope, l);
return SCF_DFA_OK;
}
}
- if (SCF_FUNCTION_PTR == id->type->type) {
+ if (SCF_FUNCTION_PTR == id->type->node.type) {
id->func_ptr = _type_find_function(parse->ast->current_block, id->identity->text->data);
}
assert(t);
- if (t->type != ap->type || 0 != ap->nb_dimentions) {
+ if (t->node.type != ap->type || 0 != ap->nb_dimentions) {
scf_loge("variable %s is not va_list type\n", w->text->data);
return SCF_DFA_ERROR;
}
int _check_recursive(scf_type_t* parent, scf_type_t* child, scf_lex_word_t* w)
{
- if (child->type == parent->type) {
-
+ if (child->node.type == parent->node.type) {
+
scf_loge("recursive define '%s' type member var '%s' in type '%s', line: %d\n",
child->name->data, w->text->data, parent->name->data, w->line);
}
if (child->scope) {
- assert(child->type >= SCF_STRUCT);
+ assert(child->node.type >= SCF_STRUCT);
scf_variable_t* v = NULL;
scf_type_t* type_v = NULL;
global_flag = 0;
member_flag = 1;
- if (0 == id0->nb_pointers && id0->type->type >= SCF_STRUCT) {
+ if (0 == id0->nb_pointers && id0->type->node.type >= SCF_STRUCT) {
// if not pointer var, check if define recursive struct/union/class var
if (_check_recursive((scf_type_t*)b, id0->type, id->identity) < 0) {
}
}
- if (SCF_FUNCTION_PTR == id0->type->type
+ if (SCF_FUNCTION_PTR == id0->type->node.type
&& (!id0->func_ptr || 0 == id0->nb_pointers)) {
scf_loge("invalid func ptr\n");
return SCF_DFA_ERROR;
}
}
- if (SCF_VAR_VOID == id0->type->type && 0 == id0->nb_pointers) {
+ if (SCF_VAR_VOID == id0->type->node.type && 0 == id0->nb_pointers) {
scf_loge("void var must be a pointer, like void*\n");
return SCF_DFA_ERROR;
}
if (!v_std)
return -ENOMEM;
- if (t->type != v0->type) {
+ if (t->node.type != v0->type) {
ret = _semantic_add_type_cast(ast, &nodes[0], v_std, nodes[0]);
if (ret < 0) {
scf_loge("add type cast failed\n");
}
}
- if (t->type != v1->type) {
+ if (t->node.type != v1->type) {
ret = _semantic_add_type_cast(ast, &nodes[1], v_std, nodes[1]);
if (ret < 0) {
scf_loge("add type cast failed\n");
if (!new)
return -ENOMEM;
- v_pf = SCF_VAR_ALLOC_BY_TYPE(t->w, pt, 1, 1, NULL);
+ v_pf = SCF_VAR_ALLOC_BY_TYPE(t->node.w, pt, 1, 1, NULL);
if (!v_pf)
return -ENOMEM;
v_pf->const_literal_flag = 1;
- node_pf = scf_node_alloc(t->w, v_pf->type, v_pf);
+ node_pf = scf_node_alloc(t->node.w, v_pf->type, v_pf);
if (!node_pf)
return -ENOMEM;
if (!argv)
return -ENOMEM;
- ret = _semantic_add_var(&nthis, ast, NULL, v0->w, class->type, 0, 1, NULL);
+ ret = _semantic_add_var(&nthis, ast, NULL, v0->w, class->node.type, 0, 1, NULL);
if (ret < 0) {
scf_vector_free(argv);
return ret;
scf_node_t* nl = nodes[0];
assert(SCF_LABEL == nl->type);
- scf_label_t* l = nl->label;
- assert(l->w);
-
- scf_label_t* l2 = scf_block_find_label(ast->current_block, l->w->text->data);
- if (!l2) {
+ scf_label_t* l = scf_block_find_label(ast->current_block, nl->w->text->data);
+ if (!l) {
scf_loge("label '%s' not found\n", l->w->text->data);
return -1;
}
if (ret < 0)
return ret;
- if (t->type != v0->type)
+ if (t->node.type != v0->type)
ret = _semantic_add_type_cast(ast, &nodes[0], v1, nodes[0]);
else
ret = _semantic_add_type_cast(ast, &nodes[1], v0, nodes[1]);
#include"scf_leb128.h"
#include"scf_eda.h"
-scf_base_type_t base_types[] =
+scf_base_type_t base_types[] =
{
- {SCF_VAR_CHAR, "char", 1},
-
- {SCF_VAR_VOID, "void", 1},
- {SCF_VAR_BIT, "bit", 1},
- {SCF_VAR_U2, "bit2_t", 1},
- {SCF_VAR_U3, "bit3_t", 1},
- {SCF_VAR_U4, "bit4_t", 1},
-
- {SCF_VAR_I1, "int1_t", 1},
- {SCF_VAR_I2, "int2_t", 1},
- {SCF_VAR_I3, "int3_t", 1},
- {SCF_VAR_I4, "int4_t", 1},
-
- {SCF_VAR_INT, "int", 4},
- {SCF_VAR_FLOAT, "float", 4},
- {SCF_VAR_DOUBLE, "double", 8},
-
- {SCF_VAR_I8, "int8_t", 1},
- {SCF_VAR_I16, "int16_t", 2},
- {SCF_VAR_I32, "int32_t", 4},
- {SCF_VAR_I64, "int64_t", 8},
-
- {SCF_VAR_U8, "uint8_t", 1},
- {SCF_VAR_U16, "uint16_t", 2},
- {SCF_VAR_U32, "uint32_t", 4},
- {SCF_VAR_U64, "uint64_t", 8},
-
- {SCF_VAR_INTPTR, "intptr_t", sizeof(void*)},
- {SCF_VAR_UINTPTR, "uintptr_t", sizeof(void*)},
- {SCF_FUNCTION_PTR, "funcptr", sizeof(void*)},
+ {"char", SCF_VAR_CHAR, 1},
+ {"void", SCF_VAR_VOID, 1},
+
+ {"bit", SCF_VAR_BIT, 1},
+ {"bit2_t", SCF_VAR_U2, 1},
+ {"bit3_t", SCF_VAR_U3, 1},
+ {"bit4_t", SCF_VAR_U4, 1},
+
+ {"int1_t", SCF_VAR_I1, 1},
+ {"int2_t", SCF_VAR_I2, 1},
+ {"int3_t", SCF_VAR_I3, 1},
+ {"int4_t", SCF_VAR_I4, 1},
+
+ {"int", SCF_VAR_INT, 4},
+ {"float", SCF_VAR_FLOAT, 4},
+ {"double", SCF_VAR_DOUBLE, 8},
+
+ {"int8_t", SCF_VAR_I8, 1},
+ {"int16_t", SCF_VAR_I16, 2},
+ {"int32_t", SCF_VAR_I32, 4},
+ {"int64_t", SCF_VAR_I64, 8},
+
+ {"uint8_t", SCF_VAR_U8, 1},
+ {"uint16_t", SCF_VAR_U16, 2},
+ {"uint32_t", SCF_VAR_U32, 4},
+ {"uint64_t", SCF_VAR_U64, 8},
+
+ {"intptr_t", SCF_VAR_INTPTR, sizeof(void*)},
+ {"uintptr_t", SCF_VAR_UINTPTR, sizeof(void*)},
+ {"funcptr", SCF_FUNCTION_PTR, sizeof(void*)},
};
int scf_parse_open(scf_parse_t** pparse)
tag = DW_TAG_pointer_type;
types = parse->debug->base_types;
- } else if (t->type < SCF_STRUCT) {
+ } else if (t->node.type < SCF_STRUCT) {
tag = DW_TAG_base_type;
types = parse->debug->base_types;
assert(ie->attributes->size == d->attributes->size);
- if (ie->type == t->type && ie->nb_pointers == nb_pointers)
+ if (ie->type == t->node.type && ie->nb_pointers == nb_pointers)
return ie;
#if 0
for (j = 0; j < d ->attributes->size; j++) {
types = parse->debug->base_types;
- } else if (t->type < SCF_STRUCT) {
+ } else if (t->node.type < SCF_STRUCT) {
d = scf_vector_find_cmp(parse->debug->abbrevs, (void*)DW_TAG_base_type, _debug_abbrev_find_by_tag);
if (!d) {
return -ENOMEM;
ie->code = d->code;
- ie->type = t->type;
+ ie->type = t->node.type;
ie->nb_pointers = nb_pointers;
ret = scf_vector_add(types, ie);
uint8_t ate;
- if (SCF_VAR_CHAR == t->type || SCF_VAR_I8 == t->type)
+ if (SCF_VAR_CHAR == t->node.type || SCF_VAR_I8 == t->node.type)
ate = DW_ATE_signed_char;
- else if (scf_type_is_signed(t->type))
+ else if (scf_type_is_signed(t->node.type))
ate = DW_ATE_signed;
- else if (SCF_VAR_U8 == t->type)
+ else if (SCF_VAR_U8 == t->node.type)
ate = DW_ATE_unsigned_char;
- else if (scf_type_is_unsigned(t->type))
+ else if (scf_type_is_unsigned(t->node.type))
ate = DW_ATE_unsigned;
- else if (scf_type_is_float(t->type))
+ else if (scf_type_is_float(t->node.type))
ate = DW_ATE_float;
else {
scf_loge("\n");
} else if (DW_AT_decl_line == iattr->name) {
- ret = scf_dwarf_info_fill_attr(iattr, (uint8_t*)&t->w->line, sizeof(t->w->line));
+ ret = scf_dwarf_info_fill_attr(iattr, (uint8_t*)&t->node.w->line, sizeof(t->node.w->line));
if (ret < 0)
return ret;
v_member = t->scope->vars->data[i];
- if (v_member->type != t->type)
+ if (v_member->type != t->node.type)
continue;
if (v_member->nb_pointers != j)
ie = _debug_find_type(parse, t, 0);
if (!ie) {
- if (t->type < SCF_STRUCT) {
+ if (t->node.type < SCF_STRUCT) {
ret = __debug_add_type(&ie, &d, parse, t, 0, NULL);
if (ret < 0)
scf_node_t* current_node;
- scf_node_t* current_while;
-
- scf_node_t* current_for;
- scf_vector_t* for_exprs;
-
scf_node_t* current_return;
scf_node_t* current_goto;