diff --git a/src/ast.h b/src/ast.h index c7ae211..aecff7d 100644 --- a/src/ast.h +++ b/src/ast.h @@ -66,18 +66,11 @@ typedef enum { UNOP_REF = 3, } UnaryOp; -typedef enum { - EXPRESSION_CONSTANT_TRUTHY, - EXPRESSION_CONSTANT_FALSY, - EXPRESSION_NOT_CONSTANT -} ASTExprConstantType; - union AST; typedef struct { ASTKind nodeKind; Type *type; - ASTExprConstantType constantType; } ASTExpr; typedef struct { diff --git a/src/parse.c b/src/parse.c index 76f2942..2bc17b5 100644 --- a/src/parse.c +++ b/src/parse.c @@ -83,8 +83,6 @@ static ASTExprPrimitive *parse_prim(Parser *P) { ret->val = strtol(str, NULL, base); - ret->constantType = ret->val == 0 ? EXPRESSION_CONSTANT_FALSY : EXPRESSION_CONSTANT_TRUTHY; - return ret; } @@ -108,7 +106,6 @@ AST *nct_cast_expr(AST *what, Type *to) { if(to->type == TYPE_TYPE_ARRAY && type_equal(primitive_parse("u8"), to->array.of) && to->array.length == what->exprStrLit.length) { ASTExprArray *ret = malloc(sizeof(*ret)); ret->nodeKind = AST_EXPR_ARRAY; - ret->constantType = what->expression.constantType; ret->items = malloc(sizeof(*ret->items) * to->array.length); ret->type = to; @@ -117,7 +114,6 @@ AST *nct_cast_expr(AST *what, Type *to) { ASTExprPrimitive *item = malloc(sizeof(*item)); item->nodeKind = AST_EXPR_PRIMITIVE; - item->constantType = bajt == 0 ? EXPRESSION_CONSTANT_FALSY : EXPRESSION_CONSTANT_TRUTHY; item->type = to->array.of; item->val = bajt; @@ -130,7 +126,6 @@ AST *nct_cast_expr(AST *what, Type *to) { ret->nodeKind = AST_EXPR_PRIMITIVE; ret->type = primitive_parse("u32"); memcpy(&ret->val, what->exprStrLit.data, sizeof(ret->val)); - ret->constantType = what->expression.constantType; return (AST*) ret; } else abort(); } @@ -144,14 +139,12 @@ AST *nct_cast_expr(AST *what, Type *to) { if(what->nodeKind == AST_EXPR_PRIMITIVE && to->type == TYPE_TYPE_PRIMITIVE) { ASTExprPrimitive *ret = malloc(sizeof(*ret)); ret->nodeKind = AST_EXPR_PRIMITIVE; - ret->constantType = what->exprPrim.val == 0 ? EXPRESSION_CONSTANT_FALSY : EXPRESSION_CONSTANT_FALSY; ret->type = to; ret->val = what->exprPrim.val & (((int64_t) 1 << to->primitive.width) - 1); return (AST*) ret; } else { ASTExprCast *ret = malloc(sizeof(*ret)); ret->nodeKind = AST_EXPR_CAST; - ret->constantType = EXPRESSION_CONSTANT_TRUTHY; ret->type = to; ret->what = what; ret->to = to; @@ -177,22 +170,12 @@ AST *nct_parse_expression(Parser *P, int lOP) { ret->data = tok.content; ret->length = tok.length; - ret->constantType = EXPRESSION_CONSTANT_FALSY; - - for(size_t i = 0; i < tok.length; i++) { - if(tok.content[i]) { - ret->constantType = EXPRESSION_CONSTANT_TRUTHY; - break; - } - } - return (AST*) ret; } } else if(lOP == 4) { if(maybe(P, TOKEN_STAR)) { ASTExprUnaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_UNARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->operator = UNOP_DEREF; astop->operand = nct_parse_expression(P, lOP); /* Not +1! */ astop->type = astop->operand->expression.type->pointer.of; @@ -201,7 +184,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { } else if(maybe(P, TOKEN_AMPERSAND)) { ASTExprUnaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_UNARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->operator = UNOP_REF; astop->operand = nct_parse_expression(P, lOP); astop->type = type_pointer_wrap(astop->operand->expression.type); @@ -216,7 +198,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { } else { ASTExprUnaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_UNARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->operator = UNOP_NEGATE; astop->operand = operand; astop->type = operand->expression.type; @@ -233,7 +214,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { } else { ASTExprUnaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_UNARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->operator = UNOP_BITWISE_NOT; astop->operand = child; astop->type = child->expression.type; @@ -252,7 +232,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { ASTExprCall *call = malloc(sizeof(*call)); call->nodeKind = AST_EXPR_CALL; - call->constantType = EXPRESSION_NOT_CONSTANT; call->type = ret->expression.type->function.ret; call->what = ret; call->args = NULL; @@ -277,14 +256,12 @@ AST *nct_parse_expression(Parser *P, int lOP) { } else if(maybe(P, TOKEN_SQUAREN_L)) { ASTExprUnaryOp *ref = malloc(sizeof(*ref)); ref->nodeKind = AST_EXPR_UNARY_OP; - ref->constantType = EXPRESSION_NOT_CONSTANT; ref->operator = UNOP_REF; ref->operand = ret; ref->type = type_pointer_wrap(ret->expression.type->array.of); ASTExprBinaryOp *child = malloc(sizeof(*child)); child->nodeKind = AST_EXPR_BINARY_OP; - child->constantType = EXPRESSION_NOT_CONSTANT; child->operands[0] = (AST*) ref; child->operands[1] = nct_parse_expression(P, 0); child->operator = BINOP_ADD; @@ -308,7 +285,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { ASTExprUnaryOp *unop = malloc(sizeof(*unop)); unop->nodeKind = AST_EXPR_UNARY_OP; - unop->constantType = EXPRESSION_NOT_CONSTANT; unop->type = ret->expression.type->array.of; unop->operator = UNOP_DEREF; unop->operand = (AST*) child; @@ -332,7 +308,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { ASTExprBinaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_BINARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->type = ret->expression.type; astop->operator = op; astop->operands[0] = ret; @@ -361,7 +336,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { AST *operand2 = malloc(sizeof(ASTExprVar)); operand2->nodeKind = AST_EXPR_VAR; operand2->expression.type = operand->expression.type; - operand2->expression.constantType = EXPRESSION_NOT_CONSTANT; operand2->exprVar.thing = thing; operand = operand2; } @@ -402,7 +376,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { ASTExprBinaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_BINARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->type = ret->expression.type; astop->operator = op; astop->operands[0] = ret; @@ -438,7 +411,6 @@ AST *nct_parse_expression(Parser *P, int lOP) { ASTExprBinaryOp *astop = malloc(sizeof(*astop)); astop->nodeKind = AST_EXPR_BINARY_OP; - astop->constantType = EXPRESSION_NOT_CONSTANT; astop->type = NULL; astop->operator = op; astop->operands[0] = ret; @@ -613,9 +585,9 @@ static AST *parse_declaration(Parser *P) { ret->expression = nct_cast_expr(nct_parse_expression(P, 0), type); if(ret->expression) { - if(ret->expression->expression.constantType == EXPRESSION_NOT_CONSTANT) { - stahp(1, 4142, "Symbol declaration may contain constant expressions only."); - } + //if(ret->expression->expression.constantType == EXPRESSION_NOT_CONSTANT) { + // stahp(1, 4142, "Symbol declaration may contain constant expressions only."); + //} } } else if(isExternal) { entry->kind = VARTABLEENTRY_SYMBOL;