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/ILSpy
base: 49c92cf
...
head fork: icsharpcode/ILSpy
compare: 09c2b45
  • 2 commits
  • 93 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 09, 2011
@dgrunwald dgrunwald Squashed 'NRefactory/' changes from 36c9cae..858d4cc
858d4cc Fixed NullReferenceException in ControlFlow.NodeCreationVisitor.VisitSwitchStatement.
f70a726 Fixed resolving "-2147483648".
dd59e41 Add missing mscorlib reference
f1a1ab3 Added ResolverTest to consistency check and fixed some crashing bugs in the resolver.
3e8eb1e Add NRefactory.ConsistencyCheck with round-tripping test. Added parser unit tests for bugs discovered by the round-tripping test.
93a5c13 FindReferences: add support for searching in a different compilation than the entity is defined in.
119bc9b Fix formatting tests on Windows with git autocrlf enabled.
37795e4 Fixed parsing of some statements, improved "foreach" context in code completion.
6b7acf5 Added foreach statement variable declaration test.
3d551ed Fixed parsing of some incomplete statements.
8007d25 Fix CSharpOutputVisitorTests.AssignmentInCollectionInitializer. Ignore some failing parser unit tests.
38b35b7 Fixed formatting unit tests on windows.
df4805f Fixed compiler warnings.
94bad6c Fixed "InactiveIf" unit test.
41f4589 Fixed unit test.
3e9a85d Fixed complex generic class unit test.
77a7581 Fixed constraints parsing #2.
8124aeb Fixed some more cases of "new" completion.
fa8e9a2 Fixed bug in "new" completion.
b84c06e Make CSharpResolver immutable.
92c8bd6 Fix NullReferenceException in DefaultResolvedField.ConstantValue when the field is not a constant.
1464b5d For IAssembly.GetTypeDefinition, treat ns==null the same as ns==string.Empty.
3b48632 Fixed bug in constraints parsing.
a781604 Corrected parameter index.
e90bf1c fixed "Bug 2072 - Duplicate entries in the code completion list".
fa5ec27 Resolve object create expression, if the parent is one. That causes a jump/tooltip for the constructor rather than the class on a object create expression.
831c059 Added unit test for reported md bug.
4bf1ddb Updated Gtk demo.
d7d9a55 Added mono compiler bug workaround.
48b6968 Updated mcs sources.
63367b9 Fixed some keyword cc tests.
0e92f47 Prevented a key already exists exception (but it's not a real fix for the problem).
d5880aa Fixed possible null reference exception.
27f18d7 Fixed possible null reference exception.
ae54fd5 Added GetTypeResolveContext implementation.
9606b56 Added GetTypeResolveContext to IParsedFile.
b1bfe5c Added full name constructor to defaultunresolvedTypeDefinition.

git-subtree-dir: NRefactory
git-subtree-split: 858d4cc673d3029460f6a009a3fb268884304c7f
8f45b7e
@dgrunwald dgrunwald Merge NRefactory 858d4cc6 into ILSpy master. 09c2b45
Showing with 5,878 additions and 4,232 deletions.
  1. +1 −1  ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. +18 −3 ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  3. +1 −1  NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
  4. +29 −2 NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ErrorExpression.cs
  5. +5 −4 NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Constraint.cs
  6. +28 −0 NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs
  7. +12 −1 NRefactory/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs
  8. +116 −18 NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  9. +2 −49 NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  10. +2 −2 NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs
  11. +1 −1  NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  12. +18 −14 NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
  13. +1 −1  NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs
  14. +1 −0  NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/IOutputFormatter.cs
  15. +68 −53 NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/TextWriterOutputFormatter.cs
  16. +12 −9 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  17. +9 −9 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs
  18. +3,506 −3,465 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  19. +40 −14 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  20. +10 −14 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  21. +1 −2  NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  22. +3 −3 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  23. +18 −7 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs
  24. +2 −1  NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs
  25. +38 −36 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  26. +24 −0 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/typespec.cs
  27. +6 −22 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/visit.cs
  28. +1 −1  NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TextReplaceAction.cs
  29. +1 −1  NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
  30. +1 −1  NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpAstResolver.cs
  31. +10 −4 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs
  32. +139 −54 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs
  33. +3 −2 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/FindReferenceSearchScope.cs
  34. +255 −123 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs
  35. +20 −1 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/Log.cs
  36. +4 −0 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveAtLocation.cs
  37. +107 −95 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
  38. +4 −1 NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs
  39. +25 −0 NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs
  40. +2 −8 NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/ConstantValues.cs
  41. +2 −2 NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  42. +3 −0  NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/.gitignore
  43. +176 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/CSharpProject.cs
  44. +72 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/ICSharpCode.NRefactory.ConsistencyCheck.csproj
  45. +91 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs
  46. +31 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/Properties/AssemblyInfo.cs
  47. +8 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/Readme.txt
  48. +83 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/ResolverTest.cs
  49. +108 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/RoundtripTest.cs
  50. +67 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/Solution.cs
  51. +6 −0 NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/app.config
  52. +1 −1  NRefactory/ICSharpCode.NRefactory.Demo/CSDemo.cs
  53. +23 −28 NRefactory/ICSharpCode.NRefactory.GtkDemo/MainWindow.cs
  54. +144 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
  55. +78 −4 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/KeywordTests.cs
  56. +27 −0 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ParameterCompletionTests.cs
  57. +33 −0 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/VariableDeclarationStatementTests.cs
  58. +2 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeDomConvertVisitorTests.cs
  59. +1 −1  NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs
  60. +2 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/CastExpressionTests.cs
  61. +4 −4 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/InvocationExpressionTests.cs
  62. +2 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs
  63. +18 −6 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PrimitiveExpressionTests.cs
  64. +1 −13 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeReferenceExpressionTests.cs
  65. +33 −1 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
  66. +1 −1  NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs
  67. +57 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/PreprocessorDirectiveTests.cs
  68. +10 −20 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
  69. +1 −1  NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseSelfTests.cs
  70. +2 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs
  71. +3 −3 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  72. +2 −5 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
  73. +2 −4 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/BinaryOperatorTests.cs
  74. +3 −6 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/CastTests.cs
  75. +43 −30 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  76. +22 −2 NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/UnaryOperatorTests.cs
  77. +1 −1  NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs
  78. +12 −12 NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs
  79. +11 −3 NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs
  80. +1 −0  NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  81. +1 −1  NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs
  82. +1 −4 NRefactory/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  83. +36 −0 NRefactory/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  84. +5 −0 NRefactory/ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs
  85. +20 −4 NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs
  86. +3 −1 NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedMember.cs
  87. +5 −1 NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedField.cs
  88. +41 −35 NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs
  89. +1 −1  NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedAssembly.cs
  90. +1 −1  NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedMethod.cs
  91. +18 −0 NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs
  92. +4 −0 NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/FullNameAndTypeParameterCount.cs
  93. +11 −1 NRefactory/NRefactory.sln
View
2  ICSharpCode.Decompiler/Ast/AstBuilder.cs
@@ -797,7 +797,7 @@ IEnumerable<Constraint> MakeConstraints(IEnumerable<GenericParameter> genericPar
{
foreach (var gp in genericParameters) {
Constraint c = new Constraint();
- c.TypeParameter = CleanName(gp.Name);
+ c.TypeParameter = new SimpleType(CleanName(gp.Name));
// class/struct must be first
if (gp.HasReferenceTypeConstraint)
c.BaseTypes.Add(new PrimitiveType("class"));
View
21 ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
@@ -147,7 +147,7 @@ object GetCurrentDefinition()
if (nodeStack == null || nodeStack.Count == 0)
return null;
- var node = nodeStack.Peek();
+ var node = nodeStack.Peek();
if (IsDefinition(node))
return node.Annotation<MemberReference>();
@@ -246,7 +246,22 @@ public void WriteComment(CommentType commentType, string content)
}
output.WriteLine();
break;
+ default:
+ output.Write(content);
+ break;
+ }
+ }
+
+ public void WritePreProcessorDirective(PreProcessorDirectiveType type, string argument)
+ {
+ // pre-processor directive must start on its own line
+ output.Write('#');
+ output.Write(type.ToString().ToLowerInvariant());
+ if (!string.IsNullOrEmpty(argument)) {
+ output.Write(' ');
+ output.Write(argument);
}
+ output.WriteLine();
}
Stack<TextLocation> startLocations = new Stack<TextLocation>();
@@ -312,10 +327,10 @@ public void EndNode(AstNode node)
private static bool IsDefinition(AstNode node)
{
- return
+ return
node is FieldDeclaration ||
node is ConstructorDeclaration ||
- node is DestructorDeclaration ||
+ node is DestructorDeclaration ||
node is EventDeclaration ||
node is DelegateDeclaration ||
node is OperatorDeclaration||
View
2  NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
@@ -436,7 +436,7 @@ public override ControlFlowNode VisitSwitchStatement(SwitchStatement switchState
}
}
}
- if (constant.IsCompileTimeConstant && sectionMatchedByConstant == null)
+ if (constant != null && constant.IsCompileTimeConstant && sectionMatchedByConstant == null)
sectionMatchedByConstant = defaultSection;
int gotoCaseOrDefaultInOuterScope = gotoCaseOrDefault.Count;
View
31 NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ErrorExpression.cs
@@ -27,16 +27,43 @@
namespace ICSharpCode.NRefactory.CSharp
{
- public class ErrorExpression : EmptyExpression
+ public class ErrorExpression : Expression
{
+ TextLocation location;
+
+ public override TextLocation StartLocation {
+ get {
+ return location;
+ }
+ }
+
+ public override TextLocation EndLocation {
+ get {
+ return location;
+ }
+ }
+
public ErrorExpression ()
{
}
- public ErrorExpression (TextLocation location) : base (location)
+ public ErrorExpression (TextLocation location)
{
+ this.location = location;
}
+
+ public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
+ {
+ // nothing
+ return default(S);
+ }
+
+ protected internal override bool DoMatch (AstNode other, PatternMatching.Match match)
+ {
+ var o = other as ErrorExpression;
+ return o != null;
+ }
}
}
View
9 NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Constraint.cs
@@ -38,6 +38,7 @@ public class Constraint : AstNode
{
public readonly static Role<CSharpTokenNode> ColonRole = TypeDeclaration.ColonRole;
public readonly static Role<AstType> BaseTypeRole = TypeDeclaration.BaseTypeRole;
+ public readonly static Role<SimpleType> TypeParameterRole = new Role<SimpleType> ("TypeParameter", SimpleType.Null);
public override NodeType NodeType {
get {
@@ -45,12 +46,12 @@ public class Constraint : AstNode
}
}
- public string TypeParameter {
+ public SimpleType TypeParameter {
get {
- return GetChildByRole (Roles.Identifier).Name;
+ return GetChildByRole (TypeParameterRole);
}
set {
- SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
+ SetChildByRole(TypeParameterRole, value);
}
}
@@ -66,7 +67,7 @@ public class Constraint : AstNode
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Constraint o = other as Constraint;
- return o != null && MatchString(this.TypeParameter, o.TypeParameter) && this.BaseTypes.DoMatch(o.BaseTypes, match);
+ return o != null && this.TypeParameter.DoMatch (o.TypeParameter, match) && this.BaseTypes.DoMatch(o.BaseTypes, match);
}
}
}
View
28 NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs
@@ -33,6 +33,29 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class SimpleType : AstType
{
+ #region Null
+ public new static readonly SimpleType Null = new NullSimpleType ();
+
+ sealed class NullSimpleType : SimpleType
+ {
+ public override bool IsNull {
+ get {
+ return true;
+ }
+ }
+
+ public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
+ {
+ return default (S);
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ return other == null || other.IsNull;
+ }
+ }
+ #endregion
+
public SimpleType()
{
}
@@ -42,6 +65,11 @@ public SimpleType(string identifier)
this.Identifier = identifier;
}
+ public SimpleType (Identifier identifier)
+ {
+ this.IdentifierToken = identifier;
+ }
+
public SimpleType(string identifier, TextLocation location)
{
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (identifier, location));
View
13 NRefactory/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs
@@ -139,7 +139,18 @@ public IProjectContent UpdateProjectContent(IParsedFile oldFile, IParsedFile new
public IProjectContent UpdateProjectContent(IEnumerable<IParsedFile> oldFiles, IEnumerable<IParsedFile> newFiles)
{
- throw new NotImplementedException();
+ CSharpProjectContent pc = new CSharpProjectContent(this);
+ if (oldFiles != null) {
+ foreach (var oldFile in oldFiles) {
+ pc.parsedFiles.Remove(oldFile.FileName);
+ }
+ }
+ if (newFiles != null) {
+ foreach (var newFile in newFiles) {
+ pc.parsedFiles.Add(newFile.FileName, newFile);
+ }
+ }
+ return pc;
}
IAssembly IAssemblyReference.Resolve(ITypeResolveContext context)
View
134 NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
@@ -78,8 +78,10 @@ public IEnumerable<ICompletionData> GetCompletionData (int offset, bool controlS
offset--;
if (offset > 0) {
var nonWsResult = MagicKeyCompletion (document.GetCharAt (offset), controlSpace);
- if (nonWsResult != null)
- result = result.Concat (nonWsResult);
+ if (nonWsResult != null) {
+ var text = new HashSet<string> (result.Select (r => r.CompletionText));
+ result = result.Concat (nonWsResult.Where (r => !text.Contains (r.CompletionText)));
+ }
}
}
@@ -243,9 +245,8 @@ IEnumerable<ICompletionData> MagicKeyCompletion (char completionChar, bool contr
int tokenIndex = offset;
string token = GetPreviousToken (ref tokenIndex, false);
-
// check propose name, for context <variable name> <ctrl+space> (but only in control space context)
- IType isAsType = null;
+ //IType isAsType = null;
var isAsExpression = GetExpressionAt (offset);
if (controlSpace && isAsExpression != null && isAsExpression.Item2 is VariableDeclarationStatement && token != "new") {
var parent = isAsExpression.Item2 as VariableDeclarationStatement;
@@ -431,12 +432,12 @@ IEnumerable<ICompletionData> MagicKeyCompletion (char completionChar, bool contr
// Do not pop up completion on identifier identifier (should be handled by keyword completion).
tokenIndex = offset - 1;
token = GetPreviousToken (ref tokenIndex, false);
- if (identifierStart == null && !string.IsNullOrEmpty (token) && !(IsInsideComment (tokenIndex) || IsInsideString (tokenIndex))) {
+ int prevTokenIndex = tokenIndex;
+ var prevToken2 = GetPreviousToken (ref prevTokenIndex, false);
+ if (identifierStart == null && !string.IsNullOrEmpty (token) && !(IsInsideComment (tokenIndex) || IsInsideString (tokenIndex)) && (prevToken2 == ";" || prevToken2 == "{" || prevToken2 == "}")) {
char last = token [token.Length - 1];
if (char.IsLetterOrDigit (last) || last == '_' || token == ">") {
return HandleKeywordCompletion (tokenIndex, token);
-
- //return controlSpace ? DefaultControlSpaceItems () : null;
}
}
if (identifierStart == null)
@@ -444,6 +445,24 @@ IEnumerable<ICompletionData> MagicKeyCompletion (char completionChar, bool contr
CSharpResolver csResolver;
AstNode n = identifierStart.Item2;
+ // Handle foreach (type name _
+ if (n is IdentifierExpression) {
+ var prev = n.GetPrevNode () as ForeachStatement;
+ if (prev != null && prev.InExpression.IsNull) {
+ if (controlSpace) {
+ contextList.AddCustom ("in");
+ return contextList.Result;
+ }
+ return null;
+ }
+ }
+
+ if (n is Identifier && n.Parent is ForeachStatement) {
+ if (controlSpace)
+ return DefaultControlSpaceItems ();
+ return null;
+ }
+
if (n is ArrayInitializerExpression) {
var initalizerResult = ResolveExpression (identifierStart.Item1, n.Parent, identifierStart.Item3);
@@ -578,7 +597,6 @@ IEnumerable<ICompletionData> HandleEnumContext ()
if (cu == null)
return null;
var member = cu.GetNodeAt<EnumMemberDeclaration> (location);
- Console.WriteLine ("member:" + cu.GetNodeAt (location) +"/" + location);
Print (cu);
if (member != null && member.NameToken.EndLocation < location)
return DefaultControlSpaceItems ();
@@ -622,6 +640,8 @@ IEnumerable<ICompletionData> HandleAccessorContext ()
IEnumerable<ICompletionData> DefaultControlSpaceItems ()
{
var wrapper = new CompletionDataWrapper (this);
+ if (offset >= document.TextLength)
+ offset = document.TextLength - 1;
while (offset > 1 && char.IsWhiteSpace (document.GetCharAt (offset))) {
offset--;
}
@@ -636,6 +656,18 @@ IEnumerable<ICompletionData> DefaultControlSpaceItems ()
node = Unit.GetNodeAt (location);
rr = ResolveExpression (CSharpParsedFile, node, Unit);
}
+ if (node is Identifier && node.Parent is ForeachStatement) {
+ var foreachStmt = (ForeachStatement)node.Parent;
+ foreach (var possibleName in GenerateNameProposals (foreachStmt.VariableType)) {
+ if (possibleName.Length > 0)
+ wrapper.Result.Add (factory.CreateLiteralCompletionData (possibleName.ToString ()));
+ }
+
+ AutoSelect = false;
+ AutoCompleteEmptyMatch = false;
+ return wrapper.Result;
+ }
+
AddContextCompletion (wrapper, rr != null && (node is Expression) ? rr.Item2 : GetState (), node);
@@ -674,16 +706,16 @@ void AddContextCompletion (CompletionDataWrapper wrapper, CSharpResolver state,
AddTypesAndNamespaces (wrapper, state, node, typePred);
wrapper.Result.Add (factory.CreateLiteralCompletionData ("global"));
- if (state.CurrentMember != null) {
+ if (currentMember != null) {
AddKeywords (wrapper, statementStartKeywords);
AddKeywords (wrapper, expressionLevelKeywords);
- } else if (state.CurrentTypeDefinition != null) {
+ } else if (currentType != null) {
AddKeywords (wrapper, typeLevelKeywords);
} else {
AddKeywords (wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
- if (prop != null && prop.Setter.Region.IsInside (location))
+ if (prop != null && prop.Setter != null && prop.Setter.Region.IsInside (location))
wrapper.AddCustom ("value");
if (currentMember is IUnresolvedEvent)
wrapper.AddCustom ("value");
@@ -977,6 +1009,51 @@ IEnumerable<ICompletionData> HandleKeywordCompletion (int wordStart, string word
if (newParentNode is VariableInitializer)
newParentNode = newParentNode.Parent;
}
+ if (newParentNode is InvocationExpression) {
+ var invoke = (InvocationExpression)newParentNode;
+ var resolved = ResolveExpression (expressionOrVariableDeclaration.Item1, invoke, expressionOrVariableDeclaration.Item3);
+ if (resolved != null) {
+ var mgr = resolved.Item1 as CSharpInvocationResolveResult;
+ if (mgr != null) {
+ int i1 = 0;
+ foreach (var a in invoke.Arguments) {
+ if (a == expressionOrVariableDeclaration.Item2) {
+ if (mgr.Member.Parameters.Count > i1)
+ hintType = mgr.Member.Parameters[i1].Type;
+ break;
+ }
+ i1++;
+ }
+ }
+ }
+ }
+
+ if (newParentNode is ObjectCreateExpression) {
+ var invoke = (ObjectCreateExpression)newParentNode;
+ var resolved = ResolveExpression (expressionOrVariableDeclaration.Item1, invoke, expressionOrVariableDeclaration.Item3);
+ if (resolved != null) {
+ var mgr = resolved.Item1 as CSharpInvocationResolveResult;
+ if (mgr != null) {
+ int i1 = 0;
+ foreach (var a in invoke.Arguments) {
+ if (a == expressionOrVariableDeclaration.Item2) {
+ if (mgr.Member.Parameters.Count > i1)
+ hintType = mgr.Member.Parameters[i1].Type;
+ break;
+ }
+ i1++;
+ }
+ }
+ }
+ }
+
+ if (newParentNode is AssignmentExpression) {
+ var assign = (AssignmentExpression)newParentNode;
+ var resolved = ResolveExpression (expressionOrVariableDeclaration.Item1, assign.Left, expressionOrVariableDeclaration.Item3);
+ if (resolved != null) {
+ hintType = resolved.Item1.Type;
+ }
+ }
if (newParentNode is VariableDeclarationStatement) {
var varDecl = (VariableDeclarationStatement)newParentNode;
@@ -1096,7 +1173,6 @@ IEnumerable<ICompletionData> CreateTypeCompletionData (IType hintType, AstType h
if (hintType != null) {
if (hintType.Kind != TypeKind.Unknown) {
- Console.WriteLine ("hint!");
var lookup = new MemberLookup (ctx.CurrentTypeDefinition, Compilation.MainAssembly);
pred = t => {
// check if type is in inheritance tree.
@@ -1106,7 +1182,6 @@ IEnumerable<ICompletionData> CreateTypeCompletionData (IType hintType, AstType h
// check for valid constructors
if (t.GetConstructors ().Count () == 0)
return true;
- Console.WriteLine ("check!");
bool isProtectedAllowed = currentType != null ? currentType.Resolve (ctx).GetDefinition ().IsDerivedFrom (t.GetDefinition ()) : false;
return t.GetConstructors ().Any (m => lookup.IsAccessible (m, isProtectedAllowed));
};
@@ -1556,8 +1631,8 @@ IEnumerable<ICompletionData> CreateCompletionData (TextLocation location, Resolv
includeStaticMembers = mrr.Member.Name == mrr.Type.Name;
}
- Console.WriteLine ("type:" + type +"/"+type.GetType ());
- Console.WriteLine ("IS PROT ALLOWED:" + isProtectedAllowed);
+// Console.WriteLine ("type:" + type +"/"+type.GetType ());
+// Console.WriteLine ("IS PROT ALLOWED:" + isProtectedAllowed);
// Console.WriteLine (resolveResult);
// Console.WriteLine (currentMember != null ? currentMember.IsStatic : "currentMember == null");
@@ -1785,6 +1860,15 @@ IEnumerable<ICompletionData> CreateCaseCompletionData (TextLocation location)
}
}
+ if (expr == null) {
+ var forStmt = tmpUnit.GetNodeAt<ForeachStatement> (location.Line, location.Column - 3);
+ if (forStmt != null && forStmt.EmbeddedStatement.IsNull) {
+ forStmt.VariableNameToken = Identifier.Create ("stub");
+ expr = forStmt.VariableNameToken;
+ baseUnit = tmpUnit;
+ }
+ }
+
if (expr == null) {
expr = tmpUnit.GetNodeAt<VariableInitializer> (location.Line, location.Column - 1);
@@ -1841,14 +1925,27 @@ IEnumerable<ICompletionData> CreateCaseCompletionData (TextLocation location)
var sb = new StringBuilder (text);
sb.Append ("a ();");
AppendMissingClosingBrackets (sb, text, false);
+
var stream = new System.IO.StringReader (sb.ToString ());
var completionUnit = parser.Parse (stream, CSharpParsedFile.FileName, 0);
stream.Close ();
var loc = document.GetLocation (offset);
var expr = completionUnit.GetNodeAt (loc, n => n is Expression);
- if (expr == null)
- return null;
+ if (expr == null) {
+ // try without ";"
+ sb = new StringBuilder (text);
+ sb.Append ("a ()");
+ AppendMissingClosingBrackets (sb, text, false);
+ stream = new System.IO.StringReader (sb.ToString ());
+ completionUnit = parser.Parse (stream, CSharpParsedFile.FileName, 0);
+ stream.Close ();
+ loc = document.GetLocation (offset);
+
+ expr = completionUnit.GetNodeAt (loc, n => n is Expression);
+ if (expr == null)
+ return null;
+ }
var tsvisitor = new TypeSystemConvertVisitor (CSharpParsedFile.FileName);
completionUnit.AcceptVisitor (tsvisitor, null);
@@ -2082,7 +2179,8 @@ IEnumerable<ICompletionData> GetXmlDocumentationCompletionData ()
"true", "false", "typeof", "checked", "unchecked", "from", "break", "checked",
"unchecked", "const", "continue", "do", "finally", "fixed", "for", "foreach",
"goto", "if", "lock", "return", "stackalloc", "switch", "throw", "try", "unsafe",
- "using", "while", "yield", "dynamic", "var" };
+ "using", "while", "yield", "dynamic", "var", "dynamic"
+ };
static string[] globalLevelKeywords = new string [] {
"namespace", "using", "extern", "public", "internal",
"class", "interface", "struct", "enum", "delegate",
View
51 NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
@@ -402,60 +402,13 @@ protected virtual void Reset ()
} else {
return null;
}
-// Print (baseUnit);
- /* var member = Unit.GetNodeAt<AttributedNode> (memberLocation);
- var member2 = baseUnit.GetNodeAt<AttributedNode> (memberLocation);
- member2.Remove ();
- member.ReplaceWith (member2);
- var tsvisitor = new TypeSystemConvertVisitor (ProjectContent, CSharpParsedFile.FileName);
- baseUnit.AcceptVisitor (tsvisitor, null);*/
- return Tuple.Create (CSharpParsedFile, (AstNode)expr, baseUnit);
-
- /*
-
- ///////
- if (currentMember == null && currentType == null)
- return null;
-
- CSharpParser parser = new CSharpParser ();
- int startOffset;
- if (currentMember != null) {
- startOffset = document.Editor.LocationToOffset (currentMember.Region.BeginLine, currentMember.Region.BeginColumn);
- } else {
- startOffset = document.Editor.LocationToOffset (currentType.Region.BeginLine, currentType.Region.BeginColumn);
- }
- string memberText = Document.Editor.GetTextBetween (startOffset, Document.Editor.Caret.Offset - 1);
-
- var memberLocation = currentMember != null ? currentMember.Region.Begin : currentType.Region.Begin;
- StringBuilder wrapper = new StringBuilder ();
- wrapper.Append ("class Stub {");
- wrapper.AppendLine ();
- wrapper.Append (memberText);
-
- if (afterBracket) {
- wrapper.Append ("();");
- } else {
- wrapper.Append ("x);");
- }
-
- wrapper.Append (" SomeCall (); } } }");
- var stream = new System.IO.StringReader (wrapper.ToString ());
- var baseUnit = parser.Parse (stream, memberLocation.Line - 2);
- stream.Close ();
- var expr = baseUnit.GetNodeAt<Expression> (document.Editor.Caret.Line, document.Editor.Caret.Column);
- if (expr is InvocationExpression) {
- expr = ((InvocationExpression)expr).Target;
- }
- if (expr == null)
- return null;
var member = Unit.GetNodeAt<AttributedNode> (memberLocation);
var member2 = baseUnit.GetNodeAt<AttributedNode> (memberLocation);
member2.Remove ();
member.ReplaceWith (member2);
-
- var tsvisitor = new TypeSystemConvertVisitor (ProjectContext, Document.FileName);
+ var tsvisitor = new TypeSystemConvertVisitor (CSharpParsedFile.FileName);
Unit.AcceptVisitor (tsvisitor, null);
- return Tuple.Create (tsvisitor.ParsedFile, expr, Unit);*/
+ return Tuple.Create (tsvisitor.ParsedFile, (AstNode)expr, Unit);
}
protected Tuple<ResolveResult, CSharpResolver> ResolveExpression (CSharpParsedFile file, AstNode expr, CompilationUnit unit)
View
4 NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs
@@ -194,6 +194,8 @@ public int GetCurrentParameterIndex (int triggerOffset)
{
SetOffset (triggerOffset);
var text = GetMemberTextToCaret ();
+ if (text.Item1.EndsWith ("("))
+ return 0;
var parameter = new Stack<int> ();
bool inSingleComment = false, inString = false, inVerbatimString = false, inChar = false, inMultiLineComment = false;
@@ -278,8 +280,6 @@ public int GetCurrentParameterIndex (int triggerOffset)
}
if (parameter.Count == 0)
return -1;
- if (text.Item1.EndsWith ("("))
- return 1;
return parameter.Pop () + 1;
}
View
2  NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
@@ -995,7 +995,7 @@ void AddChange (int offset, int removedChars, string insertedText)
return;
}
}
- //Console.WriteLine ("offset={0}, removedChars={1}, insertedText={2}", offset, removedChars, insertedText == null ? "<null>" : insertedText.Replace ("\n", "\\n").Replace ("\t", "\\t").Replace (" ", "."));
+ //Console.WriteLine ("offset={0}, removedChars={1}, insertedText={2}", offset, removedChars, insertedText == null ? "<null>" : insertedText.Replace ("\n", "\\n").Replace ("\r", "\\r").Replace ("\t", "\\t").Replace (" ", "."));
//Console.WriteLine (Environment.StackTrace);
changes.Add (factory.CreateTextReplaceAction (offset, removedChars, insertedText));
View
32 NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
@@ -604,8 +604,14 @@ public object VisitArrayCreateExpression (ArrayCreateExpression arrayCreateExpre
public object VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression, object data)
{
StartNode (arrayInitializerExpression);
+ // "new List<int> { { 1 } }" and "new List<int> { 1 }" are the same semantically.
+ // We also use the same AST for both: we always use two nested ArrayInitializerExpressions
+ // for collection initializers, even if the user did not write nested brackets.
+ // The output visitor will output nested braces only if they are necessary,
+ // or if the braces tokens exist in the AST.
bool bracesAreOptional = arrayInitializerExpression.Elements.Count == 1
- && IsObjectInitializer(arrayInitializerExpression.Parent);
+ && IsObjectOrCollectionInitializer(arrayInitializerExpression.Parent)
+ && !CanBeConfusedWithObjectInitializer(arrayInitializerExpression.Elements.Single());
if (bracesAreOptional && arrayInitializerExpression.LBraceToken.IsNull) {
arrayInitializerExpression.Elements.Single().AcceptVisitor(this, data);
} else {
@@ -614,7 +620,15 @@ public object VisitArrayInitializerExpression (ArrayInitializerExpression arrayI
return EndNode (arrayInitializerExpression);
}
- bool IsObjectInitializer(AstNode node)
+ bool CanBeConfusedWithObjectInitializer(Expression expr)
+ {
+ // "int a; new List<int> { a = 1 };" is an object initalizers and invalid, but
+ // "int a; new List<int> { { a = 1 } };" is a valid collection initializer.
+ AssignmentExpression ae = expr as AssignmentExpression;
+ return ae != null && ae.Operator == AssignmentOperatorType.Assign;
+ }
+
+ bool IsObjectOrCollectionInitializer(AstNode node)
{
if (!(node is ArrayInitializerExpression))
return false;
@@ -2318,18 +2332,8 @@ public object VisitComment (Comment comment, object data)
public object VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective, object data)
{
- if (lastWritten == LastWritten.Division) {
- // When there's a comment starting after a division operator
- // "1.0 / /*comment*/a", then we need to insert a space in front of the comment.
- formatter.Space ();
- }
formatter.StartNode (preProcessorDirective);
- formatter.WriteToken ("#" + preProcessorDirective.Type.ToString ().ToLower ());
- if (!string.IsNullOrEmpty(preProcessorDirective.Argument)) {
- formatter.Space();
- formatter.WriteToken(preProcessorDirective.Argument);
- }
- formatter.NewLine();
+ formatter.WritePreProcessorDirective(preProcessorDirective.Type, preProcessorDirective.Argument);
formatter.EndNode (preProcessorDirective);
lastWritten = LastWritten.Whitespace;
return null;
@@ -2360,7 +2364,7 @@ public object VisitConstraint (Constraint constraint, object data)
StartNode (constraint);
Space ();
WriteKeyword ("where");
- WriteIdentifier (constraint.TypeParameter);
+ WriteIdentifier (constraint.TypeParameter.Identifier);
Space ();
WriteToken (":", Constraint.ColonRole);
Space ();
View
2  NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs
@@ -1269,7 +1269,7 @@ CodeTypeParameter[] ConvertTypeParameters(IEnumerable<TypeParameterDeclaration>
CodeTypeParameter tp = new CodeTypeParameter(tpDecl.Name);
tp.CustomAttributes.AddRange(Convert(tpDecl.Attributes));
foreach (Constraint constraint in constraints) {
- if (constraint.TypeParameter == tp.Name) {
+ if (constraint.TypeParameter.Identifier == tp.Name) {
foreach (AstType baseType in constraint.BaseTypes) {
if (baseType is PrimitiveType && ((PrimitiveType)baseType).Keyword == "new") {
tp.HasConstructorConstraint = true;
View
1  NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/IOutputFormatter.cs
@@ -55,5 +55,6 @@ public interface IOutputFormatter
void NewLine();
void WriteComment(CommentType commentType, string content);
+ void WritePreProcessorDirective(PreProcessorDirectiveType type, string argument);
}
}
View
121 NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/TextWriterOutputFormatter.cs
@@ -77,39 +77,39 @@ public void OpenBrace(BraceStyle style)
{
bool isAtStartOfLine = needsIndent;
switch (style) {
- case BraceStyle.DoNotChange:
- case BraceStyle.EndOfLine:
- WriteIndentation();
- if (!isAtStartOfLine)
- textWriter.Write(' ');
- textWriter.Write('{');
- break;
- case BraceStyle.EndOfLineWithoutSpace:
- WriteIndentation();
- textWriter.Write('{');
- break;
- case BraceStyle.NextLine:
- if (!isAtStartOfLine)
+ case BraceStyle.DoNotChange:
+ case BraceStyle.EndOfLine:
+ WriteIndentation();
+ if (!isAtStartOfLine)
+ textWriter.Write(' ');
+ textWriter.Write('{');
+ break;
+ case BraceStyle.EndOfLineWithoutSpace:
+ WriteIndentation();
+ textWriter.Write('{');
+ break;
+ case BraceStyle.NextLine:
+ if (!isAtStartOfLine)
+ NewLine();
+ WriteIndentation();
+ textWriter.Write('{');
+ break;
+
+ case BraceStyle.NextLineShifted:
+ NewLine ();
+ Indent();
+ WriteIndentation();
+ textWriter.Write('{');
NewLine();
- WriteIndentation();
- textWriter.Write('{');
- break;
-
- case BraceStyle.NextLineShifted:
- NewLine ();
- Indent();
- WriteIndentation();
- textWriter.Write('{');
- NewLine();
- return;
- case BraceStyle.NextLineShifted2:
- NewLine ();
- Indent();
- WriteIndentation();
- textWriter.Write('{');
- break;
- default:
- throw new ArgumentOutOfRangeException ();
+ return;
+ case BraceStyle.NextLineShifted2:
+ NewLine ();
+ Indent();
+ WriteIndentation();
+ textWriter.Write('{');
+ break;
+ default:
+ throw new ArgumentOutOfRangeException ();
}
Indent();
NewLine();
@@ -118,27 +118,27 @@ public void OpenBrace(BraceStyle style)
public void CloseBrace(BraceStyle style)
{
switch (style) {
- case BraceStyle.DoNotChange:
- case BraceStyle.EndOfLine:
- case BraceStyle.EndOfLineWithoutSpace:
- case BraceStyle.NextLine:
- Unindent();
- WriteIndentation();
- textWriter.Write('}');
- break;
- case BraceStyle.NextLineShifted:
- WriteIndentation();
- textWriter.Write('}');
- Unindent();
- break;
- case BraceStyle.NextLineShifted2:
- Unindent();
- WriteIndentation();
- textWriter.Write('}');
- Unindent();
- break;
- default:
- throw new ArgumentOutOfRangeException ();
+ case BraceStyle.DoNotChange:
+ case BraceStyle.EndOfLine:
+ case BraceStyle.EndOfLineWithoutSpace:
+ case BraceStyle.NextLine:
+ Unindent();
+ WriteIndentation();
+ textWriter.Write('}');
+ break;
+ case BraceStyle.NextLineShifted:
+ WriteIndentation();
+ textWriter.Write('}');
+ Unindent();
+ break;
+ case BraceStyle.NextLineShifted2:
+ Unindent();
+ WriteIndentation();
+ textWriter.Write('}');
+ Unindent();
+ break;
+ default:
+ throw new ArgumentOutOfRangeException ();
}
}
@@ -193,6 +193,21 @@ public void WriteComment(CommentType commentType, string content)
}
}
+ public void WritePreProcessorDirective(PreProcessorDirectiveType type, string argument)
+ {
+ // pre-processor directive must start on its own line
+ if (!needsIndent)
+ NewLine();
+ WriteIndentation();
+ textWriter.Write('#');
+ textWriter.Write(type.ToString().ToLowerInvariant());
+ if (!string.IsNullOrEmpty(argument)) {
+ textWriter.Write(' ');
+ textWriter.Write(argument);
+ }
+ NewLine();
+ }
+
public virtual void StartNode(AstNode node)
{
}
View
21 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
@@ -1353,7 +1353,7 @@ public override object Visit (If ifStatement)
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IfElseStatement.Roles.LPar);
result.AddChild ((Expression)ifStatement.Expr.Accept (this), IfElseStatement.Roles.Condition);
- if (location != null)
+ if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IfElseStatement.Roles.RPar);
if (ifStatement.TrueStatement != null)
@@ -1376,10 +1376,11 @@ public override object Visit (Do doStatement)
result.AddChild ((Statement)doStatement.EmbeddedStatement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), DoWhileStatement.WhileKeywordRole);
- if (location != null)
+ if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DoWhileStatement.Roles.LPar);
- result.AddChild ((Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition);
- if (location != null) {
+ if (doStatement.expr != null)
+ result.AddChild ((Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition);
+ if (location != null && location.Count > 2) {
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DoWhileStatement.Roles.RPar);
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DoWhileStatement.Roles.Semicolon);
}
@@ -1848,8 +1849,10 @@ public override object Visit (TryCatch tryCatchStatement)
result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole);
if (tryCatchStatement.Block != null)
result.AddChild ((BlockStatement)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole);
- foreach (Catch ctch in tryCatchStatement.Specific) {
- result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
+ if (tryCatchStatement.Specific != null) {
+ foreach (Catch ctch in tryCatchStatement.Specific) {
+ result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
+ }
}
if (tryCatchStatement.General != null)
result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole);
@@ -1891,13 +1894,13 @@ public override object Visit (Foreach foreachStatement)
if (foreachStatement.Variable != null)
result.AddChild (Identifier.Create (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier);
- if (location != null)
+ if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location [1]), "in".Length), ForeachStatement.Roles.InKeyword);
if (foreachStatement.Expr != null)
result.AddChild ((Expression)foreachStatement.Expr.Accept (this), ForeachStatement.Roles.Expression);
- if (location != null)
+ if (location != null && location.Count > 2)
result.AddChild (new CSharpTokenNode (Convert (location [2]), 1), ForeachStatement.Roles.RPar);
if (foreachStatement.Statement != null)
result.AddChild ((Statement)foreachStatement.Statement.Accept (this), ForeachStatement.Roles.EmbeddedStatement);
@@ -2414,7 +2417,7 @@ void AddConstraints (AstNode parent, DeclSpace d)
var location = LocationsBag.GetLocations (c);
var constraint = new Constraint ();
constraint.AddChild (new CSharpTokenNode (Convert (c.Location), "where".Length), InvocationExpression.Roles.Keyword);
- constraint.AddChild (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
+ constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Constraint.TypeParameterRole);
if (location != null)
constraint.AddChild (new CSharpTokenNode (Convert (location [0]), 1), Constraint.ColonRole);
var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
View
18 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs
@@ -318,17 +318,16 @@ public void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, P
string assembly_name = a.GetString ();
if (assembly_name.Length == 0)
return;
-
- AssemblyName aname = null;
- try {
- aname = new AssemblyName (assembly_name);
- } catch (Exception) {
+#if STATIC
+ ParsedAssemblyName aname;
+ ParseAssemblyResult r = Fusion.ParseAssemblyName (assembly_name, out aname);
+ if (r != ParseAssemblyResult.OK) {
Report.Warning (1700, 3, a.Location, "Assembly reference `{0}' is invalid and cannot be resolved",
assembly_name);
return;
}
- if (aname.Version != null || aname.CultureInfo != null || aname.ProcessorArchitecture != ProcessorArchitecture.None) {
+ if (aname.Version != null || aname.Culture != null || aname.ProcessorArchitecture != ProcessorArchitecture.None) {
Report.Error (1725, a.Location,
"Friend assembly reference `{0}' is invalid. InternalsVisibleTo declarations cannot have a version, culture or processor architecture specified",
assembly_name);
@@ -336,13 +335,13 @@ public void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, P
return;
}
- // TODO: GetPublicKey () does not work on .NET when AssemblyName is constructed from a string
- if (public_key != null && aname.GetPublicKey () == null) {
+ if (public_key != null && !aname.HasPublicKey) {
Report.Error (1726, a.Location,
"Friend assembly reference `{0}' is invalid. Strong named assemblies must specify a public key in their InternalsVisibleTo declarations",
assembly_name);
return;
}
+#endif
} else if (a.Type == pa.RuntimeCompatibility) {
wrap_non_exception_throws_custom = true;
} else if (a.Type == pa.AssemblyFileVersion) {
@@ -486,6 +485,7 @@ public virtual void Emit ()
}
#else
var args = new PermissionSet[3];
+#pragma warning disable 618
declarative_security.TryGetValue (SecurityAction.RequestMinimum, out args[0]);
declarative_security.TryGetValue (SecurityAction.RequestOptional, out args[1]);
declarative_security.TryGetValue (SecurityAction.RequestRefuse, out args[2]);
@@ -827,7 +827,7 @@ public void Save ()
Compiler.TimeReporter.Stop (TimeReporter.TimerType.OutputSave);
// Save debug symbols file
- if (symbol_writer != null) {
+ if (symbol_writer != null && Compiler.Report.Errors == 0) {
// TODO: it should run in parallel
Compiler.TimeReporter.Start (TimeReporter.TimerType.DebugSave);
symbol_writer.WriteSymbolFile (SymbolWriter.GetGuid (module.Builder));
View
6,971 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
3,506 additions, 3,465 deletions not shown
View
54 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
@@ -151,19 +151,6 @@ namespace Mono.CSharp
List<Location> attributeCommas = new List<Location> ();
List<Location> attributeArgumentCommas = new List<Location> ();
List<Location> parameterListCommas = new List<Location> ();
-
- object lastYYVal;
-
- // Can be used for code completion to get the last valid expression before an error.
- // needs a hack in yyparse to make it work add
- // lastYYVal = yyVal;
- // after the big switch/case (somewhere around line 3915)
- public object LastYYVal {
- get {
- return lastYYVal;
- }
- }
-
%}
%token EOF
@@ -5165,6 +5152,12 @@ if_statement
if ($7 is EmptyStatement)
Warning_EmptyStatement (GetLocation ($7));
}
+ | IF open_parens_any boolean_expression error {
+ var eloc = GetLocation ($3);
+ report.Error (1026, eloc, "Expected a ')'");
+ $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2));
+ }
;
switch_statement
@@ -5276,6 +5269,18 @@ do_statement
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
}
+ | DO embedded_statement error
+ {
+ var loc = GetLocation ($1);
+ report.Error (-100, loc, "Expected `while'");
+ $$ = new Do ((Statement) $2, null, loc);
+ }
+ | DO embedded_statement
+ WHILE open_parens_any boolean_expression error
+ {
+ $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
+ }
;
for_statement
@@ -5403,6 +5408,27 @@ foreach_statement
lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
$$ = end_block (GetLocation ($7));
}
+ | FOREACH open_parens_any type identifier_inside_body error
+ {
+ start_block (GetLocation ($2));
+ current_block.IsCompilerGenerated = true;
+ var lt = $4 as Tokenizer.LocatedToken;
+ var li = lt != null ? new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location) : null;
+
+ Foreach f = new Foreach ((Expression) $3, li, null, null, GetLocation ($1));
+ current_block.AddStatement (f);
+
+ lbag.AddStatement (f, GetLocation ($2));
+ $$ = end_block (GetLocation ($5));
+ }
+ | FOREACH open_parens_any type error
+ {
+ Foreach f = new Foreach ((Expression) $3, null, null, null, GetLocation ($1));
+ current_block.AddStatement (f);
+
+ lbag.AddStatement (f, GetLocation ($2));
+ $$ = f;
+ }
;
jump_statement
@@ -5521,7 +5547,7 @@ try_statement
| TRY block error
{
report.Error (1524, GetLocation ($1), "Expected catch or finally");
- $$ = null;
+ $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
}
;
View
24 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
@@ -836,7 +836,6 @@ int GetKeyword (char[] id, int id_len)
}
return res;
- return res;
}
static PreprocessorDirective GetPreprocessorDirective (char[] id, int id_len)
@@ -1825,11 +1824,11 @@ int TokenizePreprocessorIdentifier (out int c, out int endLine, out int endCol)
{
// skip over white space
do {
+ endLine = line;
+ endCol = col;
c = get_char ();
} while (c == ' ' || c == '\t');
-
- endLine = line;
- endCol = col;
+
int pos = 0;
while (c != -1 && c >= 'a' && c <= 'z') {
id_builder[pos++] = (char) c;
@@ -1870,17 +1869,13 @@ PreprocessorDirective get_cmd_arg (out string arg)
return cmd;
}
-
// skip over white space
- while (c == ' ' || c == '\t')
+ while (c == ' ' || c == '\t') {
c = get_char ();
-
+ }
int has_identifier_argument = (int)(cmd & PreprocessorDirective.RequiresArgument);
int pos = 0;
- endLine = line;
- endCol = col;
-
while (c != -1 && c != '\n' && c != '\r') {
if (c == '\\' && has_identifier_argument >= 0) {
if (has_identifier_argument != 0) {
@@ -1914,9 +1909,9 @@ PreprocessorDirective get_cmd_arg (out string arg)
break;
}
-
+
endLine = line;
- endCol = col;
+ endCol = col + 1;
if (pos == value_builder.Length)
Array.Resize (ref value_builder, pos * 2);
@@ -1935,7 +1930,7 @@ PreprocessorDirective get_cmd_arg (out string arg)
arg = arg.Trim (simple_whitespaces);
}
if (position_stack.Count == 0)
- sbag.AddPreProcessorDirective (startLine, startCol, endLine, endCol + 1, cmd, arg);
+ sbag.AddPreProcessorDirective (startLine, startCol, endLine, endCol, cmd, arg);
return cmd;
}
@@ -3348,7 +3343,7 @@ public int xtoken ()
if (ParsePreprocessingDirective (true))
continue;
- sbag.StartComment (SpecialsBag.CommentType.Multi, false, line, col);
+ sbag.StartComment (SpecialsBag.CommentType.InactiveCode, false, line, 1);
bool directive_expected = false;
while ((c = get_char ()) != -1) {
if (col == 1) {
@@ -3359,6 +3354,7 @@ public int xtoken ()
// Eror_WrongPreprocessorLocation ();
// return Token.ERROR;
// }
+ sbag.PushCommentChar (c);
continue;
}
View
3  NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
@@ -462,8 +462,7 @@ public static CompilerCompilationUnit ParseFile (string[] args, Stream input, st
ModuleCompiled = RootContext.ToplevelTypes,
LocationsBag = parser.LocationsBag,
UsingsBag = parser.UsingsBag,
- SpecialsBag = parser.Lexer.sbag,
- LastYYValue = parser.LastYYVal
+ SpecialsBag = parser.Lexer.sbag
};
} finally {
Reset ();
View
6 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
@@ -6044,7 +6044,7 @@ public class ArrayCreation : Expression
// The number of constants in array initializers
int const_initializers_count;
- bool only_constant_initializers;
+// bool only_constant_initializers;
public List<Expression> Arguments {
get { return this.arguments; }
@@ -6179,7 +6179,7 @@ bool CheckIndices (ResolveContext ec, ArrayInitializer probe, int idx, bool spec
++const_initializers_count;
}
} else {
- only_constant_initializers = false;
+// only_constant_initializers = false;
}
array_data.Add (element);
@@ -6284,7 +6284,7 @@ protected virtual Expression ResolveArrayElement (ResolveContext ec, Expression
protected bool ResolveInitializers (ResolveContext ec)
{
- only_constant_initializers = true;
+// only_constant_initializers = true;
if (arguments != null) {
bool res = true;
View
25 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs
@@ -3264,7 +3264,7 @@ int LowerBoundInference (TypeSpec u, TypeSpec v, bool inversed)
return LowerBoundInference (u_ac.Element, v_i);
}
- if (TypeManager.IsGenericType (v)) {
+ if (v.IsGenericOrParentIsGeneric) {
//
// if V is a constructed type C<V1..Vk> and there is a unique type C<U1..Uk>
// such that U is identical to, inherits from (directly or indirectly),
@@ -3292,8 +3292,8 @@ int LowerBoundInference (TypeSpec u, TypeSpec v, bool inversed)
}
}
- TypeSpec [] unique_candidate_targs = null;
- TypeSpec[] ga_v = TypeManager.GetTypeArguments (v);
+ TypeSpec[] unique_candidate_targs = null;
+ var ga_v = TypeSpec.GetAllTypeArguments (v);
foreach (TypeSpec u_candidate in u_candidates) {
//
// The unique set of types U1..Uk means that if we have an interface I<T>,
@@ -3301,7 +3301,7 @@ int LowerBoundInference (TypeSpec u, TypeSpec v, bool inversed)
// type I<T> by applying type U because T could be int or long
//
if (unique_candidate_targs != null) {
- TypeSpec[] second_unique_candidate_targs = TypeManager.GetTypeArguments (u_candidate);
+ TypeSpec[] second_unique_candidate_targs = TypeSpec.GetAllTypeArguments (u_candidate);
if (TypeSpecComparer.Equals (unique_candidate_targs, second_unique_candidate_targs)) {
unique_candidate_targs = second_unique_candidate_targs;
continue;
@@ -3327,15 +3327,25 @@ int LowerBoundInference (TypeSpec u, TypeSpec v, bool inversed)
for (int i = 0; i < unique_candidate_targs.Length; ++i)
unique_candidate_targs[i] = u_candidate;
} else {
- unique_candidate_targs = TypeManager.GetTypeArguments (u_candidate);
+ unique_candidate_targs = TypeSpec.GetAllTypeArguments (u_candidate);
}
}
if (unique_candidate_targs != null) {
- var ga_open_v = open_v.TypeParameters;
int score = 0;
+ int tp_index = -1;
+ TypeParameterSpec[] tps = null;
+
for (int i = 0; i < unique_candidate_targs.Length; ++i) {
- Variance variance = ga_open_v [i].Variance;
+ if (tp_index < 0) {
+ while (v.Arity == 0)
+ v = v.DeclaringType;
+
+ tps = v.MemberDefinition.TypeParameters;
+ tp_index = tps.Length - 1;
+ }
+
+ Variance variance = tps [tp_index--].Variance;
TypeSpec u_i = unique_candidate_targs [i];
if (variance == Variance.None || TypeSpec.IsValueType (u_i)) {
@@ -3349,6 +3359,7 @@ int LowerBoundInference (TypeSpec u, TypeSpec v, bool inversed)
++score;
}
}
+
return score;
}
}
View
3  NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs
@@ -477,7 +477,8 @@ public enum CommentType
{
Single,
Multi,
- Documentation
+ Documentation,
+ InactiveCode
}
public class Comment
View
74 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
@@ -667,6 +667,37 @@ public override object Accept (StructuralVisitor visitor)
}
}
+ public class StatementErrorExpression : Statement
+ {
+ readonly Expression expr;
+
+ public StatementErrorExpression (Expression expr)
+ {
+ this.expr = expr;
+ }
+
+ public Expression Expression {
+ get {
+ return expr;
+ }
+ }
+
+ protected override void DoEmit (EmitContext ec)
+ {
+ throw new NotSupportedException ();
+ }
+
+ protected override void CloneTo (CloneContext clonectx, Statement target)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
+ }
+
//
// Simple version of statement list not requiring a block
//
@@ -5181,11 +5212,13 @@ public TryCatch (Block block, List<Catch> catch_clauses, Location l, bool inside
this.Block = block;
this.Specific = catch_clauses;
this.inside_try_finally = inside_try_finally;
-
- Catch c = catch_clauses [0];
- if (c.IsGeneral) {
- this.General = c;
- catch_clauses.RemoveAt (0);
+
+ if (catch_clauses != null) {
+ Catch c = catch_clauses [0];
+ if (c.IsGeneral) {
+ this.General = c;
+ catch_clauses.RemoveAt (0);
+ }
}
}
@@ -6161,35 +6194,4 @@ public override object Accept (StructuralVisitor visitor)
return visitor.Visit (this);
}
}
-
- public class StatementErrorExpression : Statement
- {
- readonly Expression expr;
-
- public Expression Expression {
- get {
- return expr;
- }
- }
-
- public StatementErrorExpression (Expression expr)
- {
- this.expr = expr;
- }
-
- protected override void DoEmit (EmitContext ec)
- {
- throw new NotImplementedException ();
- }
-
- protected override void CloneTo (CloneContext clonectx, Statement target)
- {
- throw new NotImplementedException ();
- }
-
- public override object Accept (StructuralVisitor visitor)
- {
- return visitor.Visit (this);
- }
- }
}
View
24 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/typespec.cs
@@ -390,6 +390,30 @@ public bool AddInterfaceDefined (TypeSpec iface)
return true;
}
+ //
+ // Returns all type arguments, usefull for nested types
+ //
+ public static TypeSpec[] GetAllTypeArguments (TypeSpec type)
+ {
+ IList<TypeSpec> targs = TypeSpec.EmptyTypes;
+
+ do {
+ if (type.Arity > 0) {
+ if (targs.Count == 0) {
+ targs = type.TypeArguments;
+ } else {
+ var list = targs as List<TypeSpec> ?? new List<TypeSpec> (targs);
+ list.AddRange (type.TypeArguments);
+ targs = list;
+ }
+ }
+
+ type = type.declaringType;
+ } while (type != null);
+
+ return targs as TypeSpec[] ?? ((List<TypeSpec>) targs).ToArray ();
+ }
+
public AttributeUsageAttribute GetAttributeUsage (PredefinedAttribute pa)
{
if (Kind != MemberKind.Class)
View
28 NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/visit.cs
@@ -7,6 +7,7 @@
// Dual licensed under the terms of the MIT X11 or GNU GPL
//
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc
//
using System;
@@ -178,7 +179,7 @@ public virtual object Visit (EmptyExpressionStatement emptyExpressionStatement)
{
return null;
}
-
+
public virtual object Visit (EmptyExpression emptyExpression)
{
return null;
@@ -200,73 +201,66 @@ public virtual object Visit (Do doStatement)
return null;
}
-
public virtual object Visit (While whileStatement)
{
return null;
}
-
public virtual object Visit (For forStatement)
{
return null;
}
-
public virtual object Visit (StatementExpression statementExpression)
{
return null;
}
+ public virtual object Visit (StatementErrorExpression errorStatement)
+ {
+ return null;
+ }
public virtual object Visit (Return returnStatement)
{
return null;
}
-
public virtual object Visit (Goto gotoStatement)
{
return null;
}
-
public virtual object Visit (LabeledStatement labeledStatement)
{
return null;
}
-
public virtual object Visit (GotoDefault gotoDefault)
{
return null;
}
-
public virtual object Visit (GotoCase gotoCase)
{
return null;
}
-
public virtual object Visit (Throw throwStatement)
{
return null;
}
-
public virtual object Visit (Break breakStatement)
{
return null;
}
-
public virtual object Visit (Continue continueStatement)
{
return null;
}
-
public virtual object Visit (Block blockStatement)
{
return null;
@@ -287,19 +281,16 @@ public virtual object Visit (Lock lockStatement)
return null;
}
-
public virtual object Visit (Unchecked uncheckedStatement)
{
return null;
}
-
public virtual object Visit (Checked checkedStatement)
{
return null;
}
-
public virtual object Visit (Unsafe unsafeStatement)
{
return null;
@@ -317,7 +308,6 @@ public virtual object Visit (TryFinally tryFinallyStatement)
return null;
}
-
public virtual object Visit (TryCatch tryCatchStatement)
{
return null;
@@ -445,7 +435,6 @@ public virtual object Visit (Nullable.NullCoalescingOperator nullCoalescingOpera
return null;
}
-
public virtual object Visit (Conditional conditionalExpression)
{
return null;
@@ -646,10 +635,5 @@ public virtual object Visit (Await awaitExpr)
{
return null;
}
-
- public virtual object Visit (StatementErrorExpression statementErrorExpression)
- {
- return null;
- }
}
}
View
2  NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TextReplaceAction.cs
@@ -128,7 +128,7 @@ public TextReplaceAction (int offset, int removedChars, string insertedText) : t
/// </returns>
public override string ToString ()
{
- return string.Format ("[TextReplaceAction: Offset={0}, RemovedChars={1}, InsertedText={2}]", Offset, RemovedChars, InsertedText == null ? "<null>" : InsertedText.Replace ("\t", "\\t").Replace ("\n", "\\n"));
+ return string.Format ("[TextReplaceAction: Offset={0}, RemovedChars={1}, InsertedText={2}]", Offset, RemovedChars, InsertedText == null ? "<null>" : InsertedText.Replace ("\t", "\\t").Replace ("\n", "\\n").Replace ("\r", "\\r"));
}
}
}
View
2  NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
@@ -682,7 +682,7 @@ Constraint ConvertTypeParameterConstraint(ITypeParameter tp)
return null;
}
Constraint c = new Constraint();
- c.TypeParameter = tp.Name;
+ c.TypeParameter = new SimpleType (tp.Name);
if (tp.HasReferenceTypeConstraint) {
c.BaseTypes.Add(new PrimitiveType("class"));
} else if (tp.HasValueTypeConstraint) {
View
2  NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpAstResolver.cs
@@ -70,7 +70,7 @@ public CSharpAstResolver(CSharpResolver resolver, AstNode rootNode, CSharpParsed
throw new ArgumentNullException("resolver");
if (rootNode == null)
throw new ArgumentNullException("rootNode");
- this.initialResolverState = resolver.Clone();
+ this.initialResolverState = resolver;
this.rootNode = rootNode;
this.parsedFile = parsedFile;
}
View
14 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs
@@ -289,6 +289,8 @@ public LambdaUnaryOperatorMethod(CSharpOperators operators, Func<T, T> func)
public override object Invoke(CSharpResolver resolver, object input)
{
+ if (input == null)
+ return null;
return func((T)resolver.CSharpPrimitiveCast(Type.GetTypeCode(typeof(T)), input));
}
@@ -456,6 +458,8 @@ public LambdaBinaryOperatorMethod(CSharpOperators operators, Func<T1, T2, T1> ch
public override object Invoke(CSharpResolver resolver, object lhs, object rhs)
{
+ if (lhs == null || rhs == null)
+ return null;
Func<T1, T2, T1> func = resolver.CheckForOverflow ? checkedFunc : uncheckedFunc;
return func((T1)resolver.CSharpPrimitiveCast(Type.GetTypeCode(typeof(T1)), lhs),
(T2)resolver.CSharpPrimitiveCast(Type.GetTypeCode(typeof(T2)), rhs));
@@ -692,6 +696,10 @@ public EqualityOperatorMethod(CSharpOperators operators, TypeCode type, bool neg
public override object Invoke(CSharpResolver resolver, object lhs, object rhs)
{
+ if (lhs == null && rhs == null)
+ return !Negate; // ==: true; !=: false
+ if (lhs == null || rhs == null)
+ return Negate; // ==: false; !=: true
lhs = resolver.CSharpPrimitiveCast(Type, lhs);
rhs = resolver.CSharpPrimitiveCast(Type, rhs);
bool equal;
@@ -734,10 +742,6 @@ public LiftedEqualityOperatorMethod(CSharpOperators operators, EqualityOperatorM
public override object Invoke(CSharpResolver resolver, object lhs, object rhs)
{
- if (lhs == null && rhs == null)
- return !baseMethod.Negate; // ==: true; !=: false
- if (lhs == null || rhs == null)
- return baseMethod.Negate; // ==: false; !=: true
return baseMethod.Invoke(resolver, lhs, rhs);
}
@@ -809,6 +813,8 @@ public RelationalOperatorMethod(CSharpOperators operators, Func<T1, T2, bool> fu
public override object Invoke(CSharpResolver resolver, object lhs, object rhs)
{
+ if (lhs == null || rhs == null)
+ return null;
return func((T1)resolver.CSharpPrimitiveCast(Type.GetTypeCode(typeof(T1)), lhs),
(T2)resolver.CSharpPrimitiveCast(Type.GetTypeCode(typeof(T2)), rhs));
}
View
193 NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs
@@ -43,7 +43,9 @@ public class CSharpResolver