{
visit((Type *)t);
if (t->dim)
- buf->printf("%llu", t->dim->toInteger());
+ buf->print(t->dim->toInteger());
if (t->next)
visitWithMask(t->next, t->mod);
}
visit((Type *)t);
const char *name = t->ident->toChars();
size_t len = strlen(name);
- buf->printf("%u%s", (unsigned)len, name);
+ buf->print(len);
+ buf->writestring(name);
}
void visit(TypeEnum *t)
s->error("excessive length %llu for symbol, possible recursive expansion?", buf->length() + len);
else
{
- buf->printf("%llu", (ulonglong)len);
+ buf->print(len);
buf->write(id, len);
}
}
void visit(IntegerExp *e)
{
if ((sinteger_t)e->value < 0)
- buf->printf("N%lld", -e->value);
+ {
+ buf->writeByte('N');
+ buf->print(-e->value);
+ }
else
- buf->printf("i%lld", e->value);
+ {
+ buf->writeByte('i');
+ buf->print(e->value);
+ }
}
void visit(RealExp *e)
}
buf->reserve(1 + 11 + 2 * qlen);
buf->writeByte(m);
- buf->printf("%d_", (int)qlen); // nbytes <= 11
+ buf->print(qlen);
+ buf->writeByte('_'); // nbytes <= 11
for (utf8_t *p = (utf8_t *)buf->slice().ptr + buf->length(), *pend = p + 2 * qlen;
p < pend; p += 2, ++q)
void visit(ArrayLiteralExp *e)
{
size_t dim = e->elements ? e->elements->length : 0;
- buf->printf("A%u", dim);
+ buf->writeByte('A');
+ buf->print(dim);
for (size_t i = 0; i < dim; i++)
{
e->getElement(i)->accept(this);
void visit(AssocArrayLiteralExp *e)
{
size_t dim = e->keys->length;
- buf->printf("A%u", dim);
+ buf->writeByte('A');
+ buf->print(dim);
for (size_t i = 0; i < dim; i++)
{
(*e->keys)[i]->accept(this);
void visit(StructLiteralExp *e)
{
size_t dim = e->elements ? e->elements->length : 0;
- buf->printf("S%u", dim);
+ buf->writeByte('S');
+ buf->print(dim);
for (size_t i = 0; i < dim; i++)
{
Expression *ex = (*e->elements)[i];
va_end(ap);
}
+/**************************************
+ * Convert `u` to a string and append it to the buffer.
+ * Params:
+ * u = integral value to append
+ */
+void OutBuffer::print(unsigned long long u)
+{
+ unsigned long long value = u;
+ char buf[20];
+ const unsigned radix = 10;
+
+ size_t i = sizeof(buf);
+ do
+ {
+ if (value < radix)
+ {
+ unsigned char x = (unsigned char)value;
+ buf[--i] = (char)(x + '0');
+ break;
+ }
+ else
+ {
+ unsigned char x = (unsigned char)(value % radix);
+ value = value / radix;
+ buf[--i] = (char)(x + '0');
+ }
+ } while (value);
+
+ write(buf + i, sizeof(buf) - i);
+}
+
void OutBuffer::bracket(char left, char right)
{
reserve(2);
void fill0(size_t nbytes);
void vprintf(const char *format, va_list args);
void printf(const char *format, ...);
+ void print(unsigned long long u);
void bracket(char left, char right);
size_t bracket(size_t i, const char *left, size_t j, const char *right);
void spread(size_t offset, size_t nbytes);