This commit is contained in:
Hackerpilot 2015-04-24 17:28:06 -07:00
parent 7109c5b4f2
commit 04f6684a50
6 changed files with 126 additions and 3 deletions

@ -1 +1 @@
Subproject commit f0bb347b9aa9f9cb487531debc67c91057d602aa
Subproject commit 256b979f3b53c3367b6556c5b68e9cc76ceaf391

View file

@ -26,7 +26,9 @@ struct ASTInformation
sort(funLitStartLocations);
sort(funLitEndLocations);
sort(conditionalWithElseLocations);
sort(conditionalStatementLocations);
sort(arrayStartLocations);
sort(contractLocations);
}
/// Locations of end braces for struct bodies
@ -64,6 +66,9 @@ struct ASTInformation
/// Locations of start locations of array initializers
size_t[] arrayStartLocations;
/// Locations of "in" and "out" tokens that begin contracts
size_t[] contractLocations;
}
/// Collects information from the AST that is useful for the formatter
@ -212,6 +217,18 @@ final class FormatVisitor : ASTVisitor
attributeDeclaration.accept(this);
}
override void visit(const InStatement inStatement)
{
astInformation.contractLocations ~= inStatement.inTokenLocation;
inStatement.accept(this);
}
override void visit(const OutStatement outStatement)
{
astInformation.contractLocations ~= outStatement.outTokenLocation;
outStatement.accept(this);
}
private:
ASTInformation* astInformation;
alias visit = ASTVisitor.visit;

View file

@ -663,6 +663,15 @@ private:
if (currentIs(tok!"("))
writeParens(config.dfmt_space_after_cast == OptionalBoolean.t);
break;
case tok!"out":
if (!peekBackIs(tok!"}") && astInformation.contractLocations.canFindIndex(current.index))
newline();
else if (peekBackIsKeyword)
write(" ");
writeToken();
if (!currentIs(tok!"(") && !currentIs(tok!"{"))
write(" ");
break;
case tok!"try":
if (peekIs(tok!"{"))
writeToken();
@ -674,8 +683,17 @@ private:
}
break;
case tok!"in":
auto isContract = astInformation.contractLocations.canFindIndex(current.index);
if (isContract)
newline();
else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!"))
write(" ");
writeToken();
if (!isContract)
write(" ");
break;
case tok!"is":
if (!peekBackIsOneOf(false, tok!"!", tok!"(", tok!","))
if (!peekBackIsOneOf(false, tok!"!", tok!"(", tok!",", tok!"}") && !peekBackIsKeyword())
write(" ");
writeToken();
if (!currentIs(tok!"(") && !currentIs(tok!"{"))
@ -695,7 +713,7 @@ private:
default:
if (index + 1 < tokens.length)
{
if (!peekIs(tok!"@") && peekIsOperator())
if (!peekIs(tok!"@") && (peekIsOperator() || peekIs(tok!"out") || peekIs(tok!"in")))
writeToken();
else
{

View file

@ -0,0 +1,32 @@
void foo(auto in a, auto out int b) const
out
{
assert(true);
}
body
{
}
void foo() const
in
{
}
out
{
assert(true);
}
body
{
}
void foo() const
in
{
}
out (result)
{
assert(true);
}
body
{
}

32
tests/issue0139.d Normal file
View file

@ -0,0 +1,32 @@
void foo(auto in a, auto out int b) const
out
{
assert(true);
}
body
{
}
void foo() const
in
{
}
out
{
assert(true);
}
body
{
}
void foo() const
in
{
}
out (result)
{
assert(true);
}
body
{
}

View file

@ -0,0 +1,24 @@
void foo(auto in a, auto out int b) const
out {
assert(true);
}
body {
}
void foo() const
in {
}
out {
assert(true);
}
body {
}
void foo() const
in {
}
out (result) {
assert(true);
}
body {
}