Skip to content

Commit

Permalink
Yeet away FQN
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Feb 18, 2024
1 parent 13901ae commit a5d8a97
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
16 changes: 8 additions & 8 deletions sourcegeneration/StereologueSourceGenerator/LoggableMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal enum DeclarationKind
NullableReferenceType
}

internal record MemberDeclaration(DeclarationType LoggedType, SpecialType SpecialType, DeclarationKind LoggedKind, string? FQN);
internal record MemberDeclaration(DeclarationType LoggedType, SpecialType SpecialType, DeclarationKind LoggedKind);

// Contains all information about a loggable member
internal record LoggableMember(string Name, MemberType MemberType, MemberDeclaration MemberDeclaration, LogAttributeInfo AttributeInfo);
Expand Down Expand Up @@ -96,19 +96,19 @@ private static DeclarationKind GetInnerType(this ITypeSymbol typeSymbol, out ITy
if (typeSymbol.SpecialType != SpecialType.None)
{
// We're a built in special type, no need to check for anything else
return new(DeclarationType.SpecialType, typeSymbol.SpecialType, nestedKind, null);
return new(DeclarationType.SpecialType, typeSymbol.SpecialType, nestedKind);
}

// If we know we're generating a loggable implementation
if (typeSymbol.GetAttributes().Where(x => x.AttributeClass?.ToDisplayString() == "Stereologue.GenerateLogAttribute").Any())
{
return new(DeclarationType.Logged, SpecialType.None, nestedKind, null);
return new(DeclarationType.Logged, SpecialType.None, nestedKind);
}
token.ThrowIfCancellationRequested();
// If we know we already implement ILogged
if (typeSymbol.AllInterfaces.Where(x => x.ToDisplayString() == "Stereologue.ILogged").Any())
{
return new(DeclarationType.Logged, SpecialType.None, nestedKind, null);
return new(DeclarationType.Logged, SpecialType.None, nestedKind);
}
token.ThrowIfCancellationRequested();
// If we have an UpdateMonologue function
Expand All @@ -132,7 +132,7 @@ private static DeclarationKind GetInnerType(this ITypeSymbol typeSymbol, out ITy
}
if (parameters[0].Type.SpecialType == SpecialType.System_String && parameters[1].Type.ToDisplayString() == "Stereologue.Stereologuer")
{
return new(DeclarationType.Logged, SpecialType.None, nestedKind, null);
return new(DeclarationType.Logged, SpecialType.None, nestedKind);
}
}
}
Expand All @@ -153,20 +153,20 @@ private static DeclarationKind GetInnerType(this ITypeSymbol typeSymbol, out ITy
{
if (!attributeInfo.UseProtobuf)
{
return new(DeclarationType.Struct, SpecialType.None, nestedKind, typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
return new(DeclarationType.Struct, SpecialType.None, nestedKind);
}
}
else if (interfaceName == protobufName)
{
if (attributeInfo.UseProtobuf)
{
return new(DeclarationType.Protobuf, SpecialType.None, nestedKind, typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
return new(DeclarationType.Protobuf, SpecialType.None, nestedKind);
}
}
}

// We get here by attempting to log a type we have no clue about
return new(DeclarationType.None, SpecialType.None, DeclarationKind.None, null);
return new(DeclarationType.None, SpecialType.None, DeclarationKind.None);
}

public static LoggableMember? ToLoggableMember(this ISymbol member, CancellationToken token)
Expand Down
6 changes: 3 additions & 3 deletions sourcegeneration/StereologueSourceGenerator/LoggableType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
if (data.MemberDeclaration.LoggedKind != DeclarationKind.None && data.MemberDeclaration.LoggedKind != DeclarationKind.NullableValueType && data.MemberDeclaration.LoggedKind != DeclarationKind.NullableReferenceType)
{
// We're an array
logMethod = $"LogStructArray<{data.MemberDeclaration.FQN}>";
logMethod = "LogStructArray";
}
else
{
logMethod = $"LogStruct<{data.MemberDeclaration.FQN}>";
logMethod = "LogStruct";
}
if (data.MemberDeclaration.LoggedKind == DeclarationKind.NullableValueType)
{
Expand All @@ -107,7 +107,7 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
}
else
{
logMethod = $"LogProto<{data.MemberDeclaration.FQN}>";
logMethod = "LogProto";
}
if (data.MemberDeclaration.LoggedKind == DeclarationKind.NullableValueType)
{
Expand Down
12 changes: 12 additions & 0 deletions src/thirdparty/Stereologue/Stereologuer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public void LogStruct<T>(string path, LogType logType, in T value, LogLevel logL
}
}

public void LogStructArray<T>(string path, LogType logType, T[]? value, LogLevel logLevel = LogLevel.Default) where T : IStructSerializable<T>
{
ReadOnlySpan<T> ros = value.AsSpan();
LogStructArray(path, logType, ros, logLevel);
}

public void LogStructArray<T>(string path, LogType logType, Span<T> value, LogLevel logLevel = LogLevel.Default) where T : IStructSerializable<T>
{
ReadOnlySpan<T> ros = value;
LogStructArray(path, logType, ros, logLevel);
}

public void LogStructArray<T>(string path, LogType logType, ReadOnlySpan<T> value, LogLevel logLevel = LogLevel.Default) where T : IStructSerializable<T>
{
ref var logs = ref CheckDoLog(path, ref logType, logLevel, structArrayLogs);
Expand Down
2 changes: 1 addition & 1 deletion test/stereologue.test/TestTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public partial class GenerateAllKnownTypes
[Log(UseProtobuf = true)]
public Rotation2d RotationProto => new();

[Log(UseProtobuf = true)]
[Log(UseProtobuf = true)]
public Rotation2d? RotationProtoNullable => null;

[Log()]
Expand Down

0 comments on commit a5d8a97

Please sign in to comment.