示例#1
0
        IEnumerable <FieldSymbol> LoadFields()
        {
            var binder = new SemanticsBinder(null);

            // fields
            foreach (var flist in _syntax.Members.OfType <FieldDeclList>())
            {
                var fkind = (flist.Modifiers & PhpMemberAttributes.Static) == 0
                    ? SourceFieldSymbol.KindEnum.InstanceField
                    : SourceFieldSymbol.KindEnum.StaticField;

                foreach (var f in flist.Fields)
                {
                    yield return(new SourceFieldSymbol(this, f.Name.Value, flist.Modifiers.GetAccessibility(), f.PHPDoc ?? flist.PHPDoc, fkind,
                                                       (f.Initializer != null) ? binder.BindExpression(f.Initializer, BoundAccess.Read) : null));
                }
            }

            // constants
            foreach (var clist in _syntax.Members.OfType <ConstDeclList>())
            {
                foreach (var c in clist.Constants)
                {
                    yield return(new SourceFieldSymbol(this, c.Name.Name.Value, Accessibility.Public, c.PHPDoc ?? clist.PHPDoc,
                                                       SourceFieldSymbol.KindEnum.ClassConstant,
                                                       binder.BindExpression(c.Initializer, BoundAccess.Read)));
                }
            }
        }
示例#2
0
        private BuilderVisitor(IList <Statement> /*!*/ statements, SemanticsBinder /*!*/ binder, NamingContext naming)
        {
            Contract.ThrowIfNull(statements);
            Contract.ThrowIfNull(binder);

            // TODO: Implement a cleaner way to enable SemanticsBinder to create BoundBlocks trough BuilderVisitor
            if (binder is GeneratorSemanticsBinder gsb)
            {
                gsb.GetNewBlock = this.NewBlock;
            }

            _binder = binder;
            _naming = naming;

            this.Start = WithNewOrdinal(new StartBlock()
            {
                Naming = _naming
            });
            this.Exit = new ExitBlock();

            _current = WithOpenScope(this.Start);

            statements.ForEach(this.VisitElement);
            FinalizeRoutine();
            _current = Connect(_current, this.Exit);

            //
            WithNewOrdinal(this.Exit);
            CloseScope();

            //
            Debug.Assert(_scopes.Count == 0);
            Debug.Assert(_tryTargets == null || _tryTargets.Count == 0);
            Debug.Assert(_breakTargets == null || _breakTargets.Count == 0);
        }
示例#3
0
        IEnumerable <FieldSymbol> LoadFields()
        {
            var binder = new SemanticsBinder(locals: null, diagnostics: DeclaringCompilation.DeclarationDiagnostics);

            // fields
            foreach (var flist in _syntax.Members.OfType <FieldDeclList>())
            {
                var fkind = (flist.Modifiers & PhpMemberAttributes.Static) == 0
                    ? SourceFieldSymbol.KindEnum.InstanceField
                    : SourceFieldSymbol.KindEnum.StaticField;

                foreach (var f in flist.Fields)
                {
                    yield return(new SourceFieldSymbol(this, f.Name.Value,
                                                       CreateLocation(f.NameSpan.ToTextSpan()),
                                                       flist.Modifiers.GetAccessibility(), f.PHPDoc ?? flist.PHPDoc,
                                                       fkind,
                                                       (f.Initializer != null) ? binder.BindWholeExpression(f.Initializer, BoundAccess.Read).GetOnlyBoundElement() : null));
                }
            }

            // constants
            foreach (var clist in _syntax.Members.OfType <ConstDeclList>())
            {
                foreach (var c in clist.Constants)
                {
                    yield return(new SourceFieldSymbol(this, c.Name.Name.Value,
                                                       CreateLocation(c.Name.Span.ToTextSpan()),
                                                       Accessibility.Public, c.PHPDoc ?? clist.PHPDoc,
                                                       SourceFieldSymbol.KindEnum.ClassConstant,
                                                       binder.BindWholeExpression(c.Initializer, BoundAccess.Read).GetOnlyBoundElement()));
                }
            }
        }
示例#4
0
        private BuilderVisitor(IList <Statement> /*!*/ statements, SemanticsBinder /*!*/ binder, NamingContext naming)
        {
            Contract.ThrowIfNull(statements);
            Contract.ThrowIfNull(binder);

            _binder = binder;
            _naming = naming;

            this.Start = WithNewOrdinal(new StartBlock()
            {
                Naming = _naming
            });
            this.Exit = new ExitBlock();

            _current = WithOpenScope(this.Start);

            statements.ForEach(this.VisitElement);
            _current = Connect(_current, this.Exit);

            //
            WithNewOrdinal(this.Exit);
            CloseScope();

            //
            Debug.Assert(_scopes.Count == 0);
            Debug.Assert(_tryTargets == null || _tryTargets.Count == 0);
            Debug.Assert(_breakTargets == null || _breakTargets.Count == 0);
        }
        private BuilderVisitor(IList <Statement> /*!*/ statements, SemanticsBinder /*!*/ binder)
        {
            Contract.ThrowIfNull(statements);
            Contract.ThrowIfNull(binder);

            // setup the binder
            binder.SetupBuilder(this.NewBlock);

            _binder = binder;

            this.Start = WithNewOrdinal(new StartBlock());
            this.Exit  = new ExitBlock();

            _current = WithOpenScope(this.Start);

            statements.ForEach(this.VisitElement);
            FinalizeRoutine();
            _current = Connect(_current, this.Exit);

            //
            WithNewOrdinal(this.Exit);
            CloseScope();

            //
            Debug.Assert(_scopes.Count == 0);
            Debug.Assert(_tryTargets == null || _tryTargets.Count == 0);
            Debug.Assert(_breakTargets == null || _breakTargets.Count == 0);
        }
示例#6
0
        /// <summary>
        /// Ensures the routine has flow context.
        /// Otherwise it is created and routine is enqueued for analysis.
        /// </summary>
        void EnsureRoutine(SourceRoutineSymbol routine)
        {
            Contract.ThrowIfNull(routine);

            var cfg = routine.ControlFlowGraph;

            if (cfg == null)
            {
                // create initial flow state
                var state  = StateBinder.CreateInitialState(routine);
                var binder = new SemanticsBinder(routine, state.FlowContext);

                // create control flow
                routine.ControlFlowGraph = cfg = new ControlFlowGraph(routine.Statements, binder);

                // enqueue the method for the analysis
                cfg.Start.FlowState = state;
                _worklist.Enqueue(cfg.Start);
            }
        }
示例#7
0
 public static BuilderVisitor /*!*/ Build(IList <Statement> /*!*/ statements, SemanticsBinder /*!*/ binder, NamingContext naming)
 {
     return(new BuilderVisitor(statements, binder, naming));
 }
 public static BuilderVisitor /*!*/ Build(IList <Statement> /*!*/ statements, SemanticsBinder /*!*/ binder)
 {
     return(new BuilderVisitor(statements, binder));
 }
示例#9
0
 internal override ConstantValue GetConstantValue(bool earlyDecodingWellKnownAttributes)
 {
     return(_resolvedValue ?? (_resolvedValue = SemanticsBinder.TryGetConstantValue(this.DeclaringCompilation, _value)));
 }
示例#10
0
 protected SemanticsBinder CreateBinder()
 {
     return(SemanticsBinder.Create(DeclaringCompilation, ContainingFile.SyntaxTree, LocalsTable, ContainingType as SourceTypeSymbol));
 }
示例#11
0
 internal ControlFlowGraph(IList<Statement>/*!*/statements, SemanticsBinder/*!*/binder, NamingContext naming)
     : this(BuilderVisitor.Build(statements, binder, naming))
 {
 }
示例#12
0
 internal ControlFlowGraph(IList <Statement> /*!*/ statements, SemanticsBinder /*!*/ binder)
     : this(BuilderVisitor.Build(statements, binder))
 {
 }