#include <iostream>
#include <iomanip>
+#include <objc/runtime.h>
+#include <sstream>
+
_finline CYFlags operator ~(CYFlags rhs) {
return static_cast<CYFlags>(~static_cast<unsigned>(rhs));
}
void CYAddressOf::Output(std::ostream &out, CYFlags flags) const {
rhs_->Output(out, 1, CYLeft(flags));
- out << ".$()";
+ out << ".addressOf()";
}
void CYArgument::Output(std::ostream &out) const {
void CYSend::Output(std::ostream &out, CYFlags flags) const {
out << "objc_msgSend(";
self_->Output(out, CYPA, CYNoFlags);
- out << ",\"";
+ out << ",";
+ std::ostringstream name;
for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
if (argument->name_ != NULL) {
- out << *argument->name_;
+ name << *argument->name_;
if (argument->value_ != NULL)
- out << ':';
+ name << ':';
}
- out << "\"";
+ out << reinterpret_cast<void *>(sel_registerName(name.str().c_str()));
for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
if (argument->value_ != NULL) {
out << ",";
}
void CYString::Output(std::ostream &out, CYFlags flags) const {
- out << '\"';
+ unsigned quot(0), apos(0);
+ for (const char *value(value_), *end(value_ + size_); value != end; ++value)
+ if (*value == '"')
+ ++quot;
+ else if (*value == '\'')
+ ++apos;
+
+ bool single(quot > apos);
+
+ out << (single ? '\'' : '"');
for (const char *value(value_), *end(value_ + size_); value != end; ++value)
switch (*value) {
- case '"': out << "\\\""; break;
case '\\': out << "\\\\"; break;
case '\b': out << "\\b"; break;
case '\f': out << "\\f"; break;
case '\t': out << "\\t"; break;
case '\v': out << "\\v"; break;
+ case '"':
+ if (!single)
+ out << "\\\"";
+ else goto simple;
+ break;
+
+ case '\'':
+ if (single)
+ out << "\\'";
+ else goto simple;
+ break;
+
default:
if (*value < 0x20 || *value >= 0x7f)
out << "\\x" << std::setbase(16) << std::setw(2) << std::setfill('0') << unsigned(*value);
- else
+ else simple:
out << *value;
}
- out << '\"';
+ out << (single ? '\'' : '"');
}
void CYSwitch::Output(std::ostream &out) const {