Introducing TYPE_NOEXPR so that these undefined labels cannot be used on the expression side of goto ternary expressions; ast_label now is TYPE_NOEXPR; we may consider setting ast_ifthen to that too unless we want ifthen to return a value...

This commit is contained in:
Wolfgang Bumiller 2013-01-03 12:49:21 +01:00
parent e146fd121c
commit ae09831227
3 changed files with 12 additions and 1 deletions

2
ast.c
View file

@ -831,6 +831,8 @@ ast_label* ast_label_new(lex_ctx ctx, const char *name, bool undefined)
ast_instantiate(ast_label, ctx, ast_label_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_label_codegen);
self->expression.vtype = TYPE_NOEXPR;
self->name = util_strdup(name);
self->irblock = NULL;
self->gotos = NULL;

View file

@ -445,6 +445,7 @@ enum {
TYPE_ARRAY ,
TYPE_NIL , /* it's its own type / untyped */
TYPE_NOEXPR , /* simply invalid in expressions */
TYPE_COUNT
};

10
ir.c
View file

@ -44,7 +44,8 @@ const char *type_name[TYPE_COUNT] = {
"union",
"array",
"nil"
"nil",
"<no-expression>"
};
size_t type_sizeof_[TYPE_COUNT] = {
@ -62,6 +63,7 @@ size_t type_sizeof_[TYPE_COUNT] = {
0, /* TYPE_UNION */
0, /* TYPE_ARRAY */
0, /* TYPE_NIL */
0, /* TYPE_NOESPR */
};
uint16_t type_store_instr[TYPE_COUNT] = {
@ -85,6 +87,7 @@ uint16_t type_store_instr[TYPE_COUNT] = {
AINSTR_END, /* union */
AINSTR_END, /* array */
AINSTR_END, /* nil */
AINSTR_END, /* noexpr */
};
uint16_t field_store_instr[TYPE_COUNT] = {
@ -108,6 +111,7 @@ uint16_t field_store_instr[TYPE_COUNT] = {
AINSTR_END, /* union */
AINSTR_END, /* array */
AINSTR_END, /* nil */
AINSTR_END, /* noexpr */
};
uint16_t type_storep_instr[TYPE_COUNT] = {
@ -131,6 +135,7 @@ uint16_t type_storep_instr[TYPE_COUNT] = {
AINSTR_END, /* union */
AINSTR_END, /* array */
AINSTR_END, /* nil */
AINSTR_END, /* noexpr */
};
uint16_t type_eq_instr[TYPE_COUNT] = {
@ -154,6 +159,7 @@ uint16_t type_eq_instr[TYPE_COUNT] = {
AINSTR_END, /* union */
AINSTR_END, /* array */
AINSTR_END, /* nil */
AINSTR_END, /* noexpr */
};
uint16_t type_ne_instr[TYPE_COUNT] = {
@ -177,6 +183,7 @@ uint16_t type_ne_instr[TYPE_COUNT] = {
AINSTR_END, /* union */
AINSTR_END, /* array */
AINSTR_END, /* nil */
AINSTR_END, /* noexpr */
};
uint16_t type_not_instr[TYPE_COUNT] = {
@ -200,6 +207,7 @@ uint16_t type_not_instr[TYPE_COUNT] = {
AINSTR_END, /* union */
AINSTR_END, /* array */
AINSTR_END, /* nil */
AINSTR_END, /* noexpr */
};
/* protos */