public ClassVisitor(ResolverContext resolver, SymbolTable rootTable, LabelTable labelTable)
            : base(SyntaxWalkerDepth.Node)
        {
            visitorContext = new ASTVisitorContext(resolver, rootTable, labelTable);
            methodVisitor  = new MethodVisitor(resolver, rootTable, labelTable);

            classDefinition = new ClassDefinition();
        }
 public CompilationModule(UdonSharpProgramAsset sourceAsset)
 {
     programAsset           = sourceAsset;
     resolver               = new ResolverContext();
     moduleSymbols          = new SymbolTable(resolver, null);
     moduleLabels           = new LabelTable();
     fieldsWithInitializers = new HashSet <FieldDeclarationSyntax>();
 }
Beispiel #3
0
        private List <ClassDefinition> BuildClassDefinitions()
        {
            string[] udonSharpDataAssets = AssetDatabase.FindAssets($"t:{typeof(UdonSharpProgramAsset).Name}");

            List <UdonSharpProgramAsset> udonSharpPrograms = new List <UdonSharpProgramAsset>();

            foreach (string dataGuid in udonSharpDataAssets)
            {
                udonSharpPrograms.Add(AssetDatabase.LoadAssetAtPath <UdonSharpProgramAsset>(AssetDatabase.GUIDToAssetPath(dataGuid)));
            }

            List <ClassDefinition> classDefinitions = new List <ClassDefinition>();

            foreach (UdonSharpProgramAsset udonSharpProgram in udonSharpPrograms)
            {
                if (udonSharpProgram.sourceCsScript == null)
                {
                    continue;
                }

                string sourcePath    = AssetDatabase.GetAssetPath(udonSharpProgram.sourceCsScript);
                string programSource = UdonSharpUtils.ReadFileTextSync(sourcePath);

                ResolverContext resolver     = new ResolverContext();
                SymbolTable     classSymbols = new SymbolTable(resolver, null);

                classSymbols.OpenSymbolTable();

                LabelTable classLabels = new LabelTable();

                SyntaxTree tree = CSharpSyntaxTree.ParseText(programSource);

                ClassVisitor classVisitor = new ClassVisitor(resolver, classSymbols, classLabels);

                try
                {
                    classVisitor.Visit(tree.GetRoot());
                }
                catch (System.Exception e)
                {
                    UdonSharpUtils.LogBuildError($"{e.GetType()}: {e.Message}", sourcePath.Replace("/", "\\"), 0, 0);

                    return(null);
                }

                classSymbols.CloseSymbolTable();

                classVisitor.classDefinition.classScript = udonSharpProgram.sourceCsScript;
                classDefinitions.Add(classVisitor.classDefinition);
            }

            return(classDefinitions);
        }
        public SymbolTable(ResolverContext resolverContext, SymbolTable parentTable)
        {
            resolver          = resolverContext;
            parentSymbolTable = parentTable;

            childSymbolTables = new List <SymbolTable>();

            if (parentTable != null)
            {
                parentTable.childSymbolTables.Add(this);
            }

            symbolDefinitions   = new List <SymbolDefinition>();
            namedSymbolCounters = new Dictionary <string, int>();
        }
        public CompilationModule(UdonSharpProgramAsset sourceAsset)
        {
            programAsset           = sourceAsset;
            resolver               = new ResolverContext();
            moduleSymbols          = new SymbolTable(resolver, null);
            moduleLabels           = new LabelTable();
            fieldsWithInitializers = new HashSet <FieldDeclarationSyntax>();

            if (programAsset.sourceCsScript == null)
            {
                throw new System.ArgumentException($"Asset '{AssetDatabase.GetAssetPath(programAsset)}' does not have a valid program source to compile from");
            }


            sourceCode = UdonSharpUtils.ReadFileTextSync(AssetDatabase.GetAssetPath(programAsset.sourceCsScript));

            settings = UdonSharpSettings.GetSettings();
        }
 public NamespaceVisitor(ResolverContext resolverIn)
 {
     resolver       = resolverIn;
     visitorContext = new ASTVisitorContext(resolver, new SymbolTable(resolver, null), new LabelTable());
 }
 public MethodVisitor(ResolverContext resolver, SymbolTable rootTable, LabelTable labelTable)
     : base(SyntaxWalkerDepth.Node)
 {
     visitorContext = new ASTVisitorContext(resolver, rootTable, labelTable);
 }