Skip to content

Commit

Permalink
Merge NRefactory changes from SharpDevelop
Browse files Browse the repository at this point in the history
* Add ICodeContext interface
* Fix icsharpcode/SharpDevelop#320: C# Ambience does not escape parameter names
  • Loading branch information
dgrunwald committed Feb 2, 2014
1 parent ef1a5d6 commit 616f542
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public InsertRequiredSpacesDecorator(TokenWriter writer)

public override void WriteIdentifier(Identifier identifier)
{
if (identifier.IsVerbatim) {
if (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier)) {
if (lastWritten == LastWritten.KeywordOrIdentifier) {
// this space is not strictly required, so we call Space()
Space();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public TextWriterTokenWriter(TextWriter textWriter)
public override void WriteIdentifier(Identifier identifier)
{
WriteIndentation();
if (identifier.IsVerbatim) {
if (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier)) {
textWriter.Write('@');
column++;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public override void WriteComment(CommentType commentType, string content)
textWriter.Write("/*");
textWriter.Write(content);
textWriter.Write("*/");
column += 2;
column += 2;
UpdateEndLocation(content, ref line, ref column);
column += 2;
isAtStartOfLine = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void Dispose()
undoGroup.Dispose();
}

public override void Remove(AstNode node, bool removeEmptyLine)
public override void Remove(AstNode node, bool removeEmptyLine = true)
{
var segment = GetSegment (node);
int startOffset = segment.Offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ MethodDeclaration ConvertMethod(IMethod method)
{
MethodDeclaration decl = new MethodDeclaration();
decl.Modifiers = GetMemberModifiers(method);
if (method.IsAsync)
decl.Modifiers |= Modifiers.Async;
decl.ReturnType = ConvertType(method.ReturnType);
decl.Name = method.Name;

Expand Down
24 changes: 17 additions & 7 deletions ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
Expand All @@ -38,10 +34,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// <remarks>
/// This class is thread-safe.
/// </remarks>
public class CSharpResolver
public class CSharpResolver : ICodeContext
{
static readonly ResolveResult ErrorResult = ErrorResolveResult.UnknownError;

readonly ICompilation compilation;
internal readonly CSharpConversions conversions;
readonly CSharpTypeResolveContext context;
Expand Down Expand Up @@ -101,6 +96,10 @@ public ICompilation Compilation {
public CSharpTypeResolveContext CurrentTypeResolveContext {
get { return context; }
}

IAssembly ITypeResolveContext.CurrentAssembly {
get { return context.CurrentAssembly; }
}

CSharpResolver WithContext(CSharpTypeResolveContext newContext)
{
Expand All @@ -125,7 +124,7 @@ public CSharpResolver WithCheckForOverflow(bool checkForOverflow)
}

/// <summary>
/// Gets whether the resolver is currently within a lambda expression.
/// Gets whether the resolver is currently within a lambda expression or anonymous method.
/// </summary>
public bool IsWithinLambdaExpression {
get { return isWithinLambdaExpression; }
Expand Down Expand Up @@ -157,6 +156,11 @@ public CSharpResolver WithCurrentMember(IMember member)
return WithContext(context.WithCurrentMember(member));
}

ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember member)
{
return WithCurrentMember(member);
}

/// <summary>
/// Gets the current using scope that is used to look up identifiers as class names.
/// </summary>
Expand Down Expand Up @@ -201,6 +205,11 @@ public CSharpResolver WithCurrentTypeDefinition(ITypeDefinition typeDefinition)
checkForOverflow, isWithinLambdaExpression, newTypeDefinitionCache, localVariableStack, objectInitializerStack);
}

ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition typeDefinition)
{
return WithCurrentTypeDefinition(typeDefinition);
}

sealed class TypeDefinitionCache
{
public readonly ITypeDefinition TypeDefinition;
Expand Down Expand Up @@ -272,6 +281,7 @@ public CSharpResolver PopLastVariable()

/// <summary>
/// Gets all currently visible local variables and lambda parameters.
/// Does not include method parameters.
/// </summary>
public IEnumerable<IVariable> LocalVariables {
get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
// Copyright (c) 2014 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;
Expand Down
19 changes: 17 additions & 2 deletions ICSharpCode.NRefactory.Tests/CSharp/Parser/ConsistencyChecker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
// Copyright (c) 2014 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;
Expand Down
1 change: 1 addition & 0 deletions ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="TypeSystem\DefaultSolutionSnapshot.cs" />
<Compile Include="TypeSystem\DomRegion.cs" />
<Compile Include="TypeSystem\EntityType.cs" />
<Compile Include="TypeSystem\ICodeContext.cs" />
<Compile Include="TypeSystem\Implementation\BlobReader.cs" />
<Compile Include="TypeSystem\Implementation\DefaultVariable.cs" />
<Compile Include="TypeSystem\Implementation\ResolvedAttributeBlob.cs" />
Expand Down
38 changes: 38 additions & 0 deletions ICSharpCode.NRefactory/TypeSystem/ICodeContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2014 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.Collections.Generic;

namespace ICSharpCode.NRefactory.TypeSystem
{
public interface ICodeContext : ITypeResolveContext
{
/// <summary>
/// Gets all currently visible local variables and lambda parameters.
/// Does not include method parameters.
/// </summary>
IEnumerable<IVariable> LocalVariables { get; }

/// <summary>
/// Gets whether the context is within a lambda expression or anonymous method.
/// </summary>
bool IsWithinLambdaExpression { get; }
}
}

2 changes: 1 addition & 1 deletion doc/license.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2010-2012 AlphaSierraPapa
Copyright (c) 2010-2014 AlphaSierraPapa, 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
Expand Down

0 comments on commit 616f542

Please sign in to comment.