Exemple #1
0
        private static AbstractExpression ReadInterpolatedString(IInterpolatedStringOperation op)
        {
            var result = new InterpolatedStringExpression();

            foreach (var part in op.Parts)
            {
                switch (part)
                {
                case IInterpolatedStringTextOperation text:
                    result.Parts.Add(new InterpolatedStringExpression.TextPart {
                        Text = ReadExpression(text.Text).GetConstantValueOrNull() as string
                    });
                    break;

                case IInterpolationOperation interpolation:
                    result.Parts.Add(new InterpolatedStringExpression.InterpolationPart {
                        Value        = ReadExpression(interpolation.Expression),
                        Alignment    = ReadExpression(interpolation.Alignment),
                        FormatString = ReadExpression(interpolation.FormatString)
                    });
                    break;
                }
            }

            return(result);
        }
Exemple #2
0
            public override TaintedDataAbstractValue?VisitInterpolatedString(IInterpolatedStringOperation operation, object?argument)
            {
                var ret = base.VisitInterpolatedString(operation, argument);

                if (ret.Kind == TaintedDataAbstractValueKind.Tainted)
                {
                    foreach (var interpolation in operation.Children)
                    {
                        if (interpolation.Type != null)
                        {
                            throw new Exception($"interpolation.Type was not null but {interpolation.Type}");
                        }

                        bool shouldSanitize = true;
                        foreach (var child in interpolation.Children)
                        {
                            shouldSanitize = ShouldSanitizeConversion(SpecialType.System_String, child);
                            if (!shouldSanitize)
                            {
                                break;
                            }
                        }

                        if (shouldSanitize)
                        {
                            return(ValueDomain.UnknownOrMayBeValue);
                        }
                    }
                }

                return(ret);
            }
            public override ValueContentAbstractValue VisitInterpolatedString(IInterpolatedStringOperation operation, object argument)
            {
                if (operation.Parts.IsEmpty)
                {
                    return(ValueContentAbstractValue.ContainsEmptyStringLiteralState);
                }

                ValueContentAbstractValue mergedValue = Visit(operation.Parts[0], argument);

                for (int i = 1; i < operation.Parts.Length; i++)
                {
                    var newValue = Visit(operation.Parts[i], argument);
                    mergedValue = mergedValue.MergeBinaryOperation(newValue, BinaryOperatorKind.Add, leftType: operation.Type, rightType: operation.Type, resultType: operation.Type);
                }

                return(mergedValue);
            }
Exemple #4
0
            public override StringContentAbstractValue VisitInterpolatedString(IInterpolatedStringOperation operation, object argument)
            {
                if (operation.Parts.IsEmpty)
                {
                    return(StringContentAbstractValue.Create(string.Empty));
                }

                StringContentAbstractValue mergedValue = Visit(operation.Parts[0], argument);

                for (int i = 1; i < operation.Parts.Length; i++)
                {
                    var newValue = Visit(operation.Parts[i], argument);
                    mergedValue = mergedValue.MergeBinaryAdd(newValue);
                }

                return(mergedValue);
            }
Exemple #5
0
            public override PointsToAbstractValue VisitInterpolatedString(IInterpolatedStringOperation operation, object argument)
            {
                var _ = base.VisitInterpolatedString(operation, argument);

                return(PointsToAbstractValue.NoLocation);
            }
            public override NullAbstractValue VisitInterpolatedString(IInterpolatedStringOperation operation, object argument)
            {
                var _ = base.VisitInterpolatedString(operation, argument);

                return(NullAbstractValue.NotNull);
            }
Exemple #7
0
 public override IOperation VisitInterpolatedString(IInterpolatedStringOperation operation, object argument)
 {
     return(new InterpolatedStringExpression(VisitArray(operation.Parts), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
 public override void VisitInterpolatedString(IInterpolatedStringOperation operation)
 {
     Assert.Equal(OperationKind.InterpolatedString, operation.Kind);
     AssertEx.Equal(operation.Parts, operation.Children);
 }
Exemple #9
0
 public virtual void VisitInterpolatedString(IInterpolatedStringOperation operation)
 {
     DefaultVisit(operation);
 }
Exemple #10
0
 public override void VisitInterpolatedString([NotNull] IInterpolatedStringOperation operation)
 {
     base.VisitInterpolatedString(operation);
 }
Exemple #11
0
 public override Scope VisitInterpolatedString(IInterpolatedStringOperation operation, Scope currentScope)
 {
     return(operation.Parts.Aggregate(currentScope, (scope, part) => part.Accept(this, scope)));
 }
Exemple #12
0
 public override bool VisitInterpolatedString([NotNull] IInterpolatedStringOperation operation1,
                                              [CanBeNull] IOperation argument)
 {
     return(argument is IInterpolatedStringOperation operation2 && AreBaseOperationsEqual(operation1, operation2));
 }