public static PreprocessingDirective CSharpToVB(PreprocessingDirective dir) { string cmd = dir.Cmd; string arg = dir.Arg; switch (cmd) { case "#region": cmd = "#Region"; if (!arg.StartsWith("\"")) { arg = "\"" + arg.Trim() + "\""; } break; case "#endregion": 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) { Expression = dir.Expression }; }
public static PreprocessingDirective VBToCSharp(PreprocessingDirective dir) { string cmd = dir.Cmd; string arg = dir.Arg; if (cmd.Equals("#End", StringComparison.InvariantCultureIgnoreCase)) { if (arg.ToLowerInvariant().StartsWith("region")) { cmd = "#endregion"; arg = ""; } else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) { cmd = "#endif"; arg = ""; } } else if (cmd.Equals("#Region", StringComparison.InvariantCultureIgnoreCase)) { cmd = "#region"; } else if (cmd.Equals("#If", StringComparison.InvariantCultureIgnoreCase)) { cmd = "#if"; if (arg.ToLowerInvariant().EndsWith(" then")) { arg = arg.Substring(0, arg.Length - 5); } } return(new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { Expression = dir.Expression }); }
public static PreprocessingDirective VBToCSharp(PreprocessingDirective dir) { string cmd = dir.Cmd; string arg = dir.Arg; if (cmd.Equals("#End", StringComparison.InvariantCultureIgnoreCase)) { if (arg.ToLowerInvariant().StartsWith("region")) { cmd = "#endregion"; arg = ""; } else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) { cmd = "#endif"; arg = ""; } } else if (cmd.Equals("#Region", StringComparison.InvariantCultureIgnoreCase)) { cmd = "#region"; } else if (cmd.Equals("#If", StringComparison.InvariantCultureIgnoreCase)) { cmd = "#if"; if (arg.ToLowerInvariant().EndsWith(" then")) arg = arg.Substring(0, arg.Length - 5); } else if (cmd.Equals("#Else", StringComparison.InvariantCultureIgnoreCase)) { if (dir.Expression != null) cmd = "#elif"; else cmd = "#else"; } else if (cmd.Equals("#ElseIf", StringComparison.InvariantCultureIgnoreCase)) { cmd = "#elif"; } return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { Expression = dir.Expression }; }
public static PreprocessingDirective CSharpToVB(PreprocessingDirective dir) { string cmd = dir.Cmd; string arg = dir.Arg; switch (cmd) { case "#region": cmd = "#Region"; if (!arg.StartsWith("\"")) { arg = "\"" + arg.Trim() + "\""; } break; case "#endregion": 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)); }
void ICSharpCode.NRefactory.PrettyPrinter.IOutputFormatter.PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock) { }
public object Visit (ICSharpCode.NRefactory.PreprocessingDirective directive, object data) { DomLocation loc = new DomLocation (directive.StartPosition.Line, directive.StartPosition.Column); switch (directive.Cmd) { case "#if": directive.Expression.AcceptVisitor (visitor, null); conditionalRegions.Push (new ConditionalRegion (visitor.Text)); visitor.Reset (); ifBlocks.Push (directive); ConditionalRegion.Start = loc; break; case "#elif": CloseConditionBlock (new DomLocation (directive.LastLineEnd.Line, directive.LastLineEnd.Column)); directive.Expression.AcceptVisitor (visitor, null); if (ConditionalRegion != null) ConditionalRegion.ConditionBlocks.Add (new ConditionBlock (visitor.Text, loc)); visitor.Reset (); // elifBlocks.Add (directive); break; case "#else": CloseConditionBlock (new DomLocation (directive.LastLineEnd.Line, directive.LastLineEnd.Column)); if (ConditionalRegion != null) ConditionalRegion.ElseBlock = new DomRegion (loc, DomLocation.Empty); // elseBlock = directive; break; case "#endif": DomLocation endLoc = new DomLocation (directive.LastLineEnd.Line, directive.LastLineEnd.Column); CloseConditionBlock (endLoc); if (ConditionalRegion != null && !ConditionalRegion.ElseBlock.Start.IsEmpty) ConditionalRegion.ElseBlock = new DomRegion (ConditionalRegion.ElseBlock.Start, endLoc); AddCurRegion (directive.EndPosition); if (ifBlocks.Count > 0) { ICSharpCode.NRefactory.PreprocessingDirective ifBlock = ifBlocks.Pop (); DomRegion dr = new DomRegion (ifBlock.StartPosition.Line, ifBlock.StartPosition.Column, directive.EndPosition.Line, directive.EndPosition.Column); result.Add (new FoldingRegion ("#if " + ifBlock.Arg.Trim (), dr, FoldType.UserRegion, false)); foreach (ICSharpCode.NRefactory.PreprocessingDirective d in elifBlocks) { dr.Start = new DomLocation (d.StartPosition.Line, d.StartPosition.Column); result.Add (new FoldingRegion ("#elif " + ifBlock.Arg.Trim (), dr, FoldType.UserRegion, false)); } if (elseBlock != null) { dr.Start = new DomLocation (elseBlock.StartPosition.Line, elseBlock.StartPosition.Column); result.Add (new FoldingRegion ("#else", dr, FoldType.UserRegion, false)); } } elseBlock = null; break; case "#define": result.Add (new PreProcessorDefine (directive.Arg, loc)); break; case "#region": regions.Push (directive); break; case "#endregion": if (regions.Count > 0) { ICSharpCode.NRefactory.PreprocessingDirective start = regions.Pop (); DomRegion dr = new DomRegion (start.StartPosition.Line, start.StartPosition.Column, directive.EndPosition.Line, directive.EndPosition.Column); result.Add (new FoldingRegion (start.Arg, dr, FoldType.UserRegion, true)); } break; } return null; }
void IOutputFormatter.PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock) { }
public object Visit (ICSharpCode.NRefactory.PreprocessingDirective directive, object data) { DomLocation loc = new DomLocation (directive.StartPosition.Line, directive.StartPosition.Column); switch (directive.Cmd) { case "#if": directive.Expression.AcceptVisitor (visitor, null); conditionalRegions.Push (new ConditionalRegion (visitor.Text)); visitor.Reset (); ifBlocks.Push (directive); ConditionalRegion.Start = loc; break; case "#elif": CloseConditionBlock (new DomLocation (directive.LastLineEnd.Line, directive.LastLineEnd.Column)); directive.Expression.AcceptVisitor (visitor, null); if (ConditionalRegion != null) ConditionalRegion.ConditionBlocks.Add (new ConditionBlock (visitor.Text, loc)); visitor.Reset (); // elifBlocks.Add (directive); break; case "#else": CloseConditionBlock (new DomLocation (directive.LastLineEnd.Line, directive.LastLineEnd.Column)); if (ConditionalRegion != null) ConditionalRegion.ElseBlock = new DomRegion (loc, DomLocation.Empty); // elseBlock = directive; break; case "#endif": DomLocation endLoc = new DomLocation (directive.LastLineEnd.Line, directive.LastLineEnd.Column); CloseConditionBlock (endLoc); if (ConditionalRegion != null && !ConditionalRegion.ElseBlock.Start.IsEmpty) ConditionalRegion.ElseBlock = new DomRegion (ConditionalRegion.ElseBlock.Start, endLoc); AddCurRegion (directive.EndPosition); if (ifBlocks.Count > 0) { ICSharpCode.NRefactory.PreprocessingDirective ifBlock = ifBlocks.Pop (); DomRegion dr = new DomRegion (ifBlock.StartPosition.Line, ifBlock.StartPosition.Column, directive.EndPosition.Line, directive.EndPosition.Column); result.Add (new FoldingRegion ("#if " + ifBlock.Arg.Trim (), dr, FoldType.UserRegion, false)); foreach (ICSharpCode.NRefactory.PreprocessingDirective d in elifBlocks) { dr.Start = new DomLocation (d.StartPosition.Line, d.StartPosition.Column); result.Add (new FoldingRegion ("#elif " + ifBlock.Arg.Trim (), dr, FoldType.UserRegion, false)); } if (elseBlock != null) { dr.Start = new DomLocation (elseBlock.StartPosition.Line, elseBlock.StartPosition.Column); result.Add (new FoldingRegion ("#else", dr, FoldType.UserRegion, false)); } } elseBlock = null; break; case "#define": result.Add (new PreProcessorDefine (directive.Arg, loc)); break; case "#region": regions.Push (directive); break; case "#endregion": if (regions.Count > 0) { ICSharpCode.NRefactory.PreprocessingDirective start = regions.Pop (); DomRegion dr = new DomRegion (start.StartPosition.Line, start.StartPosition.Column, directive.EndPosition.Line, directive.EndPosition.Column); result.Add (new FoldingRegion (start.Arg, dr, FoldType.UserRegion, true)); } break; } return null; }
object ISpecialVisitor.Visit(PreprocessingDirective special, object data) { if (string.IsNullOrEmpty(special.Arg)) WriteSpecialText(false, "{0}", special.Cmd); else WriteSpecialText(false, "{0} {1}", special.Cmd, special.Arg); return null; }