예제 #1
0
 public ScopePositionInfo(int start, int stop, InterpreterScope scope)
 {
     Start = start;
     Stop = stop;
     Scope = scope;
     Children = new List<ScopePositionInfo>();
 }
예제 #2
0
 private AnalysisUnit(Node ast, InterpreterScope[] scopes, AnalysisUnit parent, bool forEval)
 {
     _ast = ast;
     _scopes = scopes;
     _parent = parent;
     _forEval = forEval;
 }
예제 #3
0
        public override bool Walk(FunctionDefinition node)
        {
            if (node.Body == null || node.Name == null)
            {
                return(false);
            }

            var queue  = _entry.ProjectState.Queue;
            var scopes = new InterpreterScope[_scopes.Count + 1];

            _scopes.CopyTo(scopes);

            _analysisStack.Push(_curUnit);
            var unit      = _curUnit = new AnalysisUnit(node, scopes, _curUnit);
            var function  = new FunctionInfo(unit, _entry);
            var funcScope = new FunctionScope(function);

            _entry.MyScope.GetOrMakeNodeVariable(node, x => function.SelfSet);
            _scopes.Push(funcScope);
            scopes[scopes.Length - 1] = funcScope;

            if (!node.IsLambda)
            {
                // lambdas don't have their names published
                var scope = _scopes[_scopes.Count - 2];
                scope.SetVariable(node, unit, node.Name, function.SelfSet);
            }

            var newParams = new VariableDef[node.Parameters.Count];
            int index     = 0;

            foreach (var param in node.Parameters)
            {
                newParams[index++] = funcScope.DefineVariable(param, _curUnit);
            }
            function.SetParameters(newParams);

            PushPositionScope(node, funcScope);

            return(true);
        }
예제 #4
0
 public ExpressionEvaluator(AnalysisUnit unit, InterpreterScope[] scopes)
 {
     _unit = unit;
     _currentScopes = scopes;
 }
예제 #5
0
        // TODO: What about names being redefined?
        // remember classes/functions as they start new scopes
        public override bool Walk(ClassDefinition node)
        {
            if (node.Body == null || node.Name == null) {
                return false;
            }

            var queue = _entry.ProjectState.Queue;

            var scopes = new InterpreterScope[_scopes.Count + 1];
            _scopes.CopyTo(scopes);

            _analysisStack.Push(_curUnit);
            var unit = _curUnit = new AnalysisUnit(node, scopes, _curUnit);
            var klass = new ClassInfo(unit, _entry);
            var classScope = klass.Scope;

            var scope = _scopes.Peek();
            scope.SetVariable(node, unit, node.Name, klass.SelfSet);

            _scopes.Push(classScope);
            scopes[scopes.Length - 1] = classScope;

            // TODO: Add parameters for __new__/__init__
            PushPositionScope(node, classScope);

            return true;
        }
예제 #6
0
 private void PushPositionScope(Node node, InterpreterScope newScope)
 {
     var newPositionInfo = new ScopePositionInfo(node.Start.Line, node.End.Line, newScope);
     _scopeTree.Peek().Children.Add(newPositionInfo);
     _scopeTree.Push(newPositionInfo);
 }
예제 #7
0
        public override bool Walk(FunctionDefinition node)
        {
            if (node.Body == null || node.Name == null) {
                return false;
            }

            var queue = _entry.ProjectState.Queue;
            var scopes = new InterpreterScope[_scopes.Count + 1];
            _scopes.CopyTo(scopes);

            _analysisStack.Push(_curUnit);
            var unit = _curUnit = new AnalysisUnit(node, scopes, _curUnit);
            var function = new FunctionInfo(unit, _entry);
            var funcScope = new FunctionScope(function);

            _entry.MyScope.GetOrMakeNodeVariable(node, x => function.SelfSet);
            _scopes.Push(funcScope);
            scopes[scopes.Length - 1] = funcScope;

            if (!node.IsLambda) {
                // lambdas don't have their names published
                var scope = _scopes[_scopes.Count - 2];
                scope.SetVariable(node, unit, node.Name, function.SelfSet);
            }

            var newParams = new VariableDef[node.Parameters.Count];
            int index = 0;
            foreach (var param in node.Parameters) {
                newParams[index++] = funcScope.DefineVariable(param, _curUnit);
            }
            function.SetParameters(newParams);

            PushPositionScope(node, funcScope);

            return true;
        }
예제 #8
0
 public AnalysisUnit(Node node, InterpreterScope[] scopes, AnalysisUnit parent)
 {
     _ast = node;
     _scopes = scopes;
     _parent = parent;
 }