From 367034373f2451778c0ec4df50467c28a7eb08bd Mon Sep 17 00:00:00 2001 From: Merlin <36685500+Merlin-san@users.noreply.github.com> Date: Tue, 7 Apr 2020 16:26:07 -0700 Subject: [PATCH] More leniant handling on the binary expression copying - Only create a new intermediate value when we captured a scope that hasn't already necessarily created a new intermediate variable --- .../UdonSharp/Editor/UdonSharpASTVisitor.cs | 19 +++++++++++++------ .../Editor/UdonSharpExpressionCapture.cs | 5 +++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs b/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs index 1bb7b7db..f432bbc5 100644 --- a/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs +++ b/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs @@ -1574,15 +1574,22 @@ public override void VisitBinaryExpression(BinaryExpressionSyntax node) { Visit(node.Left); - // This needs to be copied because someone can do an in place assignment operator on the rhs that changes the lhs value - SymbolDefinition lhsCopy = visitorContext.topTable.CreateUnnamedSymbol(lhsCapture.GetReturnType(true), SymbolDeclTypeFlags.Internal); - using (ExpressionCaptureScope lhsCopySetter = new ExpressionCaptureScope(visitorContext, null)) + if (lhsCapture.DoesReturnIntermediateSymbol()) { - lhsCopySetter.SetToLocalSymbol(lhsCopy); - lhsCopySetter.ExecuteSetDirect(lhsCapture); + lhsValue = lhsCapture.ExecuteGet(); } + else + { + // This needs to be copied because someone can do an in place assignment operator on the rhs that changes the lhs value + SymbolDefinition lhsCopy = visitorContext.topTable.CreateUnnamedSymbol(lhsCapture.GetReturnType(true), SymbolDeclTypeFlags.Internal); + using (ExpressionCaptureScope lhsCopySetter = new ExpressionCaptureScope(visitorContext, null)) + { + lhsCopySetter.SetToLocalSymbol(lhsCopy); + lhsCopySetter.ExecuteSetDirect(lhsCapture); + } - lhsValue = lhsCopy; + lhsValue = lhsCopy; + } using (ExpressionCaptureScope rhsCapture = new ExpressionCaptureScope(visitorContext, null)) { diff --git a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs index 33ab92b1..0b4b1b6c 100644 --- a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs +++ b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs @@ -1414,6 +1414,11 @@ public System.Type GetReturnType(bool getUserType = false) } } + public bool DoesReturnIntermediateSymbol() + { + return !IsLocalSymbol(); + } + public bool ResolveAccessToken(string accessToken) { bool resolvedToken = false;