Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/NRefactory.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Grunwald <daniel@danielgrunwald.de>2015-05-30 12:57:23 +0300
committerDaniel Grunwald <daniel@danielgrunwald.de>2015-05-30 13:16:22 +0300
commit530d5b583fc378f98dd27e42067bfdef77b350da (patch)
treed0c8a0c8817a9bd5bb51dec845cc0bfae30e8936 /ICSharpCode.NRefactory.CSharp
parente2f72129355af155048ba5a36439f25c01010618 (diff)
Merge changes from ILSpy newdecompiler branch
Diffstat (limited to 'ICSharpCode.NRefactory.CSharp')
-rw-r--r--ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs11
-rw-r--r--ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs2
-rw-r--r--ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs12
-rw-r--r--ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs34
4 files changed, 50 insertions, 9 deletions
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs b/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs
index 3611574b..b93a168a 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs
@@ -90,6 +90,8 @@ namespace ICSharpCode.NRefactory.CSharp
public class CatchClause : AstNode
{
public static readonly TokenRole CatchKeywordRole = new TokenRole ("catch");
+ public static readonly TokenRole WhenKeywordRole = new TokenRole ("when");
+ public static readonly Role<Expression> ConditionRole = Roles.Condition;
#region Null
public new static readonly CatchClause Null = new NullCatchClause ();
@@ -212,6 +214,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); }
}
+ public CSharpTokenNode WhenToken {
+ get { return GetChildByRole (WhenKeywordRole); }
+ }
+
+ public Expression Condition {
+ get { return GetChildByRole(ConditionRole); }
+ set { SetChildByRole(ConditionRole, value); }
+ }
+
public BlockStatement Body {
get { return GetChildByRole (Roles.Body); }
set { SetChildByRole (Roles.Body, value); }
diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
index f6c153b1..93c73052 100644
--- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
+++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
@@ -171,7 +171,7 @@ namespace ICSharpCode.NRefactory.CSharp
TypeSystemAstBuilder CreateAstBuilder()
{
TypeSystemAstBuilder astBuilder = new TypeSystemAstBuilder();
- astBuilder.AddAnnotations = true;
+ astBuilder.AddTypeReferenceAnnotations = true;
astBuilder.ShowModifiers = (ConversionFlags & ConversionFlags.ShowModifiers) == ConversionFlags.ShowModifiers;
astBuilder.ShowAccessibility = (ConversionFlags & ConversionFlags.ShowAccessibility) == ConversionFlags.ShowAccessibility;
astBuilder.AlwaysUseShortTypeNames = (ConversionFlags & ConversionFlags.UseFullyQualifiedTypeNames) != ConversionFlags.UseFullyQualifiedTypeNames;
diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
index 4fc5ed9f..fa7e1644 100644
--- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
+++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
@@ -1158,7 +1158,7 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(attributeSection);
WriteToken(Roles.LBracket);
if (!string.IsNullOrEmpty(attributeSection.AttributeTarget)) {
- WriteIdentifier(attributeSection.AttributeTargetToken);
+ WriteKeyword(attributeSection.AttributeTarget, Roles.Identifier);
WriteToken(Roles.Colon);
Space();
}
@@ -1678,6 +1678,16 @@ namespace ICSharpCode.NRefactory.CSharp
Space(policy.SpacesWithinCatchParentheses);
RPar();
}
+ if (!catchClause.Condition.IsNull) {
+ Space();
+ WriteKeyword(CatchClause.WhenKeywordRole);
+ Space(policy.SpaceBeforeIfParentheses);
+ LPar();
+ Space(policy.SpacesWithinIfParentheses);
+ catchClause.Condition.AcceptVisitor(this);
+ Space(policy.SpacesWithinIfParentheses);
+ RPar();
+ }
catchClause.Body.AcceptVisitor(this);
EndNode(catchClause);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
index 6793680e..d4d9fc41 100644
--- a/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
+++ b/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
@@ -77,7 +77,13 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// Specifies whether the ast builder should add annotations to type references.
/// The default value is <c>false</c>.
/// </summary>
- public bool AddAnnotations { get; set; }
+ public bool AddTypeReferenceAnnotations { get; set; }
+
+ /// <summary>
+ /// Specifies whether the ast builder should add ResolveResult annotations to AST nodes.
+ /// The default value is <c>false</c>.
+ /// </summary>
+ public bool AddResolveResultAnnotations { get; set; }
/// <summary>
/// Controls the accessibility modifiers are shown.
@@ -159,8 +165,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (type == null)
throw new ArgumentNullException("type");
AstType astType = ConvertTypeHelper(type);
- if (AddAnnotations)
+ if (AddTypeReferenceAnnotations)
astType.AddAnnotation(type);
+ if (AddResolveResultAnnotations)
+ astType.AddAnnotation(new TypeResolveResult(type));
return astType;
}
@@ -417,7 +425,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
if (rr is TypeOfResolveResult) {
- return new TypeOfExpression(ConvertType(rr.Type));
+ var expr = new TypeOfExpression(ConvertType(((TypeOfResolveResult)rr).ReferencedType));
+ if (AddResolveResultAnnotations)
+ expr.AddAnnotation(rr);
+ return expr;
} else if (rr is ArrayCreateResolveResult) {
ArrayCreateResolveResult acrr = (ArrayCreateResolveResult)rr;
ArrayCreateExpression ace = new ArrayCreateExpression();
@@ -438,6 +449,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
initializer.Elements.AddRange(acrr.InitializerElements.Select(ConvertConstantValue));
ace.Initializer = initializer;
}
+ if (AddResolveResultAnnotations)
+ ace.AddAnnotation(rr);
return ace;
} else if (rr.IsCompileTimeConstant) {
return ConvertConstantValue(rr.Type, rr.ConstantValue);
@@ -451,10 +464,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (type == null)
throw new ArgumentNullException("type");
if (constantValue == null) {
- if (type.IsReferenceType == true)
- return new NullReferenceExpression();
- else
- return new DefaultValueExpression(ConvertType(type));
+ if (type.IsReferenceType == true) {
+ var expr = new NullReferenceExpression();
+ if (AddResolveResultAnnotations)
+ expr.AddAnnotation(new ConstantResolveResult(SpecialType.NullType, null));
+ return expr;
+ } else {
+ var expr = new DefaultValueExpression(ConvertType(type));
+ if (AddResolveResultAnnotations)
+ expr.AddAnnotation(new ConstantResolveResult(type, null));
+ return expr;
+ }
} else if (type.Kind == TypeKind.Enum) {
return ConvertEnumValue(type, (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false));
} else {