1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
7
namespace ICSharpCode.NRefactory
9
public class PreprocessingDirective : AbstractSpecial
11
#region Conversion C# <-> VB
12
public static void VBToCSharp(IList<ISpecial> list)
14
for (int i = 0; i < list.Count; ++i) {
15
if (list[i] is PreprocessingDirective)
16
list[i] = VBToCSharp((PreprocessingDirective)list[i]);
20
public static PreprocessingDirective VBToCSharp(PreprocessingDirective dir)
24
if (cmd.Equals("#End", StringComparison.InvariantCultureIgnoreCase)) {
25
if (arg.ToLowerInvariant().StartsWith("region")) {
28
} else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) {
32
} else if (cmd.Equals("#Region", StringComparison.InvariantCultureIgnoreCase)) {
34
} else if (cmd.Equals("#If", StringComparison.InvariantCultureIgnoreCase)) {
36
if (arg.ToLowerInvariant().EndsWith(" then"))
37
arg = arg.Substring(0, arg.Length - 5);
38
} else if (cmd.Equals("#Else", StringComparison.InvariantCultureIgnoreCase)) {
39
if (dir.Expression != null)
43
} else if (cmd.Equals("#ElseIf", StringComparison.InvariantCultureIgnoreCase)) {
46
return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) {
47
Expression = dir.Expression
51
public static void CSharpToVB(List<ISpecial> list)
53
for (int i = 0; i < list.Count; ++i) {
54
if (list[i] is PreprocessingDirective)
55
list[i] = CSharpToVB((PreprocessingDirective)list[i]);
59
public static PreprocessingDirective CSharpToVB(PreprocessingDirective dir)
66
if (!arg.StartsWith("\"")) {
67
arg = "\"" + arg.Trim() + "\"";
83
cmd = cmd.Substring(0, 2).ToUpperInvariant() + cmd.Substring(2);
85
return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) {
86
Expression = dir.Expression
93
Ast.Expression expression = Ast.Expression.Null;
96
/// Gets the directive name, including '#'.
103
cmd = value ?? string.Empty;
108
/// Gets the directive argument.
115
arg = value ?? string.Empty;
120
/// Gets/sets the expression (for directives that take an expression, e.g. #if and #elif).
122
public Ast.Expression Expression {
123
get { return expression; }
124
set { expression = value ?? Ast.Expression.Null; }
128
/// The end position of the pre processor directive line.
129
/// May be != EndPosition.
131
public Location LastLineEnd {
137
public override string ToString()
139
return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]",
144
public PreprocessingDirective(string cmd, string arg, Location start, Location end)
151
public override object AcceptVisitor(ISpecialVisitor visitor, object data)
153
return visitor.Visit(this, data);