本文整理汇总了C#中PascalABCCompiler.TreeRealization.type_node.get_internal_interface方法的典型用法代码示例。如果您正苦于以下问题:C# type_node.get_internal_interface方法的具体用法?C# type_node.get_internal_interface怎么用?C# type_node.get_internal_interface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PascalABCCompiler.TreeRealization.type_node
的用法示例。
在下文中一共展示了type_node.get_internal_interface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTemplateParametersTypeDependsOn
private static List<ident> GetTemplateParametersTypeDependsOn(type_node type)
{
if (type.generic_function_container != null)
{
return new List<ident>
{
new ident(type.name)
};
}
var typeRef = type as ref_type_node;
if (typeRef != null)
{
return GetTemplateParametersTypeDependsOn(typeRef.pointed_type);
}
var typeIi = type.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (typeIi != null)
{
return GetTemplateParametersTypeDependsOn(typeIi.element_type);
}
if (type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.set_type)
{
return GetTemplateParametersTypeDependsOn(type.element_type);
}
if (type.IsDelegate)
{
var dii = type.get_internal_interface(internal_interface_kind.delegate_interface) as delegate_internal_interface;
var res = new List<ident>();
if (dii != null)
{
var paramCount = dii.parameters.Count;
for (var i = 0; i < paramCount; i++)
{
res.AddRange(GetTemplateParametersTypeDependsOn(dii.parameters[i].type));
}
}
return res;
}
if (type.is_generic_type_instance)
{
var pcount = type.instance_params.Count;
var res = new List<ident>();
for (var i = 0; i < pcount; i++)
{
res.AddRange(GetTemplateParametersTypeDependsOn(type.instance_params[i]));
}
return res;
}
return new List<ident>();
}
示例2: ConvertArrayInitializer
private array_initializer ConvertArrayInitializer(type_node tn, array_initializer constant)
{
type_node element_type = null;
if (IsBoundedArray(tn))
{
bounded_array_interface bai = tn.get_internal_interface(internal_interface_kind.bounded_array_interface) as bounded_array_interface;
element_type = bai.element_type;
ordinal_type_interface oti_indexer = bai.ordinal_type_interface;
int arr_length = oti_indexer.ordinal_type_to_int(oti_indexer.upper_value) - oti_indexer.ordinal_type_to_int(oti_indexer.lower_value) + 1;
if (arr_length != constant.element_values.Count)
AddError(constant.location, "ARRAY_CONST_{0}_ELEMENTS_EXPECTED", arr_length);
}
else
if (IsUnsizedArray(tn))
{
array_internal_interface aii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
element_type = aii.element_type;
if (aii.rank > 1)
{
array_initializer cnst = ConvertNDimArrayInitializer(tn,1,element_type,constant);
cnst.type = tn;
return cnst;
}
}
else
AddError(new CanNotConvertTypes(constant,constant.type,tn,constant.location));//CompilerInternalError("Unexpected array type");
for (int i = 0; i < constant.element_values.Count; i++)
if (constant.element_values[i] is array_initializer)
constant.element_values[i] = ConvertArrayInitializer(element_type, constant.element_values[i] as array_initializer);
else if (constant.element_values[i] is record_initializer)
{
if (element_type is common_type_node)
constant.element_values[i] = ConvertRecordInitializer(element_type as common_type_node, constant.element_values[i] as record_initializer);
else throw new NotSupportedError(constant.element_values[i].location);
}
else
{
constant.element_values[i] = convertion_data_and_alghoritms.convert_type(constant.element_values[i], element_type);
}
constant.type = tn;
return constant;
}
示例3: ConvertNDimArrayInitializer
private array_initializer ConvertNDimArrayInitializer(type_node tn, int cur_rank, type_node element_type, array_initializer constant)
{
array_internal_interface aii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
int rank = aii.rank;
for (int i=0; i<constant.element_values.Count; i++)
{
expression_node e = constant.element_values[i];
if (e is array_initializer)
{
if (cur_rank>=rank)
constant.element_values[i] = ConvertArrayInitializer(tn.element_type,e as array_initializer);
//AddError(new CanNotConvertTypes(e,e.type,tn.element_type,e.location));
else
constant.element_values[i] = ConvertNDimArrayInitializer(tn,cur_rank+1,element_type,e as array_initializer);
}
else if (e is record_initializer)
{
if (element_type is common_type_node)
constant.element_values[i] = ConvertRecordInitializer(element_type as common_type_node, e as record_initializer);
else throw new NotSupportedError(constant.element_values[i].location);
}
else
{
if (cur_rank != rank)
AddError(constant.location, "RANK_MISMATCH_IN_INITILIALIZER");
constant.element_values[i] = convertion_data_and_alghoritms.convert_type(constant.element_values[i], element_type);
}
}
constant.type = tn;
return constant;
}
示例4: is_range_checkable
internal bool is_range_checkable(type_node tn)
{
ordinal_type_interface oti = tn.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface;
if (oti != null && !tn.IsEnum && tn != SystemLibrary.SystemLibrary.bool_type)
return true;
return false;
}
示例5: convert_strong_to_constant_node
private constant_node convert_strong_to_constant_node(expression_node expr, type_node tn)
{
location loc = expr.location;
constant_node constant = null;
try_convert_typed_expression_to_function_call(ref expr);
if (expr is null_const_node)
{
if (!(tn is null_type_node) && !type_table.is_with_nil_allowed(tn))
AddError(loc, "NIL_WITH_VALUE_TYPES_NOT_ALLOWED");
return null_const_node.get_const_node_with_type(tn, expr as null_const_node);
}
if (expr is compiled_static_method_call)
{
compiled_static_method_call csmc = expr as compiled_static_method_call;
if (/*csmc.parameters.Count == 0 &&*/ csmc.type != null && csmc.type != SystemLibrary.SystemLibrary.void_type)
constant = new compiled_static_method_call_as_constant(csmc, expr.location);
}
else if (expr is common_namespace_function_call && (expr as common_namespace_function_call).function_node == SystemLibrary.SystemLibInitializer.CreateSetProcedure.sym_info as common_namespace_function_node)
{
common_namespace_function_call cnfc = expr as common_namespace_function_call;
expressions_list exprs = get_set_initializer(cnfc);
check_set_for_constant(cnfc);
foreach (expression_node en in exprs)
{
if (en is common_namespace_function_call)
{
common_namespace_function_call cnfc2 = en as common_namespace_function_call;
check_set_for_constant(cnfc2);
}
else
if (!(en is constant_node)) AddError(loc, "CONSTANT_EXPRESSION_EXPECTED");
}
constant = new common_namespace_function_call_as_constant(cnfc, loc);
}
else if (expr is common_namespace_function_call)
{
common_namespace_function_call cnfc=expr as common_namespace_function_call;
//if (cnfc.function_node.namespace_node == context.converted_namespace)
// throw new ConstantExpressionExpected(loc);
constant = new common_namespace_function_call_as_constant(expr as common_namespace_function_call, loc);
}
else if (expr is basic_function_call)
{
basic_function_call cnfc=expr as basic_function_call;
//if (cnfc.function_node.namespace_node == context.converted_namespace)
// throw new ConstantExpressionExpected(loc);
constant = new basic_function_call_as_constant(expr as basic_function_call, loc);
}
else if (expr is typed_expression)
{
expr = convertion_data_and_alghoritms.convert_type(expr, tn);
if (expr is common_constructor_call)
{
constant = new common_constructor_call_as_constant(expr as common_constructor_call, null);
}
else
if (expr is typed_expression)
{
if (const_def_type != null)
{
expr = convertion_data_and_alghoritms.convert_type(expr, const_def_type);
tn = const_def_type;
constant = new common_constructor_call_as_constant(expr as common_constructor_call, null);
}
else
{
base_function_call bfc = ((expr as typed_expression).type as delegated_methods).proper_methods[0];
common_type_node del =
convertion_data_and_alghoritms.type_constructor.create_delegate(context.get_delegate_type_name(), bfc.simple_function_node.return_value_type, bfc.simple_function_node.parameters, context.converted_namespace, null);
context.converted_namespace.types.AddElement(del);
tn = del;
expr = convertion_data_and_alghoritms.explicit_convert_type(expr, del);
expr.type = tn;
constant = new common_constructor_call_as_constant(expr as common_constructor_call, null);
}
}
}
else if (expr is namespace_constant_reference)
{
constant = (expr as namespace_constant_reference).constant.const_value;
convertion_data_and_alghoritms.check_convert_type(constant,tn,expr.location);
if ((tn.type_special_kind == SemanticTree.type_special_kind.set_type || tn.type_special_kind == SemanticTree.type_special_kind.base_set_type) && tn.element_type != null)
{
ordinal_type_interface oti = tn.element_type.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface;
if (oti != null)
{
common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as common_namespace_function_node,null);
cmc.parameters.AddElement(expr);
cmc.parameters.AddElement(oti.lower_value.get_constant_copy(null));
cmc.parameters.AddElement(oti.upper_value.get_constant_copy(null));
cmc.ret_type = tn;
constant = new common_namespace_function_call_as_constant(cmc,null);
}
else if (tn.element_type.type_special_kind == SemanticTree.type_special_kind.short_string)
{
common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as common_namespace_function_node,null);
cmc.parameters.AddElement(expr);
cmc.parameters.AddElement(new int_const_node((tn.element_type as short_string_type_node).Length,null));
//.........这里部分代码省略.........
示例6: get_convertions
//TODO: Возможно стоит если пересечение типов найдено в откомпилированных типах, добавлять к нашим структурам и не искать повторно.
public static possible_type_convertions get_convertions(type_node from,type_node to, bool is_implicit)
{
possible_type_convertions ret = new possible_type_convertions();
ret.first = null;
ret.second = null;
if ((from == null) || (to == null))
{
return ret;
}
type_intersection_node tin_from=from.get_type_intersection(to);
type_intersection_node tin_to=to.get_type_intersection(from);
if (tin_from != null)
{
if (tin_from.this_to_another != null)
{
if ((!is_implicit) || (!(tin_from.this_to_another.is_explicit)))
{
add_conversion(ret, tin_from.this_to_another.convertion_method, from, to);
}
}
}
if (tin_to != null)
{
if (tin_to.another_to_this != null)
{
if ((!is_implicit) || (!(tin_to.another_to_this.is_explicit)))
{
add_conversion(ret, tin_to.another_to_this.convertion_method, from, to);
}
}
}
if (ret.second != null)
{
return ret;
}
if (is_derived(to, from) || (from.IsInterface && to == SystemLibrary.SystemLibrary.object_type))
{
add_conversion(ret, TreeConverter.convertion_data_and_alghoritms.get_empty_conversion(from, to, true), from, to);
//add_conversion(ret, SystemLibrary.SystemLibrary.empty_method, from, to);
}
if (ret.second != null)
{
return ret;
}
wrapped_type ctn_to=to as wrapped_type;
wrapped_type ctn_from=from as wrapped_type;
if (ctn_to != null)
{
function_node fnode1 = null;
fnode1 = ctn_to.get_implicit_conversion_from(from);
add_conversion(ret, fnode1, from, to);
if (ret.second != null)
{
return ret;
}
fnode1 = null;
if (!is_implicit)
{
fnode1 = ctn_to.get_explicit_conversion_from(from);
}
add_conversion(ret, fnode1, from, to);
if (ret.second != null)
{
return ret;
}
}
if (ctn_from != null)
{
function_node fnode2 = null;
fnode2 = ctn_from.get_implicit_conversion_to(to);
add_conversion(ret, fnode2, from, to);
if (ret.second != null)
{
return ret;
}
fnode2 = null;
if (!is_implicit)
{
fnode2 = ctn_from.get_explicit_conversion_to(to);
}
add_conversion(ret, fnode2, from, to);
if (ret.second != null)
{
return ret;
}
}
//TODO: Вот это должно быть в каком нибудь другом месте.
internal_interface ii = from.get_internal_interface(internal_interface_kind.delegate_interface);
if (ii != null)
{
delegate_internal_interface dii = (delegate_internal_interface)ii;
//.........这里部分代码省略.........
示例7: IsUnsizedArray
private bool IsUnsizedArray(type_node tn)
{
return tn.get_internal_interface(internal_interface_kind.unsized_array_interface) != null;
}
示例8: get_possible_array_const
private SyntaxTree.expression get_possible_array_const(SyntaxTree.expression expr, type_node tn)
{
try
{
if (tn == null)
return expr;
if (expr is SyntaxTree.bracket_expr && (tn.type_special_kind == SemanticTree.type_special_kind.array_kind || tn.type_special_kind == SemanticTree.type_special_kind.array_wrapper))
{
array_internal_interface aii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (aii != null && aii.rank > 1)
return get_possible_array_const(expr, tn, aii.rank);
SyntaxTree.array_const arr = new SyntaxTree.array_const();
arr.source_context = expr.source_context;
arr.elements = new SyntaxTree.expression_list();
arr.elements.expressions.Add(get_possible_array_const((expr as SyntaxTree.bracket_expr).expr, tn.element_type));
return arr;
}
else if (expr is SyntaxTree.array_const && (tn.type_special_kind == SemanticTree.type_special_kind.array_kind || tn.type_special_kind == SemanticTree.type_special_kind.array_wrapper))
{
array_internal_interface aii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (aii != null && aii.rank > 1)
return get_possible_array_const(expr, tn, aii.rank);
SyntaxTree.array_const arr = expr as SyntaxTree.array_const;
if (arr.elements != null)
for (int i = 0; i < arr.elements.expressions.Count; i++)
arr.elements.expressions[i] = get_possible_array_const(arr.elements.expressions[i], tn.element_type);
return arr;
}
else if (expr is SyntaxTree.record_const && tn is common_type_node)
{
common_type_node ctn = tn as common_type_node;
SyntaxTree.record_const rec = expr as SyntaxTree.record_const;
for (int i = 0; i < rec.rec_consts.Count; i++)
{
if (i < ctn.fields.Count)
rec.rec_consts[i].val = get_possible_array_const(rec.rec_consts[i].val, ctn.fields[i].type);
}
return rec;
}
}
catch
{
}
return expr;
}
示例9: CheckIfTypeDependsOnUndeducedGenericParameters
private static bool CheckIfTypeDependsOnUndeducedGenericParameters(type_node formalType, type_node[] deduced) //lroman
{
if (formalType.generic_function_container != null)
{
var par_num = formalType.generic_param_index;
return deduced[par_num] == null;
}
var formalRef = formalType as ref_type_node;
if (formalRef != null)
{
return CheckIfTypeDependsOnUndeducedGenericParameters(formalRef.pointed_type, deduced);
}
var formalIi = formalType.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (formalIi != null)
{
return CheckIfTypeDependsOnUndeducedGenericParameters(formalIi.element_type, deduced);
}
if (formalType.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.set_type)
{
return CheckIfTypeDependsOnUndeducedGenericParameters(formalType.element_type, deduced);
}
if (formalType.IsDelegate)
{
var dii = formalType.get_internal_interface(internal_interface_kind.delegate_interface) as delegate_internal_interface;
var paramCount = dii.parameters.Count;
for (var i = 0; i < paramCount; i++)
{
if (!CheckIfTypeDependsOnUndeducedGenericParameters(dii.parameters[i].type, deduced))
{
return false;
}
}
return CheckIfTypeDependsOnUndeducedGenericParameters(dii.return_value_type, deduced);
}
if (formalType.is_generic_type_instance)
{
var pcount = formalType.instance_params.Count;
for (var k = 0; k < pcount; ++k)
{
if (!CheckIfTypeDependsOnUndeducedGenericParameters(formalType.instance_params[k], deduced))
{
return false;
}
}
return true;
}
return false;
}
示例10: determine_type
public static type_node determine_type(type_node tn, List<type_node> param_types, bool method_param_types)
{
if (tn == null) return null;
ref_type_node rtn = tn as ref_type_node;
if (rtn != null)
{
type_node ptype = generic_convertions.determine_type(rtn.pointed_type, param_types, method_param_types);
if (ptype == rtn.pointed_type) return tn;
ref_type_node rez_ref = ptype.ref_type;
rez_ref.loc = rtn.loc;
return rez_ref;
}
array_internal_interface ii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (ii != null)
{
type_node elem_tp = determine_type(ii.element_type, param_types, method_param_types);
if (elem_tp != ii.element_type)
{
return SystemLibrary.SystemLibrary.syn_visitor.convertion_data_and_alghoritms.type_constructor.create_unsized_array(elem_tp, null, ii.rank, null);
}
return tn;
}
common_type_node comm_type = tn as common_type_node;
if (comm_type != null)
{
if (comm_type.is_generic_parameter)
{
if (method_param_types && comm_type.generic_function_container != null)
{
return param_types[comm_type.generic_param_index];
}
else if (!method_param_types && comm_type.generic_type_container != null)
{
return param_types[comm_type.generic_param_index];
}
return tn;
}
generic_instance_type_node gitn = tn as generic_instance_type_node;
if (gitn != null)
{
List<type_node> semantic_args = new List<type_node>();
List<type_node> gitn_inst_parameters = gitn.instance_params;
foreach (type_node arg in gitn_inst_parameters)
{
semantic_args.Add(determine_type(arg, param_types, method_param_types));
}
return gitn.original_generic.get_instance(semantic_args);
}
if (comm_type.is_generic_type_definition)
{
return comm_type.get_instance(param_types);
}
if (comm_type.type_special_kind == SemanticTree.type_special_kind.array_kind)
{
type_node elem_tp = determine_type(comm_type.element_type, param_types, method_param_types);
if (elem_tp != comm_type.element_type)
{
return SystemLibrary.SystemLibrary.syn_visitor.convertion_data_and_alghoritms.type_constructor.create_unsized_array(elem_tp, null, 1, comm_type.loc);
}
return tn;
}
if (comm_type.type_special_kind == SemanticTree.type_special_kind.set_type)
{
type_node elem_tp = determine_type(comm_type.element_type, param_types, method_param_types);
if (elem_tp != comm_type.element_type)
{
return SystemLibrary.SystemLibrary.syn_visitor.context.create_set_type(elem_tp, comm_type.loc);
}
return tn;
}
if (comm_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.typed_file)
{
type_node elem_tp = determine_type(comm_type.element_type, param_types, method_param_types);
if (elem_tp != comm_type.element_type)
{
return SystemLibrary.SystemLibrary.syn_visitor.context.create_typed_file_type(elem_tp, comm_type.loc);
}
return tn;
}
return tn;
}
compiled_type_node ctn = tn as compiled_type_node;
if (ctn == null || (!ctn.compiled_type.IsGenericType && !ctn.compiled_type.IsGenericParameter))
{
return tn;
}
return determine_type(ctn.compiled_type, param_types, method_param_types);
}
示例11: init_generic_instance
public static void init_generic_instance(type_node original, generic_instance_type_node instance, /*SymbolTable.ClassScope instance_scope,*/ List<type_node> param_types)
{
instance.IsInterface = original.IsInterface;
instance.is_class = original.is_class;
instance.internal_is_value = original.is_value;
instance.SetIsSealed(original.IsSealed);
instance.IsDelegate = original.IsDelegate;
instance.type_special_kind = original.type_special_kind;
//Определяем базовый тип
type_node btype = determine_type(
original.base_type, param_types, false);
instance.SetBaseTypeIgnoringScope(btype);
//instance._scope = new SymbolTable.GenericTypeInstanceScope(instance, instance.original_generic.Scope, btype.Scope);
foreach (type_node interf in original.ImplementingInterfaces)
{
instance.ImplementingInterfaces.Add(
determine_type(interf, param_types, false)
);
}
SystemLibrary.SystemLibrary.init_reference_type(instance);
instance.conform_basic_functions();
//(ssyy) Нужно, чтобы добавились конструкторы
//ctnode.find_in_type(compiler_string_consts.default_constructor_name);
instance.instance_params = param_types;
property_node orig_pn = original.default_property_node;
if (orig_pn != null)
{
if (orig_pn.comprehensive_type == original)
{
//Свойство по умолчанию описано в оригинальном коде generic-a;
//конвертируем его
instance.default_property = instance.ConvertMember(orig_pn) as common_property_node;
}
else
{
//Свойство по умолчанию описано в каком-то предке оригинального generic-a
if (orig_pn.comprehensive_type.is_generic_type_definition)
{
instance.default_property = instance.find_instance_type_from(orig_pn.comprehensive_type).default_property;
}
}
}
var shouldAddToAllTypeInstances = true;
if (LambdaHelper.processingLambdaParametersForTypeInference != 0)
{
foreach (var par in instance.generic_parameters)
{
if (par is lambda_any_type_node)
{
shouldAddToAllTypeInstances = false;
break;
}
}
}
if (shouldAddToAllTypeInstances) //lroman// Если зашли сюда при выведении типов параметров лямбды, то тип инстанцироваться может с типом lambda_any_type_node. Поэтому, если выводим типы. То данную инстанцию не добавляем
generic_convertions.all_type_instances.Add(instance);
internal_interface ii = original.get_internal_interface(internal_interface_kind.delegate_interface);
if (ii != null)
{
delegate_internal_interface dii = ii as delegate_internal_interface;
common_method_node inv = instance.ConvertMember(dii.invoke_method) as common_method_node;
common_method_node constr = instance.ConvertMember(dii.constructor) as common_method_node;
constr.function_code = new runtime_statement(SemanticTree.runtime_statement_type.ctor_delegate, null);
delegate_internal_interface converted_dii = new delegate_internal_interface(inv.return_value_type,
inv, constr);
converted_dii.parameters.AddRange(inv.parameters);
instance.add_internal_interface(converted_dii);
}
}
示例12: check_type_generic_useful
public static CompilationErrorWithLocation check_type_generic_useful(type_node tn, location loc)
{
if (tn == null)
{
return new SimpleSemanticError(loc, "TYPE_NAME_EXPECTED");
}
if (tn.IsPointer)
{
return new SimpleSemanticError(loc, "CANNOT_USE_POINTER_AS_GENERIC_ARGUMENT");
}
switch (tn.type_special_kind)
{
case PascalABCCompiler.SemanticTree.type_special_kind.diap_type:
return new SimpleSemanticError(loc, "CANNOT_USE_DIAPASON_AS_GENERIC_ARGUMENT");
case PascalABCCompiler.SemanticTree.type_special_kind.typed_file:
return new SimpleSemanticError(loc, "CANNOT_USE_TYPED_FILE_AS_GENERIC_ARGUMENT");
case PascalABCCompiler.SemanticTree.type_special_kind.short_string:
return new SimpleSemanticError(loc, "CANNOT_USE_SHORT_STRING_AS_GENERIC_ARGUMENT");
}
/*if (tn == SystemLibrary.SystemLibrary.void_type)
{
return new VoidNotValid(loc);
}*/
SystemLibrary.SystemLibrary.syn_visitor.check_for_type_allowed(tn,loc);
internal_interface ii = tn.get_internal_interface(internal_interface_kind.bounded_array_interface);
if (ii != null)
{
return new SimpleSemanticError(loc, "CANNOT_USE_BOUNDED_ARRAY_AS_GENERIC_ARGUMENT");
}
return null;
}
示例13: InferTypesFromVarStmt
/// <summary>
/// Вывод типа параметров лямбд и типа возвращаемого значения при присваивании лямбды переменной
/// </summary>
public static void InferTypesFromVarStmt(type_node leftType, function_lambda_definition lambdaDef, syntax_tree_visitor visitor)
{
if (lambdaDef == null)
return;
if (leftType != null)
{
delegate_internal_interface dii_left =
(delegate_internal_interface)leftType.get_internal_interface(internal_interface_kind.delegate_interface);
if (dii_left == null)
visitor.AddError(visitor.get_location(lambdaDef), "ILLEGAL_LAMBDA_VARIABLE_TYPE");
int leftTypeParamsNumber = dii_left.parameters.Count;
int lambdaDefParamsCount = 0;
if (lambdaDef.formal_parameters != null && lambdaDef.formal_parameters.params_list.Count != 0)
{
for (int i = 0; i < lambdaDef.formal_parameters.params_list.Count; i++)
lambdaDefParamsCount += lambdaDef.formal_parameters.params_list[i].idents.idents.Count;
if (lambdaDefParamsCount != leftTypeParamsNumber)
visitor.AddError(visitor.get_location(lambdaDef), "ILLEGAL_LAMBDA_PARAMETERS_NUMBER");
bool flag = true;
SyntaxTree.formal_parameters lambdaDefParamsTypes = new formal_parameters();
for (int i = 0; i < lambdaDef.formal_parameters.params_list.Count; i++)
for (int j = 0; j < lambdaDef.formal_parameters.params_list[i].idents.idents.Count; j++)
{
var param = new SyntaxTree.typed_parameters();
param.idents = new ident_list();
param.idents.Add(lambdaDef.formal_parameters.params_list[i].idents.idents[j]);
param.vars_type = lambdaDef.formal_parameters.params_list[i].vars_type;
lambdaDefParamsTypes.Add(param);
}
for (int i = 0; i < leftTypeParamsNumber && flag; i++)
{
if (lambdaDefParamsTypes.params_list[i].vars_type is SyntaxTree.lambda_inferred_type)
{
if ((lambdaDefParamsTypes.params_list[i].vars_type as SyntaxTree.lambda_inferred_type).real_type is lambda_any_type_node)
{
var curLeftParType = dii_left.parameters[i].type;
lambdaDefParamsTypes.params_list[i].vars_type = new SyntaxTree.lambda_inferred_type();
(lambdaDefParamsTypes.params_list[i].vars_type as SyntaxTree.lambda_inferred_type).real_type = curLeftParType;
continue;
}
}
var lambdaPar = visitor.convert_strong(lambdaDefParamsTypes.params_list[i].vars_type);
if (!convertion_data_and_alghoritms.eq_type_nodes(dii_left.parameters[i].type, lambdaPar))
{
visitor.AddError(visitor.get_location(lambdaDef), "ILLEGAL_LAMBDA_VARIABLE_TYPE");
}
}
lambdaDef.formal_parameters = lambdaDefParamsTypes;
}
if (lambdaDef.return_type != null && lambdaDef.return_type is lambda_inferred_type)
{
if (dii_left.return_value_type != null)
(lambdaDef.return_type as lambda_inferred_type).real_type = dii_left.return_value_type;
else // SSM 23/07/16 - попытка бороться с var p: Shape->() := a->a.Print()
{
var b = TryConvertFuncLambdaBodyWithMethodCallToProcLambdaBody(lambdaDef);
if (!b)
throw new SimpleSemanticError(visitor.get_location(lambdaDef), "UNABLE_TO_CONVERT_FUNCTIONAL_TYPE_TO_PROCEDURAL_TYPE");
}
}
}
else
{
if (lambdaDef.formal_parameters != null)
for (int i = 0; i < lambdaDef.formal_parameters.params_list.Count; i++)
if (lambdaDef.formal_parameters.params_list[i].vars_type is lambda_inferred_type)
visitor.AddError(visitor.get_location(lambdaDef), "IMPOSSIBLE_TO_INFER_TYPES_IN_LAMBDA");
}
}
示例14: ConvertNDimArrayConst
private array_const ConvertNDimArrayConst(type_node tn, int cur_rank, type_node element_type, array_const constant)
{
array_internal_interface aii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
int rank = aii.rank;
for (int i=0; i<constant.element_values.Count; i++)
{
expression_node e = constant.element_values[i];
if (e is array_const)
{
if (cur_rank>=rank)
constant.element_values[i] = ConvertArrayConst(tn.element_type,e as array_const);
//AddError(new CanNotConvertTypes(e,e.type,tn.element_type,e.location));
else
constant.element_values[i] = ConvertNDimArrayConst(tn,cur_rank+1,element_type,e as array_const);
}
else if (e is record_constant)
{
if (element_type is common_type_node)
constant.element_values[i] = ConvertRecordConst(element_type as common_type_node, e as record_constant);
else AddError(new NotSupportedError(constant.element_values[i].location));
}
else
{
if (cur_rank != rank)
AddError(constant.location, "RANK_MISMATCH_IN_INITILIALIZER");
constant.element_values[i] = convert_strong_to_constant_node(constant.element_values[i], element_type);
}
}
constant.SetType(tn);
return constant;
}
示例15: DeduceInstanceTypes
//Выведение типов
public static bool DeduceInstanceTypes(type_node formal_type, type_node fact_type, type_node[] deduced, List<int> nils)
{
if (formal_type.generic_function_container == null && fact_type.generic_function_container != null)
{
//swap
type_node tmp = formal_type;
formal_type = fact_type;
fact_type = tmp;
}
//Формальный тип - generic-параметр функции. Выводим.
if (formal_type.generic_function_container != null)
{
int par_num = formal_type.generic_param_index;
if (fact_type.semantic_node_type == semantic_node_type.null_type_node)
{
nils.Add(par_num);
return true;
}
if (deduced[par_num] == null)
{
//Этот тип-параметр ещё не был выведен.
deduced[par_num] = fact_type;
return true;
}
//Этот тип-параметр уже был выведен. Сравниваем с выведенным.
if (!convertion_data_and_alghoritms.eq_type_nodes(fact_type, deduced[par_num], true))
{
return false;
}
return true;
}
//Указатели
ref_type_node formal_ref = formal_type as ref_type_node;
if (formal_ref != null)
{
ref_type_node fact_ref = fact_type as ref_type_node;
if (fact_ref == null)
{
goto eq_cmp;
}
return DeduceInstanceTypes(formal_ref.pointed_type, fact_ref.pointed_type, deduced, nils);
}
//безразмерные массивы
array_internal_interface formal_ii = formal_type.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (formal_ii != null)
{
array_internal_interface fact_ii = fact_type.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
if (fact_ii == null)
{
goto eq_cmp;
}
return DeduceInstanceTypes(formal_ii.element_type, fact_ii.element_type, deduced, nils);
}
//множества
if (formal_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.set_type)
{
if (fact_type.type_special_kind != PascalABCCompiler.SemanticTree.type_special_kind.set_type)
{
goto eq_cmp;
}
return DeduceInstanceTypes(formal_type.element_type, fact_type.element_type, deduced, nils);
}
//множества
if (formal_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.typed_file)
{
if (fact_type.type_special_kind != PascalABCCompiler.SemanticTree.type_special_kind.typed_file)
{
goto eq_cmp;
}
return DeduceInstanceTypes(formal_type.element_type, fact_type.element_type, deduced, nils);
}
//Делегаты
if (formal_type.IsDelegate)
{
//Если текущий параметр - лямбда, то просто выводим дженерик-параметры из типов, которые уже известны. Не трогаем lambda_any_type_node. Остальное выведется в цикле выше
var lambda_func = fact_type as delegated_methods;
if (lambda_func != null
&& lambda_func.proper_methods.Count == 1
&& LambdaHelper.IsLambdaName(lambda_func.proper_methods[0].simple_function_node.name))
{
var dii = formal_type.get_internal_interface(internal_interface_kind.delegate_interface) as delegate_internal_interface;
var fact_func = lambda_func.proper_methods[0].simple_function_node;
if (fact_func.parameters.Count != dii.parameters.Count)
{
goto eq_cmp;
}
var param_count = fact_func.parameters.Count;
for (var i = 0; i < param_count; i++)
{
if (fact_func.parameters[i].parameter_type != dii.parameters[i].parameter_type ||
fact_func.parameters[i].is_params != dii.parameters[i].is_params)
goto eq_cmp;
}
for (var i = 0; i < param_count; i++)
{
if (fact_func.parameters[i].type is lambda_any_type_node)
//.........这里部分代码省略.........