Refactor nodes
This commit is contained in:
parent
5aff52feeb
commit
17cb96a479
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -8,6 +8,8 @@ bin/*.dll
|
|||
bin/*.pdb
|
||||
bin/*.config
|
||||
bin/*.xml
|
||||
bin/log.txt
|
||||
bin/CompilerController.ini
|
||||
|
||||
TestSuite/CompilationSamples/*.pcu
|
||||
TestSuite/CompilationSamples/*.pdb
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// This CSharp output file generated by Gardens Point LEX
|
||||
// Version: 1.1.3.301
|
||||
// Machine: ALEXANDER-PC
|
||||
// DateTime: 01.05.2018 19:10:10
|
||||
// DateTime: 01.05.2018 19:45:44
|
||||
// UserName: Alexander
|
||||
// GPLEX input file <ABCPascal.lex>
|
||||
// GPLEX frame file <embedded resource>
|
||||
|
|
|
|||
4072
Parsers/PascalABCParserNewSaushkin/ABCPascal.lst
Normal file
4072
Parsers/PascalABCParserNewSaushkin/ABCPascal.lst
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -173,8 +173,8 @@
|
|||
%type <stn> full_lambda_fp_list lambda_simple_fp_sect lambda_function_body lambda_procedure_body optional_full_lambda_fp_list
|
||||
%type <ob> field_in_unnamed_object list_fields_in_unnamed_object func_class_name_ident_list rem_lambda variable_list var_ident_list
|
||||
%type <ti> tkAssignOrEqual
|
||||
%type <stn> pattern match_with pattern_case pattern_cases pattern_out_param_list pattern_out_param
|
||||
|
||||
%type <stn> pattern match_with pattern_case pattern_cases pattern_out_param
|
||||
%type <ob> pattern_out_param_list
|
||||
%%
|
||||
|
||||
parse_goal
|
||||
|
|
@ -2999,18 +2999,21 @@ relop_expr
|
|||
pattern
|
||||
: simple_or_template_type_reference tkRoundOpen pattern_out_param_list tkRoundClose
|
||||
{
|
||||
$$ = new deconstructor_pattern($3 as pattern_deconstructor_call_params, $1);
|
||||
$$ = new deconstructor_pattern($3 as List<pattern_deconstructor_parameter>, $1);
|
||||
}
|
||||
;
|
||||
|
||||
pattern_out_param_list
|
||||
: pattern_out_param
|
||||
{
|
||||
$$ = new pattern_deconstructor_call_params($1 as pattern_deconstructor_parameter);
|
||||
$$ = new List<pattern_deconstructor_parameter>();
|
||||
($$ as List<pattern_deconstructor_parameter>).Add($1 as pattern_deconstructor_parameter);
|
||||
}
|
||||
| pattern_out_param_list tkSemiColon pattern_out_param
|
||||
{
|
||||
$$ = ($1 as pattern_deconstructor_call_params).Add($3 as pattern_deconstructor_parameter);
|
||||
var list = $1 as List<pattern_deconstructor_parameter>;
|
||||
list.Add($3 as pattern_deconstructor_parameter);
|
||||
$$ = list;
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// GPPG version 1.3.6
|
||||
// Machine: ALEXANDER-PC
|
||||
// DateTime: 01.05.2018 19:10:11
|
||||
// DateTime: 01.05.2018 19:45:45
|
||||
// UserName: Alexander
|
||||
// Input file <ABCPascal.y>
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
|
|||
"lambda_procedure_body", "optional_full_lambda_fp_list", "field_in_unnamed_object",
|
||||
"list_fields_in_unnamed_object", "func_class_name_ident_list", "rem_lambda",
|
||||
"variable_list", "var_ident_list", "tkAssignOrEqual", "pattern", "match_with",
|
||||
"pattern_case", "pattern_cases", "pattern_out_param_list", "pattern_out_param",
|
||||
"pattern_case", "pattern_cases", "pattern_out_param", "pattern_out_param_list",
|
||||
"$accept", };
|
||||
|
||||
static GPPGParser() {
|
||||
|
|
@ -1000,10 +1000,10 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
|
|||
states[840] = new State(new int[]{133,287,135,23,78,25,79,26,73,28,71,223,40,295,37,713,8,714,17,373,18,378,136,146,138,147,137,149,146,151,148,152,147,153,52,738,83,113,35,707,21,743,89,755,49,730,30,765,50,775,94,781,42,788,31,791,48,799,55,812,70,817,68,823,33,828,84,-464,10,-464},new int[]{-241,841,-3,119,-98,120,-112,281,-97,288,-127,293,-132,24,-133,27,-173,294,-237,372,-274,377,-13,734,-146,143,-148,144,-147,148,-14,150,-52,735,-100,388,-193,736,-113,737,-235,740,-134,741,-30,742,-227,754,-293,763,-104,764,-294,774,-141,779,-279,780,-228,787,-103,790,-289,798,-53,808,-156,809,-155,810,-150,811,-106,816,-107,821,-105,822,-314,827});
|
||||
states[841] = new State(-509);
|
||||
states[842] = new State(new int[]{8,843});
|
||||
states[843] = new State(new int[]{48,848},new int[]{-317,844,-318,852});
|
||||
states[843] = new State(new int[]{48,848},new int[]{-318,844,-317,852});
|
||||
states[844] = new State(new int[]{9,845,10,846});
|
||||
states[845] = new State(-590);
|
||||
states[846] = new State(new int[]{48,848},new int[]{-318,847});
|
||||
states[846] = new State(new int[]{48,848},new int[]{-317,847});
|
||||
states[847] = new State(-592);
|
||||
states[848] = new State(new int[]{135,23,78,25,79,26,73,28,71,29},new int[]{-127,849,-132,24,-133,27});
|
||||
states[849] = new State(new int[]{5,850,9,-594,10,-594});
|
||||
|
|
@ -2161,11 +2161,11 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
|
|||
rules[587] = new Rule(-88, new int[]{-91});
|
||||
rules[588] = new Rule(-88, new int[]{-88,-178,-91});
|
||||
rules[589] = new Rule(-88, new int[]{-247,8,48,-127,9});
|
||||
rules[590] = new Rule(-313, new int[]{-263,8,-317,9});
|
||||
rules[591] = new Rule(-317, new int[]{-318});
|
||||
rules[592] = new Rule(-317, new int[]{-317,10,-318});
|
||||
rules[593] = new Rule(-318, new int[]{48,-127,5,-257});
|
||||
rules[594] = new Rule(-318, new int[]{48,-127});
|
||||
rules[590] = new Rule(-313, new int[]{-263,8,-318,9});
|
||||
rules[591] = new Rule(-318, new int[]{-317});
|
||||
rules[592] = new Rule(-318, new int[]{-318,10,-317});
|
||||
rules[593] = new Rule(-317, new int[]{48,-127,5,-257});
|
||||
rules[594] = new Rule(-317, new int[]{48,-127});
|
||||
rules[595] = new Rule(-99, new int[]{-91});
|
||||
rules[596] = new Rule(-99, new int[]{});
|
||||
rules[597] = new Rule(-102, new int[]{-91,5,-99});
|
||||
|
|
@ -5115,18 +5115,21 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
|
|||
case 590: // pattern -> simple_or_template_type_reference, tkRoundOpen,
|
||||
// pattern_out_param_list, tkRoundClose
|
||||
{
|
||||
CurrentSemanticValue.stn = new deconstructor_pattern(ValueStack[ValueStack.Depth-2].stn as pattern_deconstructor_call_params, ValueStack[ValueStack.Depth-4].td);
|
||||
CurrentSemanticValue.stn = new deconstructor_pattern(ValueStack[ValueStack.Depth-2].ob as List<pattern_deconstructor_parameter>, ValueStack[ValueStack.Depth-4].td);
|
||||
}
|
||||
break;
|
||||
case 591: // pattern_out_param_list -> pattern_out_param
|
||||
{
|
||||
CurrentSemanticValue.stn = new pattern_deconstructor_call_params(ValueStack[ValueStack.Depth-1].stn as pattern_deconstructor_parameter);
|
||||
CurrentSemanticValue.ob = new List<pattern_deconstructor_parameter>();
|
||||
(CurrentSemanticValue.ob as List<pattern_deconstructor_parameter>).Add(ValueStack[ValueStack.Depth-1].stn as pattern_deconstructor_parameter);
|
||||
}
|
||||
break;
|
||||
case 592: // pattern_out_param_list -> pattern_out_param_list, tkSemiColon,
|
||||
// pattern_out_param
|
||||
{
|
||||
CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as pattern_deconstructor_call_params).Add(ValueStack[ValueStack.Depth-1].stn as pattern_deconstructor_parameter);
|
||||
var list = ValueStack[ValueStack.Depth-3].ob as List<pattern_deconstructor_parameter>;
|
||||
list.Add(ValueStack[ValueStack.Depth-1].stn as pattern_deconstructor_parameter);
|
||||
CurrentSemanticValue.ob = list;
|
||||
}
|
||||
break;
|
||||
case 593: // pattern_out_param -> tkVar, identifier, tkColon, type_ref
|
||||
|
|
|
|||
3
Patterns/.gitignore
vendored
Normal file
3
Patterns/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Ignore PascalABC.NET compiler output
|
||||
*.pdb
|
||||
*.exe
|
||||
39
Patterns/All-examples.pas
Normal file
39
Patterns/All-examples.pas
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Switch-statement
|
||||
|
||||
begin
|
||||
var a := new List<integer>(arr(1, 2));
|
||||
match a with
|
||||
integer(var c) when c = 3: write(1);
|
||||
string(var s) when not string.IsNullOrEmpty(s): write(2);
|
||||
List<integer>(var l) when l.Count > 0: write(3)
|
||||
end;
|
||||
end.
|
||||
|
||||
// User defined
|
||||
|
||||
type
|
||||
Person = class
|
||||
name: string;
|
||||
age: integer;
|
||||
|
||||
function Deconstruct(p: Person; name: string; age: integer): boolean;
|
||||
begin
|
||||
name := p.name;
|
||||
age := p.age;
|
||||
result := true;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
var p := new Person;
|
||||
if p is Person(var name, var age) then
|
||||
Print(name, ' ', age);
|
||||
end.
|
||||
|
||||
// Recursive patterns
|
||||
|
||||
begin
|
||||
if (tree is BinOp(IntConst(var ln), IntConst(var rn))) then
|
||||
tree = new IntConst(ln + rn);
|
||||
end.
|
||||
|
|
@ -1148,11 +1148,6 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
DefaultVisit(_pattern_cases);
|
||||
}
|
||||
|
||||
public virtual void visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
DefaultVisit(_pattern_deconstructor_call_params);
|
||||
}
|
||||
|
||||
public virtual void visit(deconstructor_pattern _deconstructor_pattern)
|
||||
{
|
||||
DefaultVisit(_deconstructor_pattern);
|
||||
|
|
|
|||
|
|
@ -1829,14 +1829,6 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
{
|
||||
}
|
||||
|
||||
public virtual void pre_do_visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void post_do_visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void pre_do_visit(deconstructor_pattern _deconstructor_pattern)
|
||||
{
|
||||
}
|
||||
|
|
@ -3809,20 +3801,12 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
post_do_visit(_pattern_cases);
|
||||
}
|
||||
|
||||
public override void visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
DefaultVisit(_pattern_deconstructor_call_params);
|
||||
pre_do_visit(_pattern_deconstructor_call_params);
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
visit(pattern_deconstructor_call_params.parameters[i]);
|
||||
post_do_visit(_pattern_deconstructor_call_params);
|
||||
}
|
||||
|
||||
public override void visit(deconstructor_pattern _deconstructor_pattern)
|
||||
{
|
||||
DefaultVisit(_deconstructor_pattern);
|
||||
pre_do_visit(_deconstructor_pattern);
|
||||
visit(deconstructor_pattern.parameters);
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
visit(deconstructor_pattern.parameters[i]);
|
||||
visit(deconstructor_pattern.type);
|
||||
post_do_visit(_deconstructor_pattern);
|
||||
}
|
||||
|
|
@ -3831,7 +3815,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
{
|
||||
DefaultVisit(_pattern_deconstructor_parameter);
|
||||
pre_do_visit(_pattern_deconstructor_parameter);
|
||||
visit(pattern_deconstructor_parameter.name);
|
||||
visit(pattern_deconstructor_parameter.identifier);
|
||||
visit(pattern_deconstructor_parameter.type);
|
||||
post_do_visit(_pattern_deconstructor_parameter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -477,10 +477,8 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
case 227:
|
||||
return new pattern_cases();
|
||||
case 228:
|
||||
return new pattern_deconstructor_call_params();
|
||||
case 229:
|
||||
return new deconstructor_pattern();
|
||||
case 230:
|
||||
case 229:
|
||||
return new pattern_deconstructor_parameter();
|
||||
}
|
||||
return null;
|
||||
|
|
@ -4027,30 +4025,6 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
}
|
||||
|
||||
|
||||
public void visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
read_pattern_deconstructor_call_params(_pattern_deconstructor_call_params);
|
||||
}
|
||||
|
||||
public void read_pattern_deconstructor_call_params(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
read_syntax_tree_node(_pattern_deconstructor_call_params);
|
||||
if (br.ReadByte() == 0)
|
||||
{
|
||||
_pattern_deconstructor_call_params.parameters = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pattern_deconstructor_call_params.parameters = new List<pattern_deconstructor_parameter>();
|
||||
Int32 ssyy_count = br.ReadInt32();
|
||||
for(Int32 ssyy_i = 0; ssyy_i < ssyy_count; ssyy_i++)
|
||||
{
|
||||
_pattern_deconstructor_call_params.parameters.Add(_read_node() as pattern_deconstructor_parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void visit(deconstructor_pattern _deconstructor_pattern)
|
||||
{
|
||||
read_deconstructor_pattern(_deconstructor_pattern);
|
||||
|
|
@ -4059,7 +4033,19 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
public void read_deconstructor_pattern(deconstructor_pattern _deconstructor_pattern)
|
||||
{
|
||||
read_pattern_node(_deconstructor_pattern);
|
||||
_deconstructor_pattern.parameters = _read_node() as pattern_deconstructor_call_params;
|
||||
if (br.ReadByte() == 0)
|
||||
{
|
||||
_deconstructor_pattern.parameters = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_deconstructor_pattern.parameters = new List<pattern_deconstructor_parameter>();
|
||||
Int32 ssyy_count = br.ReadInt32();
|
||||
for(Int32 ssyy_i = 0; ssyy_i < ssyy_count; ssyy_i++)
|
||||
{
|
||||
_deconstructor_pattern.parameters.Add(_read_node() as pattern_deconstructor_parameter);
|
||||
}
|
||||
}
|
||||
_deconstructor_pattern.type = _read_node() as type_definition;
|
||||
}
|
||||
|
||||
|
|
@ -4072,7 +4058,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
public void read_pattern_deconstructor_parameter(pattern_deconstructor_parameter _pattern_deconstructor_parameter)
|
||||
{
|
||||
read_syntax_tree_node(_pattern_deconstructor_parameter);
|
||||
_pattern_deconstructor_parameter.name = _read_node() as ident;
|
||||
_pattern_deconstructor_parameter.identifier = _read_node() as ident;
|
||||
_pattern_deconstructor_parameter.type = _read_node() as type_definition;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6314,42 +6314,9 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
}
|
||||
|
||||
|
||||
public void visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
bw.Write((Int16)228);
|
||||
write_pattern_deconstructor_call_params(_pattern_deconstructor_call_params);
|
||||
}
|
||||
|
||||
public void write_pattern_deconstructor_call_params(pattern_deconstructor_call_params _pattern_deconstructor_call_params)
|
||||
{
|
||||
write_syntax_tree_node(_pattern_deconstructor_call_params);
|
||||
if (_pattern_deconstructor_call_params.parameters == null)
|
||||
{
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write((byte)1);
|
||||
bw.Write(_pattern_deconstructor_call_params.parameters.Count);
|
||||
for(Int32 ssyy_i = 0; ssyy_i < _pattern_deconstructor_call_params.parameters.Count; ssyy_i++)
|
||||
{
|
||||
if (_pattern_deconstructor_call_params.parameters[ssyy_i] == null)
|
||||
{
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write((byte)1);
|
||||
_pattern_deconstructor_call_params.parameters[ssyy_i].visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void visit(deconstructor_pattern _deconstructor_pattern)
|
||||
{
|
||||
bw.Write((Int16)229);
|
||||
bw.Write((Int16)228);
|
||||
write_deconstructor_pattern(_deconstructor_pattern);
|
||||
}
|
||||
|
||||
|
|
@ -6363,7 +6330,19 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
else
|
||||
{
|
||||
bw.Write((byte)1);
|
||||
_deconstructor_pattern.parameters.visit(this);
|
||||
bw.Write(_deconstructor_pattern.parameters.Count);
|
||||
for(Int32 ssyy_i = 0; ssyy_i < _deconstructor_pattern.parameters.Count; ssyy_i++)
|
||||
{
|
||||
if (_deconstructor_pattern.parameters[ssyy_i] == null)
|
||||
{
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write((byte)1);
|
||||
_deconstructor_pattern.parameters[ssyy_i].visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_deconstructor_pattern.type == null)
|
||||
{
|
||||
|
|
@ -6379,21 +6358,21 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
|
||||
public void visit(pattern_deconstructor_parameter _pattern_deconstructor_parameter)
|
||||
{
|
||||
bw.Write((Int16)230);
|
||||
bw.Write((Int16)229);
|
||||
write_pattern_deconstructor_parameter(_pattern_deconstructor_parameter);
|
||||
}
|
||||
|
||||
public void write_pattern_deconstructor_parameter(pattern_deconstructor_parameter _pattern_deconstructor_parameter)
|
||||
{
|
||||
write_syntax_tree_node(_pattern_deconstructor_parameter);
|
||||
if (_pattern_deconstructor_parameter.name == null)
|
||||
if (_pattern_deconstructor_parameter.identifier == null)
|
||||
{
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write((byte)1);
|
||||
_pattern_deconstructor_parameter.name.visit(this);
|
||||
_pattern_deconstructor_parameter.identifier.visit(this);
|
||||
}
|
||||
if (_pattern_deconstructor_parameter.type == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48598,13 +48598,13 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
///
|
||||
///</summary>
|
||||
[Serializable]
|
||||
public partial class pattern_deconstructor_call_params : syntax_tree_node
|
||||
public partial class deconstructor_pattern : pattern_node
|
||||
{
|
||||
|
||||
///<summary>
|
||||
///Конструктор без параметров.
|
||||
///</summary>
|
||||
public pattern_deconstructor_call_params()
|
||||
public deconstructor_pattern()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -48612,31 +48612,34 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
///<summary>
|
||||
///Конструктор с параметрами.
|
||||
///</summary>
|
||||
public pattern_deconstructor_call_params(List<pattern_deconstructor_parameter> _parameters)
|
||||
public deconstructor_pattern(List<pattern_deconstructor_parameter> _parameters,type_definition _type)
|
||||
{
|
||||
this._parameters=_parameters;
|
||||
this._type=_type;
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Конструктор с параметрами.
|
||||
///</summary>
|
||||
public pattern_deconstructor_call_params(List<pattern_deconstructor_parameter> _parameters,SourceContext sc)
|
||||
public deconstructor_pattern(List<pattern_deconstructor_parameter> _parameters,type_definition _type,SourceContext sc)
|
||||
{
|
||||
this._parameters=_parameters;
|
||||
this._type=_type;
|
||||
source_context = sc;
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
public pattern_deconstructor_call_params(pattern_deconstructor_parameter elem, SourceContext sc = null)
|
||||
public deconstructor_pattern(pattern_deconstructor_parameter elem, SourceContext sc = null)
|
||||
{
|
||||
Add(elem, sc);
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
|
||||
protected List<pattern_deconstructor_parameter> _parameters=new List<pattern_deconstructor_parameter>();
|
||||
protected type_definition _type;
|
||||
|
||||
///<summary>
|
||||
///
|
||||
///Результат деконструирования
|
||||
///</summary>
|
||||
public List<pattern_deconstructor_parameter> parameters
|
||||
{
|
||||
|
|
@ -48650,8 +48653,23 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
}
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Деконструируемый тип
|
||||
///</summary>
|
||||
public type_definition type
|
||||
{
|
||||
get
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
set
|
||||
{
|
||||
_type=value;
|
||||
}
|
||||
}
|
||||
|
||||
public pattern_deconstructor_call_params Add(pattern_deconstructor_parameter elem, SourceContext sc = null)
|
||||
|
||||
public deconstructor_pattern Add(pattern_deconstructor_parameter elem, SourceContext sc = null)
|
||||
{
|
||||
parameters.Add(elem);
|
||||
if (elem != null)
|
||||
|
|
@ -48802,7 +48820,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
/// <summary> Создает копию узла </summary>
|
||||
public override syntax_tree_node Clone()
|
||||
{
|
||||
pattern_deconstructor_call_params copy = new pattern_deconstructor_call_params();
|
||||
deconstructor_pattern copy = new deconstructor_pattern();
|
||||
copy.Parent = this.Parent;
|
||||
if (source_context != null)
|
||||
copy.source_context = new SourceContext(source_context);
|
||||
|
|
@ -48819,185 +48837,6 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
copy.Add(null);
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary> Получает копию данного узла корректного типа </summary>
|
||||
public new pattern_deconstructor_call_params TypedClone()
|
||||
{
|
||||
return Clone() as pattern_deconstructor_call_params;
|
||||
}
|
||||
|
||||
///<summary> Заполняет поля Parent в непосредственных дочерних узлах </summary>
|
||||
public override void FillParentsInDirectChilds()
|
||||
{
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var child in parameters)
|
||||
if (child != null)
|
||||
child.Parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Заполняет поля Parent во всем поддереве </summary>
|
||||
public override void FillParentsInAllChilds()
|
||||
{
|
||||
FillParentsInDirectChilds();
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var child in parameters)
|
||||
child?.FillParentsInAllChilds();
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Свойство для получения количества всех подузлов без элементов поля типа List
|
||||
///</summary>
|
||||
public override Int32 subnodes_without_list_elements_count
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
///<summary>
|
||||
///Свойство для получения количества всех подузлов. Подузлом также считается каждый элемент поля типа List
|
||||
///</summary>
|
||||
public override Int32 subnodes_count
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0 + (parameters == null ? 0 : parameters.Count);
|
||||
}
|
||||
}
|
||||
///<summary>
|
||||
///Индексатор для получения всех подузлов
|
||||
///</summary>
|
||||
public override syntax_tree_node this[Int32 ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if(subnodes_count == 0 || ind < 0 || ind > subnodes_count-1)
|
||||
throw new IndexOutOfRangeException();
|
||||
Int32 index_counter=ind - 0;
|
||||
if(parameters != null)
|
||||
{
|
||||
if(index_counter < parameters.Count)
|
||||
{
|
||||
return parameters[index_counter];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(subnodes_count == 0 || ind < 0 || ind > subnodes_count-1)
|
||||
throw new IndexOutOfRangeException();
|
||||
Int32 index_counter=ind - 0;
|
||||
if(parameters != null)
|
||||
{
|
||||
if(index_counter < parameters.Count)
|
||||
{
|
||||
parameters[index_counter]= (pattern_deconstructor_parameter)value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
///<summary>
|
||||
///Метод для обхода дерева посетителем
|
||||
///</summary>
|
||||
///<param name="visitor">Объект-посетитель.</param>
|
||||
///<returns>Return value is void</returns>
|
||||
public override void visit(IVisitor visitor)
|
||||
{
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///<summary>
|
||||
///
|
||||
///</summary>
|
||||
[Serializable]
|
||||
public partial class deconstructor_pattern : pattern_node
|
||||
{
|
||||
|
||||
///<summary>
|
||||
///Конструктор без параметров.
|
||||
///</summary>
|
||||
public deconstructor_pattern()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Конструктор с параметрами.
|
||||
///</summary>
|
||||
public deconstructor_pattern(pattern_deconstructor_call_params _parameters,type_definition _type)
|
||||
{
|
||||
this._parameters=_parameters;
|
||||
this._type=_type;
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Конструктор с параметрами.
|
||||
///</summary>
|
||||
public deconstructor_pattern(pattern_deconstructor_call_params _parameters,type_definition _type,SourceContext sc)
|
||||
{
|
||||
this._parameters=_parameters;
|
||||
this._type=_type;
|
||||
source_context = sc;
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
protected pattern_deconstructor_call_params _parameters;
|
||||
protected type_definition _type;
|
||||
|
||||
///<summary>
|
||||
///Результат деконструирования
|
||||
///</summary>
|
||||
public pattern_deconstructor_call_params parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
return _parameters;
|
||||
}
|
||||
set
|
||||
{
|
||||
_parameters=value;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Деконструируемый тип
|
||||
///</summary>
|
||||
public type_definition type
|
||||
{
|
||||
get
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
set
|
||||
{
|
||||
_type=value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Создает копию узла </summary>
|
||||
public override syntax_tree_node Clone()
|
||||
{
|
||||
deconstructor_pattern copy = new deconstructor_pattern();
|
||||
copy.Parent = this.Parent;
|
||||
if (source_context != null)
|
||||
copy.source_context = new SourceContext(source_context);
|
||||
if (parameters != null)
|
||||
{
|
||||
copy.parameters = (pattern_deconstructor_call_params)parameters.Clone();
|
||||
copy.parameters.Parent = copy;
|
||||
}
|
||||
if (type != null)
|
||||
{
|
||||
copy.type = (type_definition)type.Clone();
|
||||
|
|
@ -49016,7 +48855,11 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
public override void FillParentsInDirectChilds()
|
||||
{
|
||||
if (parameters != null)
|
||||
parameters.Parent = this;
|
||||
{
|
||||
foreach (var child in parameters)
|
||||
if (child != null)
|
||||
child.Parent = this;
|
||||
}
|
||||
if (type != null)
|
||||
type.Parent = this;
|
||||
}
|
||||
|
|
@ -49025,7 +48868,11 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
public override void FillParentsInAllChilds()
|
||||
{
|
||||
FillParentsInDirectChilds();
|
||||
parameters?.FillParentsInAllChilds();
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var child in parameters)
|
||||
child?.FillParentsInAllChilds();
|
||||
}
|
||||
type?.FillParentsInAllChilds();
|
||||
}
|
||||
|
||||
|
|
@ -49036,7 +48883,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
{
|
||||
get
|
||||
{
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
///<summary>
|
||||
|
|
@ -49046,7 +48893,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
{
|
||||
get
|
||||
{
|
||||
return 2;
|
||||
return 1 + (parameters == null ? 0 : parameters.Count);
|
||||
}
|
||||
}
|
||||
///<summary>
|
||||
|
|
@ -49061,10 +48908,16 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
switch(ind)
|
||||
{
|
||||
case 0:
|
||||
return parameters;
|
||||
case 1:
|
||||
return type;
|
||||
}
|
||||
Int32 index_counter=ind - 1;
|
||||
if(parameters != null)
|
||||
{
|
||||
if(index_counter < parameters.Count)
|
||||
{
|
||||
return parameters[index_counter];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
|
|
@ -49074,12 +48927,18 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
switch(ind)
|
||||
{
|
||||
case 0:
|
||||
parameters = (pattern_deconstructor_call_params)value;
|
||||
break;
|
||||
case 1:
|
||||
type = (type_definition)value;
|
||||
break;
|
||||
}
|
||||
Int32 index_counter=ind - 1;
|
||||
if(parameters != null)
|
||||
{
|
||||
if(index_counter < parameters.Count)
|
||||
{
|
||||
parameters[index_counter]= (pattern_deconstructor_parameter)value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
///<summary>
|
||||
|
|
@ -49113,9 +48972,9 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
///<summary>
|
||||
///Конструктор с параметрами.
|
||||
///</summary>
|
||||
public pattern_deconstructor_parameter(ident _name,type_definition _type)
|
||||
public pattern_deconstructor_parameter(ident _identifier,type_definition _type)
|
||||
{
|
||||
this._name=_name;
|
||||
this._identifier=_identifier;
|
||||
this._type=_type;
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
|
|
@ -49123,28 +48982,28 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
///<summary>
|
||||
///Конструктор с параметрами.
|
||||
///</summary>
|
||||
public pattern_deconstructor_parameter(ident _name,type_definition _type,SourceContext sc)
|
||||
public pattern_deconstructor_parameter(ident _identifier,type_definition _type,SourceContext sc)
|
||||
{
|
||||
this._name=_name;
|
||||
this._identifier=_identifier;
|
||||
this._type=_type;
|
||||
source_context = sc;
|
||||
FillParentsInDirectChilds();
|
||||
}
|
||||
protected ident _name;
|
||||
protected ident _identifier;
|
||||
protected type_definition _type;
|
||||
|
||||
///<summary>
|
||||
///
|
||||
///</summary>
|
||||
public ident name
|
||||
public ident identifier
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
return _identifier;
|
||||
}
|
||||
set
|
||||
{
|
||||
_name=value;
|
||||
_identifier=value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49171,10 +49030,10 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
copy.Parent = this.Parent;
|
||||
if (source_context != null)
|
||||
copy.source_context = new SourceContext(source_context);
|
||||
if (name != null)
|
||||
if (identifier != null)
|
||||
{
|
||||
copy.name = (ident)name.Clone();
|
||||
copy.name.Parent = copy;
|
||||
copy.identifier = (ident)identifier.Clone();
|
||||
copy.identifier.Parent = copy;
|
||||
}
|
||||
if (type != null)
|
||||
{
|
||||
|
|
@ -49193,8 +49052,8 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
///<summary> Заполняет поля Parent в непосредственных дочерних узлах </summary>
|
||||
public override void FillParentsInDirectChilds()
|
||||
{
|
||||
if (name != null)
|
||||
name.Parent = this;
|
||||
if (identifier != null)
|
||||
identifier.Parent = this;
|
||||
if (type != null)
|
||||
type.Parent = this;
|
||||
}
|
||||
|
|
@ -49203,7 +49062,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
public override void FillParentsInAllChilds()
|
||||
{
|
||||
FillParentsInDirectChilds();
|
||||
name?.FillParentsInAllChilds();
|
||||
identifier?.FillParentsInAllChilds();
|
||||
type?.FillParentsInAllChilds();
|
||||
}
|
||||
|
||||
|
|
@ -49239,7 +49098,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
switch(ind)
|
||||
{
|
||||
case 0:
|
||||
return name;
|
||||
return identifier;
|
||||
case 1:
|
||||
return type;
|
||||
}
|
||||
|
|
@ -49252,7 +49111,7 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
switch(ind)
|
||||
{
|
||||
case 0:
|
||||
name = (ident)value;
|
||||
identifier = (ident)value;
|
||||
break;
|
||||
case 1:
|
||||
type = (type_definition)value;
|
||||
|
|
|
|||
|
|
@ -1373,12 +1373,6 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
///<returns> Return value is void </returns>
|
||||
void visit(pattern_cases _pattern_cases);
|
||||
///<summary>
|
||||
///Method to visit pattern_deconstructor_call_params.
|
||||
///</summary>
|
||||
///<param name="_pattern_deconstructor_call_params">Node to visit</param>
|
||||
///<returns> Return value is void </returns>
|
||||
void visit(pattern_deconstructor_call_params _pattern_deconstructor_call_params);
|
||||
///<summary>
|
||||
///Method to visit deconstructor_pattern.
|
||||
///</summary>
|
||||
///<param name="_deconstructor_pattern">Node to visit</param>
|
||||
|
|
|
|||
|
|
@ -2918,19 +2918,9 @@
|
|||
<TagIndices />
|
||||
</Tags>
|
||||
</SyntaxNode>
|
||||
<SyntaxNode Name="pattern_deconstructor_call_params" BaseName="syntax_tree_node">
|
||||
<Fields>
|
||||
<ExtendedField Name="parameters" Type="List<pattern_deconstructor_parameter>" CreateVariable="true" DeleteVariable="false" />
|
||||
</Fields>
|
||||
<Methods />
|
||||
<Tags>
|
||||
<CategoryIndices />
|
||||
<TagIndices />
|
||||
</Tags>
|
||||
</SyntaxNode>
|
||||
<SyntaxNode Name="deconstructor_pattern" BaseName="pattern_node">
|
||||
<Fields>
|
||||
<SyntaxField Name="parameters" SyntaxType="pattern_deconstructor_call_params" />
|
||||
<ExtendedField Name="parameters" Type="List<pattern_deconstructor_parameter>" CreateVariable="true" DeleteVariable="false" />
|
||||
<SyntaxField Name="type" SyntaxType="type_definition" />
|
||||
</Fields>
|
||||
<Methods />
|
||||
|
|
@ -2941,7 +2931,7 @@
|
|||
</SyntaxNode>
|
||||
<SyntaxNode Name="pattern_deconstructor_parameter" BaseName="syntax_tree_node">
|
||||
<Fields>
|
||||
<SyntaxField Name="name" SyntaxType="ident" />
|
||||
<SyntaxField Name="identifier" SyntaxType="ident" />
|
||||
<SyntaxField Name="type" SyntaxType="type_definition" />
|
||||
</Fields>
|
||||
<Methods />
|
||||
|
|
@ -3803,6 +3793,7 @@
|
|||
<HelpData Key="pattern_deconstructor_call_params" Value="" />
|
||||
<HelpData Key="pattern_deconstructor_call_params.parameters" Value="" />
|
||||
<HelpData Key="pattern_deconstructor_parameter" Value="" />
|
||||
<HelpData Key="pattern_deconstructor_parameter.identifier" Value="" />
|
||||
<HelpData Key="pattern_deconstructor_parameter.name" Value="" />
|
||||
<HelpData Key="pattern_deconstructor_parameter.type" Value="" />
|
||||
<HelpData Key="pattern_node" Value="" />
|
||||
|
|
|
|||
|
|
@ -94,13 +94,13 @@ namespace SyntaxVisitors.SugarVisitors
|
|||
// Если есть секция when - добавляем ее в условие
|
||||
{
|
||||
// Переименовываем идентификатор, т.к. мы сгенерировали внутреннее имя
|
||||
patternCase.condition.RenameIdentifierInDescendants(pattern.parameters.parameters[0].name.name, matchResultVariableName.name);
|
||||
patternCase.condition.RenameIdentifierInDescendants(pattern.parameters[0].identifier.name, matchResultVariableName.name);
|
||||
matchCondition = new bin_expr(isTest, patternCase.condition, Operators.LogicalAND);
|
||||
}
|
||||
|
||||
// Создание узла if с объявлением переменной из паттерна и присвоение ей значения
|
||||
// сгенерированной переменной
|
||||
var patternVarDef = new var_statement(pattern.parameters.parameters[0].name.name, matchResultVariableName);
|
||||
var patternVarDef = new var_statement(pattern.parameters[0].identifier.name, matchResultVariableName);
|
||||
// Создание тела if из объявления переменной и соттветствующего тела case
|
||||
var ifCheck = SubtreeCreator.CreateIf(matchCondition, new statement_list(patternVarDef, patternCase.case_action));
|
||||
result.Add(ifCheck);
|
||||
|
|
|
|||
Loading…
Reference in a new issue