Previous way of accessing templated methods was a bit bulky,
I suggest to solve this using small interface class.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
ELF/LinkerScript.h | ||
---|---|---|
140 ↗ | (On Diff #69243) | This is the same as Script<ELFT>::X, just with a non templated type, no? Can you rename ScriptMethods to LinkerScriptBase and replace Script<ELFT>::X with a "LinkerScriptBase *Script"? |
As I wrote in the comment to the other patch, I think I still prefer the current way than the way you are suggesting in this patch. The current approach seems silly but simple.
I see. But there are 4 methods already and probably we`ll need more. Each one use of non-template stuff is an excessive call redirection and always a new method with bunch of code.
Virtual calls for linkerscript tasks costs nothing at the same time.
I updated this patch just in case to show how much code is removed from head revision.
ELF/LinkerScript.h | ||
---|---|---|
140 ↗ | (On Diff #69243) | Not sure I understand the idea correctly. If I replace usings of Script<ELFT>::X with a "LinkerScriptBase *Script", std::vector<PhdrEntry<ELFT>> createPhdrs(); bool shouldKeep(InputSectionBase<ELFT> *S); I tried to do: extern LinkerScriptBase* ScriptBase; template <class ELFT> LinkerScript<ELFT> *getScript() { return static_cast<LinkerScript<ELFT> *>(ScriptBase); } Instead of: template <class ELFT> struct Script { static LinkerScript<ELFT> *X; }; template <class ELFT> LinkerScript<ELFT> *Script<ELFT>::X; But use of getScript<ELFT() everywhere in the code introduces lots of minor changes, I ended up with adding single global variable. |
Something like getScript is what I had in mind, but the current solution is OK too.
I like this change, but wait to see if Rui is OK with it too.
ELF/LinkerScript.cpp | ||
---|---|---|
629 ↗ | (On Diff #69822) | Is this being used? |
I'm trying to not do too much stuff in the "object-oriented" style, but this seems to be undeniably an improvement, so we probably should go with this.
ELF/LinkerScript.cpp | ||
---|---|---|
44 ↗ | (On Diff #69822) | Format. |
ELF/LinkerScript.h | ||
192–193 ↗ | (On Diff #69822) | This comment is for struct Script and Script<ELFT>::X, so you shouldn't add the new line below this. |
194 ↗ | (On Diff #69822) | clang-format. |
LGTM with this fix.
ELF/LinkerScript.h | ||
---|---|---|
205 ↗ | (On Diff #70511) | Please run clang-format on this patch. You want to put a space before * instead of after it. |
ELF/LinkerScript.h | ||
---|---|---|
205 ↗ | (On Diff #70511) | Sorry for this. |