Beispiel #1
0
 public UdonSharpFieldVisitor(HashSet <FieldDeclarationSyntax> fieldsWithInitializers, ResolverContext resolver, SymbolTable rootTable, LabelTable labelTable, List <ClassDefinition> classDefinitions, ClassDebugInfo classDebugInfo)
     : base(UdonSharpSyntaxWalkerDepth.ClassDefinitions, resolver, rootTable, labelTable, classDebugInfo)
 {
     this.fieldsWithInitializers           = fieldsWithInitializers;
     visitorContext.externClassDefinitions = classDefinitions;
 }
Beispiel #2
0
 public UdonSharpSyntaxWalker(UdonSharpSyntaxWalkerDepth depth, ResolverContext resolver, SymbolTable rootTable, LabelTable labelTable, ClassDebugInfo classDebugInfo = null)
     : base(SyntaxWalkerDepth.Node)
 {
     syntaxWalkerDepth = depth;
     visitorContext    = new ASTVisitorContext(resolver, rootTable, labelTable, classDebugInfo);
 }
        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);
        }