private static type_compare get_table_type_compare(type_node left, type_node right) { type_intersection_node[] tins = get_type_intersections(left, right); if (tins.Length == 0) { return(type_compare.non_comparable_type); } if (tins.Length == 1) { return(tins[0].type_compare); } if (tins.Length == 2) { type_compare tc1 = tins[0].type_compare; type_compare tc2 = tins[1].type_compare; if ((tc1 == type_compare.non_comparable_type) && (tc2 == type_compare.non_comparable_type)) { return(type_compare.non_comparable_type); } if ((tc1 == type_compare.greater_type) && (tc2 == type_compare.less_type)) { return(type_compare.greater_type); } if ((tc1 == type_compare.less_type) && (tc2 == type_compare.greater_type)) { return(type_compare.less_type); } throw new PascalABCCompiler.TreeConverter.CompilerInternalError("Conflicting type comparsion"); } return(type_compare.non_comparable_type); }
public static type_compare compare_types(type_node left, type_node right) { type_compare ret = get_table_type_compare(left, right); if (ret != type_compare.non_comparable_type) { return(ret); } if (is_derived(left, right)) { return(type_compare.greater_type); } if (is_derived(right, left)) { return(type_compare.less_type); } return(type_compare.non_comparable_type); }
public static basic_function_node make_generated_type_conversion(type_node from, type_node to, type_compare tc, SemanticTree.basic_function_type bft, bool is_implicit) { basic_function_node conv_method = new basic_function_node(bft, to, false); basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name, from, SemanticTree.parameter_type.value, conv_method); conv_method.parameters.AddElement(bp); type_table.add_generated_type_conversion_from_defined(from, to, conv_method, tc, is_implicit); return conv_method; }
public static basic_function_node make_type_conversion(type_node from, type_node to, type_compare tc, SemanticTree.basic_function_type bft, bool is_implicit) { basic_function_node conv_method = new basic_function_node(bft, to,false); basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name, from, SemanticTree.parameter_type.value, conv_method); conv_method.parameters.AddElement(bp); type_table.add_type_conversion_from_defined(from, to, conv_method, tc, is_implicit); //type_intersection_node inter_node = new type_intersection_node(tc); //inter_node.this_to_another = new type_conversion(conv_method,!is_implicit); //from.add_intersection_node(to, inter_node); add_stand_type(bft, conv_method); return conv_method; }
public static basic_function_node make_type_conversion(type_node from, type_node to, type_compare tc, SemanticTree.basic_function_type bft) { return make_type_conversion(from, to, tc, bft, true); }
public static compiled_constructor_node make_type_conversion_use_ctor(compiled_type_node from, compiled_type_node to, type_compare tc, bool is_implicit) { Type[] ctor_params = new Type[1]; ctor_params[0] = from.compiled_type; System.Reflection.ConstructorInfo ci = to.compiled_type.GetConstructor(ctor_params); compiled_constructor_node conv_method = null; if (ci != null) { conv_method = compiled_constructor_node.get_compiled_constructor(ci); type_table.add_type_conversion_from_defined(from, to, conv_method, tc, is_implicit); } return conv_method; }
private void make_type_conversion(compiled_type_node from,compiled_type_node to,type_compare tc, SemanticTree.basic_function_type bft) { parameterArrayList pars=new parameterArrayList(); basic_function_node conv_method=new basic_function_node(bft,pars,to); basic_parameter bp=new basic_parameter(compiler_string_consts.unary_param_name, from,SemanticTree.parameter_type.value,conv_method); pars.Add(bp); type_intersection_node inter_node=new type_intersection_node(tc); inter_node.this_to_another=new type_conversion_factory(conv_method); from.add_intersection_node(to,inter_node); }
public type_intersection_node(type_compare type_compare) { _type_compare = type_compare; }
public static void add_type_conversion_from_defined(type_node from, type_node to, function_node convertion_method, type_compare comp, bool is_implicit, bool is_generated) { type_intersection_node tin = from.get_type_intersection(to); if (tin == null) { tin = new type_intersection_node(comp); from.add_intersection_node(to, tin, is_generated); } #if (DEBUG) else { if (tin.this_to_another != null) { throw new PascalABCCompiler.TreeConverter.CompilerInternalError("Duplicate type conversion added"); } } #endif tin.this_to_another = new type_conversion(convertion_method, !is_implicit); }
public static bool is_derived(type_node base_class, type_node derived_class) { if (derived_class == null) //void? { return(false); } if (base_class == null) { return(false); } type_node tn = derived_class.base_type; //TODO: Проверить на ссылочный и размерный тип. if (derived_class.semantic_node_type == semantic_node_type.null_type_node) { if (is_with_nil_allowed(base_class) || base_class.IsPointer) { return(true); } else { return(false); } } if (base_class.type_special_kind == SemanticTree.type_special_kind.short_string && derived_class.type_special_kind == SemanticTree.type_special_kind.short_string) { return(true); } else if (derived_class == SystemLibrary.SystemLibrary.string_type && base_class.type_special_kind == SemanticTree.type_special_kind.short_string) { return(true); } else if (base_class == SystemLibrary.SystemLibrary.string_type && derived_class.type_special_kind == SemanticTree.type_special_kind.short_string) { return(true); } if (SystemLibrary.SystemLibInitializer.TypedSetType != null && SystemLibrary.SystemLibInitializer.TypedSetType.Found && base_class.type_special_kind == SemanticTree.type_special_kind.set_type && derived_class == SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node ) { return(true); } if (base_class.type_special_kind == SemanticTree.type_special_kind.set_type && derived_class.type_special_kind == SemanticTree.type_special_kind.set_type) { if (base_class.element_type == derived_class.element_type) { return(true); } type_compare tc = get_table_type_compare(base_class.element_type, derived_class.element_type); if (tc == type_compare.non_comparable_type) { if (base_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { if (base_class.element_type.base_type == derived_class.element_type.base_type) { return(true); } tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type.base_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin = base_class.element_type.base_type.get_type_intersection(derived_class.element_type.base_type); if (tin == null || tin.this_to_another == null) { if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } return(!tin.this_to_another.is_explicit); } else { if (base_class.element_type.base_type == derived_class.element_type) { return(true); } tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin = base_class.element_type.base_type.get_type_intersection(derived_class.element_type); if (tin == null || tin.this_to_another == null) { if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type && (derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } return(!tin.this_to_another.is_explicit); } } else if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { if (base_class.element_type == derived_class.element_type.base_type) { return(true); } tc = get_table_type_compare(base_class.element_type, derived_class.element_type.base_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin = base_class.element_type.get_type_intersection(derived_class.element_type.base_type); if (tin == null || tin.this_to_another == null) { if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } return(!tin.this_to_another.is_explicit); } else if (base_class.element_type.type_special_kind == SemanticTree.type_special_kind.short_string && derived_class.element_type == SystemLibrary.SystemLibrary.string_type || derived_class.element_type.type_special_kind == SemanticTree.type_special_kind.short_string && base_class.element_type == SystemLibrary.SystemLibrary.string_type) { return(true); } else { return(false); } } else { type_intersection_node tin = base_class.element_type.get_type_intersection(derived_class.element_type); if (tin == null || tin.this_to_another == null) { //proverka na diapasony if (base_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { if (base_class.element_type.base_type == derived_class.element_type.base_type) { return(true); } tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type.base_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin2 = base_class.element_type.base_type.get_type_intersection(derived_class.element_type.base_type); if (tin == null || tin.this_to_another == null) { if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } return(!tin.this_to_another.is_explicit); } else { if (base_class.element_type.base_type == derived_class.element_type) { return(true); } tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin2 = base_class.element_type.base_type.get_type_intersection(derived_class.element_type); if (tin == null || tin.this_to_another == null) { if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type && (derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } return(!tin.this_to_another.is_explicit); } } else if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { if (base_class.element_type == derived_class.element_type.base_type) { return(true); } tc = get_table_type_compare(base_class.element_type, derived_class.element_type.base_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin2 = base_class.element_type.get_type_intersection(derived_class.element_type.base_type); if (tin == null || tin.this_to_another == null) { if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } return(!tin.this_to_another.is_explicit); } if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) { if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) { return(false); } else { return(false); } } else { return(true); } } return(!tin.this_to_another.is_explicit); } } //ssyy Рассматриваем случай интерфейса if (base_class.IsInterface) { bool implements = false; type_node tnode = derived_class; while (!implements && tnode != null && tnode.ImplementingInterfaces != null) { implements = tnode.ImplementingInterfaces.Contains(base_class); tnode = tnode.base_type; } return(implements); } //\ssyy if (base_class.type_special_kind == SemanticTree.type_special_kind.diap_type && derived_class.type_special_kind == SemanticTree.type_special_kind.diap_type) { if (base_class.base_type == derived_class.base_type) { return(true); } type_compare tc = get_table_type_compare(base_class.base_type, derived_class.base_type); if (tc == type_compare.non_comparable_type) { return(false); } type_intersection_node tin = base_class.base_type.get_type_intersection(derived_class.base_type); if (tin == null || tin.this_to_another == null) { return(false); } return(!tin.this_to_another.is_explicit); } while ((tn != null) && (tn != base_class)) { tn = tn.base_type; } if (tn == null) { return(false); } return(true); }
public static void add_generated_type_conversion_from_defined(type_node from, type_node to, function_node convertion_method, type_compare comp, bool is_implicit) { add_type_conversion_from_defined(from, to, convertion_method, comp, is_implicit, true); }
private void make_type_conversion(compiled_type_node from, compiled_type_node to, type_compare tc, SemanticTree.basic_function_type bft) { parameterArrayList pars = new parameterArrayList(); basic_function_node conv_method = new basic_function_node(bft, pars, to); basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name, from, SemanticTree.parameter_type.value, conv_method); pars.Add(bp); type_intersection_node inter_node = new type_intersection_node(tc); inter_node.this_to_another = new type_conversion_factory(conv_method); from.add_intersection_node(to, inter_node); }
public type_intersection_node(type_compare type_compare) { _type_compare=type_compare; }
public static void add_type_conversion_from_defined(type_node from, type_node to, function_node convertion_method,type_compare comp,bool is_implicit,bool is_generated) { type_intersection_node tin=from.get_type_intersection(to); if (tin==null) { tin=new type_intersection_node(comp); from.add_intersection_node(to,tin,is_generated); } #if (DEBUG) else { if (tin.this_to_another!=null) { throw new PascalABCCompiler.TreeConverter.CompilerInternalError("Duplicate type conversion added"); } } #endif tin.this_to_another=new type_conversion(convertion_method,!is_implicit); }