Browse Source

Extend StackAllocExpression: Add support for initializers.

pull/1246/head
Siegfried Pammer 7 years ago
parent
commit
b58c356222
  1. 1
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 5
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs
  3. 14
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/StackAllocExpression.cs
  4. 4
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

1
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -1048,6 +1048,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -1048,6 +1048,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(StackAllocExpression.StackallocKeywordRole);
stackAllocExpression.Type.AcceptVisitor(this);
WriteCommaSeparatedListInBrackets(new[] { stackAllocExpression.CountExpression });
stackAllocExpression.Initializer.AcceptVisitor(this);
EndNode(stackAllocExpression);
}

5
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs

@ -72,7 +72,10 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -72,7 +72,10 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ArrayCreateExpression o = other as ArrayCreateExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match);
return o != null && this.Type.DoMatch(o.Type, match)
&& this.Arguments.DoMatch(o.Arguments, match)
&& this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match)
&& this.Initializer.DoMatch(o.Initializer, match);
}
}
}

14
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/StackAllocExpression.cs

@ -33,7 +33,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -33,7 +33,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public class StackAllocExpression : Expression
{
public readonly static TokenRole StackallocKeywordRole = new TokenRole ("stackalloc");
public readonly static Role<ArrayInitializerExpression> InitializerRole = new Role<ArrayInitializerExpression>("Initializer", ArrayInitializerExpression.Null);
public CSharpTokenNode StackAllocToken {
get { return GetChildByRole (StackallocKeywordRole); }
}
@ -55,7 +56,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -55,7 +56,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public CSharpTokenNode RBracketToken {
get { return GetChildByRole (Roles.RBracket); }
}
public ArrayInitializerExpression Initializer {
get { return GetChildByRole(InitializerRole); }
set { SetChildByRole(InitializerRole, value); }
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitStackAllocExpression (this);
@ -74,7 +80,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -74,7 +80,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
StackAllocExpression o = other as StackAllocExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.CountExpression.DoMatch(o.CountExpression, match);
return o != null && this.Type.DoMatch(o.Type, match)
&& this.CountExpression.DoMatch(o.CountExpression, match)
&& this.Initializer.DoMatch(o.Initializer, match);
}
}
}

4
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -74,9 +74,7 @@ @@ -74,9 +74,7 @@
<Compile Include="CSharp\Syntax\ErrorNode.cs" />
<Compile Include="CSharp\Syntax\Expressions\AnonymousMethodExpression.cs" />
<Compile Include="CSharp\Syntax\Expressions\AnonymousTypeCreateExpression.cs" />
<Compile Include="CSharp\Syntax\Expressions\ArrayCreateExpression.cs">
<DependentUpon>ArrayInitializerExpression.cs</DependentUpon>
</Compile>
<Compile Include="CSharp\Syntax\Expressions\ArrayCreateExpression.cs" />
<Compile Include="CSharp\Syntax\Expressions\ArrayInitializerExpression.cs" />
<Compile Include="CSharp\Syntax\Expressions\AsExpression.cs" />
<Compile Include="CSharp\Syntax\Expressions\AssignmentExpression.cs" />

Loading…
Cancel
Save