示例#1
0
        private void Bind(PythonAst unboundAst)
        {
            Assert.NotNull(unboundAst);

            _currentScope = _globalScope = unboundAst;
            _finallyCount.Add(0);

            // Find all scopes and variables
            unboundAst.Walk(this);

            // Bind
            foreach (ScopeStatement scope in _scopes)
            {
                scope.Bind(this);
            }

            // Finish the globals
            unboundAst.Bind(this);

            // Finish Binding w/ outer most scopes first.
            for (int i = _scopes.Count - 1; i >= 0; i--)
            {
                _scopes[i].FinishBind(this);
            }

            // Finish the globals
            unboundAst.FinishBind(this);

            // Run flow checker
            foreach (ScopeStatement scope in _scopes)
            {
                FlowChecker.Check(scope);
            }
        }
        public DocumentationComment Parse(ProjectDom dom, string fileName, string content)
        {
            var document        = new DocumentationComment(fileName);
            var compilationUnit = new PythonCompilationUnit(fileName);

            document.CompilationUnit = compilationUnit;

            if (String.IsNullOrEmpty(content))
            {
                return(document);
            }

            var scriptSource = pythonEngine.CreateScriptSourceFromString(content, SourceCodeKind.File);
            var context      = new CompilerContext(HostingHelpers.GetSourceUnit(scriptSource),
                                                   compilerOptions, ErrorSink.Default);
            var parser = IronPythonParserEngine.CreateParser(context, langOptions);

            IronPythonAst ast = null;

            try {
                ast = parser.ParseFile(false);
            } catch (SyntaxErrorException exc) {
                // We could likely improve the error message
                document.Errors.Add(new Error(exc.Line, exc.Column, exc.Message));
                return(document);
            }

            walker.Reset();
            ast.Walk(walker);

            compilationUnit.Module = walker.Module;
            compilationUnit.Build();

            return(document);
        }
		string Resolve(string variableName, PythonAst ast)
		{
			typeName = null;
			this.variableName = variableName;
			ast.Walk(this);
			return typeName;
		}
示例#4
0
        private void Bind(PythonAst unboundAst)
        {
            Assert.NotNull(unboundAst);

            _currentScope = _globalScope = unboundAst;
            _finallyCount.Add(0);

            // Find all scopes and variables
            unboundAst.Walk(this);

            // Bind
            foreach (ScopeStatement scope in _scopes) {
                scope.Bind(this);
            }

            // Finish the globals
            unboundAst.Bind(this);

            // Finish Binding w/ outer most scopes first.
            for (int i = _scopes.Count - 1; i >= 0; i--) {
                _scopes[i].FinishBind(this);
            }

            // Finish the globals
            unboundAst.FinishBind(this);

            // Run flow checker
            foreach (ScopeStatement scope in _scopes) {
                FlowChecker.Check(scope);
            }
        }
示例#5
0
        public string ToJavaScript(PythonAst ast)
        {
            content.Clear();
            tree.Clear();
            scope.Clear();
            indent = 0;

            ast.Walk(this);

            return content.Pop();
        }
示例#6
0
        private void Bind(PythonAst unboundAst) {
            Assert.NotNull(unboundAst);

            _currentScope = _globalScope = unboundAst;

            // Find all scopes and variables
            unboundAst.Walk(this);

            // Bind
            foreach (ScopeStatement scope in _scopes) {
                scope.Bind(this);
            }

            // Finish the globals
            unboundAst.Bind(this);

            // Run flow checker
            foreach (ScopeStatement scope in _scopes) {
                FlowChecker.Check(scope);
            }
        }
示例#7
0
        public static void Check(PythonAst ast, CompilerContext context)
        {
            var finder = new StarredExpressionChecker(context);

            ast.Walk(finder);
        }