Skip to content

Commit

Permalink
Implement special ditto documentation handling (#111)
Browse files Browse the repository at this point in the history
Implement special ditto documentation handling
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
  • Loading branch information
WebFreak001 authored and dlang-bot committed Dec 29, 2018
1 parent 211a3cf commit 913e1f1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 11 deletions.
64 changes: 54 additions & 10 deletions src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ final class FirstPass : ASTVisitor
dec.name.index, dec.returnType);
scope (exit) popSymbol();
currentSymbol.protection = protection.current;
currentSymbol.acSymbol.doc = internString(dec.comment);
currentSymbol.acSymbol.doc = makeDocumentation(dec.comment);

istring lastComment = this.lastComment;
this.lastComment = istring.init;
scope(exit) this.lastComment = lastComment;

if (dec.functionBody !is null)
{
Expand Down Expand Up @@ -206,7 +210,7 @@ final class FirstPass : ASTVisitor
addTypeToLookups(symbol.typeLookups, dec.type);
symbol.parent = currentSymbol;
symbol.protection = protection.current;
symbol.acSymbol.doc = internString(declarator.comment);
symbol.acSymbol.doc = makeDocumentation(declarator.comment);
currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, false);

Expand All @@ -228,7 +232,7 @@ final class FirstPass : ASTVisitor
symbol.parent = currentSymbol;
populateInitializer(symbol, part.initializer);
symbol.protection = protection.current;
symbol.acSymbol.doc = internString(dec.comment);
symbol.acSymbol.doc = makeDocumentation(dec.comment);
currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, false);

Expand Down Expand Up @@ -257,7 +261,7 @@ final class FirstPass : ASTVisitor
currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, false);
symbol.protection = protection.current;
symbol.acSymbol.doc = internString(aliasDeclaration.comment);
symbol.acSymbol.doc = makeDocumentation(aliasDeclaration.comment);
}
}
else
Expand All @@ -273,7 +277,7 @@ final class FirstPass : ASTVisitor
currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, false);
symbol.protection = protection.current;
symbol.acSymbol.doc = internString(aliasDeclaration.comment);
symbol.acSymbol.doc = makeDocumentation(aliasDeclaration.comment);
}
}
}
Expand Down Expand Up @@ -349,7 +353,12 @@ final class FirstPass : ASTVisitor
symbol.parent = currentSymbol;
currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, false);
symbol.acSymbol.doc = internString(dec.comment);
symbol.acSymbol.doc = makeDocumentation(dec.comment);

istring lastComment = this.lastComment;
this.lastComment = istring.init;
scope(exit) this.lastComment = lastComment;

currentSymbol = symbol;

if (dec.enumBody !is null)
Expand Down Expand Up @@ -775,7 +784,7 @@ private:
pushSymbol(member.name.text, CompletionKind.enumMember, symbolFile,
member.name.index, member.type);
scope(exit) popSymbol();
currentSymbol.acSymbol.doc = internString(member.comment);
currentSymbol.acSymbol.doc = makeDocumentation(member.comment);
}
}

Expand All @@ -794,7 +803,11 @@ private:
else
currentSymbol.acSymbol.addChildren(aggregateSymbols[], false);
currentSymbol.protection = protection.current;
currentSymbol.acSymbol.doc = internString(dec.comment);
currentSymbol.acSymbol.doc = makeDocumentation(dec.comment);

istring lastComment = this.lastComment;
this.lastComment = istring.init;
scope(exit) this.lastComment = lastComment;

immutable size_t scopeBegin = dec.name.index + dec.name.text.length;
static if (is (AggType == const(TemplateDeclaration)))
Expand All @@ -819,7 +832,12 @@ private:
currentSymbol.addChild(symbol, true);
processParameters(symbol, null, THIS_SYMBOL_NAME, parameters, templateParameters);
symbol.protection = protection.current;
symbol.acSymbol.doc = internString(doc);
symbol.acSymbol.doc = makeDocumentation(doc);

istring lastComment = this.lastComment;
this.lastComment = istring.init;
scope(exit) this.lastComment = lastComment;

if (functionBody !is null)
{
pushFunctionScope(functionBody, semanticAllocator,
Expand All @@ -839,7 +857,12 @@ private:
currentSymbol.addChild(symbol, true);
symbol.acSymbol.callTip = internString("~this()");
symbol.protection = protection.current;
symbol.acSymbol.doc = internString(doc);
symbol.acSymbol.doc = makeDocumentation(doc);

istring lastComment = this.lastComment;
this.lastComment = istring.init;
scope(exit) this.lastComment = lastComment;

if (functionBody !is null)
{
pushFunctionScope(functionBody, semanticAllocator, location + 4); // 4 == "this".length
Expand Down Expand Up @@ -1034,6 +1057,17 @@ private:
lookups.insert(lookup);
}

DocString makeDocumentation(string documentation)
{
if (documentation.isDitto)
return DocString(lastComment, true);
else
{
lastComment = internString(documentation);
return DocString(lastComment, false);
}
}

/// Current protection type
ProtectionStack protection;

Expand All @@ -1055,6 +1089,9 @@ private:
/// Field names for struct constructor generation
UnrolledList!(istring) structFieldNames;

/// Last comment for ditto-ing
istring lastComment;

const Module mod;

IAllocator semanticAllocator;
Expand Down Expand Up @@ -1201,6 +1238,13 @@ auto byIdentifier(const TypeIdentifierPart tip) pure nothrow @trusted
return range;
}

bool isDitto(scope const(char)[] comment)
{
import std.uni : icmp;

return comment.length == 5 && icmp(comment, "ditto") == 0;
}

void writeIotcTo(T)(const TypeIdentifierPart tip, ref T output) nothrow
{
import std.algorithm : each;
Expand Down
28 changes: 27 additions & 1 deletion src/dsymbol/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public:
/**
* Documentation for the symbol.
*/
istring doc;
DocString doc;

/**
* The symbol that represents the type.
Expand Down Expand Up @@ -424,6 +424,32 @@ public:

}

/**
* istring with actual content and information if it was ditto
*/
struct DocString
{
/// Creates a non-ditto comment.
this(istring content)
{
this.content = content;
}

/// Creates a comment which may have been ditto, but has been resolved.
this(istring content, bool ditto)
{
this.content = content;
this.ditto = ditto;
}

alias content this;

/// Contains the documentation string associated with this symbol, resolves ditto to the previous comment with correct scope.
istring content;
/// `true` if the documentation was just a "ditto" comment copying from the previous comment.
bool ditto;
}

struct UpdatePair
{
ptrdiff_t opCmp(ref const UpdatePair other) const pure nothrow @nogc @safe
Expand Down

0 comments on commit 913e1f1

Please sign in to comment.