public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, IEnumerable <TypedConstant> items, Semmle.Extraction.Entities.Location location)
        {
            var info = new ExpressionInfo(
                cx,
                AnnotatedTypeSymbol.CreateNotAnnotated(type),
                location,
                ExprKind.ARRAY_CREATION,
                parent,
                childIndex,
                true,
                null);

            var arrayCreation = new Expression(info);

            var length = items.Count();

            Literal.CreateGenerated(cx, arrayCreation, 0, cx.Compilation.GetSpecialType(SpecialType.System_Int32), length, location);

            if (length > 0)
            {
                var arrayInit = ArrayInitializer.CreateGenerated(cx, arrayCreation, InitializerIndex, location);
                var child     = 0;
                foreach (var item in items)
                {
                    Expression.CreateGenerated(cx, item, arrayInit, child++, location);
                }
            }

            return(arrayCreation);
        }
예제 #2
0
        protected override void PopulateExpression(TextWriter trapFile)
        {
            if (Syntax.Initializer != null)
            {
                ArrayInitializer.Create(new ExpressionNodeInfo(cx, Syntax.Initializer, this, -1));
            }

            trapFile.implicitly_typed_array_creation(this);
        }
예제 #3
0
        protected override void Populate()
        {
            if (Syntax.Initializer != null)
            {
                ArrayInitializer.Create(new ExpressionNodeInfo(cx, Syntax.Initializer, this, -1));
            }

            cx.Emit(Tuples.implicitly_typed_array_creation(this));
        }
예제 #4
0
        protected override void PopulateExpression(TextWriter trapFile)
        {
            var child           = 0;
            var explicitlySized = false;

            if (TypeSyntax is null)
            {
                cx.ModelError(Syntax, "Array has unexpected type syntax");
            }

            foreach (var rank in TypeSyntax.RankSpecifiers.SelectMany(rs => rs.Sizes))
            {
                if (rank is OmittedArraySizeExpressionSyntax)
                {
                    // Create an expression which simulates the explicit size of the array

                    if (!(Initializer is null))
                    {
                        // An implicitly-sized array must have an initializer.
                        // Guard it just in case.
                        var size = Initializer.Expressions.Count;

                        var info = new ExpressionInfo(
                            cx,
                            new AnnotatedType(Entities.Type.Create(cx, cx.Compilation.GetSpecialType(Microsoft.CodeAnalysis.SpecialType.System_Int32)), Kinds.TypeAnnotation.NotAnnotated),
                            Location,
                            ExprKind.INT_LITERAL,
                            this,
                            child,
                            false,
                            size.ToString());

                        new Expression(info);
                    }
                }
                else
                {
                    Create(cx, rank, this, child);
                    explicitlySized = true;
                }
                child++;
            }
            if (!(Initializer is null))
            {
                ArrayInitializer.Create(new ExpressionNodeInfo(cx, Initializer, this, -1));
            }

            if (explicitlySized)
            {
                trapFile.explicitly_sized_array_creation(this);
            }
        }
예제 #5
0
        protected override void Populate()
        {
            var  child           = 0;
            bool explicitlySized = false;

            foreach (var rank in Syntax.Type.RankSpecifiers.SelectMany(rs => rs.Sizes))
            {
                if (rank is OmittedArraySizeExpressionSyntax)
                {
                    // Create an expression which simulates the explicit size of the array

                    if (Syntax.Initializer != null)
                    {
                        // An implicitly-sized array must have an initializer.
                        // Guard it just in case.
                        var size = Syntax.Initializer.Expressions.Count;

                        var info = new ExpressionInfo(
                            cx,
                            Type.Create(cx, cx.Compilation.GetSpecialType(Microsoft.CodeAnalysis.SpecialType.System_Int32)),
                            Location,
                            ExprKind.INT_LITERAL,
                            this,
                            child,
                            false,
                            size.ToString());

                        new Expression(info);
                    }
                }
                else
                {
                    Create(cx, rank, this, child);
                    explicitlySized = true;
                }
                child++;
            }
            if (Syntax.Initializer != null)
            {
                ArrayInitializer.Create(new ExpressionNodeInfo(cx, Syntax.Initializer, this, -1));
            }

            if (explicitlySized)
            {
                cx.Emit(Tuples.explicitly_sized_array_creation(this));
            }
        }
        protected override void PopulateExpression(TextWriter trapFile)
        {
            var explicitlySized = false;

            if (TypeSyntax is null)
            {
                Context.ModelError(Syntax, "Array has unexpected type syntax");
                return;
            }

            var firstLevelSizes = TypeSyntax.RankSpecifiers.First()?.Sizes ?? SyntaxFactory.SeparatedList <ExpressionSyntax>();

            if (firstLevelSizes.OfType <ExpressionSyntax>().Any(s => s is OmittedArraySizeExpressionSyntax))
            {
                SetArraySizes(Initializer, firstLevelSizes.Count);
            }
            else
            {
                for (var sizeIndex = 0; sizeIndex < firstLevelSizes.Count; sizeIndex++)
                {
                    Create(Context, firstLevelSizes[sizeIndex], this, sizeIndex);
                }
                explicitlySized = true;
            }

            if (!(Initializer is null))
            {
                ArrayInitializer.Create(new ExpressionNodeInfo(Context, Initializer, this, InitializerIndex));
            }

            if (explicitlySized)
            {
                trapFile.explicitly_sized_array_creation(this);
            }

            TypeMention.Create(Context, TypeSyntax, this, Type);
        }
 protected override void PopulateExpression(TextWriter trapFile)
 {
     ArrayInitializer.Create(new ExpressionNodeInfo(Context, Syntax.Initializer, this, InitializerIndex));
     trapFile.implicitly_typed_array_creation(this);
     trapFile.stackalloc_array_creation(this);
 }