static matchtype_t is_nominal_match_entity(ast_t* operand, ast_t* pattern) { AST_GET_CHILDREN(operand, o_pkg, o_id, o_typeargs, o_cap, o_eph); AST_GET_CHILDREN(pattern, p_pkg, p_id, p_typeargs, p_cap, p_eph); // We say the pattern provides the operand if it is a subtype after changing // it to have the same refcap as the operand. token_id tcap = ast_id(p_cap); token_id teph = ast_id(p_eph); ast_t* r_operand = set_cap_and_ephemeral(operand, tcap, teph); bool provides = is_subtype(pattern, r_operand, false); ast_free_unattached(r_operand); // If the pattern doesn't provide the operand, reject the match. if(!provides) return MATCHTYPE_REJECT; // If the operand does provide the pattern, but the operand refcap can't // match the pattern refcap, deny the match. if(!is_cap_match_cap(ast_id(o_cap), ast_id(o_eph), tcap, teph)) return MATCHTYPE_DENY; // Otherwise, accept the match. return MATCHTYPE_ACCEPT; }
static matchtype_t is_entity_match_trait(ast_t* operand, ast_t* pattern, pass_opt_t* opt) { AST_GET_CHILDREN(operand, o_pkg, o_id, o_typeargs, o_cap, o_eph); AST_GET_CHILDREN(pattern, p_pkg, p_id, p_typeargs, p_cap, p_eph); token_id tcap = ast_id(p_cap); token_id teph = ast_id(p_eph); ast_t* r_operand = set_cap_and_ephemeral(operand, tcap, teph); bool provides = is_subtype(r_operand, pattern, NULL, opt); ast_free_unattached(r_operand); // If the operand doesn't provide the pattern (trait or interface), reject // the match. if(!provides) return MATCHTYPE_REJECT; // If the operand does provide the pattern, but the operand refcap can't // match the pattern refcap, deny the match. if(!is_cap_match_cap(ast_id(o_cap), ast_id(o_eph), tcap, teph)) return MATCHTYPE_DENY; // Otherwise, accept the match. return MATCHTYPE_ACCEPT; }
static matchtype_t is_trait_match_trait(ast_t* operand, ast_t* pattern) { AST_GET_CHILDREN(operand, o_pkg, o_id, o_typeargs, o_cap, o_eph); AST_GET_CHILDREN(pattern, p_pkg, p_id, p_typeargs, p_cap, p_eph); // If the operand refcap can't match the pattern refcap, deny the match. if(!is_cap_match_cap(ast_id(o_cap), ast_id(o_eph), ast_id(p_cap), ast_id(p_eph))) return MATCHTYPE_DENY; // Otherwise, accept the match. return MATCHTYPE_ACCEPT; }