diff --git a/Assets/UdonSharp/Editor/UdonSharpAssemblyBuilder.cs b/Assets/UdonSharp/Editor/UdonSharpAssemblyBuilder.cs index db8df2eb..f4f7ec76 100644 --- a/Assets/UdonSharp/Editor/UdonSharpAssemblyBuilder.cs +++ b/Assets/UdonSharp/Editor/UdonSharpAssemblyBuilder.cs @@ -1,7 +1,9 @@  //#define USE_UDON_LABELS +using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Text; @@ -39,6 +41,8 @@ public string GetAssemblyStr(LabelTable labelTable = null) } #if !USE_UDON_LABELS + private static readonly char[] _trimChars = new[] {' ', '\n', '\r'}; + private string ReplaceLabels(string assemblyString, LabelTable labelTable) { StringBuilder newAssemblyBuilder = new StringBuilder(); @@ -49,26 +53,27 @@ private string ReplaceLabels(string assemblyString, LabelTable labelTable) while (currentLine != null) { - string line = currentLine.TrimStart(' ', '\n', '\r'); - if (line.StartsWith("JUMP_LABEL,")) + string line = currentLine.TrimStart(_trimChars); + if (line.StartsWith("JUMP_LABEL,", StringComparison.Ordinal)) { int startIdx = line.IndexOf('[') + 1; int endIdx = line.IndexOf(']'); string labelName = line.Substring(startIdx, endIdx - startIdx); JumpLabel label = labelTable.GetLabel(labelName); - newAssemblyBuilder.Append($" JUMP, {label.AddresStr()}\n"); + newAssemblyBuilder.AppendFormat(" JUMP, {0}\n", label.AddresStr()); } - else if (line.StartsWith("JUMP_IF_FALSE_LABEL,")) + else if (line.StartsWith("JUMP_IF_FALSE_LABEL,", StringComparison.Ordinal)) { int startIdx = line.IndexOf('[') + 1; int endIdx = line.IndexOf(']'); string labelName = line.Substring(startIdx, endIdx - startIdx); JumpLabel label = labelTable.GetLabel(labelName); - newAssemblyBuilder.Append($" JUMP_IF_FALSE, {label.AddresStr()}\n"); + newAssemblyBuilder.AppendFormat(" JUMP_IF_FALSE, {0}\n", label.AddresStr()); } else { - newAssemblyBuilder.Append(currentLine + "\n"); + newAssemblyBuilder.Append(currentLine); + newAssemblyBuilder.Append("\n"); } currentLine = reader.ReadLine(); @@ -86,10 +91,6 @@ public int GetExternStrCount() public void AppendCommentedLine(string line, string comment, int indent = 2) { - // Make sure the comment stays on the same line - comment.Replace('\n', ' '); - comment.Replace('\r', ' '); - //if (programCounter > 0) // assemblyTextBuilder.AppendFormat(" # {0:X8}\n", programCounter); diff --git a/Assets/UdonSharp/Editor/UdonSharpClassDebugInfo.cs b/Assets/UdonSharp/Editor/UdonSharpClassDebugInfo.cs index 8712b342..5cf33df0 100644 --- a/Assets/UdonSharp/Editor/UdonSharpClassDebugInfo.cs +++ b/Assets/UdonSharp/Editor/UdonSharpClassDebugInfo.cs @@ -50,7 +50,7 @@ public void UpdateSyntaxNode(SyntaxNode node) if (debugSpans.Count == 0) debugSpans.Add(new DebugLineSpan()); - int nodeSpanStart = node.Span.Start; + int nodeSpanStart = node.SpanStart; if (nodeSpanStart < mostRecentSpanStart || nodeSpanStart >= sourceText.Length) return; @@ -60,12 +60,12 @@ public void UpdateSyntaxNode(SyntaxNode node) DebugLineSpan lastLineSpan = debugSpans.Last(); lastLineSpan.endInstruction = assemblyBuilder.programCounter - 1; - lastLineSpan.endSourceChar = node.SpanStart; + lastLineSpan.endSourceChar = nodeSpanStart; //lastLineSpan.spanCodeSection = sourceText.Substring(lastLineSpan.startSourceChar, lastLineSpan.endSourceChar - lastLineSpan.startSourceChar); DebugLineSpan nextLineSpan = new DebugLineSpan(); nextLineSpan.startInstruction = assemblyBuilder.programCounter; - nextLineSpan.startSourceChar = node.SpanStart; + nextLineSpan.startSourceChar = nodeSpanStart; debugSpans.Add(nextLineSpan); diff --git a/Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs b/Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs index 67eee133..f83bb989 100644 --- a/Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs +++ b/Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs @@ -197,16 +197,18 @@ private string BuildHeapDataBlock() // Prettify the symbol order in the data block // Reflection info goes first so that we can use it for knowing what script threw an error from in game logs foreach (SymbolDefinition symbol in moduleSymbols.GetAllUniqueChildSymbols() - .OrderBy(e => e.declarationType.HasFlag(SymbolDeclTypeFlags.Reflection)) - .ThenBy(e => e.declarationType.HasFlag(SymbolDeclTypeFlags.Public)) - .ThenBy(e => e.declarationType.HasFlag(SymbolDeclTypeFlags.Private)) - .ThenBy(e => e.declarationType.HasFlag(SymbolDeclTypeFlags.This)) - .ThenBy(e => !e.declarationType.HasFlag(SymbolDeclTypeFlags.Internal)) - .ThenBy(e => e.declarationType.HasFlag(SymbolDeclTypeFlags.Constant)) + .OrderBy(e => (e.declarationType & SymbolDeclTypeFlags.Reflection) != 0) + .ThenBy(e => (e.declarationType & SymbolDeclTypeFlags.Public) != 0) + .ThenBy(e => (e.declarationType & SymbolDeclTypeFlags.Private) != 0) + .ThenBy(e => (e.declarationType & SymbolDeclTypeFlags.This) != 0) + .ThenBy(e => (e.declarationType & SymbolDeclTypeFlags.Internal) == 0) + .ThenBy(e => (e.declarationType &SymbolDeclTypeFlags.Constant) != 0) .ThenByDescending(e => e.symbolCsType.Name) - .ThenByDescending(e => e.symbolUniqueName).Reverse()) + //.ThenByDescending(e => e.symbolUniqueName) + .Reverse() + ) { - if (symbol.declarationType.HasFlag(SymbolDeclTypeFlags.This)) + if ((symbol.declarationType & SymbolDeclTypeFlags.This) != 0) builder.AppendLine($"{symbol.symbolUniqueName}: %{symbol.symbolResolvedTypeName}, this", 1); else builder.AppendLine($"{symbol.symbolUniqueName}: %{symbol.symbolResolvedTypeName}, null", 1); diff --git a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs index 04270680..ebb5f505 100644 --- a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs +++ b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs @@ -2337,12 +2337,18 @@ private bool HandleLocalUdonBehaviourMethodLookup(string localUdonMethodName) return true; } + private static readonly PropertyInfo[] _componentProperties = + typeof(Component).GetProperties(BindingFlags.Instance | BindingFlags.Public); + + private static readonly PropertyInfo[] _udonEventReceiverProperties = + typeof(VRC.Udon.Common.Interfaces.IUdonEventReceiver).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + private bool HandleLocalUdonBehaviourPropertyLookup(string localUdonPropertyName) { - PropertyInfo[] foundProperties = typeof(Component).GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(e => e.Name == localUdonPropertyName).ToArray(); + PropertyInfo[] foundProperties = _componentProperties.Where(e => e.Name == localUdonPropertyName).ToArray(); if (localUdonPropertyName == "enabled") - foundProperties = typeof(VRC.Udon.Common.Interfaces.IUdonEventReceiver).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(e => e.Name == localUdonPropertyName).ToArray(); + foundProperties = _udonEventReceiverProperties.Where(e => e.Name == localUdonPropertyName).ToArray(); if (foundProperties.Length == 0) return false; @@ -2586,6 +2592,9 @@ private bool HandleMemberFieldAccess(string fieldToken) return true; } + private static readonly MethodInfo[] _objectMethods = + typeof(object).GetMethods(BindingFlags.Public | BindingFlags.Instance); + private bool HandleMemberMethodLookup(string methodToken) { if (captureArchetype != ExpressionCaptureArchetype.LocalSymbol && @@ -2603,7 +2612,7 @@ private bool HandleMemberMethodLookup(string methodToken) List foundMethodInfos = new List(returnType.GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(e => e.Name == methodToken)); if (returnType != typeof(object)) - foundMethodInfos.AddRange(typeof(object).GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(e => e.Name == methodToken)); + foundMethodInfos.AddRange(_objectMethods.Where(e => e.Name == methodToken)); if (foundMethodInfos.Count == 0) return false; diff --git a/Assets/UdonSharp/Editor/UdonSharpResolverContext.cs b/Assets/UdonSharp/Editor/UdonSharpResolverContext.cs index 81ce0635..a5ff54c1 100644 --- a/Assets/UdonSharp/Editor/UdonSharpResolverContext.cs +++ b/Assets/UdonSharp/Editor/UdonSharpResolverContext.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Text; using UnityEngine; using VRC.Udon.Editor; using VRC.Udon.Graph; @@ -427,18 +428,18 @@ public string GetUdonMethodName(MethodBase externMethod, bool validate = true, L } string paramStr = ""; - + if (methodParams.Length > 0) { - paramStr += "_"; // Arg separator - + paramStr = "_"; // Arg separator + foreach (ParameterInfo parameterInfo in methodParams) { paramStr += $"_{GetUdonTypeName(parameterInfo.ParameterType, true)}"; } } else if (externMethod is ConstructorInfo) - paramStr += "__"; + paramStr = "__"; string returnStr = ""; diff --git a/Assets/UdonSharp/Editor/UdonSharpUtils.cs b/Assets/UdonSharp/Editor/UdonSharpUtils.cs index b3580d0a..d7dded84 100644 --- a/Assets/UdonSharp/Editor/UdonSharpUtils.cs +++ b/Assets/UdonSharp/Editor/UdonSharpUtils.cs @@ -503,12 +503,15 @@ public static System.Type GetRootElementType(System.Type type) private static Dictionary GetInheritedTypeMap() { + if (inheritedTypeMap != null) + return inheritedTypeMap; + lock (inheritedTypeMapLock) { if (inheritedTypeMap != null) return inheritedTypeMap; - - inheritedTypeMap = new Dictionary(); + + Dictionary typeMap = new Dictionary(); IEnumerable typeList = System.AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == "VRCSDK3").GetTypes().Where(t => t != null && t.Namespace != null && t.Namespace.StartsWith("VRC.SDK3.Components")); @@ -516,12 +519,14 @@ public static System.Type GetRootElementType(System.Type type) { if (childType.BaseType != null && childType.BaseType.Namespace.StartsWith("VRC.SDKBase")) { - inheritedTypeMap.Add(childType.BaseType, childType); + typeMap.Add(childType.BaseType, childType); } } - inheritedTypeMap.Add(typeof(VRC.SDK3.Video.Components.VRCUnityVideoPlayer), typeof(VRC.SDK3.Video.Components.Base.BaseVRCVideoPlayer)); - inheritedTypeMap.Add(typeof(VRC.SDK3.Video.Components.AVPro.VRCAVProVideoPlayer), typeof(VRC.SDK3.Video.Components.Base.BaseVRCVideoPlayer)); + typeMap.Add(typeof(VRC.SDK3.Video.Components.VRCUnityVideoPlayer), typeof(VRC.SDK3.Video.Components.Base.BaseVRCVideoPlayer)); + typeMap.Add(typeof(VRC.SDK3.Video.Components.AVPro.VRCAVProVideoPlayer), typeof(VRC.SDK3.Video.Components.Base.BaseVRCVideoPlayer)); + + inheritedTypeMap = typeMap; } return inheritedTypeMap;