Skip to content

Commit

Permalink
Handle all loggable types
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Feb 16, 2024
1 parent 303e17d commit ce5a66f
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 40 deletions.
51 changes: 36 additions & 15 deletions sourcegeneration/MonologueSourceGenerator/LogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ private static LogData ComputeOperation(ITypeSymbol logType, string getOp, strin
return new($"{getOp}.UpdateMonologue($\"{{path}}/{path}\", logger);", null, null, null);
//return $"{getOp}.UpdateMonologue($\"{{path}}/{path}\", logger);";
}
var fullName = logType.ToDisplayString();
var fmt = new SymbolDisplayFormat(typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters);
var fullName = logType.ToDisplayString(fmt);
var structName = $"WPIUtil.Serialization.Struct.IStructSerializable<{fullName}>";
var protobufName = $"WPIUtil.Serialization.Protobuf.IProtobufSerializable<{fullName}>";
foreach (var inf in logType.AllInterfaces)
Expand Down Expand Up @@ -151,22 +152,42 @@ static void ConstructCall(LogData data, StringBuilder builder)
}

var ret = data.Type switch {
"float" => ("LogFloat", ""),
"double" => ("LogDouble", ""),
"byte" => ("LogInteger", ""),
"sbyte" => ("LogInteger", ""),
"short" => ("LogInteger", ""),
"ushort" => ("LogInteger", ""),
"int" => ("LogInteger", ""),
"uint" => ("LogInteger", ""),
"long" => ("LogInteger", ""),
"ulong" => ("LogInteger", "(long)"),
"bool" => ("LogBoolean", ""),
"char" => ("LogChar", ""),
_ => (data.Type, "")
"System.Single" => ("LogFloat", "", ""),
"System.Double" => ("LogDouble", "", ""),
"System.Byte" => ("LogInteger", "", ""),
"System.SByte" => ("LogInteger", "", ""),
"System.Int16" => ("LogInteger", "", ""),
"System.UInt16" => ("LogInteger", "", ""),
"System.Int32" => ("LogInteger", "", ""),
"System.UInt32" => ("LogInteger", "", ""),
"System.Int64" => ("LogInteger", "", ""),
"System.UInt64" => ("LogInteger", "(long)", ""),
"System.Boolean" => ("LogBoolean", "", ""),
"System.Char" => ("LogChar", "", ""),
"System.String" => ("LogString", "", ""),
"System.Single[]" => ("LogFloatArray", "", ".AsSpan()"),
"System.Double[]" => ("LogDoubleArray", "", ".AsSpan()"),
"System.Int64[]" => ("LogIntegerArray", "", ".AsSpan()"),
"System.String[]" => ("LogStringArray", "", ".AsSpan()"),
"System.Byte[]" => ("LogRaw", "", ".AsSpan()"),
"System.Boolean[]" => ("LogBooleanArray", "", ".AsSpan()"),
"System.ReadOnlySpan<System.Char>" => ("LogString", "", ""),
"System.ReadOnlySpan<System.Single>" => ("LogFloatArray", "", ""),
"System.ReadOnlySpan<System.Double>" => ("LogDoubleArray", "", ""),
"System.ReadOnlySpan<System.Int64>" => ("LogIntegerArray", "", ""),
"System.ReadOnlySpan<System.String>" => ("LogStringArray", "", ""),
"System.ReadOnlySpan<System.Byte>" => ("LogRaw", "", ""),
"System.ReadOnlySpan<System.Boolean>" => ("LogBooleanArray", "", ""),
"System.Span<System.Single>" => ("LogFloatArray", "", ""),
"System.Span<System.Double>" => ("LogDoubleArray", "", ""),
"System.Span<System.Int64>" => ("LogIntegerArray", "", ""),
"System.Span<System.String>" => ("LogStringArray", "", ""),
"System.Span<System.Byte>" => ("LogRaw", "", ""),
"System.Span<System.Boolean>" => ("LogBooleanArray", "", ""),
_ => (data.Type, "", "")
};

builder.AppendLine($" logger.{ret.Item1}($\"{{path}}/{data.Path}\", LogType.Nt, {ret.Item2}{data.GetOperation});");
builder.AppendLine($" logger.{ret.Item1}($\"{{path}}/{data.Path}\", LogType.Nt, {ret.Item2}{data.GetOperation}{ret.Item3});");
}

static void Execute(ClassData? classData, SourceProductionContext context)
Expand Down
57 changes: 57 additions & 0 deletions src/thirdparty/Monologue/Monologuer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using NetworkTables;
Expand Down Expand Up @@ -112,4 +113,60 @@ public void LogProto<T>(string path, LogType logType, in T value) where T : IPro
tl.Append(value);
}
}

public void LogChar(string path, LogType logType, char value)
{

}

public void LogFloat(string path, LogType logType, float value)
{

}

public void LogDouble(string path, LogType logType, double value)
{

}

public void LogString(string path, LogType logType, string? value)
{
LogString(path, logType, value.AsSpan());
}

public void LogString(string path, LogType logType, ReadOnlySpan<char> value)
{

}

public void LogBooleanArray(string path, LogType logType, ReadOnlySpan<bool> value)
{

}

public void LogStringArray(string path, LogType logType, ReadOnlySpan<string?> value)
{

}

public void LogRaw(string path, LogType logType, ReadOnlySpan<byte> value)
{

}

public void LogIntegerArray(string path, LogType logType, ReadOnlySpan<long> value)
{

}

public void LogFloatArray(string path, LogType logType, ReadOnlySpan<float> value)
{

}

public void LogDoubleArray(string path, LogType logType, ReadOnlySpan<double> value)
{

}

}
81 changes: 56 additions & 25 deletions test/monologue.test/TestTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,40 +90,71 @@ public partial record class GenerateRecordClass
}

[GenerateLog]
public partial class TestRootClass
public partial class GenerateAllKnownTypes
{
[Log]
public readonly TestClass TCField = new();


public bool boolVar;
[Log]
public TestClass TCMethod() => new();

public char charVar;
[Log]
public TestClass TC { get; } = new();
public byte byteVar;
[Log]
public TestStruct TS { get; } = new();
}

[GenerateLog]
public partial class TestClass
{
public sbyte sbyteVar;
[Log]
public TestStruct TS { get; } = new();
}
public short shortVar;
[Log]
public ushort ushortVar;
[Log]
public int intVar;
[Log]
public uint uintVar;
[Log]
public long longVar;
[Log]
public ulong ulongVar;
[Log]
public float floatVar;
[Log]
public double doubleVar;
[Log]
public string? stringVar;

[GenerateLog]
public partial struct TestStruct
{
[Log]
public Rotation2d Rotation { get; set; } = new();
public long[]? longArrVar;
[Log]
public float[]? floatArrVar;
[Log]
public double[]? doubleArrVar;
[Log]
public string?[]? stringArrVar;
[Log]
public byte[]? rawVar;
[Log]
public bool[]? boolArrVar;

public TestStruct() { }
}
[Log]
public ReadOnlySpan<float> FloatROSpan => new();
[Log]
public ReadOnlySpan<double> DoubleROSpan => new();
[Log]
public ReadOnlySpan<long> LongROSpan => new();
[Log]
public ReadOnlySpan<string?> StringROSpan => new();
[Log]
public ReadOnlySpan<byte> RawROSpan => new();
[Log]
public ReadOnlySpan<bool> BoolROSpan => new();

[GenerateLog]
public partial class TestDemo
{
[Log]
public Rotation2d Rotation { get; set; } = new();
public Span<float> FloatSpan => new();
[Log]
public Span<double> DoubleSpan => new();
[Log]
public Span<long> LongSpan => new();
[Log]
public Span<string?> StringSpan => new();
[Log]
public Span<byte> RawSpan => new();
[Log]
public Span<bool> BoolSpan => new();
}

0 comments on commit ce5a66f

Please sign in to comment.