diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs index 3b662a95a4..dbcf0192dd 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp public string Name { get { - return NamespaceName.ToString(); + return UsingDeclaration.ConstructNamespace(NamespaceName); } set { var arr = value.Split('.'); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingDeclaration.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingDeclaration.cs index eff582c338..9e0c35a898 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingDeclaration.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingDeclaration.cs @@ -27,6 +27,7 @@ using System; using System.Linq; using System.Text; +using System.Collections.Generic; namespace ICSharpCode.NRefactory.CSharp { @@ -54,7 +55,29 @@ namespace ICSharpCode.NRefactory.CSharp } public string Namespace { - get { return this.Import.ToString(); } + get { return ConstructNamespace (Import); } + } + + internal static string ConstructNamespace (AstType type) + { + var stack = new Stack(); + while (type is MemberType) { + var mt = (MemberType)type; + stack.Push(mt.MemberName); + type = mt.Target; + if (mt.IsDoubleColon) { + stack.Push("::"); + } else { + stack.Push("."); + } + } + if (type is SimpleType) + stack.Push(((SimpleType)type).Identifier); + + var result = new StringBuilder(); + while (stack.Count > 0) + result.Append(stack.Pop()); + return result.ToString(); } public CSharpTokenNode SemicolonToken { diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index eb4f38f525..235ee5501b 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -350,8 +350,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } var lookup = new MemberLookup(ctx.CurrentTypeDefinition, Compilation.MainAssembly); bool isProtectedAllowed = ctx.CurrentTypeDefinition != null && initializerType.GetDefinition() != null ? - ctx.CurrentTypeDefinition.IsDerivedFrom(initializerType.GetDefinition()) : - false; + ctx.CurrentTypeDefinition.IsDerivedFrom(initializerType.GetDefinition()) : + false; foreach (var m in initializerType.GetMembers (m => m.SymbolKind == SymbolKind.Field)) { var f = m as IField; if (f != null && (f.IsReadOnly || f.IsConst)) @@ -844,6 +844,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return null; case "+=": case "-=": + var curTokenIndex = tokenIndex; GetPreviousToken(ref tokenIndex, false); expressionOrVariableDeclaration = GetExpressionAt(tokenIndex); @@ -881,17 +882,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion if (token == "+=") { string parameterDefinition = AddDelegateHandlers( wrapper, - delegateType - ); - string varName = GetPreviousMemberReferenceExpression(tokenIndex); - wrapper.Result.Add( - factory.CreateEventCreationCompletionData( - varName, - delegateType, - evt, - parameterDefinition, - currentMember, - currentType) + delegateType, + optDelegateName: GuessEventHandlerMethodName(curTokenIndex) ); } @@ -2316,7 +2308,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion for (int j = line.Offset; j < line.EndOffset; j++) { char ch = document.GetCharAt(j); if (!char.IsWhiteSpace(ch)) { - return document.GetText(line.Offset, j - line.Offset - 1); + return document.GetText(line.Offset, j - line.Offset); } } return ""; @@ -2364,7 +2356,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion // check for valid constructors if (t.GetConstructors().Count() > 0) { bool isProtectedAllowed = currentType != null ? - currentType.Resolve(ctx).GetDefinition().IsDerivedFrom(t.GetDefinition()) : false; + currentType.Resolve(ctx).GetDefinition().IsDerivedFrom(t.GetDefinition()) : false; if (!t.GetConstructors().Any(m => lookup.IsAccessible(m, isProtectedAllowed))) { return null; } @@ -2589,36 +2581,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } } - public string GetPreviousMemberReferenceExpression(int tokenIndex) + public string GuessEventHandlerMethodName(int tokenIndex) { string result = GetPreviousToken(ref tokenIndex, false); - result = GetPreviousToken(ref tokenIndex, false); - if (result != ".") { - result = null; - } else { - var names = new List(); - while (result == ".") { - result = GetPreviousToken(ref tokenIndex, false); - if (result == "this") { - names.Add("handle"); - } else if (result != null) { - string trimmedName = result.Trim(); - if (trimmedName.Length == 0) { - break; - } - names.Insert(0, trimmedName); - } - result = GetPreviousToken(ref tokenIndex, false); - } - result = String.Join("", names.ToArray()); - foreach (char ch in result) { - if (!char.IsLetterOrDigit(ch) && ch != '_') { - result = ""; - break; - } - } - } - return result; + return "Handle" + result; } bool MatchDelegate(IType delegateType, IMethod method) @@ -2654,13 +2620,13 @@ namespace ICSharpCode.NRefactory.CSharp.Completion "delegate", "Creates anonymous delegate.", "delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; if (LanguageVersion.Major >= 5) { completionList.AddCustom( "async delegate", "Creates anonymous async delegate.", "async delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; } } var sb = new StringBuilder("("); @@ -2691,26 +2657,26 @@ namespace ICSharpCode.NRefactory.CSharp.Completion "delegate" + signature, "Creates anonymous delegate.", "delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; if (LanguageVersion.Major >= 5) { completionList.AddCustom( "async delegate" + signature, "Creates anonymous async delegate.", "async delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; } if (!completionList.Result.Any(data => data.DisplayText == sb.ToString())) { completionList.AddCustom( signature, "Creates typed lambda expression.", signature + " => |" + (addSemicolon ? ";" : "") - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; if (LanguageVersion.Major >= 5) { completionList.AddCustom( "async " + signature, "Creates typed async lambda expression.", "async " + signature + " => |" + (addSemicolon ? ";" : "") - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; } if (!delegateMethod.Parameters.Any(p => p.IsOut || p.IsRef) && !completionList.Result.Any(data => data.DisplayText == sbWithoutTypes.ToString())) { @@ -2718,33 +2684,25 @@ namespace ICSharpCode.NRefactory.CSharp.Completion sbWithoutTypes.ToString(), "Creates lambda expression.", sbWithoutTypes + " => |" + (addSemicolon ? ";" : "") - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; if (LanguageVersion.Major >= 5) { completionList.AddCustom( "async " + sbWithoutTypes, "Creates async lambda expression.", "async " + sbWithoutTypes + " => |" + (addSemicolon ? ";" : "") - ); + ).DisplayFlags |= DisplayFlags.MarkedBold; } } } } - string varName = "Handle" + delegateType.Name + optDelegateName; - completionList.Add(factory.CreateEventCreationCompletionData(varName, delegateType, null, signature, currentMember, currentType)); + string varName = optDelegateName ?? "Handle" + delegateType.Name; + var ecd = factory.CreateEventCreationCompletionData(varName, delegateType, null, signature, currentMember, currentType); + ecd.DisplayFlags |= DisplayFlags.MarkedBold; + completionList.Add(ecd); - /* TODO:Make factory method out of it. - // It's needed to temporarly disable inserting auto matching bracket because the anonymous delegates are selectable with '(' - // otherwise we would end up with () => ) - if (!containsDelegateData) { - var savedValue = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket; - MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = false; - completionList.Result.CompletionListClosed += delegate { - MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = savedValue; - }; - }*/ return sb.ToString(); } @@ -2835,7 +2793,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion var astResolver = unit != null ? CompletionContextProvider.GetResolver(state, unit) : null; IType hintType = exprParent != null && astResolver != null ? TypeGuessing.GetValidTypes(astResolver, exprParent).FirstOrDefault() : - null; + null; var result = new CompletionDataWrapper(this); var lookup = new MemberLookup( ctx.CurrentTypeDefinition, @@ -2900,7 +2858,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion if (resolvedType.Kind == TypeKind.Delegate) { if (addedDelegates.Contains(resolvedType.ReflectionName)) return; - AddDelegateHandlers(result, resolvedType, false, true, method.Parameters [parameter].Name); + AddDelegateHandlers(result, resolvedType, false, true, "Handle" + method.Parameters [parameter].Type.Name + method.Parameters [parameter].Name); } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CompletionDataWrapper.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CompletionDataWrapper.cs index 39cbba279f..4bf10d937d 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CompletionDataWrapper.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CompletionDataWrapper.cs @@ -65,9 +65,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } - public void AddCustom (string displayText, string description = null, string completionText = null) + public ICompletionData AddCustom (string displayText, string description = null, string completionText = null) { - result.Add (Factory.CreateLiteralCompletionData (displayText, description, completionText)); + var literalCompletionData = Factory.CreateLiteralCompletionData(displayText, description, completionText); + result.Add(literalCompletionData); + return literalCompletionData; } HashSet usedNamespaces = new HashSet (); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/ICompletionDataFactory.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/ICompletionDataFactory.cs index 10d7a04d10..da61f89077 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/ICompletionDataFactory.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/ICompletionDataFactory.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion ICompletionData CreateVariableCompletionData (ITypeParameter parameter); - ICompletionData CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType); + ICompletionData CreateEventCreationCompletionData (string delegateMethodName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType); ICompletionData CreateNewOverrideCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IMember m); ICompletionData CreateNewPartialCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IUnresolvedMember m); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs index 052c3a75a4..0a97a1c0b8 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs @@ -186,6 +186,11 @@ namespace ICSharpCode.NRefactory.CSharp get; set; } + + public bool IndentBlocksInsideExpressions { + get; + set; + } #endregion #region Braces diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs index be934091a6..ff32c1f8cb 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs @@ -59,6 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp IndentCaseBody = true, IndentBreakStatements = true, IndentPreprocessorDirectives = true, + IndentBlocksInsideExpressions = false, NamespaceBraceStyle = BraceStyle.NextLine, ClassBraceStyle = BraceStyle.NextLine, InterfaceBraceStyle = BraceStyle.NextLine, @@ -390,6 +391,7 @@ namespace ICSharpCode.NRefactory.CSharp baseOptions.FinallyNewLinePlacement = NewLinePlacement.NewLine; baseOptions.WhileNewLinePlacement = NewLinePlacement.DoNotCare; baseOptions.ArrayInitializerWrapping = Wrapping.DoNotChange; + baseOptions.IndentBlocksInsideExpressions = true; return baseOptions; } @@ -418,6 +420,7 @@ namespace ICSharpCode.NRefactory.CSharp baseOptions.EventAddBraceStyle = BraceStyle.NextLineShifted; baseOptions.EventRemoveBraceStyle = BraceStyle.NextLineShifted; baseOptions.StatementBraceStyle = BraceStyle.NextLineShifted; + baseOptions.IndentBlocksInsideExpressions = true; return baseOptions; } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Expressions.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Expressions.cs index 6b6cd2ff15..582e26fea2 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Expressions.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Expressions.cs @@ -389,13 +389,21 @@ namespace ICSharpCode.NRefactory.CSharp } else { foreach (var arg in arguments.Take (argumentStart)) { + if (policy.IndentBlocksInsideExpressions) + curIndent.Push(IndentType.Continuation); arg.AcceptVisitor(this); + if (policy.IndentBlocksInsideExpressions) + curIndent.Pop(); } foreach (var arg in arguments.Skip(argumentStart)) { if (arg.GetPrevSibling(NoWhitespacePredicate) != null) { if (methodCallArgumentWrapping == Wrapping.DoNotWrap) { ForceSpacesBeforeRemoveNewLines(arg, spaceAfterMethodCallParameterComma && arg.GetPrevSibling(NoWhitespacePredicate).Role == Roles.Comma); + if (policy.IndentBlocksInsideExpressions) + curIndent.Push(IndentType.Continuation); arg.AcceptVisitor(this); + if (policy.IndentBlocksInsideExpressions) + curIndent.Pop(); } else { if (!doAlignToFirstArgument && arg.PrevSibling.Role == Roles.NewLine) { curIndent.Push(IndentType.Continuation); @@ -405,7 +413,11 @@ namespace ICSharpCode.NRefactory.CSharp } else { if (arg.PrevSibling.StartLocation.Line == arg.StartLocation.Line) { ForceSpacesBefore(arg, spaceAfterMethodCallParameterComma && arg.GetPrevSibling(NoWhitespacePredicate).Role == Roles.Comma); + if (policy.IndentBlocksInsideExpressions) + curIndent.Push(IndentType.Continuation); arg.AcceptVisitor(this); + if (policy.IndentBlocksInsideExpressions) + curIndent.Pop(); } else { int extraSpaces = Math.Max(0, arguments.First().StartLocation.Column - 1 - curIndent.IndentString.Length); curIndent.ExtraSpaces += extraSpaces; diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs index 1d020e1b57..1e230e0918 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs @@ -485,7 +485,6 @@ namespace ICSharpCode.NRefactory.CSharp ThisLineIndent.RemoveAlignment(); while (ThisLineIndent.CurIndent > PreviousLineIndent && ThisLineIndent.PopIf(IndentType.Continuation)) ; - ThisLineIndent.Push(IndentType.Continuation); NextLineIndent = ThisLineIndent.Clone(); } @@ -517,8 +516,10 @@ namespace ICSharpCode.NRefactory.CSharp var parent = Parent as BracesBodyState; if (parent == null || parent.LastBlockIndent == null || !Engine.EnableCustomIndentLevels) { - NextLineIndent.RemoveAlignment(); - NextLineIndent.PopIf(IndentType.Continuation); + if (!Engine.formattingOptions.IndentBlocksInsideExpressions) { + NextLineIndent.RemoveAlignment(); + NextLineIndent.PopIf(IndentType.Continuation); + } } else { @@ -1032,7 +1033,7 @@ namespace ICSharpCode.NRefactory.CSharp public override void OnExit() { - // override the base.OnExit() logic + Parent.OnExit(); } public override IndentState Clone(CSharpIndentEngine engine) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs index d5c05a4e36..f6c153b1af 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs @@ -24,7 +24,7 @@ using ICSharpCode.NRefactory.TypeSystem; namespace ICSharpCode.NRefactory.CSharp { /// - /// C# ambience. + /// C# ambience. Used to convert type system symbols to text (usually for displaying the symbol to the user; e.g. in editor tooltips) /// public class CSharpAmbience : IAmbience { diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs index 2c0984649d..fb627fc54f 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs @@ -936,20 +936,30 @@ namespace Mono.CSharp } } - class StackFieldExpr : FieldExpr, IExpressionCleanup + public class StackFieldExpr : FieldExpr, IExpressionCleanup { public StackFieldExpr (Field field) : base (field, Location.Null) { } + public bool IsAvailableForReuse { + get { + var field = (Field) spec.MemberDefinition; + return field.IsAvailableForReuse; + } + set { + var field = (Field) spec.MemberDefinition; + field.IsAvailableForReuse = value; + } + } + public override void AddressOf (EmitContext ec, AddressOp mode) { base.AddressOf (ec, mode); if (mode == AddressOp.Load) { - var field = (Field) spec.MemberDefinition; - field.IsAvailableForReuse = true; + IsAvailableForReuse = true; } } @@ -957,8 +967,17 @@ namespace Mono.CSharp { base.Emit (ec); - var field = (Field) spec.MemberDefinition; - field.IsAvailableForReuse = true; + PrepareCleanup (ec); + } + + public void EmitLoad (EmitContext ec) + { + base.Emit (ec); + } + + public void PrepareCleanup (EmitContext ec) + { + IsAvailableForReuse = true; // // Release any captured reference type stack variables diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs index 96062f2748..bea0ee06df 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs @@ -390,14 +390,14 @@ namespace Mono.CSharp { return new DoubleConstant (ec.BuiltinTypes, res, left.Location); } if (left is FloatConstant){ - float res; - + double a, b, res; + a = ((FloatConstant) left).DoubleValue; + b = ((FloatConstant) right).DoubleValue; + if (ec.ConstantCheckState) - res = checked (((FloatConstant) left).Value + - ((FloatConstant) right).Value); + res = checked (a + b); else - res = unchecked (((FloatConstant) left).Value + - ((FloatConstant) right).Value); + res = unchecked (a + b); result = new FloatConstant (ec.BuiltinTypes, res, left.Location); } else if (left is ULongConstant){ @@ -514,14 +514,14 @@ namespace Mono.CSharp { result = new DoubleConstant (ec.BuiltinTypes, res, left.Location); } else if (left is FloatConstant){ - float res; - + double a, b, res; + a = ((FloatConstant) left).DoubleValue; + b = ((FloatConstant) right).DoubleValue; + if (ec.ConstantCheckState) - res = checked (((FloatConstant) left).Value - - ((FloatConstant) right).Value); + res = checked (a - b); else - res = unchecked (((FloatConstant) left).Value - - ((FloatConstant) right).Value); + res = unchecked (a - b); result = new FloatConstant (ec.BuiltinTypes, res, left.Location); } else if (left is ULongConstant){ @@ -611,14 +611,14 @@ namespace Mono.CSharp { return new DoubleConstant (ec.BuiltinTypes, res, left.Location); } else if (left is FloatConstant){ - float res; - + double a, b, res; + a = ((FloatConstant) left).DoubleValue; + b = ((FloatConstant) right).DoubleValue; + if (ec.ConstantCheckState) - res = checked (((FloatConstant) left).Value * - ((FloatConstant) right).Value); + res = checked (a * b); else - res = unchecked (((FloatConstant) left).Value * - ((FloatConstant) right).Value); + res = unchecked (a * b); return new FloatConstant (ec.BuiltinTypes, res, left.Location); } else if (left is ULongConstant){ @@ -707,14 +707,14 @@ namespace Mono.CSharp { return new DoubleConstant (ec.BuiltinTypes, res, left.Location); } else if (left is FloatConstant){ - float res; - + double a, b, res; + a = ((FloatConstant) left).DoubleValue; + b = ((FloatConstant) right).DoubleValue; + if (ec.ConstantCheckState) - res = checked (((FloatConstant) left).Value / - ((FloatConstant) right).Value); + res = checked (a / b); else - res = unchecked (((FloatConstant) left).Value / - ((FloatConstant) right).Value); + res = unchecked (a / b); return new FloatConstant (ec.BuiltinTypes, res, left.Location); } else if (left is ULongConstant){ @@ -807,14 +807,14 @@ namespace Mono.CSharp { return new DoubleConstant (ec.BuiltinTypes, res, left.Location); } else if (left is FloatConstant){ - float res; + double a, b, res; + a = ((FloatConstant) left).DoubleValue; + b = ((FloatConstant) right).DoubleValue; if (ec.ConstantCheckState) - res = checked (((FloatConstant) left).Value % - ((FloatConstant) right).Value); + res = checked (a % b); else - res = unchecked (((FloatConstant) left).Value % - ((FloatConstant) right).Value); + res = unchecked (a % b); return new FloatConstant (ec.BuiltinTypes, res, left.Location); } else if (left is ULongConstant){ @@ -883,7 +883,6 @@ namespace Mono.CSharp { IntConstant ic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant; if (ic == null){ - Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); return null; } @@ -905,8 +904,7 @@ namespace Mono.CSharp { if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int) return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value << lshift_val, left.Location); - Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); - break; + return null; // // There is no overflow checking on right shift @@ -920,7 +918,6 @@ namespace Mono.CSharp { IntConstant sic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant; if (sic == null){ - Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); return null; } int rshift_val = sic.Value; @@ -941,8 +938,7 @@ namespace Mono.CSharp { if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int) return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value >> rshift_val, left.Location); - Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); - break; + return null; case Binary.Operator.Equality: if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) || @@ -969,8 +965,8 @@ namespace Mono.CSharp { bool_res = ((DoubleConstant) left).Value == ((DoubleConstant) right).Value; else if (left is FloatConstant) - bool_res = ((FloatConstant) left).Value == - ((FloatConstant) right).Value; + bool_res = ((FloatConstant) left).DoubleValue == + ((FloatConstant) right).DoubleValue; else if (left is ULongConstant) bool_res = ((ULongConstant) left).Value == ((ULongConstant) right).Value; @@ -1013,8 +1009,8 @@ namespace Mono.CSharp { bool_res = ((DoubleConstant) left).Value != ((DoubleConstant) right).Value; else if (left is FloatConstant) - bool_res = ((FloatConstant) left).Value != - ((FloatConstant) right).Value; + bool_res = ((FloatConstant) left).DoubleValue != + ((FloatConstant) right).DoubleValue; else if (left is ULongConstant) bool_res = ((ULongConstant) left).Value != ((ULongConstant) right).Value; @@ -1049,8 +1045,8 @@ namespace Mono.CSharp { bool_res = ((DoubleConstant) left).Value < ((DoubleConstant) right).Value; else if (left is FloatConstant) - bool_res = ((FloatConstant) left).Value < - ((FloatConstant) right).Value; + bool_res = ((FloatConstant) left).DoubleValue < + ((FloatConstant) right).DoubleValue; else if (left is ULongConstant) bool_res = ((ULongConstant) left).Value < ((ULongConstant) right).Value; @@ -1085,8 +1081,8 @@ namespace Mono.CSharp { bool_res = ((DoubleConstant) left).Value > ((DoubleConstant) right).Value; else if (left is FloatConstant) - bool_res = ((FloatConstant) left).Value > - ((FloatConstant) right).Value; + bool_res = ((FloatConstant) left).DoubleValue > + ((FloatConstant) right).DoubleValue; else if (left is ULongConstant) bool_res = ((ULongConstant) left).Value > ((ULongConstant) right).Value; @@ -1121,8 +1117,8 @@ namespace Mono.CSharp { bool_res = ((DoubleConstant) left).Value >= ((DoubleConstant) right).Value; else if (left is FloatConstant) - bool_res = ((FloatConstant) left).Value >= - ((FloatConstant) right).Value; + bool_res = ((FloatConstant) left).DoubleValue >= + ((FloatConstant) right).DoubleValue; else if (left is ULongConstant) bool_res = ((ULongConstant) left).Value >= ((ULongConstant) right).Value; @@ -1157,8 +1153,8 @@ namespace Mono.CSharp { bool_res = ((DoubleConstant) left).Value <= ((DoubleConstant) right).Value; else if (left is FloatConstant) - bool_res = ((FloatConstant) left).Value <= - ((FloatConstant) right).Value; + bool_res = ((FloatConstant) left).DoubleValue <= + ((FloatConstant) right).DoubleValue; else if (left is ULongConstant) bool_res = ((ULongConstant) left).Value <= ((ULongConstant) right).Value; @@ -1176,7 +1172,7 @@ namespace Mono.CSharp { return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location); } - + return null; } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs index 083d9a9c91..2b8b8d0e14 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs @@ -144,8 +144,8 @@ namespace Mono.CSharp } if ((existing.ModFlags & Modifiers.AccessibilityMask) != (next_part.ModFlags & Modifiers.AccessibilityMask) && - ((existing.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) == 0 && - (next_part.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) == 0)) { + ((existing.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFIER) == 0 && + (next_part.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFIER) == 0)) { Report.SymbolRelatedToPreviousError (existing); Report.Error (262, next_part.Location, "Partial declarations of `{0}' have conflicting accessibility modifiers", @@ -172,10 +172,10 @@ namespace Mono.CSharp } } - if ((next_part.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) != 0) { - existing.ModFlags |= next_part.ModFlags & ~(Modifiers.DEFAULT_ACCESS_MODIFER | Modifiers.AccessibilityMask); - } else if ((existing.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) != 0) { - existing.ModFlags &= ~(Modifiers.DEFAULT_ACCESS_MODIFER | Modifiers.AccessibilityMask); + if ((next_part.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFIER) != 0) { + existing.ModFlags |= next_part.ModFlags & ~(Modifiers.DEFAULT_ACCESS_MODIFIER | Modifiers.AccessibilityMask); + } else if ((existing.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFIER) != 0) { + existing.ModFlags &= ~(Modifiers.DEFAULT_ACCESS_MODIFIER | Modifiers.AccessibilityMask); existing.ModFlags |= next_part.ModFlags; } else { existing.ModFlags |= next_part.ModFlags; diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs index 2e2f73182d..bb65071203 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs @@ -370,7 +370,7 @@ namespace Mono.CSharp // // Creates temporary field in current async storey // - public FieldExpr GetTemporaryField (TypeSpec type) + public StackFieldExpr GetTemporaryField (TypeSpec type) { var f = AsyncTaskStorey.AddCapturedLocalVariable (type); var fexpr = new StackFieldExpr (f); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/complete.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/complete.cs index 2931d137f7..f66a7bd9fb 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/complete.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/complete.cs @@ -147,14 +147,14 @@ namespace Mono.CSharp { } var results = new List (); - if (expr is Namespace) { - Namespace nexpr = expr as Namespace; + var nexpr = expr as NamespaceExpression; + if (nexpr != null) { string namespaced_partial; if (partial_name == null) - namespaced_partial = nexpr.Name; + namespaced_partial = nexpr.Namespace.Name; else - namespaced_partial = nexpr.Name + "." + partial_name; + namespaced_partial = nexpr.Namespace.Name + "." + partial_name; rc.CurrentMemberDefinition.GetCompletionStartingWith (namespaced_partial, results); if (partial_name != null) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs index 681ae161e2..ec2ee12f71 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs @@ -1652,20 +1652,32 @@ namespace Mono.CSharp { } public class FloatConstant : Constant { - public readonly float Value; + // + // Store constant value as double because float constant operations + // need to work on double value to match JIT + // + public readonly double DoubleValue; - public FloatConstant (BuiltinTypes types, float v, Location loc) + public FloatConstant (BuiltinTypes types, double v, Location loc) : this (types.Float, v, loc) { } - public FloatConstant (TypeSpec type, float v, Location loc) + public FloatConstant (TypeSpec type, double v, Location loc) : base (loc) { this.type = type; eclass = ExprClass.Value; - Value = v; + DoubleValue = v; + } + + public override Constant ConvertImplicitly (TypeSpec type) + { + if (type.BuiltinType == BuiltinTypeSpec.Type.Double) + return new DoubleConstant (type, DoubleValue, loc); + + return base.ConvertImplicitly (type); } public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType) @@ -1678,6 +1690,12 @@ namespace Mono.CSharp { ec.Emit (OpCodes.Ldc_R4, Value); } + public float Value { + get { + return (float) DoubleValue; + } + } + public override object GetValue () { return Value; @@ -1713,59 +1731,59 @@ namespace Mono.CSharp { if (Value < byte.MinValue || Value > byte.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new ByteConstant (target_type, (byte) Value, Location); + return new ByteConstant (target_type, (byte) DoubleValue, Location); case BuiltinTypeSpec.Type.SByte: if (in_checked_context) { if (Value < sbyte.MinValue || Value > sbyte.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new SByteConstant (target_type, (sbyte) Value, Location); + return new SByteConstant (target_type, (sbyte) DoubleValue, Location); case BuiltinTypeSpec.Type.Short: if (in_checked_context) { if (Value < short.MinValue || Value > short.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new ShortConstant (target_type, (short) Value, Location); + return new ShortConstant (target_type, (short) DoubleValue, Location); case BuiltinTypeSpec.Type.UShort: if (in_checked_context) { if (Value < ushort.MinValue || Value > ushort.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new UShortConstant (target_type, (ushort) Value, Location); + return new UShortConstant (target_type, (ushort) DoubleValue, Location); case BuiltinTypeSpec.Type.Int: if (in_checked_context) { if (Value < int.MinValue || Value > int.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new IntConstant (target_type, (int) Value, Location); + return new IntConstant (target_type, (int) DoubleValue, Location); case BuiltinTypeSpec.Type.UInt: if (in_checked_context) { if (Value < uint.MinValue || Value > uint.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new UIntConstant (target_type, (uint) Value, Location); + return new UIntConstant (target_type, (uint) DoubleValue, Location); case BuiltinTypeSpec.Type.Long: if (in_checked_context) { if (Value < long.MinValue || Value > long.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new LongConstant (target_type, (long) Value, Location); + return new LongConstant (target_type, (long) DoubleValue, Location); case BuiltinTypeSpec.Type.ULong: if (in_checked_context) { if (Value < ulong.MinValue || Value > ulong.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new ULongConstant (target_type, (ulong) Value, Location); + return new ULongConstant (target_type, (ulong) DoubleValue, Location); case BuiltinTypeSpec.Type.Double: - return new DoubleConstant (target_type, (double) Value, Location); + return new DoubleConstant (target_type, DoubleValue, Location); case BuiltinTypeSpec.Type.Char: if (in_checked_context) { if (Value < (float) char.MinValue || Value > (float) char.MaxValue || float.IsNaN (Value)) throw new OverflowException (); } - return new CharConstant (target_type, (char) Value, Location); + return new CharConstant (target_type, (char) DoubleValue, Location); case BuiltinTypeSpec.Type.Decimal: - return new DecimalConstant (target_type, (decimal) Value, Location); + return new DecimalConstant (target_type, (decimal) DoubleValue, Location); } return null; diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs index e2e1268f35..6fc03b11d9 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs @@ -1235,7 +1235,7 @@ namespace Mono.CSharp { // // User operator is of T? // - if (t_x.IsNullableType && target.IsNullableType) { + if (t_x.IsNullableType && (target.IsNullableType || !implicitOnly)) { // // User operator return type does not match target type we need // yet another conversion. This should happen for promoted numeric @@ -1251,7 +1251,8 @@ namespace Mono.CSharp { if (source == null) return null; - source = new Nullable.LiftedConversion (source, unwrap, target).Resolve (ec); + if (target.IsNullableType) + source = new Nullable.LiftedConversion (source, unwrap, target).Resolve (ec); } } else { source = implicitOnly ? @@ -1412,25 +1413,23 @@ namespace Mono.CSharp { } } - if (ec.IsUnsafe) { - var target_pc = target_type as PointerContainer; - if (target_pc != null) { - if (expr_type.IsPointer) { - // - // Pointer types are same when they have same element types - // - if (expr_type == target_pc) - return expr; + var target_pc = target_type as PointerContainer; + if (target_pc != null) { + if (expr_type.IsPointer) { + // + // Pointer types are same when they have same element types + // + if (expr_type == target_pc) + return expr; - if (target_pc.Element.Kind == MemberKind.Void) - return EmptyCast.Create (expr, target_type); + if (target_pc.Element.Kind == MemberKind.Void) + return EmptyCast.Create (expr, target_type); //return null; - } - - if (expr_type == InternalType.NullLiteral) - return new NullPointer (target_type, loc); } + + if (expr_type == InternalType.NullLiteral) + return new NullPointer (target_type, loc); } if (expr_type == InternalType.AnonymousMethod){ diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs index 9b0af466a7..e8e4cfa0f7 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs @@ -4586,7 +4586,7 @@ void case_60() void case_61() #line 748 "cs-parser.jay" { - CheckAttributeTarget (GetTokenName (yyToken), GetLocation (yyVals[0+yyTop])); + CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation (yyVals[0+yyTop])); yyVal = null; } @@ -4594,7 +4594,7 @@ void case_62() #line 756 "cs-parser.jay" { var lt = (LocatedToken) yyVals[0+yyTop]; - yyVal = CheckAttributeTarget (lt.Value, lt.Location); + yyVal = CheckAttributeTarget (yyToken, lt.Value, lt.Location); PushLocation (GetLocation (yyVals[0+yyTop])); } @@ -14499,15 +14499,20 @@ Location PopLocation () return location_stack.Pop (); } -string CheckAttributeTarget (string a, Location l) +string CheckAttributeTarget (int token, string a, Location l) { switch (a) { case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" : return a; } - report.Warning (658, 1, l, - "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a); + if (!Tokenizer.IsValidIdentifier (a)) { + Error_SyntaxError (token); + } else { + report.Warning (658, 1, l, + "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a); + } + return string.Empty; } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay index 6748b77de2..d161bc9a85 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay @@ -746,7 +746,7 @@ attribute_section_cont } | error { - CheckAttributeTarget (GetTokenName (yyToken), GetLocation ($1)); + CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)); $$ = null; } ; @@ -755,7 +755,7 @@ attribute_target : IDENTIFIER { var lt = (LocatedToken) $1; - $$ = CheckAttributeTarget (lt.Value, lt.Location); + $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location); PushLocation (GetLocation ($1)); } | EVENT { $$ = "event"; PushLocation (GetLocation ($1)); } @@ -7174,15 +7174,20 @@ Location PopLocation () return location_stack.Pop (); } -string CheckAttributeTarget (string a, Location l) +string CheckAttributeTarget (int token, string a, Location l) { switch (a) { case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" : return a; } - report.Warning (658, 1, l, - "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a); + if (!Tokenizer.IsValidIdentifier (a)) { + Error_SyntaxError (token); + } else { + report.Warning (658, 1, l, + "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a); + } + return string.Empty; } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs index aa6fdf1f2c..213cd62f7f 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs @@ -679,6 +679,9 @@ namespace Mono.CSharp { } } + if (type.IsNested) + return ContainsMethodTypeParameter (type.DeclaringType); + return false; } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs index 4abcf6a0ef..34faed5594 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs @@ -297,7 +297,7 @@ namespace Mono.CSharp return context.LookupNamespaceOrType (mn.Name, mn.Arity, LookupMode.Probing, Location.Null); var left = ResolveMemberName (context, mn.Left); - var ns = left as Namespace; + var ns = left as NamespaceExpression; if (ns != null) return ns.LookupTypeOrNamespace (context, mn.Name, mn.Arity, LookupMode.Probing, Location.Null); @@ -383,7 +383,7 @@ namespace Mono.CSharp } else if (ParsedName.Left != null) { fne = ResolveMemberName (mc, ParsedName.Left); if (fne != null) { - var ns = fne as Namespace; + var ns = fne as NamespaceExpression; if (ns != null) { fne = ns.LookupTypeOrNamespace (mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null); if (fne != null) { diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs index dd7e3627e7..fc957771e4 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs @@ -466,7 +466,7 @@ namespace Mono.CSharp { return e; } catch (Exception ex) { - if (loc.IsNull || ec.Module.Compiler.Settings.DebugFlags > 0 || ex is CompletionResult || ec.Report.IsDisabled || ex is FatalException || + if (loc.IsNull || ec.Module.Compiler.Settings.BreakOnInternalError || ex is CompletionResult || ec.Report.IsDisabled || ex is FatalException || ec.Report.Printer is NullReportPrinter) throw; @@ -2313,11 +2313,11 @@ namespace Mono.CSharp { protected override Expression DoResolve (ResolveContext rc) { expr = expr.Resolve (rc); - if (expr != null) { - type = expr.Type; - eclass = expr.eclass; - } + if (expr == null) + return null; + type = expr.Type; + eclass = expr.eclass; return this; } @@ -2606,7 +2606,7 @@ namespace Mono.CSharp { // // dynamic namespace is ignored when dynamic is allowed (does not apply to types) // - if (!(fne is Namespace)) + if (!(fne is NamespaceExpression)) return fne; } @@ -2989,6 +2989,114 @@ namespace Mono.CSharp { } } + public class NamespaceExpression : FullNamedExpression + { + readonly Namespace ns; + + public NamespaceExpression (Namespace ns, Location loc) + { + this.ns = ns; + this.Type = InternalType.Namespace; + this.eclass = ExprClass.Namespace; + this.loc = loc; + } + + public Namespace Namespace { + get { + return ns; + } + } + + protected override Expression DoResolve (ResolveContext rc) + { + throw new NotImplementedException (); + } + + public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc) + { + return this; + } + + public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int arity) + { + var retval = Namespace.LookupType (ctx, name, arity, LookupMode.IgnoreAccessibility, loc); + if (retval != null) { +// ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (retval.MemberDefinition); + ErrorIsInaccesible (ctx, retval.GetSignatureForError (), loc); + return; + } + + retval = Namespace.LookupType (ctx, name, -System.Math.Max (1, arity), LookupMode.Probing, loc); + if (retval != null) { + Error_TypeArgumentsCannotBeUsed (ctx, retval, loc); + return; + } + + Namespace ns; + if (arity > 0 && Namespace.TryGetNamespace (name, out ns)) { + Error_TypeArgumentsCannotBeUsed (ctx, ExprClassName, ns.GetSignatureForError (), loc); + return; + } + + string assembly = null; + string possible_name = Namespace.GetSignatureForError () + "." + name; + + // Only assembly unique name should be added + switch (possible_name) { + case "System.Drawing": + case "System.Web.Services": + case "System.Web": + case "System.Data": + case "System.Configuration": + case "System.Data.Services": + case "System.DirectoryServices": + case "System.Json": + case "System.Net.Http": + case "System.Numerics": + case "System.Runtime.Caching": + case "System.ServiceModel": + case "System.Transactions": + case "System.Web.Routing": + case "System.Xml.Linq": + case "System.Xml": + assembly = possible_name; + break; + + case "System.Linq": + case "System.Linq.Expressions": + assembly = "System.Core"; + break; + + case "System.Windows.Forms": + case "System.Windows.Forms.Layout": + assembly = "System.Windows.Forms"; + break; + } + + assembly = assembly == null ? "an" : "`" + assembly + "'"; + + if (Namespace is GlobalRootNamespace) { + ctx.Module.Compiler.Report.Error (400, loc, + "The type or namespace name `{0}' could not be found in the global namespace. Are you missing {1} assembly reference?", + name, assembly); + } else { + ctx.Module.Compiler.Report.Error (234, loc, + "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing {2} assembly reference?", + name, GetSignatureForError (), assembly); + } + } + + public override string GetSignatureForError () + { + return ns.GetSignatureForError (); + } + + public FullNamedExpression LookupTypeOrNamespace (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc) + { + return ns.LookupTypeOrNamespace (ctx, name, arity, mode, loc); + } + } + /// /// This class denotes an expression which evaluates to a member /// of a struct or a class. @@ -4274,7 +4382,7 @@ namespace Mono.CSharp { AParametersCollection best_pd = ((IParametersMember) best).Parameters; bool better_at_least_one = false; - bool same = true; + bool are_equivalent = true; int args_count = args == null ? 0 : args.Count; int j = 0; Argument a = null; @@ -4319,7 +4427,7 @@ namespace Mono.CSharp { if (TypeSpecComparer.IsEqual (ct, bt)) continue; - same = false; + are_equivalent = false; int result = BetterExpressionConversion (ec, a, ct, bt); // for each argument, the conversion to 'ct' should be no worse than @@ -4337,68 +4445,56 @@ namespace Mono.CSharp { return true; // - // This handles the case - // - // Add (float f1, float f2, float f3); - // Add (params decimal [] foo); + // Tie-breaking rules are applied only for equivalent parameter types // - // The call Add (3, 4, 5) should be ambiguous. Without this check, the - // first candidate would've chosen as better. - // - if (!same && !a.IsDefaultArgument) + if (!are_equivalent) return false; // - // The two methods have equal non-optional parameter types, apply tie-breaking rules + // If candidate is applicable in its normal form and best has a params array and is applicable + // only in its expanded form, then candidate is better // + if (candidate_params != best_params) + return !candidate_params; // - // This handles the following cases: - // - // Foo (int i) is better than Foo (int i, long l = 0) - // Foo (params int[] args) is better than Foo (int i = 0, params int[] args) - // Foo (string s, params string[] args) is better than Foo (params string[] args) - // - // Prefer non-optional version - // - // LAMESPEC: Specification claims this should be done at last but the opposite is true + // We have not reached end of parameters list due to params or used default parameters // - if (candidate_params == best_params && candidate_pd.Count != best_pd.Count) { - if (j < candidate_pd.Count && candidate_pd.FixedParameters[j].HasDefaultValue) - return false; - - if (j < best_pd.Count && best_pd.FixedParameters[j].HasDefaultValue) - return true; + if (j < candidate_pd.Count && j < best_pd.Count) { + var cand_param = candidate_pd.FixedParameters [j]; + var best_param = best_pd.FixedParameters [j]; - return candidate_pd.Count >= best_pd.Count; + if (candidate_pd.Count == best_pd.Count) { + // + // LAMESPEC: + // + // void Foo (params int[]) is better than void Foo (int i = 0) for Foo () + // void Foo (string[] s, string value = null) is better than Foo (string s, params string[]) for Foo (null) + // + if (cand_param.HasDefaultValue != best_param.HasDefaultValue) + return !candidate_params; + } else { + // + // Neither is better when not all arguments are provided + // + // void Foo (string s, int i = 0) <-> Foo (string s, int i = 0, int i2 = 0) + // void Foo (string s, int i = 0) <-> Foo (string s, byte i = 0) + // void Foo (string s, params int[]) <-> Foo (string s, params byte[]) + // + if (cand_param.HasDefaultValue && best_param.HasDefaultValue) + return false; + } } + if (candidate_pd.Count != best_pd.Count) + return candidate_pd.Count < best_pd.Count; + // // One is a non-generic method and second is a generic method, then non-generic is better // if (best.IsGeneric != candidate.IsGeneric) return best.IsGeneric; - // - // This handles the following cases: - // - // Trim () is better than Trim (params char[] chars) - // Concat (string s1, string s2, string s3) is better than - // Concat (string s1, params string [] srest) - // Foo (int, params int [] rest) is better than Foo (params int [] rest) - // - // Prefer non-expanded version - // - if (candidate_params != best_params) - return best_params; - - int candidate_param_count = candidate_pd.Count; - int best_param_count = best_pd.Count; - - if (candidate_param_count != best_param_count) - // can only happen if (candidate_params && best_params) - return candidate_param_count > best_param_count && best_pd.HasParams; - // // Both methods have the same number of parameters, and the parameters have equal types // Pick the "more specific" signature using rules over original (non-inflated) types @@ -4626,7 +4722,8 @@ namespace Mono.CSharp { if (g_args_count != type_arguments.Count) return int.MaxValue - 20000 + System.Math.Abs (type_arguments.Count - g_args_count); - ms = ms.MakeGenericMethod (ec, type_arguments.Arguments); + if (type_arguments.Arguments != null) + ms = ms.MakeGenericMethod (ec, type_arguments.Arguments); } else { // // Deploy custom error reporting for infered anonymous expression or lambda methods. When @@ -4808,12 +4905,6 @@ namespace Mono.CSharp { } } - // - // When params parameter has no argument it will be provided later if the method is the best candidate - // - if (arg_count + 1 == pd.Count && (cpd.FixedParameters [arg_count].ModFlags & Parameter.Modifier.PARAMS) != 0) - params_expanded_form = true; - // // Restore original arguments for dynamic binder to keep the intention of original source code // @@ -5819,48 +5910,39 @@ namespace Mono.CSharp { } var fe = InstanceExpression as FieldExpr; - if (fe != null || lvalue_instance) { - if (fe == null) - return; + if (fe != null) { + Expression instance; - /* - while (fe.InstanceExpression is FieldExpr) { - fe = (FieldExpr) fe.InstanceExpression; - if (!fe.Spec.DeclaringType.IsStruct) - continue; + do { + instance = fe.InstanceExpression; + var fe_instance = instance as FieldExpr; + if ((fe_instance != null && !fe_instance.IsStatic) || instance is LocalVariableReference) { + if (TypeSpec.IsReferenceType (fe.Type) && instance.Type.IsStruct) { + var var = InstanceExpression as IVariableReference; + if (var != null && var.VariableInfo == null) { + var var_inst = instance as IVariableReference; + if (var_inst == null || (var_inst.VariableInfo != null && !fc.IsDefinitelyAssigned (var_inst.VariableInfo))) + fc.Report.Warning (1060, 1, fe.loc, "Use of possibly unassigned field `{0}'", fe.Name); + } + } - if (fe.VariableInfo != null && fc.IsStructFieldDefinitelyAssigned (fe.VariableInfo, fe.Name)) { - fc.Report.Warning (1060, 1, fe.loc, "Use of possibly unassigned field `{0}'", fe.Name); + if (fe_instance != null) { + fe = fe_instance; + continue; + } } - } - fe.InstanceExpression.FlowAnalysis (fc); - */ + break; + } while (true); + + if (instance != null && TypeSpec.IsReferenceType (instance.Type)) + instance.FlowAnalysis (fc); } else { - InstanceExpression.FlowAnalysis (fc); + if (TypeSpec.IsReferenceType (InstanceExpression.Type)) + InstanceExpression.FlowAnalysis (fc); } } - - public void VerifyAssignedStructField (FlowAnalysisContext fc) - { - var fe = this; - - do { - var var = fe.InstanceExpression as IVariableReference; - if (var != null) { - var vi = var.VariableInfo; - - if (vi != null && !fc.IsStructFieldDefinitelyAssigned (vi, fe.Name) && !fe.type.IsStruct) { - fc.Report.Warning (1060, 1, fe.loc, "Use of possibly unassigned field `{0}'", fe.Name); - } - } - - fe = fe.InstanceExpression as FieldExpr; - - } while (fe != null); - } - Expression Error_AssignToReadonly (ResolveContext rc, Expression right_side) { // The return value is always null. Returning a value simplifies calling code. diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs index 34c183bd97..176f5339ea 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs @@ -5031,7 +5031,7 @@ namespace Mono.CSharp AParametersCollection pd = oper.Parameters; if (!TypeSpecComparer.IsEqual (type, pd.Types[0]) || !TypeSpecComparer.IsEqual (type, pd.Types[1])) { ec.Report.Error (217, loc, - "A user-defined operator `{0}' must have parameters and return values of the same type in order to be applicable as a short circuit operator", + "A user-defined operator `{0}' must have each parameter type and return type of the same type in order to be applicable as a short circuit operator", oper.GetSignatureForError ()); return null; } @@ -7495,7 +7495,7 @@ namespace Mono.CSharp // // This always expect the top value on the stack to be the array // - void EmitDynamicInitializers (EmitContext ec, bool emitConstants, FieldExpr stackArray) + void EmitDynamicInitializers (EmitContext ec, bool emitConstants, StackFieldExpr stackArray) { int dims = bounds.Count; var current_pos = new int [dims]; @@ -7515,7 +7515,7 @@ namespace Mono.CSharp e = e.EmitToField (ec); } - stackArray.Emit (ec); + stackArray.EmitLoad (ec); } else { ec.Emit (OpCodes.Dup); } @@ -7527,26 +7527,8 @@ namespace Mono.CSharp // If we are dealing with a struct, get the // address of it, so we can store it. // - if (dims == 1 && etype.IsStruct) { - switch (etype.BuiltinType) { - case BuiltinTypeSpec.Type.Byte: - case BuiltinTypeSpec.Type.SByte: - case BuiltinTypeSpec.Type.Bool: - case BuiltinTypeSpec.Type.Short: - case BuiltinTypeSpec.Type.UShort: - case BuiltinTypeSpec.Type.Char: - case BuiltinTypeSpec.Type.Int: - case BuiltinTypeSpec.Type.UInt: - case BuiltinTypeSpec.Type.Long: - case BuiltinTypeSpec.Type.ULong: - case BuiltinTypeSpec.Type.Float: - case BuiltinTypeSpec.Type.Double: - break; - default: - ec.Emit (OpCodes.Ldelema, etype); - break; - } - } + if (dims == 1 && etype.IsStruct && !BuiltinTypeSpec.IsPrimitiveType (etype)) + ec.Emit (OpCodes.Ldelema, etype); e.Emit (ec); @@ -7563,6 +7545,9 @@ namespace Mono.CSharp current_pos [j] = 0; } } + + if (stackArray != null) + stackArray.PrepareCleanup (ec); } public override void Emit (EmitContext ec) @@ -7577,7 +7562,7 @@ namespace Mono.CSharp first_emit_temp.Store (ec); } - FieldExpr await_stack_field; + StackFieldExpr await_stack_field; if (ec.HasSet (BuilderContext.Options.AsyncBody) && InitializersContainAwait ()) { await_stack_field = ec.GetTemporaryField (type); ec.EmitThis (); @@ -8669,7 +8654,7 @@ namespace Mono.CSharp public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec) { if (alias == GlobalAlias) { - expr = ec.Module.GlobalRootNamespace; + expr = new NamespaceExpression (ec.Module.GlobalRootNamespace, loc); return base.ResolveAsTypeOrNamespace (ec); } @@ -8832,12 +8817,12 @@ namespace Mono.CSharp if (expr == null) return null; - Namespace ns = expr as Namespace; + var ns = expr as NamespaceExpression; if (ns != null) { var retval = ns.LookupTypeOrNamespace (rc, Name, Arity, LookupMode.Normal, loc); if (retval == null) { - ns.Error_NamespaceDoesNotExist (rc, Name, Arity, loc); + ns.Error_NamespaceDoesNotExist (rc, Name, Arity); return null; } @@ -8972,12 +8957,12 @@ namespace Mono.CSharp if (expr_resolved == null) return null; - Namespace ns = expr_resolved as Namespace; + var ns = expr_resolved as NamespaceExpression; if (ns != null) { FullNamedExpression retval = ns.LookupTypeOrNamespace (rc, Name, Arity, LookupMode.Normal, loc); if (retval == null) { - ns.Error_NamespaceDoesNotExist (rc, Name, Arity, loc); + ns.Error_NamespaceDoesNotExist (rc, Name, Arity); } else if (HasTypeArguments) { retval = new GenericTypeExpr (retval.Type, targs, loc); if (retval.ResolveAsType (rc) == null) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs index f71647968d..0d7e9e5ad5 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs @@ -190,6 +190,12 @@ namespace Mono.CSharp try { field_type = ImportType (fi.FieldType, new DynamicTypeReader (fi)); + + // + // Private field has private type which is not fixed buffer + // + if (field_type == null) + return null; } catch (Exception e) { // TODO: I should construct fake TypeSpec based on TypeRef signature // but there is no way to do it with System.Reflection @@ -340,6 +346,9 @@ namespace Mono.CSharp } } + if (spec == null) + return null; + ++dtype.Position; tspec[index] = spec; } @@ -376,7 +385,7 @@ namespace Mono.CSharp kind = MemberKind.Method; if (tparams == null && !mb.DeclaringType.IsInterface && name.Length > 6) { if ((mod & (Modifiers.STATIC | Modifiers.PUBLIC)) == (Modifiers.STATIC | Modifiers.PUBLIC)) { - if (name[2] == '_' && name[1] == 'p' && name[0] == 'o') { + if (name[2] == '_' && name[1] == 'p' && name[0] == 'o' && (mb.Attributes & MethodAttributes.SpecialName) != 0) { var op_type = Operator.GetType (name); if (op_type.HasValue && parameters.Count > 0 && parameters.Count < 3) { kind = MemberKind.Operator; @@ -756,6 +765,8 @@ namespace Mono.CSharp return spec; var targs = CreateGenericArguments (0, type.GetGenericArguments (), dtype); + if (targs == null) + return null; if (declaringType == null) { // Simple case, no nesting spec = CreateType (type_def, null, new DynamicTypeReader (), canImportBaseType); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/modifiers.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/modifiers.cs index 970e8dedd7..c8c6b73e60 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/modifiers.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/modifiers.cs @@ -46,7 +46,7 @@ namespace Mono.CSharp PROPERTY_CUSTOM = 0x10000, PARTIAL = 0x20000, - DEFAULT_ACCESS_MODIFER = 0x40000, + DEFAULT_ACCESS_MODIFIER = 0x40000, METHOD_EXTENSION = 0x80000, COMPILER_GENERATED = 0x100000, BACKING_FIELD = 0x200000, @@ -256,7 +256,7 @@ namespace Mono.CSharp if ((mod & Modifiers.AccessibilityMask) == 0) { mod |= def_access; if (def_access != 0) - mod |= Modifiers.DEFAULT_ACCESS_MODIFER; + mod |= Modifiers.DEFAULT_ACCESS_MODIFIER; return mod; } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs index 11099983af..0989d1cd2d 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs @@ -22,9 +22,10 @@ namespace Mono.CSharp { readonly Dictionary all_namespaces; public RootNamespace (string alias_name) - : base (null, String.Empty) + : base () { this.alias_name = alias_name; + RegisterNamespace (this); all_namespaces = new Dictionary (); all_namespaces.Add ("", this); @@ -87,24 +88,13 @@ namespace Mono.CSharp { all_namespaces.Add (child.Name, child); } - public bool IsNamespace (string name) - { - return all_namespaces.ContainsKey (name); - } - - protected void RegisterNamespace (string dotted_name) - { - if (dotted_name != null && dotted_name.Length != 0 && ! IsNamespace (dotted_name)) - GetNamespace (dotted_name, true); - } - public override string GetSignatureForError () { return alias_name + "::"; } } - public class GlobalRootNamespace : RootNamespace + public sealed class GlobalRootNamespace : RootNamespace { public GlobalRootNamespace () : base ("global") @@ -115,65 +105,50 @@ namespace Mono.CSharp { // // Namespace cache for imported and compiled namespaces // - // This is an Expression to allow it to be referenced in the - // compiler parse/intermediate tree during name resolution. - // - public class Namespace : FullNamedExpression + public class Namespace { - Namespace parent; + readonly Namespace parent; string fullname; protected Dictionary namespaces; protected Dictionary> types; List extension_method_types; Dictionary cached_types; - RootNamespace root; bool cls_checked; - public readonly MemberName MemberName; - /// /// Constructor Takes the current namespace and the /// name. This is bootstrapped with parent == null /// and name = "" /// public Namespace (Namespace parent, string name) + : this () { - // Expression members. - this.eclass = ExprClass.Namespace; - this.Type = InternalType.Namespace; - this.loc = Location.Null; + if (name == null) + throw new ArgumentNullException ("name"); this.parent = parent; - if (parent != null) - this.root = parent.root; - else - this.root = this as RootNamespace; - - if (this.root == null) - throw new InternalErrorException ("Root namespaces must be created using RootNamespace"); - - string pname = parent != null ? parent.fullname : ""; + string pname = parent != null ? parent.fullname : null; - if (pname == "") + if (pname == null) fullname = name; else - fullname = parent.fullname + "." + name; + fullname = pname + "." + name; - if (fullname == null) - throw new InternalErrorException ("Namespace has a null fullname"); + while (parent.parent != null) + parent = parent.parent; - if (parent != null && parent.MemberName != MemberName.Null) - MemberName = new MemberName (parent.MemberName, name, Location.Null); - else if (name.Length == 0) - MemberName = MemberName.Null; - else - MemberName = new MemberName (name, Location.Null); + var root = parent as RootNamespace; + if (root == null) + throw new InternalErrorException ("Root namespaces must be created using RootNamespace"); + + root.RegisterNamespace (this); + } + protected Namespace () + { namespaces = new Dictionary (); cached_types = new Dictionary (); - - root.RegisterNamespace (this); } #region Properties @@ -195,85 +170,6 @@ namespace Mono.CSharp { #endregion - protected override Expression DoResolve (ResolveContext ec) - { - return this; - } - - public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int arity, Location loc) - { - var retval = LookupType (ctx, name, arity, LookupMode.IgnoreAccessibility, loc); - if (retval != null) { -// ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (retval.MemberDefinition); - ErrorIsInaccesible (ctx, retval.GetSignatureForError (), loc); - return; - } - - retval = LookupType (ctx, name, -System.Math.Max (1, arity), LookupMode.Probing, loc); - if (retval != null) { - Error_TypeArgumentsCannotBeUsed (ctx, retval, loc); - return; - } - - Namespace ns; - if (arity > 0 && namespaces.TryGetValue (name, out ns)) { - ns.Error_TypeArgumentsCannotBeUsed (ctx, null, loc); - return; - } - - string assembly = null; - string possible_name = fullname + "." + name; - - // Only assembly unique name should be added - switch (possible_name) { - case "System.Drawing": - case "System.Web.Services": - case "System.Web": - case "System.Data": - case "System.Configuration": - case "System.Data.Services": - case "System.DirectoryServices": - case "System.Json": - case "System.Net.Http": - case "System.Numerics": - case "System.Runtime.Caching": - case "System.ServiceModel": - case "System.Transactions": - case "System.Web.Routing": - case "System.Xml.Linq": - case "System.Xml": - assembly = possible_name; - break; - - case "System.Linq": - case "System.Linq.Expressions": - assembly = "System.Core"; - break; - - case "System.Windows.Forms": - case "System.Windows.Forms.Layout": - assembly = "System.Windows.Forms"; - break; - } - - assembly = assembly == null ? "an" : "`" + assembly + "'"; - - if (this is GlobalRootNamespace) { - ctx.Module.Compiler.Report.Error (400, loc, - "The type or namespace name `{0}' could not be found in the global namespace. Are you missing {1} assembly reference?", - name, assembly); - } else { - ctx.Module.Compiler.Report.Error (234, loc, - "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing {2} assembly reference?", - name, GetSignatureForError (), assembly); - } - } - - public override string GetSignatureForError () - { - return fullname; - } - public Namespace AddNamespace (MemberName name) { var ns_parent = name.Left == null ? this : AddNamespace (name.Left); @@ -292,6 +188,11 @@ namespace Mono.CSharp { return ns; } + public bool TryGetNamespace (string name, out Namespace ns) + { + return namespaces.TryGetValue (name, out ns); + } + // TODO: Replace with CreateNamespace where MemberName is created for the method call public Namespace GetNamespace (string name, bool create) { @@ -327,6 +228,11 @@ namespace Mono.CSharp { return found; } + public virtual string GetSignatureForError () + { + return fullname; + } + public TypeSpec LookupType (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc) { if (types == null) @@ -415,7 +321,7 @@ namespace Mono.CSharp { Namespace ns; if (arity == 0 && namespaces.TryGetValue (name, out ns)) { if (texpr == null) - return ns; + return new NamespaceExpression (ns, loc); if (mode != LookupMode.Probing) { //ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (texpr.Type); @@ -426,7 +332,7 @@ namespace Mono.CSharp { } if (texpr.MemberDefinition.IsImported) - return ns; + return new NamespaceExpression (ns, loc); } if (texpr == null) @@ -580,11 +486,6 @@ namespace Mono.CSharp { cached_types.Remove (tc.Basename); } - public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc) - { - return this; - } - public void SetBuiltinType (BuiltinTypeSpec pts) { var found = types[pts.Name]; @@ -651,11 +552,6 @@ namespace Mono.CSharp { "Identifier `{0}' differing only in case is not CLS-compliant", compiled.GetSignatureForError ()); } } - - public override string ToString () - { - return Name; - } } public class CompilationSourceFile : NamespaceContainer @@ -1279,18 +1175,18 @@ namespace Mono.CSharp { continue; } - Namespace using_ns = entry.ResolvedExpression as Namespace; + var using_ns = entry.ResolvedExpression as NamespaceExpression; if (using_ns == null) continue; - if (list.Contains (using_ns)) { + if (list.Contains (using_ns.Namespace)) { // Ensure we don't report the warning multiple times in repl clauses.RemoveAt (i--); Compiler.Report.Warning (105, 3, entry.Location, "The using directive for `{0}' appeared previously in this namespace", using_ns.GetSignatureForError ()); } else { - list.Add (using_ns); + list.Add (using_ns.Namespace); } } @@ -1405,7 +1301,7 @@ namespace Mono.CSharp { public virtual void Define (NamespaceContainer ctx) { resolved = expr.ResolveAsTypeOrNamespace (ctx); - var ns = resolved as Namespace; + var ns = resolved as NamespaceExpression; if (ns == null) { if (resolved != null) { ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (resolved.Type); @@ -1436,12 +1332,15 @@ namespace Mono.CSharp { public override void Define (NamespaceContainer ctx) { - resolved = ctx.Module.GetRootNamespace (Alias.Value); - if (resolved == null) { + var ns = ctx.Module.GetRootNamespace (Alias.Value); + if (ns == null) { ctx.Module.Compiler.Report.Error (430, Location, "The extern alias `{0}' was not specified in -reference option", Alias.Value); + return; } + + resolved = new NamespaceExpression (ns, Location); } public override void Accept (StructuralVisitor visitor) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs index 5b846b59b2..19ec40870e 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs @@ -659,10 +659,10 @@ namespace Mono.CSharp.Nullable { if (rc.IsRuntimeBinder) { if (UnwrapLeft == null && !Left.Type.IsNullableType) - Left = Wrap.Create (Left, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { Left.Type })); + Left = LiftOperand (rc, Left); if (UnwrapRight == null && !Right.Type.IsNullableType) - Right = Wrap.Create (Right, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { Right.Type })); + Right = LiftOperand (rc, Right); } else { if (UnwrapLeft == null && Left != null && Left.Type.IsNullableType) { Left = Unwrap.CreateUnwrapped (Left); @@ -681,6 +681,21 @@ namespace Mono.CSharp.Nullable return this; } + Expression LiftOperand (ResolveContext rc, Expression expr) + { + TypeSpec type; + if (expr.IsNull) { + type = Left.IsNull ? Right.Type : Left.Type; + } else { + type = expr.Type; + } + + if (!type.IsNullableType) + type = rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { type }); + + return Wrap.Create (expr, type); + } + public override void Emit (EmitContext ec) { if (IsBitwiseBoolean && UserOperator == null) { @@ -762,6 +777,9 @@ namespace Mono.CSharp.Nullable if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) { Left = Left.EmitToField (ec); Right = Right.EmitToField (ec); + } else { + UnwrapLeft.Store (ec); + UnwrapRight.Store (ec); } Left.Emit (ec); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs index bcd814149a..da2b13e4ab 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs @@ -635,7 +635,7 @@ namespace Mono.CSharp { if (OptAttributes != null) OptAttributes.Emit (); - if (HasDefaultValue) { + if (HasDefaultValue && default_expr.Type != null) { // // Emit constant values for true constants only, the other // constant-like expressions will rely on default value expression @@ -1336,8 +1336,10 @@ namespace Mono.CSharp { public void Resolve (ResolveContext rc, Parameter p) { var expr = Resolve (rc); - if (expr == null) + if (expr == null) { + this.expr = ErrorExpression.Instance; return; + } expr = Child; diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs index 6ea8d3ccf9..1d8c7e4fa1 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs @@ -1109,8 +1109,8 @@ namespace Mono.CSharp return false; if (declarators != null) { - if ((mod_flags_src & Modifiers.DEFAULT_ACCESS_MODIFER) != 0) - mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFER); + if ((mod_flags_src & Modifiers.DEFAULT_ACCESS_MODIFIER) != 0) + mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFIER); var t = new TypeExpression (MemberType, TypeExpression.Location); foreach (var d in declarators) { diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs index eaac597412..dc097dbc60 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs @@ -146,6 +146,7 @@ namespace Mono.CSharp { public int VerboseParserFlag; public int FatalCounter; public bool Stacktrace; + public bool BreakOnInternalError; #endregion public bool ShowFullPaths; @@ -159,6 +160,8 @@ namespace Mono.CSharp { public RuntimeVersion StdLibRuntimeVersion; + public string RuntimeMetadataVersion; + public bool WriteMetadataOnly; readonly List conditional_symbols; @@ -669,7 +672,8 @@ namespace Mono.CSharp { " --stacktrace Shows stack trace at error location\n" + " --timestamp Displays time stamps of various compiler events\n" + " -v Verbose parsing (for debugging the parser)\n" + - " --mcs-debug X Sets MCS debugging level to X\n"); + " --mcs-debug X Sets MCS debugging level to X\n" + + " --break-on-ice Breaks compilation on internal compiler error"); } // @@ -1180,6 +1184,15 @@ namespace Mono.CSharp { } return ParseResult.Success; + case "runtimemetadataversion": + if (value.Length == 0) { + Error_RequiresArgument (option); + return ParseResult.Error; + } + + settings.RuntimeMetadataVersion = value; + return ParseResult.Success; + default: return ParseResult.UnknownOption; } @@ -1421,6 +1434,10 @@ namespace Mono.CSharp { settings.WriteMetadataOnly = true; return ParseResult.Success; + case "--break-on-ice": + settings.BreakOnInternalError = true; + return ParseResult.Success; + default: if (arg.StartsWith ("--fatal", StringComparison.Ordinal)){ int fatal = 1; diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs index 9aa1fff04f..ed4160aa45 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs @@ -2817,12 +2817,7 @@ namespace Mono.CSharp { if (rc.IsUnreachable) return rc; - base.MarkReachable (rc); - - if (scope_initializers != null) { - foreach (var si in scope_initializers) - si.MarkReachable (rc); - } + MarkReachableScope (rc); foreach (var s in statements) { rc = s.MarkReachable (rc); @@ -2839,6 +2834,16 @@ namespace Mono.CSharp { return rc; } + public void MarkReachableScope (Reachability rc) + { + base.MarkReachable (rc); + + if (scope_initializers != null) { + foreach (var si in scope_initializers) + si.MarkReachable (rc); + } + } + public override bool Resolve (BlockContext bc) { if ((flags & Flags.Resolved) != 0) @@ -3798,7 +3803,7 @@ namespace Mono.CSharp { return false; } catch (Exception e) { - if (e is CompletionResult || bc.Report.IsDisabled || e is FatalException || bc.Report.Printer is NullReportPrinter) + if (e is CompletionResult || bc.Report.IsDisabled || e is FatalException || bc.Report.Printer is NullReportPrinter || bc.Module.Compiler.Settings.BreakOnInternalError) throw; if (bc.CurrentBlock != null) { @@ -3806,9 +3811,6 @@ namespace Mono.CSharp { } else { bc.Report.Error (587, "Internal compiler error: {0}", e.Message); } - - if (bc.Module.Compiler.Settings.DebugFlags > 0) - throw; } // @@ -5031,6 +5033,8 @@ namespace Mono.CSharp { base.MarkReachable (rc); + block.MarkReachableScope (rc); + if (block.Statements.Count == 0) return rc; @@ -6552,6 +6556,9 @@ namespace Mono.CSharp { ok &= c.Resolve (bc); TypeSpec resolved_type = c.CatchType; + if (resolved_type == null) + continue; + for (int ii = 0; ii < clauses.Count; ++ii) { if (ii == i) continue; diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/typespec.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/typespec.cs index edaa4dde69..73d82b086f 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/typespec.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/typespec.cs @@ -1253,6 +1253,9 @@ namespace Mono.CSharp return false; } + if (a.IsNested && b.IsNested) + return IsEqual (a.DeclaringType, b.DeclaringType); + return true; } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs index 69592c9b70..e7b47bcacf 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs @@ -432,7 +432,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver } default: - throw new ArgumentException("Invalid value for UnaryOperatorType", "op"); + return ErrorResolveResult.UnknownError; } } // If the type is nullable, get the underlying type: @@ -611,7 +611,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver // null coalescing operator is not overloadable and needs to be handled separately return ResolveNullCoalescingOperator(lhs, rhs); } else { - throw new ArgumentException("Invalid value for BinaryOperatorType", "op"); + return ErrorResolveResult.UnknownError; } } @@ -1694,6 +1694,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver case NameLookupMode.Type: case NameLookupMode.TypeInUsingDeclaration: case NameLookupMode.BaseTypeReference: + // Don't do the UnknownMemberResolveResult/MethodGroupResolveResult processing, + // it's only relevant for expressions. return lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType); default: throw new NotSupportedException("Invalid value for NameLookupMode"); diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/DelegateContextTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/DelegateContextTests.cs index 3d8318284a..215ae50c49 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/DelegateContextTests.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/DelegateContextTests.cs @@ -148,6 +148,25 @@ public class Test "); Assert.IsNull(provider.Find(".ctor")); } + + [Test] + public void TestCrashOnEventHandlerCCWithoutIndentation() + { + // An off-by-one error in GetLineIndent() was causing an ArgumentOutOfRangeException + CodeCompletionBugTests.CombinedProviderTest( +@"using System; + +public class Test +{ +void TestFoo() +{ +$Action act = a$ +} +} +", provider => { + Assert.IsFalse(provider.AutoSelect); + }); + } } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantUsingDirectiveIssueTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantUsingDirectiveIssueTests.cs index c2a39c03b9..adcb27fd32 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantUsingDirectiveIssueTests.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantUsingDirectiveIssueTests.cs @@ -269,6 +269,33 @@ class Foo } + + [Test] + public void TestKeywordsInNamespace () + { + TestWrongContext(@" + +namespace org.eclipse.jgit.@internal.storage.file +{ + public class File {} +} + +namespace Foo +{ + using org.eclipse.jgit.@internal.storage.file; + + class Bar + { + public static void Main (string[] args) + { + File file; + } + } +} + + +"); + } } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs index 503fd99d86..dcd1c74895 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs @@ -400,7 +400,6 @@ class Activator { Assert.AreEqual("Testnamespace.Activator", result.Type.FullName); } - [Ignore("Fixme")] [Test] public void NamespaceDefinitionOverwritesTypeName () { @@ -1135,5 +1134,16 @@ namespace Test Assert.IsFalse(rr.IsError); Assert.AreEqual("ConcreteTable+Record.Value", rr.Member.ReflectionName); } + + [Test] + public void UsingStatementReferringToMissingNestedType() + { + string program = @"using System; +using $A.B$; + +class A { }"; + var rr = Resolve(program); + + } } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs index 25b62b767d..4adfd1e20a 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs @@ -482,5 +482,61 @@ namespace B { }"); } + + [Test] + public void TestIndentBlocksInsideExpressions () + { + var policy = FormattingOptionsFactory.CreateAllman (); + Test (policy, + @"class Test +{ + void Foo() + { + FooBar(delegate{Foo();}); + } +}", + @"class Test +{ + void Foo() + { + FooBar(delegate + { + Foo(); + }); + } +}"); + } + + /// + /// Bug 18254 - Allow customization of indentation for anonymous methods + /// + [Test] + public void TestBug18254 () + { + var policy = FormattingOptionsFactory.CreateAllman (); + Test (policy, + @"class Test +{ + void Foo() + { + UIView.Animate(duration, () => +{ + view.Alpha = 0; +}, null); + + } +}", + @"class Test +{ + void Foo() + { + UIView.Animate(duration, () => + { + view.Alpha = 0; + }, null); + + } +}"); + } } } \ No newline at end of file diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/IndentationTests/BlockTest.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/IndentationTests/BlockTest.cs index 1aeba2b4f8..c7d8c99efc 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/IndentationTests/BlockTest.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/IndentationTests/BlockTest.cs @@ -862,6 +862,7 @@ class Foo public void TestBrackets_AnonymousMethodOpenBracketAlignment() { var policy = FormattingOptionsFactory.CreateAllman(); + policy.IndentBlocksInsideExpressions = false; var indent = Helper.CreateEngine(@" class Foo { @@ -878,6 +879,7 @@ class Foo public void TestBrackets_AnonymousMethodCloseingBracketAlignment() { var policy = FormattingOptionsFactory.CreateAllman(); + policy.IndentBlocksInsideExpressions = false; var indent = Helper.CreateEngine(@" class Foo { @@ -1166,5 +1168,71 @@ class X Assert.AreEqual("\t\t\t", indent.ThisLineIndent); Assert.AreEqual("\t\t\t", indent.NextLineIndent); } + + [Test] + public void TestBrackets_IndentBlocksInsideExpressionsOpenBrace() + { + var policy = FormattingOptionsFactory.CreateAllman(); + + var indent = Helper.CreateEngine(@" +class Foo +{ + void Test() + { + Foo (new MyOBject + {$ +", policy); + Assert.AreEqual("\t\t\t", indent.ThisLineIndent); + Assert.AreEqual("\t\t\t\t", indent.NextLineIndent); + } + + [Test] + public void TestBrackets_IndentBlocksInsideExpressions() + { + var policy = FormattingOptionsFactory.CreateAllman(); + + var indent = Helper.CreateEngine(@" +class Foo +{ + void Test() + { + Foo (new MyOBject + { + $ +", policy); + Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent); + Assert.AreEqual("\t\t\t\t", indent.NextLineIndent); + } + + /// + /// Bug 18463 - Indentation does not work when typed statement does not require semicolon + /// + [Test] + public void TestBug18463() + { + var policy = FormattingOptionsFactory.CreateMono(); + + var indent = Helper.CreateEngine(@" +namespace FooBar +{ + public class TestProject + { + public static int Main () + { + switch (current_token) { + case Token.CLOSE_PARENS: + case Token.TRUE: + case Token.FALSE: + case Token.NULL: + case Token.LITERAL: + return Token.INTERR; + } + if (true) { + $ +", policy); + Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent); + Assert.AreEqual("\t\t\t\t", indent.NextLineIndent); + } + } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/Completion/DisplayFlags.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/Completion/DisplayFlags.cs index fb7acf9991..dcba38585f 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/Completion/DisplayFlags.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/Completion/DisplayFlags.cs @@ -35,7 +35,8 @@ namespace ICSharpCode.NRefactory.Completion Obsolete = 2, DescriptionHasMarkup = 4, NamedArgument = 8, - IsImportCompletion = 16 + IsImportCompletion = 16, + MarkedBold = 32 } } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs index a64d7bae13..18beccfa64 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs @@ -87,6 +87,9 @@ namespace ICSharpCode.NRefactory.TypeSystem All = 0x7ff, } + /// + /// Ambiences are used to convert type system symbols to text (usually for displaying the symbol to the user; e.g. in editor tooltips). + /// public interface IAmbience { ConversionFlags ConversionFlags { get; set; }