Skip to content

Commit

Permalink
ddoc: Add DDOC_TEMPLATE_PARAM
Browse files Browse the repository at this point in the history
  • Loading branch information
landaire committed Dec 22, 2015
1 parent ffe22e7 commit b81c727
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/doc.d
Expand Up @@ -453,6 +453,7 @@ DDOC_PARAM = $(I $0)
DDOC_CONSTRAINT =  if($0)
DDOC_OVERLOAD_SEPARATOR = $(BR)
DDOC_TEMPLATE_PARAM_LIST = $0
DDOC_TEMPLATE_PARAM = $0
ESCAPES = /</&lt;/
/>/&gt;/
Expand Down Expand Up @@ -2504,23 +2505,31 @@ extern (C++) void highlightCode(Scope* sc, Dsymbols* a, OutBuffer* buf, size_t o
{
FuncDeclaration fd = (*a)[symi].isFuncDeclaration();

if (!fd || !fd.parent.isTemplateDeclaration())
if (!fd || !fd.parent || !fd.parent.isTemplateDeclaration())
{
continue;
}

TemplateDeclaration td = fd.parent.isTemplateDeclaration();

// build the template parameters
size_t[] paramLens;
OutBuffer parametersBuf;
HdrGenState hgs;
parametersBuf.writeByte('(');

for (size_t parami = 0; parami < td.parameters.dim; parami++)
{
TemplateParameter tp = (*td.parameters)[parami];

if (parami)
parametersBuf.writestring(", ");

size_t lastOffset = parametersBuf.offset;

.toCBuffer(tp, &parametersBuf, &hgs);

paramLens ~= [parametersBuf.offset - lastOffset];
}
parametersBuf.writeByte(')');

Expand All @@ -2531,8 +2540,26 @@ extern (C++) void highlightCode(Scope* sc, Dsymbols* a, OutBuffer* buf, size_t o

if (cmp(templateParams, start, templateParamsLen) == 0)
{
i = buf.bracket(i, "$(DDOC_TEMPLATE_PARAM_LIST ", i + templateParamsLen, ")") - 1;
const(char*) templateParamListMacro = "$(DDOC_TEMPLATE_PARAM_LIST ";
size_t paramListEnd = buf.bracket(i, templateParamListMacro, i + templateParamsLen, ")") - 1;

// We have the parameter list. While we're here we might
// as well wrap the parameters themselves as well

// + 1 here to take into account the opening paren of the
// template param list
i += strlen(templateParamListMacro) + 1;

foreach (size_t len; paramLens)
{
i = buf.bracket(i, "$(DDOC_TEMPLATE_PARAM ", i + len, ")");
// increment two here for space + comma
i += 2;
}

resolvedTemplateParameters = true;
// reset i to be positioned out of the DDOC_TEMPLATE_PARAM_LIST
i = paramListEnd;

continue;
}
Expand Down

0 comments on commit b81c727

Please sign in to comment.