|
|
|
@ -4,8 +4,11 @@
@@ -4,8 +4,11 @@
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.Globalization; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
|
|
|
|
|
|
using ICSharpCode.NRefactory.PatternMatching; |
|
|
|
|
using ICSharpCode.NRefactory.VB.Ast; |
|
|
|
|
|
|
|
|
@ -261,7 +264,11 @@ namespace ICSharpCode.NRefactory.VB
@@ -261,7 +264,11 @@ namespace ICSharpCode.NRefactory.VB
|
|
|
|
|
|
|
|
|
|
public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
StartNode(primitiveExpression); |
|
|
|
|
|
|
|
|
|
WritePrimitiveValue(primitiveExpression.Value); |
|
|
|
|
|
|
|
|
|
return EndNode(primitiveExpression); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public object VisitInstanceExpression(InstanceExpression instanceExpression, object data) |
|
|
|
@ -306,6 +313,43 @@ namespace ICSharpCode.NRefactory.VB
@@ -306,6 +313,43 @@ namespace ICSharpCode.NRefactory.VB
|
|
|
|
|
return EndNode(addressOfExpression); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public object VisitGetTypeExpression(GetTypeExpression getTypeExpression, object data) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public object VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, object data) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public object VisitMemberAccessExpression(MemberAccessExpression memberAccessExpression, object data) |
|
|
|
|
{ |
|
|
|
|
StartNode(memberAccessExpression); |
|
|
|
|
|
|
|
|
|
memberAccessExpression.Target.AcceptVisitor(this, data); |
|
|
|
|
WriteToken(".", MemberAccessExpression.Roles.Dot); |
|
|
|
|
memberAccessExpression.Member.AcceptVisitor(this, data); |
|
|
|
|
WriteTypeArguments(memberAccessExpression.TypeArguments); |
|
|
|
|
|
|
|
|
|
return EndNode(memberAccessExpression); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) |
|
|
|
|
{ |
|
|
|
|
StartNode(typeReferenceExpression); |
|
|
|
|
|
|
|
|
|
typeReferenceExpression.Type.AcceptVisitor(this, data); |
|
|
|
|
|
|
|
|
|
return EndNode(typeReferenceExpression); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region TypeName
|
|
|
|
|
public object VisitPrimitiveType(PrimitiveType primitiveType, object data) |
|
|
|
|
{ |
|
|
|
@ -818,6 +862,109 @@ namespace ICSharpCode.NRefactory.VB
@@ -818,6 +862,109 @@ namespace ICSharpCode.NRefactory.VB
|
|
|
|
|
WriteToken(".", AstNode.Roles.Dot); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WritePrimitiveValue(object val) |
|
|
|
|
{ |
|
|
|
|
if (val == null) { |
|
|
|
|
WriteKeyword("Nothing"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (val is bool) { |
|
|
|
|
if ((bool)val) { |
|
|
|
|
WriteKeyword("True"); |
|
|
|
|
} else { |
|
|
|
|
WriteKeyword("False"); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (val is string) { |
|
|
|
|
formatter.WriteToken("\"" + ConvertString(val.ToString()) + "\""); |
|
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
|
} else if (val is char) { |
|
|
|
|
formatter.WriteToken("\"" + ConvertCharLiteral((char)val) + "\"c"); |
|
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
|
} else if (val is decimal) { |
|
|
|
|
formatter.WriteToken(((decimal)val).ToString(NumberFormatInfo.InvariantInfo) + "D"); |
|
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
|
} else if (val is float) { |
|
|
|
|
float f = (float)val; |
|
|
|
|
if (float.IsInfinity(f) || float.IsNaN(f)) { |
|
|
|
|
// Strictly speaking, these aren't PrimitiveExpressions;
|
|
|
|
|
// but we still support writing these to make life easier for code generators.
|
|
|
|
|
WriteKeyword("Single"); |
|
|
|
|
WriteToken(".", AstNode.Roles.Dot); |
|
|
|
|
if (float.IsPositiveInfinity(f)) |
|
|
|
|
WriteIdentifier("PositiveInfinity"); |
|
|
|
|
else if (float.IsNegativeInfinity(f)) |
|
|
|
|
WriteIdentifier("NegativeInfinity"); |
|
|
|
|
else |
|
|
|
|
WriteIdentifier("NaN"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
formatter.WriteToken(f.ToString("R", NumberFormatInfo.InvariantInfo) + "F"); |
|
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
|
} else if (val is double) { |
|
|
|
|
double f = (double)val; |
|
|
|
|
if (double.IsInfinity(f) || double.IsNaN(f)) { |
|
|
|
|
// Strictly speaking, these aren't PrimitiveExpressions;
|
|
|
|
|
// but we still support writing these to make life easier for code generators.
|
|
|
|
|
WriteKeyword("Double"); |
|
|
|
|
WriteToken(".", AstNode.Roles.Dot); |
|
|
|
|
if (double.IsPositiveInfinity(f)) |
|
|
|
|
WriteIdentifier("PositiveInfinity"); |
|
|
|
|
else if (double.IsNegativeInfinity(f)) |
|
|
|
|
WriteIdentifier("NegativeInfinity"); |
|
|
|
|
else |
|
|
|
|
WriteIdentifier("NaN"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
string number = f.ToString("R", NumberFormatInfo.InvariantInfo); |
|
|
|
|
if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) |
|
|
|
|
number += ".0"; |
|
|
|
|
formatter.WriteToken(number); |
|
|
|
|
// needs space if identifier follows number; this avoids mistaking the following identifier as type suffix
|
|
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
|
} else if (val is IFormattable) { |
|
|
|
|
StringBuilder b = new StringBuilder(); |
|
|
|
|
// if (primitiveExpression.LiteralFormat == LiteralFormat.HexadecimalNumber) {
|
|
|
|
|
// b.Append("0x");
|
|
|
|
|
// b.Append(((IFormattable)val).ToString("x", NumberFormatInfo.InvariantInfo));
|
|
|
|
|
// } else {
|
|
|
|
|
b.Append(((IFormattable)val).ToString(null, NumberFormatInfo.InvariantInfo)); |
|
|
|
|
// }
|
|
|
|
|
if (val is uint || val is ulong) { |
|
|
|
|
b.Append("U"); |
|
|
|
|
} |
|
|
|
|
if (val is long || val is ulong) { |
|
|
|
|
b.Append("L"); |
|
|
|
|
} |
|
|
|
|
formatter.WriteToken(b.ToString()); |
|
|
|
|
// needs space if identifier follows number; this avoids mistaking the following identifier as type suffix
|
|
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
|
} else { |
|
|
|
|
formatter.WriteToken(val.ToString()); |
|
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ConvertLiteral
|
|
|
|
|
static string ConvertCharLiteral(char ch) |
|
|
|
|
{ |
|
|
|
|
if (ch == '"') return "\"\""; |
|
|
|
|
return ch.ToString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static string ConvertString(string str) |
|
|
|
|
{ |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
foreach (char ch in str) { |
|
|
|
|
sb.Append(ConvertCharLiteral(ch)); |
|
|
|
|
} |
|
|
|
|
return sb.ToString(); |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|