[cfe-dev] Codegen for Character Literals and Conditional Operator

Chris Lattner clattner at apple.com
Thu Jul 12 22:18:44 PDT 2007


On Jul 12, 2007, at 9:58 PM, Keith Bauer wrote:

> Both in one patch, and the test case that Chris didn't commit last
> time is in there too...
>
> I'll split the patch up if somebody wants it split.

Splitting it up is good in that it lets us apply patches  
independently.  I applied the patch, but here are some comments for  
follow-up:

@@ -291,8 +292,14 @@
  }

  void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
-  // FIXME: print value.
-  OS << "x";
+  unsigned value = Node->getValue();
+  if (isprint(value)) {
+    OS << "'" << (char)value << "'";
+  } else {
+    // FIXME something to indicate this is a character literal?
+    OS << std::hex << std::setiosflags(std::ios_base::showbase) <<  
value
+       << std::dec << std::resetiosflags(std::ios_base::showbase);
+  }
  }


This should only print the 'x' syntax if the type is 'char'.  If it  
is something else, it should print L'x'.

For the fixme, you could print it as charliteral(0x1235) or something.


Also, your ?: code won't work correctly for structs.  That's ok,  
because structs are completely unimplemented, but please add a fixme.

-Chris



More information about the cfe-dev mailing list