Beispiel #1
0
        private static void AppendArrayType(IArrayTypeSymbol symbol, StringBuilder builder)
        {
            builder.Append(GetMetadataName(symbol.ElementType));

            builder.Append('[');
            builder.Append(',', symbol.Rank - 1);
            builder.Append(']');
        }
Beispiel #2
0
                public override bool VisitArrayType(IArrayTypeSymbol symbol)
                {
                    if (symbol.NullableAnnotation() == NullableAnnotation.None)
                    {
                        return(true);
                    }

                    return(Visit(symbol.ElementType));
                }
            public override void VisitArrayType(IArrayTypeSymbol symbol)
            {
                if (!_visited.Add(symbol))
                {
                    return;
                }

                symbol.ElementType.Accept(this);
            }
Beispiel #4
0
            public override void VisitArrayType(IArrayTypeSymbol symbol)
            {
                if (!visited.Add(symbol))
                {
                    return;
                }

                symbol.ElementType.Accept(this);
            }
Beispiel #5
0
        private IEnumerable <Instruction> BuildNewArrayInstance(ExpressionSyntax syntaxNode,
                                                                IArrayTypeSymbol arrayTypeSymbol, InitializerExpressionSyntax arrayInitializationNode)
        {
            var newInstructions = BuildNewInstance(syntaxNode, arrayTypeSymbol);

            var callTarget = expressionService.GetOrDefault(syntaxNode);

            return(newInstructions.Concat(ProcessArrayInitializer(arrayInitializationNode, callTarget)));
        }
Beispiel #6
0
 public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol?symbol)
 {
     return(symbol switch
     {
         IArrayTypeSymbol a => ContainsAnonymousType(a.ElementType),
         IPointerTypeSymbol p => ContainsAnonymousType(p.PointedAtType),
         INamedTypeSymbol n => ContainsAnonymousType(n),
         _ => false,
     });
Beispiel #7
0
 public SendSizeComplexArrayInvokationExpressionEmitter([NotNull] IArrayTypeSymbol arraySymbol, ISymbol member, PrimitiveSizeType sizeType, SerializationMode mode)
     : base(arraySymbol, member, mode)
 {
     if (!Enum.IsDefined(typeof(PrimitiveSizeType), sizeType))
     {
         throw new InvalidEnumArgumentException(nameof(sizeType), (int)sizeType, typeof(PrimitiveSizeType));
     }
     SizeType = sizeType;
 }
Beispiel #8
0
 /// <summary>
 /// Constructs an array suffix string for this array type symbol.
 /// </summary>
 /// <param name="trapFile">The trap builder used to store the result.</param>
 public static void BuildArraySuffix(this IArrayTypeSymbol array, TextWriter trapFile)
 {
     trapFile.Write('[');
     for (int i = 0; i < array.Rank - 1; i++)
     {
         trapFile.Write(',');
     }
     trapFile.Write(']');
 }
Beispiel #9
0
            public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol)
            {
                ThrowIfNameOnly();

                ITypeSymbol underlyingType = symbol;

                while (underlyingType is IArrayTypeSymbol innerArray)
                {
                    underlyingType = innerArray.ElementType;

#if !CODE_STYLE // TODO: Remove the #if once NullableAnnotation is available.
                    // https://github.com/dotnet/roslyn/issues/41462 tracks adding this support
                    if (underlyingType.NullableAnnotation == NullableAnnotation.Annotated)
                    {
                        // If the inner array we just moved to is also nullable, then
                        // we must terminate the digging now so we produce the syntax for that,
                        // and then append the ranks we passed through at the end. This is because
                        // nullability annotations acts as a "barrier" where we won't reorder array
                        // through. So whereas:
                        //
                        //     string[][,]
                        //
                        // is really an array of rank 1 that has an element of rank 2,
                        //
                        //     string[]?[,]
                        //
                        // is really an array of rank 2 that has nullable elements of rank 1.

                        break;
                    }
#endif
                }

                var elementTypeSyntax = underlyingType.GenerateTypeSyntax();
                var ranks             = new List <ArrayRankSpecifierSyntax>();

                var arrayType = symbol;
                while (arrayType != null && !arrayType.Equals(underlyingType))
                {
                    ranks.Add(SyntaxFactory.ArrayRankSpecifier(
                                  SyntaxFactory.SeparatedList(Enumerable.Repeat <ExpressionSyntax>(SyntaxFactory.OmittedArraySizeExpression(), arrayType.Rank))));

                    arrayType = arrayType.ElementType as IArrayTypeSymbol;
                }

                TypeSyntax arrayTypeSyntax = SyntaxFactory.ArrayType(elementTypeSyntax, ranks.ToSyntaxList());

#if !CODE_STYLE // TODO: Remove the #if once NullableAnnotation is available.
                // https://github.com/dotnet/roslyn/issues/41462 tracks adding this support
                if (symbol.NullableAnnotation == NullableAnnotation.Annotated)
                {
                    arrayTypeSyntax = SyntaxFactory.NullableType(arrayTypeSyntax);
                }
#endif

                return(AddInformationTo(arrayTypeSyntax, symbol));
            }
Beispiel #10
0
 public ArrayCreationExpression(IArrayTypeSymbol arrayType, ImmutableArray <IOperation> elementValues, SyntaxNode syntax) :
     this(arrayType.ElementType,
          ImmutableArray.Create <IOperation>(new LiteralExpression(elementValues.Count(), resultType : null, syntax : syntax)),
          new ArrayInitializer(elementValues, elementValues.Any(v => v.IsInvalid), syntax, arrayType, default(Optional <object>)),
          syntax,
          arrayType,
          default(Optional <object>))
 {
 }
            public override bool VisitArrayType(IArrayTypeSymbol symbol)
            {
                if (!_visited.Add(symbol))
                {
                    return(false);
                }

                return(symbol.ElementType.Accept(this));
            }
Beispiel #12
0
 /// <summary>
 /// Constructs an array suffix string for this array type symbol.
 /// </summary>
 /// <param name="tb">The trap builder used to store the result.</param>
 public static void BuildArraySuffix(this IArrayTypeSymbol array, ITrapBuilder tb)
 {
     tb.Append("[");
     for (int i = 0; i < array.Rank - 1; i++)
     {
         tb.Append(",");
     }
     tb.Append("]");
 }
        private void VisitArrayType(IArrayTypeSymbol symbol, TypeSymbolWithAnnotations typeOpt)
        {
            if (TryAddAlias(symbol, builder))
            {
                return;
            }

            //See spec section 12.1 for the order of rank specifiers
            //e.g. int[][,][,,] is stored as
            //     ArrayType
            //         Rank = 1
            //         ElementType = ArrayType
            //             Rank = 2
            //             ElementType = ArrayType
            //                 Rank = 3
            //                 ElementType = int

            if (format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.ReverseArrayRankSpecifiers))
            {
                // Ironically, reverse order is simpler - we just have to recurse on the element type and then add a rank specifier.
                symbol.ElementType.Accept(this);
                AddArrayRank(symbol);
                return;
            }

            TypeSymbolWithAnnotations underlyingTypeWithAnnotations;
            ITypeSymbol underlyingType = symbol;

            do
            {
                underlyingTypeWithAnnotations = (underlyingType as ArrayTypeSymbol)?.ElementType ?? default;
                underlyingType = ((IArrayTypeSymbol)underlyingType).ElementType;
            }while (underlyingType.Kind == SymbolKind.ArrayType && !ShouldAddNullableAnnotation(underlyingTypeWithAnnotations));

            if (underlyingTypeWithAnnotations.HasType)
            {
                VisitTypeSymbolWithAnnotations(underlyingTypeWithAnnotations);
            }
            else
            {
                underlyingType.Accept(this.NotFirstVisitor);
            }

            var arrayType = symbol;

            while (arrayType != null && arrayType != underlyingType)
            {
                if (!this.isFirstSymbolVisited)
                {
                    AddCustomModifiersIfRequired(arrayType.CustomModifiers, leadingSpace: true);
                }

                AddArrayRank(arrayType);
                arrayType = arrayType.ElementType as IArrayTypeSymbol;
            }
        }
        public void ReturnsTrue_When_HasNoConstraints()
        {
            IArrayTypeSymbol            type      = GetSymbol();
            Mock <ITypeParameterSymbol> parameter = new();

            parameter.SetupGet(p => p.Name).Returns("T");
            parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>());

            Assert.True(type.IsValidForTypeParameter(parameter.Object));
        }
        public void ReturnsFalse_When_DoesNotInheritFromConstrainedType()
        {
            IArrayTypeSymbol            type      = GetSymbol();
            Mock <ITypeParameterSymbol> parameter = new();

            parameter.SetupGet(p => p.Name).Returns("T");
            parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>(Compilation.CurrentCompilation.GetTypeByMetadataName("System.Collections.ArrayList") !));

            Assert.False(type.IsValidForTypeParameter(parameter.Object));
        }
Beispiel #16
0
            public override ITypeSymbol VisitArrayType(IArrayTypeSymbol symbol)
            {
                var elementType = symbol.ElementType.Accept(this);

                if (elementType != null && elementType.Equals(symbol.ElementType))
                {
                    return(symbol);
                }
                return(_compilation.CreateArrayTypeSymbol(elementType));
            }
        public void ThrowsArgumentNullException_When_ArrayTypelIsNull()
        {
            IArrayTypeSymbol            type      = null !;
            Mock <ITypeParameterSymbol> parameter = new();

            parameter.SetupGet(p => p.Name).Returns("T");
            parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>());

            Assert.Throws <ArgumentNullException>(() => type.IsValidForTypeParameter(parameter.Object));
        }
        public FixedSizePrimitiveArrayInvokationExpressionEmitter([NotNull] IArrayTypeSymbol arraySymbol, ISymbol member, int knownSize, SerializationMode mode)
            : base(arraySymbol, member, mode)
        {
            KnownSize = knownSize;

            if (!arraySymbol.ElementType.IsPrimitive())
            {
                throw new InvalidOperationException($"Type: {arraySymbol.ElementType.Name} must be primitive.");
            }
        }
Beispiel #19
0
        public static ITypeInfo CreateFrom(ITypeSymbol typeSymbol, Compilation compilation)
        {
            typeSymbol.EnsureNotError();

            return(typeSymbol switch
            {
                IArrayTypeSymbol array => new SymbolArrayTypeInfo(array, compilation),
                INamedTypeSymbol named when named.TypeArguments.Any() /*ne IsGenericType legyen*/ => new SymbolGenericTypeInfo(named, compilation),
                _ => new SymbolTypeInfo(typeSymbol, compilation)
            });
Beispiel #20
0
        static void MakeArray(IArrayTypeSymbol array, List <GenericSerializationInfo> list)
        {
            var arrayInfo = new GenericSerializationInfo
            {
                FormatterName = $"global::MessagePack.Formatters.ArrayFormatter<{array.ElementType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>()",
                FullName      = array.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            list.Add(arrayInfo);
        }
        public void ReturnsFalse_When_HasUnmanagedConstraint()
        {
            IArrayTypeSymbol            type      = GetSymbol();
            Mock <ITypeParameterSymbol> parameter = new();

            parameter.SetupGet(p => p.Name).Returns("T");
            parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>());
            parameter.SetupGet(p => p.HasUnmanagedTypeConstraint).Returns(true);

            Assert.False(type.IsValidForTypeParameter(parameter.Object));
        }
Beispiel #22
0
 public override string VisitArrayType(IArrayTypeSymbol symbol)
 {
     if (symbol.Rank == 1)
     {
         return(symbol.ElementType.Accept(this) + "[]");
     }
     else
     {
         return(symbol.ElementType.Accept(this) + "[" + new string(',', symbol.Rank - 1) + "]");
     }
 }
Beispiel #23
0
        ///<summary>Array types can only be one dimensional and not System.Array,
        ///and there are some types not usable in the Windows Runtime, like KeyValuePair</summary>
        ///<param name="typeSymbol">The type to check</param><param name="loc">where the type is</param>
        ///<param name="memberId">The method or property with this type in its signature</param>
        /// <param name="typeId">the type this member (method/prop) lives in</param>
        private void ReportIfInvalidType(ITypeSymbol typeSymbol, Location loc, SyntaxToken memberId, SyntaxToken typeId)
        {
            // If it's of the form int[], it has to be one dimensional
            if (typeSymbol.TypeKind == TypeKind.Array)
            {
                IArrayTypeSymbol arrTypeSym = (IArrayTypeSymbol)typeSymbol;

                // [,,]?
                if (arrTypeSym.Rank > 1)
                {
                    Report(WinRTRules.MultiDimensionalArrayRule, loc, memberId, typeId);
                    return;
                }
                // [][]?
                if (arrTypeSym.ElementType.TypeKind == TypeKind.Array)
                {
                    Report(WinRTRules.JaggedArrayRule, loc, memberId, typeId);
                    return;
                }
            }

            // NotValidTypes is an array of types that don't exist in Windows Runtime, so can't be passed between functions in Windows Runtime
            foreach (var typeName in NotValidTypes)
            {
                var notValidTypeSym = GetTypeByMetadataName(typeName);
                if (SymEq(typeSymbol.OriginalDefinition, notValidTypeSym))
                {
                    Report(WinRTRules.UnsupportedTypeRule, loc, memberId, typeName, SuggestType(typeName));
                    return;
                }
            }

            // construct the qualified name for this type
            string qualifiedName = "";

            if (typeSymbol.ContainingNamespace != null && !typeSymbol.ContainingNamespace.IsGlobalNamespace)
            {
                // ContainingNamespace for Enumerable is just System, but we need System.Linq which is the ContainingSymbol
                qualifiedName += typeSymbol.ContainingSymbol + ".";
            }
            // instead of TypeName<int>, TypeName`1
            qualifiedName += typeSymbol.MetadataName;

            // GetTypeByMetadataName fails on "System.Linq.Enumerable" & "System.Collections.ObjectModel.ReadOnlyDictionary`2"
            // Would be fixed by issue #678 on the dotnet/roslyn-sdk repo
            foreach (var notValidType in WIPNotValidTypes)
            {
                if (qualifiedName == notValidType)
                {
                    Report(WinRTRules.UnsupportedTypeRule, loc, memberId, notValidType, SuggestType(notValidType));
                    return;
                }
            }
        }
            public override async ValueTask <ITypeSymbol> VisitArrayType(IArrayTypeSymbol symbol)
            {
                var elementType = await symbol.ElementType.Accept(this).ConfigureAwait(false);

                if (elementType != null && elementType.Equals(symbol.ElementType))
                {
                    return(symbol);
                }

                return(_compilation.CreateArrayTypeSymbol(elementType, symbol.Rank));
            }
Beispiel #25
0
            public override ITypeSymbol VisitArrayType(IArrayTypeSymbol symbol)
            {
                var elementType = symbol.ElementType.Accept(this);

                if (elementType != null && elementType.Equals(symbol.ElementType))
                {
                    return(symbol);
                }

                return(typeGenerator.CreateArrayTypeSymbol(elementType, symbol.Rank));
            }
 public UdonSharpBehaviourTypeSymbol(IArrayTypeSymbol sourceSymbol, AbstractPhaseContext context)
     : base(sourceSymbol, context)
 {
     if (sourceSymbol.ElementType.TypeKind == TypeKind.Array)
     {
         UdonType = (ExternTypeSymbol)context.GetTypeSymbol(SpecialType.System_Object).MakeArrayType(context);
     }
     else
     {
         UdonType = (ExternTypeSymbol)context.GetTypeSymbol(typeof(Component[]));
     }
 }
Beispiel #27
0
        public ExternTypeSymbol(IArrayTypeSymbol sourceSymbol, AbstractPhaseContext context)
            : base(sourceSymbol, context)
        {
            TryGetSystemType(sourceSymbol, out Type systemType);
            SystemType = systemType;

            Type udonType = UdonSharpUtils.UserTypeToUdonType(SystemType);

            UdonType = (ExternTypeSymbol)(udonType == SystemType ? this : context.GetUdonTypeSymbol(sourceSymbol));

            ExternSignature = CompilerUdonInterface.GetUdonTypeName(UdonType);
        }
 public ImportedUdonSharpTypeSymbol(IArrayTypeSymbol sourceSymbol, AbstractPhaseContext context)
     : base(sourceSymbol, context)
 {
     if (sourceSymbol.ElementType.TypeKind == TypeKind.Enum)
     {
         UdonType = (ExternTypeSymbol)context.GetTypeSymbol(((INamedTypeSymbol)sourceSymbol.ElementType).EnumUnderlyingType).UdonType.MakeArrayType(context);
     }
     else
     {
         UdonType = context.GetTypeSymbol(typeof(object[])).UdonType;
     }
 }
Beispiel #29
0
        private static (ITypeSymbol ElementType, string Prefix) ExpandArray(IArrayTypeSymbol array)
        {
            var prefix = "Array";

            while (array.ElementType is IArrayTypeSymbol subArray)
            {
                prefix += "Array";
                array   = subArray;
            }

            return(array.ElementType, prefix);
        }
        public void ReturnsTrue_When_HasNullableReferenceTypeConstraint()
        {
            IArrayTypeSymbol            type      = GetSymbol();
            Mock <ITypeParameterSymbol> parameter = new();

            parameter.SetupGet(p => p.Name).Returns("T");
            parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>());
            parameter.SetupGet(p => p.HasReferenceTypeConstraint).Returns(true);
            parameter.SetupGet(p => p.ReferenceTypeConstraintNullableAnnotation).Returns(NullableAnnotation.Annotated);

            Assert.True(type.IsValidForTypeParameter(parameter.Object));
        }
            public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol)
            {
                ThrowIfNameOnly();

                ITypeSymbol underlyingType = symbol;

                while (underlyingType is IArrayTypeSymbol innerArray)
                {
                    underlyingType = innerArray.ElementType;

                    if (underlyingType.NullableAnnotation == NullableAnnotation.Annotated)
                    {
                        // If the inner array we just moved to is also nullable, then
                        // we must terminate the digging now so we produce the syntax for that,
                        // and then append the ranks we passed through at the end. This is because
                        // nullability annotations acts as a "barrier" where we won't reorder array
                        // through. So whereas:
                        //
                        //     string[][,]
                        //
                        // is really an array of rank 1 that has an element of rank 2,
                        //
                        //     string[]?[,]
                        //
                        // is really an array of rank 2 that has nullable elements of rank 1.

                        break;
                    }
                }

                var elementTypeSyntax = underlyingType.GenerateTypeSyntax();

                using var _ = ArrayBuilder <ArrayRankSpecifierSyntax> .GetInstance(out var ranks);

                var arrayType = symbol;

                while (arrayType != null && !arrayType.Equals(underlyingType))
                {
                    ranks.Add(SyntaxFactory.ArrayRankSpecifier(
                                  SyntaxFactory.SeparatedList(Enumerable.Repeat <ExpressionSyntax>(SyntaxFactory.OmittedArraySizeExpression(), arrayType.Rank))));

                    arrayType = arrayType.ElementType as IArrayTypeSymbol;
                }

                TypeSyntax arrayTypeSyntax = SyntaxFactory.ArrayType(elementTypeSyntax, ranks.ToSyntaxList());

                if (symbol.NullableAnnotation == NullableAnnotation.Annotated)
                {
                    arrayTypeSyntax = SyntaxFactory.NullableType(arrayTypeSyntax);
                }

                return(AddInformationTo(arrayTypeSyntax, symbol));
            }
        public void ReturnsTrue_When_InheritFromConstraintType_And_ParameterIsConstrainedToNullable()
        {
            IArrayTypeSymbol type = GetSymbol();

            Mock <ITypeParameterSymbol> parameter = new();

            parameter.SetupGet(p => p.Name).Returns("T");
            parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>(Compilation.CurrentCompilation.GetTypeByMetadataName("System.Collections.IList") !));
            parameter.SetupGet(p => p.ConstraintNullableAnnotations).Returns(ImmutableArray.Create(NullableAnnotation.Annotated));

            Assert.True(type.IsValidForTypeParameter(parameter.Object));
        }
        public override void VisitArrayType(IArrayTypeSymbol symbol)
        {
            if (TryAddAlias(symbol, builder))
            {
                return;
            }

            //See spec section 12.1 for the order of rank specifiers
            //e.g. int[][,][,,] is stored as 
            //     ArrayType
            //         Rank = 1
            //         ElementType = ArrayType
            //             Rank = 2
            //             ElementType = ArrayType
            //                 Rank = 3
            //                 ElementType = int

            if (format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.ReverseArrayRankSpecifiers))
            {
                // Ironically, reverse order is simpler - we just have to recurse on the element type and then add a rank specifier.
                symbol.ElementType.Accept(this);
                AddArrayRank(symbol);
                return;
            }

            var underlyingNonArrayType = symbol.ElementType;
            while (underlyingNonArrayType.Kind == SymbolKind.ArrayType)
            {
                underlyingNonArrayType = ((IArrayTypeSymbol)underlyingNonArrayType).ElementType;
            }

            underlyingNonArrayType.Accept(this.NotFirstVisitor);

            var arrayType = symbol;
            while (arrayType != null)
            {
                if (!this.isFirstSymbolVisited)
                {
                    AddCustomModifiersIfRequired(arrayType.CustomModifiers, leadingSpace: true);
                }

                AddArrayRank(arrayType);
                arrayType = arrayType.ElementType as IArrayTypeSymbol;
            }
        }
        private void AddArrayRank(IArrayTypeSymbol symbol)
        {
            bool insertStars = format.MiscellaneousOptions.IncludesOption(SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays);

            AddPunctuation(SyntaxKind.OpenBracketToken);

            if (insertStars && symbol.Rank > 1)
            {
                AddPunctuation(SyntaxKind.AsteriskToken);
            }

            for (int i = 0; i < symbol.Rank - 1; i++)
            {
                AddPunctuation(SyntaxKind.CommaToken);

                if (insertStars)
                {
                    AddPunctuation(SyntaxKind.AsteriskToken);
                }
            }

            AddPunctuation(SyntaxKind.CloseBracketToken);
        }
        private void AddArrayRank(IArrayTypeSymbol symbol)
        {
            bool insertStars = format.MiscellaneousOptions.IncludesOption(SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays);

            AddPunctuation(SyntaxKind.OpenBracketToken);

            if (symbol.Rank > 1)
            {
                if (insertStars)
                {
                    AddPunctuation(SyntaxKind.AsteriskToken);
                }
            }
            else
            {
                var array = symbol as ArrayTypeSymbol;

                if ((object)array != null && !array.IsSZArray)
                {
                    // Always add an asterisk in this case in order to distinguish between SZArray and MDArray.
                    AddPunctuation(SyntaxKind.AsteriskToken);
                }
            }

            for (int i = 0; i < symbol.Rank - 1; i++)
            {
                AddPunctuation(SyntaxKind.CommaToken);

                if (insertStars)
                {
                    AddPunctuation(SyntaxKind.AsteriskToken);
                }
            }

            AddPunctuation(SyntaxKind.CloseBracketToken);
        }
 public ArrayCreation(IArrayTypeSymbol arrayType, ImmutableArray<IExpression> elementValues, SyntaxNode syntax)
 {
     _arrayType = arrayType;
     this.DimensionSizes = ImmutableArray.Create<IExpression>(new IntegerLiteral(elementValues.Count(), null, syntax));
     this.ElementValues = new DimensionInitializer(elementValues);
     this.Syntax = syntax;
 }
 public override void VisitArrayType(IArrayTypeSymbol arrayTypeSymbol)
 {
     arrayTypeSymbol.ElementType.Accept(this);
 }
Beispiel #38
0
 public override void VisitArrayType(IArrayTypeSymbol symbol)
 {
     base.VisitArrayType(symbol);
 }
 private bool ArrayTypesAreEquivalent(IArrayTypeSymbol x, IArrayTypeSymbol y, Dictionary<INamedTypeSymbol, INamedTypeSymbol> equivalentTypesWithDifferingAssemblies)
 {
     return
         x.Rank == y.Rank &&
         AreEquivalent(x.ElementType, y.ElementType, equivalentTypesWithDifferingAssemblies);
 }
 private void Visit(IArrayTypeSymbol type)
 {
     Visit(type.ElementType);
     builder.Append("[");
     for (int i = 1; i <= type.Rank; i++) builder.Append(",");
     builder.Append("]");
 }
 private static bool AtLeastOneExactTypeMatch(SemanticModel semanticModel, ArrayCreationExpressionSyntax arrayCreation, IArrayTypeSymbol arrayType)
 {
     return arrayCreation.Initializer.Initializers.Any(initializer => arrayType.ElementType.Equals(semanticModel.GetTypeInfo(initializer).Type));
 }
			public ArrayParameterHintingData (IArrayTypeSymbol arrayType) : base (arrayType)
			{
				this.arrayType = arrayType;
			}
        private static async Task<GraphNodeId> GetPartialForArrayTypeAsync(IArrayTypeSymbol arrayType, GraphNodeIdName nodeName, Solution solution, CancellationToken cancellationToken)
        {
            var partials = new List<GraphNodeId>();

            var underlyingType = ChaseToUnderlyingType(arrayType);

            if (underlyingType.TypeKind == TypeKind.Dynamic)
            {
                partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, "Object"));
            }
            else if (underlyingType.TypeKind != TypeKind.TypeParameter)
            {
                partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, underlyingType.Name));
            }

            partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.ArrayRank, arrayType.Rank.ToString()));
            partials.Add(await GetPartialForTypeAsync(arrayType.ElementType, CodeGraphNodeIdName.ParentType, solution, cancellationToken).ConfigureAwait(false));

            return GraphNodeId.GetPartial(nodeName, MakeCollectionIfNecessary(false, partials.ToArray()));
        }
		public string GetArrayIndexerMarkup (IArrayTypeSymbol arrayType)
		{
			if (arrayType == null)
				throw new ArgumentNullException ("arrayType");
			var result = new StringBuilder ();
			result.Append (GetTypeReferenceString (arrayType.ElementType));
			if (BreakLineAfterReturnType) {
				result.AppendLine ();
			} else {
				result.Append (" ");
			}
			result.Append (Highlight ("this", colorStyle.KeywordAccessors));
			result.Append ("[");
			for (int i = 0; i < arrayType.Rank; i++) {
				if (i > 0)
					result.Append (", ");
				var doHighightParameter = i == HighlightParameter;
				if (doHighightParameter)
					result.Append ("<u>");

				result.Append (Highlight ("int ", colorStyle.KeywordTypes));
				result.Append (arrayType.Rank == 1 ? "index" : "i" + (i + 1));
				if (doHighightParameter)
					result.Append ("</u>");
			}
			result.Append ("]");

			result.Append (" {");
			result.Append (Highlight (" get", colorStyle.KeywordProperty) + ";");
			result.Append (Highlight (" set", colorStyle.KeywordProperty) + ";");
			result.Append (" }");

			return result.ToString ();
		}
Beispiel #45
0
 public override void VisitArrayType(IArrayTypeSymbol symbol)
 {
     symbol.ElementType.Accept(this);
     if (symbol.Rank == 1)
     {
         ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem
         {
             DisplayName = "[]",
             DisplayQualifiedNames = "[]",
         });
     }
     else
     {
         ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem
         {
             DisplayName = "[" + new string(',', symbol.Rank - 1) + "]",
             DisplayQualifiedNames = "[" + new string(',', symbol.Rank - 1) + "]",
         });
     }
 }
Beispiel #46
0
 public override void VisitArrayType(IArrayTypeSymbol symbol)
 {
     symbol.ElementType.Accept(this);
     if (symbol.Rank == 1)
     {
         Append("()");
     }
     else
     {
         Append("(");
         for (int i = 1; i < symbol.Rank; i++)
         {
             Append(",");
         }
         Append(")");
     }
 }
 public static void Create(IArrayTypeSymbol symbol, SymbolKeyWriter visitor)
 {
     visitor.WriteSymbolKey(symbol.ElementType);
     visitor.WriteInteger(symbol.Rank);
 }
Beispiel #48
0
        public JsInvocationExpression MakeArray(JsExpression array, IArrayTypeSymbol arrayType)
        {
            if (arrayType.ElementType.Equals(Context.Instance.Int32))
                array = Js.New(Js.Reference("Int32Array"), array);
            else if (arrayType.ElementType.Equals(Context.Instance.Int16))
                array = Js.New(Js.Reference("Int16Array"), array);
            else if (arrayType.ElementType.Equals(Context.Instance.Byte))
                array = Js.New(Js.Reference("Uint8Array"), array);
            else if (arrayType.ElementType.Equals(Context.Instance.SByte))
                array = Js.New(Js.Reference("Int8Array"), array);
            else if (arrayType.ElementType.Equals(Context.Instance.Single))
                array = Js.New(Js.Reference("Float32Array"), array);
            else if (arrayType.ElementType.Equals(Context.Instance.Double))
                array = Js.New(Js.Reference("Float64Array"), array);

            return Js.Reference(SpecialNames.InitializeArray).Invoke(
                array,
                Type(arrayType.ElementType));
        }
Beispiel #49
0
 public virtual void VisitArrayType(IArrayTypeSymbol symbol)
 {
     DefaultVisit(symbol);
 }
 public sealed override void VisitArrayType(IArrayTypeSymbol symbol)
 {
     Visit(symbol.ElementType);
 }
 private static bool AllTypesAreConvertible(SemanticModel semanticModel, ArrayCreationExpressionSyntax arrayCreation, IArrayTypeSymbol arrayType)
 {
     return arrayCreation.Initializer.Initializers.All(initializer =>
     {
         var conversion = semanticModel.ClassifyConversion(initializer, arrayType.ElementType);
         return conversion.Exists && (conversion.IsIdentity || conversion.IsWidening);
     });
 }
Beispiel #52
0
 public JsInvocationExpression Array(IArrayTypeSymbol arrayType, params JsExpression[] elements)
 {
     return MakeArray(Js.Array(elements), arrayType);
 }