From 24dd7a8f945da5a6d9e0c5119fe848be660c22e9 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: Sun, 18 Oct 2020 13:41:10 +0200 Subject: [PATCH] fix #2322 fix #2323 --- NETGenerator/NETGenerator.cs | 11 +++++- TestSuite/attributes2.pas | 14 ++++++++ TestSuite/errors/err0378.pas | 10 ++++++ .../TreeConversion/syntax_tree_visitor.cs | 35 +++++++++++++++---- 4 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 TestSuite/attributes2.pas create mode 100644 TestSuite/errors/err0378.pas diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 204c6a611..fbfcf659c 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -1698,7 +1698,16 @@ namespace PascalABCCompiler.NETGenerator object[] objs = new object[cnsts.Length]; for (int i = 0; i < objs.Length; i++) { - objs[i] = cnsts[i].value; + if (cnsts[i] is IArrayConstantNode) + { + List lst = new List(); + var arr_cnst = cnsts[i] as IArrayConstantNode; + foreach (IConstantNode cn in arr_cnst.ElementValues) + lst.Add(cn.value); + objs[i] = lst.ToArray(); + } + else + objs[i] = cnsts[i].value; } return objs; } diff --git a/TestSuite/attributes2.pas b/TestSuite/attributes2.pas new file mode 100644 index 000000000..f421dbaf6 --- /dev/null +++ b/TestSuite/attributes2.pas @@ -0,0 +1,14 @@ +//nopabcrtl +uses NUnitABC; + +type TClass = class +public +[Test, Combinatorial] +static procedure TestPrime4([ValuesAttribute(1,2,3,4)] a: real); +begin +end; +end; + +begin + TClass.TestPrime4(2); +end. \ No newline at end of file diff --git a/TestSuite/errors/err0378.pas b/TestSuite/errors/err0378.pas new file mode 100644 index 000000000..8317700a3 --- /dev/null +++ b/TestSuite/errors/err0378.pas @@ -0,0 +1,10 @@ +uses NUnitABC; + +[Test, Combinatorial] +procedure TestPrime4([Values(a)] a: real; + [RangeAttribute(1,200)] b: real); +begin +end; + +begin +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 1e2f090aa..90625c943 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -12204,8 +12204,25 @@ namespace PascalABCCompiler.TreeConverter attribute_node attr_node = new attribute_node(bfc.simple_function_node, tn, get_location(attr)); foreach (expression_node en in bfc.parameters) { - constant_node cn = convert_strong_to_constant_node(en, en.type); - check_for_strong_constant(cn, en.location); + constant_node cn = null; + if (en is array_initializer) + { + List cnst_list = new List(); + foreach (expression_node ex in (en as array_initializer).element_values) + { + constant_node elem_cn = convert_strong_to_constant_node(ex, ex.type); + check_for_strong_constant(elem_cn, ex.location); + cnst_list.Add(elem_cn); + } + + cn = convert_strong_to_constant_node(new array_const(cnst_list, en.location), en.type); + } + else + { + cn = convert_strong_to_constant_node(en, en.type); + check_for_strong_constant(cn, en.location); + } + attr_node.args.Add(cn); } if (attr.arguments != null) @@ -14227,10 +14244,6 @@ namespace PascalABCCompiler.TreeConverter foreach (SyntaxTree.ident id in _typed_parametres.idents.idents) { com_par = context.add_parameter(id.name, par_type, cpt, get_location(id)); - if (_typed_parametres.attributes != null) - { - make_attributes_for_declaration(_typed_parametres, com_par); - } if (is_params) { com_par.intrenal_is_params = true; @@ -14258,7 +14271,17 @@ namespace PascalABCCompiler.TreeConverter } } com_par.type = tn; + foreach (SyntaxTree.ident id in _typed_parametres.idents.idents) + { + if (_typed_parametres.attributes != null) + { + make_attributes_for_declaration(_typed_parametres, com_par); + } + + } + com_par.type = tn; context.in_parameters_block = true; + //TODO: Доделать параметры со значениями по умолчанию. if (_typed_parametres.inital_value != null) {