コード例 #1
0
ファイル: matchtype.c プロジェクト: aturley/ponyc
static matchtype_t is_nominal_match_nominal(ast_t* operand, ast_t* pattern,
  errorframe_t* errorf, bool report_reject, pass_opt_t* opt)
{
  ast_t* pattern_def = (ast_t*)ast_data(pattern);

  switch(ast_id(pattern_def))
  {
    case TK_PRIMITIVE:
    case TK_CLASS:
    case TK_ACTOR:
      return is_nominal_match_entity(operand, pattern, errorf, report_reject,
        opt);

    case TK_STRUCT:
      return is_nominal_match_struct(operand, pattern, errorf, report_reject,
        opt);

    case TK_TRAIT:
    case TK_INTERFACE:
      return is_nominal_match_trait(operand, pattern, errorf, report_reject,
        opt);

    default: {}
  }

  pony_assert(0);
  return MATCHTYPE_DENY;
}
コード例 #2
0
ファイル: matchtype.c プロジェクト: aturley/ponyc
static matchtype_t is_nominal_match_struct(ast_t* operand, ast_t* pattern,
  errorframe_t* errorf, bool report_reject, pass_opt_t* opt)
{
  // A struct pattern can only be used if the operand is the same struct.
  // Otherwise, since there is no type descriptor, there is no way to
  // determine a match at runtime.
  ast_t* operand_def = (ast_t*)ast_data(operand);
  ast_t* pattern_def = (ast_t*)ast_data(pattern);

  // This must be a deny to prevent a union or intersection type that includes
  // the same struct as the pattern from matching.
  if(operand_def != pattern_def)
  {
    if((errorf != NULL) && report_reject)
    {
      ast_error_frame(errorf, pattern,
        "%s cannot match %s: the pattern type is a struct",
        ast_print_type(operand), ast_print_type(pattern));
      ast_error_frame(errorf, pattern,
        "since a struct has no type descriptor, pattern matching at runtime "
        "would be impossible");
    }

    return MATCHTYPE_DENY;
  }

  return is_nominal_match_entity(operand, pattern, errorf, report_reject, opt);
}
コード例 #3
0
ファイル: matchtype.c プロジェクト: mgist/ponyc
static matchtype_t is_nominal_match_nominal(ast_t* operand, ast_t* pattern)
{
  ast_t* pattern_def = (ast_t*)ast_data(pattern);

  switch(ast_id(pattern_def))
  {
    case TK_PRIMITIVE:
    case TK_STRUCT:
    case TK_CLASS:
    case TK_ACTOR:
      return is_nominal_match_entity(operand, pattern);

    case TK_TRAIT:
    case TK_INTERFACE:
      return is_nominal_match_trait(operand, pattern);

    default: {}
  }

  assert(0);
  return MATCHTYPE_DENY;
}