mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-04-20 10:49:02 +02:00
Merged DMD commit c0d4f02e996e7913f729102a2c07eedcb015ba90:
4878 DDoc: Default arguments can break DDoc output Merged from D2 into D1
This commit is contained in:
32
dmd/doc.c
32
dmd/doc.c
@@ -363,6 +363,36 @@ void Module::gendocfile()
|
|||||||
/****************************************************
|
/****************************************************
|
||||||
* Having unmatched parentheses can hose the output of Ddoc,
|
* Having unmatched parentheses can hose the output of Ddoc,
|
||||||
* as the macros depend on properly nested parentheses.
|
* 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).
|
* Fix by replacing unmatched ( with $(LPAREN) and unmatched ) with $(RPAREN).
|
||||||
*/
|
*/
|
||||||
void escapeStrayParenthesis(OutBuffer *buf, unsigned start, Loc loc)
|
void escapeStrayParenthesis(OutBuffer *buf, unsigned start, Loc loc)
|
||||||
@@ -852,7 +882,7 @@ void FuncDeclaration::toDocBuffer(OutBuffer *buf)
|
|||||||
tp->toCBuffer(buf, &hgs);
|
tp->toCBuffer(buf, &hgs);
|
||||||
}
|
}
|
||||||
buf->writeByte(')');
|
buf->writeByte(')');
|
||||||
Parameter::argsToCBuffer(buf, &hgs, tf->parameters, tf->varargs);
|
Parameter::argsToCBuffer(buf, &hgs, tf ? tf->parameters : NULL, tf ? tf->varargs : 0);
|
||||||
buf->writestring(";\n");
|
buf->writestring(";\n");
|
||||||
|
|
||||||
highlightCode(NULL, this, buf, o);
|
highlightCode(NULL, this, buf, o);
|
||||||
|
|||||||
@@ -15,5 +15,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif /* __DMC__ */
|
#endif /* __DMC__ */
|
||||||
|
|
||||||
|
void escapeDdocString(OutBuffer *buf, unsigned start);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
#include "import.h"
|
#include "import.h"
|
||||||
#include "aggregate.h"
|
#include "aggregate.h"
|
||||||
#include "hdrgen.h"
|
#include "hdrgen.h"
|
||||||
|
#include "doc.h"
|
||||||
|
|
||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
//#include "gen/tollvm.h"
|
//#include "gen/tollvm.h"
|
||||||
@@ -5714,7 +5715,12 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
|
|||||||
if (arg->defaultArg)
|
if (arg->defaultArg)
|
||||||
{
|
{
|
||||||
argbuf.writestring(" = ");
|
argbuf.writestring(" = ");
|
||||||
|
unsigned o = argbuf.offset;
|
||||||
arg->defaultArg->toCBuffer(&argbuf, hgs);
|
arg->defaultArg->toCBuffer(&argbuf, hgs);
|
||||||
|
if(hgs->ddoc)
|
||||||
|
{
|
||||||
|
escapeDdocString(&argbuf, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf->write(&argbuf);
|
buf->write(&argbuf);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user