protected override bool AnalyzeNode(ICSharpArgument navigated, ICSharpExpression from)
        {
            var invocationExpression = InvocationExpressionNavigator.GetByArgument(navigated);

            if (invocationExpression != null)
            {
                var callee = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

                if (BurstCodeAnalysisUtil.IsBurstPossibleArgumentString(navigated) &&
                    callee != null &&
                    (BurstCodeAnalysisUtil.IsDebugLog(callee) ||
                     BurstCodeAnalysisUtil.IsStringFormat(callee)))
                {
                    return(false);
                }
            }


            return(true);
        }
Ejemplo n.º 2
0
        public static bool CheckAndAnalyze(ITreeNode node, IHighlighting highlighting, IHighlightingConsumer consumer)
        {
            var firstNode = node;

            do
            {
                var parent = node.Parent;

                if (parent is IExpressionInitializer expressionInitializer)
                {
                    if (ReferenceEquals(expressionInitializer.Value, firstNode))
                    {
                        do
                        {
                            node   = parent;
                            parent = node.Parent;
                        } while (parent != null && !(parent is IInitializerOwnerDeclaration));

                        if (parent == null)
                        {
                            return(true);
                        }

                        var initializerOwnerDeclaration = (IInitializerOwnerDeclaration)parent;
                        if (ReferenceEquals(initializerOwnerDeclaration.Initializer, expressionInitializer))
                        {
                            var typeOwner = initializerOwnerDeclaration.DeclaredElement as ITypeOwner;
                            var type      = typeOwner?.Type;
                            if (BurstCodeAnalysisUtil.IsFixedString(type))
                            {
                                return(false);
                            }
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                if (parent is ICSharpArgument cSharpArgument)
                {
                    var invocationInfo = cSharpArgument.Invocation;
                    if (invocationInfo is IInvocationExpression info)
                    {
                        var callee = CallGraphUtil.GetCallee(info) as IMethod;

                        if (BurstCodeAnalysisUtil.IsBurstPermittedString(cSharpArgument.GetExpressionType().ToIType()) &&
                            callee != null &&
                            (BurstCodeAnalysisUtil.IsDebugLog(callee) ||
                             BurstCodeAnalysisUtil.IsStringFormat(callee)))
                        {
                            return(false);
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                if (parent is IAssignmentExpression assignmentExpression)
                {
                    if (assignmentExpression.Dest == node)
                    {
                        return(false);
                    }

                    if (BurstCodeAnalysisUtil.IsFixedString(assignmentExpression.Dest.Type()) &&
                        assignmentExpression.Source.Type().IsString())
                    {
                        return(false);
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                if (parent is ITypeMemberDeclaration)
                {
                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                node = parent;
            } while (node != null);

            consumer?.AddHighlighting(highlighting);
            return(true);
        }
Ejemplo n.º 3
0
        public static bool CheckAndAnalyze(ICSharpExpression startNode, IHighlighting highlighting,
                                           IHighlightingConsumer consumer)
        {
            var firstNode = startNode;

            do
            {
                var parent = startNode.Parent;

                switch (parent)
                {
                case IExpressionInitializer expressionInitializer:
                {
                    if (ReferenceEquals(expressionInitializer.Value, firstNode))
                    {
                        do
                        {
                            parent = parent.Parent;
                        } while (parent != null && !(parent is IInitializerOwnerDeclaration));

                        if (parent == null)
                        {
                            return(true);
                        }

                        var initializerOwnerDeclaration = (IInitializerOwnerDeclaration)parent;

                        if (ReferenceEquals(initializerOwnerDeclaration.Initializer, expressionInitializer))
                        {
                            var typeOwner = initializerOwnerDeclaration.DeclaredElement as ITypeOwner;
                            var type      = typeOwner?.Type;

                            if (BurstCodeAnalysisUtil.IsFixedString(type))
                            {
                                return(false);
                            }
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                case ICSharpArgument cSharpArgument:
                {
                    var invocationInfo = cSharpArgument.Invocation;

                    if (invocationInfo is IInvocationExpression invocationExpression)
                    {
                        var callee = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

                        if (BurstCodeAnalysisUtil.IsBurstPossibleArgumentString(cSharpArgument) &&
                            callee != null &&
                            (BurstCodeAnalysisUtil.IsDebugLog(callee) ||
                             BurstCodeAnalysisUtil.IsStringFormat(callee)))
                        {
                            return(false);
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                case IAssignmentExpression assignmentExpression
                    when assignmentExpression.Dest == startNode ||
                    BurstCodeAnalysisUtil.IsFixedString(assignmentExpression.Dest.Type()) &&
                    assignmentExpression.Source.Type().IsString():
                    return(false);

                case IAssignmentExpression _:
                case ITypeMemberDeclaration _:
                    consumer?.AddHighlighting(highlighting);
                    return(true);

                case ICSharpExpression expression:
                    startNode = expression;
                    break;

                default:
                    startNode = null;
                    break;
                }
            } while (startNode != null);

            consumer?.AddHighlighting(highlighting);
            return(true);
        }