this is what I've been using to dump a SourceRange:<div><br><div><div>void DumpSourceRange(SourceRange sr, SourceManager& sm) {</div><div>  const char* b = sm.getCharacterData(sr.getBegin());</div><div>  const char* e = sm.getCharacterData(sr.getEnd())+1; // include last character</div>
<div>  llvm::errs() << llvm::StringRef(b, e - b) << "\n";</div><div>}</div><div><br></div><div>I don't think there's a "Right way" to do it. If there were it would probably be a method on SourceManager though.</div>
<div><br></div><div>--Sean Silva</div><br><div class="gmail_quote">On Mon, Mar 5, 2012 at 1:35 PM, Philip Reames <span dir="ltr"><<a href="mailto:listmail@philipreames.com">listmail@philipreames.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Over the weekend, I took a look at an easy diagnostic bug.<br>
(<a href="http://llvm.org/bugs/show_bug.cgi?id=9243" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=9243</a>)  Essentially, the issue<br>
comes down to how to report duplicate case values when some of the<br>
values are enums or chars.  As shown today, we show the actual integer<br>
value of the case value.  This is sometimes confusing.<br>
<br>
My proposed syntax for the revised error is:<br>
CGDecl.cpp:85:8: error: duplicate case for 'Decl::Label' (underlying<br>
value '6')<br>
   case Decl::Label:        // __label__ x;<br>
        ^<br>
CGDecl.cpp:73:8: note: previous case defined here<br>
   case Decl::Label:<br>
<br>
After some digging around, I couldn't find a way to get the actual text<br>
of a given source range.  Is there an easy way (within Sema) to get<br>
this?  I tried playing tricks with looking up enum values from the<br>
underlying integer, but that has edge cases I wouldn't want to actually<br>
check in.<br>
<br>
The second question I had was whether we should add a warning for the<br>
use of non-enum labels when switching on an enum value.  While this is<br>
certainly valid C/C++, it's probably not best practice.  Are best<br>
practice style warnings something we want to include?  Or is that better<br>
off in a separate tool?<br>
<br>
Yours,<br>
Philip Reames<br>
<br>
<br>
Here's the c++ test case I've been using.<br>
<br>
enum Foo {A=0,B};<br>
<br>
int main() {<br>
   Foo a = A;<br>
   switch(a) {<br>
   case A:<br>
   case A:<br>
     break;<br>
   };<br>
<br>
   switch(a) {<br>
   case A:<br>
   case 0:<br>
     break;<br>
   };<br>
<br>
   switch(a) {<br>
   case 0:<br>
   case 1:<br>
     break;<br>
   };<br>
<br>
   switch(a) {<br>
   case A:<br>
   case '\0':<br>
     break;<br>
   };<br>
<br>
   char b = '0';<br>
   switch(b) {<br>
   case 'a':<br>
   case 'a':<br>
     break;<br>
   };<br>
<br>
#define CASE1 case 'a':<br>
   switch(b) {<br>
   CASE1<br>
   CASE1<br>
     break;<br>
   };<br>
<br>
   return 0;<br>
}<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>