fix #2164
This commit is contained in:
parent
938c0d27e3
commit
750654fd9f
|
|
@ -1,9 +1,9 @@
|
||||||
//
|
//
|
||||||
// This CSharp output file generated by Gardens Point LEX
|
// This CSharp output file generated by Gardens Point LEX
|
||||||
// Version: 1.1.3.301
|
// Version: 1.1.3.301
|
||||||
// Machine: DESKTOP-G8V08V4
|
// Machine: DESKTOP-P4NLNB1
|
||||||
// DateTime: 13.01.2020 1:44:39
|
// DateTime: 2/10/2020 2:41:45 PM
|
||||||
// UserName: ?????????
|
// UserName: fatco
|
||||||
// GPLEX input file <ABCPascal.lex>
|
// GPLEX input file <ABCPascal.lex>
|
||||||
// GPLEX frame file <embedded resource>
|
// GPLEX frame file <embedded resource>
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
// (see accompanying GPPGcopyright.rtf)
|
// (see accompanying GPPGcopyright.rtf)
|
||||||
|
|
||||||
// GPPG version 1.3.6
|
// GPPG version 1.3.6
|
||||||
// Machine: DESKTOP-G8V08V4
|
// Machine: DESKTOP-P4NLNB1
|
||||||
// DateTime: 13.01.2020 1:44:39
|
// DateTime: 2/10/2020 2:41:46 PM
|
||||||
// UserName: ?????????
|
// UserName: fatco
|
||||||
// Input file <ABCPascal.y>
|
// Input file <ABCPascal.y>
|
||||||
|
|
||||||
// options: no-lines gplex
|
// options: no-lines gplex
|
||||||
|
|
|
||||||
|
|
@ -124,14 +124,15 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
{
|
{
|
||||||
if (patternCase == null)
|
if (patternCase == null)
|
||||||
continue;
|
continue;
|
||||||
|
DefaultDesugarPattern(matchWith.expr, patternCase);
|
||||||
|
|
||||||
switch (patternCase.pattern)
|
/*switch (patternCase.pattern)
|
||||||
{
|
{
|
||||||
case deconstructor_pattern pattern:
|
case deconstructor_pattern pattern:
|
||||||
{
|
{
|
||||||
// Проверяем встречался ли уже такой тип при деконструкции
|
// Проверяем встречался ли уже такой тип при деконструкции
|
||||||
// SSM 02.01.19 пока закомментировал этот кусок т.к. при этом коде падает стандартный пример ArithmSimplify.cs. #1408 снова открыл
|
// SSM 02.01.19 пока закомментировал этот кусок т.к. при этом коде падает стандартный пример ArithmSimplify.cs. #1408 снова открыл
|
||||||
/*var deconstructionType = (patternCase.pattern as deconstructor_pattern).
|
var deconstructionType = (patternCase.pattern as deconstructor_pattern).
|
||||||
type as named_type_reference;
|
type as named_type_reference;
|
||||||
if (deconstructionType != null &&
|
if (deconstructionType != null &&
|
||||||
deconstructionType.names != null &&
|
deconstructionType.names != null &&
|
||||||
|
|
@ -144,14 +145,15 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
patternCase.pattern.source_context);
|
patternCase.pattern.source_context);
|
||||||
}
|
}
|
||||||
usedDeconstructionTypes.Add(deconstructionTypeName);
|
usedDeconstructionTypes.Add(deconstructionTypeName);
|
||||||
} */
|
}
|
||||||
|
|
||||||
DefaultDesugarPattern(matchWith.expr, patternCase);
|
DefaultDesugarPattern(matchWith.expr, patternCase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case const_pattern p:
|
case const_pattern p:
|
||||||
{
|
{
|
||||||
DesugarConstPatternCase(matchWith.expr, patternCase);
|
//DesugarConstPatternCase(matchWith.expr, patternCase);
|
||||||
|
DefaultDesugarPattern(matchWith.expr, patternCase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case collection_pattern p:
|
case collection_pattern p:
|
||||||
|
|
@ -164,7 +166,7 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
DefaultDesugarPattern(matchWith.expr, patternCase);
|
DefaultDesugarPattern(matchWith.expr, patternCase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchWith.defaultAction != null)
|
if (matchWith.defaultAction != null)
|
||||||
|
|
@ -692,6 +694,9 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
case tuple_pattern cp:
|
case tuple_pattern cp:
|
||||||
statementsToAdd = ProcessDesugaringForTuplePattern(isExpression);
|
statementsToAdd = ProcessDesugaringForTuplePattern(isExpression);
|
||||||
break;
|
break;
|
||||||
|
case const_pattern cp:
|
||||||
|
statementsToAdd = ProcessDesugaringForConstPattern(isExpression);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var enclosingIf = GetAscendant<if_node>(isExpression);
|
var enclosingIf = GetAscendant<if_node>(isExpression);
|
||||||
|
|
@ -712,6 +717,33 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<statement> ProcessDesugaringForConstPattern(is_pattern_expr isExpression)
|
||||||
|
{
|
||||||
|
var patternExpressionNode = isExpression.right as const_pattern;
|
||||||
|
|
||||||
|
var statementsToAdd = new List<statement>();
|
||||||
|
var equalCalls = new List<bin_expr>();
|
||||||
|
|
||||||
|
foreach (var patternExpression in patternExpressionNode.pattern_expressions.expressions)
|
||||||
|
{
|
||||||
|
statementsToAdd.Add(GetTypeCompatibilityCheck(isExpression.left, patternExpression));
|
||||||
|
|
||||||
|
equalCalls.Add(
|
||||||
|
new bin_expr(isExpression.left, patternExpression, Operators.Equal, isExpression.source_context
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
typeChecks.AddRange(statementsToAdd);
|
||||||
|
expression orPatternCases = equalCalls[0];
|
||||||
|
for (int i = 1; i < equalCalls.Count; ++i)
|
||||||
|
{
|
||||||
|
orPatternCases = bin_expr.LogicalOr(orPatternCases, equalCalls[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReplaceUsingParent(isExpression, orPatternCases);
|
||||||
|
return statementsToAdd;
|
||||||
|
}
|
||||||
|
|
||||||
private List<statement> ProcessDesugaringForDeconstructorPattern(is_pattern_expr isExpression)
|
private List<statement> ProcessDesugaringForDeconstructorPattern(is_pattern_expr isExpression)
|
||||||
{
|
{
|
||||||
var pattern = isExpression.right as deconstructor_pattern;
|
var pattern = isExpression.right as deconstructor_pattern;
|
||||||
|
|
|
||||||
14
TestSuite/patterns/patterns-nested-const-pattern.pas
Normal file
14
TestSuite/patterns/patterns-nested-const-pattern.pas
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
begin
|
||||||
|
var a := 3;
|
||||||
|
var b := 2;
|
||||||
|
match a with
|
||||||
|
1: assert(false);
|
||||||
|
2: assert(false);
|
||||||
|
3:
|
||||||
|
match b with
|
||||||
|
1: assert(false);
|
||||||
|
2: exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
assert(false);
|
||||||
|
end.
|
||||||
Loading…
Reference in a new issue