From 70c85a0c6a7f4afe3cfda5e18be2a9e1ddfe9816 Mon Sep 17 00:00:00 2001 From: miks1965 Date: Sun, 1 Jul 2018 11:53:34 +0300 Subject: [PATCH] fix #265 --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 2 +- .../PascalABCParserNewSaushkin/ABCPascal.cs | 2 +- .../PascalABCParserNewSaushkin/ABCPascal.lst | 409 +++++- .../PascalABCParserNewSaushkin/ABCPascal.y | 106 +- .../ABCPascalYacc.cs | 1300 +++++++++-------- Parsers/PascalABCParserNewSaushkin/PABC.tags | 1 - Parsers/PascalABCParserNewSaushkin/PABC.ymc | 1 + .../SemanticRules.cs | 38 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- SyntaxTree/tree/HierarchyVisitor.cs | 2 + SyntaxTree/tree/NodesBuilder.cs | 2 +- SyntaxTree/tree/SyntaxTreeStreamReader.cs | 3 + SyntaxTree/tree/SyntaxTreeStreamWriter.cs | 19 + SyntaxTree/tree/Tree.cs | 113 +- SyntaxTree/tree/TreeHelper.cs | 4 +- SyntaxTree/tree/tree.xml | 14 +- 17 files changed, 1299 insertions(+), 721 deletions(-) diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index f27ac01a1..b253d8b61 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "4"; public const string Build = "0"; - public const string Revision = "1682"; + public const string Revision = "1684"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 4e22e0aef..1e0ad074f 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ %MINOR%=4 -%REVISION%=1682 +%REVISION%=1684 %COREVERSION%=0 %MAJOR%=3 diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs index 7f03a5195..651b69ecc 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs @@ -2,7 +2,7 @@ // This CSharp output file generated by Gardens Point LEX // Version: 1.1.3.301 // Machine: DESKTOP-A6LT9RI -// DateTime: 28.06.2018 21:28:15 +// DateTime: 01.07.2018 11:33:54 // UserName: ????????? // GPLEX input file // GPLEX frame file diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.lst b/Parsers/PascalABCParserNewSaushkin/ABCPascal.lst index d3b3bee1e..b2d709d28 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.lst +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.lst @@ -3,9 +3,9 @@ // GPPG error listing for yacc source file // ========================================================================== // Version: 1.3.6 -// Machine: ALEXANDER-PC -// DateTime: 11.05.2018 11:34:59 -// UserName: Alexander +// Machine: DESKTOP-A6LT9RI +// DateTime: 01.07.2018 10:55:30 +// UserName: Станислав // ========================================================================== @@ -44,7 +44,7 @@ %token tkDirectiveName tkAmpersend tkColon tkDotDot tkPoint tkRoundOpen tkRoundClose tkSemiColon tkSquareOpen tkSquareClose tkQuestion tkQuestionPoint tkDoubleQuestion tkQuestionSquareOpen %token tkSizeOf tkTypeOf tkWhere tkArray tkCase tkClass tkAuto tkConst tkConstructor tkDestructor tkElse tkExcept tkFile tkFor tkForeach tkFunction tkMatch tkWhen -%token tkIf tkImplementation tkInherited tkInterface tkProcedure tkOperator tkProperty tkRaise tkRecord tkSet tkType tkThen tkUses tkVar tkWhile tkWith tkNil +%token tkIf tkImplementation tkInherited tkInterface tkTypeclass tkInstance tkProcedure tkOperator tkProperty tkRaise tkRecord tkSet tkType tkThen tkUses tkVar tkWhile tkWith tkNil %token tkGoto tkOf tkLabel tkLock tkProgram tkEvent tkDefault tkTemplate tkPacked tkExports tkResourceString tkThreadvar tkSealed tkPartial tkTo tkDownto %token tkLoop %token tkSequence tkYield @@ -92,7 +92,7 @@ %type enumeration_id expr_l1_list %type enumeration_id_list %type const_simple_expr term simple_term typed_const typed_const_plus typed_var_init_expression expr expr_with_func_decl_lambda const_expr elem range_expr const_elem array_const factor relop_expr expr_dq expr_l1 simple_expr range_term range_factor -%type external_directive_ident init_const_expr case_label variable var_reference simple_expr_or_nothing var_question_point +%type external_directive_ident init_const_expr case_label variable var_reference /*optional_write_expr*/ optional_read_expr simple_expr_or_nothing var_question_point %type for_cycle_type %type format_expr %type foreach_stmt @@ -102,8 +102,9 @@ %type var_address %type goto_stmt %type func_name_ident param_name const_field_name func_name_with_template_args identifier_or_keyword unit_name exception_variable const_name func_meth_name_ident label_name type_decl_identifier template_identifier_with_equal -%type program_param identifier identifier_keyword_operatorname func_class_name_ident optional_identifier visibility_specifier +%type program_param identifier identifier_keyword_operatorname func_class_name_ident /*optional_identifier*/ visibility_specifier %type property_specifier_directives non_reserved +%type typeclass_restriction %type if_stmt %type initialization_part %type template_arguments label_list ident_or_keyword_pointseparator_list ident_list param_name_list @@ -153,7 +154,7 @@ %type string_type %type sizeof_expr %type simple_prim_property_definition simple_property_definition -%type stmt_or_expression unlabelled_stmt stmt case_item +%type stmt_or_expression unlabelled_stmt optional_unlabelled_stmt stmt case_item %type set_type %type as_is_expr as_is_constexpr is_expr as_expr power_expr power_constexpr %type unsized_array_type simple_type_or_ simple_type array_name_for_new_expr foreach_stmt_ident_dype_opt fptype type_ref fptype_noproctype array_type @@ -164,7 +165,8 @@ %type class_or_interface_keyword optional_tk_do keyword reserved_keyword %type typeof_expr %type simple_fp_sect -%type template_param_list template_type_params +%type template_param_list template_type_params +%type template_type_or_typeclass_params typeclass_params %type template_type %type try_stmt %type uses_clause used_units_list @@ -184,9 +186,16 @@ %type full_lambda_fp_list lambda_simple_fp_sect lambda_function_body lambda_procedure_body optional_full_lambda_fp_list %type field_in_unnamed_object list_fields_in_unnamed_object func_class_name_ident_list rem_lambda variable_list var_ident_list %type tkAssignOrEqual -%type pattern match_with pattern_case pattern_cases pattern_out_param -%type pattern_out_param_list +%type pattern pattern_optional_var match_with pattern_case pattern_cases pattern_out_param pattern_out_param_optional_var +%type pattern_out_param_list pattern_out_param_list_optional_var %% +// Warning: NonTerminal symbol "optional_unlabelled_stmt" is unreachable +// Error: NonTerminal symbol "optional_unlabelled_stmt" has no productions +// Error: There are 1 non-terminating NonTerminal Symbols + // {optional_unlabelled_stmt} +// Warning: Terminating optional_unlabelled_stmt fixes the following size-1 NonTerminal set + // {optional_unlabelled_stmt} +// ---------------------------------------------------------------------------------------- parse_goal : program_file @@ -323,17 +332,27 @@ uses_clause if (parsertools.build_tree_for_formatter) { if ($1 == null) - $1 = new uses_closure($3 as uses_list,@$); - else ($1 as uses_closure).AddUsesList($3 as uses_list,@$); - $$ = $1; + { + $$ = new uses_closure($3 as uses_list,@$); + } + else { + ($1 as uses_closure).AddUsesList($3 as uses_list,@$); + $$ = $1; + } } else { if ($1 == null) - $1 = $3; - else ($1 as uses_list).AddUsesList($3 as uses_list,@$); - $$ = $1; - $$.source_context = @$; + { + $$ = $3; + $$.source_context = @$; + } + else + { + ($1 as uses_list).AddUsesList($3 as uses_list,@$); + $$ = $1; + $$.source_context = @$; + } } } ; @@ -835,6 +854,28 @@ const_factor } | sign const_factor { + // ðó÷íàß êîððåêöèß öåëûõ êîíñòàíò + if ($1.type == Operators.Minus) + { + var i64 = $2 as int64_const; + if (i64 != null && i64.val == (Int64)Int32.MaxValue + 1) + { + $$ = new int32_const(Int32.MinValue); + break; + } + var ui64 = $2 as uint64_const; + if (ui64 != null && ui64.val == (UInt64)Int64.MaxValue + 1) + { + $$ = new int64_const(Int64.MinValue); + break; + } + if (ui64 != null && ui64.val > (UInt64)Int64.MaxValue + 1) + { + parsertools.AddErrorFromResource("BAD_INT2",@$); + break; + } + // ìîæíî ñäåëàòü âû÷èñëåíèå êîíñòàíòû ñ âìîíòèðîâàííûì ìèíóñîì + } $$ = new un_expr($2, $1.type, @$); } | new_expr @@ -862,15 +903,28 @@ sign const_variable : identifier { $$ = $1; } + | tkInherited identifier + { + $$ = new inherited_ident($2.name, @$); + } | sizeof_expr { $$ = $1; } | typeof_expr { $$ = $1; } +/* | tkRoundOpen const_expr tkRoundClose + { + if (!parsertools.build_tree_for_formatter) + { + $2.source_context = @$; + $$ = $2; + } + else $$ = new bracket_expr($2, @$); + }*/ | const_variable const_variable_2 { $$ = NewConstVariable($1, $2, @$); } - | const_variable tkAmpersend template_type_params + | const_variable tkAmpersend template_type_or_typeclass_params { $$ = new ident_with_templateparams($1 as addressed_value, $3 as template_param_list, @$); } @@ -1084,8 +1138,40 @@ simple_type_decl { $$ = new type_declaration($1, $2, @$); } + | typeclass_restriction tkEqual tkTypeclass optional_base_classes optional_component_list_seq_end tkSemiColon + { + $$ = new type_declaration($1 as typeclass_restriction, new typeclass_definition($4 as named_type_reference_list, $5 as class_body_list, @$), @$); + } + | typeclass_restriction tkEqual tkInstance optional_component_list_seq_end tkSemiColon + { + $$ = new type_declaration($1 as typeclass_restriction, new instance_definition($4 as class_body_list, @$), @$); + } ; +typeclass_restriction + : simple_type_identifier typeclass_params + { + $$ = new typeclass_restriction(($1 as named_type_reference).ToString(), $2 as template_param_list, @$); + } + ; + +typeclass_params + : tkSquareOpen template_param_list tkSquareClose + { + $$ = new typeclass_param_list($2 as template_param_list); + } + ; + +template_type_or_typeclass_params + : template_type_params + { + $$ = $1; + } + | typeclass_params + { + $$ = $1; + } + ; type_decl_identifier : identifier { $$ = $1; } @@ -1430,6 +1516,25 @@ object_type : class_attributes class_or_interface_keyword optional_base_classes optional_where_section optional_component_list_seq_end { $$ = NewObjectType((class_attribute)$1, $2, $3 as named_type_reference_list, $4 as where_definition_list, $5 as class_body_list, @$); + class_definition cd = $$ as class_definition; + var ccnt = cd.body.DescendantNodes().OfType().ToArray(); + var cm = new class_members(access_modifer.private_modifer); + foreach (var prop in ccnt) + { + var td = prop.property_type; + if (prop.accessors.read_accessor != null && prop.accessors.read_accessor.pr != null) + { + (prop.accessors.read_accessor.pr.proc_header as function_header).return_type = td; + cm.Add(prop.accessors.read_accessor.pr); + } + if (prop.accessors.write_accessor != null && prop.accessors.write_accessor.pr != null) + { + prop.accessors.write_accessor.pr.proc_header.parameters.params_list[0].vars_type = td; + cm.Add(prop.accessors.write_accessor.pr); + } + } + if (cm.Count>0) + cd.body.Insert(0, cm); } ; @@ -1469,8 +1574,8 @@ class_attributes1 } | class_attributes1 class_attribute { - $1 = ((class_attribute)$1) | ((class_attribute)$2); - $$ = $1; + $$ = ((class_attribute)$1) | ((class_attribute)$2); + //$$ = $1; } ; @@ -1529,6 +1634,11 @@ base_class_name { $$ = $1; } | template_type { $$ = $1; } + | typeclass_restriction + { + var names = new List(); + names.Add(($1 as typeclass_restriction).name); + $$ = new typeclass_reference(null, names, ($1 as typeclass_restriction).restriction_args); } ; template_arguments @@ -1562,6 +1672,10 @@ where_part { $$ = new where_definition($2 as ident_list, $4 as where_type_specificator_list, @$); } + | tkWhere typeclass_restriction tkSemiColon + { + $$ = new where_typeclass_constraint($2 as typeclass_restriction); + } ; type_ref_and_secific_list @@ -1724,6 +1838,8 @@ method_decl_withattr | attribute_declarations method_decl { ($2 as declaration).attributes = $1 as attribute_list; + if ($2 is procedure_definition && ($2 as procedure_definition).proc_header != null) + ($2 as procedure_definition).proc_header.attributes = $1 as attribute_list; $$ = $2; } ; @@ -1874,37 +1990,105 @@ parameter_decl } ; -optional_identifier +/*optional_identifier : identifier { $$ = $1; } | { $$ = null; } ; + +optional_write_expr + : var_reference + { $$ = $1; } + | + { $$ = null; } + ;*/ + +/*optional_unlabelled_stmt + : unlabelled_stmt + { $$ = $1; } + | + { $$ = null; } + ;*/ + +optional_read_expr + : expr_with_func_decl_lambda + { $$ = $1; } + | + { $$ = null; } + ; property_specifiers : - | tkRead optional_identifier write_property_specifiers + | tkRead optional_read_expr write_property_specifiers { - $$ = NewPropertySpecifiersRead($1, $2, $3 as property_accessors, @$); + if ($2 == null || $2 is ident) + { + $$ = NewPropertySpecifiersRead($1, $2 as ident, null, $3 as property_accessors, @$); + } + else + { + var id = NewId("#GetGen"); + var pr = CreateAndAddToClassReadFunc($2,id,@2); + $$ = NewPropertySpecifiersRead($1, id, pr, $3 as property_accessors, @$); + } } - | tkWrite optional_identifier read_property_specifiers + | tkWrite unlabelled_stmt read_property_specifiers { - $$ = NewPropertySpecifiersWrite($1, $2, $3 as property_accessors, @$); + if ($2 is empty_statement) + { + + $$ = NewPropertySpecifiersWrite($1, null, null, $3 as property_accessors, @$); + } + else if ($2 is procedure_call && ($2 as procedure_call).func_name.is_ident) + { + + $$ = NewPropertySpecifiersWrite($1, ($2 as procedure_call).func_name as ident, null, $3 as property_accessors, @$); + } + else + { + var id = NewId("#SetGen"); + //var pr = CreateAndAddToClassWriteProc($2,id,@2); + $$ = NewPropertySpecifiersWrite($1, id, null, $3 as property_accessors, @$); + } } ; write_property_specifiers : - | tkWrite optional_identifier + | tkWrite unlabelled_stmt { - $$ = NewPropertySpecifiersWrite($1, $2, null, @$); + if ($2 is empty_statement) + { + + $$ = NewPropertySpecifiersWrite($1, null, null, null, @$); + } + else if ($2 is procedure_call && ($2 as procedure_call).func_name.is_ident) + { + $$ = NewPropertySpecifiersWrite($1, ($2 as procedure_call).func_name as ident, null, null, @$); + } + else + { + var id = NewId("#SetGen"); + //var pr = CreateAndAddToClassWriteProc($2,id,@2); + $$ = NewPropertySpecifiersWrite($1, id, null, null, @$); + } } ; read_property_specifiers : - | tkRead optional_identifier + | tkRead optional_read_expr { - $$ = NewPropertySpecifiersRead($1, $2, null, @$); + if ($2 == null || $2 is ident) + { + $$ = NewPropertySpecifiersRead($1, $2 as ident, null, null, @$); + } + else + { + var id = NewId("#GetGen"); + var pr = CreateAndAddToClassReadFunc($2,id,@2); + $$ = NewPropertySpecifiersRead($1, id, pr, null, @$); + } } ; @@ -2014,6 +2198,15 @@ constr_destr_decl if (parsertools.build_tree_for_formatter) $$ = new short_func_definition($$ as procedure_definition); } + | tkClass tkConstructor optional_proc_name fp_list tkAssign unlabelled_stmt tkSemiColon + { + if ($6 is empty_statement) + parsertools.AddErrorFromResource("EMPTY_STATEMENT_IN_SHORT_PROC_DEFINITION",@7); + var tmp = new constructor(null,$4 as formal_parameters,new procedure_attributes_list(new List(),@$),$3 as method_name,false,true,null,null,@$); + $$ = new procedure_definition(tmp as procedure_header, new block(null,new statement_list($6 as statement,@6),@6), @$); + if (parsertools.build_tree_for_formatter) + $$ = new short_func_definition($$ as procedure_definition); + } ; inclass_constr_destr_decl @@ -2025,11 +2218,20 @@ inclass_constr_destr_decl { if ($5 is empty_statement) parsertools.AddErrorFromResource("EMPTY_STATEMENT_IN_SHORT_PROC_DEFINITION",@6); - var tmp = new constructor(null,$3 as formal_parameters,new procedure_attributes_list(new List(),@$),$2 as method_name,false,false,null,null,LexLocation.MergeAll(@1,@2,@3)); + var tmp = new constructor(null,$3 as formal_parameters,new procedure_attributes_list(new List(),@$),$2 as method_name,false,false,null,null,LexLocation.MergeAll(@1,@2,@3,@4)); $$ = new procedure_definition(tmp as procedure_header, new block(null,new statement_list($5 as statement,@5),@5), @$); if (parsertools.build_tree_for_formatter) $$ = new short_func_definition($$ as procedure_definition); } + | tkClass tkConstructor optional_proc_name fp_list tkAssign unlabelled_stmt tkSemiColon + { + if ($6 is empty_statement) + parsertools.AddErrorFromResource("EMPTY_STATEMENT_IN_SHORT_PROC_DEFINITION",@7); + var tmp = new constructor(null,$4 as formal_parameters,new procedure_attributes_list(new List(),@$),$3 as method_name,false,true,null,null,LexLocation.MergeAll(@1,@2,@3,@4)); + $$ = new procedure_definition(tmp as procedure_header, new block(null,new statement_list($6 as statement,@6),@6), @$); + if (parsertools.build_tree_for_formatter) + $$ = new short_func_definition($$ as procedure_definition); + } ; proc_func_decl @@ -2053,6 +2255,9 @@ proc_func_decl_noclass } | tkFunction func_name fp_list optional_method_modificators1 tkAssign expr_l1 tkSemiColon { + if ($6 is dot_question_node) + parsertools.AddErrorFromResource("DOT_QUECTION_IN_SHORT_FUN",@6); + $$ = SyntaxTreeBuilder.BuildShortFuncDefinition($3 as formal_parameters, $4 as procedure_attributes_list, $2 as method_name, null, $6, @1.Merge(@4)); } | tkFunction func_name fp_list tkColon fptype optional_method_modificators1 tkAssign func_decl_lambda tkSemiColon @@ -2483,7 +2688,7 @@ var_ident_list proc_call : var_reference { - $$ = new procedure_call($1 as addressed_value, @$); + $$ = new procedure_call($1 as addressed_value, $1 is ident, @$); } ; @@ -2527,9 +2732,9 @@ if_stmt ; match_with - : tkMatch expr_l1 tkWith pattern_cases tkEnd + : tkMatch expr_l1 tkWith pattern_cases else_case tkEnd { - $$ = new match_with($2, $4 as pattern_cases); + $$ = new match_with($2, $4 as pattern_cases, $5 as statement, @$); } ; @@ -2545,13 +2750,15 @@ pattern_cases ; pattern_case - : pattern tkWhen expr_l1 tkColon unlabelled_stmt + : + { $$ = new empty_statement(); } + | pattern_optional_var tkWhen expr_l1 tkColon unlabelled_stmt { - $$ = new pattern_case($1 as pattern_node, $5 as statement, $3); + $$ = new pattern_case($1 as pattern_node, $5 as statement, $3, @$); } - | pattern tkColon unlabelled_stmt + | pattern_optional_var tkColon unlabelled_stmt { - $$ = new pattern_case($1 as pattern_node, $3 as statement, null); + $$ = new pattern_case($1 as pattern_node, $3 as statement, null, @$); } ; @@ -2873,6 +3080,8 @@ typeof_expr question_expr : expr_l1 tkQuestion expr_l1 tkColon expr_l1 { + if ($3 is nil_const && $5 is nil_const) + parsertools.AddErrorFromResource("TWO_NILS_IN_QUESTION_EXPR",@3); $$ = new question_colon_expression($1, $3, $5, @$); } ; @@ -2886,7 +3095,7 @@ simple_or_template_type_reference { $$ = new template_type_reference((named_type_reference)$1, (template_param_list)$2, @$); } - | simple_type_identifier tkAmpersend template_type_params + | simple_type_identifier tkAmpersend template_type_or_typeclass_params { $$ = new template_type_reference((named_type_reference)$1, (template_param_list)$3, @$); } @@ -2998,12 +3207,11 @@ relop_expr { $$ = new bin_expr($1, $3, $2.type, @$); } - | is_expr tkRoundOpen tkVar identifier tkRoundClose + | is_expr tkRoundOpen pattern_out_param_list tkRoundClose { var isTypeCheck = $1 as typecast_node; - var typeDef = isTypeCheck.type_def; - var pattern = new type_pattern($4, typeDef, typeDef.source_context); - $$ = new is_pattern_expr(isTypeCheck.expr, pattern, @$); + var deconstructorPattern = new deconstructor_pattern($3 as List, isTypeCheck.type_def, @$); + $$ = new is_pattern_expr(isTypeCheck.expr, deconstructorPattern, @$); } ; @@ -3013,7 +3221,34 @@ pattern $$ = new deconstructor_pattern($3 as List, $1, @$); } ; + +pattern_optional_var + : simple_or_template_type_reference tkRoundOpen pattern_out_param_list_optional_var tkRoundClose + { + $$ = new deconstructor_pattern($3 as List, $1, @$); + } + ; +pattern_out_param_list_optional_var + : pattern_out_param_optional_var + { + $$ = new List(); + ($$ as List).Add($1 as pattern_deconstructor_parameter); + } + | pattern_out_param_list_optional_var tkSemiColon pattern_out_param_optional_var + { + var list = $1 as List; + list.Add($3 as pattern_deconstructor_parameter); + $$ = list; + } + | pattern_out_param_list_optional_var tkComma pattern_out_param_optional_var + { + var list = $1 as List; + list.Add($3 as pattern_deconstructor_parameter); + $$ = list; + } + ; + pattern_out_param_list : pattern_out_param { @@ -3026,22 +3261,49 @@ pattern_out_param_list list.Add($3 as pattern_deconstructor_parameter); $$ = list; } - ; - + | pattern_out_param_list tkComma pattern_out_param + { + var list = $1 as List; + list.Add($3 as pattern_deconstructor_parameter); + $$ = list; + } + ; + pattern_out_param + : tkVar identifier tkColon type_ref + { + $$ = new var_deconstructor_parameter($2, $4, @$); + } + | tkVar identifier + { + $$ = new var_deconstructor_parameter($2, null, @$); + } + | pattern + { + $$ = new recursive_deconstructor_parameter($1 as pattern_node, @$); + } + ; + +pattern_out_param_optional_var : identifier tkColon type_ref { - $$ = new pattern_deconstructor_parameter($2, $4, @$); -//-------------------------------------------------------^^ -// Error: Semantic action index is out of bounds -// --------------------------------------------- + $$ = new var_deconstructor_parameter($1, $3, @$); } | identifier { - $$ = new pattern_deconstructor_parameter($2, null, @$); -//---------------------------------------------------^^ -// Error: Semantic action index is out of bounds -// --------------------------------------------- + $$ = new var_deconstructor_parameter($1, null, @$); + } + | tkVar identifier tkColon type_ref + { + $$ = new var_deconstructor_parameter($2, $4, @$); + } + | tkVar identifier + { + $$ = new var_deconstructor_parameter($2, null, @$); + } + | pattern_optional_var + { + $$ = new recursive_deconstructor_parameter($1 as pattern_node, @$); } ; @@ -3203,7 +3465,7 @@ tuple if ($6 != null) parsertools.AddErrorFromResource("BAD_TUPLE",@6);*/ - if (($4 as expression_list).Count>7) + if (($4 as expression_list).Count>6) parsertools.AddErrorFromResource("TUPLE_ELEMENTS_COUNT_MUST_BE_LESSEQUAL_7",@$); ($4 as expression_list).Insert(0,$2); $$ = new tuple_node($4 as expression_list,@$); @@ -3229,7 +3491,29 @@ factor $$ = new un_expr($2, $1.type, @$); } | sign factor - { + { + if ($1.type == Operators.Minus) + { + var i64 = $2 as int64_const; + if (i64 != null && i64.val == (Int64)Int32.MaxValue + 1) + { + $$ = new int32_const(Int32.MinValue); + break; + } + var ui64 = $2 as uint64_const; + if (ui64 != null && ui64.val == (UInt64)Int64.MaxValue + 1) + { + $$ = new int64_const(Int64.MinValue); + break; + } + if (ui64 != null && ui64.val > (UInt64)Int64.MaxValue + 1) + { + parsertools.AddErrorFromResource("BAD_INT2",@$); + break; + } + // ìîæíî ñäåëàòü âû÷èñëåíèå êîíñòàíòû ñ âìîíòèðîâàííûì ìèíóñîì + } + $$ = new un_expr($2, $1.type, @$); } | tkDeref factor @@ -3336,10 +3620,13 @@ variable if (el.Count==1 && el.expressions[0] is format_expr) { var fe = el.expressions[0] as format_expr; - if (fe.expr == null) - fe.expr = new int32_const(int.MaxValue,@3); - if (fe.format1 == null) - fe.format1 = new int32_const(int.MaxValue,@3); + if (!parsertools.build_tree_for_formatter) + { + if (fe.expr == null) + fe.expr = new int32_const(int.MaxValue,@3); + if (fe.format1 == null) + fe.format1 = new int32_const(int.MaxValue,@3); + } $$ = new slice_expr($1 as addressed_value,fe.expr,fe.format1,fe.format2,@$); } else $$ = new indexer($1 as addressed_value,el, @$); @@ -3373,7 +3660,7 @@ variable { $$ = new roof_dereference($1 as addressed_value,@$); } - | variable tkAmpersend template_type_params + | variable tkAmpersend template_type_or_typeclass_params { $$ = new ident_with_templateparams($1 as addressed_value, $3 as template_param_list, @$); } @@ -3707,6 +3994,10 @@ keyword { $$ = $1; } | tkYield { $$ = $1; } + | tkMatch + { $$ = $1; } + | tkWhen + { $$ = $1; } ; reserved_keyword diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.y b/Parsers/PascalABCParserNewSaushkin/ABCPascal.y index 3306b46e7..4513ce759 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.y +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.y @@ -81,7 +81,7 @@ %type enumeration_id expr_l1_list %type enumeration_id_list %type const_simple_expr term simple_term typed_const typed_const_plus typed_var_init_expression expr expr_with_func_decl_lambda const_expr elem range_expr const_elem array_const factor relop_expr expr_dq expr_l1 simple_expr range_term range_factor -%type external_directive_ident init_const_expr case_label variable var_reference simple_expr_or_nothing var_question_point +%type external_directive_ident init_const_expr case_label variable var_reference /*optional_write_expr*/ optional_read_expr simple_expr_or_nothing var_question_point %type for_cycle_type %type format_expr %type foreach_stmt @@ -91,7 +91,7 @@ %type var_address %type goto_stmt %type func_name_ident param_name const_field_name func_name_with_template_args identifier_or_keyword unit_name exception_variable const_name func_meth_name_ident label_name type_decl_identifier template_identifier_with_equal -%type program_param identifier identifier_keyword_operatorname func_class_name_ident optional_identifier visibility_specifier +%type program_param identifier identifier_keyword_operatorname func_class_name_ident /*optional_identifier*/ visibility_specifier %type property_specifier_directives non_reserved %type typeclass_restriction %type if_stmt @@ -1498,6 +1498,27 @@ object_type : class_attributes class_or_interface_keyword optional_base_classes optional_where_section optional_component_list_seq_end { $$ = NewObjectType((class_attribute)$1, $2, $3 as named_type_reference_list, $4 as where_definition_list, $5 as class_body_list, @$); + class_definition cd = $$ as class_definition; + if (cd == null || cd.body == null) + break; + var ccnt = cd.body.DescendantNodes().OfType().ToArray(); + var cm = new class_members(access_modifer.private_modifer); + foreach (var prop in ccnt) + { + var td = prop.property_type; + if (prop.accessors.read_accessor != null && prop.accessors.read_accessor.pr != null) + { + (prop.accessors.read_accessor.pr.proc_header as function_header).return_type = td; + cm.Add(prop.accessors.read_accessor.pr); + } + if (prop.accessors.write_accessor != null && prop.accessors.write_accessor.pr != null) + { + prop.accessors.write_accessor.pr.proc_header.parameters.params_list[0].vars_type = td; + cm.Add(prop.accessors.write_accessor.pr); + } + } + if (cm.Count>0) + cd.body.Insert(0, cm); } ; @@ -1953,37 +1974,98 @@ parameter_decl } ; -optional_identifier +/*optional_identifier : identifier { $$ = $1; } | { $$ = null; } ; + +optional_write_expr + : var_reference + { $$ = $1; } + | + { $$ = null; } + ;*/ + +optional_read_expr + : expr_with_func_decl_lambda + { $$ = $1; } + | + { $$ = null; } + ; property_specifiers : - | tkRead optional_identifier write_property_specifiers + | tkRead optional_read_expr write_property_specifiers { - $$ = NewPropertySpecifiersRead($1, $2, $3 as property_accessors, @$); + if ($2 == null || $2 is ident) + { + $$ = NewPropertySpecifiersRead($1, $2 as ident, null, $3 as property_accessors, @$); + } + else + { + var id = NewId("#GetGen"); + var pr = CreateAndAddToClassReadFunc($2,id,@2); + $$ = NewPropertySpecifiersRead($1, id, pr, $3 as property_accessors, @$); + } } - | tkWrite optional_identifier read_property_specifiers + | tkWrite unlabelled_stmt read_property_specifiers { - $$ = NewPropertySpecifiersWrite($1, $2, $3 as property_accessors, @$); + if ($2 is empty_statement) + { + + $$ = NewPropertySpecifiersWrite($1, null, null, $3 as property_accessors, @$); + } + else if ($2 is procedure_call && ($2 as procedure_call).is_ident) + { + + $$ = NewPropertySpecifiersWrite($1, ($2 as procedure_call).func_name as ident, null, $3 as property_accessors, @$); // - + } + else + { + var id = NewId("#SetGen"); + var pr = CreateAndAddToClassWriteProc($2 as statement,id,@2); + $$ = NewPropertySpecifiersWrite($1, id, pr, $3 as property_accessors, @$); + } } ; write_property_specifiers : - | tkWrite optional_identifier + | tkWrite unlabelled_stmt { - $$ = NewPropertySpecifiersWrite($1, $2, null, @$); + if ($2 is empty_statement) + { + + $$ = NewPropertySpecifiersWrite($1, null, null, null, @$); + } + else if ($2 is procedure_call && ($2 as procedure_call).is_ident) + { + $$ = NewPropertySpecifiersWrite($1, ($2 as procedure_call).func_name as ident, null, null, @$); // - + } + else + { + var id = NewId("#SetGen"); + var pr = CreateAndAddToClassWriteProc($2 as statement,id,@2); + $$ = NewPropertySpecifiersWrite($1, id, pr, null, @$); + } } ; read_property_specifiers : - | tkRead optional_identifier + | tkRead optional_read_expr { - $$ = NewPropertySpecifiersRead($1, $2, null, @$); + if ($2 == null || $2 is ident) + { + $$ = NewPropertySpecifiersRead($1, $2 as ident, null, null, @$); + } + else + { + var id = NewId("#GetGen"); + var pr = CreateAndAddToClassReadFunc($2,id,@2); + $$ = NewPropertySpecifiersRead($1, id, pr, null, @$); + } } ; @@ -2583,7 +2665,7 @@ var_ident_list proc_call : var_reference { - $$ = new procedure_call($1 as addressed_value, @$); + $$ = new procedure_call($1 as addressed_value, $1 is ident, @$); } ; diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs index 81f88b16d..af7f9a79f 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs @@ -2,7 +2,7 @@ // GPPG version 1.3.6 // Machine: DESKTOP-A6LT9RI -// DateTime: 28.06.2018 21:28:15 +// DateTime: 01.07.2018 11:33:54 // UserName: ????????? // Input file @@ -99,55 +99,55 @@ public partial class GPPGParser: ShiftReduceParser().ToArray(); + var cm = new class_members(access_modifer.private_modifer); + foreach (var prop in ccnt) + { + var td = prop.property_type; + if (prop.accessors.read_accessor != null && prop.accessors.read_accessor.pr != null) + { + (prop.accessors.read_accessor.pr.proc_header as function_header).return_type = td; + cm.Add(prop.accessors.read_accessor.pr); + } + if (prop.accessors.write_accessor != null && prop.accessors.write_accessor.pr != null) + { + prop.accessors.write_accessor.pr.proc_header.parameters.params_list[0].vars_type = td; + cm.Add(prop.accessors.write_accessor.pr); + } + } + if (cm.Count>0) + cd.body.Insert(0, cm); } break; case 287: // record_type -> tkRecord, optional_base_classes, optional_where_section, @@ -4221,30 +4242,77 @@ public partial class GPPGParser: ShiftReduceParser identifier -{ CurrentSemanticValue.id = ValueStack[ValueStack.Depth-1].id; } + case 383: // optional_read_expr -> expr_with_func_decl_lambda +{ CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 384: // optional_identifier -> /* empty */ -{ CurrentSemanticValue.id = null; } + case 384: // optional_read_expr -> /* empty */ +{ CurrentSemanticValue.ex = null; } break; - case 386: // property_specifiers -> tkRead, optional_identifier, write_property_specifiers + case 386: // property_specifiers -> tkRead, optional_read_expr, write_property_specifiers { - CurrentSemanticValue.stn = NewPropertySpecifiersRead(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-2].id, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); + if (ValueStack[ValueStack.Depth-2].ex == null || ValueStack[ValueStack.Depth-2].ex is ident) + { + CurrentSemanticValue.stn = NewPropertySpecifiersRead(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-2].ex as ident, null, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); + } + else + { + var id = NewId("#GetGen"); + var pr = CreateAndAddToClassReadFunc(ValueStack[ValueStack.Depth-2].ex,id,LocationStack[LocationStack.Depth-2]); + CurrentSemanticValue.stn = NewPropertySpecifiersRead(ValueStack[ValueStack.Depth-3].id, id, pr, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); + } } break; - case 387: // property_specifiers -> tkWrite, optional_identifier, read_property_specifiers + case 387: // property_specifiers -> tkWrite, unlabelled_stmt, read_property_specifiers { - CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-2].id, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); + if (ValueStack[ValueStack.Depth-2].stn is empty_statement) + { + + CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-3].id, null, null, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); + } + else if (ValueStack[ValueStack.Depth-2].stn is procedure_call && (ValueStack[ValueStack.Depth-2].stn as procedure_call).is_ident) + { + + CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-3].id, (ValueStack[ValueStack.Depth-2].stn as procedure_call).func_name as ident, null, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); // ������ �������� - � ��������������� + } + else + { + var id = NewId("#SetGen"); + var pr = CreateAndAddToClassWriteProc(ValueStack[ValueStack.Depth-2].stn as statement,id,LocationStack[LocationStack.Depth-2]); + CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-3].id, id, pr, ValueStack[ValueStack.Depth-1].stn as property_accessors, CurrentLocationSpan); + } } break; - case 389: // write_property_specifiers -> tkWrite, optional_identifier + case 389: // write_property_specifiers -> tkWrite, unlabelled_stmt { - CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-2].id, ValueStack[ValueStack.Depth-1].id, null, CurrentLocationSpan); + if (ValueStack[ValueStack.Depth-1].stn is empty_statement) + { + + CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-2].id, null, null, null, CurrentLocationSpan); + } + else if (ValueStack[ValueStack.Depth-1].stn is procedure_call && (ValueStack[ValueStack.Depth-1].stn as procedure_call).is_ident) + { + CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-2].id, (ValueStack[ValueStack.Depth-1].stn as procedure_call).func_name as ident, null, null, CurrentLocationSpan); // ������ �������� - � ��������������� + } + else + { + var id = NewId("#SetGen"); + var pr = CreateAndAddToClassWriteProc(ValueStack[ValueStack.Depth-1].stn as statement,id,LocationStack[LocationStack.Depth-1]); + CurrentSemanticValue.stn = NewPropertySpecifiersWrite(ValueStack[ValueStack.Depth-2].id, id, pr, null, CurrentLocationSpan); + } } break; - case 391: // read_property_specifiers -> tkRead, optional_identifier + case 391: // read_property_specifiers -> tkRead, optional_read_expr { - CurrentSemanticValue.stn = NewPropertySpecifiersRead(ValueStack[ValueStack.Depth-2].id, ValueStack[ValueStack.Depth-1].id, null, CurrentLocationSpan); + if (ValueStack[ValueStack.Depth-1].ex == null || ValueStack[ValueStack.Depth-1].ex is ident) + { + CurrentSemanticValue.stn = NewPropertySpecifiersRead(ValueStack[ValueStack.Depth-2].id, ValueStack[ValueStack.Depth-1].ex as ident, null, null, CurrentLocationSpan); + } + else + { + var id = NewId("#GetGen"); + var pr = CreateAndAddToClassReadFunc(ValueStack[ValueStack.Depth-1].ex,id,LocationStack[LocationStack.Depth-1]); + CurrentSemanticValue.stn = NewPropertySpecifiersRead(ValueStack[ValueStack.Depth-2].id, id, pr, null, CurrentLocationSpan); + } } break; case 392: // var_decl -> var_decl_part, tkSemiColon @@ -4836,7 +4904,7 @@ public partial class GPPGParser: ShiftReduceParser var_reference { - CurrentSemanticValue.stn = new procedure_call(ValueStack[ValueStack.Depth-1].ex as addressed_value, CurrentLocationSpan); + CurrentSemanticValue.stn = new procedure_call(ValueStack[ValueStack.Depth-1].ex as addressed_value, ValueStack[ValueStack.Depth-1].ex is ident, CurrentLocationSpan); } break; case 510: // goto_stmt -> tkGoto, label_name diff --git a/Parsers/PascalABCParserNewSaushkin/PABC.tags b/Parsers/PascalABCParserNewSaushkin/PABC.tags index dd31edd6d..86974509d 100644 --- a/Parsers/PascalABCParserNewSaushkin/PABC.tags +++ b/Parsers/PascalABCParserNewSaushkin/PABC.tags @@ -220,7 +220,6 @@ - diff --git a/Parsers/PascalABCParserNewSaushkin/PABC.ymc b/Parsers/PascalABCParserNewSaushkin/PABC.ymc index 146761c0b..8cc599e0d 100644 --- a/Parsers/PascalABCParserNewSaushkin/PABC.ymc +++ b/Parsers/PascalABCParserNewSaushkin/PABC.ymc @@ -195,5 +195,6 @@ script= + diff --git a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs index d0ac91a11..a1851d98b 100644 --- a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs +++ b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs @@ -216,7 +216,7 @@ namespace GPPGParserScanner return nnspd; } - public property_accessors NewPropertySpecifiersRead(ident tkRead, ident opt_identifier, property_accessors property_specifiers, LexLocation loc) + public property_accessors NewPropertySpecifiersRead(ident tkRead, ident opt_identifier, procedure_definition pr, property_accessors property_specifiers, LexLocation loc) { var nnps = property_specifiers; if (nnps == null) @@ -225,23 +225,23 @@ namespace GPPGParserScanner } if (opt_identifier != null && opt_identifier.name.ToLower() == "write") { - nnps.read_accessor = new read_accessor_name(null); - nnps.write_accessor = new write_accessor_name(null); + nnps.read_accessor = new read_accessor_name(null, null); + nnps.write_accessor = new write_accessor_name(null, null); nnps.read_accessor.source_context = tkRead.source_context; nnps.write_accessor.source_context = opt_identifier.source_context; } else { if (opt_identifier != null) - nnps.read_accessor = new read_accessor_name(opt_identifier, tkRead.source_context.Merge(opt_identifier.source_context)); - else nnps.read_accessor = new read_accessor_name(opt_identifier, tkRead.source_context); + nnps.read_accessor = new read_accessor_name(opt_identifier, pr, tkRead.source_context.Merge(opt_identifier.source_context)); + else nnps.read_accessor = new read_accessor_name(opt_identifier, pr, tkRead.source_context); } nnps.source_context = loc; return nnps; } - public property_accessors NewPropertySpecifiersWrite(ident tkWrite, ident opt_identifier, property_accessors property_specifiers, LexLocation loc) + public property_accessors NewPropertySpecifiersWrite(ident tkWrite, ident opt_identifier, procedure_definition pr, property_accessors property_specifiers, LexLocation loc) { var nnpsw = property_specifiers; if (nnpsw == null) @@ -249,8 +249,8 @@ namespace GPPGParserScanner nnpsw = new property_accessors(); } if (opt_identifier != null) - nnpsw.write_accessor = new write_accessor_name(opt_identifier,tkWrite.source_context.Merge(opt_identifier.source_context)); - else nnpsw.write_accessor = new write_accessor_name(opt_identifier,tkWrite.source_context); + nnpsw.write_accessor = new write_accessor_name(opt_identifier,pr,tkWrite.source_context.Merge(opt_identifier.source_context)); + else nnpsw.write_accessor = new write_accessor_name(opt_identifier,pr,tkWrite.source_context); nnpsw.source_context = loc; return nnpsw; } @@ -509,5 +509,25 @@ namespace GPPGParserScanner sl.source_context = loc; return sl; } - } + + public procedure_definition CreateAndAddToClassReadFunc(expression ex, ident id, SourceContext sc) + { + var fd = SyntaxTreeBuilder.BuildShortFuncDefinition(new formal_parameters(), null, new method_name(id.name, sc), new no_type(), ex, sc); + return fd; + } + public procedure_definition CreateAndAddToClassWriteProc(statement st, ident id, SourceContext sc) + { + var fp = SyntaxTreeBuilder.BuildFormalParameters(new List() { new ident("value") }, new List() { new no_type() }); + var pd = SyntaxTreeBuilder.BuildShortProcDefinition(fp, null, new method_name(id.name, sc), st, sc); + return pd; + } + + private int num1 = 0; + + public ident NewId(string prefix) + { + num1++; + return new ident(prefix + num1.ToString()); + } + } } diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index cd5513b4c..ac9289338 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.4.0.1682' +!define VERSION '3.4.0.1684' diff --git a/SyntaxTree/tree/HierarchyVisitor.cs b/SyntaxTree/tree/HierarchyVisitor.cs index 275d859ab..9717c401d 100644 --- a/SyntaxTree/tree/HierarchyVisitor.cs +++ b/SyntaxTree/tree/HierarchyVisitor.cs @@ -2545,6 +2545,7 @@ namespace PascalABCCompiler.SyntaxTree DefaultVisit(_write_accessor_name); pre_do_visit(_write_accessor_name); visit(write_accessor_name.accessor_name); + visit(write_accessor_name.pr); post_do_visit(_write_accessor_name); } @@ -2553,6 +2554,7 @@ namespace PascalABCCompiler.SyntaxTree DefaultVisit(_read_accessor_name); pre_do_visit(_read_accessor_name); visit(read_accessor_name.accessor_name); + visit(read_accessor_name.pr); post_do_visit(_read_accessor_name); } diff --git a/SyntaxTree/tree/NodesBuilder.cs b/SyntaxTree/tree/NodesBuilder.cs index da88f1b53..35bd56687 100644 --- a/SyntaxTree/tree/NodesBuilder.cs +++ b/SyntaxTree/tree/NodesBuilder.cs @@ -86,7 +86,7 @@ namespace PascalABCCompiler.SyntaxTree public static simple_property BuildSimpleReadWriteProperty(ident name, ident field, type_definition type) { - return new simple_property(name, type, new property_accessors(new read_accessor_name(field), new write_accessor_name(field))); + return new simple_property(name, type, new property_accessors(new read_accessor_name(field,null), new write_accessor_name(field, null))); } public static class_members BuildSimpleReadPropertiesSection(List names, List fields, List types) diff --git a/SyntaxTree/tree/SyntaxTreeStreamReader.cs b/SyntaxTree/tree/SyntaxTreeStreamReader.cs index 690efc42f..5c176c1aa 100644 --- a/SyntaxTree/tree/SyntaxTreeStreamReader.cs +++ b/SyntaxTree/tree/SyntaxTreeStreamReader.cs @@ -1650,6 +1650,7 @@ namespace PascalABCCompiler.SyntaxTree { read_syntax_tree_node(_write_accessor_name); _write_accessor_name.accessor_name = _read_node() as ident; + _write_accessor_name.pr = _read_node() as procedure_definition; } @@ -1662,6 +1663,7 @@ namespace PascalABCCompiler.SyntaxTree { read_syntax_tree_node(_read_accessor_name); _read_accessor_name.accessor_name = _read_node() as ident; + _read_accessor_name.pr = _read_node() as procedure_definition; } @@ -2057,6 +2059,7 @@ namespace PascalABCCompiler.SyntaxTree { read_statement(_procedure_call); _procedure_call.func_name = _read_node() as addressed_value; + _procedure_call.is_ident = br.ReadBoolean(); } diff --git a/SyntaxTree/tree/SyntaxTreeStreamWriter.cs b/SyntaxTree/tree/SyntaxTreeStreamWriter.cs index 4f3df5ea0..3f109fd23 100644 --- a/SyntaxTree/tree/SyntaxTreeStreamWriter.cs +++ b/SyntaxTree/tree/SyntaxTreeStreamWriter.cs @@ -2066,6 +2066,15 @@ namespace PascalABCCompiler.SyntaxTree bw.Write((byte)1); _write_accessor_name.accessor_name.visit(this); } + if (_write_accessor_name.pr == null) + { + bw.Write((byte)0); + } + else + { + bw.Write((byte)1); + _write_accessor_name.pr.visit(this); + } } @@ -2087,6 +2096,15 @@ namespace PascalABCCompiler.SyntaxTree bw.Write((byte)1); _read_accessor_name.accessor_name.visit(this); } + if (_read_accessor_name.pr == null) + { + bw.Write((byte)0); + } + else + { + bw.Write((byte)1); + _read_accessor_name.pr.visit(this); + } } @@ -2819,6 +2837,7 @@ namespace PascalABCCompiler.SyntaxTree bw.Write((byte)1); _procedure_call.func_name.visit(this); } + bw.Write(_procedure_call.is_ident); } diff --git a/SyntaxTree/tree/Tree.cs b/SyntaxTree/tree/Tree.cs index 411178fdf..9ae97dff9 100644 --- a/SyntaxTree/tree/Tree.cs +++ b/SyntaxTree/tree/Tree.cs @@ -13949,7 +13949,7 @@ namespace PascalABCCompiler.SyntaxTree FillParentsInDirectChilds(); } - protected List _ln; + protected List _ln=new List(); protected ident _class_name; protected ident _meth_name; protected ident _explicit_interface_name; @@ -15665,7 +15665,7 @@ namespace PascalABCCompiler.SyntaxTree /// - /// + ///procedure_definition pr != null если метод сгенерирован по выражению /// [Serializable] public partial class write_accessor_name : syntax_tree_node @@ -15682,22 +15682,25 @@ namespace PascalABCCompiler.SyntaxTree /// ///Конструктор с параметрами. /// - public write_accessor_name(ident _accessor_name) + public write_accessor_name(ident _accessor_name,procedure_definition _pr) { this._accessor_name=_accessor_name; + this._pr=_pr; FillParentsInDirectChilds(); } /// ///Конструктор с параметрами. /// - public write_accessor_name(ident _accessor_name,SourceContext sc) + public write_accessor_name(ident _accessor_name,procedure_definition _pr,SourceContext sc) { this._accessor_name=_accessor_name; + this._pr=_pr; source_context = sc; FillParentsInDirectChilds(); } protected ident _accessor_name; + protected procedure_definition _pr; /// /// @@ -15716,6 +15719,23 @@ namespace PascalABCCompiler.SyntaxTree } } + /// + /// + /// + public procedure_definition pr + { + get + { + return _pr; + } + set + { + _pr=value; + if (_pr != null) + _pr.Parent = this; + } + } + /// Создает копию узла public override syntax_tree_node Clone() @@ -15729,6 +15749,11 @@ namespace PascalABCCompiler.SyntaxTree copy.accessor_name = (ident)accessor_name.Clone(); copy.accessor_name.Parent = copy; } + if (pr != null) + { + copy.pr = (procedure_definition)pr.Clone(); + copy.pr.Parent = copy; + } return copy; } @@ -15743,6 +15768,8 @@ namespace PascalABCCompiler.SyntaxTree { if (accessor_name != null) accessor_name.Parent = this; + if (pr != null) + pr.Parent = this; } /// Заполняет поля Parent во всем поддереве @@ -15750,6 +15777,7 @@ namespace PascalABCCompiler.SyntaxTree { FillParentsInDirectChilds(); accessor_name?.FillParentsInAllChilds(); + pr?.FillParentsInAllChilds(); } /// @@ -15759,7 +15787,7 @@ namespace PascalABCCompiler.SyntaxTree { get { - return 1; + return 2; } } /// @@ -15769,7 +15797,7 @@ namespace PascalABCCompiler.SyntaxTree { get { - return 1; + return 2; } } /// @@ -15785,6 +15813,8 @@ namespace PascalABCCompiler.SyntaxTree { case 0: return accessor_name; + case 1: + return pr; } return null; } @@ -15797,6 +15827,9 @@ namespace PascalABCCompiler.SyntaxTree case 0: accessor_name = (ident)value; break; + case 1: + pr = (procedure_definition)value; + break; } } } @@ -15814,7 +15847,7 @@ namespace PascalABCCompiler.SyntaxTree /// - /// + ///procedure_definition pr != null если метод сгенерирован по выражению /// [Serializable] public partial class read_accessor_name : syntax_tree_node @@ -15831,22 +15864,25 @@ namespace PascalABCCompiler.SyntaxTree /// ///Конструктор с параметрами. /// - public read_accessor_name(ident _accessor_name) + public read_accessor_name(ident _accessor_name,procedure_definition _pr) { this._accessor_name=_accessor_name; + this._pr=_pr; FillParentsInDirectChilds(); } /// ///Конструктор с параметрами. /// - public read_accessor_name(ident _accessor_name,SourceContext sc) + public read_accessor_name(ident _accessor_name,procedure_definition _pr,SourceContext sc) { this._accessor_name=_accessor_name; + this._pr=_pr; source_context = sc; FillParentsInDirectChilds(); } protected ident _accessor_name; + protected procedure_definition _pr; /// /// @@ -15865,6 +15901,23 @@ namespace PascalABCCompiler.SyntaxTree } } + /// + /// + /// + public procedure_definition pr + { + get + { + return _pr; + } + set + { + _pr=value; + if (_pr != null) + _pr.Parent = this; + } + } + /// Создает копию узла public override syntax_tree_node Clone() @@ -15878,6 +15931,11 @@ namespace PascalABCCompiler.SyntaxTree copy.accessor_name = (ident)accessor_name.Clone(); copy.accessor_name.Parent = copy; } + if (pr != null) + { + copy.pr = (procedure_definition)pr.Clone(); + copy.pr.Parent = copy; + } return copy; } @@ -15892,6 +15950,8 @@ namespace PascalABCCompiler.SyntaxTree { if (accessor_name != null) accessor_name.Parent = this; + if (pr != null) + pr.Parent = this; } /// Заполняет поля Parent во всем поддереве @@ -15899,6 +15959,7 @@ namespace PascalABCCompiler.SyntaxTree { FillParentsInDirectChilds(); accessor_name?.FillParentsInAllChilds(); + pr?.FillParentsInAllChilds(); } /// @@ -15908,7 +15969,7 @@ namespace PascalABCCompiler.SyntaxTree { get { - return 1; + return 2; } } /// @@ -15918,7 +15979,7 @@ namespace PascalABCCompiler.SyntaxTree { get { - return 1; + return 2; } } /// @@ -15934,6 +15995,8 @@ namespace PascalABCCompiler.SyntaxTree { case 0: return accessor_name; + case 1: + return pr; } return null; } @@ -15946,6 +16009,9 @@ namespace PascalABCCompiler.SyntaxTree case 0: accessor_name = (ident)value; break; + case 1: + pr = (procedure_definition)value; + break; } } } @@ -21631,7 +21697,7 @@ namespace PascalABCCompiler.SyntaxTree /// - /// + ///bool is_ident; // является ли вызов процедуры идентификатором. Нужно исключительно для секции write свойств /// [Serializable] public partial class procedure_call : statement @@ -21648,22 +21714,25 @@ namespace PascalABCCompiler.SyntaxTree /// ///Конструктор с параметрами. /// - public procedure_call(addressed_value _func_name) + public procedure_call(addressed_value _func_name,bool _is_ident) { this._func_name=_func_name; + this._is_ident=_is_ident; FillParentsInDirectChilds(); } /// ///Конструктор с параметрами. /// - public procedure_call(addressed_value _func_name,SourceContext sc) + public procedure_call(addressed_value _func_name,bool _is_ident,SourceContext sc) { this._func_name=_func_name; + this._is_ident=_is_ident; source_context = sc; FillParentsInDirectChilds(); } protected addressed_value _func_name; + protected bool _is_ident; /// /// @@ -21682,6 +21751,21 @@ namespace PascalABCCompiler.SyntaxTree } } + /// + /// + /// + public bool is_ident + { + get + { + return _is_ident; + } + set + { + _is_ident=value; + } + } + /// Создает копию узла public override syntax_tree_node Clone() @@ -21700,6 +21784,7 @@ namespace PascalABCCompiler.SyntaxTree copy.func_name = (addressed_value)func_name.Clone(); copy.func_name.Parent = copy; } + copy.is_ident = is_ident; return copy; } diff --git a/SyntaxTree/tree/TreeHelper.cs b/SyntaxTree/tree/TreeHelper.cs index dff8e7c7d..130afdaf2 100644 --- a/SyntaxTree/tree/TreeHelper.cs +++ b/SyntaxTree/tree/TreeHelper.cs @@ -1063,7 +1063,7 @@ namespace PascalABCCompiler.SyntaxTree public partial class property_accessors { public property_accessors(ident read_accessor, ident write_accessor, SourceContext sc = null) - : this(new read_accessor_name(read_accessor), new write_accessor_name(write_accessor),sc) + : this(new read_accessor_name(read_accessor, null), new write_accessor_name(write_accessor, null),sc) { } } @@ -1134,6 +1134,8 @@ namespace PascalABCCompiler.SyntaxTree public partial class procedure_call { + public procedure_call(addressed_value _func_name, SourceContext sc=null) : this(_func_name, false, sc) { } + public procedure_call(ident name) { this._func_name = name; diff --git a/SyntaxTree/tree/tree.xml b/SyntaxTree/tree/tree.xml index e39fa0daf..d59196ab6 100644 --- a/SyntaxTree/tree/tree.xml +++ b/SyntaxTree/tree/tree.xml @@ -846,7 +846,7 @@ - + @@ -979,6 +979,7 @@ + @@ -989,6 +990,7 @@ + @@ -1327,6 +1329,7 @@ + @@ -4020,9 +4023,10 @@ - + + @@ -4117,8 +4121,9 @@ - + + @@ -4603,8 +4608,9 @@ - + +