Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Add special formatting for ctor and dtor
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugen Wissner authored and Eugen Wissner committed Apr 6, 2022
1 parent 5a1352c commit 1d5f8d3
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/cogito/meter.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct ScoreScope
* Declaration identifier (e.g. function or struct name, may be empty if
* this is a lambda).
*/
Identifier name;
Identifier identifier;

/// Source position.
Loc location;
Expand All @@ -63,15 +63,32 @@ struct Meter
private Type type;

/// Gets the evaluated identifier.
@property ref Identifier name() return
@property ref Identifier identifier() return
{
return this.scoreScope.name;
return this.scoreScope.identifier;
}

/// Sets the evaluated identifier.
@property void name(ref Identifier name)
@property void identifier(ref Identifier identifier)
{
this.scoreScope.name = name;
this.scoreScope.identifier = identifier;
}

@property const(char)[] name()
{
auto stringName = this.scoreScope.identifier.toString();

switch (stringName)
{
case "":
return "(λ)";
case "__ctor":
return "this";
case "__dtor":
return "~this";
default:
return stringName;
}
}

/// Gets identifier location.
Expand All @@ -88,13 +105,13 @@ struct Meter

/**
* Params:
* name = Identifier.
* identifier = Identifier.
* location = Identifier location.
* type = Symbol type.
*/
public this(Identifier name, Loc location, Type type)
public this(Identifier identifier, Loc location, Type type)
{
this.name = name;
this.identifier = identifier;
this.location = location;
this.type = type;
}
Expand Down Expand Up @@ -135,10 +152,9 @@ void verbose(ref Meter meter, void delegate(const(char)[]) sink,
const indentBytes = ' '.repeat(indentation * 2).array;
const nextIndentation = indentation + 1;
const nextIndentBytes = ' '.repeat(nextIndentation * 2).array;
const identifierName = meter.name.toString();

sink(indentBytes);
sink(identifierName.empty ? "(λ)" : identifierName);
sink(meter.name);

sink(":\n");
sink(nextIndentBytes);
Expand Down Expand Up @@ -173,9 +189,7 @@ void flat(ref Meter meter, void delegate(const(char)[]) sink,
{
return;
}
const identifierName = meter.name.toString();
const anonymousName = identifierName.empty? "(λ)" : identifierName;
const nameParts = path ~ [anonymousName.idup];
const nameParts = path ~ [meter.name.idup];

if (meter.type == Meter.Type.callable)
{
Expand Down

0 comments on commit 1d5f8d3

Please sign in to comment.