Esempio n. 1
0
        internal AstGenerator(AstGenerator/*!*/ parent, string name, bool generator, string profilerName)
            : this(name, generator, profilerName, false) {
            Assert.NotNull(parent);
            _context = parent.Context;
            _binderState = parent.BinderState;
            _parent = parent;
            _document = _context.SourceUnit.Document;
            _profiler = parent._profiler;

            _globals = parent._globals;
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new AstGenerator for top-level (module) code.
        /// </summary>
        internal AstGenerator(CompilationMode mode, CompilerContext/*!*/ context, SourceSpan span, string name, bool generator, bool print)
            : this(name, generator, null, print) {
            Assert.NotNull(context);
            _context = context;
            _pythonContext = (PythonContext)context.SourceUnit.LanguageContext;
            _document = _context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid);
            _funcCodeExpr.Code = _functionCode;

            switch (mode) {
                case CompilationMode.Collectable: _globals = new ArrayGlobalAllocator(_pythonContext); break;
                case CompilationMode.Lookup: _globals = new DictionaryGlobalAllocator(); break;
                case CompilationMode.ToDisk: _globals = new SavableGlobalAllocator(_pythonContext); break;
                case CompilationMode.Uncollectable: _globals = new SharedGlobalAllocator(_pythonContext); break;
            }

            PythonOptions po = (_pythonContext.Options as PythonOptions);
            Assert.NotNull(po);
            if (po.EnableProfiler && mode != CompilationMode.ToDisk) {
                _profiler = Profiler.GetProfiler(PyContext);
                if (mode == CompilationMode.Lookup) {
                    _profilerName = NameForExec;
                }
            }
        }
Esempio n. 3
0
        internal AstGenerator(CompilationMode mode, CompilerContext/*!*/ context, SourceSpan span, string name, bool generator, bool print)
            : this(name, generator, null, print) {
            Assert.NotNull(context);
            _context = context;
            _binderState = new BinderState(Binder);
            _document = _context.SourceUnit.Document;

            LanguageContext pc = context.SourceUnit.LanguageContext;
            switch (mode) {
                case CompilationMode.Collectable: _globals = new ArrayGlobalAllocator(pc); break;
                case CompilationMode.Lookup: _globals = new DictionaryGlobalAllocator(); break;
                case CompilationMode.ToDisk: _globals = new SavableGlobalAllocator(pc); break;
                case CompilationMode.Uncollectable: _globals = new StaticGlobalAllocator(pc, name); break;
            }

            PythonOptions po = (pc.Options as PythonOptions);
            Assert.NotNull(po);
            if (po.EnableProfiler && mode != CompilationMode.ToDisk) {
                _profiler = Profiler.GetProfiler(PythonContext);
                if (mode == CompilationMode.Lookup) {
                    _profilerName = NameForExec;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new AstGenerator for a class or function definition.
        /// </summary>
        internal AstGenerator(AstGenerator/*!*/ parent, string name, bool generator, string profilerName)
            : this(name, generator, profilerName, false) {
            Assert.NotNull(parent);
            _context = parent.Context;
            _pythonContext = parent.PyContext;
            _parent = parent;
            _document = _context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid);
            _profiler = parent._profiler;

            _globals = parent._globals;
        }