Browse Source

Merge branch 'master' into bookmarks

pull/263/head
Ronny Klier 14 years ago
parent
commit
c0155fad9e
  1. 5
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 26
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  3. 6
      ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs
  4. 23
      ILSpy/XmlDoc/XmlDocKeyProvider.cs
  5. 92
      NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs
  6. 55
      NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs
  7. 6
      NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  8. 11
      NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  9. 2078
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstTransformer.cs
  10. 1156
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstVisitor.cs
  11. 1266
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/NodeTrackingAstVisitor.cs

5
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -1112,6 +1112,11 @@ namespace ICSharpCode.Decompiler.Ast @@ -1112,6 +1112,11 @@ namespace ICSharpCode.Decompiler.Ast
attributedNode.Attributes.Add(new AttributeSection(CreateNonCustomAttribute(typeof(SerializableAttribute))));
#endregion
#region ComImportAttribute
if (typeDefinition.IsImport)
attributedNode.Attributes.Add(new AttributeSection(CreateNonCustomAttribute(typeof(ComImportAttribute))));
#endregion
#region StructLayoutAttribute
LayoutKind layoutKind = LayoutKind.Auto;
switch (typeDefinition.Attributes & TypeAttributes.LayoutMask) {

26
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -958,30 +958,30 @@ namespace ICSharpCode.Decompiler.Ast @@ -958,30 +958,30 @@ namespace ICSharpCode.Decompiler.Ast
if (cecilMethodDef != null) {
if (cecilMethodDef.IsGetter && methodArgs.Count == 0) {
foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
if (prop.GetMethod == cecilMethodDef)
return target.Member(prop.Name).WithAnnotation(prop);
if (prop.GetMethod == cecilMethodDef)
return target.Member(prop.Name).WithAnnotation(prop).WithAnnotation(cecilMethod);
}
} else if (cecilMethodDef.IsGetter) { // with parameters
PropertyDefinition indexer = GetIndexer(cecilMethodDef);
if (indexer != null)
return target.Indexer(methodArgs).WithAnnotation(indexer);
return target.Indexer(methodArgs).WithAnnotation(indexer).WithAnnotation(cecilMethod);
} else if (cecilMethodDef.IsSetter && methodArgs.Count == 1) {
foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
if (prop.SetMethod == cecilMethodDef)
return new Ast.AssignmentExpression(target.Member(prop.Name).WithAnnotation(prop), methodArgs[0]);
if (prop.SetMethod == cecilMethodDef)
return new Ast.AssignmentExpression(target.Member(prop.Name).WithAnnotation(prop).WithAnnotation(cecilMethod), methodArgs[0]);
}
} else if (cecilMethodDef.IsSetter && methodArgs.Count > 1) {
PropertyDefinition indexer = GetIndexer(cecilMethodDef);
if (indexer != null)
return new AssignmentExpression(
target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)).WithAnnotation(indexer),
return new AssignmentExpression(
target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)).WithAnnotation(indexer).WithAnnotation(cecilMethod),
methodArgs[methodArgs.Count - 1]
);
} else if (cecilMethodDef.IsAddOn && methodArgs.Count == 1) {
foreach (var ev in cecilMethodDef.DeclaringType.Events) {
if (ev.AddMethod == cecilMethodDef) {
return new Ast.AssignmentExpression {
Left = target.Member(ev.Name).WithAnnotation(ev),
return new Ast.AssignmentExpression {
Left = target.Member(ev.Name).WithAnnotation(ev).WithAnnotation(cecilMethod),
Operator = AssignmentOperatorType.Add,
Right = methodArgs[0]
};
@ -990,16 +990,16 @@ namespace ICSharpCode.Decompiler.Ast @@ -990,16 +990,16 @@ namespace ICSharpCode.Decompiler.Ast
} else if (cecilMethodDef.IsRemoveOn && methodArgs.Count == 1) {
foreach (var ev in cecilMethodDef.DeclaringType.Events) {
if (ev.RemoveMethod == cecilMethodDef) {
return new Ast.AssignmentExpression {
Left = target.Member(ev.Name).WithAnnotation(ev),
return new Ast.AssignmentExpression {
Left = target.Member(ev.Name).WithAnnotation(ev).WithAnnotation(cecilMethod),
Operator = AssignmentOperatorType.Subtract,
Right = methodArgs[0]
};
}
}
} else if (cecilMethodDef.Name == "Invoke" && cecilMethodDef.DeclaringType.BaseType != null && cecilMethodDef.DeclaringType.BaseType.FullName == "System.MulticastDelegate") {
AdjustArgumentsForMethodCall(cecilMethod, methodArgs);
return target.Invoke(methodArgs);
AdjustArgumentsForMethodCall(cecilMethod, methodArgs);
return target.Invoke(methodArgs).WithAnnotation(cecilMethod);
}
}
// Default invocation

6
ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs

@ -107,6 +107,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -107,6 +107,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
AstNode fieldOrEventDecl = members.FirstOrDefault(f => f.Annotation<FieldDefinition>() == fieldDef);
if (fieldOrEventDecl == null)
break;
Expression initializer = m.Get<Expression>("initializer").Single();
// 'this'/'base' cannot be used in field initializers
if (initializer.DescendantsAndSelf.Any(n => n is ThisReferenceExpression || n is BaseReferenceExpression))
break;
allSame = true;
for (int i = 1; i < instanceCtorsNotChainingWithThis.Length; i++) {
@ -116,7 +120,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -116,7 +120,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (allSame) {
foreach (var ctor in instanceCtorsNotChainingWithThis)
ctor.Body.First().Remove();
fieldOrEventDecl.GetChildrenByRole(AstNode.Roles.Variable).Single().Initializer = m.Get<Expression>("initializer").Single().Detach();
fieldOrEventDecl.GetChildrenByRole(AstNode.Roles.Variable).Single().Initializer = initializer.Detach();
}
} while (allSame);
}

23
ILSpy/XmlDoc/XmlDocKeyProvider.cs

@ -50,6 +50,7 @@ namespace ICSharpCode.ILSpy.XmlDoc @@ -50,6 +50,7 @@ namespace ICSharpCode.ILSpy.XmlDoc
b.Append('.');
b.Append(member.Name.Replace('.', '#'));
IList<ParameterDefinition> parameters;
TypeReference explicitReturnType = null;
if (member is PropertyDefinition) {
parameters = ((PropertyDefinition)member).Parameters;
} else if (member is MethodReference) {
@ -59,6 +60,9 @@ namespace ICSharpCode.ILSpy.XmlDoc @@ -59,6 +60,9 @@ namespace ICSharpCode.ILSpy.XmlDoc
b.Append(mr.GenericParameters.Count);
}
parameters = mr.Parameters;
if (mr.Name == "op_Implicit" || mr.Name == "op_Explicit") {
explicitReturnType = mr.ReturnType;
}
} else {
parameters = null;
}
@ -70,6 +74,10 @@ namespace ICSharpCode.ILSpy.XmlDoc @@ -70,6 +74,10 @@ namespace ICSharpCode.ILSpy.XmlDoc
}
b.Append(')');
}
if (explicitReturnType != null) {
b.Append('~');
AppendTypeName(b, explicitReturnType);
}
}
return b.ToString();
}
@ -101,8 +109,15 @@ namespace ICSharpCode.ILSpy.XmlDoc @@ -101,8 +109,15 @@ namespace ICSharpCode.ILSpy.XmlDoc
ArrayType arrayType = type as ArrayType;
if (arrayType != null) {
b.Append('[');
for (int i = 1; i < arrayType.Dimensions.Count; i++) {
b.Append(',');
for (int i = 0; i < arrayType.Dimensions.Count; i++) {
if (i > 0)
b.Append(',');
ArrayDimension ad = arrayType.Dimensions[i];
if (ad.IsSized) {
b.Append(ad.LowerBound);
b.Append(':');
b.Append(ad.UpperBound);
}
}
b.Append(']');
}
@ -112,7 +127,7 @@ namespace ICSharpCode.ILSpy.XmlDoc @@ -112,7 +127,7 @@ namespace ICSharpCode.ILSpy.XmlDoc
}
PointerType ptrType = type as PointerType;
if (ptrType != null) {
b.Append('*'); // TODO: is this correct?
b.Append('*');
}
} else {
GenericParameter gp = type as GenericParameter;
@ -183,7 +198,7 @@ namespace ICSharpCode.ILSpy.XmlDoc @@ -183,7 +198,7 @@ namespace ICSharpCode.ILSpy.XmlDoc
Debug.WriteLine(memberKey);
if (memberKey == key)
return member;
if (shortName == member.Name)
if (shortName == member.Name.Replace('.', '#'))
shortNameMatch = member;
}
// if there's no match by ID string (key), return the match by name.

92
NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs

@ -1,92 +0,0 @@ @@ -1,92 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.VB.Ast;
namespace ICSharpCode.NRefactory.VB.AstBuilder
{
/// <summary>
/// Extension methods for NRefactory.Dom.Expression.
/// </summary>
public static class ExpressionBuilder
{/*
public static SimpleNameExpression Identifier(string identifier)
{
return new SimpleNameExpression(identifier);
}
public static MemberReferenceExpression Member(this Expression targetObject, string memberName)
{
if (targetObject == null)
throw new ArgumentNullException("targetObject");
return new MemberReferenceExpression(targetObject, memberName);
}
public static InvocationExpression Call(this Expression callTarget, string methodName, params Expression[] arguments)
{
if (callTarget == null)
throw new ArgumentNullException("callTarget");
return Call(Member(callTarget, methodName), arguments);
}
public static InvocationExpression Call(this Expression callTarget, params Expression[] arguments)
{
if (callTarget == null)
throw new ArgumentNullException("callTarget");
if (arguments == null)
throw new ArgumentNullException("arguments");
return new InvocationExpression(callTarget, new List<Expression>(arguments));
}
public static ObjectCreateExpression New(this TypeReference createType, params Expression[] arguments)
{
if (createType == null)
throw new ArgumentNullException("createType");
if (arguments == null)
throw new ArgumentNullException("arguments");
return new ObjectCreateExpression(createType, new List<Expression>(arguments));
}
public static Expression CreateDefaultValueForType(TypeReference type)
{
if (type != null && !type.IsArrayType) {
switch (type.Type) {
case "System.SByte":
case "System.Byte":
case "System.Int16":
case "System.UInt16":
case "System.Int32":
case "System.UInt32":
case "System.Int64":
case "System.UInt64":
case "System.Single":
case "System.Double":
return new PrimitiveExpression(0, "0");
case "System.Char":
return new PrimitiveExpression('\0', "'\\0'");
case "System.Object":
case "System.String":
return new PrimitiveExpression(null, "null");
case "System.Boolean":
return new PrimitiveExpression(false, "false");
default:
return new DefaultValueExpression(type);
}
} else {
return new PrimitiveExpression(null, "null");
}
}
/// <summary>
/// Just calls the BinaryOperatorExpression constructor,
/// but being an extension method; this allows for a nicer
/// infix syntax in some cases.
/// </summary>
public static BinaryOperatorExpression Operator(this Expression left, BinaryOperatorType op, Expression right)
{
return new BinaryOperatorExpression(left, op, right);
}*/
}
}

55
NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs

@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.VB.Ast;
namespace ICSharpCode.NRefactory.VB.AstBuilder
{
/// <summary>
/// Extension methods for NRefactory.Dom.Expression.
/// </summary>
// public static class StatementBuilder
// {
// public static void AddStatement(this BlockStatement block, Statement statement)
// {
// if (block == null)
// throw new ArgumentNullException("block");
// if (statement == null)
// throw new ArgumentNullException("statement");
// block.AddChild(statement);
// statement.Parent = block;
// }
//
// public static void AddStatement(this BlockStatement block, Expression expressionStatement)
// {
// if (expressionStatement == null)
// throw new ArgumentNullException("expressionStatement");
// AddStatement(block, new ExpressionStatement(expressionStatement));
// }
//
// public static void Throw(this BlockStatement block, Expression expression)
// {
// if (expression == null)
// throw new ArgumentNullException("expression");
// AddStatement(block, new ThrowStatement(expression));
// }
//
// public static void Return(this BlockStatement block, Expression expression)
// {
// if (expression == null)
// throw new ArgumentNullException("expression");
// AddStatement(block, new ReturnStatement(expression));
// }
//
// public static void Assign(this BlockStatement block, Expression left, Expression right)
// {
// if (left == null)
// throw new ArgumentNullException("left");
// if (right == null)
// throw new ArgumentNullException("right");
// AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right));
// }
// }
}

6
NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -45,8 +45,6 @@ @@ -45,8 +45,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AstBuilder\ExpressionBuilder.cs" />
<Compile Include="AstBuilder\StatementBuilder.cs" />
<Compile Include="Ast\AstLocation.cs" />
<Compile Include="Ast\AstNode.cs" />
<Compile Include="Ast\AstNodeCollection.cs" />
@ -180,14 +178,10 @@ @@ -180,14 +178,10 @@
<Compile Include="PrettyPrinter\VBNet\VBNetPrettyPrintOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VBParser.cs" />
<Compile Include="Visitors\AbstractAstTransformer.cs" />
<Compile Include="Visitors\AbstractAstVisitor.cs" />
<Compile Include="Visitors\CSharpToVBConverterVisitor.cs" />
<Compile Include="Visitors\NodeTrackingAstVisitor.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Ast" />
<Folder Include="AstBuilder" />
<Folder Include="Ast\General" />
<Folder Include="Ast\GlobalScope" />
<Folder Include="Ast\Expressions" />

11
NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.NRefactory.VB @@ -115,7 +115,7 @@ namespace ICSharpCode.NRefactory.VB
StartNode(parameterDeclaration);
WriteAttributes(parameterDeclaration.Attributes);
WriteModifiers(parameterDeclaration.ModifierTokens);
WriteIdentifier(parameterDeclaration.Name.Name);
parameterDeclaration.Name.AcceptVisitor(this, data);
if (!parameterDeclaration.Type.IsNull) {
WriteKeyword("As");
parameterDeclaration.Type.AcceptVisitor(this, data);
@ -1053,7 +1053,7 @@ namespace ICSharpCode.NRefactory.VB @@ -1053,7 +1053,7 @@ namespace ICSharpCode.NRefactory.VB
#endregion
#region IsKeyword Test
static readonly HashSet<string> unconditionalKeywords = new HashSet<string> {
static readonly HashSet<string> unconditionalKeywords = new HashSet<string>(StringComparer.OrdinalIgnoreCase) {
"AddHandler", "AddressOf", "Alias", "And", "AndAlso", "As", "Boolean", "ByRef", "Byte",
"ByVal", "Call", "Case", "Catch", "CBool", "CByte", "CChar", "CInt", "Class", "CLng",
"CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt",
@ -1705,6 +1705,11 @@ namespace ICSharpCode.NRefactory.VB @@ -1705,6 +1705,11 @@ namespace ICSharpCode.NRefactory.VB
WriteCommaSeparatedListInParenthesis(objectCreationExpression.Arguments, false);
if (!objectCreationExpression.Initializer.IsNull) {
Space();
if (objectCreationExpression.Initializer.Elements.Any(x => x is FieldInitializerExpression))
WriteKeyword("With");
else
WriteKeyword("From");
Space();
objectCreationExpression.Initializer.AcceptVisitor(this, data);
}
@ -1870,7 +1875,7 @@ namespace ICSharpCode.NRefactory.VB @@ -1870,7 +1875,7 @@ namespace ICSharpCode.NRefactory.VB
{
StartNode(fieldInitializerExpression);
if (fieldInitializerExpression.IsKey) {
if (fieldInitializerExpression.IsKey && fieldInitializerExpression.Parent is AnonymousObjectCreationExpression) {
WriteKeyword("Key");
Space();
}

2078
NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstTransformer.cs

File diff suppressed because it is too large Load Diff

1156
NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstVisitor.cs

File diff suppressed because it is too large Load Diff

1266
NRefactory/ICSharpCode.NRefactory.VB/Visitors/NodeTrackingAstVisitor.cs

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save