WONKY



LOG | FILES | OVERVIEW


F diff --git a/src/frontend/parse/.parse_expression.c.swp b/src/frontend/parse/.parse_expression.c.swp new file mode 100644
B Binary files /dev/null and b/src/frontend/parse/.parse_expression.c.swp differ
F diff --git a/src/semantics/ast.c b/src/semantics/ast.c --- a/src/semantics/ast.c +++ b/src/semantics/ast.c
return ret;
}
+ struct AST_Binary_Expression* get_modulo_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data)
+ {
+ struct Type *hold_type;
+ hold_type=extract_expresion_value_type(left,translation_data);
+ if(!type_is_integer_type(hold_type))
+ { push_translation_error("expected integer type in modulo operation",translation_data); return get_error_tree(get_binary_expression_tree(left,right,OP_REMAINDER)); }
+
+ hold_type=extract_expresion_value_type(right,translation_data);
+ if(!type_is_integer_type(hold_type))
+ { push_translation_error("expected integer type in modulo operation",translation_data); return get_error_tree(get_binary_expression_tree(left,right,OP_REMAINDER)); }
+ return get_binary_expression_after_conversion(left,right,OP_REMAINDER,translation_data);
+
+ }
+ struct AST_Binary_Expression* get_multiplicative_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ struct Type *hold_type;
+ hold_type=extract_expresion_value_type(left,translation_data);
+ if(!type_is_arithmetic(hold_type))
+ { push_translation_error("expected arithmetic type in multiplicative operation",translation_data); return get_error_tree(get_binary_expression_tree(left,right,operation)); }
+
+ hold_type=extract_expresion_value_type(right,translation_data);
+ if(!type_is_arithmetic(hold_type))
+ { push_translation_error("expected arithmetic type in multiplicative operation",translation_data); return get_error_tree(get_binary_expression_tree(left,right,OP_REMAINDER)); }
+ return get_binary_expression_after_conversion(left,right,operation,translation_data);
+ }
+ struct AST_Binary_Expression* get_additive_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ struct Type *left_type;
+ struct Type *right_type;
+
+ left_type=extract_expresion_value_type(left,translation_data);
+ right_type=extract_expresion_value_type(left,translation_data);
+
+ if(!type_is_arithmetic(left_type))
+ {
+ if(left_type->specifier==TS_POINTER && type_is_integer_type(right_type))
+ {
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(left_type)),OP_POINTER_ADDITION);
+ }else
+ {
+ push_translation_error("expected arithmetic type in additive operation",translation_data);
+ return get_error_tree(get_binary_expression_tree(left,right,operation));
+ }
+ }else if(!type_is_arithmetic(right_type))
+ {
+ if(right_type->specifier==TS_POINTER && type_is_integer_type(left_type))
+ {
+ return get_binary_expression_tree(right,left,get_expression_value_rvalue(get_temp_object(right_type)),OP_POINTER_ADDITION);
+ }else
+ {
+ push_translation_error("expected arithmetic type in additive operation",translation_data);
+ return get_error_tree(get_binary_expression_tree(left,right,operation));
+ }
+ }else
+ {
+ return get_binary_expression_after_conversion(left,right,operation,translation_data);
+ }
+ }
+ struct AST_Binary_Expression* get_shift_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ struct Type *left_type;
+ struct Type *right_type;
+
+ left_type=extract_expresion_value_type(left,translation_data);
+ right=extract_expresion_value_type(right,translation_data);
+
+ if(!type_is_integer_type(left_type) || !type_is_integer_type(right_type))
+ {
+ push_translation_error("expected integer type in shift operation",translation_data);
+ return get_error_tree(get_binary_expression_tree(left,right,operation));
+ }
+ left=get_promoted_expression(left,translation_data);
+ right=get_promoted_expression(right,translation_data);
+
+ left_type=extract_expresion_value_type(left,translation_data);
+ right=extract_expresion_value_type(right,translation_data);
+
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(left_type)),operation);
+
+ }
+ struct AST_Binary_Expression* get_bitwise_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ struct Type *left_type;
+ struct Type *right_type;
+
+ left_type=extract_expresion_value_type(left,translation_data);
+ right=extract_expresion_value_type(right,translation_data);
+
+ if(!type_is_integer_type(left_type) || !type_is_integer_type(right_type))
+ {
+ push_translation_error("expected integer type in bitwise operation",translation_data);
+ return get_error_tree(get_binary_expression_tree(left,right,operation));
+ }
+ return get_binary_expression_after_conversion(left,right,operation,translation_data);
+ }
+
+ /*TODO*/
+ struct AST_Binary_Expression* get_equality_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
+
+ }
+ struct AST_Binary_Expression* get_logical_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ struct Type *left_type;
+ struct Type *right_type;
+
+ left_type=extract_expresion_value_type(left,translation_data);
+ right=extract_expresion_value_type(right,translation_data);
+
+ if(!type_is_scalar(left_type) || !type_is_scalar(right_type))
+ {
+ push_translation_error("expected scalar type in logical expression",translation_data);
+ return get_error_tree(get_binary_expression_tree(left,right,operation));
+ }
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
+ }
+
+ /*TODO*/
+ struct AST_Binary_Expression* get_assignment_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
+ {
+ struct
+ if(left->value->type!=VALUE_LVALUE)
+ {
+ push_translation_error("expected lvalue in left operand of assignment expression",translation_data);
+ return get_error_tree(get_binary_expression_tree(left,right,operation));
+ }else
+ {
+ return get_binary_expression_tree(left,right,get_temp
+ }
+ }
+
struct AST_Binary_Expression* get_binary_expression_after_conversion(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type type,struct Translation_Data *translation_data)
{
struct Type_Basic *left_type;
F diff --git a/src/semantics/ast.h b/src/semantics/ast.h --- a/src/semantics/ast.h +++ b/src/semantics/ast.h
struct AST_Expression *right;
};
+ struct AST_Pointer_Addition_Expression
+ {
+ enum AST_Type type;
+ struct Expression_Value *value;
+
+ struct AST_Expression *pointer;
+ struct AST_Expression *integer;
+ };
struct AST_Conditional_Expression
{
enum AST_Type type;
struct AST_Binary_Expression* get_binary_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Expression_Value *value,enum AST_Type type);
struct AST_Binary_Expression* get_binary_expression_after_conversion(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type type,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_modulo_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_multiplicative_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_additive_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+
+ struct AST_Binary_Expression* get_shift_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_bitwise_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_equality_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_logical_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_assignment_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_comma_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
+
+
+
struct AST_Binary_Expression* get_array_subscript_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_address_expression_tree(struct AST_Expression *operand);
struct AST_Unary_Expression* get_sizeof_by_type_tree(struct Type *type);
struct AST_Unary_Expression* get_unary_arithmetic_tree(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data);
+ struct AST_Unary_Expression* get_postfix_inc_dec_tree(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data);
+
+ //TODO compound literals
+
+
F diff --git a/src/semantics/ast.hh b/src/semantics/ast.hh --- a/src/semantics/ast.hh +++ b/src/semantics/ast.hh
enum AST_Type{
OP_COMMA
- ,OP_ADDITION,OP_SUBTRACTION,OP_MUL,OP_DIV,OP_REMAINDER
+ ,OP_ADDITION,OP_POINTER_ADDITION,OP_SUBTRACTION,OP_MUL,OP_DIV,OP_REMAINDER
,OP_COND,OP_FUNCTION
,OP_ASSIGN,OP_ADD_ASSIGN,OP_SUBTRACT_ASSIGN,OP_MULTIPLY_ASSIGN,OP_REMAINDER_ASSIGN,OP_DIV_ASSIGN
,OP_SHIFT_LEFT_ASSIGN,OP_SHIFT_RIGHT_ASSIGN