static declaration_t *allocate_declaration_zero(void)
{
- return allocate_ast_zero(sizeof(*allocate_declaration_zero()));
+ declaration_t *declaration = allocate_ast_zero(sizeof(*allocate_declaration_zero()));
+ declaration->type = type_error_type;
+ return declaration;
}
/**
size_t size = get_expression_struct_size(kind);
expression_t *res = allocate_ast_zero(size);
- res->base.kind = kind;
+ res->base.kind = kind;
+ res->base.datatype = type_error_type;
return res;
}
}
break;
- /* TODO: if type != NULL for the following rules should issue
+ /* TODO: if is_type_valid(type) for the following rules should issue
* an error */
case T_struct: {
type = allocate_type_zero(TYPE_COMPOUND_STRUCT);
* Check if a given type is a vilid array type.
*/
static bool is_valid_array_type(const type_t *type) {
- if (type == NULL) {
- /* the error type should be already handled */
- return true;
- }
if (type->kind == TYPE_ARRAY) {
const array_type_t *array = &type->array;
- const type_t *etype = array->element_type;
+ const type_t *etype = skip_typeref(array->element_type);
if (! is_valid_array_type(etype))
return false;
- if (etype != NULL && etype->kind == TYPE_ATOMIC) {
+ if (etype->kind == TYPE_ATOMIC) {
const atomic_type_t *atype = &etype->atomic;
if (atype->akind == ATOMIC_TYPE_VOID) {
static declaration_t *record_declaration(declaration_t *declaration)
{
declaration = internal_record_declaration(declaration, false);
- const type_t *type = declaration->type;
- if (type != NULL) {
- /* check the type here for several not allowed combinations */
- if (! is_valid_array_type(type)) {
- errorf(declaration->source_position, "declaration of '%Y' as array of voids",
- declaration->symbol);
+ const type_t *type = skip_typeref(declaration->type);
+
+ /* check the type here for several not allowed combinations */
+ if (type->kind == TYPE_FUNCTION) {
+ const function_type_t* function_type = &type->function;
+ const type_t* ret_type = skip_typeref(function_type->return_type);
+
+ if (ret_type->kind == TYPE_FUNCTION) {
+ errorf(declaration->source_position, "'%Y' declared as function returning a function",
+ declaration->symbol);
+ declaration->type = type_error_type;
}
}
+ if (! is_valid_array_type(type)) {
+ errorf(declaration->source_position, "declaration of '%Y' as array of voids",
+ declaration->symbol);
+ declaration->type = type_error_type;
+ }
return declaration;
}
eat('=');
type_t *orig_type = declaration->type;
- type_t *type = NULL;
- if(orig_type != NULL)
- type = skip_typeref(orig_type);
+ type_t *type = type = skip_typeref(orig_type);
if(declaration->init.initializer != NULL) {
parser_error_multiple_definition(declaration, token.source_position);
/* ยง 6.7.5 (22) array initializers for arrays with unknown size determine
* the array type size */
- if(type != NULL && is_type_array(type) && initializer != NULL) {
+ if(is_type_array(type) && initializer != NULL) {
array_type_t *array_type = &type->array;
if(array_type->size == NULL) {
}
}
- if(type != NULL && is_type_function(type)) {
+ if(is_type_function(type)) {
errorf(declaration->source_position,
"initializers not allowed for function types at declator '%Y' (type '%T')",
declaration->symbol, orig_type);
type_t *orig_type = declaration->type;
type_t *type = skip_typeref(orig_type);
- if(type->kind != TYPE_FUNCTION && declaration->is_inline) {
+ if(is_type_valid(type) &&
+ type->kind != TYPE_FUNCTION && declaration->is_inline) {
warningf(declaration->source_position,
"variable '%Y' declared 'inline'\n", declaration->symbol);
}
function_type_t *function_type = NULL;
type_t *orig_type = expression->base.datatype;
- if(orig_type != NULL) {
+ if(is_type_valid(orig_type)) {
type_t *type = skip_typeref(orig_type);
if(is_type_pointer(type)) {
/* 6.5.15.2 */
type_t *condition_type_orig = expression->base.datatype;
- if(condition_type_orig != NULL) {
+ if(is_type_valid(condition_type_orig)) {
type_t *condition_type = skip_typeref(condition_type_orig);
- if(condition_type != NULL && !is_type_scalar(condition_type)) {
+ if(condition_type->kind != TYPE_ERROR && !is_type_scalar(condition_type)) {
type_error("expected a scalar type in conditional condition",
expression->base.source_position, condition_type_orig);
}
type_t *orig_true_type = true_expression->base.datatype;
type_t *orig_false_type = false_expression->base.datatype;
- if(orig_true_type == NULL || orig_false_type == NULL)
+ if(!is_type_valid(orig_true_type) || !is_type_valid(orig_false_type))
return result;
type_t *true_type = skip_typeref(orig_true_type);
static void semantic_incdec(unary_expression_t *expression)
{
type_t *orig_type = expression->value->base.datatype;
- if(orig_type == NULL)
+ if(!is_type_valid(orig_type))
return;
type_t *type = skip_typeref(orig_type);
static void semantic_unexpr_arithmetic(unary_expression_t *expression)
{
type_t *orig_type = expression->value->base.datatype;
- if(orig_type == NULL)
+ if(!is_type_valid(orig_type))
return;
type_t *type = skip_typeref(orig_type);
static void semantic_unexpr_scalar(unary_expression_t *expression)
{
type_t *orig_type = expression->value->base.datatype;
- if(orig_type == NULL)
+ if(!is_type_valid(orig_type))
return;
type_t *type = skip_typeref(orig_type);
static void semantic_unexpr_integer(unary_expression_t *expression)
{
type_t *orig_type = expression->value->base.datatype;
- if(orig_type == NULL)
+ if(!is_type_valid(orig_type))
return;
type_t *type = skip_typeref(orig_type);
static void semantic_dereference(unary_expression_t *expression)
{
type_t *orig_type = expression->value->base.datatype;
- if(orig_type == NULL)
+ if(!is_type_valid(orig_type))
return;
type_t *type = skip_typeref(orig_type);
value->base.datatype = revert_automatic_type_conversion(value);
type_t *orig_type = value->base.datatype;
- if(orig_type == NULL)
+ if(!is_type_valid(orig_type))
return;
if(value->kind == EXPR_REFERENCE) {
"'return' with a value, in function returning void");
return_value = NULL;
} else {
- if(return_type != NULL) {
+ if(is_type_valid(return_type)) {
semantic_assign(return_type, &return_value, "'return'");
}
}