[PATCH] D17499: [ELF] - replaced std::function with raw pointers in LinkerScript.cpp
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 01:31:12 PST 2016
This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.
Closed by commit rL261729: [ELF] - replaced std::function with raw pointers in LinkerScript.cpp (authored by grimar).
Changed prior to commit:
http://reviews.llvm.org/D17499?vs=48785&id=48897#toc
Repository:
rL LLVM
http://reviews.llvm.org/D17499
Files:
lld/trunk/ELF/LinkerScript.cpp
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -95,21 +95,11 @@
}
class elf2::ScriptParser {
+ typedef void (ScriptParser::*Handler)();
+
public:
ScriptParser(BumpPtrAllocator *A, StringRef S, bool B)
- : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {
- Cmd["ENTRY"] = std::mem_fn(&ScriptParser::readEntry);
- Cmd["EXTERN"] = std::mem_fn(&ScriptParser::readExtern);
- Cmd["GROUP"] = std::mem_fn(&ScriptParser::readGroup);
- Cmd["INCLUDE"] = std::mem_fn(&ScriptParser::readInclude);
- Cmd["INPUT"] = std::mem_fn(&ScriptParser::readGroup);
- Cmd["OUTPUT"] = std::mem_fn(&ScriptParser::readOutput);
- Cmd["OUTPUT_ARCH"] = std::mem_fn(&ScriptParser::readOutputArch);
- Cmd["OUTPUT_FORMAT"] = std::mem_fn(&ScriptParser::readOutputFormat);
- Cmd["SEARCH_DIR"] = std::mem_fn(&ScriptParser::readSearchDir);
- Cmd["SECTIONS"] = std::mem_fn(&ScriptParser::readSections);
- Cmd[";"] = [](ScriptParser &) {};
- }
+ : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}
void run();
@@ -129,6 +119,7 @@
void readExtern();
void readGroup();
void readInclude();
+ void readNothing() {}
void readOutput();
void readOutputArch();
void readOutputFormat();
@@ -140,22 +131,32 @@
StringSaver Saver;
std::vector<StringRef> Tokens;
- llvm::StringMap<std::function<void(ScriptParser &)>> Cmd;
+ const static StringMap<Handler> Cmd;
size_t Pos = 0;
bool IsUnderSysroot;
bool Error = false;
};
+const StringMap<elf2::ScriptParser::Handler> elf2::ScriptParser::Cmd = {
+ {"ENTRY", &ScriptParser::readEntry},
+ {"EXTERN", &ScriptParser::readExtern},
+ {"GROUP", &ScriptParser::readGroup},
+ {"INCLUDE", &ScriptParser::readInclude},
+ {"INPUT", &ScriptParser::readGroup},
+ {"OUTPUT", &ScriptParser::readOutput},
+ {"OUTPUT_ARCH", &ScriptParser::readOutputArch},
+ {"OUTPUT_FORMAT", &ScriptParser::readOutputFormat},
+ {"SEARCH_DIR", &ScriptParser::readSearchDir},
+ {"SECTIONS", &ScriptParser::readSections},
+ {";", &ScriptParser::readNothing}};
+
void ScriptParser::run() {
while (!atEOF()) {
StringRef Tok = next();
- auto It = Cmd.find(Tok);
- if (It != Cmd.end()) {
- std::function<void(ScriptParser &)> &Handler = It->second;
- Handler(*this);
- } else {
+ if (Handler Fn = Cmd.lookup(Tok))
+ (this->*Fn)();
+ else
setError("unknown directive: " + Tok);
- }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17499.48897.patch
Type: text/x-patch
Size: 2567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160224/750be81b/attachment.bin>
More information about the llvm-commits
mailing list