本文整理汇总了C#中ObjectCreationExpressionSyntax.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectCreationExpressionSyntax.ToString方法的具体用法?C# ObjectCreationExpressionSyntax.ToString怎么用?C# ObjectCreationExpressionSyntax.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectCreationExpressionSyntax
的用法示例。
在下文中一共展示了ObjectCreationExpressionSyntax.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetectGivenUpFieldOwnershipInObjectCreation
/// <summary>
/// Analyses the summary of the given object creation 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="model">SemanticModel</param>
/// <param name="log">Log</param>
/// <returns>Set of return symbols</returns>
private HashSet<ISymbol> DetectGivenUpFieldOwnershipInObjectCreation(ObjectCreationExpressionSyntax call,
ISymbol target, SyntaxNode syntaxNode, ControlFlowGraphNode cfgNode, SyntaxNode givesUpSyntaxNode,
ControlFlowGraphNode givesUpCfgNode, 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 == null)
{
if (call.ArgumentList != null && call.ArgumentList.Arguments.Count > 0)
{
AnalysisErrorReporter.ReportUnknownInvocation(callLog);
}
return new HashSet<ISymbol>();
}
var definition = SymbolFinder.FindSourceDefinitionAsync(callSymbol,
this.AnalysisContext.Solution).Result;
if (definition == null || definition.DeclaringSyntaxReferences.IsEmpty)
{
if (call.ArgumentList != null && call.ArgumentList.Arguments.Count > 0)
{
AnalysisErrorReporter.ReportUnknownInvocation(callLog);
}
return new HashSet<ISymbol>();
}
var constructorCall = definition.DeclaringSyntaxReferences.First().GetSyntax()
as ConstructorDeclarationSyntax;
var constructorSummary = MethodSummary.Factory.Summarize(this.AnalysisContext, constructorCall);
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 (constructorSummary.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);
}
}
}
return constructorSummary.GetResolvedReturnSymbols(call.ArgumentList, model);
}
示例2: DetectPotentialDataRaceInObjectCreation
/// <summary>
/// Analyses the summary of the given object creation 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="model">SemanticModel</param>
/// <param name="log">Log</param>
private void DetectPotentialDataRaceInObjectCreation(ObjectCreationExpressionSyntax call,
ISymbol target, SyntaxNode syntaxNode, ControlFlowGraphNode cfgNode, SyntaxNode givesUpSyntaxNode,
ControlFlowGraphNode givesUpCfgNode, 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;
var definition = SymbolFinder.FindSourceDefinitionAsync(callSymbol,
this.AnalysisContext.Solution).Result;
if (definition == null || definition.DeclaringSyntaxReferences.IsEmpty)
{
AnalysisErrorReporter.ReportUnknownInvocation(callLog);
return;
}
var constructorCall = definition.DeclaringSyntaxReferences.First().GetSyntax()
as ConstructorDeclarationSyntax;
var constructorSummary = MethodSummary.Factory.Summarize(this.AnalysisContext, constructorCall);
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))
{
if (constructorSummary.AccessSet.ContainsKey(idx))
{
foreach (var access in constructorSummary.AccessSet[idx])
{
Log newLog = new Log();
newLog.Merge(callLog);
newLog.AddTrace(access.ToString(), access.SyntaxTree.FilePath, access.SyntaxTree.
GetLineSpan(access.Span).StartLinePosition.Line + 1);
AnalysisErrorReporter.ReportPotentialDataRace(newLog);
}
}
if (constructorSummary.SideEffects.Any(
v => v.Value.Contains(idx) &&
this.AnalysisContext.DoesFieldBelongToMachine(v.Key, cfgNode.Summary)))
{
AnalysisErrorReporter.ReportGivenUpOwnershipFieldAssignment(callLog);
}
if (constructorSummary.GivesUpSet.Contains(idx))
{
AnalysisErrorReporter.ReportGivenUpOwnershipSending(callLog);
}
}
}
foreach (var fieldAccess in constructorSummary.FieldAccessSet)
{
if (DataFlowAnalysis.FlowsFromTarget(fieldAccess.Key, target, syntaxNode,
cfgNode, givesUpSyntaxNode, givesUpCfgNode))
{
foreach (var access in fieldAccess.Value)
{
Log newLog = new Log();
newLog.Merge(callLog);
newLog.AddTrace(access.ToString(), access.SyntaxTree.FilePath, access.SyntaxTree.
GetLineSpan(access.Span).StartLinePosition.Line + 1);
AnalysisErrorReporter.ReportPotentialDataRace(newLog);
}
}
}
}