当前位置: 首页>>代码示例>>C#>>正文


C# InvocationExpressionSyntax.ToString方法代码示例

本文整理汇总了C#中InvocationExpressionSyntax.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpressionSyntax.ToString方法的具体用法?C# InvocationExpressionSyntax.ToString怎么用?C# InvocationExpressionSyntax.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InvocationExpressionSyntax的用法示例。


在下文中一共展示了InvocationExpressionSyntax.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitInvocationExpression

        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            //Logger.Trace("Visiting invocation: {0}", node);

            if (node == null) throw new ArgumentNullException("node");

            if (!node.ToString().Contains("Begin"))
                return node;

            //Logger.Debug("Found potential Begin method: {0} at {1}:{2}",
            //    node,
            //    node.SyntaxTree.FilePath,
            //    node.GetStartLineNumber()
            //);

            MethodSymbol method;
            try
            {
                method = _model.LookupMethodSymbol(node);
            }
            catch (SymbolMissingException e)
            {
                //Logger.Trace("Symbol missing for invocation: {0} @ {1}:{2}: {3}",
                //    node,
                //    node.SyntaxTree.FilePath,
                //    node.GetStartLineNumber(),
                //    e.Message
                //);

                return node;
            }

            if (method.IsAPMBeginMethod())
            {
                //Logger.Info("Found APM Begin method invocation, annotating it: @ {0}:{1}",
                //    node.SyntaxTree.FilePath,
                //    node.GetStartLineNumber()
                //);
                //Logger.Trace("Actual code @ {0}:{1}:\n{2}",
                //    node.SyntaxTree.FilePath,
                //    node.GetStartLineNumber(),
                //    node
                //);

                var annotation = new RefactorableAPMInstance(NumAnnotations++);

                return base
                    .VisitInvocationExpression(node)
                    .WithAdditionalAnnotations(
                        annotation
                    );
            }

            return base.VisitInvocationExpression(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:55,代码来源:APMBeginInvocationAnnotater.cs

示例2: SimpleMethodName

 public static string SimpleMethodName(InvocationExpressionSyntax expr)
 {
     if (expr.Expression is IdentifierNameSyntax)
       {
     return expr.Expression.ToString();
       }
       else if (expr.Expression is MemberAccessExpressionSyntax)
       {
     return ((MemberAccessExpressionSyntax)expr.Expression).Name.ToString();
       }
       else if (expr.Expression is GenericNameSyntax)
       {
     return expr.Expression.ToString();
       }
       else
       {
     throw new Exception(string.Format("Unexpected method invocation node: {0}", expr.ToString()));
       }
 }
开发者ID:twschiller,项目名称:contract-classifier,代码行数:19,代码来源:CodeContractCollector.cs

示例3: VisitInvocationExpression

 public override void VisitInvocationExpression(InvocationExpressionSyntax node)
 {
     cb.Append(node.ToString());
 }
开发者ID:ActiveMesa,项目名称:Blackmire,代码行数:4,代码来源:CppImplWalker.cs

示例4: DetectGivenUpFieldOwnershipInInvocation

        /// <summary>
        /// Analyses the summary of the given invocation to find if it gives up ownership
        /// of data from a machine field.
        /// </summary>
        /// <param name="call">Call</param>
        /// <param name="target">Target</param>
        /// <param name="syntaxNode">SyntaxNode</param>
        /// <param name="cfgNode">ControlFlowGraphNode</param>
        /// <param name="givesUpSyntaxNode">Gives up syntaxNode</param>
        /// <param name="givesUpCfgNode">Gives up controlFlowGraphNode</param>
        /// <param name="originalMachine">Original machine</param>
        /// <param name="model">SemanticModel</param>
        /// <param name="log">Log</param>
        /// <returns>Set of return symbols</returns>
        private HashSet<ISymbol> DetectGivenUpFieldOwnershipInInvocation(InvocationExpressionSyntax call,
            ISymbol target, SyntaxNode syntaxNode, ControlFlowGraphNode cfgNode, SyntaxNode givesUpSyntaxNode,
            ControlFlowGraphNode givesUpCfgNode, ClassDeclarationSyntax originalMachine, SemanticModel model,
            Log log)
        {
            Log callLog = new Log();
            callLog.Merge(log);
            callLog.AddTrace(call.ToString(), call.SyntaxTree.FilePath, call.SyntaxTree.
                GetLineSpan(call.Span).StartLinePosition.Line + 1);

            var callSymbol = model.GetSymbolInfo(call).Symbol;
            if (callSymbol.ContainingType.ToString().Equals("Microsoft.PSharp.Machine") ||
                callSymbol.ContainingType.ToString().Equals("Microsoft.PSharp.MachineState"))
            {
                return new HashSet<ISymbol>();
            }

            var definition = SymbolFinder.FindSourceDefinitionAsync(callSymbol,
                this.AnalysisContext.Solution).Result;
            if (definition == null || definition.DeclaringSyntaxReferences.IsEmpty)
            {
                AnalysisErrorReporter.ReportUnknownInvocation(callLog);
                return new HashSet<ISymbol>();
            }

            HashSet<MethodDeclarationSyntax> potentialCalls = new HashSet<MethodDeclarationSyntax>();
            var invocationCall = definition.DeclaringSyntaxReferences.First().GetSyntax()
                as MethodDeclarationSyntax;
            if ((invocationCall.Modifiers.Any(SyntaxKind.AbstractKeyword) &&
                !originalMachine.Modifiers.Any(SyntaxKind.AbstractKeyword)) ||
                invocationCall.Modifiers.Any(SyntaxKind.VirtualKeyword) ||
                invocationCall.Modifiers.Any(SyntaxKind.OverrideKeyword))
            {
                HashSet<MethodDeclarationSyntax> overriders = null;
                if (!InheritanceAnalysis.TryGetPotentialMethodOverriders(out overriders,
                    call, syntaxNode, cfgNode, originalMachine, model, this.AnalysisContext))
                {
                    AnalysisErrorReporter.ReportUnknownVirtualCall(callLog);
                }

                foreach (var overrider in overriders)
                {
                    potentialCalls.Add(overrider);
                }
            }

            if (potentialCalls.Count == 0)
            {
                potentialCalls.Add(invocationCall);
            }

            HashSet<ISymbol> potentialReturnSymbols = new HashSet<ISymbol>();
            foreach (var potentialCall in potentialCalls)
            {
                var invocationSummary = MethodSummary.Factory.Summarize(this.AnalysisContext, potentialCall);
                var arguments = call.ArgumentList.Arguments;

                for (int idx = 0; idx < arguments.Count; idx++)
                {
                    if (DataFlowAnalysis.FlowsIntoTarget(arguments[idx].Expression, target,
                        syntaxNode, cfgNode, givesUpSyntaxNode, givesUpCfgNode,
                        model, this.AnalysisContext))
                    {
                        if (invocationSummary.SideEffects.Any(
                            v => v.Value.Contains(idx) &&
                            this.AnalysisContext.DoesFieldBelongToMachine(v.Key, cfgNode.Summary) &&
                            FieldUsageAnalysis.IsAccessedBeforeBeingReset(v.Key,
                            cfgNode.Summary, this.AnalysisContext)))
                        {
                            AnalysisErrorReporter.ReportGivenUpFieldOwnershipError(callLog);
                        }
                    }
                }

                var resolvedReturnSymbols = invocationSummary.GetResolvedReturnSymbols(
                    call.ArgumentList, model);
                foreach (var rrs in resolvedReturnSymbols)
                {
                    potentialReturnSymbols.Add(rrs);
                }
            }

            return potentialReturnSymbols;
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:98,代码来源:RespectsOwnershipAnalysis.cs

示例5: AnalyseArgumentSyntax

        /// <summary>
        /// Analyse the given argument to see if it respects the given up ownerships.
        /// </summary>
        /// <param name="arg">Argument</param>
        /// <param name="call">Call</param>
        /// <param name="givesUpNode">Gives up node</param>
        /// <param name="machine">Machine</param>
        /// <param name="state">State</param>
        /// <param name="originalMachine">Original machine</param>
        private void AnalyseArgumentSyntax(ExpressionSyntax arg, InvocationExpressionSyntax call,
            ControlFlowGraphNode givesUpNode, ClassDeclarationSyntax machine, ClassDeclarationSyntax state,
            ClassDeclarationSyntax originalMachine)
        {
            var model = this.AnalysisContext.Compilation.GetSemanticModel(arg.SyntaxTree);
            
            if (arg is MemberAccessExpressionSyntax || arg is IdentifierNameSyntax)
            {
                Log log = new Log(givesUpNode.Summary.Method as MethodDeclarationSyntax, machine, state, arg);
                log.AddTrace(call.ToString(), call.SyntaxTree.FilePath, call.SyntaxTree.
                    GetLineSpan(call.Span).StartLinePosition.Line + 1);

                if (this.IsArgumentSafeToAccess(arg, givesUpNode, model, log, true))
                {
                    return;
                }
                
                ISymbol argSymbol = null;
                if (arg is IdentifierNameSyntax)
                {
                    argSymbol = model.GetSymbolInfo(arg as IdentifierNameSyntax).Symbol;
                }
                else if (arg is MemberAccessExpressionSyntax)
                {
                    argSymbol = model.GetSymbolInfo((arg as MemberAccessExpressionSyntax).Name).Symbol;
                }
                
                this.DetectGivenUpFieldOwnershipInControlFlowGraph(givesUpNode,
                    givesUpNode, argSymbol, call, new HashSet<ControlFlowGraphNode>(),
                    originalMachine, model, log);
                this.DetectPotentialDataRacesInControlFlowGraph(givesUpNode,
                    givesUpNode, argSymbol, call, new HashSet<ControlFlowGraphNode>(),
                    originalMachine, model, log);

                var aliases = DataFlowAnalysis.GetAliases(argSymbol, givesUpNode.SyntaxNodes.First(), givesUpNode);
                foreach (var alias in aliases)
                {
                    log.Payload = alias.Name;
                    this.DetectGivenUpFieldOwnershipInControlFlowGraph(givesUpNode,
                        givesUpNode, alias, call, new HashSet<ControlFlowGraphNode>(),
                        originalMachine, model, log);
                    this.DetectPotentialDataRacesInControlFlowGraph(givesUpNode,
                        givesUpNode, alias, call, new HashSet<ControlFlowGraphNode>(),
                        originalMachine, model, log);
                }
            }
            else if (arg is ObjectCreationExpressionSyntax)
            {
                var payload = arg as ObjectCreationExpressionSyntax;
                foreach (var item in payload.ArgumentList.Arguments)
                {
                    this.AnalyseArgumentSyntax(item.Expression,
                        call, givesUpNode, machine, state, originalMachine);
                }
            }
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:65,代码来源:RespectsOwnershipAnalysis.cs

示例6: DetectPotentialDataRaceInInvocation

        /// <summary>
        /// Analyses the summary of the given invocation to find if it respects the
        /// given up ownerships and reports any potential data races.
        /// </summary>
        /// <param name="invocation">Invocation</param>
        /// <param name="target">Target</param>
        /// <param name="syntaxNode">SyntaxNode</param>
        /// <param name="cfgNode">ControlFlowGraphNode</param>
        /// <param name="givesUpSyntaxNode">Gives up syntaxNode</param>
        /// <param name="givesUpCfgNode">Gives up controlFlowGraphNode</param>
        /// <param name="originalMachine">Original machine</param>
        /// <param name="model">SemanticModel</param>
        /// <param name="log">Log</param>
        private void DetectPotentialDataRaceInInvocation(InvocationExpressionSyntax call,
            ISymbol target, SyntaxNode syntaxNode, ControlFlowGraphNode cfgNode, SyntaxNode givesUpSyntaxNode,
            ControlFlowGraphNode givesUpCfgNode, ClassDeclarationSyntax originalMachine, SemanticModel model,
            Log log)
        {
            Log callLog = new Log();
            callLog.Merge(log);
            callLog.AddTrace(call.ToString(), call.SyntaxTree.FilePath, call.SyntaxTree.
                GetLineSpan(call.Span).StartLinePosition.Line + 1);
            
            var callSymbol = model.GetSymbolInfo(call).Symbol;
            if (callSymbol.ContainingType.ToString().Equals("Microsoft.PSharp.Machine") ||
                callSymbol.ContainingType.ToString().Equals("Microsoft.PSharp.MachineState"))
            {
                this.DetectPotentialDataRaceInGivesUpOperation(call, target,
                    syntaxNode, cfgNode, givesUpSyntaxNode, givesUpCfgNode, model, callLog);
                return;
            }
            
            var definition = SymbolFinder.FindSourceDefinitionAsync(callSymbol,
                this.AnalysisContext.Solution).Result;
            if (definition == null || definition.DeclaringSyntaxReferences.IsEmpty)
            {
                if (call.Expression is MemberAccessExpressionSyntax)
                {
                    var callee = (call.Expression as MemberAccessExpressionSyntax).Expression;
                    if (DataFlowAnalysis.FlowsFromTarget(callee, target, syntaxNode, cfgNode,
                        givesUpSyntaxNode, givesUpCfgNode, model, this.AnalysisContext) &&
                        !DataFlowAnalysis.DoesResetInLoop(callee, syntaxNode, cfgNode,
                        givesUpSyntaxNode, givesUpCfgNode, model, this.AnalysisContext))
                    {
                        var typeSymbol = model.GetTypeInfo(callee).Type;
                        if (typeSymbol.ContainingNamespace.ToString().Equals("System.Collections.Generic"))
                        {
                            Log newLog = new Log();
                            newLog.Merge(callLog);
                            newLog.AddTrace(callee.ToString(), callee.SyntaxTree.FilePath, callee.SyntaxTree.
                                GetLineSpan(callee.Span).StartLinePosition.Line + 1);
                            AnalysisErrorReporter.ReportPotentialDataRace(newLog);
                            return;
                        }
                    }
                }

                AnalysisErrorReporter.ReportUnknownInvocation(callLog);
                return;
            }

            HashSet<MethodDeclarationSyntax> potentialCalls = new HashSet<MethodDeclarationSyntax>();
            var invocationCall = definition.DeclaringSyntaxReferences.First().GetSyntax()
                as MethodDeclarationSyntax;
            if ((invocationCall.Modifiers.Any(SyntaxKind.AbstractKeyword) &&
                !originalMachine.Modifiers.Any(SyntaxKind.AbstractKeyword)) ||
                invocationCall.Modifiers.Any(SyntaxKind.VirtualKeyword) ||
                invocationCall.Modifiers.Any(SyntaxKind.OverrideKeyword))
            {
                HashSet<MethodDeclarationSyntax> overriders = null;
                if (!InheritanceAnalysis.TryGetPotentialMethodOverriders(out overriders,
                    call, syntaxNode, cfgNode, originalMachine, model, this.AnalysisContext))
                {
                    AnalysisErrorReporter.ReportUnknownVirtualCall(callLog);
                }

                foreach (var overrider in overriders)
                {
                    potentialCalls.Add(overrider);
                }
            }

            if (potentialCalls.Count == 0)
            {
                potentialCalls.Add(invocationCall);
            }

            foreach (var potentialCall in potentialCalls)
            {
                var invocationSummary = MethodSummary.Factory.Summarize(this.AnalysisContext, potentialCall);
                var arguments = call.ArgumentList.Arguments;

                for (int idx = 0; idx < arguments.Count; idx++)
                {
                    if (!this.AnalysisContext.IsExprEnum(arguments[idx].Expression, model) &&
                        DataFlowAnalysis.FlowsFromTarget(arguments[idx].Expression, target, syntaxNode,
                        cfgNode, givesUpSyntaxNode, givesUpCfgNode, model, this.AnalysisContext) &&
                        !DataFlowAnalysis.DoesResetInLoop(arguments[idx].Expression, syntaxNode, cfgNode,
                        givesUpSyntaxNode, givesUpCfgNode, model, this.AnalysisContext))
                    {
//.........这里部分代码省略.........
开发者ID:huangpf,项目名称:PSharp,代码行数:101,代码来源:RespectsOwnershipAnalysis.cs


注:本文中的InvocationExpressionSyntax.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。