Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SVF::CFGrammar Class Reference

#include <CFGrammar.h>

Inheritance diagram for SVF::CFGrammar:
SVF::GrammarBase

Public Member Functions

 CFGrammar ()
 
ProductionsgetEpsilonProds ()
 
SymbolMap< Symbol, Productions > & getSingleRHSToProds ()
 
SymbolMap< Symbol, Productions > & getFirstRHSToProds ()
 
SymbolMap< Symbol, Productions > & getSecondRHSToProds ()
 
const bool hasProdsFromFirstRHS (const Symbol sym) const
 
const bool hasProdsFromSingleRHS (const Symbol sym) const
 
const bool hasProdsFromSecondRHS (const Symbol sym) const
 
const ProductionsgetProdsFromSingleRHS (const Symbol sym) const
 
const ProductionsgetProdsFromFirstRHS (const Symbol sym) const
 
const ProductionsgetProdsFromSecondRHS (const Symbol sym) const
 
const SymbolgetLHSSymbol (const Production &prod) const
 
const SymbolgetFirstRHSSymbol (const Production &prod) const
 
const SymbolgetSecondRHSSymbol (const Production &prod) const
 
void dump () const
 
void dump (std::string fileName) const
 
const u32_t num_generator ()
 
- Public Member Functions inherited from SVF::GrammarBase
Map< std::string, Kind > & getNonterminals ()
 
void setNonterminals (Map< std::string, Kind > &nonterminals)
 
Map< std::string, Kind > & getTerminals ()
 
void setTerminals (Map< std::string, Kind > &terminals)
 
Map< std::string, Kind > & getEBNFSigns ()
 
void setEBNFSigns (Map< std::string, Kind > &EBNFSigns)
 
SymbolMap< Symbol, Productions > & getRawProductions ()
 
const Map< Kind, Set< Attribute > > & getKindToAttrsMap () const
 
Kind getTotalKind ()
 
Kind getStartKind ()
 
void setStartKind (Kind startKind)
 
void setTotalKind (Kind totalKind)
 
std::string extractKindStrFromSymbolStr (const std::string &symbolStr) const
 
std::string extractAttributeStrFromSymbolStr (const std::string &symbolStr) const
 
void setRawProductions (SymbolMap< Symbol, Productions > &rawProductions)
 
void setKindToAttrsMap (const Map< Kind, Set< Attribute > > &kindToAttrsMap)
 
void setAttributeKinds (const Set< Kind > &attributeKind)
 
Kind strToKind (std::string str) const
 
Symbol strToSymbol (const std::string str) const
 
std::string kindToStr (Kind kind) const
 
std::string symToStrDump (Symbol sym) const
 
Symbol getSymbol (const Production &prod, u32_t pos)
 
const Set< Kind > & getAttrSyms () const
 
Kind insertNonterminalKind (std::string const kindStr)
 Insert kind to nonterminal and return kind.
 
Kind insertTerminalKind (std::string strLit)
 
Symbol insertSymbol (std::string strLit)
 
Symbol insertNonTerminalSymbol (std::string strLit)
 
Symbol insertTerminalSymbol (std::string strLit)
 
Symbol insertEBNFSigns (std::string strLit)
 
void insertAttribute (Kind kind, Attribute a)
 

Static Public Member Functions

static bool classof (const CFGrammar *)
 Methods for support type inquiry through isa, cast, and dyn_cast:
 
static bool classof (const GrammarBase *node)
 
- Static Public Member Functions inherited from SVF::GrammarBase
static Kind getAttributedKind (Attribute attribute, Kind kind)
 
static Kind getVariabledKind (VariableAttribute variableAttribute, Kind kind)
 

Private Attributes

SymbolSet< ProductionepsilonProds
 
SymbolMap< Symbol, ProductionssingleRHSToProds
 
SymbolMap< Symbol, ProductionsfirstRHSToProds
 
SymbolMap< Symbol, ProductionssecondRHSToProds
 
u32_t newTerminalSubscript
 

Additional Inherited Members

- Public Types inherited from SVF::GrammarBase
typedef u32_t Kind
 
typedef u32_t Attribute
 
typedef u32_t VariableAttribute
 
typedef struct SVF::GrammarBase::Symbol Symbol
 
template<typename Key , typename Value , typename Hash = SymbolHash, typename KeyEqual = std::equal_to<Key>, typename Allocator = std::allocator<std::pair<const Key, Value>>>
using SymbolMap = std::unordered_map< Key, Value, Hash, KeyEqual, Allocator >
 
template<typename Key , typename Hash = SymbolVectorHash, typename KeyEqual = std::equal_to<Key>, typename Allocator = std::allocator<Key>>
using SymbolSet = std::unordered_set< Key, Hash, KeyEqual, Allocator >
 
typedef std::vector< SymbolProduction
 
typedef SymbolSet< ProductionProductions
 
- Protected Attributes inherited from SVF::GrammarBase
Kind startKind
 
- Static Protected Attributes inherited from SVF::GrammarBase
static constexpr unsigned char EdgeKindMaskBits = 8
 We use the lower 8 bits to denote edge kind.
 
static constexpr unsigned char AttributedKindMaskBits = 24
 We use the lower 24 bits to denote attributed kind.
 
static constexpr u64_t EdgeKindMask = (~0ULL) >> (64 - EdgeKindMaskBits)
 

Detailed Description

Definition at line 290 of file CFGrammar.h.

Constructor & Destructor Documentation

◆ CFGrammar()

CFGrammar::CFGrammar ( )

Definition at line 341 of file CFGrammar.cpp.

342{
344}
u32_t newTerminalSubscript
Definition CFGrammar.h:398

Member Function Documentation

◆ classof() [1/2]

static bool SVF::CFGrammar::classof ( const CFGrammar )
inlinestatic

Methods for support type inquiry through isa, cast, and dyn_cast:

Definition at line 298 of file CFGrammar.h.

299 {
300 return true;
301 }

◆ classof() [2/2]

static bool SVF::CFGrammar::classof ( const GrammarBase node)
inlinestatic

Definition at line 303 of file CFGrammar.h.

304 {
305 return true;
306 }

◆ dump() [1/2]

void CFGrammar::dump ( ) const

Definition at line 346 of file CFGrammar.cpp.

347{
348 dump("Normailized_Grammar.txt");
349}
void dump() const

◆ dump() [2/2]

void CFGrammar::dump ( std::string  fileName) const

Definition at line 351 of file CFGrammar.cpp.

352{
353 std::ofstream gramFile(fileName);
354 gramFile << "Start Kind:\n";
355 gramFile << '\t' << kindToStr(startKind) << '(' << startKind << ')' << ' ' << "\n\n";
356
357 gramFile << "Epsilon Production:\n";
358 std::vector<std::string> strV;
359 for (auto pro: this->epsilonProds)
360 {
361 std::stringstream ss;
362 for (auto sym : pro)
363 {
364 if (sym == pro[1])
365 {
366 ss << "-> ";
367 }
368 ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
369 }
370 strV.insert(strV.begin(), ss.str());
371 }
372 std::sort(strV.begin(), strV.end());
373 for (auto pro: strV)
374 {
375 gramFile << '\t';
376 gramFile << pro;
377 gramFile << '\n';
378 }
379 gramFile << '\n';
380
381 gramFile << "Single Production:\n";
382 strV = {};
383 for (auto symProPair: singleRHSToProds)
384 {
385 for (auto pro: symProPair.second)
386 {
387 std::stringstream ss;
388 int i = 0;
389 for (auto sym : pro)
390 {
391 i++;
392 if (i == 2)
393 {
394 ss << "-> ";
395 }
396 ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
397 }
398 strV.insert(strV.begin(), ss.str());
399 }
400 }
401 std::sort(strV.begin(), strV.end());
402 for (auto pro: strV)
403 {
404 gramFile << '\t';
405 gramFile << pro;
406 gramFile << '\n';
407 }
408 gramFile << '\n';
409
410 gramFile << "Binary Production:\n";
411 strV = {};
412 for (auto symProPair: firstRHSToProds)
413 {
414 for (auto pro: symProPair.second)
415 {
416 std::stringstream ss;
417 int i = 0;
418 for (auto sym : pro)
419 {
420 i++;
421
422 if (i == 2)
423 {
424 ss << "-> ";
425 }
426 ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
427 }
428 strV.insert(strV.begin(), ss.str());
429 }
430 }
431 std::sort(strV.begin(), strV.end());
432 for (auto pro: strV)
433 {
434 gramFile << '\t';
435 gramFile << pro;
436 gramFile << '\n';
437 }
438 gramFile << '\n';
439
440 gramFile.close();
441}
SymbolMap< Symbol, Productions > firstRHSToProds
Definition CFGrammar.h:396
SymbolSet< Production > epsilonProds
Definition CFGrammar.h:394
SymbolMap< Symbol, Productions > singleRHSToProds
Definition CFGrammar.h:395
std::string symToStrDump(Symbol sym) const
std::string kindToStr(Kind kind) const
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ getEpsilonProds()

Productions & SVF::CFGrammar::getEpsilonProds ( )
inline

Definition at line 308 of file CFGrammar.h.

309 {
310 return epsilonProds;
311 }

◆ getFirstRHSSymbol()

const Symbol & SVF::CFGrammar::getFirstRHSSymbol ( const Production prod) const
inline

Definition at line 373 of file CFGrammar.h.

374 {
375 return prod.at(1);
376 }

◆ getFirstRHSToProds()

SymbolMap< Symbol, Productions > & SVF::CFGrammar::getFirstRHSToProds ( )
inline

Definition at line 318 of file CFGrammar.h.

319 {
320 return firstRHSToProds;
321 }

◆ getLHSSymbol()

const Symbol & SVF::CFGrammar::getLHSSymbol ( const Production prod) const
inline

Definition at line 368 of file CFGrammar.h.

369 {
370 return prod.at(0);
371 }

◆ getProdsFromFirstRHS()

const Productions & SVF::CFGrammar::getProdsFromFirstRHS ( const Symbol  sym) const
inline

Definition at line 353 of file CFGrammar.h.

354 {
355 auto it = firstRHSToProds.find(sym);
356 assert(it!=firstRHSToProds.end() && "production (X -> sym Y ) not found for sym!!");
357 return it->second;
358 }

◆ getProdsFromSecondRHS()

const Productions & SVF::CFGrammar::getProdsFromSecondRHS ( const Symbol  sym) const
inline

Definition at line 360 of file CFGrammar.h.

361 {
362 auto it = secondRHSToProds.find(sym);
363 assert(it!=secondRHSToProds.end() && "production (X -> Y sym) not found for sym!!");
364 return it->second;
365 }
SymbolMap< Symbol, Productions > secondRHSToProds
Definition CFGrammar.h:397

◆ getProdsFromSingleRHS()

const Productions & SVF::CFGrammar::getProdsFromSingleRHS ( const Symbol  sym) const
inline

Definition at line 346 of file CFGrammar.h.

347 {
348 auto it = singleRHSToProds.find(sym);
349 assert(it!=singleRHSToProds.end() && "production (X -> sym) not found for sym!!");
350 return it->second;
351 }

◆ getSecondRHSSymbol()

const Symbol & SVF::CFGrammar::getSecondRHSSymbol ( const Production prod) const
inline

Definition at line 378 of file CFGrammar.h.

379 {
380 return prod.at(2);
381 }

◆ getSecondRHSToProds()

SymbolMap< Symbol, Productions > & SVF::CFGrammar::getSecondRHSToProds ( )
inline

Definition at line 323 of file CFGrammar.h.

324 {
325 return secondRHSToProds;
326 }

◆ getSingleRHSToProds()

SymbolMap< Symbol, Productions > & SVF::CFGrammar::getSingleRHSToProds ( )
inline

Definition at line 313 of file CFGrammar.h.

314 {
315 return singleRHSToProds;
316 }

◆ hasProdsFromFirstRHS()

const bool SVF::CFGrammar::hasProdsFromFirstRHS ( const Symbol  sym) const
inline

Definition at line 328 of file CFGrammar.h.

329 {
330 auto it = firstRHSToProds.find(sym);
331 return it!=firstRHSToProds.end();
332 }

◆ hasProdsFromSecondRHS()

const bool SVF::CFGrammar::hasProdsFromSecondRHS ( const Symbol  sym) const
inline

Definition at line 340 of file CFGrammar.h.

341 {
342 auto it = secondRHSToProds.find(sym);
343 return it!=secondRHSToProds.end();
344 }

◆ hasProdsFromSingleRHS()

const bool SVF::CFGrammar::hasProdsFromSingleRHS ( const Symbol  sym) const
inline

Definition at line 334 of file CFGrammar.h.

335 {
336 auto it = singleRHSToProds.find(sym);
337 return it!=singleRHSToProds.end();
338 }

◆ num_generator()

const u32_t SVF::CFGrammar::num_generator ( )
inline

Definition at line 388 of file CFGrammar.h.

389 {
390 return newTerminalSubscript++;
391 }

Member Data Documentation

◆ epsilonProds

SymbolSet<Production> SVF::CFGrammar::epsilonProds
private

Definition at line 394 of file CFGrammar.h.

◆ firstRHSToProds

SymbolMap<Symbol, Productions> SVF::CFGrammar::firstRHSToProds
private

Definition at line 396 of file CFGrammar.h.

◆ newTerminalSubscript

u32_t SVF::CFGrammar::newTerminalSubscript
private

Definition at line 398 of file CFGrammar.h.

◆ secondRHSToProds

SymbolMap<Symbol, Productions> SVF::CFGrammar::secondRHSToProds
private

Definition at line 397 of file CFGrammar.h.

◆ singleRHSToProds

SymbolMap<Symbol, Productions> SVF::CFGrammar::singleRHSToProds
private

Definition at line 395 of file CFGrammar.h.


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