Ejemplo n.º 1
0
        public Binder(StatementBlockSyntax syntaxTree, DiagnosticBag diagnostics, bool isRunningOnDesktop)
        {
            this.diagnostics        = diagnostics;
            this.isRunningOnDesktop = isRunningOnDesktop;
            this.definedSubModules  = new SubModuleNamesCollector(syntaxTree).Names;

            var mainModule = new List <BaseBoundStatement>();
            var subModules = new Dictionary <string, BoundSubModule>();

            foreach (var syntax in syntaxTree.Body)
            {
                switch (syntax)
                {
                case SubModuleStatementSyntax subModuleStatement:
                {
                    var body      = this.BindStatementBlock(subModuleStatement.Body);
                    var subModule = new BoundSubModule(subModuleStatement, subModuleStatement.NameToken.Text, body);

                    if (subModules.ContainsKey(subModule.Name))
                    {
                        this.diagnostics.ReportTwoSubModulesWithTheSameName(subModuleStatement.NameToken.Range, subModule.Name);
                    }
                    else
                    {
                        subModules.Add(subModule.Name, subModule);
                    }

                    break;
                }

                default:
                {
                    var statement = this.BindStatementOpt(syntax);
                    if (!statement.IsDefault())
                    {
                        mainModule.Add(statement);
                    }

                    break;
                }
                }
            }

            this.MainModule = new BoundStatementBlock(syntaxTree, mainModule);
            this.CheckForLabelErrors(this.MainModule);

            this.SubModules = subModules;
            foreach (var subModule in this.SubModules.Values)
            {
                this.CheckForLabelErrors(subModule.Body);
            }
        }
Ejemplo n.º 2
0
 private protected virtual void VisitSubModule(BoundSubModule node)
 {
     this.DefaultVisit(node);
 }
Ejemplo n.º 3
0
 private protected override void VisitSubModule(BoundSubModule node)
 {
     this.names.Add(node.Name);
     base.VisitSubModule(node);
 }