if_expr_new узел для форматирования

This commit is contained in:
Mikhalkovich Stanislav 2020-01-06 20:02:07 +03:00
parent 9aa197df1d
commit a0fda1e045
11 changed files with 349 additions and 8 deletions

View file

@ -2,7 +2,7 @@
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: DESKTOP-G8V08V4
// DateTime: 06.01.2020 1:08:55
// DateTime: 06.01.2020 19:58:31
// UserName: ?????????
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>

View file

@ -3166,9 +3166,16 @@ question_expr
}
| tkIf expr_dq tkThen expr_l1 tkElse expr_l1
{
if ($4 is nil_const && $6 is nil_const)
parsertools.AddErrorFromResource("TWO_NILS_IN_QUESTION_EXPR",@4);
$$ = new question_colon_expression($2, $4, $6, @$);
if (parsertools.build_tree_for_formatter)
{
$$ = new if_expr_new($2, $4, $6, @$);
}
else
{
if ($4 is nil_const && $6 is nil_const)
parsertools.AddErrorFromResource("TWO_NILS_IN_QUESTION_EXPR",@4);
$$ = new question_colon_expression($2, $4, $6, @$);
}
}
;

View file

@ -2,7 +2,7 @@
// GPPG version 1.3.6
// Machine: DESKTOP-G8V08V4
// DateTime: 06.01.2020 1:08:55
// DateTime: 06.01.2020 19:58:32
// UserName: ?????????
// Input file <ABCPascal.y>
@ -5491,9 +5491,16 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
break;
case 591: // question_expr -> tkIf, expr_dq, tkThen, expr_l1, tkElse, expr_l1
{
if (ValueStack[ValueStack.Depth-3].ex is nil_const && ValueStack[ValueStack.Depth-1].ex is nil_const)
parsertools.AddErrorFromResource("TWO_NILS_IN_QUESTION_EXPR",LocationStack[LocationStack.Depth-3]);
CurrentSemanticValue.ex = new question_colon_expression(ValueStack[ValueStack.Depth-5].ex, ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan);
if (parsertools.build_tree_for_formatter)
{
CurrentSemanticValue.ex = new if_expr_new(ValueStack[ValueStack.Depth-5].ex, ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan);
}
else
{
if (ValueStack[ValueStack.Depth-3].ex is nil_const && ValueStack[ValueStack.Depth-1].ex is nil_const)
parsertools.AddErrorFromResource("TWO_NILS_IN_QUESTION_EXPR",LocationStack[LocationStack.Depth-3]);
CurrentSemanticValue.ex = new question_colon_expression(ValueStack[ValueStack.Depth-5].ex, ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan);
}
}
break;
case 592: // empty_template_type_reference -> simple_type_identifier,

View file

@ -256,5 +256,6 @@ script=

View file

@ -1257,6 +1257,11 @@ namespace PascalABCCompiler.SyntaxTree
{
DefaultVisit(_diapason_expr_new);
}
public virtual void visit(if_expr_new _if_expr_new)
{
DefaultVisit(_if_expr_new);
}
}

View file

@ -2005,6 +2005,14 @@ namespace PascalABCCompiler.SyntaxTree
{
}
public virtual void pre_do_visit(if_expr_new _if_expr_new)
{
}
public virtual void post_do_visit(if_expr_new _if_expr_new)
{
}
public override void visit(expression _expression)
{
DefaultVisit(_expression);
@ -4140,6 +4148,16 @@ namespace PascalABCCompiler.SyntaxTree
visit(diapason_expr_new.right);
post_do_visit(_diapason_expr_new);
}
public override void visit(if_expr_new _if_expr_new)
{
DefaultVisit(_if_expr_new);
pre_do_visit(_if_expr_new);
visit(if_expr_new.condition);
visit(if_expr_new.if_true);
visit(if_expr_new.if_false);
post_do_visit(_if_expr_new);
}
}

View file

@ -520,6 +520,8 @@ namespace PascalABCCompiler.SyntaxTree
return new recursive_tuple_parameter();
case 249:
return new diapason_expr_new();
case 250:
return new if_expr_new();
}
return null;
}
@ -4370,6 +4372,20 @@ namespace PascalABCCompiler.SyntaxTree
_diapason_expr_new.right = _read_node() as expression;
}
public void visit(if_expr_new _if_expr_new)
{
read_if_expr_new(_if_expr_new);
}
public void read_if_expr_new(if_expr_new _if_expr_new)
{
read_expression(_if_expr_new);
_if_expr_new.condition = _read_node() as expression;
_if_expr_new.if_true = _read_node() as expression;
_if_expr_new.if_false = _read_node() as expression;
}
}

View file

@ -6825,6 +6825,45 @@ namespace PascalABCCompiler.SyntaxTree
}
}
public void visit(if_expr_new _if_expr_new)
{
bw.Write((Int16)250);
write_if_expr_new(_if_expr_new);
}
public void write_if_expr_new(if_expr_new _if_expr_new)
{
write_expression(_if_expr_new);
if (_if_expr_new.condition == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_if_expr_new.condition.visit(this);
}
if (_if_expr_new.if_true == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_if_expr_new.if_true.visit(this);
}
if (_if_expr_new.if_false == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_if_expr_new.if_false.visit(this);
}
}
}

View file

@ -53458,6 +53458,229 @@ namespace PascalABCCompiler.SyntaxTree
}
///<summary>
///Новое условное выражение в стиле Паскаля. Доступно только при форматировании
///</summary>
[Serializable]
public partial class if_expr_new : expression
{
///<summary>
///Конструктор без параметров.
///</summary>
public if_expr_new()
{
}
///<summary>
///Конструктор с параметрами.
///</summary>
public if_expr_new(expression _condition,expression _if_true,expression _if_false)
{
this._condition=_condition;
this._if_true=_if_true;
this._if_false=_if_false;
FillParentsInDirectChilds();
}
///<summary>
///Конструктор с параметрами.
///</summary>
public if_expr_new(expression _condition,expression _if_true,expression _if_false,SourceContext sc)
{
this._condition=_condition;
this._if_true=_if_true;
this._if_false=_if_false;
source_context = sc;
FillParentsInDirectChilds();
}
protected expression _condition;
protected expression _if_true;
protected expression _if_false;
///<summary>
///
///</summary>
public expression condition
{
get
{
return _condition;
}
set
{
_condition=value;
if (_condition != null)
_condition.Parent = this;
}
}
///<summary>
///
///</summary>
public expression if_true
{
get
{
return _if_true;
}
set
{
_if_true=value;
if (_if_true != null)
_if_true.Parent = this;
}
}
///<summary>
///
///</summary>
public expression if_false
{
get
{
return _if_false;
}
set
{
_if_false=value;
if (_if_false != null)
_if_false.Parent = this;
}
}
/// <summary> Создает копию узла </summary>
public override syntax_tree_node Clone()
{
if_expr_new copy = new if_expr_new();
copy.Parent = this.Parent;
if (source_context != null)
copy.source_context = new SourceContext(source_context);
if (attributes != null)
{
copy.attributes = (attribute_list)attributes.Clone();
copy.attributes.Parent = copy;
}
if (condition != null)
{
copy.condition = (expression)condition.Clone();
copy.condition.Parent = copy;
}
if (if_true != null)
{
copy.if_true = (expression)if_true.Clone();
copy.if_true.Parent = copy;
}
if (if_false != null)
{
copy.if_false = (expression)if_false.Clone();
copy.if_false.Parent = copy;
}
return copy;
}
/// <summary> Получает копию данного узла корректного типа </summary>
public new if_expr_new TypedClone()
{
return Clone() as if_expr_new;
}
///<summary> Заполняет поля Parent в непосредственных дочерних узлах </summary>
public override void FillParentsInDirectChilds()
{
if (attributes != null)
attributes.Parent = this;
if (condition != null)
condition.Parent = this;
if (if_true != null)
if_true.Parent = this;
if (if_false != null)
if_false.Parent = this;
}
///<summary> Заполняет поля Parent во всем поддереве </summary>
public override void FillParentsInAllChilds()
{
FillParentsInDirectChilds();
attributes?.FillParentsInAllChilds();
condition?.FillParentsInAllChilds();
if_true?.FillParentsInAllChilds();
if_false?.FillParentsInAllChilds();
}
///<summary>
///Свойство для получения количества всех подузлов без элементов поля типа List
///</summary>
public override Int32 subnodes_without_list_elements_count
{
get
{
return 3;
}
}
///<summary>
///Свойство для получения количества всех подузлов. Подузлом также считается каждый элемент поля типа List
///</summary>
public override Int32 subnodes_count
{
get
{
return 3;
}
}
///<summary>
///Индексатор для получения всех подузлов
///</summary>
public override syntax_tree_node this[Int32 ind]
{
get
{
if(subnodes_count == 0 || ind < 0 || ind > subnodes_count-1)
throw new IndexOutOfRangeException();
switch(ind)
{
case 0:
return condition;
case 1:
return if_true;
case 2:
return if_false;
}
return null;
}
set
{
if(subnodes_count == 0 || ind < 0 || ind > subnodes_count-1)
throw new IndexOutOfRangeException();
switch(ind)
{
case 0:
condition = (expression)value;
break;
case 1:
if_true = (expression)value;
break;
case 2:
if_false = (expression)value;
break;
}
}
}
///<summary>
///Метод для обхода дерева посетителем
///</summary>
///<param name="visitor">Объект-посетитель.</param>
///<returns>Return value is void</returns>
public override void visit(IVisitor visitor)
{
visitor.visit(this);
}
}
}

View file

@ -1504,6 +1504,12 @@ namespace PascalABCCompiler.SyntaxTree
///<param name="_diapason_expr_new">Node to visit</param>
///<returns> Return value is void </returns>
void visit(diapason_expr_new _diapason_expr_new);
///<summary>
///Method to visit if_expr_new.
///</summary>
///<param name="_if_expr_new">Node to visit</param>
///<returns> Return value is void </returns>
void visit(if_expr_new _if_expr_new);
}

View file

@ -3236,6 +3236,18 @@
<TagIndices />
</Tags>
</SyntaxNode>
<SyntaxNode Name="if_expr_new" BaseName="expression">
<Fields>
<SyntaxField Name="condition" SyntaxType="expression" />
<SyntaxField Name="if_true" SyntaxType="expression" />
<SyntaxField Name="if_false" SyntaxType="expression" />
</Fields>
<Methods />
<Tags>
<CategoryIndices />
<TagIndices />
</Tags>
</SyntaxNode>
</SyntaxNodes>
<Settings>
<FileName>Tree.cs</FileName>
@ -3285,6 +3297,7 @@
<HelpData Key=".body" Value="" />
<HelpData Key=".cconst" Value="Значение константы." />
<HelpData Key=".char_num" Value="Номер символа." />
<HelpData Key=".condition" Value="" />
<HelpData Key=".count" Value="" />
<HelpData Key=".def" Value="" />
<HelpData Key=".definitions" Value="" />
@ -3299,6 +3312,8 @@
<HelpData Key=".guardstats" Value="" />
<HelpData Key=".handlers" Value="" />
<HelpData Key=".i" Value="" />
<HelpData Key=".if_false" Value="" />
<HelpData Key=".if_true" Value="" />
<HelpData Key=".item_expression" Value="" />
<HelpData Key=".left" Value="" />
<HelpData Key=".lists" Value="" />
@ -3856,6 +3871,10 @@
<HelpData Key="ident_with_templateparams." Value="" />
<HelpData Key="ident_with_templateparams.name" Value="" />
<HelpData Key="ident_with_templateparams.template_params" Value="" />
<HelpData Key="if_expr_new" Value="Новое условное выражение в стиле Паскаля. Доступно только при форматировании" />
<HelpData Key="if_expr_new.condition" Value="" />
<HelpData Key="if_expr_new.if_false" Value="" />
<HelpData Key="if_expr_new.if_true" Value="" />
<HelpData Key="if_node" Value="Условный оператор" />
<HelpData Key="if_node.condition" Value="Условие" />
<HelpData Key="if_node.else_body" Value="Оператор по ветви else" />