From cf8282b3cc229cb1c054fd11d2499dc1f898009a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Thu, 3 Dec 2015 19:59:37 +0100 Subject: [PATCH] disabled declarations of extension methods in interface part of unit --- TreeConverter/TreeConversion/syntax_tree_visitor.cs | 11 ++++++++++- bin/Lng/Eng/SemanticErrors_ib.dat | 1 + bin/Lng/Rus/SemanticErrors_ib.dat | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 43df7fe73..cb9955e17 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -562,6 +562,7 @@ namespace PascalABCCompiler.TreeConverter set_intls.Clear(); NetHelper.NetHelper.reset(); from_pabc_dll = false; + in_interface_part = false; compiled_type_node[] ctns = new compiled_type_node[compiled_type_node.compiled_types.Values.Count]; compiled_type_node.compiled_types.Values.CopyTo(ctns, 0); null_type_node.reset(); @@ -3030,6 +3031,8 @@ namespace PascalABCCompiler.TreeConverter weak_node_test_and_visit(_implementation_node.implementation_definitions); } + bool in_interface_part = false; + public override void visit(SyntaxTree.interface_node _interface_node) { if (_interface_node.interface_definitions != null && _interface_node.interface_definitions.defs != null) @@ -9429,8 +9432,12 @@ namespace PascalABCCompiler.TreeConverter //cnsn.scope=_compiled_unit.scope; reset_for_interface(); + in_interface_part = false; + if (_unit_module.implementation_part != null) + in_interface_part = true; hard_node_test_and_visit(_unit_module.interface_part); - + if (_unit_module.implementation_part != null) + in_interface_part = false; //compiled_program=new program_node(); //compiled_program.units.Add(compiled_main_unit); @@ -11809,6 +11816,8 @@ namespace PascalABCCompiler.TreeConverter } case proc_attribute.attr_extension: { + if (in_interface_part) + AddError(get_location(_procedure_attributes_list), "EXTENSION_METHODS_IN_INTERFACE_PART_NOT_ALLOWED"); if (!(context.top_function is common_namespace_function_node)) AddError(get_location(_procedure_attributes_list), "EXTENSION_ATTRIBUTE_ONLY_FOR_NAMESPACE_FUNCTIONS_ALLOWED"); if (context.top_function.parameters.Count == 0) diff --git a/bin/Lng/Eng/SemanticErrors_ib.dat b/bin/Lng/Eng/SemanticErrors_ib.dat index 795653dbf..ba6efd272 100644 --- a/bin/Lng/Eng/SemanticErrors_ib.dat +++ b/bin/Lng/Eng/SemanticErrors_ib.dat @@ -99,6 +99,7 @@ EXTENSION_METHODS_MUST_HAVE_LEAST_ONE_PARAMETER=Parameter with name 'self' expec FIRST_PARAMETER_SHOULDBE_ONLY_VALUE_PARAMETER=var and const are not allowed for first parameter of extension method FIRST_PARAMETER_MUST_HAVE_NAME_SELF=Parameter with 'name' self expected EXTENSION_METHODS_FOR_CONSTRUCTED_TYPES_NOT_ALLOWED=Cannot extend this type +EXTENSION_METHODS_IN_INTERFACE_PART_NOT_ALLOWED=Cannot declare extension methods in interface part of unit %PREFIX%=COMPILATIONERROR_ UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Unit expected, library found ASSEMBLY_{0}_READING_ERROR=Error by reading assembly '{0}' diff --git a/bin/Lng/Rus/SemanticErrors_ib.dat b/bin/Lng/Rus/SemanticErrors_ib.dat index a126063ae..20e9d4fc8 100644 --- a/bin/Lng/Rus/SemanticErrors_ib.dat +++ b/bin/Lng/Rus/SemanticErrors_ib.dat @@ -101,6 +101,7 @@ EXTENSION_METHODS_MUST_HAVE_LEAST_ONE_PARAMETER=Ожидался парамет FIRST_PARAMETER_SHOULDBE_ONLY_VALUE_PARAMETER=Недопустимо использование var или const в первом параметре extension-метода FIRST_PARAMETER_MUST_HAVE_NAME_SELF=Первый параметр должен иметь имя self EXTENSION_METHODS_FOR_CONSTRUCTED_TYPES_NOT_ALLOWED=Нельзя расширять этот тип +EXTENSION_METHODS_IN_INTERFACE_PART_NOT_ALLOWED=Объявление extension-методов в интерфейсной части модуля недопустимо %PREFIX%=COMPILATIONERROR_ UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Ожидался модуль, а встречена библиотека ASSEMBLY_{0}_READING_ERROR=Ошибка при чтении сборки '{0}' \ No newline at end of file