diff options
author | Søren Sandmann <sandmann@redhat.com> | 2007-10-18 01:30:26 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2007-10-18 01:30:26 -0400 |
commit | 757c8d3e52ea7bb9fb8c836e310689e49db148ed (patch) | |
tree | 07219935e0b7aa82f7623da0f4ce9f3e2e2bea54 /type-check.c | |
parent | 642ac5bd670996cbef8754270e60a7219d546ed2 (diff) |
Get rid of type resolution function. Instead just overwrite the
contents of the type spec in the type-checker.
Diffstat (limited to 'type-check.c')
-rw-r--r-- | type-check.c | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/type-check.c b/type-check.c index 9ee3af1..f8464b6 100644 --- a/type-check.c +++ b/type-check.c @@ -27,12 +27,6 @@ * Various helpers */ static ast_type_spec_t * -resolve (const ast_type_spec_t *type) -{ - return ast_type_spec_resolve (type); -} - -static ast_type_spec_t * new_int32 (void) { return ast_type_spec_new (AST_INT32_TYPE); @@ -53,31 +47,31 @@ new_bool (void) static gboolean is_bool (ast_type_spec_t *type) { - return resolve (type)->common.type == AST_BOOL_TYPE; + return type->common.type == AST_BOOL_TYPE; } static gboolean is_null (ast_type_spec_t *type) { - return resolve (type)->common.type == AST_NULL_TYPE; + return type->common.type == AST_NULL_TYPE; } static gboolean is_int32 (ast_type_spec_t *type) { - return resolve (type)->common.type == AST_INT32_TYPE; + return type->common.type == AST_INT32_TYPE; } static gboolean is_void (ast_type_spec_t *type) { - return resolve (type)->common.type == AST_VOID_TYPE; + return type->common.type == AST_VOID_TYPE; } static gboolean is_function (ast_type_spec_t *type) { - return resolve (type)->common.type == AST_FUNCTION_TYPE; + return type->common.type == AST_FUNCTION_TYPE; } static gboolean @@ -101,8 +95,8 @@ promote_numeric (const ast_type_spec_t *left, { ast_type_spec_type_t new_type; - if (resolve (left)->common.type == AST_DOUBLE_TYPE || - resolve (right)->common.type == AST_DOUBLE_TYPE) + if (left->common.type == AST_DOUBLE_TYPE || + right->common.type == AST_DOUBLE_TYPE) { new_type = AST_DOUBLE_TYPE; } @@ -117,7 +111,7 @@ promote_numeric (const ast_type_spec_t *left, static ast_type_spec_t * get_type (ast_expression_t *expr) { - return ast_type_spec_resolve (expr->common.type_spec); + return expr->common.type_spec; } static gboolean assignable (ast_type_spec_t *left, @@ -165,15 +159,13 @@ is_class (ast_type_spec_t *type) { g_return_val_if_fail (type != NULL, FALSE); - return resolve(type)->common.type == AST_OBJECT_TYPE; + return type->common.type == AST_OBJECT_TYPE; } static gboolean is_array (ast_type_spec_t *type) { - type = ast_type_spec_resolve (type); - - return resolve(type)->common.type == AST_ARRAY_TYPE; + return type->common.type == AST_ARRAY_TYPE; } static gboolean @@ -277,14 +269,15 @@ type_check_resolve_identifiers (ast_t *ast) for (list = ast->common.children->head; list != NULL; list = list->next) type_check_resolve_identifiers (list->data); - if (ast_is (ast, AST_TYPE_SPEC, AST_IDENTIFIER_TYPE)) + while (ast_is (ast, AST_TYPE_SPEC, AST_IDENTIFIER_TYPE)) { ast_identifier_type_spec_t *id = &ast->type_spec.identifier; - + ast_type_spec_t *spec = &ast->type_spec; + if (id->definition->common.type == AST_CLASS_DEFINITION) - id->resolved = id->definition->class.type_spec; + *spec = *id->definition->class.type_spec; else if (id->definition->common.type == AST_TYPE_DEFINITION) - id->resolved = id->definition->type.type_spec; + *spec = *id->definition->type.type_spec; else g_assert_not_reached(); } @@ -518,8 +511,7 @@ type_check_arguments (ast_type_spec_t **types, for (i = 0; types[i] != NULL; ++i) { - if (!assignable (ast_type_spec_resolve (types[i]), - ast_type_spec_resolve (arguments[i]->common.type_spec))) + if (!assignable (types[i], arguments[i]->common.type_spec)) { g_print ("Type error in argument list\n"); return FALSE; @@ -569,15 +561,13 @@ type_check_expression (ast_expression_t *expr) case AST_IDENTIFIER_EXPRESSION: id_expr = &expr->identifier; - /* FIXME: this code is duplicated below */ + switch (id_expr->definition->common.type) { case AST_VARIABLE_DEFINITION: - expr->common.type_spec = - ast_type_spec_resolve (id_expr->definition->variable.type_spec); + expr->common.type_spec = id_expr->definition->variable.type_spec; - if (expr->common.type_spec->common.type == AST_INFERRED_TYPE && - !expr->common.type_spec->inferred.resolved) + if (expr->common.type_spec->common.type == AST_INFERRED_TYPE) { g_print ("Type of %s cannot be determined at this point\n", id_expr->definition->variable.name); |