private expression_node convert_diap_for_set(SyntaxTree.diapason_expr _diapason_expr, out type_node elem_type) { expression_node left = convert_strong(_diapason_expr.left); if (left is typed_expression) left = convert_typed_expression_to_function_call(left as typed_expression); expression_node right = convert_strong(_diapason_expr.right); if (right is typed_expression) right = convert_typed_expression_to_function_call(right as typed_expression); internal_interface ii = left.type.get_internal_interface(internal_interface_kind.ordinal_interface); if (ii == null) { AddError(new OrdinalTypeExpected(left.location)); } internal_interface iir = right.type.get_internal_interface(internal_interface_kind.ordinal_interface); if (iir == null) { AddError(new OrdinalTypeExpected(right.location)); } type_node_list tnl = new type_node_list(); tnl.AddElement(left.type); tnl.AddElement(right.type); elem_type = convertion_data_and_alghoritms.select_base_type(tnl); expression_node l = convertion_data_and_alghoritms.explicit_convert_type(left, PascalABCCompiler.SystemLibrary.SystemLibrary.integer_type); expression_node r = convertion_data_and_alghoritms.explicit_convert_type(right, PascalABCCompiler.SystemLibrary.SystemLibrary.integer_type); if (PascalABCCompiler.SystemLibrary.SystemLibInitializer.CreateDiapason.sym_info is common_namespace_function_node) { common_namespace_function_node cnfn = PascalABCCompiler.SystemLibrary.SystemLibInitializer.CreateDiapason.sym_info as common_namespace_function_node; if (elem_type == PascalABCCompiler.SystemLibrary.SystemLibrary.char_type || elem_type == PascalABCCompiler.SystemLibrary.SystemLibrary.bool_type || elem_type.IsEnum) cnfn = PascalABCCompiler.SystemLibrary.SystemLibInitializer.CreateObjDiapason.sym_info as common_namespace_function_node; common_namespace_function_call cnfc = new common_namespace_function_call(cnfn, get_location(_diapason_expr)); if (elem_type != PascalABCCompiler.SystemLibrary.SystemLibrary.char_type && elem_type != PascalABCCompiler.SystemLibrary.SystemLibrary.bool_type && !elem_type.IsEnum) { cnfc.parameters.AddElement(l); cnfc.parameters.AddElement(r); } else { cnfc.parameters.AddElement(left); cnfc.parameters.AddElement(right); } return cnfc; } else { compiled_function_node cnfn = PascalABCCompiler.SystemLibrary.SystemLibInitializer.CreateDiapason.sym_info as compiled_function_node; if (elem_type == PascalABCCompiler.SystemLibrary.SystemLibrary.char_type || elem_type == PascalABCCompiler.SystemLibrary.SystemLibrary.bool_type || elem_type.IsEnum) cnfn = PascalABCCompiler.SystemLibrary.SystemLibInitializer.CreateObjDiapason.sym_info as compiled_function_node; compiled_static_method_call cnfc = new compiled_static_method_call(cnfn, get_location(_diapason_expr)); if (elem_type != PascalABCCompiler.SystemLibrary.SystemLibrary.char_type && elem_type != PascalABCCompiler.SystemLibrary.SystemLibrary.bool_type && !elem_type.IsEnum) { cnfc.parameters.AddElement(l); cnfc.parameters.AddElement(r); } else { cnfc.parameters.AddElement(left); cnfc.parameters.AddElement(right); } return cnfc; } }
public override void visit(SyntaxTree.pascal_set_constant _pascal_set_constant) { //throw new NotSupportedError(get_location(_pascal_set_constant)); if (SystemLibrary.SystemLibInitializer.TypedSetType == null || SystemLibrary.SystemLibInitializer.CreateSetProcedure == null) AddError(new NotSupportedError(get_location(_pascal_set_constant))); expressions_list consts = new expressions_list(); type_node el_type = null; type_node_list types = new type_node_list(); if (_pascal_set_constant.values != null && _pascal_set_constant.values != null) foreach (SyntaxTree.expression e in _pascal_set_constant.values.expressions) { if (e is SyntaxTree.nil_const) ErrorsList.Add(new SimpleSemanticError(get_location(e), "NIL_IN_SET_CONSTRUCTOR_NOT_ALLOWED")); else if (e is SyntaxTree.diapason_expr) { consts.AddElement(convert_diap_for_set((e as SyntaxTree.diapason_expr), out el_type)); if (el_type.IsPointer) ErrorsList.Add(new SimpleSemanticError(get_location(e), "POINTERS_IN_SETS_NOT_ALLOWED")); types.AddElement(el_type); } else { expression_node en = convert_strong(e); if (en is typed_expression) en = convert_typed_expression_to_function_call(en as typed_expression); if (en.type.type_special_kind == SemanticTree.type_special_kind.short_string) en.type = SystemLibrary.SystemLibrary.string_type; consts.AddElement(en); types.AddElement(en.type); } } expressions_list consts_copy = new expressions_list(); consts_copy.AddRange(consts); type_node ctn = null; if (consts.Count > 0) { el_type = convertion_data_and_alghoritms.select_base_type(types); ctn = context.create_set_type(el_type, get_location(_pascal_set_constant)); } else ctn = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; function_node fn = convertion_data_and_alghoritms.select_function(consts, SystemLibrary.SystemLibInitializer.CreateSetProcedure.SymbolInfo, (SystemLibrary.SystemLibInitializer.CreateSetProcedure.sym_info is common_namespace_function_node)?(SystemLibrary.SystemLibInitializer.CreateSetProcedure.sym_info as common_namespace_function_node).loc:null); if (fn is common_namespace_function_node) { common_namespace_function_call cnfc = new common_namespace_function_call(fn as common_namespace_function_node, get_location(_pascal_set_constant)); add_set_initializer(cnfc, consts_copy); cnfc.ret_type = ctn; for (int i = 0; i < consts.Count; i++) cnfc.parameters.AddElement(consts[i]); return_value(cnfc); } else { compiled_static_method_call cnfc = new compiled_static_method_call(fn as compiled_function_node, get_location(_pascal_set_constant)); add_set_initializer(cnfc, consts_copy); cnfc.ret_type = ctn; for (int i = 0; i < consts.Count; i++) cnfc.parameters.AddElement(consts[i]); return_value(cnfc); } //return_value(new common_namespace_function_call_as_constant(cnfc,cnfc.location)); }
public override void visit(SyntaxTree.array_type _array_type) { int rank = 1; if (is_unsized_array(_array_type.indexers, out rank)) { type_node ret = null; type_node et = convert_strong(_array_type.elements_type); //if (et == SystemLibrary.SystemLibrary.void_type) //AddError(new VoidNotValid(get_location(_array_type.elemets_types))); check_for_type_allowed(et,get_location(_array_type.elements_type)); ret = convertion_data_and_alghoritms.type_constructor.create_unsized_array(et, context.converted_namespace, rank, get_location(_array_type)); return_value(ret); return; } type_node_list ind_types = new type_node_list(); foreach (SyntaxTree.type_definition td in _array_type.indexers.indexers) { type_node tn = convert_strong(td); internal_interface ii = tn.get_internal_interface(internal_interface_kind.ordinal_interface); if (ii == null /*|| ((tn is common_type_node) && (tn as common_type_node).IsEnum)*/) { AddError(new OrdinalTypeExpected(get_location(td))); } if (tn.type_special_kind == SemanticTree.type_special_kind.diap_type) { if (tn.base_type == SystemLibrary.SystemLibrary.uint_type || tn.base_type == SystemLibrary.SystemLibrary.int64_type || tn.base_type == SystemLibrary.SystemLibrary.uint64_type) //ordinal_type_interface oti = tn.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; AddError(get_location(td), "RANGE_TOO_LARGE"); } else if (tn == SystemLibrary.SystemLibrary.uint_type || tn == SystemLibrary.SystemLibrary.int64_type || tn == SystemLibrary.SystemLibrary.uint64_type) AddError(get_location(td), "RANGE_TOO_LARGE"); ind_types.AddElement(tn); } type_node elem_type = convert_strong(_array_type.elements_type); //TODO: Сделать и массивы, связанные с generics! if (depended_from_generic_parameter(elem_type)) { throw new NotSupportedError(get_location(_array_type.elements_type)); } //if (elem_type == SystemLibrary.SystemLibrary.void_type) // AddError(new VoidNotValid(get_location(_array_type.elemets_types))); check_for_type_allowed(elem_type,get_location(_array_type.elements_type)); for (int i = ind_types.Count - 1; i >= 0; i--) { internal_interface ii = ind_types[i].get_internal_interface(internal_interface_kind.ordinal_interface); ordinal_type_interface oti_ind = (ordinal_type_interface)ii; elem_type = convertion_data_and_alghoritms.type_constructor.get_array_type(oti_ind, elem_type, context.converted_namespace, get_location(_array_type)); } return_value(elem_type); }