Skip to content

Commit 593751b

Browse files
committed
Fix bug with public fields not receiving attributes in some cases
- Fix bug when if you declare public fields as a comma seperated list like `float a, b, c;`, some field attributes would not propagate to all of the fields correctly - Small fix to component name in one of the samples
1 parent 8462a4f commit 593751b

File tree

6 files changed

+340
-321
lines changed

6 files changed

+340
-321
lines changed

Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -742,27 +742,30 @@ public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
742742

743743
bool isPublic = node.Modifiers.HasModifier("public") || fieldAttributes.Find(e => e is SerializeField) != null;
744744

745-
SymbolDefinition fieldSymbol = HandleVariableDeclaration(node.Declaration, isPublic ? SymbolDeclTypeFlags.Public : SymbolDeclTypeFlags.Private, fieldSyncMode);
746-
FieldDefinition fieldDefinition = new FieldDefinition(fieldSymbol);
747-
fieldDefinition.fieldAttributes = fieldAttributes;
748-
749-
if (fieldSymbol.IsUserDefinedType())
745+
List<SymbolDefinition> fieldSymbols = HandleVariableDeclaration(node.Declaration, isPublic ? SymbolDeclTypeFlags.Public : SymbolDeclTypeFlags.Private, fieldSyncMode);
746+
foreach (SymbolDefinition fieldSymbol in fieldSymbols)
750747
{
751-
System.Type fieldType = fieldSymbol.userCsType;
752-
while (fieldType.IsArray)
753-
fieldType = fieldType.GetElementType();
748+
FieldDefinition fieldDefinition = new FieldDefinition(fieldSymbol);
749+
fieldDefinition.fieldAttributes = fieldAttributes;
754750

755-
foreach (ClassDefinition classDefinition in visitorContext.externClassDefinitions)
751+
if (fieldSymbol.IsUserDefinedType())
756752
{
757-
if (classDefinition.userClassType == fieldType)
753+
System.Type fieldType = fieldSymbol.userCsType;
754+
while (fieldType.IsArray)
755+
fieldType = fieldType.GetElementType();
756+
757+
foreach (ClassDefinition classDefinition in visitorContext.externClassDefinitions)
758758
{
759-
fieldDefinition.userBehaviourSource = classDefinition.classScript;
760-
break;
759+
if (classDefinition.userClassType == fieldType)
760+
{
761+
fieldDefinition.userBehaviourSource = classDefinition.classScript;
762+
break;
763+
}
761764
}
762765
}
763-
}
764766

765-
visitorContext.localFieldDefinitions.Add(fieldSymbol.symbolUniqueName, fieldDefinition);
767+
visitorContext.localFieldDefinitions.Add(fieldSymbol.symbolUniqueName, fieldDefinition);
768+
}
766769
}
767770

768771
public override void VisitVariableDeclaration(VariableDeclarationSyntax node)
@@ -772,7 +775,7 @@ public override void VisitVariableDeclaration(VariableDeclarationSyntax node)
772775
HandleVariableDeclaration(node, SymbolDeclTypeFlags.Local, UdonSyncMode.NotSynced);
773776
}
774777

775-
public SymbolDefinition HandleVariableDeclaration(VariableDeclarationSyntax node, SymbolDeclTypeFlags symbolType, UdonSyncMode syncMode)
778+
public List<SymbolDefinition> HandleVariableDeclaration(VariableDeclarationSyntax node, SymbolDeclTypeFlags symbolType, UdonSyncMode syncMode)
776779
{
777780
UpdateSyntaxNode(node);
778781

@@ -794,9 +797,12 @@ public SymbolDefinition HandleVariableDeclaration(VariableDeclarationSyntax node
794797
}
795798

796799
SymbolDefinition newSymbol = null;
800+
List<SymbolDefinition> newSymbols = new List<SymbolDefinition>();
797801

798802
foreach (VariableDeclaratorSyntax variableDeclarator in node.Variables)
799803
{
804+
newSymbol = null;
805+
800806
string variableName = variableDeclarator.Identifier.ValueText;
801807
bool createdSymbol = false;
802808

@@ -841,13 +847,16 @@ public SymbolDefinition HandleVariableDeclaration(VariableDeclarationSyntax node
841847
symbolCreationScope.SetToLocalSymbol(newSymbol);
842848
}
843849
}
850+
851+
if (newSymbol != null)
852+
{
853+
VerifySyncValidForType(newSymbol.symbolCsType, syncMode);
854+
newSymbols.Add(newSymbol);
855+
}
844856
}
845857

846858
string udonTypeName = visitorContext.resolverContext.GetUdonTypeName(variableType);
847859

848-
if (newSymbol != null)
849-
VerifySyncValidForType(newSymbol.symbolCsType, syncMode);
850-
851860
bool isUserDefinedType = UdonSharpUtils.IsUserDefinedType(variableType);
852861

853862
if (!visitorContext.resolverContext.ValidateUdonTypeName(udonTypeName, UdonReferenceType.Variable) &&
@@ -856,7 +865,7 @@ public SymbolDefinition HandleVariableDeclaration(VariableDeclarationSyntax node
856865
!isUserDefinedType)
857866
throw new System.NotSupportedException($"Udon does not support variables of type '{variableType.Name}' yet");
858867

859-
return newSymbol;
868+
return newSymbols;
860869
}
861870

862871
public override void VisitIdentifierName(IdentifierNameSyntax node)

Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ protected override object DrawPublicVariableField(string symbol, object variable
682682
fieldDefinitions.TryGetValue(symbol, out fieldDefinition);
683683

684684
EditorGUI.BeginChangeCheck();
685-
object newValue = DrawFieldForType(null, symbol, (variableValue, variableType, fieldDefinition), fieldDefinition.fieldSymbol.userCsType, ref dirty, enabled);
685+
object newValue = DrawFieldForType(null, symbol, (variableValue, variableType, fieldDefinition), fieldDefinition != null ? fieldDefinition.fieldSymbol.userCsType : null, ref dirty, enabled);
686686

687687
if (EditorGUI.EndChangeCheck())
688688
{

Assets/UdonSharp/Examples/Tutorials/SpinningCubes/SpinningCubes_4_Signal.asset

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MonoBehaviour:
2020
null\r\n\r\n.data_end\r\n\r\n \r\n # using UnityEngine;\r\n \r\n
2121
\ # using VRC.SDK3.Components;\r\n \r\n # using VRC.SDKBase;\r\n
2222
\ \r\n # using VRC.Udon;\r\n \r\n # namespace UdonSharp.Examples.Tutorials\r\n
23-
\ \r\n # [AddComponentMenu(\"Udon Sharp/Tutorials/Spinning Cube
23+
\ \r\n # [AddComponentMenu(\"Udon Sharp/Tutorials/Spinning Cubes
2424
4 Signal\")]\r\n \r\n # public class SpinningCubes_4_Signal : UdonSharpBehaviour\r\n.code_start\r\n
2525
\ \r\n # public float speed = 60f;\r\n.code_end\r\n"
2626
assemblyError:
@@ -158,58 +158,59 @@ MonoBehaviour:
158158
- startInstruction: 0
159159
endInstruction: -1
160160
startSourceChar: 89
161-
endSourceChar: 185
161+
endSourceChar: 289
162162
line: 6
163163
lineChar: 0
164164
spanCodeSection: "namespace UdonSharp.Examples.Tutorials\r\n{\r\n /// <summary>\r\n
165-
\ /// \r\n /// </summary>\r\n "
165+
\ /// U# implementation of the fourth Udon spinning cube example (https://www.youtube.com/watch?v=HSpvrfWICeI)\r\n
166+
\ /// </summary>\r\n "
166167
- startInstruction: 0
167168
endInstruction: -1
168-
startSourceChar: 185
169-
endSourceChar: 292
169+
startSourceChar: 289
170+
endSourceChar: 397
170171
line: 11
171172
lineChar: 4
172-
spanCodeSection: "[AddComponentMenu(\"Udon Sharp/Tutorials/Spinning Cube 4 Signal\")]\r\n
173-
\ public class SpinningCubes_4_Signal "
173+
spanCodeSection: "[AddComponentMenu(\"Udon Sharp/Tutorials/Spinning Cubes 4
174+
Signal\")]\r\n public class SpinningCubes_4_Signal "
174175
- startInstruction: 0
175176
endInstruction: -1
176-
startSourceChar: 292
177-
endSourceChar: 294
177+
startSourceChar: 397
178+
endSourceChar: 399
178179
line: 12
179180
lineChar: 40
180181
spanCodeSection: ': '
181182
- startInstruction: 0
182183
endInstruction: -1
183-
startSourceChar: 294
184-
endSourceChar: 294
184+
startSourceChar: 399
185+
endSourceChar: 399
185186
line: 12
186187
lineChar: 42
187188
spanCodeSection:
188189
- startInstruction: 0
189190
endInstruction: -1
190-
startSourceChar: 294
191-
endSourceChar: 330
191+
startSourceChar: 399
192+
endSourceChar: 435
192193
line: 12
193194
lineChar: 42
194195
spanCodeSection: "UdonSharpBehaviour \r\n {\r\n "
195196
- startInstruction: 0
196197
endInstruction: -1
197-
startSourceChar: 330
198-
endSourceChar: 337
198+
startSourceChar: 435
199+
endSourceChar: 442
199200
line: 14
200201
lineChar: 8
201202
spanCodeSection: 'public '
202203
- startInstruction: 0
203204
endInstruction: -1
204-
startSourceChar: 337
205-
endSourceChar: 337
205+
startSourceChar: 442
206+
endSourceChar: 442
206207
line: 14
207208
lineChar: 15
208209
spanCodeSection:
209210
- startInstruction: 0
210211
endInstruction: 0
211-
startSourceChar: 337
212-
endSourceChar: 337
212+
startSourceChar: 442
213+
endSourceChar: 442
213214
line: 14
214215
lineChar: 15
215216
spanCodeSection:

Assets/UdonSharp/Examples/Tutorials/SpinningCubes/SpinningCubes_4_Spinner.asset

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ MonoBehaviour:
2626
\ \r\n # using UnityEngine;\r\n \r\n # using VRC.SDK3.Components;\r\n
2727
\ \r\n # using VRC.SDKBase;\r\n \r\n # using VRC.Udon;\r\n
2828
\ \r\n # namespace UdonSharp.Examples.Tutorials\r\n \r\n
29-
\ # public class SpinningCubes_4_Spinner : UdonSharpBehaviour\r\n.code_start\r\n
29+
\ # [AddComponentMenu(\"Udon Sharp/Tutorials/Spinning Cubes 4 Spinner\")]\r\n
30+
\ \r\n # public class SpinningCubes_4_Spinner : UdonSharpBehaviour\r\n.code_start\r\n
3031
\ \r\n # public SpinningCubes_4_Signal signal;\r\n \r\n #
3132
private void Update()\r\n .export _update\r\n \r\n _update:\r\n \r\n
3233
\ PUSH, __0_const_intnl_SystemUInt32\r\n PUSH, __0_intnl_returnTarget_UInt32\r\n
@@ -178,135 +179,137 @@ MonoBehaviour:
178179
- startInstruction: 0
179180
endInstruction: -1
180181
startSourceChar: 89
181-
endSourceChar: 185
182+
endSourceChar: 289
182183
line: 6
183184
lineChar: 0
184185
spanCodeSection: "namespace UdonSharp.Examples.Tutorials\r\n{\r\n /// <summary>\r\n
185-
\ /// \r\n /// </summary>\r\n "
186+
\ /// U# implementation of the fourth Udon spinning cube example (https://www.youtube.com/watch?v=HSpvrfWICeI)\r\n
187+
\ /// </summary>\r\n "
186188
- startInstruction: 0
187189
endInstruction: -1
188-
startSourceChar: 185
189-
endSourceChar: 222
190+
startSourceChar: 289
191+
endSourceChar: 399
190192
line: 11
191193
lineChar: 4
192-
spanCodeSection: 'public class SpinningCubes_4_Spinner '
194+
spanCodeSection: "[AddComponentMenu(\"Udon Sharp/Tutorials/Spinning Cubes 4
195+
Spinner\")]\r\n public class SpinningCubes_4_Spinner "
193196
- startInstruction: 0
194197
endInstruction: -1
195-
startSourceChar: 222
196-
endSourceChar: 224
197-
line: 11
198+
startSourceChar: 399
199+
endSourceChar: 401
200+
line: 12
198201
lineChar: 41
199202
spanCodeSection: ': '
200203
- startInstruction: 0
201204
endInstruction: -1
202-
startSourceChar: 224
203-
endSourceChar: 224
204-
line: 11
205+
startSourceChar: 401
206+
endSourceChar: 401
207+
line: 12
205208
lineChar: 43
206209
spanCodeSection:
207210
- startInstruction: 0
208211
endInstruction: -1
209-
startSourceChar: 224
210-
endSourceChar: 260
211-
line: 11
212+
startSourceChar: 401
213+
endSourceChar: 437
214+
line: 12
212215
lineChar: 43
213216
spanCodeSection: "UdonSharpBehaviour \r\n {\r\n "
214217
- startInstruction: 0
215218
endInstruction: -1
216-
startSourceChar: 260
217-
endSourceChar: 267
218-
line: 13
219+
startSourceChar: 437
220+
endSourceChar: 444
221+
line: 14
219222
lineChar: 8
220223
spanCodeSection: 'public '
221224
- startInstruction: 0
222225
endInstruction: -1
223-
startSourceChar: 267
224-
endSourceChar: 267
225-
line: 13
226+
startSourceChar: 444
227+
endSourceChar: 444
228+
line: 14
226229
lineChar: 15
227230
spanCodeSection:
228231
- startInstruction: 0
229232
endInstruction: -1
230-
startSourceChar: 267
231-
endSourceChar: 309
232-
line: 13
233+
startSourceChar: 444
234+
endSourceChar: 486
235+
line: 14
233236
lineChar: 15
234237
spanCodeSection: "SpinningCubes_4_Signal signal;\r\n\r\n "
235238
- startInstruction: 0
236239
endInstruction: 19
237-
startSourceChar: 309
238-
endSourceChar: 340
239-
line: 15
240+
startSourceChar: 486
241+
endSourceChar: 517
242+
line: 16
240243
lineChar: 8
241244
spanCodeSection: "private void Update()\r\n "
242245
- startInstruction: 20
243246
endInstruction: 19
244-
startSourceChar: 340
245-
endSourceChar: 355
246-
line: 16
247+
startSourceChar: 517
248+
endSourceChar: 532
249+
line: 17
247250
lineChar: 8
248251
spanCodeSection: "{\r\n "
249252
- startInstruction: 20
250253
endInstruction: 19
251-
startSourceChar: 355
252-
endSourceChar: 355
253-
line: 17
254+
startSourceChar: 532
255+
endSourceChar: 532
256+
line: 18
254257
lineChar: 12
255258
spanCodeSection:
256259
- startInstruction: 20
257260
endInstruction: 19
258-
startSourceChar: 355
259-
endSourceChar: 372
260-
line: 17
261+
startSourceChar: 532
262+
endSourceChar: 549
263+
line: 18
261264
lineChar: 12
262265
spanCodeSection: transform.Rotate(
263266
- startInstruction: 20
264267
endInstruction: 19
265-
startSourceChar: 372
266-
endSourceChar: 372
267-
line: 17
268+
startSourceChar: 549
269+
endSourceChar: 549
270+
line: 18
268271
lineChar: 29
269272
spanCodeSection:
270273
- startInstruction: 20
271274
endInstruction: 19
272-
startSourceChar: 372
273-
endSourceChar: 380
274-
line: 17
275+
startSourceChar: 549
276+
endSourceChar: 557
277+
line: 18
275278
lineChar: 29
276279
spanCodeSection: Vector3.
277280
- startInstruction: 20
278281
endInstruction: 35
279-
startSourceChar: 380
280-
endSourceChar: 384
281-
line: 17
282+
startSourceChar: 557
283+
endSourceChar: 561
284+
line: 18
282285
lineChar: 37
283286
spanCodeSection: 'up, '
284287
- startInstruction: 36
285288
endInstruction: 35
286-
startSourceChar: 384
287-
endSourceChar: 399
288-
line: 17
289+
startSourceChar: 561
290+
endSourceChar: 576
291+
line: 18
289292
lineChar: 41
290293
spanCodeSection: 'signal.speed * '
291294
- startInstruction: 36
292295
endInstruction: 35
293-
startSourceChar: 399
294-
endSourceChar: 399
295-
line: 17
296+
startSourceChar: 576
297+
endSourceChar: 576
298+
line: 18
296299
lineChar: 56
297300
spanCodeSection:
298301
- startInstruction: 36
299302
endInstruction: 35
300-
startSourceChar: 399
301-
endSourceChar: 404
302-
line: 17
303+
startSourceChar: 576
304+
endSourceChar: 581
305+
line: 18
303306
lineChar: 56
304307
spanCodeSection: Time.
305308
- startInstruction: 36
306309
endInstruction: 36
307-
startSourceChar: 404
308-
endSourceChar: 404
309-
line: 17
310+
startSourceChar: 581
311+
endSourceChar: 581
312+
line: 18
310313
lineChar: 61
311314
spanCodeSection:
312315
serializationData:

0 commit comments

Comments
 (0)