Skip to content

Commit

Permalink
Merge branch 'master' into sync-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Apr 17, 2021
2 parents 7d13435 + 2cb4a66 commit 6cca77f
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 132 deletions.
18 changes: 17 additions & 1 deletion Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,26 @@ public override void VisitArrayCreationExpression(ArrayCreationExpressionSyntax
}
else
{
SymbolDefinition capturedRank;

using (ExpressionCaptureScope rankCapture = new ExpressionCaptureScope(visitorContext, null))
{
Visit(node.Type.RankSpecifiers[0]);
arrayRankSymbol = rankCapture.ExecuteGet();
capturedRank = rankCapture.ExecuteGet();
}

if (capturedRank.symbolCsType == typeof(int))
{
arrayRankSymbol = capturedRank;
}
else
{
using (ExpressionCaptureScope convertScope = new ExpressionCaptureScope(visitorContext, null))
{
arrayRankSymbol = visitorContext.topTable.CreateUnnamedSymbol(typeof(int), SymbolDeclTypeFlags.Internal);
convertScope.SetToLocalSymbol(arrayRankSymbol);
convertScope.ExecuteSet(capturedRank, true);
}
}
}

Expand Down
26 changes: 23 additions & 3 deletions Assets/UdonSharp/Editor/UdonSharpClassDebugInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@


using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -37,15 +38,15 @@ public class DebugLineSpan
private List<DebugLineSpan> debugSpans;
private bool includeInlineCode;

public ClassDebugInfo(string source, bool includeInlineCodeIn)
internal ClassDebugInfo(string source, bool includeInlineCodeIn)
{
sourceText = source;
mostRecentSpanStart = 0;
debugSpans = new List<DebugLineSpan>();
includeInlineCode = includeInlineCodeIn;
}

public void UpdateSyntaxNode(SyntaxNode node)
internal void UpdateSyntaxNode(SyntaxNode node)
{
if (debugSpans.Count == 0)
debugSpans.Add(new DebugLineSpan());
Expand Down Expand Up @@ -102,7 +103,7 @@ public void UpdateSyntaxNode(SyntaxNode node)
}
}

public void FinalizeDebugInfo()
internal void FinalizeDebugInfo()
{
serializedDebugSpans = new DebugLineSpan[debugSpans.Count];

Expand Down Expand Up @@ -139,5 +140,24 @@ public void FinalizeDebugInfo()
serializedDebugSpans[i].lineChar = lineChar;
}
}

/// <summary>
/// Gets the debug line span from a given program counter
/// </summary>
/// <param name="programCounter"></param>
/// <returns></returns>
[PublicAPI]
public DebugLineSpan GetLineFromProgramCounter(int programCounter)
{
int debugSpanIdx = System.Array.BinarySearch(DebugLineSpans.Select(e => e.endInstruction).ToArray(), programCounter);
if (debugSpanIdx < 0)
debugSpanIdx = ~debugSpanIdx;

debugSpanIdx = UnityEngine.Mathf.Clamp(debugSpanIdx, 0, DebugLineSpans.Length - 1);

ClassDebugInfo.DebugLineSpan debugLineSpan = DebugLineSpans[debugSpanIdx];

return debugLineSpan;
}
}
}
7 changes: 5 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using System.CodeDom.Compiler;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -690,9 +692,10 @@ private int RunFieldInitalizers(CompilationModule[] compiledModules)
}
else
{
memoryStream.Seek(0, SeekOrigin.Begin);
Assembly assembly;

Assembly assembly = Assembly.Load(memoryStream.ToArray());
using (var loadScope = new UdonSharpUtils.UdonSharpAssemblyLoadStripScope())
assembly = Assembly.Load(memoryStream.ToArray());

for (int moduleIdx = 0; moduleIdx < modulesToInitialize.Length; ++moduleIdx)
{
Expand Down
18 changes: 16 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpEditorCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using JetBrains.Annotations;
using System.Collections.Generic;
using System.IO;
using UdonSharp.Compiler;
Expand All @@ -13,7 +14,7 @@ namespace UdonSharp
/// Handles cache data for U# that gets saved to the Library. All data this uses is intermediate generated data that is not required and can be regenerated from the source files.
/// </summary>
[InitializeOnLoad]
internal class UdonSharpEditorCache
public class UdonSharpEditorCache
{
#region Instance and serialization management
[System.Serializable]
Expand All @@ -31,7 +32,7 @@ struct SourceHashLookupStorage
public static UdonSharpEditorCache Instance => GetInstance();

static UdonSharpEditorCache _instance;
static object instanceLock = new object();
static readonly object instanceLock = new object();

private static UdonSharpEditorCache GetInstance()
{
Expand Down Expand Up @@ -298,6 +299,13 @@ void SaveDebugInfo(UdonSharpProgramAsset sourceProgram, DebugInfoType debugInfoT

Dictionary<UdonSharpProgramAsset, Dictionary<DebugInfoType, ClassDebugInfo>> _classDebugInfoLookup = new Dictionary<UdonSharpProgramAsset, Dictionary<DebugInfoType, ClassDebugInfo>>();

/// <summary>
/// Gets the debug info for a given program asset. If debug info type for Client is specified when there is no client debug info, will fall back to Editor debug info.
/// </summary>
/// <param name="sourceProgram"></param>
/// <param name="debugInfoType"></param>
/// <returns></returns>
[PublicAPI]
public ClassDebugInfo GetDebugInfo(UdonSharpProgramAsset sourceProgram, DebugInfoType debugInfoType)
{
if (!_classDebugInfoLookup.TryGetValue(sourceProgram, out var debugInfo))
Expand Down Expand Up @@ -392,6 +400,12 @@ void FlushUasmCache()
}
}

/// <summary>
/// Gets the uasm string for the last build of the given program asset
/// </summary>
/// <param name="programAsset"></param>
/// <returns></returns>
[PublicAPI]
public string GetUASMStr(UdonSharpProgramAsset programAsset)
{
if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(programAsset, out string guid, out long _))
Expand Down
Loading

0 comments on commit 6cca77f

Please sign in to comment.