src/onyxastnodes.c
// NOTE: Returns 0 if it was not possible to make the types compatible.
Returns 0 if it was not possible to make the types compatible.
Returns 0 if it was not possible to make the types compatible .
b32 type_check_or_auto_cast(AstTyped** pnode, Type* type) {
    AstTyped* node = *pnode;
    assert(type != NULL);
    assert(node != NULL);
    if (node->kind == Ast_Kind_Polymorphic_Proc) {
        AstFunction* func = polymorphic_proc_lookup((AstPolyProc *) node, PPLM_By_Function_Type, type, node->token->pos);
        if (func == NULL) return 0;
        *pnode = (AstTyped *) func;
        node = *pnode;
    }
    if (type->kind == Type_Kind_Function && (node->flags & Ast_Flag_Proc_Is_Null) != 0) return 1;
    if (types_are_compatible(node->type, type)) return 1;
    if (node_is_auto_cast((AstNode *) node)) {
        char* dummy;
        if (!cast_is_legal(((AstUnaryOp *) node)->expr->type, type, &dummy)) {
            return 0;
        } else {
            ((AstUnaryOp *) node)->type = type;
            return 1;
        }
    }
    else if (node->kind == Ast_Kind_NumLit) {
        if (convert_numlit_to_type((AstNumLit *) node, type)) return 1;
    }
    else if (node->kind == Ast_Kind_Compound) {
        if (type->kind != Type_Kind_Compound) return 0;
        AstCompound* compound = (AstCompound *) node;
        u32 expr_count = bh_arr_length(compound->exprs);
        if (expr_count != type->Compound.count) return 0;
        fori (i, 0, (i64) expr_count) {
            if (!type_check_or_auto_cast(&compound->exprs[i], type->Compound.types[i])) return 0;
        }
        compound->type = type_build_compound_type(semstate.node_allocator, compound);
        return 1;
    }
    return 0;
}
b32 type_check_or_auto_cast ( AstTyped * * pnode , Type * type ) { AstTyped * node = * pnode ; assert ( type != NULL ) ; assert ( node != NULL ) ; if ( node -> kind == Ast_Kind_Polymorphic_Proc ) { AstFunction * func = polymorphic_proc_lookup ( ( AstPolyProc * ) node , PPLM_By_Function_Type , type , node -> token -> pos ) ; if ( func == NULL ) return 0 ; * pnode = ( AstTyped * ) func ; node = * pnode ; } if ( type -> kind == Type_Kind_Function && ( node -> flags & Ast_Flag_Proc_Is_Null ) != 0 ) return 1 ; if ( types_are_compatible ( node -> type , type ) ) return 1 ; if ( node_is_auto_cast ( ( AstNode * ) node ) ) { char * dummy ; if ( ! cast_is_legal ( ( ( AstUnaryOp * ) node ) -> expr -> type , type , & dummy ) ) { return 0 ; } else { ( ( AstUnaryOp * ) node ) -> type = type ; return 1 ; } } else if ( node -> kind == Ast_Kind_NumLit ) { if ( convert_numlit_to_type ( ( AstNumLit * ) node , type ) ) return 1 ; } else if ( node -> kind == Ast_Kind_Compound ) { if ( type -> kind != Type_Kind_Compound ) return 0 ; AstCompound * compound = ( AstCompound * ) node ; u32 expr_count = bh_arr_length ( compound -> exprs ) ; if ( expr_count != type -> Compound . count ) return 0 ; fori ( i , 0 , ( i64 ) expr_count ) { if ( ! type_check_or_auto_cast ( & compound -> exprs [ i ] , type -> Compound . types [ i ] ) ) return 0 ; } compound -> type = type_build_compound_type ( semstate . node_allocator , compound ) ; return 1 ; } return 0 ; }
NOTE: Returns 0 if it was not possible to make the types compatible.
NOTE : Returns 0 if it was not possible to make the types compatible .
// HACK: NullProcHack