Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::CFLSolver Class Reference

#include <CFLSolver.h>

Inheritance diagram for SVF::CFLSolver:
SVF::POCRSolver SVF::POCRHybridSolver

Public Types

typedef FIFOWorkList< const CFLEdge * > WorkList
 Define worklist.
typedef CFGrammar::Production Production
typedef CFGrammar::Symbol Symbol

Public Member Functions

 CFLSolver (CFLGraph *_graph, CFGrammar *_grammar)
virtual ~CFLSolver ()
virtual void initialize ()
 Initialize worklist.
virtual void processCFLEdge (const CFLEdge *Y_edge)
 Process CFLEdge.
virtual void solve ()
 Start solving.
const CFLGraph * getGraph () const
 Return CFL Graph.
const CFGrammar * getGrammar () const
 Return CFL Grammar.
virtual bool pushIntoWorklist (const CFLEdge *item)
virtual bool isWorklistEmpty ()

Static Public Attributes

static double numOfChecks = 0

Protected Member Functions

const CFLEdge * popFromWorklist ()
 Worklist operations.
bool isInWorklist (const CFLEdge *item)

Protected Attributes

CFLGraph * graph
CFGrammar * grammar
WorkList worklist
 Worklist for resolution.

Detailed Description

Definition at line 44 of file CFLSolver.h.

Member Typedef Documentation

◆ Production

Definition at line 50 of file CFLSolver.h.

◆ Symbol

Definition at line 51 of file CFLSolver.h.

◆ WorkList

Define worklist.

Definition at line 49 of file CFLSolver.h.

Constructor & Destructor Documentation

◆ CFLSolver()

SVF::CFLSolver::CFLSolver ( CFLGraph * _graph,
CFGrammar * _grammar )
inline

Definition at line 55 of file CFLSolver.h.

55 : graph(_graph), grammar(_grammar)
56 {
57 }
CFGrammar * grammar
Definition CFLSolver.h:110
CFLGraph * graph
Definition CFLSolver.h:109

◆ ~CFLSolver()

virtual SVF::CFLSolver::~CFLSolver ( )
inlinevirtual

Definition at line 59 of file CFLSolver.h.

60 {
61 delete graph;
62 delete grammar;
63 }

Member Function Documentation

◆ getGrammar()

const CFGrammar * SVF::CFLSolver::getGrammar ( ) const
inline

Return CFL Grammar.

Definition at line 81 of file CFLSolver.h.

82 {
83 return grammar;
84 }

◆ getGraph()

const CFLGraph * SVF::CFLSolver::getGraph ( ) const
inline

Return CFL Graph.

Definition at line 75 of file CFLSolver.h.

76 {
77 return graph;
78 }

◆ initialize()

void CFLSolver::initialize ( )
virtual

Initialize worklist.

Foreach production X -> epsilon add X(i,i) if not exist to E and to worklist

Reimplemented in SVF::POCRHybridSolver, and SVF::POCRSolver.

Definition at line 36 of file CFLSolver.cpp.

37{
38 for(auto it = graph->begin(); it!= graph->end(); it++)
39 {
40 for(const CFLEdge* edge : (*it).second->getOutEdges())
41 {
42 pushIntoWorklist(edge);
43 }
44 }
45
48 for(const Production& prod : grammar->getEpsilonProds())
49 {
50 for(auto it = graph->begin(); it!= graph->end(); it++)
51 {
52 Symbol X = grammar->getLHSSymbol(prod);
53 CFLNode* i = (*it).second;
54 if(const CFLEdge* edge = graph->addCFLEdge(i, i, X))
55 {
56 pushIntoWorklist(edge);
57 }
58 }
59 }
60}
CFGrammar::Production Production
Definition CFLSolver.h:50
CFGrammar::Symbol Symbol
Definition CFLSolver.h:51
virtual bool pushIntoWorklist(const CFLEdge *item)
Definition CFLSolver.h:85

◆ isInWorklist()

bool SVF::CFLSolver::isInWorklist ( const CFLEdge * item)
inlineprotected

Definition at line 102 of file CFLSolver.h.

103 {
104 return worklist.find(item);
105 }
cJSON * item
Definition cJSON.h:222
WorkList worklist
Worklist for resolution.
Definition CFLSolver.h:112

◆ isWorklistEmpty()

virtual bool SVF::CFLSolver::isWorklistEmpty ( )
inlinevirtual

Definition at line 89 of file CFLSolver.h.

90 {
91 return worklist.empty();
92 }

◆ popFromWorklist()

const CFLEdge * SVF::CFLSolver::popFromWorklist ( )
inlineprotected

Worklist operations.

Definition at line 97 of file CFLSolver.h.

98 {
99 return worklist.pop();
100 }

◆ processCFLEdge()

void CFLSolver::processCFLEdge ( const CFLEdge * Y_edge)
virtual

Process CFLEdge.

For each production X -> Y add X(i,j) if not exist to E and to worklist

For each production X -> Y Z Foreach outgoing edge Z(j,k) from node j do add X(i,k) if not exist to E and to worklist

For each production X -> Z Y Foreach incoming edge Z(k,i) to node i do add X(k,j) if not exist to E and to worklist

Reimplemented in SVF::POCRHybridSolver, and SVF::POCRSolver.

Definition at line 62 of file CFLSolver.cpp.

63{
64 CFLNode* i = Y_edge->getSrcNode();
65 CFLNode* j = Y_edge->getDstNode();
66
69 Symbol Y = Y_edge->getEdgeKind();
70 if (grammar->hasProdsFromSingleRHS(Y))
71 for(const Production& prod : grammar->getProdsFromSingleRHS(Y))
72 {
73 Symbol X = grammar->getLHSSymbol(prod);
75 if(const CFLEdge* newEdge = graph->addCFLEdge(i, j, X))
76 {
77 pushIntoWorklist(newEdge);
78 }
79 }
80
84 if (grammar->hasProdsFromFirstRHS(Y))
85 for(const Production& prod : grammar->getProdsFromFirstRHS(Y))
86 {
87 Symbol X = grammar->getLHSSymbol(prod);
88 for(const CFLEdge* Z_edge : j->getOutEdgeWithTy(grammar->getSecondRHSSymbol(prod)))
89 {
90 CFLNode* k = Z_edge->getDstNode();
92 if(const CFLEdge* newEdge = graph->addCFLEdge(i, k, X))
93 {
94 pushIntoWorklist(newEdge);
95 }
96 }
97 }
98
102 if(grammar->hasProdsFromSecondRHS(Y))
103 for(const Production& prod : grammar->getProdsFromSecondRHS(Y))
104 {
105 Symbol X = grammar->getLHSSymbol(prod);
106 for(const CFLEdge* Z_edge : i->getInEdgeWithTy(grammar->getFirstRHSSymbol(prod)))
107 {
108 CFLNode* k = Z_edge->getSrcNode();
109 numOfChecks++;
110 if(const CFLEdge* newEdge = graph->addCFLEdge(k, j, X))
111 {
112 pushIntoWorklist(newEdge);
113 }
114 }
115 }
116}
GEdgeKind getEdgeKind() const
Definition CFLGraph.h:57
const CFLEdge::CFLEdgeSetTy & getOutEdgeWithTy(GrammarBase::Symbol s)
Definition CFLGraph.h:98
const CFLEdge::CFLEdgeSetTy & getInEdgeWithTy(GrammarBase::Symbol s)
Definition CFLGraph.h:93
static double numOfChecks
Definition CFLSolver.h:53
NodeType * getSrcNode() const
NodeType * getDstNode() const

◆ pushIntoWorklist()

virtual bool SVF::CFLSolver::pushIntoWorklist ( const CFLEdge * item)
inlinevirtual

Definition at line 85 of file CFLSolver.h.

86 {
87 return worklist.push(item);
88 }

◆ solve()

void CFLSolver::solve ( )
virtual

Start solving.

initial worklist

Select and remove an edge Y(i,j) from worklist

Definition at line 119 of file CFLSolver.cpp.

120{
122 initialize();
123
124 while(!isWorklistEmpty())
125 {
127 const CFLEdge* Y_edge = popFromWorklist();
128 processCFLEdge(Y_edge);
129 }
130}
virtual void processCFLEdge(const CFLEdge *Y_edge)
Process CFLEdge.
Definition CFLSolver.cpp:62
virtual void initialize()
Initialize worklist.
Definition CFLSolver.cpp:36
virtual bool isWorklistEmpty()
Definition CFLSolver.h:89
const CFLEdge * popFromWorklist()
Worklist operations.
Definition CFLSolver.h:97

Member Data Documentation

◆ grammar

CFGrammar* SVF::CFLSolver::grammar
protected

Definition at line 110 of file CFLSolver.h.

◆ graph

CFLGraph* SVF::CFLSolver::graph
protected

Definition at line 109 of file CFLSolver.h.

◆ numOfChecks

double CFLSolver::numOfChecks = 0
static

Definition at line 53 of file CFLSolver.h.

◆ worklist

WorkList SVF::CFLSolver::worklist
protected

Worklist for resolution.

Definition at line 112 of file CFLSolver.h.


The documentation for this class was generated from the following files: