svf-lib 1.0.1002 → 1.0.1005

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -53,19 +53,30 @@ public:
53
53
 
54
54
  /// Start Normalize (BIN Only)
55
55
  // TODO: Add different Combination Transformation Option
56
+
57
+ /// Normalization without attribute expanded
56
58
  CFLGrammar* normalize(GrammarBase *generalGrammar);
57
- private:
58
59
 
60
+ /// Fill Every attribute in CFL grammar
61
+ CFLGrammar* fillAttribute(CFLGrammar *grammar, Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> *kind2AttrMap);
62
+
63
+ private:
64
+ /// Add nonterminal to tranfer long rules to binary rules
59
65
  void ebnf_bin(GrammarBase *generalGrammar, CFLGrammar *grammar);
60
66
 
61
67
  void ebnf_sign_replace(char sign, GrammarBase* generalGrammar, CFLGrammar *grammar);
62
68
 
69
+ void insertToCFLGrammar(CFLGrammar *grammar, Production &prod);
70
+
63
71
  int ebnf_bracket_match(Production& prod, int i, CFLGrammar *grammar) ;
64
72
 
73
+ int check_head(Map<Symbol, Productions>& grammar, Production& rule);
74
+
65
75
  Production strTrans(std::string strPro, CFLGrammar *grammar);
66
76
 
67
- int check_head(Map<Symbol, Productions>& grammar, Production& rule);
77
+ Production getFilledProd(Production &prod, CFLGrammar::Attribute attribute, CFLGrammar *grammar);
68
78
 
79
+ Productions getFilledProductions(Production &prod, Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> *kind2AttriMap, CFLGrammar *grammar);
69
80
  };
70
81
 
71
82
  } // End namespace SVF
@@ -31,6 +31,8 @@
31
31
  #include "CFL/CFLSolver.h"
32
32
  #include "CFL/CFGNormalizer.h"
33
33
  #include "CFL/GrammarBuilder.h"
34
+ #include "CFL/CFLGraphBuilder.h"
35
+ #include "CFL/CFLGramGraphChecker.h"
34
36
  #include "MemoryModel/PointerAnalysis.h"
35
37
  #include "Graphs/ConsG.h"
36
38
  #include "Util/Options.h"
@@ -57,39 +59,38 @@ public:
57
59
  /// Start Analysis here (main part of pointer analysis).
58
60
  virtual void analyze()
59
61
  {
60
- PointerAnalysis::initialize();
61
- GrammarBuilder * gReader = new GrammarBuilder(Options::GrammarFilename);
62
- CFGNormalizer *normalizer = new CFGNormalizer();
63
-
64
- graph = new CFLGraph();
62
+ GrammarBuilder gReader = GrammarBuilder(Options::GrammarFilename);
63
+ CFGNormalizer normalizer = CFGNormalizer();
64
+ CFLGraphBuilder cflGraphBuilder = CFLGraphBuilder();
65
+ CFLGramGraphChecker cflChecker = CFLGramGraphChecker();
66
+ /// Assume Read From Const Graph, associate label symbol is hard coded
65
67
  if (Options::GraphIsFromDot == false)
66
68
  {
67
- // Maybe could put in SVFIR Class
68
- // In memory Graph does not have string type label
69
- Map<std::string, SVF::CFLGraph::Symbol> ConstMap = {{"Addr",0}, {"Copy", 1},{"Store", 2},{"Load", 3},{"Gep", 4},{"Vgep", 5},{"Addrbar",6}, {"Copybar", 7},{"Storebar", 8},{"Loadbar", 9},{"Gepbar", 10},{"Vgepbar", 11}};
69
+ PointerAnalysis::initialize();
70
+ Map<std::string, SVF::CFLGraph::Symbol> ConstMap = {{"Addr",0}, {"Copy", 1},{"Store", 2},{"Load", 3},{"Gep_i", 4},{"Vgep", 5},{"Addrbar",6}, {"Copybar", 7},{"Storebar", 8},{"Loadbar", 9},{"Gepbar_i", 10},{"Vgepbar", 11}};
71
+ GrammarBase *generalGrammar = gReader.build(ConstMap);
70
72
  ConstraintGraph *consCG = new ConstraintGraph(svfir);
71
- svfir->dump("SVFIR");
72
- // Can be put in build, copy from general graph
73
- graph->label2SymMap = ConstMap;
74
- graph->buildBigraph(consCG);
75
- graph->dump("PAG");
73
+ graph = cflGraphBuilder.buildBigraph(consCG);
74
+ cflChecker.check(generalGrammar, graph);
75
+ grammar = normalizer.normalize(generalGrammar);
76
76
  delete consCG;
77
- GrammarBase *generalGrammar = gReader->build(&ConstMap);
78
- grammar = normalizer->normalize(generalGrammar);
79
- graph->setMap(&grammar->terminals, &grammar->nonterminals);
77
+ delete generalGrammar;
78
+ grammar->dump();
80
79
  }
81
80
  else
82
81
  {
83
- GrammarBase *generalGrammar = gReader->build();
84
- grammar = normalizer->normalize(generalGrammar);
85
- graph->setMap(&grammar->terminals, &grammar->nonterminals);
86
- graph->buildFromDot(Options::InputFilename);
82
+ GrammarBase *generalGrammar = gReader.build();
83
+ graph = cflGraphBuilder.buildFromDot(Options::InputFilename, generalGrammar);
84
+ cflChecker.check(generalGrammar, graph);
85
+ grammar = normalizer.normalize(generalGrammar);
86
+ delete generalGrammar;
87
87
  }
88
- graph->startSymbol = grammar->startSymbol;
89
88
  solver = new CFLSolver(graph, grammar);
90
89
  solver->solve();
91
- graph->dump("map");
92
- PointerAnalysis::finalize();
90
+ if (Options::GraphIsFromDot == false)
91
+ {
92
+ PointerAnalysis::finalize();
93
+ }
93
94
  }
94
95
 
95
96
  /// Interface exposed to users of our pointer analysis, given Value infos
@@ -103,7 +104,6 @@ public:
103
104
  /// Interface exposed to users of our pointer analysis, given PAGNodeID
104
105
  virtual AliasResult alias(NodeID node1, NodeID node2)
105
106
  {
106
- /// TODO:: Fix the edge label for a reachable alias relation if it is not 1;
107
107
  if(graph->hasEdge(graph->getGNode(node1), graph->getGNode(node2), graph->startSymbol))
108
108
  return AliasResult::MayAlias;
109
109
  else
@@ -0,0 +1,64 @@
1
+ //===----- CFLGramGraphChecker.h -- CFL Checker for Grammar and Graph alignment --------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * CFLGramGraphChecker.h
25
+ *
26
+ * Created on: May 23, 2022
27
+ * Author: Pei Xu
28
+ */
29
+
30
+ #include "CFL/CFLGrammar.h"
31
+ #include "Graphs/CFLGraph.h"
32
+ namespace SVF
33
+ {
34
+
35
+ class CFLGramGraphChecker
36
+ {
37
+ public:
38
+ void check(GrammarBase *grammar, CFLGraph *graph)
39
+ {
40
+ /// Check all the symbol in grammar in graph With the same label
41
+ for(auto pairV : grammar->terminals)
42
+ {
43
+ if (graph->label2SymMap.find(pairV.first) != graph->label2SymMap.end())
44
+ {
45
+ assert(graph->label2SymMap[pairV.first] == pairV.second);
46
+ }
47
+ }
48
+
49
+ for(auto pairV : grammar->nonterminals)
50
+ {
51
+ if (graph->label2SymMap.find(pairV.first) != graph->label2SymMap.end())
52
+ {
53
+ assert(graph->label2SymMap[pairV.first] == pairV.second);
54
+ }
55
+ }
56
+
57
+ /// Get Kind2Attr Map from Graph to Grammar
58
+ grammar->kind2AttrMap = graph->kind2AttrMap;
59
+ graph->startSymbol = grammar->startSymbol;
60
+ }
61
+ };
62
+
63
+ }// SVF
64
+
@@ -32,49 +32,101 @@
32
32
 
33
33
  namespace SVF
34
34
  {
35
-
36
35
  class GrammarBase
37
36
  {
38
37
  public:
39
38
  typedef u32_t Symbol;
40
39
  typedef std::vector<Symbol> Production;
41
40
  typedef Set<Production> Productions;
41
+ typedef u32_t Attribute;
42
+ typedef u32_t Kind;
42
43
  Map<std::string, Symbol> terminals;
43
44
  Map<std::string, Symbol> nonterminals;
45
+ Symbol startSymbol;
46
+ Symbol totalSymbol;
47
+ Map<Symbol, Productions> rawProductions;
48
+ Set<Symbol> attributeSymbol;
49
+ Map<Kind, Set<Attribute>> kind2AttrMap;
44
50
 
45
51
  Symbol str2Sym(std::string str) const;
46
52
 
47
53
  std::string sym2Str(Symbol sym) const;
48
54
 
55
+ std::string sym2StrDump(Symbol sym) const;
56
+
49
57
  Symbol getSymbol(const Production& prod, u32_t pos)
50
58
  {
51
59
  return prod.at(pos);
52
60
  }
53
61
 
62
+ inline Set<Symbol>& getAttrSyms()
63
+ {
64
+ return this->attributeSymbol;
65
+ }
66
+
54
67
  Symbol insertTerminalSymbol(std::string strLit);
55
68
  Symbol insertNonTerminalSymbol(std::string strLit);
69
+ void insertAttribute(Symbol s);
70
+
71
+ inline static Kind getSymKind(Symbol sym)
72
+ {
73
+ return (EdgeKindMask & sym);
74
+ }
75
+
76
+ inline static Attribute getSymAttribute(Symbol sym)
77
+ {
78
+ return (sym >> EdgeKindMaskBits);
79
+ }
80
+
81
+ inline static Kind getAttributedKind(Attribute attribute, Kind kind)
82
+ {
83
+ return ((attribute << EdgeKindMaskBits)| kind );
84
+ }
85
+
86
+ protected:
87
+ static constexpr unsigned char EdgeKindMaskBits = 8; ///< We use the lower 8 bits to denote edge kind
88
+ static constexpr u64_t EdgeKindMask = (~0ULL) >> (64 - EdgeKindMaskBits);
56
89
 
57
- Symbol startSymbol;
58
- Symbol totalSymbol;
59
- Map<Symbol, Productions> rawProductions;
60
90
  };
61
91
 
62
92
  class CFLGrammar : public GrammarBase
63
93
  {
64
94
 
65
95
  public:
66
- Set<Production > epsilonProds;
67
- Map<Symbol, Productions> singleRHS2Prods;
68
- Map<Symbol, Productions> firstRHS2Prods;
69
- Map<Symbol, Productions> secondRHS2Prods;
70
- Symbol newTerminalSubscript;
71
96
  CFLGrammar();
72
97
 
73
- const Productions& getEpsilonProds() const
98
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
99
+ //@{
100
+ static inline bool classof(const CFLGrammar *)
101
+ {
102
+ return true;
103
+ }
104
+
105
+ static inline bool classof(const GrammarBase *node)
106
+ {
107
+ return true;
108
+ }
109
+
110
+ Productions& getEpsilonProds()
74
111
  {
75
112
  return epsilonProds;
76
113
  }
77
114
 
115
+ Map<Symbol, Productions>& getSingleRHS2Prods()
116
+ {
117
+ return singleRHS2Prods;
118
+ }
119
+
120
+ Map<Symbol, Productions>& getFirstRHS2Prods()
121
+ {
122
+ return firstRHS2Prods;
123
+ }
124
+
125
+ Map<Symbol, Productions>& getSecondRHS2Prods()
126
+ {
127
+ return secondRHS2Prods;
128
+ }
129
+
78
130
  const bool hasProdsFromFirstRHS(Symbol sym) const
79
131
  {
80
132
  auto it = firstRHS2Prods.find(sym);
@@ -93,49 +145,57 @@ public:
93
145
  return it!=secondRHS2Prods.end();
94
146
  }
95
147
 
96
- const Productions& getProdsFromSingleRHS(Symbol sym) const
148
+ const Productions getProdsFromSingleRHS(Symbol sym) const
97
149
  {
98
150
  auto it = singleRHS2Prods.find(sym);
99
151
  assert(it!=singleRHS2Prods.end() && "production (X -> sym) not found for sym!!");
100
152
  return it->second;
101
153
  }
102
154
 
103
- const Productions& getProdsFromFirstRHS(Symbol sym) const
155
+ const Productions getProdsFromFirstRHS(Symbol sym) const
104
156
  {
105
157
  auto it = firstRHS2Prods.find(sym);
106
- assert(it!=firstRHS2Prods.end() && "production (X -> sym Y) not found for sym!!");
158
+ assert(it!=firstRHS2Prods.end() && "production (X -> sym Y ) not found for sym!!");
107
159
  return it->second;
108
160
  }
109
161
 
110
- const Productions& getProdsFromSecondRHS(Symbol sym) const
162
+ const Productions getProdsFromSecondRHS(Symbol sym) const
111
163
  {
112
164
  auto it = secondRHS2Prods.find(sym);
113
165
  assert(it!=secondRHS2Prods.end() && "production (X -> Y sym) not found for sym!!");
114
166
  return it->second;
115
167
  }
116
168
 
117
- Symbol getLHSSymbol(const Production& prod)
169
+
170
+ const Symbol getLHSSymbol(const Production& prod)
118
171
  {
119
172
  return prod.at(0);
120
173
  }
121
174
 
122
- Symbol getFirstRHSSymbol(const Production& prod)
175
+ const Symbol getFirstRHSSymbol(const Production& prod)
123
176
  {
124
177
  return prod.at(1);
125
178
  }
126
179
 
127
- Symbol getSecondRHSSymbol(const Production& prod)
180
+ const Symbol getSecondRHSSymbol(const Production& prod)
128
181
  {
129
182
  return prod.at(2);
130
183
  }
131
184
 
132
- inline int num_generator()
185
+ void dump();
186
+
187
+ const inline int num_generator()
133
188
  {
134
189
  return newTerminalSubscript++;
135
190
  }
136
191
 
192
+ private:
193
+ Set<Production> epsilonProds;
194
+ Map<Symbol, Productions> singleRHS2Prods;
195
+ Map<Symbol, Productions> firstRHS2Prods;
196
+ Map<Symbol, Productions> secondRHS2Prods;
197
+ Symbol newTerminalSubscript;
137
198
  };
138
199
 
139
-
140
200
  }
141
201
  #endif /* CFLGrammar_H_ */
@@ -0,0 +1,11 @@
1
+ Start:
2
+ V
3
+ Productions:
4
+ F -> ( Copy ) *;
5
+ F -> ( Store V Load ) *;
6
+ Fbar -> ( Copybar ) *;
7
+ Fbar -> ( Loadbar V Storebar ) *;
8
+ V -> Fbar V F;
9
+ V -> Gepbar_i V Gep_i;
10
+ V -> Addrbar Addr;
11
+ V -> epsilon;
@@ -0,0 +1,114 @@
1
+ //===----- CFLGraphBuilder.h -- CFL Graph Builder --------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * CFLGraphBuilder.h
25
+ *
26
+ * Created on: May 22, 2022
27
+ * Author: Pei Xu
28
+ */
29
+
30
+ #include "CFL/CFLGrammar.h"
31
+ #include "Graphs/CFLGraph.h"
32
+ namespace SVF
33
+ {
34
+
35
+ /*!
36
+ * Build CFLGraph from memory graph or dot form
37
+
38
+ */
39
+
40
+ class CFLGraphBuilder
41
+ {
42
+ public:
43
+ /// Build graph by copying nodes and edges from any graph inherited from GenericGraph
44
+ template<class N, class E>
45
+ void build(GenericGraph<N,E>* graph, CFLGraph* cflGraph)
46
+ {
47
+ for(auto it = graph->begin(); it!= graph->end(); it++)
48
+ {
49
+ CFLNode* node = new CFLNode((*it).first);
50
+ cflGraph->addCFLNode((*it).first, node);
51
+ }
52
+ for(auto it = graph->begin(); it!= graph->end(); it++)
53
+ {
54
+ N* node = (*it).second;
55
+ for(E* edge : node->getOutEdges())
56
+ {
57
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edge->getEdgeKind());
58
+ }
59
+ }
60
+ }
61
+
62
+ /// Build Bidirectional graph by copying nodes and edges from any graph inherited from GenericGraph
63
+ template<class N, class E>
64
+ CFLGraph* buildBigraph(GenericGraph<N,E>* graph)
65
+ {
66
+ CFLGraph *cflGraph = new CFLGraph();
67
+ Map<std::string, SVF::CFLGraph::Symbol> ConstMap = {{"Addr",0}, {"Copy", 1},{"Store", 2},{"Load", 3},{"Gep_i", 4},{"Vgep", 5},{"Addrbar",6}, {"Copybar", 7},{"Storebar", 8},{"Loadbar", 9},{"Gepbar_i", 10},{"Vgepbar", 11}};
68
+ cflGraph->setMap(ConstMap);
69
+ for(auto it = graph->begin(); it!= graph->end(); it++)
70
+ {
71
+ CFLNode* node = new CFLNode((*it).first);
72
+ cflGraph->addCFLNode((*it).first, node);
73
+ }
74
+ for(auto it = graph->begin(); it!= graph->end(); it++)
75
+ {
76
+ N* node = (*it).second;
77
+ for(E* edge : node->getOutEdges())
78
+ {
79
+ CFLGrammar::Kind edgeLabel = edge->getEdgeKind();
80
+ // Need to get the offset from the Const Edge
81
+ // The offset present edge is only from Normal Gep CG at moment
82
+ if(NormalGepCGEdge::classof(edge))
83
+ {
84
+ NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
85
+ CFLGrammar::Attribute offset = nGepEdge->getConstantFieldIdx();
86
+ cflGraph->addAttribute(edgeLabel, offset);
87
+ edgeLabel = CFLGrammar::getAttributedKind(offset, edgeLabel);
88
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
89
+ std::string key = cflGraph->sym2LabelMap[edge->getEdgeKind()];
90
+ key.pop_back();
91
+ key.pop_back(); // _i standsfor attribute variable should place at last
92
+ key.append("bar_i"); // for example Gep_i should be Gepbar_i, not Gep_ibar
93
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(offset, cflGraph->label2SymMap[key]));
94
+ cflGraph->addAttribute(cflGraph->label2SymMap[key], offset);
95
+ }
96
+ else
97
+ {
98
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
99
+ std::string key = cflGraph->sym2LabelMap[edge->getEdgeKind()];
100
+ key.append("bar");
101
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), cflGraph->label2SymMap[key]);
102
+ }
103
+ }
104
+ }
105
+ return cflGraph;
106
+ }
107
+ /// Build graph from file
108
+ void build(std::string filename, CFLGraph* cflGraph);
109
+
110
+ /// Build graph from Dot
111
+ CFLGraph *buildFromDot(std::string filename, GrammarBase *grammar);
112
+ };
113
+ }// SVF
114
+
@@ -1,4 +1,4 @@
1
- //===----- CFGNormalizer.h -- CFL Alias Analysis Client--------------//
1
+ //===----- GrammarBuilder.h -- CFL Grammar Builder--------------//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -30,7 +30,6 @@
30
30
 
31
31
  #include "CFL/CFLGrammar.h"
32
32
  #include "Graphs/CFLGraph.h"
33
-
34
33
  namespace SVF
35
34
  {
36
35
 
@@ -51,6 +50,19 @@ namespace SVF
51
50
 
52
51
  class GrammarBuilder
53
52
  {
53
+ private:
54
+ /// Load whole file content to string
55
+ inline std::string loadFileString() const;
56
+
57
+ /// Parse start symbol and production from file string
58
+ inline std::string parseProduction() const;
59
+
60
+ /// Parse whole production string to production vector
61
+ inline std::vector<std::string> loadWordProductions();
62
+
63
+ /// Strip frond and tail space
64
+ inline std::string stripSpace(std::string s) const;
65
+
54
66
  public:
55
67
  std::string fileName;
56
68
  GrammarBase *grammar;
@@ -62,7 +74,7 @@ public:
62
74
 
63
75
  GrammarBase* build();
64
76
 
65
- GrammarBase* build(Map<std::string, SVF::CFLGraph::Symbol> *preMap);
77
+ GrammarBase* build(Map<std::string, SVF::CFLGraph::Symbol> &preMap);
66
78
  };
67
79
 
68
80
  } // SVF
@@ -36,6 +36,7 @@
36
36
  #include <regex>
37
37
  #include "CFL/CFLGrammar.h"
38
38
  #include "Graphs/GenericGraph.h"
39
+ #include "Graphs/ConsG.h"
39
40
 
40
41
  namespace SVF
41
42
  {
@@ -51,6 +52,11 @@ public:
51
52
  {
52
53
  }
53
54
  ~CFLEdge() override = default;
55
+
56
+ inline GEdgeKind getEdgeKind() const
57
+ {
58
+ return this->getEdgeKindWithoutMask();
59
+ }
54
60
  };
55
61
 
56
62
 
@@ -70,64 +76,20 @@ typedef GenericGraph<CFLNode,CFLEdge> GenericCFLGraphTy;
70
76
  class CFLGraph: public GenericCFLGraphTy
71
77
  {
72
78
  public:
73
- typedef u32_t Symbol;
79
+ typedef CFLGrammar::Symbol Symbol;
74
80
  typedef GenericNode<CFLNode,CFLEdge>::GEdgeSetTy CFLEdgeSet;
75
81
  Map<std::string, Symbol> label2SymMap;
82
+ Map<Symbol, std::string> sym2LabelMap;
76
83
  Symbol startSymbol;
84
+ Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> kind2AttrMap;
85
+ bool externMap;
86
+ Symbol current;
77
87
 
78
88
  CFLGraph()
79
89
  {
80
90
  }
81
91
  ~CFLGraph() override = default;
82
92
 
83
- /// Build graph by copying nodes and edges from any graph inherited from GenericGraph
84
- template<class N, class E>
85
- void build(GenericGraph<N,E>* graph)
86
- {
87
- for(auto it = graph->begin(); it!= graph->end(); it++)
88
- {
89
- CFLNode* node = new CFLNode((*it).first);
90
- addCFLNode((*it).first, node);
91
- }
92
- for(auto it = graph->begin(); it!= graph->end(); it++)
93
- {
94
- N* node = (*it).second;
95
- for(E* edge : node->getOutEdges())
96
- {
97
- addCFLEdge(getGNode(edge->getSrcID()), getGNode(edge->getDstID()), edge->getEdgeKind());
98
- }
99
- }
100
- }
101
-
102
- /// Build Bidirectional graph by copying nodes and edges from any graph inherited from GenericGraph
103
- template<class N, class E>
104
- void buildBigraph(GenericGraph<N,E>* graph)
105
- {
106
- for(auto it = graph->begin(); it!= graph->end(); it++)
107
- {
108
- CFLNode* node = new CFLNode((*it).first);
109
- addCFLNode((*it).first, node);
110
- }
111
- for(auto it = graph->begin(); it!= graph->end(); it++)
112
- {
113
- N* node = (*it).second;
114
- for(E* edge : node->getOutEdges())
115
- {
116
- addCFLEdge(getGNode(edge->getSrcID()), getGNode(edge->getDstID()), edge->getEdgeKind());
117
- std::string key = "";
118
- for (auto &i : this->label2SymMap)
119
- {
120
- if (i.second == edge->getEdgeKind())
121
- {
122
- key = i.first;
123
- }
124
- }
125
- key.append("bar");
126
- addCFLEdge(getGNode(edge->getDstID()), getGNode(edge->getSrcID()), this->label2SymMap[key]);
127
- }
128
- }
129
- }
130
-
131
93
  virtual void addCFLNode(NodeID id, CFLNode* node);
132
94
 
133
95
  virtual const CFLEdge* addCFLEdge(CFLNode* src, CFLNode* dst, CFLEdge::GEdgeFlag label);
@@ -138,19 +100,30 @@ public:
138
100
 
139
101
  void view();
140
102
 
141
- /// Build graph from file
142
- void build(std::string filename);
143
-
144
- /// Build graph from Dot
145
- void buildFromDot(std::string filename);
146
-
103
+ void setMap(Map<std::string, Symbol> &labelMap);
147
104
  /// Set label2Sym from External
148
- void setMap(Map<std::string, Symbol>* terminals, Map<std::string, Symbol>* nonterminals);
105
+ void setMap(GrammarBase *grammar);
106
+
107
+ /// add attribute to kind2Attribute Map
108
+ void addAttribute(CFLGrammar::Kind kind, CFLGrammar::Attribute attribute)
109
+ {
110
+ if(kind2AttrMap.find(kind) == kind2AttrMap.end())
111
+ {
112
+ Set<CFLGrammar::Attribute> attrs {attribute};
113
+ kind2AttrMap.insert(make_pair(kind, attrs));
114
+ }
115
+ else
116
+ {
117
+ if(kind2AttrMap[kind].find(attribute) == kind2AttrMap[kind].end())
118
+ {
119
+ kind2AttrMap[kind].insert(attribute);
120
+ }
121
+ }
122
+ }
149
123
 
150
124
  private:
151
125
  CFLEdgeSet cflEdgeSet;
152
- Symbol current;
153
- bool externMap;
126
+
154
127
  };
155
128
 
156
129
  }
@@ -82,6 +82,10 @@ public:
82
82
  {
83
83
  return (EdgeKindMask & edgeFlag);
84
84
  }
85
+ inline GEdgeKind getEdgeKindWithoutMask() const
86
+ {
87
+ return edgeFlag;
88
+ }
85
89
  NodeType* getSrcNode() const
86
90
  {
87
91
  return src;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1002",
3
+ "version": "1.0.1005",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {