Browse Source

Improved C# -> VB converter (For-Statement is converted to ForNextStatement).

Fixed VB parser (CSByte, CUShort, CUInt, CULng cast operators were missing).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@364 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
0306c5af7e
  1. 4
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt
  2. 4
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs
  3. 24
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs
  4. 46
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  5. 114
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  6. 3467
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  7. 169
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  8. 132
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/CSharpToVBNetConvertVisitor.cs
  9. 30
      src/Libraries/NRefactory/Test/Lexer/VBNet/LexerTests.cs
  10. 4
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

4
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt

@ -217,6 +217,10 @@ ConcatStringAssign = "&=" @@ -217,6 +217,10 @@ ConcatStringAssign = "&="
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
"Of"

4
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs

@ -159,6 +159,10 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -159,6 +159,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
"UINTEGER",
"ULONG",
"USHORT",
"CSBYTE",
"CUSHORT",
"CUINT",
"CULNG",
"GLOBAL",
"TRYCAST",
"OF",

24
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs

@ -205,15 +205,19 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -205,15 +205,19 @@ namespace ICSharpCode.NRefactory.Parser.VB
public const int UInteger = 191;
public const int ULong = 192;
public const int UShort = 193;
public const int Global = 194;
public const int TryCast = 195;
public const int Of = 196;
public const int Narrowing = 197;
public const int Widening = 198;
public const int Partial = 199;
public const int Custom = 200;
public const int CSByte = 194;
public const int CUShort = 195;
public const int CUInt = 196;
public const int CULng = 197;
public const int Global = 198;
public const int TryCast = 199;
public const int Of = 200;
public const int Narrowing = 201;
public const int Widening = 202;
public const int Partial = 203;
public const int Custom = 204;
public const int maxToken = 201;
public const int maxToken = 205;
static BitArray NewSet(params int[] values)
{
BitArray bitArray = new BitArray(maxToken);
@ -423,6 +427,10 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -423,6 +427,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
"UInteger",
"ULong",
"UShort",
"CSByte",
"CUShort",
"CUInt",
"CULng",
"Global",
"TryCast",
"Of",

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

@ -129,7 +129,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -129,7 +129,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (typeReference.Type == null || typeReference.Type.Length ==0) {
outputFormatter.PrintText("void");
} else if (typeReference.SystemType == "System.Nullable" && typeReference.GenericTypes != null
&& typeReference.GenericTypes.Count == 1)
&& typeReference.GenericTypes.Count == 1)
{
nodeTracker.TrackedVisit(typeReference.GenericTypes[0], data);
outputFormatter.PrintText("?");
@ -1454,7 +1454,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1454,7 +1454,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(ExitStatement exitStatement, object data)
{
outputFormatter.PrintToken(Tokens.Break);
if (exitStatement.ExitType == ExitType.Function || exitStatement.ExitType == ExitType.Sub || exitStatement.ExitType == ExitType.Property) {
outputFormatter.PrintToken(Tokens.Return);
} else {
outputFormatter.PrintToken(Tokens.Break);
}
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.PrintText("// might not be correct. Was : Exit " + exitStatement.ExitType);
outputFormatter.NewLine();
@ -1463,10 +1467,42 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1463,10 +1467,42 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(ForNextStatement forNextStatement, object data)
{
// TODO: implement me
errors.Error(-1, -1, String.Format("For...next statement is unsupported."));
outputFormatter.PrintToken(Tokens.For);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (!forNextStatement.TypeReference.IsNull) {
nodeTracker.TrackedVisit(forNextStatement.TypeReference, data);
outputFormatter.Space();
}
outputFormatter.PrintIdentifier(forNextStatement.VariableName);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space();
nodeTracker.TrackedVisit(forNextStatement.Start, data);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.Space();
outputFormatter.PrintIdentifier(forNextStatement.VariableName);
outputFormatter.Space();
PrimitiveExpression pe = forNextStatement.Step as PrimitiveExpression;
if (pe == null || !(pe.Value is int) || ((int)pe.Value) >= 0)
outputFormatter.PrintToken(Tokens.LessEqual);
else
outputFormatter.PrintToken(Tokens.GreaterEqual);
outputFormatter.Space();
nodeTracker.TrackedVisit(forNextStatement.End, data);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.Space();
outputFormatter.PrintIdentifier(forNextStatement.VariableName);
if (forNextStatement.Step.IsNull) {
outputFormatter.PrintToken(Tokens.Increment);
} else {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.PlusAssign);
outputFormatter.Space();
nodeTracker.TrackedVisit(forNextStatement.Step, data);
}
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
return nodeTracker.TrackedVisit(forNextStatement.EmbeddedStatement, data);
}
#endregion

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

@ -2079,60 +2079,68 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2079,60 +2079,68 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(CastExpression castExpression, object data)
{
if (castExpression.IsSpecializedCast) {
switch (castExpression.CastTo.Type) {
case "System.Boolean":
outputFormatter.PrintToken(Tokens.CBool);
break;
case "System.Byte":
outputFormatter.PrintToken(Tokens.CByte);
break;
case "System.Char":
outputFormatter.PrintToken(Tokens.CChar);
break;
case "System.DateTime":
outputFormatter.PrintToken(Tokens.CDate);
break;
case "System.Decimal":
outputFormatter.PrintToken(Tokens.CDec);
break;
case "System.Double":
outputFormatter.PrintToken(Tokens.CDbl);
break;
case "System.Int32":
outputFormatter.PrintToken(Tokens.CInt);
break;
case "System.Int64":
outputFormatter.PrintToken(Tokens.CLng);
break;
case "System.Object":
outputFormatter.PrintToken(Tokens.CObj);
break;
case "System.Int16":
outputFormatter.PrintToken(Tokens.CShort);
break;
case "System.Single":
outputFormatter.PrintToken(Tokens.CSng);
break;
case "System.String":
outputFormatter.PrintToken(Tokens.CStr);
break;
default:
errors.Error(-1, -1, String.Format("Specialized cast of type {0} is unsupported", castExpression.CastTo.Type));
break;
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(castExpression.Expression, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
} else {
outputFormatter.PrintToken(Tokens.CType);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(castExpression.Expression, data);
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.Space();
nodeTracker.TrackedVisit(castExpression.CastTo, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
switch (castExpression.CastTo.SystemType) {
case "System.Boolean":
outputFormatter.PrintToken(Tokens.CBool);
break;
case "System.Byte":
outputFormatter.PrintToken(Tokens.CByte);
break;
case "System.SByte":
outputFormatter.PrintToken(Tokens.CSByte);
break;
case "System.Char":
outputFormatter.PrintToken(Tokens.CChar);
break;
case "System.DateTime":
outputFormatter.PrintToken(Tokens.CDate);
break;
case "System.Decimal":
outputFormatter.PrintToken(Tokens.CDec);
break;
case "System.Double":
outputFormatter.PrintToken(Tokens.CDbl);
break;
case "System.Int16":
outputFormatter.PrintToken(Tokens.CShort);
break;
case "System.Int32":
outputFormatter.PrintToken(Tokens.CInt);
break;
case "System.Int64":
outputFormatter.PrintToken(Tokens.CLng);
break;
case "System.UInt16":
outputFormatter.PrintToken(Tokens.CUShort);
break;
case "System.UInt32":
outputFormatter.PrintToken(Tokens.CInt);
break;
case "System.UInt64":
outputFormatter.PrintToken(Tokens.CLng);
break;
case "System.Object":
outputFormatter.PrintToken(Tokens.CObj);
break;
case "System.Single":
outputFormatter.PrintToken(Tokens.CSng);
break;
case "System.String":
outputFormatter.PrintToken(Tokens.CStr);
break;
default:
outputFormatter.PrintToken(Tokens.CType);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(castExpression.Expression, data);
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.Space();
nodeTracker.TrackedVisit(castExpression.CastTo, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(castExpression.Expression, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
}

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

File diff suppressed because it is too large Load Diff

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

@ -411,6 +411,10 @@ TOKENS @@ -411,6 +411,10 @@ TOKENS
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
"Of"
@ -1742,14 +1746,18 @@ CastTarget<out TypeReference type> @@ -1742,14 +1746,18 @@ CastTarget<out TypeReference type>
.) =
"CBool" (. type = new TypeReference("System.Boolean"); .)
| "CByte" (. type = new TypeReference("System.Byte"); .)
| "CSByte" (. type = new TypeReference("System.SByte"); .)
| "CChar" (. type = new TypeReference("System.Char"); .)
| "CDate" (. type = new TypeReference("System.DateTime"); .)
| "CDec" (. type = new TypeReference("System.Decimal"); .)
| "CDbl" (. type = new TypeReference("System.Double"); .)
| "CShort" (. type = new TypeReference("System.Int16"); .)
| "CInt" (. type = new TypeReference("System.Int32"); .)
| "CLng" (. type = new TypeReference("System.Int64"); .)
| "CUShort" (. type = new TypeReference("System.UInt16"); .)
| "CUInt" (. type = new TypeReference("System.UInt32"); .)
| "CULng" (. type = new TypeReference("System.UInt64"); .)
| "CObj" (. type = new TypeReference("System.Object"); .)
| "CShort" (. type = new TypeReference("System.Int16"); .)
| "CSng" (. type = new TypeReference("System.Single"); .)
| "CStr" (. type = new TypeReference("System.String"); .)
.
@ -2752,166 +2760,13 @@ Identifier = @@ -2752,166 +2760,13 @@ Identifier =
.
/* 2.2 */
IdentifierOrKeyword<out string name>
(.
name = String.Empty;
.)
=
Identifier (. name = t.val; .)
| "AddHandler" (. name = t.val; .)
| "AddressOf" (. name = t.val; .)
| "Alias" (. name = t.val; .)
| "And" (. name = t.val; .)
| "AndAlso" (. name = t.val; .)
| "Ansi" (. name = t.val; .)
| "As" (. name = t.val; .)
| "Assembly" (. name = t.val; .)
| "Auto" (. name = t.val; .)
| "Boolean" (. name = t.val; .)
| "ByRef" (. name = t.val; .)
| "Byte" (. name = t.val; .)
| "ByVal" (. name = t.val; .)
| "Call" (. name = t.val; .)
| "Case" (. name = t.val; .)
| "Catch" (. name = t.val; .)
| "CBool" (. name = t.val; .)
| "CByte" (. name = t.val; .)
| "CChar" (. name = t.val; .)
| "CDate" (. name = t.val; .)
| "CDbl" (. name = t.val; .)
| "CDec" (. name = t.val; .)
| "Char" (. name = t.val; .)
| "CInt" (. name = t.val; .)
| "Class" (. name = t.val; .)
| "CLng" (. name = t.val; .)
| "CObj" (. name = t.val; .)
| "Const" (. name = t.val; .)
| "CShort" (. name = t.val; .)
| "CSng" (. name = t.val; .)
| "CStr" (. name = t.val; .)
| "CType" (. name = t.val; .)
| "Date" (. name = t.val; .)
| "Decimal" (. name = t.val; .)
| "Declare" (. name = t.val; .)
| "Default" (. name = t.val; .)
| "Delegate" (. name = t.val; .)
| "Dim" (. name = t.val; .)
| "DirectCast" (. name = t.val; .)
| "Do" (. name = t.val; .)
| "Double" (. name = t.val; .)
| "Each" (. name = t.val; .)
| "Else" (. name = t.val; .)
| "ElseIf" (. name = t.val; .)
| "End" (. name = t.val; .)
| "EndIf" (. name = t.val; .)
| "Enum" (. name = t.val; .)
| "Erase" (. name = t.val; .)
| "Error" (. name = t.val; .)
| "Event" (. name = t.val; .)
| "Exit" (. name = t.val; .)
| "Explicit" (. name = t.val; .)
| "False" (. name = t.val; .)
| "Finally" (. name = t.val; .)
| "For" (. name = t.val; .)
| "Friend" (. name = t.val; .)
| "Function" (. name = t.val; .)
| "Get" (. name = t.val; .)
| "GetType" (. name = t.val; .)
| "GoSub" (. name = t.val; .)
| "GoTo" (. name = t.val; .)
| "Handles" (. name = t.val; .)
| "If" (. name = t.val; .)
| "Implements" (. name = t.val; .)
| "Imports" (. name = t.val; .)
| "In" (. name = t.val; .)
| "Inherits" (. name = t.val; .)
| "Integer" (. name = t.val; .)
| "Interface" (. name = t.val; .)
| "Is" (. name = t.val; .)
| "Let" (. name = t.val; .)
| "Lib" (. name = t.val; .)
| "Like" (. name = t.val; .)
| "Long" (. name = t.val; .)
| "Loop" (. name = t.val; .)
| "Me" (. name = t.val; .)
| "Mod" (. name = t.val; .)
| "Module" (. name = t.val; .)
| "MustInherit" (. name = t.val; .)
| "MustOverride" (. name = t.val; .)
| "MyBase" (. name = t.val; .)
| "MyClass" (. name = t.val; .)
| "Namespace" (. name = t.val; .)
| "New" (. name = t.val; .)
| "Next" (. name = t.val; .)
| "Not" (. name = t.val; .)
| "Nothing" (. name = t.val; .)
| "NotInheritable" (. name = t.val; .)
| "NotOverridable" (. name = t.val; .)
| "Object" (. name = t.val; .)
| "On" (. name = t.val; .)
| "Option" (. name = t.val; .)
| "Optional" (. name = t.val; .)
| "Or" (. name = t.val; .)
| "OrElse" (. name = t.val; .)
| "Overloads" (. name = t.val; .)
| "Overridable" (. name = t.val; .)
| "Overrides" (. name = t.val; .)
| "ParamArray" (. name = t.val; .)
| "Preserve" (. name = t.val; .)
| "Private" (. name = t.val; .)
| "Property" (. name = t.val; .)
| "Protected" (. name = t.val; .)
| "Public" (. name = t.val; .)
| "RaiseEvent" (. name = t.val; .)
| "ReadOnly" (. name = t.val; .)
| "ReDim" (. name = t.val; .)
| "RemoveHandler" (. name = t.val; .)
| "Resume" (. name = t.val; .)
| "Return" (. name = t.val; .)
| "Select" (. name = t.val; .)
| "Set" (. name = t.val; .)
| "Shadows" (. name = t.val; .)
| "Shared" (. name = t.val; .)
| "Short" (. name = t.val; .)
| "Single" (. name = t.val; .)
| "Static" (. name = t.val; .)
| "Step" (. name = t.val; .)
| "Stop" (. name = t.val; .)
| "String" (. name = t.val; .)
| "Structure" (. name = t.val; .)
| "Sub" (. name = t.val; .)
| "SyncLock" (. name = t.val; .)
| "Then" (. name = t.val; .)
| "Throw" (. name = t.val; .)
| "To" (. name = t.val; .)
| "True" (. name = t.val; .)
| "Try" (. name = t.val; .)
| "TypeOf" (. name = t.val; .)
| "Unicode" (. name = t.val; .)
| "Until" (. name = t.val; .)
| "Variant" (. name = t.val; .)
| "Wend" (. name = t.val; .)
| "When" (. name = t.val; .)
| "While" (. name = t.val; .)
| "With" (. name = t.val; .)
| "WithEvents" (. name = t.val; .)
| "WriteOnly" (. name = t.val; .)
| "Xor" (. name = t.val; .)
| "Continue" (. name = t.val; .)
| "Operator" (. name = t.val; .)
| "Using" (. name = t.val; .)
| "IsNot" (. name = t.val; .)
| "SByte" (. name = t.val; .)
| "UInteger" (. name = t.val; .)
| "ULong" (. name = t.val; .)
| "UShort" (. name = t.val; .)
| "Of" (. name = t.val; .)
| "Narrowing" (. name = t.val; .)
| "Widening" (. name = t.val; .)
| "Partial" (. name = t.val; .)
(. lexer.NextToken(); name = t.val; .)
.
/* 7.3 */
PrimitiveTypeName<out string type>
(. type = String.Empty; .) =

132
src/Libraries/NRefactory/Project/Src/Parser/Visitors/CSharpToVBNetConvertVisitor.cs

@ -26,9 +26,11 @@ namespace ICSharpCode.NRefactory.Parser @@ -26,9 +26,11 @@ namespace ICSharpCode.NRefactory.Parser
// Conflicting field/property names -> m_field
// a == null -> a Is Nothing
// a != null -> a Is Not Nothing
// i++ / ++i as statement: convert to i += 1
// i-- / --i as statement: convert to i -= 1
// ForStatement -> ForNextStatement when for-loop is simple
// The following conversions should be implemented in the future:
// ForStatement -> ForNextStatement when for-loop is simple
// if (Event != null) Event(this, bla); -> RaiseEvent Event(this, bla)
public override object Visit(BinaryOperatorExpression binaryOperatorExpression, object data)
@ -82,7 +84,133 @@ namespace ICSharpCode.NRefactory.Parser @@ -82,7 +84,133 @@ namespace ICSharpCode.NRefactory.Parser
}
}
new PrefixFieldsVisitor(conflicts, "m_").Run(td);
return base.Visit(td, data);
object result = base.Visit(td, data);
ConvertForStatements();
return result;
}
public override object Visit(StatementExpression statementExpression, object data)
{
UnaryOperatorExpression uoe = statementExpression.Expression as UnaryOperatorExpression;
if (uoe != null) {
switch (uoe.Op) {
case UnaryOperatorType.Increment:
case UnaryOperatorType.PostIncrement:
statementExpression.Expression = new AssignmentExpression(uoe.Expression, AssignmentOperatorType.Add, new PrimitiveExpression(1, "1"));
break;
case UnaryOperatorType.Decrement:
case UnaryOperatorType.PostDecrement:
statementExpression.Expression = new AssignmentExpression(uoe.Expression, AssignmentOperatorType.Subtract, new PrimitiveExpression(1, "1"));
break;
}
}
return base.Visit(statementExpression, data);
}
ArrayList forStatements = new ArrayList();
public override object Visit(ForStatement forStatement, object data)
{
forStatements.Add(forStatement);
// post-pone conversion because the parent's collection cannot be modified while it
// is in use.
return base.Visit(forStatement, data);
}
void ConvertForStatements()
{
foreach (ForStatement forStatement in forStatements) {
ConvertForStatement(forStatement);
}
forStatements.Clear();
}
void ConvertForStatement(ForStatement forStatement)
{
// ForStatement -> ForNextStatement when for-loop is simple
// only the following forms of the for-statement are allowed:
// for (TypeReference name = start; name < oneAfterEnd; name += step)
// for (name = start; name < oneAfterEnd; name += step)
// for (TypeReference name = start; name <= end; name += step)
// for (name = start; name <= end; name += step)
// for (TypeReference name = start; name > oneAfterEnd; name -= step)
// for (name = start; name > oneAfterEnd; name -= step)
// for (TypeReference name = start; name >= end; name -= step)
// for (name = start; name >= end; name -= step)
// check if the form is valid and collect TypeReference, name, start, end and step
if (forStatement.Initializers.Count != 1)
return;
if (forStatement.Iterator.Count != 1)
return;
StatementExpression statement = forStatement.Iterator[0] as StatementExpression;
if (statement == null)
return;
AssignmentExpression iterator = statement.Expression as AssignmentExpression;
if (iterator == null || (iterator.Op != AssignmentOperatorType.Add && iterator.Op != AssignmentOperatorType.Subtract))
return;
IdentifierExpression iteratorIdentifier = iterator.Left as IdentifierExpression;
if (iteratorIdentifier == null)
return;
PrimitiveExpression stepExpression = iterator.Right as PrimitiveExpression;
if (stepExpression == null || !(stepExpression.Value is int))
return;
int step = (int)stepExpression.Value;
if (iterator.Op == AssignmentOperatorType.Subtract)
step = -step;
BinaryOperatorExpression condition = forStatement.Condition as BinaryOperatorExpression;
if (!(condition.Left is IdentifierExpression))
return;
if ((condition.Left as IdentifierExpression).Identifier != iteratorIdentifier.Identifier)
return;
Expression end;
if (iterator.Op == AssignmentOperatorType.Subtract) {
if (condition.Op == BinaryOperatorType.GreaterThanOrEqual)
end = condition.Right;
else if (condition.Op == BinaryOperatorType.GreaterThan)
end = new BinaryOperatorExpression(condition.Right, BinaryOperatorType.Add, new PrimitiveExpression(1, "1"));
else
return;
} else {
if (condition.Op == BinaryOperatorType.LessThanOrEqual)
end = condition.Right;
else if (condition.Op == BinaryOperatorType.LessThan)
end = new BinaryOperatorExpression(condition.Right, BinaryOperatorType.Subtract, new PrimitiveExpression(1, "1"));
else
return;
}
Expression start;
TypeReference typeReference = null;
LocalVariableDeclaration varDecl = forStatement.Initializers[0] as LocalVariableDeclaration;
if (varDecl != null) {
if (varDecl.Variables.Count != 1
|| varDecl.Variables[0].Name != iteratorIdentifier.Identifier
|| varDecl.Variables[0].Initializer == null)
return;
typeReference = varDecl.GetTypeForVariable(0);
start = varDecl.Variables[0].Initializer;
} else {
statement = forStatement.Initializers[0] as StatementExpression;
if (statement == null)
return;
AssignmentExpression assign = statement.Expression as AssignmentExpression;
if (assign == null || assign.Op != AssignmentOperatorType.Assign)
return;
if (!(assign.Left is IdentifierExpression))
return;
if ((assign.Left as IdentifierExpression).Identifier != iteratorIdentifier.Identifier)
return;
start = assign.Right;
}
ForNextStatement forNextStatement = new ForNextStatement(typeReference, iteratorIdentifier.Identifier,
start, end,
(step == 1) ? null : new PrimitiveExpression(step, step.ToString(System.Globalization.CultureInfo.InvariantCulture)),
forStatement.EmbeddedStatement, null);
forStatement.Parent.Children[forStatement.Parent.Children.IndexOf(forStatement)] = forNextStatement;
}
}
}

30
src/Libraries/NRefactory/Test/Lexer/VBNet/LexerTests.cs

@ -1151,6 +1151,30 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB @@ -1151,6 +1151,30 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.UShort, lexer.NextToken().kind);
}
[Test()]
public void TestCSByte()
{
ILexer lexer = GenerateLexer(new StringReader("CSByte"));
Assert.AreEqual(Tokens.CSByte, lexer.NextToken().kind);
}
[Test()]
public void TestCUShort()
{
ILexer lexer = GenerateLexer(new StringReader("CUShort"));
Assert.AreEqual(Tokens.CUShort, lexer.NextToken().kind);
}
[Test()]
public void TestCUInt()
{
ILexer lexer = GenerateLexer(new StringReader("CUInt"));
Assert.AreEqual(Tokens.CUInt, lexer.NextToken().kind);
}
[Test()]
public void TestCULng()
{
ILexer lexer = GenerateLexer(new StringReader("CULng"));
Assert.AreEqual(Tokens.CULng, lexer.NextToken().kind);
}
[Test()]
public void TestGlobal()
{
ILexer lexer = GenerateLexer(new StringReader("Global"));
@ -1186,5 +1210,11 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB @@ -1186,5 +1210,11 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
ILexer lexer = GenerateLexer(new StringReader("Partial"));
Assert.AreEqual(Tokens.Partial, lexer.NextToken().kind);
}
[Test()]
public void TestCustom()
{
ILexer lexer = GenerateLexer(new StringReader("Custom"));
Assert.AreEqual(Tokens.Custom, lexer.NextToken().kind);
}
}
}

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

@ -912,7 +912,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -912,7 +912,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
}
bool inStatic = true;
bool inStatic = false;
if (callingMember != null)
inStatic = callingMember.IsStatic;
@ -924,7 +924,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -924,7 +924,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
members.AddRange(t.GetEvents());
members.AddRange(t.GetProperties());
foreach (IMember m in members) {
if ((m.IsStatic || !inStatic) && m.IsAccessible(callingClass, true)) {
if ((!inStatic || m.IsStatic) && m.IsAccessible(callingClass, true)) {
result.Add(m);
}
}

Loading…
Cancel
Save