Browse Source

Fixed SD2-930: VB exponential operator not converted to C#

Fixed SD2-879: Folding breaks with consecutive operators in VB code
Fixed SD2-906: Folding breaks on VB property declaration
Fixed SD2-921: Definitions in one line converted incorrectly from VB to C#
Fixed SD2-903: 'Using' statement not converted correctly from VB to C#
Fixed SD2-890: 'uint' type converted incorrectly from C# to VB
Fixed SD2-907: static method level variables are not translated from VB to C#

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1605 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
720d93d03f
  1. 2
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs
  2. 6
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs
  3. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Statements.cs
  4. 8
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs
  5. 3
      src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs
  6. 2
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  7. 2
      src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs
  8. 2
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  9. 2
      src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs
  10. 25
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  11. 2
      src/Libraries/NRefactory/Project/Src/Output/CodeDOM/CodeDOMOutputVisitor.cs
  12. 6
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  13. 85
      src/Libraries/NRefactory/Project/Src/Parser/AST/Generated.cs
  14. 1685
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  15. 73
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  16. 4
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs
  17. 10
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractAstTransformer.cs
  18. 4
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/PrefixFieldsVisitor.cs
  19. 43
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToCSharpConvertVisitor.cs
  20. 2
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs
  21. 17
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  22. 57
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  23. 6
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs
  24. 17
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  25. 14
      src/Libraries/NRefactory/Test/Parser/Expressions/IndexerExpressionTests.cs
  26. 18
      src/Libraries/NRefactory/Test/Parser/Expressions/UnaryOperatorExpressionTests.cs
  27. 36
      src/Libraries/NRefactory/Test/Parser/TypeLevel/FieldDeclarationTests.cs
  28. 4
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

2
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs

@ -496,7 +496,7 @@ namespace NRefactoryToBooConverter @@ -496,7 +496,7 @@ namespace NRefactoryToBooConverter
{
B.SlicingExpression s = new B.SlicingExpression(GetLexicalInfo(indexerExpression));
s.Target = ConvertExpression(indexerExpression.TargetObject);
foreach (Expression expr in indexerExpression.Indices) {
foreach (Expression expr in indexerExpression.Indexes) {
s.Indices.Add(new B.Slice(ConvertExpression(expr)));
}
return s;

6
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs

@ -11,7 +11,7 @@ using System.Collections.Generic; @@ -11,7 +11,7 @@ using System.Collections.Generic;
namespace NRefactoryASTGenerator.Ast
{
[CustomImplementation]
abstract class Expression : AbstractNode {}
abstract class Expression : AbstractNode, INullable {}
[CustomImplementation]
class PrimitiveExpression : Expression {}
@ -189,9 +189,9 @@ namespace NRefactoryASTGenerator.Ast @@ -189,9 +189,9 @@ namespace NRefactoryASTGenerator.Ast
class IndexerExpression : Expression {
Expression targetObject;
List<Expression> indices;
List<Expression> indexes;
public IndexerExpression(Expression targetObject, List<Expression> indices) {}
public IndexerExpression(Expression targetObject, List<Expression> indexes) {}
}
class PointerReferenceExpression : Expression {

2
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Statements.cs

@ -11,7 +11,7 @@ using System.Collections.Generic; @@ -11,7 +11,7 @@ using System.Collections.Generic;
namespace NRefactoryASTGenerator.Ast
{
[CustomImplementation]
abstract class Statement : AbstractNode {}
abstract class Statement : AbstractNode, INullable {}
[CustomImplementation]
abstract class StatementWithEmbeddedStatement : Statement {

8
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs

@ -114,13 +114,7 @@ namespace NRefactoryASTGenerator.Ast @@ -114,13 +114,7 @@ namespace NRefactoryASTGenerator.Ast
if (!typeReference.IsNull) {
return typeReference;
}
for (int i = fieldIndex; i < Fields.Count;++i) {
if (!((VariableDeclaration)Fields[i]).TypeReference.IsNull) {
return ((VariableDeclaration)Fields[i]).TypeReference;
}
}
return TypeReference.Null;
return ((VariableDeclaration)Fields[fieldIndex]).TypeReference;
}")]
[IncludeMember(@"
public VariableDeclaration GetVariableDeclaration(string variableName)

3
src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs

@ -397,6 +397,9 @@ namespace NRefactoryASTGenerator @@ -397,6 +397,9 @@ namespace NRefactoryASTGenerator
else
ex = GetDefaultValue("value", field);
p.SetStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(field.Name), ex));
if (typeof(INode).IsAssignableFrom(field.FieldType) && typeof(INullable).IsAssignableFrom(field.FieldType)) {
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\tif (!" +field.Name+".IsNull) "+field.Name+".Parent = this;"));
}
ctd.Members.Add(p);
}
foreach (ConstructorInfo ctor in type.GetConstructors()) {

2
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Location start = new Location(Col - 1, Line);
string directive = ReadIdent('#');
string argument = ReadToEndOfLine();
this.specialTracker.AddPreProcessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y));
this.specialTracker.AddPreprocessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y));
}
protected override Token Next()

2
src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Parser
currentSpecials.Add(new BlankLine(point));
}
public void AddPreProcessingDirective(string cmd, string arg, Location start, Location end)
public void AddPreprocessingDirective(string cmd, string arg, Location start, Location end)
{
currentSpecials.Add(new PreprocessingDirective(cmd, arg, start, end));
}

2
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs

@ -476,7 +476,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -476,7 +476,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
Location start = new Location(Col - 1, Line);
string directive = ReadIdent('#');
string argument = ReadToEndOfLine();
this.specialTracker.AddPreProcessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y));
this.specialTracker.AddPreprocessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y));
}
string ReadDate()

2
src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
public AbstractOutputFormatter(AbstractPrettyPrintOptions prettyPrintOptions)
protected AbstractOutputFormatter(AbstractPrettyPrintOptions prettyPrintOptions)
{
this.prettyPrintOptions = prettyPrintOptions;
}

25
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -534,6 +534,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -534,6 +534,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
this.VisitAttributes(propertyGetRegion.Attributes, data);
outputFormatter.Indent();
OutputModifier(propertyGetRegion.Modifier);
outputFormatter.PrintText("get");
OutputBlock(propertyGetRegion.Block, prettyPrintOptions.PropertyGetBraceStyle);
return null;
@ -543,6 +544,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -543,6 +544,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
this.VisitAttributes(propertySetRegion.Attributes, data);
outputFormatter.Indent();
OutputModifier(propertySetRegion.Modifier);
outputFormatter.PrintText("set");
OutputBlock(propertySetRegion.Block, prettyPrintOptions.PropertySetBraceStyle);
return null;
@ -1717,6 +1719,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1717,6 +1719,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data);
PrintFormattedComma();
nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
case BinaryOperatorType.Power:
outputFormatter.PrintText("Math.Pow");
if (prettyPrintOptions.BeforeMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data);
PrintFormattedComma();
@ -1911,6 +1924,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1911,6 +1924,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
}
break;
default:
errors.Error(-1, -1, String.Format("Unknown binary operator {0}", binaryOperatorExpression.Op));
return null;
@ -2044,6 +2058,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2044,6 +2058,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
case AssignmentOperatorType.BitwiseOr:
outputFormatter.PrintToken(Tokens.BitwiseOrAssign);
break;
case AssignmentOperatorType.Power:
outputFormatter.PrintToken(Tokens.Assign);
if (this.prettyPrintOptions.AroundAssignmentParentheses) {
outputFormatter.Space();
}
Visit(new BinaryOperatorExpression(assignmentExpression.Left,
BinaryOperatorType.Power,
assignmentExpression.Right), data);
return null;
default:
errors.Error(-1, -1, String.Format("Unknown assignment operator {0}", assignmentExpression.Op));
return null;
@ -2196,7 +2219,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2196,7 +2219,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}
AppendCommaSeparatedList(indexerExpression.Indices);
AppendCommaSeparatedList(indexerExpression.Indexes);
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}

2
src/Libraries/NRefactory/Project/Src/Output/CodeDOM/CodeDOMOutputVisitor.cs

@ -725,7 +725,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -725,7 +725,7 @@ namespace ICSharpCode.NRefactory.Parser
public override object Visit(IndexerExpression indexerExpression, object data)
{
return new CodeIndexerExpression((CodeExpression)indexerExpression.TargetObject.AcceptVisitor(this, data), GetExpressionList(indexerExpression.Indices));
return new CodeIndexerExpression((CodeExpression)indexerExpression.TargetObject.AcceptVisitor(this, data), GetExpressionList(indexerExpression.Indexes));
}
public override object Visit(ThisReferenceExpression thisReferenceExpression, object data)

6
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -114,7 +114,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -114,7 +114,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
case "System.UInt64":
return "ULong";
case "System.UInt32":
return "UInt";
return "UInteger";
case "System.UInt16":
return "UShort";
case "System.SByte":
@ -589,6 +589,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -589,6 +589,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
VisitAttributes(propertyGetRegion.Attributes, data);
outputFormatter.Indent();
OutputModifier(propertyGetRegion.Modifier);
outputFormatter.PrintToken(Tokens.Get);
outputFormatter.NewLine();
@ -607,6 +608,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -607,6 +608,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
VisitAttributes(propertySetRegion.Attributes, data);
outputFormatter.Indent();
OutputModifier(propertySetRegion.Modifier);
outputFormatter.PrintToken(Tokens.Set);
outputFormatter.NewLine();
@ -2421,7 +2423,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2421,7 +2423,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
nodeTracker.TrackedVisit(indexerExpression.TargetObject, data);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(indexerExpression.Indices);
AppendCommaSeparatedList(indexerExpression.Indexes);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
}

85
src/Libraries/NRefactory/Project/Src/Parser/AST/Generated.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
eventExpression = value ?? Expression.Null;
if (!eventExpression.IsNull) eventExpression.Parent = this;
}
}
@ -35,6 +36,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -35,6 +36,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
handlerExpression = value ?? Expression.Null;
if (!handlerExpression.IsNull) handlerExpression.Parent = this;
}
}
@ -62,6 +64,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -62,6 +64,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -99,6 +102,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -99,6 +102,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
body = value ?? BlockStatement.Null;
if (!body.IsNull) body.Parent = this;
}
}
@ -148,6 +152,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -148,6 +152,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
arrayInitializer = value ?? ArrayInitializerExpression.Null;
if (!arrayInitializer.IsNull) arrayInitializer.Parent = this;
}
}
@ -256,6 +261,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -256,6 +261,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
left = value ?? Expression.Null;
if (!left.IsNull) left.Parent = this;
}
}
@ -274,6 +280,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -274,6 +280,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
right = value ?? Expression.Null;
if (!right.IsNull) right.Parent = this;
}
}
@ -442,6 +449,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -442,6 +449,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
left = value ?? Expression.Null;
if (!left.IsNull) left.Parent = this;
}
}
@ -460,6 +468,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -460,6 +468,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
right = value ?? Expression.Null;
if (!right.IsNull) right.Parent = this;
}
}
@ -506,6 +515,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -506,6 +515,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
label = value ?? Expression.Null;
if (!label.IsNull) label.Parent = this;
}
}
@ -524,6 +534,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -524,6 +534,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
toExpression = value ?? Expression.Null;
if (!toExpression.IsNull) toExpression.Parent = this;
}
}
@ -586,6 +597,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -586,6 +597,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -652,6 +664,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -652,6 +664,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
statementBlock = value ?? Statement.Null;
if (!statementBlock.IsNull) statementBlock.Parent = this;
}
}
@ -661,6 +674,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -661,6 +674,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
condition = value ?? Expression.Null;
if (!condition.IsNull) condition.Parent = this;
}
}
@ -705,6 +719,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -705,6 +719,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -731,6 +746,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -731,6 +746,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
block = value ?? Statement.Null;
if (!block.IsNull) block.Parent = this;
}
}
@ -775,6 +791,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -775,6 +791,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
condition = value ?? Expression.Null;
if (!condition.IsNull) condition.Parent = this;
}
}
@ -784,6 +801,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -784,6 +801,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
trueExpression = value ?? Expression.Null;
if (!trueExpression.IsNull) trueExpression.Parent = this;
}
}
@ -793,6 +811,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -793,6 +811,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
falseExpression = value ?? Expression.Null;
if (!falseExpression.IsNull) falseExpression.Parent = this;
}
}
@ -832,6 +851,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -832,6 +851,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
body = value ?? BlockStatement.Null;
if (!body.IsNull) body.Parent = this;
}
}
@ -1139,6 +1159,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1139,6 +1159,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
body = value ?? BlockStatement.Null;
if (!body.IsNull) body.Parent = this;
}
}
@ -1179,6 +1200,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1179,6 +1200,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -1210,6 +1232,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1210,6 +1232,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
condition = value ?? Expression.Null;
if (!condition.IsNull) condition.Parent = this;
}
}
@ -1258,6 +1281,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1258,6 +1281,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
condition = value ?? Expression.Null;
if (!condition.IsNull) condition.Parent = this;
}
}
@ -1343,6 +1367,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1343,6 +1367,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -1421,6 +1446,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1421,6 +1446,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
block = value ?? BlockStatement.Null;
if (!block.IsNull) block.Parent = this;
}
}
@ -1745,13 +1771,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1745,13 +1771,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
if (!typeReference.IsNull) {
return typeReference;
}
for (int i = fieldIndex; i < Fields.Count;++i) {
if (!((VariableDeclaration)Fields[i]).TypeReference.IsNull) {
return ((VariableDeclaration)Fields[i]).TypeReference;
}
}
return TypeReference.Null;
return ((VariableDeclaration)Fields[fieldIndex]).TypeReference;
}
@ -1786,6 +1806,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1786,6 +1806,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
targetObject = value ?? Expression.Null;
if (!targetObject.IsNull) targetObject.Parent = this;
}
}
@ -1885,6 +1906,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1885,6 +1906,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -1894,6 +1916,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1894,6 +1916,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
nextExpression = value ?? Expression.Null;
if (!nextExpression.IsNull) nextExpression.Parent = this;
}
}
@ -1943,6 +1966,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1943,6 +1966,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
start = value ?? Expression.Null;
if (!start.IsNull) start.Parent = this;
}
}
@ -1952,6 +1976,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1952,6 +1976,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
end = value ?? Expression.Null;
if (!end.IsNull) end.Parent = this;
}
}
@ -1961,6 +1986,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -1961,6 +1986,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
step = value ?? Expression.Null;
if (!step.IsNull) step.Parent = this;
}
}
@ -2034,6 +2060,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2034,6 +2060,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
condition = value ?? Expression.Null;
if (!condition.IsNull) condition.Parent = this;
}
}
@ -2072,6 +2099,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2072,6 +2099,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -2162,6 +2190,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2162,6 +2190,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
condition = value ?? Expression.Null;
if (!condition.IsNull) condition.Parent = this;
}
}
@ -2376,7 +2405,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2376,7 +2405,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
Expression targetObject;
List<Expression> indices;
List<Expression> indexes;
public Expression TargetObject {
get {
@ -2384,21 +2413,22 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2384,21 +2413,22 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
targetObject = value ?? Expression.Null;
if (!targetObject.IsNull) targetObject.Parent = this;
}
}
public List<Expression> Indices {
public List<Expression> Indexes {
get {
return indices;
return indexes;
}
set {
indices = value ?? new List<Expression>();
indexes = value ?? new List<Expression>();
}
}
public IndexerExpression(Expression targetObject, List<Expression> indices) {
public IndexerExpression(Expression targetObject, List<Expression> indexes) {
TargetObject = targetObject;
Indices = indices;
Indexes = indexes;
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
@ -2406,7 +2436,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2406,7 +2436,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
public override string ToString() {
return string.Format("[IndexerExpression TargetObject={0} Indices={1}]", TargetObject, GetCollectionString(Indices));
return string.Format("[IndexerExpression TargetObject={0} Indexes={1}]", TargetObject, GetCollectionString(Indexes));
}
}
@ -2462,6 +2492,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2462,6 +2492,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
targetObject = value ?? Expression.Null;
if (!targetObject.IsNull) targetObject.Parent = this;
}
}
@ -2546,6 +2577,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2546,6 +2577,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
lockExpression = value ?? Expression.Null;
if (!lockExpression.IsNull) lockExpression.Parent = this;
}
}
@ -2590,6 +2622,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2590,6 +2622,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
body = value ?? BlockStatement.Null;
if (!body.IsNull) body.Parent = this;
}
}
@ -2660,6 +2693,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2660,6 +2693,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -2912,6 +2946,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2912,6 +2946,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
defaultValue = value ?? Expression.Null;
if (!defaultValue.IsNull) defaultValue.Parent = this;
}
}
@ -2997,6 +3032,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -2997,6 +3032,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -3025,6 +3061,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3025,6 +3061,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
targetObject = value ?? Expression.Null;
if (!targetObject.IsNull) targetObject.Parent = this;
}
}
@ -3235,6 +3272,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3235,6 +3272,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
block = value ?? BlockStatement.Null;
if (!block.IsNull) block.Parent = this;
}
}
@ -3400,6 +3438,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3400,6 +3438,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
eventExpression = value ?? Expression.Null;
if (!eventExpression.IsNull) eventExpression.Parent = this;
}
}
@ -3409,6 +3448,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3409,6 +3448,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
handlerExpression = value ?? Expression.Null;
if (!handlerExpression.IsNull) handlerExpression.Parent = this;
}
}
@ -3478,6 +3518,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3478,6 +3518,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -3541,6 +3582,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3541,6 +3582,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -3568,6 +3610,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3568,6 +3610,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -3640,6 +3683,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3640,6 +3683,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
switchExpression = value ?? Expression.Null;
if (!switchExpression.IsNull) switchExpression.Parent = this;
}
}
@ -3729,6 +3773,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3729,6 +3773,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -3759,6 +3804,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3759,6 +3804,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
statementBlock = value ?? Statement.Null;
if (!statementBlock.IsNull) statementBlock.Parent = this;
}
}
@ -3777,6 +3823,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3777,6 +3823,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
finallyBlock = value ?? Statement.Null;
if (!finallyBlock.IsNull) finallyBlock.Parent = this;
}
}
@ -3909,6 +3956,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast { @@ -3909,6 +3956,7 @@ namespace ICSharpCode.NRefactory.Parser.Ast {
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -3984,6 +4032,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam @@ -3984,6 +4032,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -4016,6 +4065,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam @@ -4016,6 +4065,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -4042,6 +4092,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam @@ -4042,6 +4092,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam
}
set {
block = value ?? Statement.Null;
if (!block.IsNull) block.Parent = this;
}
}
@ -4068,6 +4119,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam @@ -4068,6 +4119,7 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam
}
set {
block = value ?? Statement.Null;
if (!block.IsNull) block.Parent = this;
}
}
@ -4173,6 +4225,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li @@ -4173,6 +4225,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li
}
set {
resourceAcquisition = value ?? Statement.Null;
if (!resourceAcquisition.IsNull) resourceAcquisition.Parent = this;
}
}
@ -4213,6 +4266,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li @@ -4213,6 +4266,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li
}
set {
initializer = value ?? Expression.Null;
if (!initializer.IsNull) initializer.Parent = this;
}
}
@ -4264,6 +4318,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li @@ -4264,6 +4318,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li
}
set {
expression = value ?? Expression.Null;
if (!expression.IsNull) expression.Parent = this;
}
}
@ -4273,6 +4328,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li @@ -4273,6 +4328,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li
}
set {
body = value ?? BlockStatement.Null;
if (!body.IsNull) body.Parent = this;
}
}
@ -4300,6 +4356,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li @@ -4300,6 +4356,7 @@ public UsingDeclaration(string nameSpace, TypeReference alias) { usings = new Li
}
set {
statement = value ?? Statement.Null;
if (!statement.IsNull) statement.Parent = this;
}
}

1685
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

73
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -947,7 +947,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -947,7 +947,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
(. Location startPos = t.Location; .)
(.
m.Check(Modifier.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
IdentifierForFieldDeclaration (. string name = t.val; .)
@ -1255,13 +1255,16 @@ AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock> @@ -1255,13 +1255,16 @@ AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
/* 9.7.1 */
GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
(. Statement stmt = null; .) =
(. Statement stmt = null; Modifier m; .)
=
PropertyAccessorAccessModifier<out m>
"Get"
(. Location startLocation = t.Location; .)
EOL
Block<out stmt>
(. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
"End" "Get"
(. getBlock.Modifier = m; .)
(. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
EOL
.
@ -1269,8 +1272,12 @@ GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attribute @@ -1269,8 +1272,12 @@ GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attribute
/* 9.7.2 */
SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
(.
Statement stmt = null; List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
.) =
Statement stmt = null;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
Modifier m;
.)
=
PropertyAccessorAccessModifier<out m>
"Set"
(. Location startLocation = t.Location; .)
[ "(" [ FormalParameterList<p> ] ")" ]
@ -1278,6 +1285,7 @@ SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attribute @@ -1278,6 +1285,7 @@ SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attribute
Block<out stmt>
(.
setBlock = new PropertySetRegion((BlockStatement)stmt, attributes);
setBlock.Modifier = m;
setBlock.Parameters = p;
.)
"End" "Set"
@ -1328,9 +1336,22 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration @@ -1328,9 +1336,22 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
}
.)
|
[ "As" TypeName<out type> ]
[ "As" TypeName<out type>
(.
for (int i = fieldDeclaration.Count - 1; i >= 0; i--) {
VariableDeclaration vd = fieldDeclaration[i];
if (vd.TypeReference.Type.Length > 0) break;
TypeReference newType = type.Clone();
newType.RankSpecifier = vd.TypeReference.RankSpecifier;
vd.TypeReference = newType;
}
.)
]
(.
if (type != null && dimension != null) {
if (type == null && (dimension != null || rank != null)) {
type = new TypeReference("");
}
if (dimension != null) {
if(type.RankSpecifier != null) {
Error("array rank only allowed one time");
} else {
@ -1344,7 +1365,7 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration @@ -1344,7 +1365,7 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
}
expr = new ArrayCreateExpression(type, dimension);
}
} else if (type != null && rank != null) {
} else if (rank != null) {
if(type.RankSpecifier != null) {
Error("array rank only allowed one time");
} else {
@ -1695,7 +1716,12 @@ ComparisonExpr<out Expression outExpr> @@ -1695,7 +1716,12 @@ ComparisonExpr<out Expression outExpr>
| "Is" (. op = BinaryOperatorType.ReferenceEquality; .)
| "IsNot" (. op = BinaryOperatorType.ReferenceInequality; .)
)
ShiftExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
(
ShiftExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
|
"Not"
ShiftExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, new UnaryOperatorExpression(expr, UnaryOperatorType.Not)); .)
)
}
.
@ -2188,7 +2214,7 @@ LocalDeclarationStatement<out Statement statement> @@ -2188,7 +2214,7 @@ LocalDeclarationStatement<out Statement statement>
(.
statement = localVariableDeclaration;
.)
.
.
EmbeddedStatement<out Statement statement>
(.
@ -2440,15 +2466,20 @@ EmbeddedStatement<out Statement statement> @@ -2440,15 +2466,20 @@ EmbeddedStatement<out Statement statement>
.)
| "Call" SimpleExpr<out expr> (. statement = new StatementExpression(expr); .)
| "Using"
(. LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifier.None); .)
(. Statement block; .)
VariableDeclarator<resourceAquisition.Variables>
{ ","
VariableDeclarator<resourceAquisition.Variables>
}
Block<out block>
( IF (Peek(1).kind == Tokens.As)
(. LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifier.None); .)
VariableDeclarator<resourceAquisition.Variables>
{ ","
VariableDeclarator<resourceAquisition.Variables>
}
Block<out block>
(. statement = new UsingStatement(resourceAquisition, block); .)
| Expr<out expr>
Block<out block>
(. statement = new UsingStatement(new StatementExpression(expr), block); .)
)
"End" "Using"
(. statement = new UsingStatement(resourceAquisition, block); .)
.
/* 10.9.2 */
@ -2775,4 +2806,14 @@ MemberModifier<Modifiers m> = @@ -2775,4 +2806,14 @@ MemberModifier<Modifiers m> =
| "Dim" (.m.Add(Modifier.Dim, t.Location);.)
.
PropertyAccessorAccessModifier<out Modifier m> =
(. m = Modifier.None; .)
{(
"Public" (. m |= Modifier.Public; .)
| "Protected" (. m |= Modifier.Protected; .)
| "Friend" (. m |= Modifier.Internal; .)
| "Private" (. m |= Modifier.Private; .)
)}
.
END VBNET.

4
src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs

@ -549,9 +549,9 @@ namespace ICSharpCode.NRefactory.Parser { @@ -549,9 +549,9 @@ namespace ICSharpCode.NRefactory.Parser {
public virtual object Visit(IndexerExpression indexerExpression, object data) {
Debug.Assert((indexerExpression != null));
Debug.Assert((indexerExpression.TargetObject != null));
Debug.Assert((indexerExpression.Indices != null));
Debug.Assert((indexerExpression.Indexes != null));
indexerExpression.TargetObject.AcceptVisitor(this, data);
foreach (Expression o in indexerExpression.Indices) {
foreach (Expression o in indexerExpression.Indexes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}

10
src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractAstTransformer.cs

@ -1001,20 +1001,20 @@ namespace ICSharpCode.NRefactory.Parser { @@ -1001,20 +1001,20 @@ namespace ICSharpCode.NRefactory.Parser {
public virtual object Visit(IndexerExpression indexerExpression, object data) {
Debug.Assert((indexerExpression != null));
Debug.Assert((indexerExpression.TargetObject != null));
Debug.Assert((indexerExpression.Indices != null));
Debug.Assert((indexerExpression.Indexes != null));
nodeStack.Push(indexerExpression.TargetObject);
indexerExpression.TargetObject.AcceptVisitor(this, data);
indexerExpression.TargetObject = ((Expression)(nodeStack.Pop()));
for (int i = 0; i < indexerExpression.Indices.Count; i++) {
Expression o = indexerExpression.Indices[i];
for (int i = 0; i < indexerExpression.Indexes.Count; i++) {
Expression o = indexerExpression.Indexes[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (Expression)nodeStack.Pop();
if (o == null)
indexerExpression.Indices.RemoveAt(i--);
indexerExpression.Indexes.RemoveAt(i--);
else
indexerExpression.Indices[i] = o;
indexerExpression.Indexes[i] = o;
}
return null;
}

4
src/Libraries/NRefactory/Project/Src/Parser/Visitors/PrefixFieldsVisitor.cs

@ -27,9 +27,9 @@ namespace ICSharpCode.NRefactory.Parser @@ -27,9 +27,9 @@ namespace ICSharpCode.NRefactory.Parser
this.prefix = prefix;
}
public void Run(TypeDeclaration typeDeclaration)
public void Run(INode typeDeclaration)
{
typeDeclaration.AcceptChildren(this, null);
typeDeclaration.AcceptVisitor(this, null);
foreach (VariableDeclaration decl in fields) {
decl.Name = prefix + decl.Name;
}

43
src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToCSharpConvertVisitor.cs

@ -44,5 +44,48 @@ namespace ICSharpCode.NRefactory.Parser @@ -44,5 +44,48 @@ namespace ICSharpCode.NRefactory.Parser
}
return base.Visit(eventDeclaration, data);
}
public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
{
base.Visit(localVariableDeclaration, data);
if ((localVariableDeclaration.Modifier & Modifier.Static) == Modifier.Static) {
INode parent = localVariableDeclaration.Parent;
while (parent != null && !IsTypeLevel(parent)) {
parent = parent.Parent;
}
if (parent != null) {
INode type = parent.Parent;
if (type != null) {
int pos = type.Children.IndexOf(parent);
if (pos >= 0) {
FieldDeclaration field = new FieldDeclaration(null);
field.TypeReference = localVariableDeclaration.TypeReference;
field.Modifier = Modifier.Static;
field.Fields = localVariableDeclaration.Variables;
new PrefixFieldsVisitor(field.Fields, "static_" + GetTypeLevelEntityName(parent) + "_").Run(parent);
type.Children.Insert(pos + 1, field);
RemoveCurrentNode();
}
}
}
}
return null;
}
static bool IsTypeLevel(INode node)
{
return node is MethodDeclaration || node is PropertyDeclaration || node is EventDeclaration
|| node is OperatorDeclaration || node is FieldDeclaration;
}
static string GetTypeLevelEntityName(INode node)
{
if (node is ParametrizedNode)
return ((ParametrizedNode)node).Name;
else if (node is FieldDeclaration)
return ((FieldDeclaration)node).Fields[0].Name;
else
throw new ArgumentException();
}
}
}

2
src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs

@ -390,6 +390,8 @@ namespace ICSharpCode.NRefactory.Parser @@ -390,6 +390,8 @@ namespace ICSharpCode.NRefactory.Parser
boe.Op = BinaryOperatorType.ReferenceInequality;
ReplaceCurrentNode(pe);
}
} else if (unaryOperatorExpression.Expression is BinaryOperatorExpression) {
unaryOperatorExpression.Expression = new ParenthesizedExpression(unaryOperatorExpression.Expression);
}
}
return null;

17
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -359,5 +359,22 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -359,5 +359,22 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestTypeMember("public static TheBug operator +(TheBug bugNode, TheBug bugNode2) { }");
TestTypeMember("public static TheBug operator >>(TheBug bugNode, int b) { }");
}
[Test]
public void PropertyWithAccessorAccessModifiers()
{
TestTypeMember("public bool ExpectsValue {\n" +
"\tinternal get {\n" +
"\t}\n" +
"\tprotected set {\n" +
"\t}\n" +
"}");
}
[Test]
public void UsingStatementForExistingVariable()
{
TestStatement("using (obj) {\n}");
}
}
}

57
src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs

@ -416,5 +416,62 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -416,5 +416,62 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"\treturn " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
"}");
}
[Test]
public void Exponentiation()
{
TestStatement("i = i ^ 2", "i = Math.Pow(i, 2);");
TestStatement("i ^= 2", "i = Math.Pow(i, 2);");
}
[Test]
public void AddNotParenthesis()
{
TestStatement("a = Not b = c", "a = !(b == c);");
}
[Test]
public void StaticMethodVariable()
{
TestMember(@"Private Sub Test
Static j As Integer = 0
j += 1
End Sub",
@"private void Test()
{
static_Test_j += 1;
}
static int static_Test_j = 0;");
}
[Test]
public void StaticMethodVariable2()
{
TestMember(@"Private Sub Test
Static j As Integer = 0
j += 1
End Sub
Private Sub Test2
Static j As Integer = 0
j += 2
End Sub",
@"private void Test()
{
static_Test_j += 1;
}
static int static_Test_j = 0;
private void Test2()
{
static_Test2_j += 2;
}
static int static_Test2_j = 0;");
}
[Test]
public void UsingStatementForExistingVariable()
{
TestStatement("Using sw\nEnd Using",
"using (sw) {\n}");
}
}
}

6
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

@ -345,5 +345,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -345,5 +345,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"\texample()\n" +
"End While");
}
[Test]
public void UIntVariableDeclaration()
{
TestStatement("uint s = 0;", "Dim s As UInteger = 0");
}
}
}

17
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -274,6 +274,17 @@ End Using"); @@ -274,6 +274,17 @@ End Using");
TestExpression("TypeOf a Is String");
}
[Test]
public void PropertyWithAccessorAccessModifiers()
{
TestTypeMember("Public Property ExpectsValue() As Boolean\n" +
"\tPublic Get\n" +
"\tEnd Get\n" +
"\tProtected Set\n" +
"\tEnd Set\n" +
"End Property");
}
[Test]
public void AbstractProperty()
{
@ -342,5 +353,11 @@ End Using"); @@ -342,5 +353,11 @@ End Using");
TestTypeMember("Public Shared Operator +(ByVal bugNode As TheBug, ByVal bugNode2 As TheBug) As TheBug\nEnd Operator");
TestTypeMember("Public Shared Operator >>(ByVal bugNode As TheBug, ByVal b As Integer) As TheBug\nEnd Operator");
}
[Test]
public void UsingStatementForExistingVariable()
{
TestStatement("Using obj\nEnd Using");
}
}
}

14
src/Libraries/NRefactory/Test/Parser/Expressions/IndexerExpressionTests.cs

@ -23,14 +23,14 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -23,14 +23,14 @@ namespace ICSharpCode.NRefactory.Tests.Ast
IndexerExpression ie = ParseUtilCSharp.ParseExpression<IndexerExpression>("field[1, \"Hello\", 'a']");
Assert.IsTrue(ie.TargetObject is IdentifierExpression);
Assert.AreEqual(3, ie.Indices.Count);
Assert.AreEqual(3, ie.Indexes.Count);
Assert.IsTrue(ie.Indices[0] is PrimitiveExpression);
Assert.AreEqual(1, (int)((PrimitiveExpression)ie.Indices[0]).Value);
Assert.IsTrue(ie.Indices[1] is PrimitiveExpression);
Assert.AreEqual("Hello", (string)((PrimitiveExpression)ie.Indices[1]).Value);
Assert.IsTrue(ie.Indices[2] is PrimitiveExpression);
Assert.AreEqual('a', (char)((PrimitiveExpression)ie.Indices[2]).Value);
Assert.IsTrue(ie.Indexes[0] is PrimitiveExpression);
Assert.AreEqual(1, (int)((PrimitiveExpression)ie.Indexes[0]).Value);
Assert.IsTrue(ie.Indexes[1] is PrimitiveExpression);
Assert.AreEqual("Hello", (string)((PrimitiveExpression)ie.Indexes[1]).Value);
Assert.IsTrue(ie.Indexes[2] is PrimitiveExpression);
Assert.AreEqual('a', (char)((PrimitiveExpression)ie.Indexes[2]).Value);
}
#endregion

18
src/Libraries/NRefactory/Test/Parser/Expressions/UnaryOperatorExpressionTests.cs

@ -101,6 +101,24 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -101,6 +101,24 @@ namespace ICSharpCode.NRefactory.Tests.Ast
VBNetTestUnaryOperatorExpressionTest("Not a", UnaryOperatorType.Not);
}
[Test]
public void VBNetInEqualsNotTest()
{
BinaryOperatorExpression e = ParseUtilVBNet.ParseExpression<BinaryOperatorExpression>("b <> Not a");
Assert.AreEqual(BinaryOperatorType.InEquality, e.Op);
UnaryOperatorExpression ue = (UnaryOperatorExpression)e.Right;
Assert.AreEqual(UnaryOperatorType.Not, ue.Op);
}
[Test]
public void VBNetNotEqualTest()
{
UnaryOperatorExpression e = ParseUtilVBNet.ParseExpression<UnaryOperatorExpression>("Not a = b");
Assert.AreEqual(UnaryOperatorType.Not, e.Op);
BinaryOperatorExpression boe = (BinaryOperatorExpression)e.Expression;
Assert.AreEqual(BinaryOperatorType.Equality, boe.Op);
}
[Test]
public void VBNetPlusTest()
{

36
src/Libraries/NRefactory/Test/Parser/TypeLevel/FieldDeclarationTests.cs

@ -39,6 +39,40 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -39,6 +39,40 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("myField", ((VariableDeclaration)fd.Fields[0]).Name);
Assert.AreEqual(new int[] { 3 } , ((VariableDeclaration)fd.Fields[0]).TypeReference.RankSpecifier);
}
#endregion
[Test]
public void VBNetMultiFieldDeclarationTest()
{
FieldDeclaration fd = ParseUtilVBNet.ParseTypeMember<FieldDeclaration>("a, b As String");
Assert.AreEqual(2, fd.Fields.Count);
Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type);
}
[Test]
public void VBNetMultiFieldDeclarationTest2()
{
FieldDeclaration fd = ParseUtilVBNet.ParseTypeMember<FieldDeclaration>("Dim a, b() As String");
Assert.AreEqual(2, fd.Fields.Count);
Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type);
Assert.IsFalse(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType);
Assert.IsTrue(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType);
}
[Test]
public void VBNetMultiFieldDeclarationTest3()
{
FieldDeclaration fd = ParseUtilVBNet.ParseTypeMember<FieldDeclaration>("Dim a(), b As String");
Assert.AreEqual(2, fd.Fields.Count);
Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type);
Assert.IsTrue(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType);
Assert.IsFalse(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType);
}
#endregion
}
}

4
src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

@ -238,9 +238,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -238,9 +238,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (!indexers[i].IsIndexer)
indexers.RemoveAt(i--);
}
IReturnType[] parameters = new IReturnType[indexerExpression.Indices.Count];
IReturnType[] parameters = new IReturnType[indexerExpression.Indexes.Count];
for (int i = 0; i < parameters.Length; i++) {
Expression expr = indexerExpression.Indices[i] as Expression;
Expression expr = indexerExpression.Indexes[i] as Expression;
if (expr != null)
parameters[i] = (IReturnType)expr.AcceptVisitor(this, null);
}

Loading…
Cancel
Save