Put a space behind static and shared constructors as well
This commit is contained in:
parent
23bd2b408c
commit
d8f9cfeae1
|
@ -31,6 +31,8 @@ struct ASTInformation
|
||||||
sort(contractLocations);
|
sort(contractLocations);
|
||||||
sort(constraintLocations);
|
sort(constraintLocations);
|
||||||
sort(constructorDestructorLocations);
|
sort(constructorDestructorLocations);
|
||||||
|
sort(staticConstructorDestructorLocations);
|
||||||
|
sort(sharedStaticConstructorDestructorLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locations of end braces for struct bodies
|
/// Locations of end braces for struct bodies
|
||||||
|
@ -75,6 +77,12 @@ struct ASTInformation
|
||||||
/// Locations of template constraint "if" tokens
|
/// Locations of template constraint "if" tokens
|
||||||
size_t[] constraintLocations;
|
size_t[] constraintLocations;
|
||||||
|
|
||||||
|
/// Locations of constructor/destructor "shared" tokens ?
|
||||||
|
size_t[] sharedStaticConstructorDestructorLocations;
|
||||||
|
|
||||||
|
/// Locations of constructor/destructor "static" tokens ?
|
||||||
|
size_t[] staticConstructorDestructorLocations;
|
||||||
|
|
||||||
/// Locations of constructor/destructor "this" tokens ?
|
/// Locations of constructor/destructor "this" tokens ?
|
||||||
size_t[] constructorDestructorLocations;
|
size_t[] constructorDestructorLocations;
|
||||||
}
|
}
|
||||||
|
@ -97,13 +105,37 @@ final class FormatVisitor : ASTVisitor
|
||||||
arrayInitializer.accept(this);
|
arrayInitializer.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const Constructor constructor)
|
override void visit (const SharedStaticConstructor sharedStaticConstructor)
|
||||||
|
{
|
||||||
|
astInformation.sharedStaticConstructorDestructorLocations ~= sharedStaticConstructor.location;
|
||||||
|
sharedStaticConstructor.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
override void visit (const SharedStaticDestructor sharedStaticDestructor)
|
||||||
|
{
|
||||||
|
astInformation.sharedStaticConstructorDestructorLocations ~= sharedStaticDestructor.location;
|
||||||
|
sharedStaticDestructor.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
override void visit (const StaticConstructor staticConstructor)
|
||||||
|
{
|
||||||
|
astInformation.staticConstructorDestructorLocations ~= staticConstructor.location;
|
||||||
|
staticConstructor.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
override void visit (const StaticDestructor staticDestructor)
|
||||||
|
{
|
||||||
|
astInformation.staticConstructorDestructorLocations ~= staticDestructor.location;
|
||||||
|
staticDestructor.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
override void visit (const Constructor constructor)
|
||||||
{
|
{
|
||||||
astInformation.constructorDestructorLocations ~= constructor.location;
|
astInformation.constructorDestructorLocations ~= constructor.location;
|
||||||
constructor.accept(this);
|
constructor.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const Destructor destructor)
|
override void visit (const Destructor destructor)
|
||||||
{
|
{
|
||||||
astInformation.constructorDestructorLocations ~= destructor.index;
|
astInformation.constructorDestructorLocations ~= destructor.index;
|
||||||
destructor.accept(this);
|
destructor.accept(this);
|
||||||
|
|
|
@ -171,6 +171,9 @@ private:
|
||||||
/// True if we're in an ASM block
|
/// True if we're in an ASM block
|
||||||
bool inAsm;
|
bool inAsm;
|
||||||
|
|
||||||
|
/// True if the next "this" should have a space behind it
|
||||||
|
bool thisSpace;
|
||||||
|
|
||||||
void formatStep()
|
void formatStep()
|
||||||
{
|
{
|
||||||
import std.range : assumeSorted;
|
import std.range : assumeSorted;
|
||||||
|
@ -269,10 +272,11 @@ private:
|
||||||
const thisIndex = current.index;
|
const thisIndex = current.index;
|
||||||
formatKeyword();
|
formatKeyword();
|
||||||
if (config.dfmt_space_before_function_parameters
|
if (config.dfmt_space_before_function_parameters
|
||||||
&& astInformation.constructorDestructorLocations
|
&& (thisSpace || astInformation.constructorDestructorLocations
|
||||||
.canFindIndex(thisIndex))
|
.canFindIndex(thisIndex)))
|
||||||
{
|
{
|
||||||
write(" ");
|
write(" ");
|
||||||
|
thisSpace = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isKeyword(current.type))
|
else if (isKeyword(current.type))
|
||||||
|
@ -1047,6 +1051,24 @@ private:
|
||||||
write(" ");
|
write(" ");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case tok!"static":
|
||||||
|
{
|
||||||
|
if (astInformation.staticConstructorDestructorLocations
|
||||||
|
.canFindIndex(current.index))
|
||||||
|
{
|
||||||
|
thisSpace = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto default;
|
||||||
|
case tok!"shared":
|
||||||
|
{
|
||||||
|
if (astInformation.sharedStaticConstructorDestructorLocations
|
||||||
|
.canFindIndex(current.index))
|
||||||
|
{
|
||||||
|
thisSpace = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto default;
|
||||||
default:
|
default:
|
||||||
if (peekBackIs(tok!"identifier"))
|
if (peekBackIs(tok!"identifier"))
|
||||||
write(" ");
|
write(" ");
|
||||||
|
|
Loading…
Reference in New Issue