/// <summary> /// Run analysis starting at EntryMethodGraph /// </summary> private void analyse() { EntryInput.CommitTransaction(); ProgramPointGraph = ProgramPointGraph.FromSource(EntryCFG); _services.SetProgramEnd(ProgramPointGraph.End); _services.SetServices(ProgramPointGraph); var output = _services.CreateEmptySet(); ProgramPointGraph.Start.Initialize(EntryInput, output); _services.EnqueueEntryPoint(ProgramPointGraph.Start, ProgramPointGraph.End); //fix point computation while (_workList.HasWork) { var point = _workList.GetWork(); //during flow through are enqueued all needed flow children point.FlowThrough(); } //because of avoid incorrect use //_services.UnSetServices(ProgramPointGraph); }
/// <summary> /// Set services for all points in given graph /// </summary> /// <param name="ppGraph">Graph which program points will be set</param> internal void SetServices(ProgramPointGraph ppGraph) { foreach (var point in ppGraph.Points) { SetServices(point); } }
/// <summary> /// Unset services for all points in given graph /// </summary> /// <param name="ppGraph">Graph which program points will be unset</param> internal void UnSetServices(ProgramPointGraph ppGraph) { foreach (var point in ppGraph.Points) { point.SetServices(null); } }
/// <summary> /// Initializes a new instance of the <see cref="ForwardAnalysisBase" /> class. /// Create forward analysis object for given entry method graph. /// </summary> /// <param name="analyzedPPG">The analyzed PPG.</param> /// <param name="direction">The direction of analysis.</param> /// <param name="analyzer">The analyzer.</param> public NextPhaseAnalysis(ProgramPointGraph analyzedPPG, AnalysisDirection direction, NextPhaseAnalyzer analyzer) { _analyzer = analyzer; Direction = direction; AnalyzedProgramPointGraph = analyzedPPG; WideningLimit = int.MaxValue; }
internal ProgramPointBase GetExitPoint(ProgramPointGraph ppg) { switch (Direction) { case AnalysisDirection.Forward: return(ppg.End); case AnalysisDirection.Backward: return(ppg.Start); default: throwUnknownDirection(); return(null); } }
private void resetPoints(HashSet <ProgramPointGraph> processedGraphs, ProgramPointGraph ppg) { processedGraphs.Add(ppg); foreach (var point in ppg.Points) { point.ResetInitialization(); foreach (var branch in point.Extension.Branches) { branch.ResetInitialization(); point.Extension.Sink.ResetInitialization(); if (!processedGraphs.Contains(branch.Graph)) { resetPoints(processedGraphs, branch.Graph); } } } }
/// <summary> /// Add extension branch indexed by given key /// </summary> /// <param name="key">Key of added extension</param> /// <param name="ppGraph">Extending program point graph</param> /// <param name="type">Type of extension</param> /// <returns>Extension point which connect extending ppGraph with Owner</returns> internal ExtensionPoint Add(object key, ProgramPointGraph ppGraph, ExtensionType type) { if (!IsConnected) { connect(); } ppGraph.Context._callers.Add(Owner); Owner.Services.SetServices(ppGraph); var extension = new ExtensionPoint(Owner, ppGraph, type); Owner.Services.SetServices(extension); _extensions.Add(key, extension); //connect ppGraph into current graph Owner.AddFlowChild(extension); extension.Graph.End.AddFlowChild(Sink); return(extension); }
public override void VisitNativeAnalyzerValue(NativeAnalyzerValue value) { Output = ProgramPointGraph.FromNative(value.Analyzer); }
public override void VisitSourceMethodValue(SourceMethodValue value) { Output = ProgramPointGraph.FromSource(value.Declaration, value.DeclaringScript); }
internal void InitializeNewPoint(ProgramPointBase point, ProgramPointGraph owningGraph) { point.Initialize(Services.CreateEmptySet(), Services.CreateEmptySet()); point.SetServices(Services); point.SetOwningGraph(owningGraph); }
/// <summary> /// Add extension branch into Point /// </summary> /// <param name="branchKey">Key of added branch</param> /// <param name="ppGraph">Extending program point used as branch</param> /// <param name="type">Type of extension</param> public void AddExtension(object branchKey, ProgramPointGraph ppGraph, ExtensionType type) { CurrentProgramPoint.Extension.Add(branchKey, ppGraph, type); }
/// <summary> /// Extend snapshot as a call to function/method callee from given callerContext /// </summary> /// <param name="callerContext">The caller context.</param> /// <param name="callee">Program point graph of the callee (identification of function or method that was called).</param> /// <param name="thisObject">The this object.</param> /// <param name="arguments">The arguments.</param> internal void ExtendAsCall(FlowOutputSet callerContext, ProgramPointGraph callee, MemoryEntry thisObject, MemoryEntry[] arguments) { Snapshot.ExtendAsCall(getSnapshot(callerContext), callee, thisObject, arguments); }
/// <summary> /// Creates program point graph for given control flow graph /// </summary> /// <param name="cfg">Input control flow graph</param> /// <returns>Created program point graph</returns> public static ProgramPointGraph FromSource(ControlFlowGraph.ControlFlowGraph cfg) { var ppgraph = new ProgramPointGraph(cfg, null); return(ppgraph); }
internal PPGraphContext(ProgramPointGraph owningPPGraph) { OwningPPGraph = owningPPGraph; }
internal void SetOwningGraph(ProgramPointGraph owningGraph) { this.OwningPPGraph = owningGraph; this.Extension.Sink.OwningPPGraph = owningGraph; }
/// <summary> /// Creates context that will be used by owningPPG to build itself /// </summary> /// <param name="owningPPG">Program point graph using context to build itself</param> internal PPGraphBuildingContext(ProgramPointGraph owningPPG) { _owningPPG = owningPPG; }