Ejemplo n.º 1
0
        public BoundStatementBlock(StatementBlockSyntax syntax, IReadOnlyList <BaseBoundStatement> body)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!body.IsDefault(), "'body' must not be null.");

            this.Syntax = syntax;
            this.Body   = body;
        }
Ejemplo n.º 2
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.º 3
0
        private BoundStatementBlock BindStatementBlock(StatementBlockSyntax syntax)
        {
            var statements = new List <BaseBoundStatement>();

            foreach (var child in syntax.Body)
            {
                var statement = this.BindStatementOpt(child);

                if (!statement.IsDefault())
                {
                    statements.Add(statement);
                }
            }

            return(new BoundStatementBlock(syntax, statements));
        }
 public SubModuleNamesCollector(StatementBlockSyntax syntaxTree)
 {
     this.Visit(syntaxTree);
 }
Ejemplo n.º 5
0
 internal RuntimeModule(string name, IReadOnlyList <BaseInstruction> instructions, StatementBlockSyntax syntax)
 {
     this.Name         = name;
     this.Instructions = instructions;
     this.Syntax       = syntax;
 }