@ -99,19 +99,25 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
/// <summary>
/// <summary>
/// Retrieves the symbol associated with this AstNode, or null if no symbol is associated with the node.
/// Retrieves the < see cref="IS ymbol"/> associated with this AstNode, or null if no symbol is associated with the node.
/// </summary>
/// </summary>
public static ISymbol GetSymbol ( this AstNode node )
public static ISymbol GetSymbol ( this AstNode node )
{
{
var rr = node . Annotation < ResolveResult > ( ) ;
var rr = node . Annotation < ResolveResult > ( ) ;
return rr ! = null ? rr . GetSymbol ( ) : null ;
return rr ! = null ? rr . GetSymbol ( ) : null ;
}
}
/// <summary>
/// Retrieves the <see cref="ResolveResult"/> associated with this <see cref="AstNode"/>, or <see cref="ErrorResolveResult.UnknownError"/> if no resolve result is associated with the node.
/// </summary>
public static ResolveResult GetResolveResult ( this AstNode node )
public static ResolveResult GetResolveResult ( this AstNode node )
{
{
return node . Annotation < ResolveResult > ( ) ? ? ErrorResolveResult . UnknownError ;
return node . Annotation < ResolveResult > ( ) ? ? ErrorResolveResult . UnknownError ;
}
}
/// <summary>
/// Retrieves the <see cref="ILVariable"/> associated with this <see cref="IdentifierExpression"/>, or <c>null</c> if no variable is associated with this identifier.
/// </summary>
public static ILVariable GetILVariable ( this IdentifierExpression expr )
public static ILVariable GetILVariable ( this IdentifierExpression expr )
{
{
var rr = expr . Annotation < ResolveResult > ( ) as ILVariableResolveResult ;
var rr = expr . Annotation < ResolveResult > ( ) as ILVariableResolveResult ;
@ -120,7 +126,10 @@ namespace ICSharpCode.Decompiler.CSharp
else
else
return null ;
return null ;
}
}
/// <summary>
/// Retrieves the <see cref="ILVariable"/> associated with this <see cref="VariableInitializer"/>, or <c>null</c> if no variable is associated with this initializer.
/// </summary>
public static ILVariable GetILVariable ( this VariableInitializer vi )
public static ILVariable GetILVariable ( this VariableInitializer vi )
{
{
var rr = vi . Annotation < ResolveResult > ( ) as ILVariableResolveResult ;
var rr = vi . Annotation < ResolveResult > ( ) as ILVariableResolveResult ;
@ -130,6 +139,9 @@ namespace ICSharpCode.Decompiler.CSharp
return null ;
return null ;
}
}
/// <summary>
/// Retrieves the <see cref="ILVariable"/> associated with this <see cref="ForeachStatement"/>, or <c>null</c> if no variable is associated with this foreach statement.
/// </summary>
public static ILVariable GetILVariable ( this ForeachStatement loop )
public static ILVariable GetILVariable ( this ForeachStatement loop )
{
{
var rr = loop . Annotation < ResolveResult > ( ) as ILVariableResolveResult ;
var rr = loop . Annotation < ResolveResult > ( ) as ILVariableResolveResult ;
@ -139,18 +151,27 @@ namespace ICSharpCode.Decompiler.CSharp
return null ;
return null ;
}
}
/// <summary>
/// Adds an <see cref="ILVariable"/> to this initializer.
/// </summary>
public static VariableInitializer WithILVariable ( this VariableInitializer vi , ILVariable v )
public static VariableInitializer WithILVariable ( this VariableInitializer vi , ILVariable v )
{
{
vi . AddAnnotation ( new ILVariableResolveResult ( v , v . Type ) ) ;
vi . AddAnnotation ( new ILVariableResolveResult ( v , v . Type ) ) ;
return vi ;
return vi ;
}
}
/// <summary>
/// Adds an <see cref="ILVariable"/> to this foreach statement.
/// </summary>
public static ForeachStatement WithILVariable ( this ForeachStatement loop , ILVariable v )
public static ForeachStatement WithILVariable ( this ForeachStatement loop , ILVariable v )
{
{
loop . AddAnnotation ( new ILVariableResolveResult ( v , v . Type ) ) ;
loop . AddAnnotation ( new ILVariableResolveResult ( v , v . Type ) ) ;
return loop ;
return loop ;
}
}
/// <summary>
/// Copies all annotations from <paramref name="other"/> to <paramref name="node"/>.
/// </summary>
public static T CopyAnnotationsFrom < T > ( this T node , AstNode other ) where T : AstNode
public static T CopyAnnotationsFrom < T > ( this T node , AstNode other ) where T : AstNode
{
{
foreach ( object annotation in other . Annotations ) {
foreach ( object annotation in other . Annotations ) {
@ -159,6 +180,9 @@ namespace ICSharpCode.Decompiler.CSharp
return node ;
return node ;
}
}
/// <summary>
/// Copies all <see cref="ILInstruction"/> annotations from <paramref name="other"/> to <paramref name="node"/>.
/// </summary>
public static T CopyInstructionsFrom < T > ( this T node , AstNode other ) where T : AstNode
public static T CopyInstructionsFrom < T > ( this T node , AstNode other ) where T : AstNode
{
{
foreach ( object annotation in other . Annotations . OfType < ILInstruction > ( ) ) {
foreach ( object annotation in other . Annotations . OfType < ILInstruction > ( ) ) {
@ -168,6 +192,9 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
}
}
/// <summary>
/// Represents a reference to a local variable.
/// </summary>
public class ILVariableResolveResult : ResolveResult
public class ILVariableResolveResult : ResolveResult
{
{
public readonly ILVariable Variable ;
public readonly ILVariable Variable ;
@ -183,6 +210,9 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
}
}
/// <summary>
/// Annotates a <see cref="ForeachStatement"/> with the instructions for the GetEnumerator, MoveNext and get_Current calls.
/// </summary>
public class ForeachAnnotation
public class ForeachAnnotation
{
{
public readonly ILInstruction GetEnumeratorCall ;
public readonly ILInstruction GetEnumeratorCall ;