svf-tools 1.0.731 → 1.0.732

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.
@@ -191,6 +191,9 @@ void CFLAlias::initialize()
191
191
  {
192
192
  stat = new CFLStat(this);
193
193
 
194
+ // Parameter Checking
195
+ checkParameter();
196
+
194
197
  // Build CFL Grammar
195
198
  buildCFLGrammar();
196
199
 
@@ -46,6 +46,21 @@ double CFLBase::numOfStartEdges = 0;
46
46
  double CFLBase::numOfIteration = 1;
47
47
  double CFLBase::numOfChecks = 1;
48
48
 
49
+ void CFLBase::checkParameter()
50
+ {
51
+ // Check for valid grammar file before parsing other options
52
+ std::string filename = Options::GrammarFilename();
53
+ bool cflfile = (filename.rfind("CFLGrammar.txt") == filename.length() - std::string("CFLGrammar.txt").length());
54
+ bool pegfile = (filename.rfind("PEGGrammar.txt") == filename.length() - std::string("PEGGrammar.txt").length());
55
+ if (!Options::Customized() && !(cflfile || pegfile))
56
+ {
57
+ SVFUtil::errs() << "Invalid alias grammar file: " << Options::GrammarFilename() << "\n"
58
+ << "Please use a file that ends with either 'CFLGrammar.txt' or 'PEGGrammar.txt', "
59
+ << "or use the -customized flag to allow custom grammar files.\n";
60
+ assert(false && "grammar loading failed!"); // exit with error
61
+ }
62
+ }
63
+
49
64
  void CFLBase::buildCFLGrammar()
50
65
  {
51
66
  // Start building grammar
@@ -76,8 +91,14 @@ void CFLBase::buildCFLGraph()
76
91
  delete consCG;
77
92
  }
78
93
  else
79
- graph = cflGraphBuilder.buildFromDot(Options::CFLGraph(), grammarBase);
80
-
94
+ {
95
+ std::string fileName = Options::CFLGraph();
96
+ bool dotfile = (fileName.rfind(".dot") == fileName.length() - std::string("dot").length());
97
+ if (dotfile)
98
+ graph = cflGraphBuilder.buildFromDot(Options::CFLGraph(), grammarBase);
99
+ else
100
+ graph = cflGraphBuilder.buildFromTextFile(Options::CFLGraph(), grammarBase);
101
+ }
81
102
  // Check CFL Graph and Grammar are accordance with grammar
82
103
  CFLGramGraphChecker cflChecker = CFLGramGraphChecker();
83
104
  cflChecker.check(grammarBase, &cflGraphBuilder, graph);
@@ -42,9 +42,9 @@ void GrammarBase::setRawProductions(SymbolMap<Symbol, Productions>& rawProductio
42
42
  this->rawProductions = rawProductions;
43
43
  }
44
44
 
45
- void GrammarBase::setKind2AttrsMap(const Map<Kind, Set<Attribute>>& kind2AttrsMap)
45
+ void GrammarBase::setKindToAttrsMap(const Map<Kind, Set<Attribute>>& kindToAttrsMap)
46
46
  {
47
- this->kind2AttrsMap = kind2AttrsMap;
47
+ this->kindToAttrsMap = kindToAttrsMap;
48
48
  }
49
49
 
50
50
  void GrammarBase::setAttributeKinds(const Set<Kind>& attributeKinds)
@@ -52,7 +52,7 @@ void GrammarBase::setAttributeKinds(const Set<Kind>& attributeKinds)
52
52
  this->attributeKinds = attributeKinds;
53
53
  }
54
54
 
55
- GrammarBase::Kind GrammarBase::str2Kind(std::string str) const
55
+ GrammarBase::Kind GrammarBase::strToKind(std::string str) const
56
56
  {
57
57
 
58
58
  auto tit = terminals.find(str);
@@ -71,12 +71,12 @@ GrammarBase::Kind GrammarBase::str2Kind(std::string str) const
71
71
  abort();
72
72
  }
73
73
 
74
- GrammarBase::Symbol GrammarBase::str2Symbol(const std::string str) const
74
+ GrammarBase::Symbol GrammarBase::strToSymbol(const std::string str) const
75
75
  {
76
76
  Symbol symbol;
77
77
  std::string attributeStr = extractAttributeStrFromSymbolStr(str);
78
78
  std::string kindStr = extractKindStrFromSymbolStr(str);
79
- symbol.kind = str2Kind(kindStr);
79
+ symbol.kind = strToKind(kindStr);
80
80
 
81
81
  if ( attributeStr == "") return symbol;
82
82
 
@@ -100,7 +100,7 @@ GrammarBase::Symbol GrammarBase::str2Symbol(const std::string str) const
100
100
  return symbol;
101
101
  }
102
102
 
103
- std::string GrammarBase::kind2Str(Kind kind) const
103
+ std::string GrammarBase::kindToStr(Kind kind) const
104
104
  {
105
105
 
106
106
  std::string key = "";
@@ -136,7 +136,7 @@ std::string GrammarBase::kind2Str(Kind kind) const
136
136
  return "";
137
137
  }
138
138
 
139
- std::string GrammarBase::sym2StrDump(Symbol sym) const
139
+ std::string GrammarBase::symToStrDump(Symbol sym) const
140
140
  {
141
141
  Kind kind = sym.kind;
142
142
  Attribute attribute = sym.attribute;
@@ -184,7 +184,7 @@ GrammarBase::Kind GrammarBase::insertTerminalKind(std::string kindStr)
184
184
  }
185
185
  else
186
186
  {
187
- kind = str2Kind(kindStr);
187
+ kind = strToKind(kindStr);
188
188
  }
189
189
  return kind;
190
190
  }
@@ -199,7 +199,7 @@ inline GrammarBase::Kind GrammarBase::insertNonterminalKind(std::string const ki
199
199
  }
200
200
  else
201
201
  {
202
- kind = str2Kind(kindStr);
202
+ kind = strToKind(kindStr);
203
203
  }
204
204
  return kind;
205
205
  }
@@ -318,7 +318,7 @@ GrammarBase::Symbol GrammarBase::insertEBNFSigns(std::string symbolStr)
318
318
  }
319
319
  else
320
320
  {
321
- sign = str2Kind(symbolStr);
321
+ sign = strToKind(symbolStr);
322
322
  }
323
323
  return sign;
324
324
 
@@ -327,14 +327,14 @@ GrammarBase::Symbol GrammarBase::insertEBNFSigns(std::string symbolStr)
327
327
  void GrammarBase::insertAttribute(Kind kind, Attribute attribute)
328
328
  {
329
329
  attributeKinds.insert(kind);
330
- if (kind2AttrsMap.find(kind)!= kind2AttrsMap.end())
330
+ if (kindToAttrsMap.find(kind)!= kindToAttrsMap.end())
331
331
  {
332
- kind2AttrsMap[kind].insert(attribute);
332
+ kindToAttrsMap[kind].insert(attribute);
333
333
  }
334
334
  else
335
335
  {
336
336
  Set<CFLGrammar::Attribute> attrs {attribute};
337
- kind2AttrsMap.insert(make_pair(kind, attrs));
337
+ kindToAttrsMap.insert(make_pair(kind, attrs));
338
338
  }
339
339
  }
340
340
 
@@ -352,7 +352,7 @@ void CFLGrammar::dump(std::string fileName) const
352
352
  {
353
353
  std::ofstream gramFile(fileName);
354
354
  gramFile << "Start Kind:\n";
355
- gramFile << '\t' << kind2Str(startKind) << '(' << startKind << ')' << ' ' << "\n\n";
355
+ gramFile << '\t' << kindToStr(startKind) << '(' << startKind << ')' << ' ' << "\n\n";
356
356
 
357
357
  gramFile << "Epsilon Production:\n";
358
358
  std::vector<std::string> strV;
@@ -365,7 +365,7 @@ void CFLGrammar::dump(std::string fileName) const
365
365
  {
366
366
  ss << "-> ";
367
367
  }
368
- ss << sym2StrDump(sym) << '(' << sym.kind << ')' << ' ';
368
+ ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
369
369
  }
370
370
  strV.insert(strV.begin(), ss.str());
371
371
  }
@@ -380,7 +380,7 @@ void CFLGrammar::dump(std::string fileName) const
380
380
 
381
381
  gramFile << "Single Production:\n";
382
382
  strV = {};
383
- for (auto symProPair: singleRHS2Prods)
383
+ for (auto symProPair: singleRHSToProds)
384
384
  {
385
385
  for (auto pro: symProPair.second)
386
386
  {
@@ -393,7 +393,7 @@ void CFLGrammar::dump(std::string fileName) const
393
393
  {
394
394
  ss << "-> ";
395
395
  }
396
- ss << sym2StrDump(sym) << '(' << sym.kind << ')' << ' ';
396
+ ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
397
397
  }
398
398
  strV.insert(strV.begin(), ss.str());
399
399
  }
@@ -409,7 +409,7 @@ void CFLGrammar::dump(std::string fileName) const
409
409
 
410
410
  gramFile << "Binary Production:\n";
411
411
  strV = {};
412
- for (auto symProPair: firstRHS2Prods)
412
+ for (auto symProPair: firstRHSToProds)
413
413
  {
414
414
  for (auto pro: symProPair.second)
415
415
  {
@@ -423,7 +423,7 @@ void CFLGrammar::dump(std::string fileName) const
423
423
  {
424
424
  ss << "-> ";
425
425
  }
426
- ss << sym2StrDump(sym) << '(' << sym.kind << ')' << ' ';
426
+ ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
427
427
  }
428
428
  strV.insert(strV.begin(), ss.str());
429
429
  }