buf.writestring (s);
}
- message ("%.*s", (int) buf.offset, (char *) buf.data);
+ message ("%s", buf.peekChars ());
}
}
buf.doindent = 1;
moduleToBuffer (&buf, m);
- message ("%.*s", (int) buf.offset, (char *) buf.data);
+ message ("%s", buf.peekChars ());
}
}
-4f1046222f3a15a746ad2455e1099ed31e39b554
+5fc1806cd7dd281e944022df2e11ef6b04ee4339
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
else
buffer.writeUTF16(c);
}
- newlen = buffer.offset / 2;
+ newlen = buffer.length() / 2;
buffer.writeUTF16(0);
goto L1;
else
buffer.writeUTF8(c);
}
- newlen = buffer.offset;
+ newlen = buffer.length();
buffer.writeUTF8(0);
goto L1;
buffer.writeUTF8(c);
newlen++;
}
- newlen = buffer.offset;
+ newlen = buffer.length();
buffer.writeUTF8(0);
goto L1;
buffer.writeUTF16(c);
newlen++;
}
- newlen = buffer.offset / 2;
+ newlen = buffer.length() / 2;
buffer.writeUTF16(0);
goto L1;
size_t end = *pend;
assert(start <= end);
- assert(end <= buf->offset);
+ assert(end <= buf->length());
/* First pass - replace $0
*/
arg = memdup(arg, arglen);
for (size_t u = start; u + 1 < end; )
{
- utf8_t *p = (utf8_t *)buf->data; // buf->data is not loop invariant
+ utf8_t *p = (utf8_t *)buf->slice().ptr; // buf->slice().ptr is not loop invariant
/* Look for $0, but not $$0, and replace it with arg.
*/
{
// Replace '$1' with '\xFF{arg\xFF}'
//printf("Replacing '$%c' with '\xFF{%.*s\xFF}'\n", p[u + 1], marglen, marg);
- buf->data[u] = 0xFF;
- buf->data[u + 1] = '{';
+ buf->slice().ptr[u] = 0xFF;
+ buf->slice().ptr[u + 1] = '{';
buf->insert(u + 2, marg, marglen);
buf->insert(u + 2 + marglen, (const char *)"\xFF}", 2);
end += -2 + 2 + marglen + 2;
u = mend;
}
//printf("u = %d, end = %d\n", u, end);
- //printf("#%.*s#\n", end, &buf->data[0]);
+ //printf("#%.*s#\n", end, &buf->slice().ptr[0]);
continue;
}
*/
for (size_t u = start; u + 4 < end; )
{
- utf8_t *p = (utf8_t *)buf->data; // buf->data is not loop invariant
+ utf8_t *p = (utf8_t *)buf->slice().ptr; // buf->slice().ptr is not loop invariant
/* A valid start of macro expansion is $(c, where c is
* an id start character, and not $$(c.
marg = memdup(marg, marglen);
// Insert replacement text
buf->spread(v + 1, 2 + m->textlen + 2);
- buf->data[v + 1] = 0xFF;
- buf->data[v + 2] = '{';
- memcpy(buf->data + v + 3, m->text, m->textlen);
- buf->data[v + 3 + m->textlen] = 0xFF;
- buf->data[v + 3 + m->textlen + 1] = '}';
+ buf->slice().ptr[v + 1] = 0xFF;
+ buf->slice().ptr[v + 2] = '{';
+ memcpy(buf->slice().ptr + v + 3, m->text, m->textlen);
+ buf->slice().ptr[v + 3 + m->textlen] = 0xFF;
+ buf->slice().ptr[v + 3 + m->textlen + 1] = '}';
end += 2 + m->textlen + 2;
u += mend - (v + 1);
mem.xfree(const_cast<utf8_t *>(marg));
//printf("u = %d, end = %d\n", u, end);
- //printf("#%.*s#\n", end - u, &buf->data[u]);
+ //printf("#%.*s#\n", end - u, &buf->slice().ptr[u]);
continue;
}
}
// Write argument types
paramsToDecoBuffer(t->parameterList.parameters);
- //if (buf->data[buf->offset - 1] == '@') halt();
+ //if (buf->slice().ptr[buf->length() - 1] == '@') halt();
buf->writeByte('Z' - t->parameterList.varargs); // mark end of arg list
if (tret != NULL)
visitWithMask(tret, 0);
Mangler v(&buf2);
v.paramsToDecoBuffer(t->arguments);
const char *s = buf2.peekChars();
- int len = (int)buf2.offset;
+ int len = (int)buf2.length();
buf->printf("%d%.*s", len, len, s);
}
else
tmp.writeUTF8(c);
}
- q = (utf8_t *)tmp.data;
- qlen = tmp.offset;
+ q = (utf8_t *)tmp.slice().ptr;
+ qlen = tmp.length();
break;
case 4:
else
tmp.writeUTF8(c);
}
- q = (utf8_t *)tmp.data;
- qlen = tmp.offset;
+ q = (utf8_t *)tmp.slice().ptr;
+ qlen = tmp.length();
break;
default:
buf->writeByte(m);
buf->printf("%d_", (int)qlen); // nbytes <= 11
- for (utf8_t *p = (utf8_t *)buf->data + buf->offset, *pend = p + 2 * qlen;
+ for (utf8_t *p = (utf8_t *)buf->slice().ptr + buf->length(), *pend = p + 2 * qlen;
p < pend; p += 2, ++q)
{
utf8_t hi = *q >> 4 & 0xF;
utf8_t lo = *q & 0xF;
p[1] = (utf8_t)(lo < 10 ? lo + '0' : lo - 10 + 'a');
}
- buf->offset += 2 * qlen;
+ buf->setsize(buf->length() + 2 * qlen);
}
void visit(ArrayLiteralExp *e)
const char *m = (*ms)[j];
const char *q = strchr(m, '=');
assert(q);
- if (dotmods->offset <= (size_t)(q - m) && memcmp(dotmods->peekChars(), m, q - m) == 0)
+ if (dotmods->length() <= (size_t)(q - m) && memcmp(dotmods->peekChars(), m, q - m) == 0)
{
buf->reset();
size_t qlen = strlen(q + 1);
dbuf.writeByte(u);
}
dbuf.writeByte(0); // add 0 as sentinel for scanner
- buflen = dbuf.offset - 1; // don't include sentinel in count
+ buflen = dbuf.length() - 1; // don't include sentinel in count
buf = (utf8_t *) dbuf.extractData();
}
else
dbuf.writeByte(u);
}
dbuf.writeByte(0); // add 0 as sentinel for scanner
- buflen = dbuf.offset - 1; // don't include sentinel in count
+ buflen = dbuf.length() - 1; // don't include sentinel in count
buf = (utf8_t *) dbuf.extractData();
}
}
mbuf.write(file.buffer, file.len);
}
}
- DocComment::parseMacros(&m->escapetable, &m->macrotable, (utf8_t *)mbuf.data, mbuf.offset);
+ DocComment::parseMacros(&m->escapetable, &m->macrotable, (utf8_t *)mbuf.slice().ptr, mbuf.length());
Scope *sc = Scope::createGlobal(m); // create root scope
emitMemberComments(m, &buf, sc);
}
- //printf("BODY= '%.*s'\n", buf.offset, buf.data);
- Macro::define(&m->macrotable, (const utf8_t *)"BODY", 4, (const utf8_t *)buf.data, buf.offset);
+ //printf("BODY= '%.*s'\n", buf.length(), buf.slice().ptr);
+ Macro::define(&m->macrotable, (const utf8_t *)"BODY", 4, (const utf8_t *)buf.slice().ptr, buf.length());
OutBuffer buf2;
buf2.writestring("$(DDOC)\n");
- size_t end = buf2.offset;
+ size_t end = buf2.length();
m->macrotable->expand(&buf2, 0, &end, NULL, 0);
/* Remove all the escape sequences from buf2,
*/
{
buf.setsize(0);
- buf.reserve(buf2.offset);
- utf8_t *p = (utf8_t *)buf2.data;
- for (size_t j = 0; j < buf2.offset; j++)
+ buf.reserve(buf2.length());
+ utf8_t *p = (utf8_t *)buf2.slice().ptr;
+ for (size_t j = 0; j < buf2.length(); j++)
{
utf8_t c = p[j];
- if (c == 0xFF && j + 1 < buf2.offset)
+ if (c == 0xFF && j + 1 < buf2.length())
{
j++;
continue;
else if (c == '\r')
{
buf.writestring("\r\n");
- if (j + 1 < buf2.offset && p[j + 1] == '\n')
+ if (j + 1 < buf2.length() && p[j + 1] == '\n')
{
j++;
}
// Transfer image to file
assert(m->docfile);
- m->docfile->setbuffer(buf.data, buf.offset);
+ m->docfile->setbuffer(buf.slice().ptr, buf.length());
m->docfile->ref = 1;
ensurePathToNameExists(Loc(), m->docfile->toChars());
writeFile(m->loc, m->docfile);
*/
void escapeDdocString(OutBuffer *buf, size_t start)
{
- for (size_t u = start; u < buf->offset; u++)
+ for (size_t u = start; u < buf->length(); u++)
{
- utf8_t c = buf->data[u];
+ utf8_t c = buf->slice().ptr[u];
switch(c)
{
case '$':
{
unsigned par_open = 0;
- for (size_t u = start; u < buf->offset; u++)
+ for (size_t u = start; u < buf->length(); u++)
{
- utf8_t c = buf->data[u];
+ utf8_t c = buf->slice().ptr[u];
switch(c)
{
case '(':
if (par_open) // if any unmatched lparens
{
par_open = 0;
- for (size_t u = buf->offset; u > start;)
+ for (size_t u = buf->length(); u > start;)
{
u--;
- utf8_t c = buf->data[u];
+ utf8_t c = buf->slice().ptr[u];
switch(c)
{
case ')':
else if (sds->isModule())
m = "$(DDOC_MODULE_MEMBERS ";
- size_t offset1 = buf->offset; // save starting offset
+ size_t offset1 = buf->length(); // save starting offset
buf->writestring(m);
- size_t offset2 = buf->offset; // to see if we write anything
+ size_t offset2 = buf->length(); // to see if we write anything
sc = sc->push(sds);
sc->pop();
- if (buf->offset == offset2)
+ if (buf->length() == offset2)
{
/* Didn't write out any members, so back out last write
*/
- buf->offset = offset1;
+ buf->setsize(offset1);
}
else
buf->writestring(")\n");
if (i == 0)
{
- size_t o = buf->offset;
+ size_t o = buf->length();
toDocBuffer(sx, buf, sc);
highlightCode(sc, sx, buf, o);
continue;
buf->writestring("$(DDOC_DITTO ");
{
- size_t o = buf->offset;
+ size_t o = buf->length();
toDocBuffer(sx, buf, sc);
highlightCode(sc, sx, buf, o);
}
emitMemberComments(sds, buf, sc);
}
buf->writestring(ddoc_decl_dd_e);
- //printf("buf.2 = [[%.*s]]\n", buf->offset - o0, buf->data + o0);
+ //printf("buf.2 = [[%.*s]]\n", buf->length() - o0, buf->slice().ptr + o0);
}
if (s)
loc = m->md->loc;
}
- size_t offset1 = buf->offset;
+ size_t offset1 = buf->length();
buf->writestring("$(DDOC_SECTIONS ");
- size_t offset2 = buf->offset;
+ size_t offset2 = buf->length();
for (size_t i = 0; i < sections.length; i++)
{
if (!sec->namelen && i == 0)
{
buf->writestring("$(DDOC_SUMMARY ");
- size_t o = buf->offset;
+ size_t o = buf->length();
buf->write(sec->body, sec->bodylen);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, a, buf, o);
buf->writestring("$(DDOC_EXAMPLES ");
- size_t o = buf->offset;
+ size_t o = buf->length();
buf->writestring((const char *)c);
if (utd->codedoc)
}
}
- if (buf->offset == offset2)
+ if (buf->length() == offset2)
{
/* Didn't write out any sections, so back out last write
*/
- buf->offset = offset1;
+ buf->setsize(offset1);
buf->writestring("$(DDOC_BLANKLINE)\n");
}
else
// Replace _ characters with spaces
buf->writestring("$(DDOC_SECTION_H ");
- size_t o = buf->offset;
+ size_t o = buf->length();
for (size_t u = 0; u < namelen; u++)
{
utf8_t c = name[u];
buf->writestring("$(DDOC_DESCRIPTION ");
}
L1:
- size_t o = buf->offset;
+ size_t o = buf->length();
buf->write(body, bodylen);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, a, buf, o);
{
buf->writestring("$(DDOC_PARAM_ID ");
{
- size_t o = buf->offset;
+ size_t o = buf->length();
Parameter *fparam = isFunctionParameter(a, namestart, namelen);
if (!fparam)
{
buf->writestring("$(DDOC_PARAM_DESC ");
{
- size_t o = buf->offset;
+ size_t o = buf->length();
buf->write(textstart, textlen);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, a, buf, o);
size_t skiptoident(OutBuffer *buf, size_t i)
{
- while (i < buf->offset)
+ while (i < buf->length())
{
dchar_t c;
size_t oi = i;
- if (utf_decodeChar((utf8_t *)buf->data, buf->offset, &i, &c))
+ if (utf_decodeChar((utf8_t *)buf->slice().ptr, buf->length(), &i, &c))
{
/* Ignore UTF errors, but still consume input
*/
size_t skippastident(OutBuffer *buf, size_t i)
{
- while (i < buf->offset)
+ while (i < buf->length())
{
dchar_t c;
size_t oi = i;
- if (utf_decodeChar((utf8_t *)buf->data, buf->offset, &i, &c))
+ if (utf_decodeChar((utf8_t *)buf->slice().ptr, buf->length(), &i, &c))
{
/* Ignore UTF errors, but still consume input
*/
size_t skippastURL(OutBuffer *buf, size_t i)
{
- size_t length = buf->offset - i;
- utf8_t *p = (utf8_t *)&buf->data[i];
+ size_t length = buf->length() - i;
+ utf8_t *p = (utf8_t *)&buf->slice().ptr[i];
size_t j;
unsigned sawdot = 0;
size_t iLineStart = offset;
- for (size_t i = offset; i < buf->offset; i++)
+ for (size_t i = offset; i < buf->length(); i++)
{
- utf8_t c = buf->data[i];
+ utf8_t c = buf->slice().ptr[i];
Lcont:
switch (c)
}
if (!sc->_module->isDocFile &&
- !inCode && i == iLineStart && i + 1 < buf->offset) // if "\n\n"
+ !inCode && i == iLineStart && i + 1 < buf->length()) // if "\n\n"
{
static const char blankline[] = "$(DDOC_BLANKLINE)\n";
leadingBlank = 0;
if (inCode)
break;
- utf8_t *p = (utf8_t *)&buf->data[i];
+ utf8_t *p = (utf8_t *)&buf->slice().ptr[i];
const char *se = sc->_module->escapetable->escapeChar('<');
if (se && strcmp(se, "<") == 0)
{
p += 4;
while (1)
{
- if (j == buf->offset)
+ if (j == buf->length())
goto L1;
if (p[0] == '-' && p[1] == '-' && p[2] == '>')
{
p += 2;
while (1)
{
- if (j == buf->offset)
+ if (j == buf->length())
break;
if (p[0] == '>')
{
leadingBlank = 0;
if (inCode)
break;
- utf8_t *p = (utf8_t *)&buf->data[i];
+ utf8_t *p = (utf8_t *)&buf->slice().ptr[i];
if (p[1] == '#' || isalpha(p[1]))
break; // already a character entity
// Replace '&' with '&' character entity
OutBuffer codebuf;
- codebuf.write(buf->data + iCodeStart + 1, i - (iCodeStart + 1));
+ codebuf.write(buf->slice().ptr + iCodeStart + 1, i - (iCodeStart + 1));
// escape the contents, but do not perform highlighting except for DDOC_PSYMBOL
highlightCode(sc, a, &codebuf, 0);
static const char pre[] = "$(DDOC_BACKQUOTED ";
i = buf->insert(iCodeStart, pre, strlen(pre));
- i = buf->insert(i, (char *)codebuf.data, codebuf.offset);
+ i = buf->insert(i, (char *)codebuf.slice().ptr, codebuf.length());
i = buf->insert(i, ")", 1);
i--; // point to the ending ) so when the for loop does i++, it will see the next character
while (1)
{
++i;
- if (i >= buf->offset)
+ if (i >= buf->length())
break;
- c = buf->data[i];
+ c = buf->slice().ptr[i];
if (c == '\n')
{
eollen = 1;
if (c == '\r')
{
eollen = 1;
- if (i + 1 >= buf->offset)
+ if (i + 1 >= buf->length())
break;
- if (buf->data[i + 1] == '\n')
+ if (buf->slice().ptr[i + 1] == '\n')
{
eollen = 2;
break;
// The code section is from iCodeStart to i
OutBuffer codebuf;
- codebuf.write(buf->data + iCodeStart, i - iCodeStart);
+ codebuf.write(buf->slice().ptr + iCodeStart, i - iCodeStart);
codebuf.writeByte(0);
// Remove leading indentations from all lines
bool lineStart = true;
- utf8_t *endp = (utf8_t *)codebuf.data + codebuf.offset;
- for (utf8_t *p = (utf8_t *)codebuf.data; p < endp; )
+ utf8_t *endp = (utf8_t *)codebuf.slice().ptr + codebuf.length();
+ for (utf8_t *p = (utf8_t *)codebuf.slice().ptr; p < endp; )
{
if (lineStart)
{
utf8_t *q = p;
while (j-- > 0 && q < endp && isIndentWS(q))
++q;
- codebuf.remove(p - (utf8_t *)codebuf.data, q - p);
- assert((utf8_t *)codebuf.data <= p);
- assert(p < (utf8_t *)codebuf.data + codebuf.offset);
+ codebuf.remove(p - (utf8_t *)codebuf.slice().ptr, q - p);
+ assert((utf8_t *)codebuf.slice().ptr <= p);
+ assert(p < (utf8_t *)codebuf.slice().ptr + codebuf.length());
lineStart = false;
- endp = (utf8_t *)codebuf.data + codebuf.offset; // update
+ endp = (utf8_t *)codebuf.slice().ptr + codebuf.length(); // update
continue;
}
if (*p == '\n')
highlightCode2(sc, a, &codebuf, 0);
buf->remove(iCodeStart, i - iCodeStart);
- i = buf->insert(iCodeStart, codebuf.data, codebuf.offset);
+ i = buf->insert(iCodeStart, codebuf.slice().ptr, codebuf.length());
i = buf->insert(i, (const char *)")\n", 2);
i -= 2; // in next loop, c should be '\n'
}
if (sc->_module->isDocFile || inCode)
break;
- utf8_t *start = (utf8_t *)buf->data + i;
+ utf8_t *start = (utf8_t *)buf->slice().ptr + i;
if (isIdStart(start))
{
size_t j = skippastident(buf, i);
// leading '_' means no highlight unless it's a reserved symbol name
if (c == '_' &&
(i == 0 || !isdigit(*(start - 1))) &&
- (i == buf->offset - 1 || !isReservedName(start, len)))
+ (i == buf->length() - 1 || !isReservedName(start, len)))
{
buf->remove(i, 1);
i = j - 1;
//printf("highlightCode(s = %s '%s')\n", s->kind(), s->toChars());
OutBuffer ancbuf;
emitAnchor(&ancbuf, s, sc);
- buf->insert(offset, (char *)ancbuf.data, ancbuf.offset);
- offset += ancbuf.offset;
+ buf->insert(offset, (char *)ancbuf.slice().ptr, ancbuf.length());
+ offset += ancbuf.length();
Dsymbols a;
a.push(s);
{
//printf("highlightCode(a = '%s')\n", a->toChars());
- for (size_t i = offset; i < buf->offset; i++)
+ for (size_t i = offset; i < buf->length(); i++)
{
- utf8_t c = buf->data[i];
+ utf8_t c = buf->slice().ptr[i];
const char *se = sc->_module->escapetable->escapeChar(c);
if (se)
{
continue;
}
- utf8_t *start = (utf8_t *)buf->data + i;
+ utf8_t *start = (utf8_t *)buf->slice().ptr + i;
if (isIdStart(start))
{
size_t j = skippastident(buf, i);
void highlightCode2(Scope *sc, Dsymbols *a, OutBuffer *buf, size_t offset)
{
unsigned errorsave = global.errors;
- Lexer lex(NULL, (utf8_t *)buf->data, 0, buf->offset - 1, 0, 1);
+ Lexer lex(NULL, (utf8_t *)buf->slice().ptr, 0, buf->length() - 1, 0, 1);
OutBuffer res;
- const utf8_t *lastp = (utf8_t *)buf->data;
+ const utf8_t *lastp = (utf8_t *)buf->slice().ptr;
- //printf("highlightCode2('%.*s')\n", buf->offset - 1, buf->data);
- res.reserve(buf->offset);
+ //printf("highlightCode2('%.*s')\n", buf->length() - 1, buf->slice().ptr);
+ res.reserve(buf->length());
while (1)
{
Token tok;
if (highlight)
{
res.writestring(highlight);
- size_t o = res.offset;
+ size_t o = res.length();
highlightCode3(sc, &res, tok.ptr, lex.p);
if (tok.value == TOKcomment || tok.value == TOKstring)
escapeDdocString(&res, o); // Bugzilla 7656, 7715, and 10519
#pragma once
-#include "root/root.h"
+#include "root/port.h"
#include "root/stringtable.h"
#include "ast_node.h"
#include "globals.h"
else if (sz == 2) { prefix = 'w'; buf.writeword(0); }
else { prefix = 'd'; buf.write4(0); }
- const size_t len = buf.offset / sz - 1;
+ const size_t len = buf.length() / sz - 1;
StringExp *se = new StringExp(loc, buf.extractData(), len, prefix);
se->sz = sz;
se->type = type;
toCBuffer(m, &buf, &hgs);
// Transfer image to file
- m->hdrfile->setbuffer(buf.data, buf.offset);
+ m->hdrfile->setbuffer(buf.slice().ptr, buf.length());
buf.extractData();
ensurePathToNameExists(Loc(), m->hdrfile->toChars());
/* fall through */
case Tchar:
{
- size_t o = buf->offset;
+ size_t o = buf->length();
if (v == '\'')
buf->writestring("'\\''");
else if (isprint((int)v) && v != '\\')
void visit(StringExp *e)
{
buf->writeByte('"');
- size_t o = buf->offset;
+ size_t o = buf->length();
for (size_t i = 0; i < e->len; i++)
{
unsigned c = e->charAt(i);
void indent()
{
- if (buf->offset >= 1 &&
- buf->data[buf->offset - 1] == '\n')
+ if (buf->length() >= 1 &&
+ buf->slice().ptr[buf->length() - 1] == '\n')
for (int i = 0; i < indentLevel; i++)
buf->writeByte(' ');
}
void removeComma()
{
- if (buf->offset >= 2 &&
- buf->data[buf->offset - 2] == ',' &&
- (buf->data[buf->offset - 1] == '\n' || buf->data[buf->offset - 1] == ' '))
- buf->offset -= 2;
+ if (buf->length() >= 2 &&
+ buf->slice().ptr[buf->length() - 2] == ',' &&
+ (buf->slice().ptr[buf->length() - 1] == '\n' || buf->slice().ptr[buf->length() - 1] == ' '))
+ buf->setsize(buf->length() - 2);
}
void comma()
{
indentLevel--;
removeComma();
- if (buf->offset >= 2 &&
- buf->data[buf->offset - 2] == '[' &&
- buf->data[buf->offset - 1] == '\n')
- buf->offset -= 1;
- else if (!(buf->offset >= 1 &&
- buf->data[buf->offset - 1] == '['))
+ if (buf->length() >= 2 &&
+ buf->slice().ptr[buf->length() - 2] == '[' &&
+ buf->slice().ptr[buf->length() - 1] == '\n')
+ buf->setsize(buf->length() - 1);
+ else if (!(buf->length() >= 1 &&
+ buf->slice().ptr[buf->length() - 1] == '['))
{
buf->writestring("\n");
indent();
{
indentLevel--;
removeComma();
- if (buf->offset >= 2 &&
- buf->data[buf->offset - 2] == '{' &&
- buf->data[buf->offset - 1] == '\n')
- buf->offset -= 1;
+ if (buf->length() >= 2 &&
+ buf->slice().ptr[buf->length() - 2] == '{' &&
+ buf->slice().ptr[buf->length() - 1] == '\n')
+ buf->setsize(buf->length() - 1);
else
{
buf->writestring("\n");
case '`':
if (c == tc)
{
- t->len = (unsigned)stringbuffer.offset;
+ t->len = (unsigned)stringbuffer.length();
stringbuffer.writeByte(0);
- t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.length());
+ memcpy(t->ustring, stringbuffer.slice().ptr, stringbuffer.length());
stringPostfix(t);
return TOKstring;
}
{ error("odd number (%d) of hex characters in hex string", n);
stringbuffer.writeByte(v);
}
- t->len = (unsigned)stringbuffer.offset;
+ t->len = (unsigned)stringbuffer.length();
stringbuffer.writeByte(0);
- t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.length());
+ memcpy(t->ustring, stringbuffer.slice().ptr, stringbuffer.length());
stringPostfix(t);
return TOKxstring;
error("delimited string must end in %s\"", hereid->toChars());
else
error("delimited string must end in %c\"", delimright);
- t->len = (unsigned)stringbuffer.offset;
+ t->len = (unsigned)stringbuffer.length();
stringbuffer.writeByte(0);
- t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.length());
+ memcpy(t->ustring, stringbuffer.slice().ptr, stringbuffer.length());
stringPostfix(t);
return TOKstring;
}
break;
case '"':
- t->len = (unsigned)stringbuffer.offset;
+ t->len = (unsigned)stringbuffer.length();
stringbuffer.writeByte(0);
- t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ t->ustring = (utf8_t *)mem.xmalloc(stringbuffer.length());
+ memcpy(t->ustring, stringbuffer.slice().ptr, stringbuffer.length());
stringPostfix(t);
return TOKstring;
}
stringbuffer.writeByte(0);
- const char *sbufptr = (char *)stringbuffer.data;
+ const char *sbufptr = (char *)stringbuffer.slice().ptr;
TOK result;
bool isOutOfRange = false;
t->floatvalue = (isWellformedString ? CTFloat::parse(sbufptr, &isOutOfRange) : CTFloat::zero);
if (isOutOfRange && !isLong)
{
const char *suffix = (result == TOKfloat32v || result == TOKimaginary32v) ? "f" : "";
- error(scanloc, "number '%s%s' is not representable", (char *)stringbuffer.data, suffix);
+ error(scanloc, "number '%s%s' is not representable", (char *)stringbuffer.slice().ptr, suffix);
}
return result;
}
case '"':
stringbuffer.writeByte(0);
- filespec = mem.xstrdup((char *)stringbuffer.data);
+ filespec = mem.xstrdup((char *)stringbuffer.slice().ptr);
p++;
break;
return u;
}
+static void trimTrailingWhitespace(OutBuffer &buf)
+{
+ const unsigned char *s = buf.slice().ptr;
+ size_t len = buf.length();
+ while (len && (s[len - 1] == ' ' || s[len - 1] == '\t'))
+ --len;
+ buf.setsize(len);
+}
/***************************************************
* Parse doc comment embedded between t->ptr and p.
{ linestart = 0;
/* Trim preceding whitespace up to preceding \n
*/
- while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
- buf.offset--;
+ trimTrailingWhitespace(buf);
continue;
}
break;
/* Trim trailing whitespace
*/
- while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
- buf.offset--;
-
+ trimTrailingWhitespace(buf);
break;
}
buf.writeByte(c);
/* Trim trailing whitespace (if the last line does not have newline)
*/
- if (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
+ if (buf.length() && (buf.slice().ptr[buf.length() - 1] == ' ' || buf.slice().ptr[buf.length() - 1] == '\t'))
{
- while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
- buf.offset--;
+ trimTrailingWhitespace(buf);
}
// Always end with a newline
- if (!buf.offset || buf.data[buf.offset - 1] != '\n')
+ if (!buf.length() || buf.slice().ptr[buf.length() - 1] != '\n')
buf.writeByte('\n');
buf.writeByte(0);
// Combine with previous doc comment, if any
if (*dc)
- *dc = combineComments(*dc, (utf8_t *)buf.data);
+ *dc = combineComments(*dc, (utf8_t *)buf.slice().ptr);
else
*dc = (utf8_t *)buf.extractData();
}
#pragma once
#include "root/dsystem.h"
-#include "root/root.h"
+#include "root/port.h"
struct Macro
mangleToBuffer(this, &buf);
- StringValue *sv = stringtable.update((char *)buf.data, buf.offset);
+ StringValue *sv = stringtable.update((char *)buf.slice().ptr, buf.length());
if (sv->ptrvalue)
{
t = (Type *) sv->ptrvalue;
buf.reserve(32);
mangleToBuffer(this, &buf);
- size_t len = buf.offset;
+ size_t len = buf.length();
buf.writeByte(0);
// Allocate buffer on stack, fail over to using malloc()
size_t namelen = 19 + sizeof(len) * 3 + len + 1;
char *name = namelen <= sizeof(namebuf) ? namebuf : (char *)mem.xmalloc(namelen);
- int length = sprintf(name, "_D%lluTypeInfo_%s6__initZ", (unsigned long long) 9 + len, buf.data);
+ int length = sprintf(name, "_D%lluTypeInfo_%s6__initZ", (unsigned long long) 9 + len, buf.slice().ptr);
//printf("%p, deco = %s, name = %s\n", this, deco, name);
assert(0 < length && (size_t)length < namelen); // don't overflow the buffer
#include "dsystem.h"
#include "filename.h"
-
+#include "port.h"
#include "outbuffer.h"
#include "array.h"
#include "file.h"
{
char *home = getenv("HOME");
// Expand ~ only if it is prefixing the rest of the path.
- if (!buf.offset && p[1] == '/' && home)
+ if (!buf.length() && p[1] == '/' && home)
buf.writestring(home);
else
buf.writestring("~");
}
break;
}
- if (buf.offset) // if path is not empty
+ if (buf.length()) // if path is not empty
{
array->push(buf.extractChars());
}
{
char *p;
- p = (char *)data;
- data = NULL;
+ p = (char *)data.ptr;
+ data = DArray<unsigned char>();
offset = 0;
- size = 0;
return p;
}
void OutBuffer::reserve(size_t nbytes)
{
- //printf("OutBuffer::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
- if (size - offset < nbytes)
+ //printf("OutBuffer::reserve: size = %d, offset = %d, nbytes = %d\n", data.length, offset, nbytes);
+ if (data.length - offset < nbytes)
{
- size = (offset + nbytes) * 2;
- size = (size + 15) & ~15;
- data = (unsigned char *)mem.xrealloc(data, size);
+ data.length = (offset + nbytes) * 2;
+ data.length = (data.length + 15) & ~15;
+ data.ptr = (unsigned char *)mem.xrealloc(data.ptr, data.length);
}
}
reserve(level);
for (int i = 0; i < level; i++)
{
- this->data[offset] = '\t';
+ this->data.ptr[offset] = '\t';
offset++;
}
}
notlinehead = 1;
}
reserve(nbytes);
- memcpy(this->data + offset, data, nbytes);
+ memcpy(this->data.ptr + offset, data, nbytes);
offset += nbytes;
}
-void OutBuffer::writebstring(utf8_t *string)
-{
- write(string,*string + 1);
-}
-
void OutBuffer::writestring(const char *string)
{
write(string,strlen(string));
{
size_t len = strlen(string);
reserve(len);
- memmove(data + len, data, offset);
- memcpy(data, string, len);
+ memmove(data.ptr + len, data.ptr, offset);
+ memcpy(data.ptr, string, len);
offset += len;
}
reserve(level);
for (int i = 0; i < level; i++)
{
- this->data[offset] = '\t';
+ this->data.ptr[offset] = '\t';
offset++;
}
}
notlinehead = 1;
}
reserve(1);
- this->data[offset] = (unsigned char)b;
+ this->data.ptr[offset] = (unsigned char)b;
offset++;
}
reserve(6);
if (b <= 0x7F)
{
- this->data[offset] = (unsigned char)b;
+ this->data.ptr[offset] = (unsigned char)b;
offset++;
}
else if (b <= 0x7FF)
{
- this->data[offset + 0] = (unsigned char)((b >> 6) | 0xC0);
- this->data[offset + 1] = (unsigned char)((b & 0x3F) | 0x80);
+ this->data.ptr[offset + 0] = (unsigned char)((b >> 6) | 0xC0);
+ this->data.ptr[offset + 1] = (unsigned char)((b & 0x3F) | 0x80);
offset += 2;
}
else if (b <= 0xFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 12) | 0xE0);
- this->data[offset + 1] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)((b & 0x3F) | 0x80);
+ this->data.ptr[offset + 0] = (unsigned char)((b >> 12) | 0xE0);
+ this->data.ptr[offset + 1] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data.ptr[offset + 2] = (unsigned char)((b & 0x3F) | 0x80);
offset += 3;
}
else if (b <= 0x1FFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 18) | 0xF0);
- this->data[offset + 1] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 3] = (unsigned char)((b & 0x3F) | 0x80);
+ this->data.ptr[offset + 0] = (unsigned char)((b >> 18) | 0xF0);
+ this->data.ptr[offset + 1] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
+ this->data.ptr[offset + 2] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data.ptr[offset + 3] = (unsigned char)((b & 0x3F) | 0x80);
offset += 4;
}
else if (b <= 0x3FFFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 24) | 0xF8);
- this->data[offset + 1] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
- this->data[offset + 3] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 4] = (unsigned char)((b & 0x3F) | 0x80);
+ this->data.ptr[offset + 0] = (unsigned char)((b >> 24) | 0xF8);
+ this->data.ptr[offset + 1] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
+ this->data.ptr[offset + 2] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
+ this->data.ptr[offset + 3] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data.ptr[offset + 4] = (unsigned char)((b & 0x3F) | 0x80);
offset += 5;
}
else if (b <= 0x7FFFFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 30) | 0xFC);
- this->data[offset + 1] = (unsigned char)(((b >> 24) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
- this->data[offset + 3] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
- this->data[offset + 4] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 5] = (unsigned char)((b & 0x3F) | 0x80);
+ this->data.ptr[offset + 0] = (unsigned char)((b >> 30) | 0xFC);
+ this->data.ptr[offset + 1] = (unsigned char)(((b >> 24) & 0x3F) | 0x80);
+ this->data.ptr[offset + 2] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
+ this->data.ptr[offset + 3] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
+ this->data.ptr[offset + 4] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data.ptr[offset + 5] = (unsigned char)((b & 0x3F) | 0x80);
offset += 6;
}
else
void OutBuffer::prependbyte(unsigned b)
{
reserve(1);
- memmove(data + 1, data, offset);
- data[0] = (unsigned char)b;
+ memmove(data.ptr + 1, data.ptr, offset);
+ data.ptr[0] = (unsigned char)b;
offset++;
}
reserve(level);
for (int i = 0; i < level; i++)
{
- this->data[offset] = '\t';
+ this->data.ptr[offset] = '\t';
offset++;
}
}
notlinehead = 1;
}
reserve(2);
- *(unsigned short *)(this->data + offset) = (unsigned short)w;
+ *(unsigned short *)(this->data.ptr + offset) = (unsigned short)w;
offset += 2;
}
reserve(4);
if (w <= 0xFFFF)
{
- *(unsigned short *)(this->data + offset) = (unsigned short)w;
+ *(unsigned short *)(this->data.ptr + offset) = (unsigned short)w;
offset += 2;
}
else if (w <= 0x10FFFF)
{
- *(unsigned short *)(this->data + offset) = (unsigned short)((w >> 10) + 0xD7C0);
- *(unsigned short *)(this->data + offset + 2) = (unsigned short)((w & 0x3FF) | 0xDC00);
+ *(unsigned short *)(this->data.ptr + offset) = (unsigned short)((w >> 10) + 0xD7C0);
+ *(unsigned short *)(this->data.ptr + offset + 2) = (unsigned short)((w & 0x3FF) | 0xDC00);
offset += 4;
}
else
reserve(level);
for (int i = 0; i < level; i++)
{
- this->data[offset] = '\t';
+ this->data.ptr[offset] = '\t';
offset++;
}
}
notlinehead = 1;
}
reserve(4);
- *(unsigned *)(this->data + offset) = w;
+ *(unsigned *)(this->data.ptr + offset) = w;
offset += 4;
}
{
if (buf)
{ reserve(buf->offset);
- memcpy(data + offset, buf->data, buf->offset);
+ memcpy(data.ptr + offset, buf->data.ptr, buf->offset);
offset += buf->offset;
}
}
void OutBuffer::fill0(size_t nbytes)
{
reserve(nbytes);
- memset(data + offset,0,nbytes);
+ memset(data.ptr + offset,0,nbytes);
offset += nbytes;
}
{
reserve(psize);
#if _WIN32
- count = _vsnprintf((char *)data + offset,psize,format,args);
+ count = _vsnprintf((char *)data.ptr + offset,psize,format,args);
if (count != -1)
break;
psize *= 2;
of ap is undefined after the call. The application should call
va_end(ap) itself afterwards.
*/
- count = vsnprintf((char *)data + offset,psize,format,va);
+ count = vsnprintf((char *)data.ptr + offset,psize,format,va);
va_end(va);
if (count == -1)
psize *= 2;
void OutBuffer::bracket(char left, char right)
{
reserve(2);
- memmove(data + 1, data, offset);
- data[0] = left;
- data[offset + 1] = right;
+ memmove(data.ptr + 1, data.ptr, offset);
+ data.ptr[0] = left;
+ data.ptr[offset + 1] = right;
offset += 2;
}
void OutBuffer::spread(size_t offset, size_t nbytes)
{
reserve(nbytes);
- memmove(data + offset + nbytes, data + offset,
+ memmove(data.ptr + offset + nbytes, data.ptr + offset,
this->offset - offset);
this->offset += nbytes;
}
size_t OutBuffer::insert(size_t offset, const void *p, size_t nbytes)
{
spread(offset, nbytes);
- memmove(data + offset, p, nbytes);
+ memmove(data.ptr + offset, p, nbytes);
return offset + nbytes;
}
void OutBuffer::remove(size_t offset, size_t nbytes)
{
- memmove(data + offset, data + offset + nbytes, this->offset - (offset + nbytes));
+ memmove(data.ptr + offset, data.ptr + offset + nbytes, this->offset - (offset + nbytes));
this->offset -= nbytes;
}
char *OutBuffer::peekChars()
{
- if (!offset || data[offset-1] != '\0')
+ if (!offset || data.ptr[offset-1] != '\0')
{
writeByte(0);
offset--; // allow appending more
}
- return (char *)data;
+ return (char *)data.ptr;
}
char *OutBuffer::extractChars()
{
- if (!offset || data[offset-1] != '\0')
+ if (!offset || data.ptr[offset-1] != '\0')
writeByte(0);
return extractData();
}
#pragma once
#include "dsystem.h"
-#include "port.h"
+#include "dcompat.h"
#include "rmem.h"
class RootObject;
struct OutBuffer
{
- unsigned char *data;
+private:
+ DArray<unsigned char> data;
size_t offset;
- size_t size;
+ bool notlinehead;
+public:
int level;
bool doindent;
-private:
- bool notlinehead;
-public:
OutBuffer()
{
- data = NULL;
+ data = DArray<unsigned char>();
offset = 0;
- size = 0;
doindent = 0;
level = 0;
}
~OutBuffer()
{
- mem.xfree(data);
+ mem.xfree(data.ptr);
}
+ const DArray<unsigned char> slice() const { return data; }
+ d_size_t length() const { return offset; }
char *extractData();
void reserve(size_t nbytes);
void setsize(size_t size);
void reset();
void write(const void *data, d_size_t nbytes);
- void writebstring(utf8_t *string);
void writestring(const char *string);
void prependstring(const char *string);
void writenl(); // write newline