<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 22, 2016 at 2:08 AM, George Rimar <span dir="ltr"><<a href="mailto:grimar@accesssoftek.com" target="_blank">grimar@accesssoftek.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">grimar created this revision.<br>
grimar added reviewers: dblaikie, ruiu, rafael.<br>
grimar added subscribers: llvm-commits, grimar.<br>
<br>
Little change as was proposed by David Blaikie.<br>
<br>
Rui, Rafal, what do you think ?<br>
<br>
<br>
<a href="http://reviews.llvm.org/D17499" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17499</a><br>
<br>
Files:<br>
ELF/LinkerScript.cpp<br>
<br>
Index: ELF/LinkerScript.cpp<br>
===================================================================<br>
--- ELF/LinkerScript.cpp<br>
+++ ELF/LinkerScript.cpp<br>
@@ -83,21 +83,11 @@<br>
}<br>
<br>
class elf2::ScriptParser {<br>
+ typedef void (ScriptParser::*CmdHandler)();<br></blockquote><div><br></div><div>I'd name just Handler.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
public:<br>
ScriptParser(BumpPtrAllocator *A, StringRef S, bool B)<br>
- : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {<br>
- Cmd["ENTRY"] = std::mem_fn(&ScriptParser::readEntry);<br>
- Cmd["EXTERN"] = std::mem_fn(&ScriptParser::readExtern);<br>
- Cmd["GROUP"] = std::mem_fn(&ScriptParser::readGroup);<br>
- Cmd["INCLUDE"] = std::mem_fn(&ScriptParser::readInclude);<br>
- Cmd["INPUT"] = std::mem_fn(&ScriptParser::readGroup);<br>
- Cmd["OUTPUT"] = std::mem_fn(&ScriptParser::readOutput);<br>
- Cmd["OUTPUT_ARCH"] = std::mem_fn(&ScriptParser::readOutputArch);<br>
- Cmd["OUTPUT_FORMAT"] = std::mem_fn(&ScriptParser::readOutputFormat);<br>
- Cmd["SEARCH_DIR"] = std::mem_fn(&ScriptParser::readSearchDir);<br>
- Cmd["SECTIONS"] = std::mem_fn(&ScriptParser::readSections);<br>
- Cmd[";"] = [](ScriptParser &) {};<br>
- }<br>
+ : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}<br>
<br>
void run();<br>
<br>
@@ -127,7 +117,18 @@<br>
<br>
StringSaver Saver;<br>
std::vector<StringRef> Tokens;<br>
- llvm::StringMap<std::function<void(ScriptParser &)>> Cmd;<br>
+ llvm::StringMap<CmdHandler> Cmd{<br>
+ {"ENTRY", &ScriptParser::readEntry},<br>
+ {"EXTERN", &ScriptParser::readExtern},<br>
+ {"GROUP", &ScriptParser::readGroup},<br>
+ {"INCLUDE", &ScriptParser::readInclude},<br>
+ {"INPUT", &ScriptParser::readGroup},<br>
+ {"OUTPUT", &ScriptParser::readOutput},<br>
+ {"OUTPUT_ARCH", &ScriptParser::readOutputArch},<br>
+ {"OUTPUT_FORMAT", &ScriptParser::readOutputFormat},<br>
+ {"SEARCH_DIR", &ScriptParser::readSearchDir},<br>
+ {"SECTIONS", &ScriptParser::readSections},<br>
+ {";", nullptr}};<br></blockquote><div><br></div><div>I think adding a nullptr is too subtle. Can you define readNothing and use that as a handler for ';'?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
size_t Pos = 0;<br>
bool IsUnderSysroot;<br>
bool Error = false;<br>
@@ -138,8 +139,9 @@<br>
StringRef Tok = next();<br>
auto It = Cmd.find(Tok);<br>
if (It != Cmd.end()) {<br>
- std::function<void(ScriptParser &)> &Handler = It->second;<br>
- Handler(*this);<br>
+ CmdHandler Handler = It->second;<br>
+ if (Handler)<br>
+ (this->*Handler)();<br></blockquote><div><br></div><div>Then you can do</div><div><br></div><div>if (Handler Fn = Cmd.lookup(Tok))</div><div> (this->*Fn)();</div><div>else</div><div> setError("unknown directive "...);</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
} else {<br>
setError("unknown directive: " + Tok);<br>
}<br>
<br>
<br>
</blockquote></div><br></div></div>