提交 cbe2b9fe 编写于 作者: V VSadov

reduced the size of Microsoft.CodeAnalysis.CSharp.Conversion

上级 ea54e1e1
......@@ -363,13 +363,14 @@ private BoundExpression CreateTupleLiteralConversion(CSharpSyntaxNode syntax, Bo
ImmutableArray<TypeSymbol> targetElementTypes = targetType.GetElementTypesOfTupleOrCompatible();
Debug.Assert(targetElementTypes.Length == arguments.Length, "converting a tuple literal to incompatible type?");
var underlyingConversions = conversionWithoutNullable.UnderlyingConversions;
for (int i = 0; i < arguments.Length; i++)
{
var argument = arguments[i];
var destType = targetElementTypes[i];
var elementConversion = underlyingConversions[i];
Conversion elementConversion = conversionWithoutNullable.UnderlyingConversions[i];
convertedArguments.Add(CreateConversion(argument.Syntax, argument, elementConversion, isCast, destType, diagnostics));
}
......
......@@ -6177,7 +6177,12 @@ private BoundExpression TryImplicitConversionToArrayIndex(BoundExpression expr,
return null;
}
BoundExpression result = CreateConversion(expr.Syntax, expr, conversion.WithArrayIndexConversion(true), isCast: false, destination: type, diagnostics: attemptDiagnostics); // UNDONE: was cast?
if (conversion.IsDynamic)
{
conversion = conversion.SetArrayIndexConversionForDynamic();
}
BoundExpression result = CreateConversion(expr.Syntax, expr, conversion, isCast: false, destination: type, diagnostics: attemptDiagnostics); // UNDONE: was cast?
Debug.Assert(result != null); // If this ever fails (it shouldn't), then put a null-check around the diagnostics update.
diagnostics.AddRange(attemptDiagnostics);
......
......@@ -337,7 +337,7 @@ private Conversion ClassifyImplicitTupleLiteralConversion(BoundTupleLiteral sour
if (underlyingTupleConversion.Exists)
{
return new Conversion(ConversionKind.ImplicitNullable, new Conversion[] { underlyingTupleConversion });
return new Conversion(ConversionKind.ImplicitNullable, ImmutableArray.Create(underlyingTupleConversion));
}
}
}
......@@ -356,7 +356,7 @@ private Conversion ClassifyExplicitTupleLiteralConversion(BoundTupleLiteral sour
// strip nullable from the destination
//
// the following should work and it is an ExplicitNullable conversion
// var x = ((byte, string)?)(1,2);
// var x = ((byte, string)?)(1,null);
if (destination.Kind == SymbolKind.NamedType)
{
var nt = (NamedTypeSymbol)destination;
......@@ -366,7 +366,7 @@ private Conversion ClassifyExplicitTupleLiteralConversion(BoundTupleLiteral sour
if (underlyingTupleConversion.Exists)
{
return new Conversion(ConversionKind.ExplicitNullable, new Conversion[] { underlyingTupleConversion });
return new Conversion(ConversionKind.ExplicitNullable, ImmutableArray.Create(underlyingTupleConversion));
}
}
}
......@@ -788,7 +788,7 @@ protected override Conversion GetImplicitTupleLiteralConversion(BoundTupleLitera
argumentConversions.Add(result);
}
return new Conversion(ConversionKind.ImplicitTupleLiteral, argumentConversions.ToArrayAndFree());
return new Conversion(ConversionKind.ImplicitTupleLiteral, argumentConversions.ToImmutableAndFree());
}
protected override Conversion GetExplicitTupleLiteralConversion(BoundTupleLiteral source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics, bool forCast)
......@@ -822,7 +822,7 @@ protected override Conversion GetExplicitTupleLiteralConversion(BoundTupleLitera
argumentConversions.Add(result);
}
return new Conversion(ConversionKind.ExplicitTupleLiteral, argumentConversions.ToArrayAndFree());
return new Conversion(ConversionKind.ExplicitTupleLiteral, argumentConversions.ToImmutableAndFree());
}
protected override Conversion GetInterpolatedStringConversion(BoundInterpolatedString source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
......
......@@ -965,7 +965,7 @@ private Conversion ClassifyImplicitNullableConversion(TypeSymbol source, TypeSym
var tupleConversion = ClassifyImplicitTupleConversion(unwrappedSource, unwrappedDestination, ref useSiteDiagnostics);
if (tupleConversion.Exists)
{
return new Conversion(ConversionKind.ImplicitNullable, new Conversion[] { tupleConversion });
return new Conversion(ConversionKind.ImplicitNullable, ImmutableArray.Create(tupleConversion));
}
return Conversion.NoConversion;
......@@ -996,7 +996,7 @@ private Conversion ClassifyImplicitTupleConversion(TypeSymbol source, TypeSymbol
nestedConversions.Add(conversion);
}
return new Conversion(ConversionKind.ImplicitTuple, nestedConversions.ToArrayAndFree());
return new Conversion(ConversionKind.ImplicitTuple, nestedConversions.ToImmutableAndFree());
}
private Conversion ClassifyExplicitTupleConversion(TypeSymbol source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics, bool forCast)
......@@ -1027,7 +1027,7 @@ private Conversion ClassifyExplicitTupleConversion(TypeSymbol source, TypeSymbol
nestedConversions.Add(conversion);
}
return new Conversion(ConversionKind.ExplicitTuple, nestedConversions.ToArrayAndFree());
return new Conversion(ConversionKind.ExplicitTuple, nestedConversions.ToImmutableAndFree());
}
private Conversion ClassifyExplicitNullableConversion(TypeSymbol source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics, bool forCast)
......@@ -1069,7 +1069,7 @@ private Conversion ClassifyExplicitNullableConversion(TypeSymbol source, TypeSym
var tupleConversion = ClassifyExplicitTupleConversion(unwrappedSource, unwrappedDestination, ref useSiteDiagnostics, forCast);
if (tupleConversion.Exists)
{
return new Conversion(ConversionKind.ExplicitNullable, new[] {tupleConversion});
return new Conversion(ConversionKind.ExplicitNullable, ImmutableArray.Create(tupleConversion));
}
if (HasExplicitEnumerationConversion(unwrappedSource, unwrappedDestination))
......
......@@ -322,11 +322,6 @@ public bool IsExtensionMethod
get { return this.Conversion.IsExtensionMethod; }
}
public bool IsArrayIndex
{
get { return this.Conversion.IsArrayIndex; }
}
public MethodSymbol SymbolOpt
{
get { return this.Conversion.Method; }
......
......@@ -1101,7 +1101,7 @@ private BoundExpression MakeLiftedUserDefinedConversionConsequence(BoundCall cal
Debug.Assert(!method.ReturnsVoid);
Debug.Assert(method.ParameterCount == 1);
conversion = conversion.WithConversionMethod(method);
conversion = conversion.SetConversionMethod(method);
if (source.IsNullableType() && target.IsNullableType())
{
......
......@@ -671,7 +671,7 @@ private BoundNode RewriteMethodGroupConversion(BoundConversion conversion)
var conversionInfo = conversion.Conversion;
if (conversionInfo.Method != (object)method)
{
conversionInfo = conversionInfo.WithConversionMethod(method);
conversionInfo = conversionInfo.SetConversionMethod(method);
}
return conversion.Update(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册