Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: icsharpcode/NRefactory
base: 41b4385
...
head fork: icsharpcode/NRefactory
compare: a92606c
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
4 ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs
@@ -7,7 +7,7 @@
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{
- [TestFixture, Ignore("Delegate.Name is broken")]
+ [TestFixture]
public class DelegateDeclarationTests
{
[Test]
@@ -26,7 +26,7 @@ public void SimpleCSharpDelegateDeclarationTest()
}});
}
- [Test]
+ [Test, Ignore("Generics not yet supported")]
public void GenericDelegateDeclarationTest()
{
ParseUtilCSharp.AssertGlobal(
View
4 ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
@@ -70,7 +70,7 @@ public void SimpleStaticClassTypeDeclarationTest()
Assert.AreEqual(Modifiers.Static, td.Modifiers);
}
- [Test, Ignore("Generic classes not yet supported")]
+ [Test, Ignore("Generics not yet supported")]
public void GenericClassTypeDeclarationTest()
{
ParseUtilCSharp.AssertGlobal(
@@ -83,7 +83,7 @@ public void GenericClassTypeDeclarationTest()
});
}
- [Test, Ignore("Generic classes not yet supported")]
+ [Test, Ignore("Constraints not yet supported")]
public void GenericClassWithWhere()
{
ParseUtilCSharp.AssertGlobal(
View
6 ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs
@@ -57,11 +57,11 @@ public AstLocation (int line, int column)
get { return column; }
}
- public override bool Equals (object other)
+ public override bool Equals (object obj)
{
- if (!(other is AstLocation))
+ if (!(obj is AstLocation))
return false;
- return (AstLocation)other == this;
+ return (AstLocation)obj == this;
}
public override int GetHashCode ()
View
13 ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
@@ -148,13 +148,14 @@ void WriteSpecialsUpToRole(Role role, AstNode nextNode)
/// Writes a comma.
/// </summary>
/// <param name="nextNode">The next node after the comma.</param>
- void Comma(AstNode nextNode)
+ /// <param name="noSpacesAfterComma">When set prevents printing a space after comma.</param>
+ void Comma(AstNode nextNode, bool noSpaceAfterComma = false)
{
WriteSpecialsUpToRole(AstNode.Roles.Comma, nextNode);
Space(policy.SpacesBeforeComma);
formatter.WriteToken(",");
lastWritten = LastWritten.Other;
- Space(policy.SpacesAfterComma);
+ Space(!noSpaceAfterComma && policy.SpacesAfterComma);
}
void WriteCommaSeparatedList(IEnumerable<AstNode> list)
@@ -1108,7 +1109,8 @@ public object VisitAttribute(Attribute attribute, object data)
StartNode(attribute);
attribute.Type.AcceptVisitor(this, data);
Space(policy.BeforeMethodCallParentheses);
- WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses);
+ if (attribute.Arguments.Count != 0 || !attribute.GetChildByRole(AstNode.Roles.LPar).IsNull)
+ WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses);
return EndNode(attribute);
}
@@ -1123,7 +1125,8 @@ public object VisitAttributeSection(AttributeSection attributeSection, object da
}
WriteCommaSeparatedList(attributeSection.Attributes.SafeCast<Attribute, AstNode>());
WriteToken("]", AstNode.Roles.RBracket);
- NewLine();
+ if (!(attributeSection.Parent is ParameterDeclaration))
+ NewLine();
return EndNode(attributeSection);
}
@@ -1201,7 +1204,7 @@ public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
if (first) {
first = false;
} else {
- Comma(member);
+ Comma(member, noSpaceAfterComma: true);
NewLine();
}
member.AcceptVisitor(this, data);
View
32 ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
@@ -225,7 +225,7 @@ public override void Visit (Class c)
var typeArgLocation = LocationsBag.GetLocations (c.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
-// AddTypeArguments (newType, typeArgLocation, c.MemberName.TypeArguments);
+ AddTypeParameters (newType, typeArgLocation, c.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newType, c);
@@ -254,7 +254,7 @@ public override void Visit (Struct s)
var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
-// AddTypeArguments (newType, typeArgLocation, s.MemberName.TypeArguments);
+ AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newType, s);
@@ -283,7 +283,7 @@ public override void Visit (Interface i)
var typeArgLocation = LocationsBag.GetLocations (i.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
-// AddTypeArguments (newType, typeArgLocation, i.MemberName.TypeArguments);
+ AddTypeParameters (newType, typeArgLocation, i.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
AddConstraints (newType, i);
@@ -307,12 +307,12 @@ public override void Visit (Mono.CSharp.Delegate d)
if (location != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword);
newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type);
- newDelegate.AddChild (new Identifier (d.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
+ newDelegate.AddChild (new Identifier (d.Basename, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
if (d.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (d.MemberName);
if (typeArgLocation != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
-// AddTypeArguments (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
+ AddTypeParameters (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
if (typeArgLocation != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newDelegate, d);
@@ -632,7 +632,7 @@ public override void Visit (Method m)
var typeArgLocation = LocationsBag.GetLocations (m.MemberName);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
-// AddTypeArguments (newMethod, typeArgLocation, m.MemberName.TypeArguments);
+ AddTypeParameters (newMethod, typeArgLocation, m.MemberName.TypeArguments);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
@@ -1835,17 +1835,22 @@ void AddParameter (AstNode parent, Mono.CSharp.AParametersCollection parameters)
}
}
- void AddTypeArguments (AstNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments)
+ void AddTypeParameters (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
{
if (typeArguments == null || typeArguments.IsEmpty)
return;
for (int i = 0; i < typeArguments.Count; i++) {
if (location != null && i > 0 && i - 1 < location.Count)
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
- var arg = typeArguments.Args[i];
+ var arg = (TypeParameterName)typeArguments.Args[i];
if (arg == null)
continue;
- parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
+ TypeParameterDeclaration tp = new TypeParameterDeclaration();
+ // TODO: attributes
+ if (arg.Variance != Variance.None)
+ throw new NotImplementedException(); // TODO: variance
+ tp.AddChild (new Identifier (arg.Name, Convert (arg.Location)), InvocationExpression.Roles.Identifier);
+ parent.AddChild (tp, InvocationExpression.Roles.TypeParameter);
}
}
@@ -1871,11 +1876,12 @@ void AddConstraints (AstNode parent, DeclSpace d)
Constraints c = d.Constraints[i];
var location = LocationsBag.GetLocations (c);
var constraint = new Constraint ();
- parent.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
- parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
- parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole);
+ constraint.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
+ constraint.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
+ constraint.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole);
foreach (var expr in c.ConstraintExpressions)
- parent.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
+ constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
+ parent.AddChild (constraint, AstNode.Roles.Constraint);
}
}
View
2  ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
@@ -16,6 +16,8 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<NoWarn>1591,0618</NoWarn>
<TargetFrameworkProfile />
+ <RunCodeAnalysis>False</RunCodeAnalysis>
+ <CodeAnalysisRules>-Microsoft.Design#CA1026;-Microsoft.Security#CA2104</CodeAnalysisRules>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
View
25 README
@@ -6,15 +6,22 @@ ICSharpCode.NRefactory.TypeSystem:
ICSharpCode.NRefactory.TypeSystem.Implementation:
Contains base classes that help implementing the type system interfaces.
-ICSharpCode.NRefactory.CSharp.Dom:
+ICSharpCode.NRefactory.CSharp.Ast:
Abstract Syntax Tree for C#
ICSharpCode.NRefactory.CSharp.Resolver:
Semantic analysis for C#
-ICSharpCode.NRefactory.VB.Dom:
+ICSharpCode.NRefactory.Util:
+ Various helper classes.
+
+ICSharpCode.NRefactory.VB.Dom: (in the separate ICSharpCode.NRefactory.VB assembly)
Abstract Syntax Tree for VB
+Dependencies:
+ .NET 3.5 or .NET 4.0
+ Mono.Cecil 0.9.4
+
Null-Object pattern:
The NRefactory library makes extensive use of the null object pattern.
As a result, NullReferenceExceptions should be very rare when working with this library.
@@ -32,6 +39,10 @@ Null-Object pattern:
error cases. Use ResolveResult.IsError to detect resolver errors.
Also note that many resolver errors still have a meaningful type attached, this allows code
completion to work in the presence of minor semantic errors.
+
+ The C# AST makes use of special null nodes when accessing the getter of an AST property and no
+ child node with that role exists. Check the IsNull property to test whether a node is a null node.
+ Null nodes are not considered to be part of the AST (e.g. they don't have a parent).
FAQ:
Q: What is the difference between types and type definitions?
@@ -193,3 +204,13 @@ A: Because if you're asking whether a type is a struct, it's very likely that yo
If you really need to know, you can do
"type.GetDefinition() != null && type.GetDefinition().ClassType == WhatIWant"
yourself, but for the most part you should be fine with IsReferenceType, IsEnum and IsDelegate.
+
+
+Q: What's the difference between the .NET 3.5 and .NET 4.0 versions?
+
+A: As for visible API difference, not much. The .NET 4.0 build has some additional overloads for a few methods,
+ taking a System.Threading.CancellationToken to allow aborting a resolve run.
+ Internally, the .NET 4.0 version might be tiny bit more performant because it uses covariance for IEnumerable,
+ where the .NET 3.5 version has to allocate wrapper objects instead.
+
+ Both versions support loading assemblies of all .NET versions (1.0 to 4.0); and both support C# 4.0.
View
33 doc/TODO
@@ -1,15 +1,24 @@
-TypeSystem API:
+
+Parser:
+- "extern alias" declarations
+- "fixed int Field[100];" (fixed-size field declarations)
+- support generics
+- fix bugs (see currently ignored unit tests)
+- put newlines into the AST
+- add API to report errors
+- allow multithreaded parsing
-* Decide on the fate of ISupportsInterning (depends on how we're going to implement persistence)
+Resolver:
+- Tons of unit tests for TypeSystemConvertVisitor
+- Lambda expressions
+- Handle attributes
+- Port all #D resolver unit tests to NR
+- Port all MD resolver unit tests to NR
-* Try to build SharedTypes for void, int, etc.
- Take care of equality with the real System.Void, System.Int32 etc.
- This seems to be hard/impossible to do, see comment in SharedTypes.cs.
- I'm trying to work without those types now.
-
- Note that having shared type *references* is possible (typeof(int).ToTypeReference())
+Features:
+- Code Completion
+- Find References
+- Extract Method refactoring
-* Implement the C# parser producing the DOM
-* Implement ResolveVisitor
-* Implement all the nasty context-dependent stuff (local variables, lambdas) that CSharpResolver doesn't do (yet)
- Where should that go? I'd like to keep it out of CSharpResolver, that class is bloated enough with the pure logic.
+For integration into SharpDevelop:
+- Review NR and DOM changes done in the timeframe

No commit comments for this range

Something went wrong with that request. Please try again.