CGRA-ME
DotParserDriver.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * The software programs comprising "CGRA-ME" and the documentation provided
3  * with them are copyright by its authors and the University of Toronto. Only
4  * non-commercial, not-for-profit use of this software is permitted without ex-
5  * plicit permission. This software is provided "as is" with no warranties or
6  * guarantees of support. See the LICENCE for more details. You should have re-
7  * ceived a copy of the full licence along with this software. If not, see
8  * <http://cgra-me.ece.utoronto.ca/license/>.
9  ******************************************************************************/
10 
11 #ifndef DOTPARSER_DRIVER_HH
12 #define DOTPARSER_DRIVER_HH
13 
14 // contains forward declarations for various things, see dot.y's "code requires" section
15 #include "generated/dot.tab.hh"
16 
18 
19 #include <string>
20 
22 {
23  public:
24  DotParserDriver(std::istream& input, std::string file_name_);
25 
30  ConfigGraph getGraph() && { return std::move(graph); }
31  const ConfigGraph& getGraph() const& { return graph; }
32 
37  const std::string& getFileName() const& { return file_name; }
38  std::string& getFileName() & { return file_name; }
39 
43  std::logic_error makeError(const yy::location& l, const std::string& m) const;
44 
48  void setGraphName(std::string name) { graph.setGraphName(std::move(name)); }
49  void appendGraphAttributes(ConfigStore attrs) { graph.setGraphAttributes(std::move(attrs)); }
50 
54  void appendDefaultNodeAttributes(ConfigStore new_attrs) { set_all(default_node_attributes, std::move(new_attrs)); }
55  void appendDefaultEdgeAttributes(ConfigStore new_attrs) { set_all(default_edge_attributes, std::move(new_attrs)); }
56 
60  ConfigGraph::VertexID addOrCreateNode(std::string name, ConfigStore custom_attrs = {}) {
61  add_all(custom_attrs, default_node_attributes);
62  return graph.insert(std::move(name), custom_attrs).first;
63  }
64 
68  ConfigGraph::EdgeID addEdge(std::string src_vname, std::string target_vname, ConfigStore custom_attrs = {}) {
69  set_all(custom_attrs, default_edge_attributes);
70  return graph.link(addOrCreateNode(src_vname), addOrCreateNode(target_vname), custom_attrs);
71  }
72 
73  // The yylex that we call from Bison
74  friend yy::parser::symbol_type yylex(
75  DotParserDriver& d, DOTScannerWrapper& scanner, yy::parser::symbol_type& context);
76  private:
77  // The name of the file being parsed.
78  // Used later to pass the file name to the location tracker.
79  std::string file_name;
80 
81  ConfigGraph graph = {};
82 
85 };
86 
87 
88 #endif /* DOTPARSER_DRIVER_HH */
DotParserDriver::appendGraphAttributes
void appendGraphAttributes(ConfigStore attrs)
Definition: DotParserDriver.h:57
ConfigGraph.h
DotParserDriver::addEdge
ConfigGraph::EdgeID addEdge(std::string src_vname, std::string target_vname, ConfigStore custom_attrs={})
Definition: DotParserDriver.h:76
DotParserDriver::getFileName
const std::string & getFileName() const &
Definition: DotParserDriver.h:45
DotParserDriver::makeError
std::logic_error makeError(const yy::location &l, const std::string &m) const
ConfigGraph
Definition: ConfigGraph.h:72
ConfigStore
Definition: ConfigStore.h:76
DotParserDriver::yylex
friend yy::parser::symbol_type yylex(DotParserDriver &d, DOTScannerWrapper &scanner, yy::parser::symbol_type &context)
DotParserDriver::default_node_attributes
ConfigStore default_node_attributes
Definition: DotParserDriver.h:91
DotParserDriver::default_edge_attributes
ConfigStore default_edge_attributes
Definition: DotParserDriver.h:92
DotParserDriver::DotParserDriver
DotParserDriver(std::istream &input, std::string file_name_)
add_all
ConfigStore & add_all(ConfigStore &into, const ConfigStore &from)
Add (or set) all keys from from in into.
Definition: ConfigStore.h:251
DotParserDriver::appendDefaultNodeAttributes
void appendDefaultNodeAttributes(ConfigStore new_attrs)
Definition: DotParserDriver.h:62
DotParserDriver::addOrCreateNode
ConfigGraph::VertexID addOrCreateNode(std::string name, ConfigStore custom_attrs={})
Definition: DotParserDriver.h:68
ConfigGraph::setGraphAttributes
void setGraphAttributes(ConfigStore &&attrs)
Definition: ConfigGraph.h:110
ConfigGraph::insert
std::pair< VertexID, bool > insert(std::string name, ConfigStore vertex_attrs={})
Definition: ConfigGraph.h:173
ConfigGraph::link
EdgeID link(VertexID source, VertexID target, ConfigStore edge_attrs={})
Definition: ConfigGraph.h:190
set_all
ConfigStore & set_all(ConfigStore &into, const ConfigStore &from)
Definition: ConfigStore.h:252
DotParserDriver::graph
ConfigGraph graph
Definition: DotParserDriver.h:89
ConfigGraph::VertexID
Definition: ConfigGraph.h:248
DotParserDriver::file_name
std::string file_name
Definition: DotParserDriver.h:87
DotParserDriver::setGraphName
void setGraphName(std::string name)
Definition: DotParserDriver.h:56
DotParserDriver::appendDefaultEdgeAttributes
void appendDefaultEdgeAttributes(ConfigStore new_attrs)
Definition: DotParserDriver.h:63
DotParserDriver
Definition: DotParserDriver.h:21
ConfigGraph::EdgeID
Definition: ConfigGraph.h:264
DotParserDriver::getGraph
ConfigGraph getGraph() &&
Definition: DotParserDriver.h:38
ConfigGraph::setGraphName
void setGraphName(const std::string &s)
Definition: ConfigGraph.h:117