Skip to content

Commit

Permalink
Remove Dsymbol parameter from escapeStrayParenthesis() function
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed May 12, 2015
1 parent acbe13e commit 17023b1
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ class Section

int nooutput;

virtual void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
virtual void write(Loc loc, DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
};

class ParamSection : public Section
{
public:
void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
void write(Loc loc, DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
};

class MacroSection : public Section
{
public:
void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
void write(Loc loc, DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
};

typedef Array<Section *> Sections;
Expand Down Expand Up @@ -336,11 +336,12 @@ void gendocfile(Module *m)
buf.printf("$(DDOC_COMMENT Generated by Ddoc from %s)\n", m->srcfile->toChars());
if (m->isDocFile)
{
Loc loc = m->md ? m->md->loc : m->loc;
size_t commentlen = strlen((char *)m->comment);
if (dc->macros)
{
commentlen = dc->macros->name - m->comment;
dc->macros->write(dc, sc, m, sc->docbuf);
dc->macros->write(loc, dc, sc, m, sc->docbuf);
}
sc->docbuf->write(m->comment, commentlen);
highlightText(sc, m, sc->docbuf, 0);
Expand Down Expand Up @@ -464,16 +465,9 @@ void escapeDdocString(OutBuffer *buf, size_t start)
* Fix by replacing unmatched ( with $(LPAREN) and unmatched ) with $(RPAREN).
*/
void escapeStrayParenthesis(OutBuffer *buf, size_t start, Dsymbol *s)
void escapeStrayParenthesis(Loc loc, OutBuffer *buf, size_t start)
{
unsigned par_open = 0;
Loc loc = s->loc;

if (Module *m = s->isModule())
{
if (m->md)
loc = m->md->loc;
}

for (size_t u = start; u < buf->offset; u++)
{
Expand Down Expand Up @@ -1527,6 +1521,13 @@ void DocComment::parseSections(const utf8_t *comment)
void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
{
//printf("DocComment::writeSections()\n");
Loc loc = s->loc;
if (Module *m = s->isModule())
{
if (m->md)
loc = m->md->loc;
}

if (sections.dim || s->ddocUnittest)
{
buf->writestring("$(DDOC_SECTIONS ");
Expand All @@ -1538,13 +1539,13 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
continue;
//printf("Section: '%.*s' = '%.*s'\n", sec->namelen, sec->name, sec->bodylen, sec->body);
if (sec->namelen || i)
sec->write(this, sc, s, buf);
sec->write(loc, this, sc, s, buf);
else
{
buf->writestring("$(DDOC_SUMMARY ");
size_t o = buf->offset;
buf->write(sec->body, sec->bodylen);
escapeStrayParenthesis(buf, o, s);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, s, buf, o);
buf->writestring(")\n");
}
Expand All @@ -1563,7 +1564,7 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
/***************************************************
*/

void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
void Section::write(Loc loc, DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
{
if (namelen)
{
Expand Down Expand Up @@ -1593,7 +1594,7 @@ void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
utf8_t c = name[u];
buf->writeByte((c == '_') ? ' ' : c);
}
escapeStrayParenthesis(buf, o, s);
escapeStrayParenthesis(loc, buf, o);
buf->writestring(":)\n");
}
else
Expand All @@ -1603,15 +1604,15 @@ void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
L1:
size_t o = buf->offset;
buf->write(body, bodylen);
escapeStrayParenthesis(buf, o, s);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, s, buf, o);
buf->writestring(")\n");
}

/***************************************************
*/

void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
void ParamSection::write(Loc loc, DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
{
const utf8_t *p = body;
size_t len = bodylen;
Expand All @@ -1626,7 +1627,7 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
const utf8_t *textstart = NULL;
size_t textlen = 0;

size_t o, paramcount = 0;
size_t paramcount = 0;
Parameter *fparam = NULL;

buf->writestring("$(DDOC_PARAMS ");
Expand Down Expand Up @@ -1684,8 +1685,10 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
++paramcount;
HdrGenState hgs;
buf->writestring("$(DDOC_PARAM_ROW ");
{
buf->writestring("$(DDOC_PARAM_ID ");
o = buf->offset;
{
size_t o = buf->offset;
fparam = isFunctionParameter(s, namestart, namelen);
bool isCVariadic = isCVariadicParameter(s, namestart, namelen);
if (isCVariadic)
Expand All @@ -1709,16 +1712,20 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
}
buf->write(namestart, namelen);
}
escapeStrayParenthesis(buf, o, s);
escapeStrayParenthesis(loc, buf, o);
highlightCode(sc, s, buf, o, false);
}
buf->writestring(")\n");

buf->writestring("$(DDOC_PARAM_DESC ");
o = buf->offset;
{
size_t o = buf->offset;
buf->write(textstart, textlen);
escapeStrayParenthesis(buf, o, s);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, s, buf, o);
}
buf->writestring(")");
}
buf->writestring(")\n");
namelen = 0;
if (p >= pend)
Expand Down Expand Up @@ -1764,7 +1771,7 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
/***************************************************
*/

void MacroSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
void MacroSection::write(Loc loc, DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
{
//printf("MacroSection::write()\n");
DocComment::parseMacros(dc->pescapetable, dc->pmacrotable, body, bodylen);
Expand Down

0 comments on commit 17023b1

Please sign in to comment.