73 changed files with 3169 additions and 841 deletions
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
[TestFixture] |
||||
public class OutputVisitorTests |
||||
{ |
||||
void AssertOutput(string expected, Expression expr, CSharpFormattingOptions policy = null) |
||||
{ |
||||
if (policy == null) |
||||
policy = new CSharpFormattingOptions();; |
||||
StringWriter w = new StringWriter(); |
||||
w.NewLine = "\n"; |
||||
expr.AcceptVisitor(new OutputVisitor(new TextWriterOutputFormatter(w) { IndentationString = "\t" }, policy), null); |
||||
Assert.AreEqual(expected.Replace("\r", ""), w.ToString()); |
||||
} |
||||
|
||||
[Test, Ignore("Incorrect whitespace")] |
||||
public void AssignmentInCollectionInitialize() |
||||
{ |
||||
Expression expr = new ObjectCreateExpression { |
||||
Type = new SimpleType("List"), |
||||
Initializer = new ArrayInitializerExpression( |
||||
new ArrayInitializerExpression( |
||||
new AssignmentExpression(new IdentifierExpression("a"), new PrimitiveExpression(1)) |
||||
) |
||||
) |
||||
}; |
||||
|
||||
AssertOutput("new List {\n {\n a = 1\n }\n}", expr); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.Editor; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Test fixture that parses NRefactory itself,
|
||||
/// ensures that there are no parser crashes while doing so,
|
||||
/// and that the returned positions are consistent.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ParseSelfTests |
||||
{ |
||||
string[] fileNames; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUp() |
||||
{ |
||||
string path = Path.GetFullPath(@"..\..\.."); |
||||
if (!File.Exists(Path.Combine(path, "NRefactory.sln"))) |
||||
throw new InvalidOperationException("Test cannot find the NRefactory source code in " + path); |
||||
fileNames = Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenerateTypeSystem() |
||||
{ |
||||
SimpleProjectContent pc = new SimpleProjectContent(); |
||||
CSharpParser parser = new CSharpParser(); |
||||
parser.GenerateTypeSystemMode = true; |
||||
foreach (string fileName in fileNames) { |
||||
CompilationUnit cu; |
||||
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan)) { |
||||
cu = parser.Parse(fs); |
||||
} |
||||
TypeSystemConvertVisitor cv = new TypeSystemConvertVisitor(pc, fileName); |
||||
pc.UpdateProjectContent(null, cv.Convert(cu)); |
||||
} |
||||
} |
||||
|
||||
#region ParseAndCheckPositions
|
||||
string currentFileName; |
||||
ReadOnlyDocument currentDocument; |
||||
|
||||
[Test] |
||||
public void ParseAndCheckPositions() |
||||
{ |
||||
CSharpParser parser = new CSharpParser(); |
||||
foreach (string fileName in fileNames) { |
||||
this.currentDocument = new ReadOnlyDocument(File.ReadAllText(fileName)); |
||||
CompilationUnit cu = parser.Parse(currentDocument.CreateReader()); |
||||
this.currentFileName = fileName; |
||||
CheckPositionConsistency(cu); |
||||
CheckMissingTokens(cu); |
||||
} |
||||
} |
||||
|
||||
void CheckPositionConsistency(AstNode node) |
||||
{ |
||||
string comment = "(" + node.GetType().Name + " at " + node.StartLocation + " in " + currentFileName + ")"; |
||||
Assert.IsTrue(node.StartLocation <= node.EndLocation, "StartLocation must be before EndLocation " + comment); |
||||
var prevNodeEnd = node.StartLocation; |
||||
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) { |
||||
Assert.IsTrue(child.StartLocation >= prevNodeEnd, "Child must start after previous sibling " + comment); |
||||
CheckPositionConsistency(child); |
||||
prevNodeEnd = child.EndLocation; |
||||
} |
||||
Assert.IsTrue(prevNodeEnd <= node.EndLocation, "Last child must end before parent node ends " + comment); |
||||
} |
||||
|
||||
void CheckMissingTokens(AstNode node) |
||||
{ |
||||
if (node is IRelocatable) { |
||||
Assert.IsNull(node.FirstChild, "Token nodes should not have children"); |
||||
} else { |
||||
var prevNodeEnd = node.StartLocation; |
||||
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) { |
||||
CheckWhitespace(prevNodeEnd, child.StartLocation); |
||||
CheckMissingTokens(child); |
||||
prevNodeEnd = child.EndLocation; |
||||
} |
||||
CheckWhitespace(prevNodeEnd, node.EndLocation); |
||||
} |
||||
} |
||||
|
||||
void CheckWhitespace(AstLocation whitespaceStart, AstLocation whitespaceEnd) |
||||
{ |
||||
if (whitespaceStart == whitespaceEnd) |
||||
return; |
||||
int start = currentDocument.GetOffset(whitespaceStart.Line, whitespaceStart.Column); |
||||
int end = currentDocument.GetOffset(whitespaceEnd.Line, whitespaceEnd.Column); |
||||
string text = currentDocument.GetText(start, end - start); |
||||
Assert.IsTrue(string.IsNullOrWhiteSpace(text), "Expected whitespace between " + whitespaceStart + " and " + whitespaceEnd |
||||
+ ", but got '" + text + "' (in " + currentFileName + ")"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
[TestFixture] |
||||
public class SerializedCecilLoaderTests : TypeSystemTests |
||||
{ |
||||
[TestFixtureSetUp] |
||||
public void FixtureSetUp() |
||||
{ |
||||
CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true }; |
||||
IProjectContent pc = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location); |
||||
FastSerializer serializer = new FastSerializer(); |
||||
using (MemoryStream ms = new MemoryStream()) { |
||||
serializer.Serialize(ms, pc); |
||||
ms.Position = 0; |
||||
testCasePC = (IProjectContent)serializer.Deserialize(ms); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// NamedExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// name = expression
|
||||
/// This isn't the same as 'assign' even if it has the same syntax. This expression is used in object initializers.
|
||||
/// </summary>
|
||||
public class NamedExpression : Expression |
||||
{ |
||||
public NamedExpression() |
||||
{ |
||||
} |
||||
|
||||
public NamedExpression (string identifier, Expression expression) |
||||
{ |
||||
this.Identifier = identifier; |
||||
this.Expression = expression; |
||||
} |
||||
|
||||
public string Identifier { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, AstLocation.Empty)); |
||||
} |
||||
} |
||||
|
||||
public Identifier IdentifierToken { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier); |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, value); |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode AssignToken { |
||||
get { return GetChildByRole (Roles.Assign); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNamedExpression(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as NamedExpression; |
||||
return o != null && MatchString(this.Identifier, o.Identifier) && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) 2011 Daniel Grunwald
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.NRefactory.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// A binary reader that can read the output of BinaryWriterWith7BitEncodedInts.
|
||||
/// </summary>
|
||||
public sealed class BinaryReaderWith7BitEncodedInts : BinaryReader |
||||
{ |
||||
public BinaryReaderWith7BitEncodedInts(Stream stream) : base(stream) |
||||
{ |
||||
} |
||||
|
||||
public override short ReadInt16() |
||||
{ |
||||
return unchecked((short)(ushort)base.Read7BitEncodedInt()); |
||||
} |
||||
|
||||
public override ushort ReadUInt16() |
||||
{ |
||||
return unchecked((ushort)base.Read7BitEncodedInt()); |
||||
} |
||||
|
||||
public override int ReadInt32() |
||||
{ |
||||
return base.Read7BitEncodedInt(); |
||||
} |
||||
|
||||
public override uint ReadUInt32() |
||||
{ |
||||
return unchecked((uint)base.Read7BitEncodedInt()); |
||||
} |
||||
|
||||
public override long ReadInt64() |
||||
{ |
||||
return unchecked((long)this.ReadUInt64()); |
||||
} |
||||
|
||||
public override ulong ReadUInt64() |
||||
{ |
||||
ulong num = 0; |
||||
int shift = 0; |
||||
while (shift < 64) { |
||||
byte b = this.ReadByte(); |
||||
num |= (ulong)(b & 127) << shift; |
||||
shift += 7; |
||||
if ((b & 128) == 0) { |
||||
return num; |
||||
} |
||||
} |
||||
throw new FormatException("Invalid 7-bit int64"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// A binary writer that encodes all integers as 7-bit-encoded-ints.
|
||||
/// </summary>
|
||||
public sealed class BinaryWriterWith7BitEncodedInts : BinaryWriter |
||||
{ |
||||
public BinaryWriterWith7BitEncodedInts(Stream stream) : base(stream) |
||||
{ |
||||
} |
||||
|
||||
public override void Write(short value) |
||||
{ |
||||
base.Write7BitEncodedInt(unchecked((ushort)value)); |
||||
} |
||||
|
||||
public override void Write(ushort value) |
||||
{ |
||||
base.Write7BitEncodedInt(value); |
||||
} |
||||
|
||||
public override void Write(int value) |
||||
{ |
||||
base.Write7BitEncodedInt(value); |
||||
} |
||||
|
||||
public override void Write(uint value) |
||||
{ |
||||
base.Write7BitEncodedInt(unchecked((int)value)); |
||||
} |
||||
|
||||
public override void Write(long value) |
||||
{ |
||||
this.Write(unchecked((ulong)value)); |
||||
} |
||||
|
||||
public override void Write(ulong value) |
||||
{ |
||||
while (value >= 128) { |
||||
this.Write(unchecked((byte)(value | 128u))); |
||||
value >>= 7; |
||||
} |
||||
this.Write(unchecked((byte)value)); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue