Oh whoops, I forgot my patch on the first email... doh!<br><br>Well, I've attached two possible patches (I really did this time!).  I'm not sure what one y'all would like to use.<br><br>The first removes the strings altogether and uses the identifiertable.  The second simply adds the missing operator aliases to the check.<br>
<br>Regards,<br><br>Chris<br><br><div class="gmail_quote">On Fri, Dec 12, 2008 at 11:15 AM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com">clattner@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style=""><br><div><div class="Ih2E3d"><div>On Dec 11, 2008, at 7:59 PM, Chris Goller wrote:</div><br></div><div class="Ih2E3d"><blockquote type="cite">Hi, I'm a first time submitter to clang (Doug G pointed me to the project).  I dipped my toe into the shallow end and came up with this operator alias patch.  All it does is add three more aliases as invalid macro tokens.<br>
 <br>Also, is there any way to get at the isCPlusPlusOperatorKeyword function at that point in the lexer?  If so, I could change the patch so all those string compares could be removed.<br clear="all"></blockquote></div></div>
<br><div>Ah, I see what you're talking about (PPDirectives.cpp):</div><div><br></div><div><div style="margin: 0px; color: rgb(0, 116, 0);">/// isCXXNamedOperator - Returns "true" if the token is a named operator in C++.</div>
<div style="margin: 0px;"><span style="color: rgb(170, 13, 145);">static</span> <span style="color: rgb(170, 13, 145);">bool</span> isCXXNamedOperator(<span style="color: rgb(170, 13, 145);">const</span> <span style="color: rgb(63, 110, 116);">std</span>::<span style="color: rgb(63, 110, 116);">string</span> &<span style="color: rgb(63, 110, 116);">Spelling</span>) {</div>
<div style="margin: 0px;">  <span style="color: rgb(170, 13, 145);">return</span> <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"and"</span> || <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"bitand"</span> || <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"bitor"</span> ||</div>
<div style="margin: 0px;">    <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"compl"</span> || <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"not"</span> || <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"not_eq"</span> ||</div>
<div style="margin: 0px;">    <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"or"</span> || <span style="color: rgb(63, 110, 116);">Spelling</span> == <span style="color: rgb(196, 26, 22);">"xor"</span>;</div>
<div style="margin: 0px;">}</div><div><font size="2" face="Monaco"><span style="font-size: 10px;"><br></span></font></div><div><font size="2" face="Monaco"><span style="font-size: 10px;">You're right that it is really ugly!  The issue here is that the only caller is this code:</span></font></div>
<div><font size="2" face="Monaco"><span style="font-size: 10px;"><br></span></font></div><div><font size="2" face="Monaco"><span style="font-size: 10px;"><div style="margin: 0px;">  <span style="color: rgb(63, 110, 116);">IdentifierInfo</span> *<span style="color: rgb(63, 110, 116);">II</span> = MacroNameTok.<span style="color: rgb(38, 71, 75);">getIdentifierInfo</span>();</div>
<div style="margin: 0px;">  <span style="color: rgb(170, 13, 145);">if</span> (<span style="color: rgb(63, 110, 116);">II</span> == <span style="color: rgb(28, 0, 207);">0</span>) {</div><div style="margin: 0px;">    <span style="color: rgb(63, 110, 116);">std</span>::<span style="color: rgb(63, 110, 116);">string</span> <span style="color: rgb(63, 110, 116);">Spelling</span> = <span style="color: rgb(38, 71, 75);">getSpelling</span>(MacroNameTok);</div>
<div style="margin: 0px; color: rgb(38, 71, 75);"><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(170, 13, 145);">if</span><span style="color: rgb(0, 0, 0);"> (</span>isCXXNamedOperator<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(63, 110, 116);">Spelling</span><span style="color: rgb(0, 0, 0);">))</span></div>
<div style="margin: 0px; color: rgb(0, 116, 0);"><span style="color: rgb(0, 0, 0);">      </span>// C++ 2.5p2: Alternative tokens behave the same as its primary token</div><div style="margin: 0px; color: rgb(0, 116, 0);">
<span style="color: rgb(0, 0, 0);">      </span>// except for their spellings.</div><div style="margin: 0px; color: rgb(38, 71, 75);"><span style="color: rgb(0, 0, 0);">      </span>Diag<span style="color: rgb(0, 0, 0);">(MacroNameTok, diag::</span>err_pp_operator_used_as_macro_name<span style="color: rgb(0, 0, 0);">) << </span><span style="color: rgb(63, 110, 116);">Spelling</span><span style="color: rgb(0, 0, 0);">;</span></div>
<div style="margin: 0px;">    <span style="color: rgb(170, 13, 145);">else</span></div><div style="margin: 0px; color: rgb(38, 71, 75);"><span style="color: rgb(0, 0, 0);">      </span>Diag<span style="color: rgb(0, 0, 0);">(MacroNameTok, diag::</span>err_pp_macro_not_identifier<span style="color: rgb(0, 0, 0);">);</span></div>
<div><br></div><div>This call only happens on an error case, so we don't really care about its performance.  If you're concerned about the maintenance cost of maintaining the extra list of keywords, a good solution would be to re-look-up the identifier in the identifier table (in the preprocessor).  This would let you query its isCPlusPlusOperatorKeyword field.</div>
<div><br></div><font color="#888888"><div>-Chris</div></font></span></font></div></div></div></blockquote></div><br><br clear="all"><br>-- <br>"Like a poet has to write poetry, I wake up in the morning and I have to write a computer program." -- Knuth<br>