Class SyntaxNode
Provides a base class for nodes in the syntax tree. Classes that represent concrete language constructs derive from this class.
Inheritance
Inherited Members
Namespace: CilTools.Syntax
Assembly: CilTools.BytecodeAnalysis.dll
Syntax
public abstract class SyntaxNode
Remarks
This assembly provides syntax node implementations for a Common Intermediate Language (CIL) assembler grammar (ECMA-335 specification, part II). They are used by the disassembler to return a parsed representation of the produced code.
The SyntaxNode
class instance contains all information required to produce the source code of the
corresponding language construct, including whitespaces. The EnumerateChildNodes() method returns all
child nodes of this node, or an empty collection if it is a leaf (terminal node).
Some child nodes may be exposed via specific properties as well.
The text representation for non-terminal node is a string concetanation of all its child nodes' text representations.
Use ToSyntaxTree(DisassemblerParams) method to get the syntax tree for the specified method.
Constructors
SyntaxNode()
Declaration
protected SyntaxNode()
Fields
_lead
Whitespace content at the beginning of this node's code
Declaration
protected string _lead
Field Value
Type | Description |
---|---|
System.String |
_parent
Parent node for this node, or null
if this node is root or not included in syntax tree
Declaration
protected SyntaxNode _parent
Field Value
Type | Description |
---|---|
SyntaxNode |
_trail
Whitespace content at the end of this node's code
Declaration
protected string _trail
Field Value
Type | Description |
---|---|
System.String |
EmptyArray
Gets an empty array of syntax nodes
Declaration
public static readonly SyntaxNode[] EmptyArray
Field Value
Type | Description |
---|---|
SyntaxNode[] |
Properties
LeadingWhitespace
Gets whitespace content at the beginning of this node's code
Declaration
public string LeadingWhitespace { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Besides the whitespace character itself, the returned string may contain line feed or carriage return characters. For efficiency purposes, the whitespace content, both syntactically meaningful and indentation-only, is stored within one of the adjacent nodes, not in the separate node.
Parent
Gets the parent node of this syntax node, or null if this node is root or not included in syntax tree.
Declaration
public SyntaxNode Parent { get; }
Property Value
Type | Description |
---|---|
SyntaxNode |
TrailingWhitespace
Gets whitespace content at the end of this node's code
Declaration
public string TrailingWhitespace { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Besides the whitespace character itself, the returned string may contain line feed or carriage return characters. For efficiency purposes, the whitespace content, both syntactically meaningful and indentation-only, is stored within one of the adjacent nodes, not in the separate node.
Methods
EnumerateChildNodes()
Enumerates child nodes of this node. For the leaf node, returns an empty collection.
Declaration
public abstract IEnumerable<SyntaxNode> EnumerateChildNodes()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<SyntaxNode> | The collection of child syntax nodes |
GetAdditionalInfo(String)
Gets an additional implementation-defined information about this node
Declaration
public object GetAdditionalInfo(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Object | The requested value, or |
GetChildNodes()
Gets the array of this node's child nodes. For the leaf node, returns an empty array.
Declaration
public SyntaxNode[] GetChildNodes()
Returns
Type | Description |
---|---|
SyntaxNode[] | The array of child syntax nodes |
GetTypeDefSyntax(Type)
Gets the CIL assembler syntax for the definition of the specified type
Declaration
public static IEnumerable<SyntaxNode> GetTypeDefSyntax(Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | Type to get definition syntax |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<SyntaxNode> | The collection of syntax nodes that make up type definition syntax |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The specified type is null |
GetTypeDefSyntax(Type, Boolean, DisassemblerParams)
Gets the CIL assembler syntax for the definition of the specified type with specified disassembler parameters
Declaration
public static IEnumerable<SyntaxNode> GetTypeDefSyntax(Type t, bool full, DisassemblerParams disassemblerParams)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | Type to get definition syntax |
System.Boolean | full |
|
DisassemblerParams | disassemblerParams | Object that specifies additional options for the disassembling operation |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<SyntaxNode> | The collection of syntax nodes that make up type definition syntax |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The specified type is null |
SetAdditionalInfo(String, Object)
Sets an additional implementation-defined information about this node
Declaration
public void SetAdditionalInfo(string name, object val)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
System.Object | val |
ToString()
Gets the text representation of this node, including whitespace content
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | The string containing CIL code of this syntax node |
Overrides
ToText(TextWriter)
Writes text representation of this node into the specified TextWriter
Declaration
public abstract void ToText(TextWriter target)
Parameters
Type | Name | Description |
---|---|---|
System.IO.TextWriter | target |