public override void VisitCompilationUnit(CompilationUnitSyntax node) { base.VisitCompilationUnit(node); try { methodVisitor.Visit(node); } catch (System.Exception e) { visitorContext.currentNode = methodVisitor.visitorContext.currentNode; throw e; } classDefinition.methodDefinitions = methodVisitor.definedMethods; try { propertyVisitor.Visit(node); } catch (System.Exception e) { visitorContext.currentNode = propertyVisitor.visitorContext.currentNode; throw e; } classDefinition.propertyDefinitions = propertyVisitor.definedProperties; if (classCount == 0) { throw new System.Exception($"No UdonSharpBehaviour class found in script file, you must define an UdonSharpBehaviour class in a script referenced by an UdonSharpProgramAsset"); } }
public CompileTaskResult Compile(List <ClassDefinition> classDefinitions, Microsoft.CodeAnalysis.SyntaxTree syntaxTree, string sourceCode, bool isEditorBuild) { programAsset.compileErrors.Clear(); CompileTaskResult result = new CompileTaskResult(); result.programAsset = programAsset; moduleSymbols.OpenSymbolTable(); UdonSharpFieldVisitor fieldVisitor = new UdonSharpFieldVisitor(fieldsWithInitializers); fieldVisitor.Visit(syntaxTree.GetRoot()); MethodVisitor methodVisitor = new MethodVisitor(resolver, moduleSymbols, moduleLabels); int errorCount = 0; try { methodVisitor.Visit(syntaxTree.GetRoot()); } catch (System.Exception e) { LogException(result, e, methodVisitor.visitorContext.currentNode, out string logMessage); programAsset.compileErrors.Add(logMessage); errorCount++; } if (ErrorCount > 0) { return(result); } ClassDebugInfo debugInfo = null; if (settings == null || settings.buildDebugInfo) { debugInfo = new ClassDebugInfo(sourceCode, settings == null || settings.includeInlineCode); } ASTVisitor visitor = new ASTVisitor(resolver, moduleSymbols, moduleLabels, methodVisitor.definedMethods, classDefinitions, debugInfo); try { visitor.Visit(syntaxTree.GetRoot()); visitor.VerifyIntegrity(); } catch (System.Exception e) { LogException(result, e, visitor.visitorContext.currentNode, out string logMessage); programAsset.compileErrors.Add(logMessage); errorCount++; } if (errorCount > 0) { return(result); } moduleSymbols.CloseSymbolTable(); if (errorCount == 0) { compiledClassDefinition = classDefinitions.Find(e => e.userClassType == visitor.visitorContext.behaviourUserType); string dataBlock = BuildHeapDataBlock(); string codeBlock = visitor.GetCompiledUasm(); result.compiledAssembly = dataBlock + codeBlock; result.symbolCount = (uint)(moduleSymbols.GetAllUniqueChildSymbols().Count + visitor.GetExternStrCount()); programAsset.behaviourIDHeapVarName = visitor.GetIDHeapVarName(); programAsset.fieldDefinitions = visitor.visitorContext.localFieldDefinitions; #if UDON_BETA_SDK programAsset.behaviourSyncMode = visitor.visitorContext.behaviourSyncMode; #endif if (debugInfo != null) { debugInfo.FinalizeDebugInfo(); } UdonSharpEditorCache.Instance.SetDebugInfo(programAsset, isEditorBuild ? UdonSharpEditorCache.DebugInfoType.Editor : UdonSharpEditorCache.DebugInfoType.Client, debugInfo); //programAsset.debugInfo = debugInfo; } return(result); }