Browse Source

Fixed C#<->VB conversion of #if preprocessing directives.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@936 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
d0b2864289
  1. 8
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/BooPrinterVisitorWithComments.cs
  2. 22
      src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs
  3. 5
      src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs
  4. 28
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

8
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/BooPrinterVisitorWithComments.cs

@ -94,7 +94,8 @@ namespace NRefactoryToBooConverter @@ -94,7 +94,8 @@ namespace NRefactoryToBooConverter
#region ICSharpCode.NRefactory.Parser.ISpecialVisitor interface implementation
int oldIndentation;
struct DelayedSpecial {
struct DelayedSpecial
{
public readonly int Indentation;
public readonly string Format;
public readonly object[] Args;
@ -182,7 +183,10 @@ namespace NRefactoryToBooConverter @@ -182,7 +183,10 @@ namespace NRefactoryToBooConverter
object ISpecialVisitor.Visit(PreProcessingDirective special, object data)
{
WriteSpecialText(false, "{0} {1}", special.Cmd, special.Arg);
if (string.IsNullOrEmpty(special.Arg))
WriteSpecialText(false, "{0}", special.Cmd);
else
WriteSpecialText(false, "{0} {1}", special.Cmd, special.Arg);
return null;
}
#endregion

22
src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs

@ -24,15 +24,22 @@ namespace ICSharpCode.NRefactory.Parser @@ -24,15 +24,22 @@ namespace ICSharpCode.NRefactory.Parser
public static PreProcessingDirective VBToCSharp(PreProcessingDirective dir)
{
string cmd = dir.Cmd.ToLower(CultureInfo.InvariantCulture);
string cmd = dir.Cmd.ToLowerInvariant();
string arg = dir.Arg;
switch (cmd) {
case "#end":
if (arg.ToLower(CultureInfo.InvariantCulture).StartsWith("region")) {
if (arg.ToLowerInvariant().StartsWith("region")) {
cmd = "#endregion";
arg = "";
} else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) {
cmd = "#endif";
arg = "";
}
break;
case "#if":
if (arg.ToLowerInvariant().EndsWith(" then"))
arg = arg.Substring(0, arg.Length - 5);
break;
}
return new PreProcessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition);
}
@ -51,7 +58,6 @@ namespace ICSharpCode.NRefactory.Parser @@ -51,7 +58,6 @@ namespace ICSharpCode.NRefactory.Parser
string arg = dir.Arg;
switch (cmd) {
case "#region":
cmd = "#Region";
if (!arg.StartsWith("\"")) {
arg = "\"" + arg.Trim() + "\"";
}
@ -60,6 +66,16 @@ namespace ICSharpCode.NRefactory.Parser @@ -60,6 +66,16 @@ namespace ICSharpCode.NRefactory.Parser
cmd = "#End";
arg = "Region";
break;
case "#endif":
cmd = "#End";
arg = "If";
break;
case "#if":
arg += " Then";
break;
}
if (cmd.Length > 1) {
cmd = cmd.Substring(0, 2).ToUpperInvariant() + cmd.Substring(2);
}
return new PreProcessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition);
}

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

@ -139,7 +139,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -139,7 +139,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public virtual void PrintPreProcessingDirective(PreProcessingDirective directive)
{
WriteInPreviousLine(directive.Cmd + " " + directive.Arg);
if (string.IsNullOrEmpty(directive.Arg))
WriteInPreviousLine(directive.Cmd);
else
WriteInPreviousLine(directive.Cmd + " " + directive.Arg);
}
public abstract void PrintToken(int token);

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

@ -2072,32 +2072,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2072,32 +2072,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(AddressOfExpression addressOfExpression, object data)
{
// TODO: implement me
errors.Error(-1, -1, String.Format("Unsupported expression : {0}", addressOfExpression));
// DebugOutput(addressOfExpression);
// string procedureName = addressOfExpression.Procedure.AcceptVisitor(this, data).ToString();
// string eventHandlerType = "EventHandler";
// bool foundEventHandler = false;
// // try to resolve the type of the eventhandler using a little trick :)
// foreach (INode node in currentType.Children) {
// MethodDeclaration md = node as MethodDeclaration;
// if (md != null && md.Parameters != null && md.Parameters.Count > 0) {
// if (procedureName == md.Name || procedureName.EndsWith("." + md.Name)) {
// ParameterDeclarationExpression pde = (ParameterDeclarationExpression)md.Parameters[md.Parameters.Count - 1];
// string typeName = GetTypeString(pde.TypeReference);
// if (typeName.EndsWith("Args")) {
// eventHandlerType = typeName.Substring(0, typeName.Length - "Args".Length) + "Handler";
// foundEventHandler = true;
// }
// }
// }
// }
// return String.Concat(foundEventHandler ? "new " : "/* might be wrong, please check */ new ",
// eventHandlerType,
// "(",
// procedureName,
// ")");
return null;
// C# 2.0 can reference methods directly
return Visit(addressOfExpression.Expression, data);
}
public object Visit(AnonymousMethodExpression anonymousMethodExpression, object data)

Loading…
Cancel
Save