Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions liberty/LibertyParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <cstdio>
#include <cstring>
#include <istream>
#include <regex>
#include <string>

Expand All @@ -46,15 +47,25 @@ parseLibertyFile(std::string_view filename,
std::string fn(filename);
gzstream::igzstream stream(fn.c_str());
if (stream.is_open()) {
LibertyParser reader(filename, library_visitor, report);
LibertyScanner scanner(&stream, filename, &reader, report);
LibertyParse parser(&scanner, &reader);
parser.parse();
parseLibertyFile(stream, filename, library_visitor, report);
}
else
throw FileNotReadable(filename);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here "// Parse Liberty from an in-memory stream.
// filename is used only as a label in diagnostic messages;
// it need not correspond to a file on disk."

It was a bit confusing to me how file_contents and filename interacted- but once I got it, I think it makes sense to add a one-line explanation.

void
parseLibertyFile(std::istream& file_contents,
std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report)
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove blank line here.

LibertyParser reader(filename, library_visitor, report);
LibertyScanner scanner(&file_contents, filename, &reader, report);
LibertyParse parser(&scanner, &reader);
parser.parse();
}

LibertyParser::LibertyParser(std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report) :
Expand Down
6 changes: 6 additions & 0 deletions liberty/LibertyParser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <functional>
#include <istream>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<istream> is fine but <iosfwd> would suffice in LibertyParser.hh since only a reference is declared, slightly reducing transitive include cost across the many translation units that pull in this header

#include <string_view>
#include <vector>
#include <map>
Expand Down Expand Up @@ -280,6 +281,11 @@ public:
virtual void visitVariable(LibertyVariable *variable) = 0;
};

void
parseLibertyFile(std::istream& file_contents,
std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report);
void
parseLibertyFile(std::string_view filename,
LibertyGroupVisitor *library_visitor,
Expand Down