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

Commit

Permalink
Display aggregate type name in the message
Browse files Browse the repository at this point in the history
  • Loading branch information
belka-ew committed May 14, 2022
1 parent dfa0393 commit c8ddd0b
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 293 deletions.
67 changes: 38 additions & 29 deletions src/cogito/meter.d
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ struct Meter
enum Type
{
aggregate, /// Aggregate.
callable /// Function.
callable, /// Function.
class_, /// Class.
interface_, /// Interface.
struct_, /// Struct.
template_, /// Template.
union_, /// Union.
}
private Type type;

Expand Down Expand Up @@ -152,7 +157,7 @@ struct Meter
return true;
}
else if (threshold.aggregate != 0
&& this.type == Type.aggregate
&& this.type != Type.callable // Aggregate.
&& this.score > threshold.aggregate)
{
return true;
Expand All @@ -166,6 +171,27 @@ struct Meter
mixin Ruler!();
}

private string typeToString(Meter.Type meterType)
{
final switch(meterType) with (Meter.Type)
{
case aggregate:
return "aggregate";
case callable:
return "function";
case class_:
return "class";
case interface_:
return "interface";
case struct_:
return "struct";
case template_:
return "template";
case union_:
return "union";
}
}

/**
* Prints the information about the given identifier.
*
Expand Down Expand Up @@ -286,33 +312,16 @@ if (isCallable!sink)
}
const nameParts = path ~ [meter.name.idup];

final switch (meter.type)
{
case Meter.Type.callable:
sink(this.source.filename);
sink(":");
sink(to!string(meter.location.linnum));
sink(": ");
sink("function ");
sink(nameParts.join("."));
sink(": ");
sink(meter.score.to!string);
sink("\n");

break;
case Meter.Type.aggregate:
sink(this.source.filename);
sink(":");
sink(to!string(meter.location.linnum));
sink(": ");
sink("aggregate ");
sink(nameParts.join("."));
sink(": ");
sink(meter.score.to!string);
sink("\n");

break;
}
sink(this.source.filename);
sink(":");
sink(to!string(meter.location.linnum));
sink(": ");
sink(typeToString(meter.type));
sink(" ");
sink(nameParts.join("."));
sink(": ");
sink(meter.score.to!string);
sink("\n");

meter.inner[].each!(meter => this.traverse(meter,
threshold, nameParts));
Expand Down
Loading

0 comments on commit c8ddd0b

Please sign in to comment.