Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
More leniant handling on the binary expression copying
Browse files Browse the repository at this point in the history
- Only create a new intermediate value when we captured a scope that hasn't already necessarily created a new intermediate variable
  • Loading branch information
MerlinVR committed Apr 7, 2020
1 parent 8ffa1ca commit 3670343
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
5 changes: 5 additions & 0 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,11 @@ public System.Type GetReturnType(bool getUserType = false)
}
}

public bool DoesReturnIntermediateSymbol()
{
return !IsLocalSymbol();
}

public bool ResolveAccessToken(string accessToken)
{
bool resolvedToken = false;
Expand Down

0 comments on commit 3670343

Please sign in to comment.