<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 11, 2008, at 7:59 PM, Chris Goller wrote:</div><br class="Apple-interchange-newline"><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><br><div>Ah, I see what you're talking about (PPDirectives.cpp):</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">/// isCXXNamedOperator - Returns "true" if the token is a named operator in C++.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #aa0d91">static</span> <span style="color: #aa0d91">bool</span> isCXXNamedOperator(<span style="color: #aa0d91">const</span> <span style="color: #3f6e74">std</span>::<span style="color: #3f6e74">string</span> &<span style="color: #3f6e74">Spelling</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">  <span style="color: #aa0d91">return</span> <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"and"</span> || <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"bitand"</span> || <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"bitor"</span> ||</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">    <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"compl"</span> || <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"not"</span> || <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"not_eq"</span> ||</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">    <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"or"</span> || <span style="color: #3f6e74">Spelling</span> == <span style="color: #c41a16">"xor"</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">}</div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-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 class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">  <span style="color: #3f6e74">IdentifierInfo</span> *<span style="color: #3f6e74">II</span> = MacroNameTok.<span style="color: #26474b">getIdentifierInfo</span>();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">  <span style="color: #aa0d91">if</span> (<span style="color: #3f6e74">II</span> == <span style="color: #1c00cf">0</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">    <span style="color: #3f6e74">std</span>::<span style="color: #3f6e74">string</span> <span style="color: #3f6e74">Spelling</span> = <span style="color: #26474b">getSpelling</span>(MacroNameTok);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(38, 71, 75); "><span style="color: #000000">    </span><span style="color: #aa0d91">if</span><span style="color: #000000"> (</span>isCXXNamedOperator<span style="color: #000000">(</span><span style="color: #3f6e74">Spelling</span><span style="color: #000000">))</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000">      </span>// C++ 2.5p2: Alternative tokens behave the same as its primary token</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000">      </span>// except for their spellings.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(38, 71, 75); "><span style="color: #000000">      </span>Diag<span style="color: #000000">(MacroNameTok, diag::</span>err_pp_operator_used_as_macro_name<span style="color: #000000">) << </span><span style="color: #3f6e74">Spelling</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">    <span style="color: #aa0d91">else</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(38, 71, 75); "><span style="color: #000000">      </span>Diag<span style="color: #000000">(MacroNameTok, diag::</span>err_pp_macro_not_identifier<span style="color: #000000">);</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><div>-Chris</div></span></font></div></div></body></html>