Skip to content

Commit 1e552a3

Browse files
authored
ros2cs : Update Supported Runtimes, Refactor Code Generation, and Add Metadata Features #46
2 parents be5597d + e0328fd commit 1e552a3

17 files changed

Lines changed: 266 additions & 205 deletions

src/Rosidl.Generator.CSharp/BuildContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public static readonly CSharpAttribute DebuggerNonUserCode
2121

2222
public static readonly CSharpAttribute GeneratedCode
2323
= new CSharpFreeAttribute($"global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"ros2cs\", " +
24-
$"\"{FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion}\")");
24+
$"\"{typeof(Attributes).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!
25+
.InformationalVersion}\")");
2526
}
2627

2728
public record VariableFieldInfo(

src/Rosidl.Generator.CSharp/Builders/ActionClassBuilder.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public CSharpElement Build(string path, bool isInternal, bool generateEvent, boo
2121
cls.Visibility = CSharpVisibility.Internal;
2222
}
2323

24-
cls.AddTypeSupportAttribute(_context.Metadata.ToString());
24+
cls.AddTypeSupportAttribute(_context.Metadata);
2525
cls.AddComments(_context.Metadata);
2626

2727
cls.Modifiers |= CSharpModifiers.Unsafe;
@@ -72,9 +72,8 @@ public CSharpElement Build(string path, bool isInternal, bool generateEvent, boo
7272

7373
private CSharpMethod EmitGetTypeSupportHandle()
7474
{
75-
var method = new CSharpMethod()
75+
var method = new CSharpMethod("GetTypeSupportHandle")
7676
{
77-
Name = "GetTypeSupportHandle",
7877
Modifiers = CSharpModifiers.Static,
7978
Visibility = CSharpVisibility.Public,
8079
ReturnType = new CSharpFreeType("global::Rosidl.Runtime.TypeSupportHandle")
@@ -142,14 +141,17 @@ public ActionBuildContext(ActionMetadata metadata, GeneratorOptions options, Msg
142141
Goal = new(
143142
new(metadata.Id with { Name = metadata.Id.Name + "_Goal" }, metadata.Comments, metadata.GoalFields),
144143
options, MessageType.ActionGoal, this);
144+
Goal.Metadata.Version = metadata.Version;
145145

146146
Result = new(
147147
new(metadata.Id with { Name = metadata.Id.Name + "_Result" }, metadata.Comments, metadata.ResultFields),
148148
options, MessageType.ActionResult, this);
149+
Result.Metadata.Version = metadata.Version;
149150

150151
Feedback = new(
151152
new(metadata.Id with { Name = metadata.Id.Name + "_Feedback" }, metadata.Comments, metadata.FeedbackFields),
152153
options, MessageType.ActionFeedback, this);
154+
Feedback.Metadata.Version = metadata.Version;
153155

154156
FeedbackMessage = GenerateFeedbackMessage();
155157
SendGoal = GenerateSendGoal(parser);

src/Rosidl.Generator.CSharp/Builders/MessageClassBuilder.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public CSharpElement Build(string? path, bool isInternal)
3131

3232
cls.Modifiers |= CSharpModifiers.Unsafe;
3333

34-
cls.AddTypeSupportAttribute(_context.Metadata.ToString());
34+
cls.AddTypeSupportAttribute(_context.Metadata);
3535
cls.AddTypeSupportInterface(_context);
3636

3737
cls.Members.Add(EmitTypeSupportNameProperty());
@@ -514,9 +514,8 @@ el.ValueType is PrimitiveTypes.String or PrimitiveTypes.WString &&
514514

515515
private CSharpMethod EmitCreateFrom()
516516
{
517-
var method = new CSharpMethod()
517+
var method = new CSharpMethod("CreateFrom")
518518
{
519-
Name = "CreateFrom",
520519
Modifiers = CSharpModifiers.Static,
521520
Visibility = CSharpVisibility.Public,
522521
ReturnType = new CSharpFreeType("global::Rosidl.Runtime.IMessage")
@@ -534,9 +533,8 @@ private CSharpMethod EmitCreateFrom()
534533

535534
private CSharpMethod EmitUnsafeCreate()
536535
{
537-
var method = new CSharpMethod()
536+
var method = new CSharpMethod("UnsafeCreate")
538537
{
539-
Name = "UnsafeCreate",
540538
Modifiers = CSharpModifiers.Static,
541539
Visibility = CSharpVisibility.Public,
542540
ReturnType = new CSharpFreeType("nint")
@@ -551,9 +549,8 @@ private CSharpMethod EmitUnsafeCreate()
551549

552550
private CSharpMethod EmitUnsafeInitialize()
553551
{
554-
var method = new CSharpMethod()
552+
var method = new CSharpMethod("UnsafeInitialize")
555553
{
556-
Name = "UnsafeInitialize",
557554
Modifiers = CSharpModifiers.Static,
558555
Visibility = CSharpVisibility.Public,
559556
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Bool)
@@ -573,9 +570,8 @@ private CSharpMethod EmitUnsafeInitialize()
573570

574571
private CSharpMethod EmitUnsafeFinalize()
575572
{
576-
var method = new CSharpMethod()
573+
var method = new CSharpMethod("UnsafeFinalize")
577574
{
578-
Name = "UnsafeFinalize",
579575
Modifiers = CSharpModifiers.Static,
580576
Visibility = CSharpVisibility.Public,
581577
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Void)
@@ -595,9 +591,8 @@ private CSharpMethod EmitUnsafeFinalize()
595591

596592
private CSharpMethod EmitUnsafeInitializeSequence()
597593
{
598-
var method = new CSharpMethod()
594+
var method = new CSharpMethod("UnsafeInitializeSequence")
599595
{
600-
Name = "UnsafeInitializeSequence",
601596
Modifiers = CSharpModifiers.Static,
602597
Visibility = CSharpVisibility.Public,
603598
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Bool)
@@ -618,9 +613,8 @@ private CSharpMethod EmitUnsafeInitializeSequence()
618613

619614
private CSharpMethod EmitUnsafeFinalizeSequence()
620615
{
621-
var method = new CSharpMethod()
616+
var method = new CSharpMethod("UnsafeFinalizeSequence")
622617
{
623-
Name = "UnsafeFinalizeSequence",
624618
Modifiers = CSharpModifiers.Static,
625619
Visibility = CSharpVisibility.Public,
626620
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Void)
@@ -640,9 +634,8 @@ private CSharpMethod EmitUnsafeFinalizeSequence()
640634

641635
private CSharpMethod EmitUnsafeDestroy()
642636
{
643-
var method = new CSharpMethod()
637+
var method = new CSharpMethod("UnsafeDestroy")
644638
{
645-
Name = "UnsafeDestroy",
646639
Modifiers = CSharpModifiers.Static,
647640
Visibility = CSharpVisibility.Public,
648641
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Void)
@@ -659,9 +652,8 @@ private CSharpMethod EmitUnsafeDestroy()
659652

660653
private CSharpMethod EmitGetTypeSupportHandle()
661654
{
662-
var method = new CSharpMethod()
655+
var method = new CSharpMethod("GetTypeSupportHandle")
663656
{
664-
Name = "GetTypeSupportHandle",
665657
Modifiers = CSharpModifiers.Static,
666658
Visibility = CSharpVisibility.Public,
667659
ReturnType = new CSharpFreeType("global::Rosidl.Runtime.TypeSupportHandle")
@@ -698,9 +690,8 @@ private CSharpProperty EmitTypeSupportNameProperty()
698690

699691
private CSharpMethod EmitWriteTo()
700692
{
701-
var method = new CSharpMethod()
693+
var method = new CSharpMethod("WriteTo")
702694
{
703-
Name = "WriteTo",
704695
Visibility = CSharpVisibility.Public,
705696
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Void)
706697
};
@@ -717,9 +708,8 @@ private CSharpMethod EmitWriteTo()
717708

718709
private CSharpMethod EmitWriteToRef()
719710
{
720-
var method = new CSharpMethod()
711+
var method = new CSharpMethod("WriteTo")
721712
{
722-
Name = "WriteTo",
723713
Visibility = CSharpVisibility.Public,
724714
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Void)
725715
};

src/Rosidl.Generator.CSharp/Builders/PrivStructBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ private record VariableField(string Name, string Type, VariableFieldMetadata Met
215215
private static CSharpMethod EmitTryInitialize(MethodBuildContext context, Func<string, string> symbolResolver)
216216
{
217217
var structType = context.StructType;
218-
var method = new CSharpMethod()
218+
var method = new CSharpMethod("TryInitialize")
219219
{
220-
Name = "TryInitialize",
221220
Visibility = CSharpVisibility.Public,
222221
Modifiers = CSharpModifiers.Static,
223222
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Bool)

src/Rosidl.Generator.CSharp/Builders/PrivStructSequenceBuilder.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ private static void EmitMethods(CSharpStruct s, MethodBuildContext context)
100100
private static CSharpMethod EmitTryInitialize(MethodBuildContext context, Func<string, string> symbolResolver)
101101
{
102102
var structType = context.StructType;
103-
var method = new CSharpMethod()
103+
var method = new CSharpMethod("TryInitialize")
104104
{
105-
Name = "TryInitialize",
106105
Visibility = CSharpVisibility.Public,
107106
Modifiers = CSharpModifiers.Static,
108107
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Bool)
@@ -130,9 +129,8 @@ private static CSharpMethod EmitTryInitialize(MethodBuildContext context, Func<s
130129

131130
private static CSharpMethod EmitAsSpan(MethodBuildContext context)
132131
{
133-
return new CSharpMethod()
132+
return new CSharpMethod("AsSpan")
134133
{
135-
Name = "AsSpan",
136134
Visibility = CSharpVisibility.Public,
137135
ReturnType = new CSharpFreeType($"System.Span<{context.MessageContext.PrivStructName}>"),
138136
Body = (writer, element) =>
@@ -144,9 +142,8 @@ private static CSharpMethod EmitAsSpan(MethodBuildContext context)
144142

145143
private static CSharpMethod EmitCopyFromSpan(MethodBuildContext context)
146144
{
147-
var method = new CSharpMethod()
145+
var method = new CSharpMethod("CopyFrom")
148146
{
149-
Name = "CopyFrom",
150147
Visibility = CSharpVisibility.Public,
151148
ReturnType = new CSharpPrimitiveType(CSharpPrimitiveKind.Void)
152149
};

src/Rosidl.Generator.CSharp/Builders/ServiceClassBuilder.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private CSharpElement[] Build(bool isInternal, bool generateEvent)
2121
}
2222

2323
cls.AddComments(_context.Metadata);
24-
cls.AddTypeSupportAttribute(_context.Metadata.ToString());
24+
cls.AddTypeSupportAttribute(_context.Metadata);
2525
cls.Modifiers |= CSharpModifiers.Unsafe;
2626
cls.BaseTypes.Add(new CSharpFreeType($"global::Rosidl.Runtime.IService<{_context.Request.ClassName}, {_context.Response.ClassName}>"));
2727

@@ -80,9 +80,8 @@ public void Build(CSharpNamespace ns, bool isInternal, bool generateEvent)
8080

8181
private CSharpMethod EmitGetTypeSupportHandle()
8282
{
83-
var method = new CSharpMethod()
83+
var method = new CSharpMethod("GetTypeSupportHandle")
8484
{
85-
Name = "GetTypeSupportHandle",
8685
Modifiers = CSharpModifiers.Static,
8786
Visibility = CSharpVisibility.Public,
8887
ReturnType = new CSharpFreeType("global::Rosidl.Runtime.TypeSupportHandle")
@@ -155,13 +154,16 @@ public ServiceBuildContext(ServiceMetadata metadata, GeneratorOptions options, S
155154
Request = new(
156155
new(metadata.Id with { Name = metadata.Id.Name + "_Request" }, metadata.Comments, metadata.RequestFields),
157156
options, MessageType.ServiceRequest, this);
157+
Request.Metadata.Version = metadata.Version;
158158

159159
Response = new(
160160
new(metadata.Id with { Name = metadata.Id.Name + "_Response" }, metadata.Comments, metadata.ResponseFields),
161161
options, MessageType.ServiceResponse, this);
162+
Response.Metadata.Version = metadata.Version;
162163

163164
Event = new(
164165
new(metadata.Id with { Name = metadata.Id.Name + "_Event" }, metadata.Comments, metadata.EventFields),
165166
options, MessageType.ServiceEvent, this);
167+
Event.Metadata.Version = metadata.Version;
166168
}
167169
}

0 commit comments

Comments
 (0)