private void VisitCommonConstructorCallAsConstant(common_constructor_call_as_constant expr) { VisitCommonConstructorCall(expr.constructor_call); }
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)); cmc.ret_type = tn; constant = new common_namespace_function_call_as_constant(cmc,null); } } else if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) { /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); cmc.parameters.AddElement(expr); cmc.parameters.AddElement(new int_const_node((tn as short_string_type_node).Length,null));*/ expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(expr,SystemLibrary.SystemLibrary.string_type),new int_const_node((tn as short_string_type_node).Length,null)); constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call,null); } /*expression_node e = convertion_data_and_alghoritms.convert_type(constant.get_constant_copy(expr.location), tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(e as compiled_constructor_call, loc); break; default: constant = e as constant_node; break; }*/ /*if (constant.get_object_value() != null) { //if (const_def_type != null) { expression_node e = convertion_data_and_alghoritms.convert_type(constant.get_constant_copy(expr.location), tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(e as compiled_constructor_call, loc); break; default: constant = e as constant_node; break; } } } else { //if (const_def_type != null) { expression_node e = convertion_data_and_alghoritms.convert_type(expr, tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(e as compiled_constructor_call, loc); break; default: constant = e as constant_node; break; } } }*/ return constant; } else if (expr is function_constant_reference) { constant = (expr as function_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)); cmc.ret_type = tn; constant = new common_namespace_function_call_as_constant(cmc,null); } } else if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) { /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); cmc.parameters.AddElement(expr); cmc.parameters.AddElement(new int_const_node((tn as short_string_type_node).Length,null));*/ expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(expr,SystemLibrary.SystemLibrary.string_type),new int_const_node((tn as short_string_type_node).Length,null)); constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call,null); } /*expression_node e = convertion_data_and_alghoritms.convert_type(constant.get_constant_copy(expr.location), tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(e as compiled_constructor_call, loc); break; default: constant = e as constant_node; break; }*/ /*if (constant.get_object_value() != null) { //if (const_def_type != null) { expression_node e = convertion_data_and_alghoritms.convert_type(constant.get_constant_copy(expr.location), tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(e as compiled_constructor_call, loc); break; default: constant = e as constant_node; break; } } } else { //if (const_def_type != null) { expression_node e = convertion_data_and_alghoritms.convert_type(expr, tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(e as compiled_constructor_call, loc); break; default: constant = e as constant_node; break; } } }*/ return constant; } else if (expr is static_compiled_variable_reference && !(expr as static_compiled_variable_reference).var.IsLiteral) { constant = new compiled_static_field_reference_as_constant(expr as static_compiled_variable_reference, null); return constant; } else { constant = expr as constant_node; if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) { /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); cmc.parameters.AddElement(expr); cmc.parameters.AddElement(new int_const_node((tn as short_string_type_node).Length,null));*/ expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(expr, SystemLibrary.SystemLibrary.string_type), new int_const_node((tn as short_string_type_node).Length, null)); if (cmc is common_namespace_function_call) constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call, null); else constant = new compiled_static_method_call_as_constant(cmc as compiled_static_method_call, null); } //else //constant = convertion_data_and_alghoritms.convert_type(constant, tn) as constant_node; if (expr is static_compiled_variable_reference) { compiled_class_constant_definition cccd = NetHelper.NetHelper.ConvertToConstant(((static_compiled_variable_reference)expr).var); if (cccd != null) constant = cccd.const_value; else constant = new compiled_static_field_reference_as_constant(expr as static_compiled_variable_reference, null); } } if (constant == null) AddError(loc, "CONSTANT_EXPRESSION_EXPECTED"); if (IsBoundedArray(tn) || IsUnsizedArray(tn)) { if (!(constant is array_const)) AddError(loc, "ARRAY_CONST_EXPECTED"); constant = ConvertArrayConst(tn, constant as array_const); } else if (tn is common_type_node) { if (tn.type_special_kind != SemanticTree.type_special_kind.set_type && tn.type_special_kind != SemanticTree.type_special_kind.base_set_type && tn.type_special_kind != SemanticTree.type_special_kind.diap_type) { if (!tn.is_value) { if (expr is common_constructor_call) return constant; if (expr is common_constructor_call_as_constant) return expr as common_constructor_call_as_constant; convertion_data_and_alghoritms.check_convert_type(expr,tn,expr.location); //AddError(new CanNotConvertTypes(expr,expr.type,tn,expr.location)); //throw new NotSupportedError(loc); } if ((tn as common_type_node).IsEnum) { convertion_data_and_alghoritms.check_convert_type(expr,tn,expr.location); enum_const_node ecn = expr as enum_const_node; if (ecn == null) AddError(expr.location, "CONSTANT_EXPRESSION_EXPECTED"); return ecn; } if (!(constant is record_constant)) AddError(loc, "RECORD_CONST_EXPECTED"); constant = ConvertRecordConst(tn as common_type_node, constant as record_constant); } else if (tn.type_special_kind == SemanticTree.type_special_kind.diap_type) { constant = expr as constant_node; if (constant == null) AddError(expr.location, "CONSTANT_EXPRESSION_EXPECTED"); //constant = (expr as namespace_constant_reference).constant.const_value; convertion_data_and_alghoritms.check_convert_type(constant,tn,expr.location); ordinal_type_interface oti = tn.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; bool success = false; int val = convertion_data_and_alghoritms.convert_type_to_int_constant(constant, out success); if (success) { int left = convertion_data_and_alghoritms.convert_type_to_int_constant(oti.lower_value, out success); if (success) { int right = convertion_data_and_alghoritms.convert_type_to_int_constant(oti.upper_value, out success); if (success) if (val < left || val > right) AddError(loc, "OUT_OF_RANGE"); } } } else { //obrezka konstantnogo mnozhestva if (!(tn == expr.type) && !type_table.is_derived(tn,expr.type)) { AddError(new CanNotConvertTypes(expr,expr.type,tn,expr.location)); } if (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) { base_function_call cmc = null; if (SystemLibrary.SystemLibInitializer.ClipFunction.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as compiled_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; if (cmc is common_namespace_function_call) constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call, null); else constant = new compiled_static_method_call_as_constant(cmc as compiled_static_method_call, null); } else if (tn.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { base_function_call cmc = null; if (SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as compiled_function_node, null); cmc.parameters.AddElement(expr); cmc.parameters.AddElement(new int_const_node((tn.element_type as short_string_type_node).Length,null)); cmc.ret_type = tn; if (cmc is common_namespace_function_call) constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call, null); else constant = new compiled_static_method_call_as_constant(cmc as compiled_static_method_call, null); } } } } else { expression_node exprc = convertion_data_and_alghoritms.convert_type(constant, tn); switch (exprc.semantic_node_type) { case semantic_node_type.compiled_constructor_call: constant = new compiled_constructor_call_as_constant(exprc as compiled_constructor_call, loc); break; case semantic_node_type.compiled_static_method_call: constant = new compiled_static_method_call_as_constant(exprc as compiled_static_method_call, loc); break; case semantic_node_type.basic_function_call: constant = new basic_function_call_as_constant(exprc as basic_function_call, loc); break; default: constant = exprc as constant_node; break; } } return constant; }