Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix that method and property, from user script containing property is not executed. #90

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public CompileTaskResult Compile(List<ClassDefinition> classDefinitions, Microso
debugInfo = new ClassDebugInfo(sourceCode, settings == null || settings.includeInlineCode);
}

PropertyVisitor propertyVisitor = new PropertyVisitor(resolver, moduleSymbols, moduleLabels);
MethodVisitor methodVisitor = new MethodVisitor(resolver, moduleSymbols, moduleLabels);

try
{
propertyVisitor.Visit(syntaxTree.GetRoot());
methodVisitor.Visit(syntaxTree.GetRoot());
}
catch (System.Exception e)
{
LogException(result, e, propertyVisitor.visitorContext.currentNode, out string logMessage);
LogException(result, e, methodVisitor.visitorContext.currentNode, out string logMessage);

programAsset.compileErrors.Add(logMessage);

Expand All @@ -104,16 +104,15 @@ public CompileTaskResult Compile(List<ClassDefinition> classDefinitions, Microso
if (ErrorCount > 0)
return result;

UdonSharpFieldVisitor fieldVisitor = new UdonSharpFieldVisitor(fieldsWithInitializers, resolver, moduleSymbols, moduleLabels, classDefinitions, debugInfo);
fieldVisitor.visitorContext.definedProperties = propertyVisitor.definedProperties;
PropertyVisitor propertyVisitor = new PropertyVisitor(resolver, moduleSymbols, moduleLabels);

try
{
fieldVisitor.Visit(syntaxTree.GetRoot());
propertyVisitor.Visit(syntaxTree.GetRoot());
}
catch (System.Exception e)
{
LogException(result, e, fieldVisitor.visitorContext.currentNode, out string logMessage);
LogException(result, e, propertyVisitor.visitorContext.currentNode, out string logMessage);

programAsset.compileErrors.Add(logMessage);

Expand All @@ -123,15 +122,16 @@ public CompileTaskResult Compile(List<ClassDefinition> classDefinitions, Microso
if (ErrorCount > 0)
return result;

MethodVisitor methodVisitor = new MethodVisitor(resolver, moduleSymbols, moduleLabels);
UdonSharpFieldVisitor fieldVisitor = new UdonSharpFieldVisitor(fieldsWithInitializers, resolver, moduleSymbols, moduleLabels, classDefinitions, debugInfo);
fieldVisitor.visitorContext.definedProperties = propertyVisitor.definedProperties;

try
{
methodVisitor.Visit(syntaxTree.GetRoot());
fieldVisitor.Visit(syntaxTree.GetRoot());
}
catch (System.Exception e)
{
LogException(result, e, methodVisitor.visitorContext.currentNode, out string logMessage);
LogException(result, e, fieldVisitor.visitorContext.currentNode, out string logMessage);

programAsset.compileErrors.Add(logMessage);

Expand Down
6 changes: 4 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ public SymbolDefinition ExecuteGet()
if (getter.type == typeof(void))
throw new System.TypeLoadException("Cannot return type of void from a get statement");

outSymbol = AllocateOutputSymbol(getter.type);

using (ExpressionCaptureScope getPropertyMethodScope = new ExpressionCaptureScope(visitorContext, null, requestedDestination))
{
getPropertyMethodScope.SetToLocalSymbol(accessSymbol);
Expand All @@ -509,8 +511,8 @@ public SymbolDefinition ExecuteGet()
getReturnScope.SetToLocalSymbol(accessSymbol);
getReturnScope.ResolveAccessToken("GetProgramVariable");

outSymbol = getReturnScope.Invoke(new SymbolDefinition[] { visitorContext.topTable.CreateConstSymbol(typeof(string), getter.returnSymbol.symbolUniqueName) });
outSymbol = CastSymbolToType(outSymbol, getter.type, true, true, outSymbol == requestedDestination ? requestedDestination : null);
SymbolDefinition externVarReturn = getReturnScope.Invoke(new SymbolDefinition[] { visitorContext.topTable.CreateConstSymbol(typeof(string), getter.returnSymbol.symbolUniqueName) });
outSymbol = CastSymbolToType(externVarReturn, getter.type, true, true, outSymbol == requestedDestination ? requestedDestination : null);
}
}
else if (captureArchetype == ExpressionCaptureArchetype.Field)
Expand Down
64 changes: 61 additions & 3 deletions Assets/UdonSharp/Tests/IntegrationTestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,62 @@ Transform:
m_Father: {fileID: 2106575507}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1539463956
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1539463958}
- component: {fileID: 1539463957}
m_Layer: 0
m_Name: ReferenceObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1539463957
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1539463956}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 45115577ef41a5b4ca741ed302693907, type: 3}
m_Name:
m_EditorClassIdentifier:
interactTextPlacement: {fileID: 0}
interactText: Use
interactTextGO: {fileID: 0}
proximity: 2
SynchronizePosition: 0
AllowCollisionOwnershipTransfer: 0
Reliable: 0
serializedProgramAsset: {fileID: 11400000, guid: bef784e0281804842a373a59335593b3,
type: 2}
programSource: {fileID: 11400000, guid: 5225e1aa92efda9499c6c5220abd76f2, type: 2}
serializedPublicVariablesBytesString: Ai8AAAAAATIAAABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlAFQAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AAAAAAAYBAAAAAAAAACcBBAAAAHQAeQBwAGUAAWgAAABTAHkAcwB0AGUAbQAuAEMAbwBsAGwAZQBjAHQAaQBvAG4AcwAuAEcAZQBuAGUAcgBpAGMALgBMAGkAcwB0AGAAMQBbAFsAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4ALgBJAG4AdABlAHIAZgBhAGMAZQBzAC4ASQBVAGQAbwBuAFYAYQByAGkAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AXQBdACwAIABtAHMAYwBvAHIAbABpAGIAAQEJAAAAVgBhAHIAaQBhAGIAbABlAHMALwEAAAABaAAAAFMAeQBzAHQAZQBtAC4AQwBvAGwAbABlAGMAdABpAG8AbgBzAC4ARwBlAG4AZQByAGkAYwAuAEwAaQBzAHQAYAAxAFsAWwBWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAEkAbgB0AGUAcgBmAGEAYwBlAHMALgBJAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlACwAIABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgBdAF0ALAAgAG0AcwBjAG8AcgBsAGkAYgABAAAABgAAAAAAAAAABwUHBQ==
publicVariablesUnityEngineObjects: []
publicVariablesSerializationDataFormat: 0
--- !u!4 &1539463958
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1539463956}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1954857073}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1546222824
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -8356,8 +8412,9 @@ MonoBehaviour:
serializedProgramAsset: {fileID: 11400000, guid: c341eeb82008276418f85fd69d4dd8b3,
type: 2}
programSource: {fileID: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B5AHAAZQABIAAAAFYAUgBDAC4AVQBkAG8AbgAuAFUAZABvAG4AQgBlAGgAYQB2AGkAbwB1AHIALAAgAFYAUgBDAC4AVQBkAG8AbgALAQUAAABWAGEAbAB1AGUAAAAAAAcFBwUHBQ==
publicVariablesUnityEngineObjects:
- {fileID: 1539463957}
publicVariablesSerializationDataFormat: 0
--- !u!4 &1954857073
Transform:
Expand All @@ -8369,7 +8426,8 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 1539463958}
m_Father: {fileID: 1722523552}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down
8 changes: 8 additions & 0 deletions Assets/UdonSharp/Tests/TestScripts/Core/PropertyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public GameObject GOCallbackTest
}
}

public PropertyTestReferenceScript referenceSource;

public void ExecuteTests()
{
PropertyTest self = this;
Expand Down Expand Up @@ -156,6 +158,12 @@ public void ExecuteTests()
SetProgramVariable(nameof(_GOCallbackTest), null);

tester.TestAssertion("Property callback modification count", goCallbackCounter == 4);

tester.TestAssertion("Property in othrer user script 1", referenceSource.Value == 1);
referenceSource._value = 2;
tester.TestAssertion("Property in othrer user script 2", referenceSource.Value == 2);
referenceSource.Value = 3;
tester.TestAssertion("Property in othrer user script 3", referenceSource.Value == 3);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: PropertyTestReferenceScript
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: bef784e0281804842a373a59335593b3,
type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: f06b58bb82787dd4cb7ac2075712e0e7, type: 3}
behaviourSyncMode: 0
behaviourIDHeapVarName: __refl_const_intnl_udonTypeID
compileErrors: []
hasInteractEvent: 0
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _value
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: fieldSymbol
Entry: 7
Data: 3|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor
- Name: internalType
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: declarationType
Entry: 3
Data: 2
- Name: syncMode
Entry: 3
Data: 0
- Name: symbolResolvedTypeName
Entry: 1
Data: SystemInt32
- Name: symbolOriginalName
Entry: 1
Data: _value
- Name: symbolUniqueName
Entry: 1
Data: _value
- Name: symbolDefaultValue
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: fieldAttributes
Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|System.NonSerializedAttribute, mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name: userBehaviourSource
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

namespace UdonSharp.Tests
{
[AddComponentMenu("Udon Sharp/Tests/UserPropertyTest")]

public class PropertyTestReferenceScript : UdonSharpBehaviour
{
[System.NonSerialized]
public int _value = 1;
public int Value { get => _value; set => _value = value; }
public int GetValue() => _value;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.