Skip to content

Commit

Permalink
Merge NRefactory changes from the SharpDevelop repository.
Browse files Browse the repository at this point in the history
Includes Siegfried's work on the output visitor (ITokenWriter) and some minor bugfixes.
  • Loading branch information
dgrunwald committed Dec 25, 2013
1 parent 72e152d commit 8b58930
Show file tree
Hide file tree
Showing 26 changed files with 1,482 additions and 791 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
format.Append('"');
if (verbatim)
format.Insert(0, '@');
formatLiteral.LiteralValue = format.ToString();
formatLiteral.SetValue(format.ToString(), format.ToString());
if (arguments.Count > 0)
script.Replace(expr, formatInvocation);
else
Expand Down
16 changes: 16 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,29 @@ public void AddChild<T> (T child, Role<T> role) where T : AstNode
if (child == null || child.IsNull)
return;
ThrowIfFrozen();
if (child == this)
throw new ArgumentException ("Cannot add a node to itself as a child.", "child");
if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child");
if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child");
AddChildUnsafe (child, role);
}

public void AddChildWithExistingRole (AstNode child)
{
if (child == null || child.IsNull)
return;
ThrowIfFrozen();
if (child == this)
throw new ArgumentException ("Cannot add a node to itself as a child.", "child");
if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child");
if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child");
AddChildUnsafe (child, child.Role);
}

/// <summary>
/// Adds a child without performing any safety checks.
/// </summary>
Expand Down
45 changes: 45 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,50 @@ public static int GetModifierLength(Modifiers modifier)
throw new NotSupportedException("Invalid value for Modifiers");
}
}

public static Modifiers GetModifierValue(string modifier)
{
switch (modifier) {
case "private":
return Modifiers.Private;
case "internal":
return Modifiers.Internal;
case "protected":
return Modifiers.Protected;
case "public":
return Modifiers.Public;
case "abstract":
return Modifiers.Abstract;
case "virtual":
return Modifiers.Virtual;
case "sealed":
return Modifiers.Sealed;
case "static":
return Modifiers.Static;
case "override":
return Modifiers.Override;
case "readonly":
return Modifiers.Readonly;
case "const":
return Modifiers.Const;
case "new":
return Modifiers.New;
case "partial":
return Modifiers.Partial;
case "extern":
return Modifiers.Extern;
case "volatile":
return Modifiers.Volatile;
case "unsafe":
return Modifiers.Unsafe;
case "async":
return Modifiers.Async;
case "any":
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
return Modifiers.Any;
default:
throw new NotSupportedException("Invalid value for Modifiers");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// NullReferenceExpression.cs
//
//
// Author:
// Mike Krüger <[email protected]>
//
Expand Down Expand Up @@ -38,6 +38,12 @@ public override TextLocation StartLocation {
}
}

internal void SetStartLocation(TextLocation value)
{
ThrowIfFrozen();
this.location = value;
}

public override TextLocation EndLocation {
get {
return new TextLocation (location.Line, location.Column + "null".Length);
Expand All @@ -57,7 +63,7 @@ public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitNullReferenceExpression (this);
}

public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitNullReferenceExpression (this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PrimitiveExpression.cs
//
//
// Author:
// Mike Krüger <[email protected]>
//
Expand Down Expand Up @@ -42,13 +42,20 @@ public override TextLocation StartLocation {
}
}

internal void SetStartLocation(TextLocation value)
{
ThrowIfFrozen();
this.startLocation = value;
this.endLocation = null;
}

string literalValue;
TextLocation? endLocation;
public override TextLocation EndLocation {
get {
if (!endLocation.HasValue) {
endLocation = value is string ? AdvanceLocation (StartLocation, literalValue) :
new TextLocation (StartLocation.Line, StartLocation.Column + literalValue.Length);
endLocation = value is string ? AdvanceLocation (StartLocation, literalValue ?? "") :
new TextLocation (StartLocation.Line, StartLocation.Column + (literalValue ?? "").Length);
}
return endLocation.Value;
}
Expand All @@ -58,46 +65,56 @@ public override TextLocation EndLocation {

public object Value {
get { return this.value; }
set {
ThrowIfFrozen();
set {
ThrowIfFrozen();
this.value = value;
literalValue = null;
}
}

/// <remarks>Never returns null.</remarks>
public string LiteralValue {
get { return literalValue ?? ""; }
}

/// <remarks>Can be null.</remarks>
public string UnsafeLiteralValue {
get { return literalValue; }
set {
if (value == null)
throw new ArgumentNullException();
ThrowIfFrozen();
literalValue = value;
}
}

public void SetValue(object value, string literalValue)
{
if (value == null)
throw new ArgumentNullException();
ThrowIfFrozen();
this.value = value;
this.literalValue = literalValue;
}

public PrimitiveExpression (object value)
{
this.Value = value;
this.literalValue = "";
this.literalValue = null;
}

public PrimitiveExpression (object value, string literalValue)
{
this.Value = value;
this.literalValue = literalValue ?? "";
this.literalValue = literalValue;
}

public PrimitiveExpression (object value, TextLocation startLocation, string literalValue)
{
this.Value = value;
this.startLocation = startLocation;
this.literalValue = literalValue ?? "";
this.literalValue = literalValue;
}

public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPrimitiveExpression (this);
}

public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPrimitiveExpression (this);
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Ast/Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public override TextLocation StartLocation {
}
}

internal void SetStartLocation(TextLocation value)
{
ThrowIfFrozen();
this.startLocation = value;
}

const uint verbatimBit = 1u << AstNodeFlagsUsedBits;

public bool IsVerbatim {
Expand Down
7 changes: 7 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public override TextLocation StartLocation {
return location;
}
}

internal void SetStartLocation(TextLocation value)
{
ThrowIfFrozen();
this.location = value;
}

public override TextLocation EndLocation {
get {
return new TextLocation (location.Line, location.Column + keyword.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@
<Compile Include="Formatter\Indent.cs" />
<Compile Include="OutputVisitor\CodeDomConvertVisitor.cs" />
<Compile Include="OutputVisitor\CSharpAmbience.cs" />
<Compile Include="OutputVisitor\InsertMissingTokensDecorator.cs" />
<Compile Include="OutputVisitor\InsertParenthesesVisitor.cs" />
<Compile Include="OutputVisitor\IOutputFormatter.cs" />
<Compile Include="OutputVisitor\InsertRequiredSpacesDecorator.cs" />
<Compile Include="OutputVisitor\CSharpOutputVisitor.cs" />
<Compile Include="OutputVisitor\InsertSpecialsDecorator.cs" />
<Compile Include="OutputVisitor\ITokenWriter.cs" />
<Compile Include="OutputVisitor\TextWriterOutputFormatter.cs" />
<Compile Include="Parser\CompilerSettings.cs" />
<Compile Include="Parser\CSharpParser.cs" />
Expand Down
Loading

0 comments on commit 8b58930

Please sign in to comment.