F diff --git a/src/semantics/value/constraints.c b/src/semantics/value/constraints.c
--- a/src/semantics/value/constraints.c
+++ b/src/semantics/value/constraints.c
}
}
/*
+ left operand is a modifiable lvalue
+
One of the following shall hold:
1. Left operand has qualified or unqualified arithmetic type and the
right has arithmetic type
struct Type *left_type;
struct Type *right_type;
+ if(!expression_value_is_modifiable(left->value))
+ {
+ push_translation_error("left operand of assignment operator must be modifiable",translation_data);
+ return 0;
+ }
+
left_type=extract_expresion_value_type(left->value,translation_data);
right_type=extract_expresion_value_type(right->value,translation_data);
//TODO ADD _BOOL TS
}
/*
+ left operand is a modifiable lvalue
if += or -=
1. left operand shall be a pointer to an object and the right operand shall be of integer type
2. left operand shall be qualified or unqualified arithmetic type and the right shall be an arithmetic type
struct Type *left_type;
struct Type *right_type;
+ if(!expression_value_is_modifiable(left->value))
+ {
+ push_translation_error("left operand of assignment operator must be modifiable",translation_data);
+ return 0;
+ }
+
switch(operation)
{
case OP_ADD_ASSIGN:
{
return 1;
}
+ /*
+ operand is a modifiable lvalue and has a (un)qualified real or pointer type
+ * */
char constraint_check_postfix_inc_dec_expression(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data)
{
- return 1;
+ struct Type *operand_type;
+
+ if(!expression_value_is_modifiable(operand->value))
+ {
+ push_translation_error("expected modifiable lvalue as operand to the ++/-- operator",translation_data);
+ return 0;
+ }
+ operand_type=extract_expresion_value_type(operand->value,translation_data);
+ if(type_is_real(operand_type) || type_is_pointer(operand_type))
+ {
+ return 1;
+ }else
+ {
+ push_translation_error("expected real or pointer type as the type of the operand in the ++/-- operator",translation_data);
+ return 0;
+ }
}
+ /*
+ operand is a modifiable lvalue and has a (un)qualified real or pointer type
+ * */
char constraint_check_prefix_inc_dec_expression(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data)
{
- return 1;
+ return constraint_check_postfix_inc_dec_expression(operand,operation,translation_data);
}
char constraint_check_cast_expression(struct Type *type,struct AST_Expression *expression,struct Translation_Data *translation_data)
{
F diff --git a/src/semantics/value/type.c b/src/semantics/value/type.c
--- a/src/semantics/value/type.c
+++ b/src/semantics/value/type.c
return (type->specifier==TS_POINTER && type_is_basic(AS_TYPE_PTR_PTR(type)->points_to) && AS_BASIC_TYPE_PTR(AS_TYPE_PTR_PTR(type)->points_to)->specifier==TS_VOID);
}
+ char type_is_real(struct Type *type)
+ {
+ /*TODO add _Complex keyword and check for it here*/
+ return type_is_floating(type) || type_is_integer_type(type);
+ }
+ char type_is_floating(struct Type *type)
+ {
+ return (type->specifier==TS_FLOAT || type->specifier==TS_DOUBLE);
+ }
char type_is_constant(struct Type *type)
{
switch(type->specifier)
F diff --git a/src/semantics/value/type.h b/src/semantics/value/type.h
--- a/src/semantics/value/type.h
+++ b/src/semantics/value/type.h
char type_is_pointer_to_object(struct Type *type);
char type_is_pointer_to_incomplete_type(struct Type *type);
char type_is_pointer_to_void(struct Type *type);
+ char type_is_real(struct Type *type);
+ char type_is_floating(struct Type *type);
/*these return 0 if constant/volatile-ness make no sense for the type*/
char type_is_constant(struct Type *type);
F diff --git a/src/semantics/value/value.c b/src/semantics/value/value.c
--- a/src/semantics/value/value.c
+++ b/src/semantics/value/value.c
}
+ inline char expression_value_is_modifiable(struct Expression_Value *expression_value)
+ {
+ return expression_value->type==VALUE_LVALUE && ((struct Expression_Value_LValue*)expression_value)->is_modifiable;
+ }
struct Type* extract_expresion_value_type(struct Expression_Value *expression_value,struct Translation_Data *translation_data)
{
F diff --git a/src/semantics/value/value.h b/src/semantics/value/value.h
--- a/src/semantics/value/value.h
+++ b/src/semantics/value/value.h
struct Type* extract_expresion_value_type(struct Expression_Value *expression_value,struct Translation_Data *translation_data);
+ char expression_value_is_modifiable(struct Expression_Value *expression_value);
+
void delete_expression_value(struct Expression_Value *expression_value);
void delete_expression_value_void(struct Expression_Value *void_expression_value);