aboutsummaryrefslogtreecommitdiff
path: root/Ld.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Ld.cpp')
-rw-r--r--Ld.cpp60
1 files changed, 10 insertions, 50 deletions
diff --git a/Ld.cpp b/Ld.cpp
index 16c40fa..7728fd6 100644
--- a/Ld.cpp
+++ b/Ld.cpp
@@ -1,4 +1,5 @@
-#include "Ld.h"
+#include "trygvis/elfinfo/Ld.h"
+#include "trygvis/antlr.h"
#include "GnuLdLexer.h"
#include "GnuLdParser.h"
#include "GnuLdParserBaseListener.h"
@@ -9,6 +10,7 @@ namespace elfinfo {
using antlr4::ANTLRFileStream;
using antlr4::tree::ParseTree;
using namespace std;
+using namespace trygvis::antlr;
static MemoryAttribute valueOf(char c) {
switch (c) {
@@ -22,7 +24,7 @@ static MemoryAttribute valueOf(char c) {
case 'X':
return MemoryAttribute::X;
default:
- throw std::domain_error("Invalid memory attribute: " + c);
+ throw domain_error("Invalid memory attribute: " + c);
}
}
@@ -30,48 +32,6 @@ static bool endsWith(const string &a, const string &b) {
return b.length() <= a.length() && a.compare(a.length() - b.length(), b.length(), b) == 0;
}
-template<typename V, bool debug = false>
-class ParseTreeProperty {
-public:
- virtual V get(Ref<ParseTree> node) {
- return get(node.get());
- }
-
- virtual V get(ParseTree *const node) {
- if (!debug) {
- return _annotations.at(node);
- }
-
- try {
-// cout << "node = " << node->getText() << endl;
- return _annotations.at(node);
- } catch (std::out_of_range &e) {
- cout << "get(" << node << "), text=" << node->getText() << endl;
- stringstream buf;
- buf << "out of range: " << node << ", text=" << node->getText();
- auto msg = buf.str();
- cout << msg << endl;
- throw LdInternalErrorException(msg);
- }
- }
-
- virtual void put(ParseTree *const node, V value) {
- if (debug) {
- cout << "put(" << node << ", " << value << "), text: " << node->getText() << endl;
- }
- _annotations[node] = value;
- }
-
- virtual V removeFrom(ParseTree *const node) {
- return _annotations.erase(node);
- }
-
-protected:
- std::map<ParseTree *, V> _annotations;
-
-private:
-};
-
class ElfinfoGnuLdBaseListener : public GnuLdParserBaseListener {
private:
public:
@@ -260,16 +220,16 @@ LdScriptLoader::LdScriptLoader() : debug_(false) {
class LdErrorListener : public BaseErrorListener {
public:
- std::vector<std::string> messages;
+ vector<string> messages;
void syntaxError(IRecognizer *recognizer, Token *offendingSymbol, size_t line, int charPositionInLine,
- const std::string &msg, std::exception_ptr e) override {
+ const string &msg, exception_ptr e) override {
messages.push_back("line " + to_string(line) + ":" + to_string(charPositionInLine) + ": " + msg);
}
};
-LdScript LdScriptLoader::load(std::string path) {
- std::ifstream stream(path, std::ios::binary);
+LdScript LdScriptLoader::load(string path) {
+ ifstream stream(path, ios::binary);
if (!stream.good() || stream.eof()) {
return {};
@@ -292,7 +252,7 @@ LdScript LdScriptLoader::load(std::string path) {
if (debug_) {
for (auto token : tokens.getTokens()) {
- std::cout << token->toString() << std::endl;
+ cout << token->toString() << endl;
}
}
@@ -311,7 +271,7 @@ LdScript LdScriptLoader::load(std::string path) {
}
if (debug_ && parser.getNumberOfSyntaxErrors() == 0) {
- std::cout << file->toStringTree(&parser) << std::endl << std::endl;
+ cout << file->toStringTree(&parser) << endl;
}
return {