/* Compiler implementation of the D programming language
- * Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved
+ * Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
* written by Walter Bright
* http://www.digitalmars.com
* Distributed under the Boost Software License, Version 1.0.
for (size_t i = 0; i < a->length; i++)
{
TypeFunction *tf = isTypeFunction((*a)[i]);
- if (tf && tf->varargs == 1 && cmp("...", p, len) == 0)
+ if (tf && tf->parameterList.varargs == VARARGvariadic && cmp("...", p, len) == 0)
return true;
}
return false;
static Parameter *isFunctionParameter(Dsymbol *s, const utf8_t *p, size_t len)
{
TypeFunction *tf = isTypeFunction(s);
- if (tf && tf->parameters)
+ if (tf && tf->parameterList.parameters)
{
- for (size_t k = 0; k < tf->parameters->length; k++)
+ for (size_t k = 0; k < tf->parameterList.parameters->length; k++)
{
- Parameter *fparam = (*tf->parameters)[k];
+ Parameter *fparam = (*tf->parameterList.parameters)[k];
if (fparam->ident && cmp(fparam->ident->toChars(), p, len) == 0)
{
return fparam;
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 ')':
{
OutBuffer anc;
emitAnchorName(&anc, s, skipNonQualScopes(sc));
- ident = Identifier::idPool(anc.peekString());
+ ident = Identifier::idPool(anc.peekChars());
}
size_t *count = (size_t*)dmd_aaGet(&sc->anchorCounts, (void *)ident);
TemplateDeclaration *td = getEponymousParent(s);
/** Recursively expand template mixin member docs into the scope. */
static void expandTemplateMixinComments(TemplateMixin *tm, OutBuffer *buf, Scope *sc)
{
- if (!tm->semanticRun) tm->semantic(sc);
+ if (!tm->semanticRun)
+ dsymbolSemantic(tm, sc);
TemplateDeclaration *td = (tm && tm->tempdecl) ?
tm->tempdecl->isTemplateDeclaration() : NULL;
if (td && td->members)
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");
void emitProtection(OutBuffer *buf, Prot prot)
{
- if (prot.kind != PROTundefined && prot.kind != PROTpublic)
+ if (prot.kind != Prot::undefined && prot.kind != Prot::public_)
{
protectionToBuffer(buf, prot);
buf->writeByte(' ');
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)
return;
if (!d->type && !d->isCtorDeclaration() && !d->isAliasDeclaration())
return;
- if (d->protection.kind == PROTprivate || sc->protection.kind == PROTprivate)
+ if (d->protection.kind == Prot::private_ || sc->protection.kind == Prot::private_)
return;
}
if (!com)
}
else
{
- if (ad->prot().kind == PROTprivate || sc->protection.kind == PROTprivate)
+ if (ad->prot().kind == Prot::private_ || sc->protection.kind == Prot::private_)
return;
if (!ad->comment)
return;
void visit(TemplateDeclaration *td)
{
//printf("TemplateDeclaration::emitComment() '%s', kind = %s\n", td->toChars(), td->kind());
- if (td->prot().kind == PROTprivate || sc->protection.kind == PROTprivate)
+ if (td->prot().kind == Prot::private_ || sc->protection.kind == Prot::private_)
return;
if (!td->comment)
return;
void visit(EnumDeclaration *ed)
{
- if (ed->prot().kind == PROTprivate || sc->protection.kind == PROTprivate)
+ if (ed->prot().kind == Prot::private_ || sc->protection.kind == Prot::private_)
return;
if (ed->isAnonymous() && ed->members)
{
void visit(EnumMember *em)
{
//printf("EnumMember::emitComment(%p '%s'), comment = '%s'\n", em, em->toChars(), em->comment);
- if (em->prot().kind == PROTprivate || sc->protection.kind == PROTprivate)
+ if (em->prot().kind == Prot::private_ || sc->protection.kind == Prot::private_)
return;
if (!em->comment)
return;
emitProtection(buf, ad->protection);
buf->printf("alias %s = ", ad->toChars());
- if (Dsymbol *s = ad->aliassym) // ident alias
+ if (Dsymbol *sa = ad->aliassym) // ident alias
{
- prettyPrintDsymbol(s, ad->parent);
+ prettyPrintDsymbol(sa, ad->parent);
}
else if (Type *type = ad->getType()) // type alias
{
buf->writestring(": ");
any = 1;
}
- emitProtection(buf, Prot(PROTpublic));
+ emitProtection(buf, Prot(Prot::public_));
if (bc->sym)
{
buf->printf("$(DDOC_PSUPER_SYMBOL %s)", bc->sym->toPrettyChars());
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);
for (UnitTestDeclaration *utd = s->ddocUnittest; utd; utd = utd->ddocUnittest)
{
- if (utd->protection.kind == PROTprivate || !utd->comment || !utd->fbody)
+ if (utd->protection.kind == Prot::private_ || !utd->comment || !utd->fbody)
continue;
// Strip whitespaces to avoid showing empty summary
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);
TypeFunction *tf = a->length == 1 ? isTypeFunction(s) : NULL;
if (tf)
{
- size_t pcount = (tf->parameters ? tf->parameters->length : 0) + (int)(tf->varargs == 1);
+ size_t pcount = (tf->parameterList.parameters ? tf->parameterList.parameters->length : 0) +
+ (int)(tf->parameterList.varargs == VARARGvariadic);
if (pcount != paramcount)
{
warning(s->loc, "Ddoc: parameter count mismatch");
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