Skip to content

Commit

Permalink
4878 Ddoc: Default arguments can break Ddoc output
Browse files Browse the repository at this point in the history
(patch by Johannes Pfau)
  • Loading branch information
Don Clugston committed Jan 27, 2011
1 parent d728641 commit 4b18789
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,36 @@ void Module::gendocfile()
/****************************************************
* Having unmatched parentheses can hose the output of Ddoc,
* as the macros depend on properly nested parentheses.
* This function replaces all ( with $(LPAREN) and ) with $(RPAREN)
* to preserve text literally. This also means macros in the
* text won't be expanded.
*/
void escapeDdocString(OutBuffer *buf, unsigned start)
{
for (unsigned u = start; u < buf->offset; u++)
{
unsigned char c = buf->data[u];
switch(c)
{
case '(':
buf->remove(u, 1); //remove the (
buf->insert(u, "$(LPAREN)", 9); //insert this instead
u += 8; //skip over newly inserted macro
break;

case ')':
buf->remove(u, 1); //remove the )
buf->insert(u, "$(RPAREN)", 9); //insert this instead
u += 8; //skip over newly inserted macro
break;
}
}
}

/****************************************************
* Having unmatched parentheses can hose the output of Ddoc,
* as the macros depend on properly nested parentheses.
* Fix by replacing unmatched ( with $(LPAREN) and unmatched ) with $(RPAREN).
*/
void escapeStrayParenthesis(OutBuffer *buf, unsigned start, Loc loc)
Expand Down
1 change: 1 addition & 0 deletions src/doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
#pragma once
#endif /* __DMC__ */

void escapeDdocString(OutBuffer *buf, unsigned start);

#endif
6 changes: 6 additions & 0 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "import.h"
#include "aggregate.h"
#include "hdrgen.h"
#include "doc.h"

FuncDeclaration *hasThis(Scope *sc);

Expand Down Expand Up @@ -8116,7 +8117,12 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
if (arg->defaultArg)
{
argbuf.writestring(" = ");
unsigned o = argbuf.offset;
arg->defaultArg->toCBuffer(&argbuf, hgs);
if (hgs->ddoc)
{
escapeDdocString(&argbuf, o);
}
}
buf->write(&argbuf);
}
Expand Down

0 comments on commit 4b18789

Please sign in to comment.