<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 3, 2017 at 4:14 PM, Mikulin, Dmitry <span dir="ltr"><<a href="mailto:dmitry.mikulin@sony.com" target="_blank">dmitry.mikulin@sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div style="word-wrap:break-word">
The following patch fixes it, but yeah, we need to look ahead 2 tokens.</div></blockquote><div><br></div><div>Hmm, that is not necessarily a bad thing, but the beauty of the current parser is its simplicity, so adding arbitrary number of look-ahead is not ideal.</div><div><br></div><div>The current parser has limitations as it was discussed in the thread about linking the Linux kernel with LLD. Maybe it's time to rewrite the lexer to fix all the issues once and for all?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">
<div><br>
</div>
<div>==============================<wbr>=============================</div>
<span>
<div>diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp</div>
<div>index 34d6be2..f59323f 100644</div>
<div>--- a/ELF/LinkerScript.cpp</div>
<div>+++ b/ELF/LinkerScript.cpp</div>
<div>@@ -1998,7 +1998,7 @@ std::vector<SymbolVersion> ScriptParser::readSymbols() {</div><span class="gmail-">
<div>       continue;</div>
<div>     }</div>
<div> </div>
<div>-    if (peek() == "}" || peek() == "local" || Error)</div>
</span><div>+    if (peek() == "}" || (peek() == "local" && peek(1) == ":") || Error)</div><span class="gmail-">
<div>       break;</div>
<div>     StringRef Tok = next();</div>
<div>     Ret.push_back({unquote(Tok), false, hasWildcard(Tok)});</div>
</span><div>diff --git a/ELF/ScriptParser.cpp b/ELF/ScriptParser.cpp</div>
<div>index 79f3cd3..9617860 100644</div>
<div>--- a/ELF/ScriptParser.cpp</div>
<div>+++ b/ELF/ScriptParser.cpp</div>
<div>@@ -156,11 +156,15 @@ StringRef ScriptParserBase::next() {</div>
<div>   return Tokens[Pos++];</div>
<div> }</div>
<div> </div>
<div>-StringRef ScriptParserBase::peek() {</div>
<div>-  StringRef Tok = next();</div>
<div>-  if (Error)</div>
<div>-    return "";</div>
<div>-  --Pos;</div>
<div>+StringRef ScriptParserBase::peek(size_t n) {</div>
<div>+  StringRef Tok;</div>
<div>+  size_t i = 0;</div>
<div>+  while (i++ <= n) {</div>
<div>+    Tok = next();</div>
<div>+    if (Error)</div>
<div>+      return "";</div>
<div>+  }</div>
<div>+  Pos -= (n + 1);</div>
<div>   return Tok;</div>
<div> }</div>
<div> </div>
<div>diff --git a/ELF/ScriptParser.h b/ELF/ScriptParser.h</div>
<div>index 264c497..944cc67 100644</div>
<div>--- a/ELF/ScriptParser.h</div>
<div>+++ b/ELF/ScriptParser.h</div>
<div>@@ -28,7 +28,7 @@ public:</div>
<div>   static StringRef skipSpace(StringRef S);</div>
<div>   bool atEOF();</div>
<div>   StringRef next();</div>
<div>-  StringRef peek();</div>
<div>+  StringRef peek(size_t n = 0);</div>
<div>   void skip();</div>
<div>   bool consume(StringRef Tok);</div>
<div>   void expect(StringRef Expect);</div>
<div>
<div>==============================<wbr>=============================</div>
</div>
</span><div><div class="gmail-h5"><span><br>
</span>
<div><br>
<div>
<blockquote type="cite">
<div>On Feb 3, 2017, at 1:21 PM, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:</div>
<br class="gmail-m_-8145904379372979866Apple-interchange-newline">
<div>
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Fri, Feb 3, 2017 at 1:19 PM, Mikulin, Dmitry via llvm-commits
<span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span><br>
> On Feb 3, 2017, at 10:30 AM, Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>> wrote:<br>
><br>
> Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>> writes:<br>
><br>
>> Does this accept "{ global: local; }”?<br>
<br>
</span>Meaning ‘a global named “local”’? Yeah, that’s a problem. We need a test case for this.<br>
I’ll fix it.<br>
</blockquote>
<div><br>
</div>
<div>Does that require to change the grammar from LL(1) to LL(2)? I think the current parser is LL(1).</div>
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Dmitry.<br>
<div class="gmail-m_-8145904379372979866HOEnZb">
<div class="gmail-m_-8145904379372979866h5"><br>
<br>
>><br>
><br>
> No, it fails.<br>
><br>
> Dimitry, can you take a look?<br>
><br>
> Cheers,<br>
> Rafael<br>
><br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div></div></div>

</blockquote></div><br></div></div>