Stores information needed to emit debugging symbol information for a source file, in particular the file name and unique language identifier.
Esempio n. 1
0
        /// <summary>
        /// Creates a new PythonAst without a body.  ParsingFinished should be called afterwards to set
        /// the body.
        /// </summary>
        public PythonAst(bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context)
        {
            _isModule         = isModule;
            _printExpressions = printExpressions;
            _languageFeatures = languageFeatures;
            _mode             = ((PythonCompilerOptions)context.Options).CompilationMode ?? GetCompilationMode(context);
            _compilerContext  = context;
            FuncCodeExpr      = _functionCode;

            PythonCompilerOptions pco = context.Options as PythonCompilerOptions;

            Debug.Assert(pco != null);

            string name;

            if (!context.SourceUnit.HasPath || (pco.Module & ModuleOptions.ExecOrEvalCode) != 0)
            {
                name = "<module>";
            }
            else
            {
                name = context.SourceUnit.Path;
            }

            _name = name;
            Debug.Assert(_name != null);
            PythonOptions po = ((PythonContext)context.SourceUnit.LanguageContext).PythonOptions;

            if (po.EnableProfiler && _mode != CompilationMode.ToDisk)
            {
                _profiler = Profiler.GetProfiler(PyContext);
            }

            _document = context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid);
        }
Esempio n. 2
0
        public TotemAst(bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context)
        {
            _isModule = isModule;
            _printExpressions = printExpressions;
            _languageFeatures = languageFeatures;
            _mode = ((TotemCompilerOptions)context.Options).CompilationMode ?? GetCompilationMode(context);
            _compilerContext = context;
            FuncCodeExpr = _functionCode;

            TotemCompilerOptions tco = context.Options as TotemCompilerOptions;
            Debug.Assert(tco != null);

            string name;
            if (!context.SourceUnit.HasPath || (tco.Module & ModuleOptions.ExecOrEvalCode) != 0)
            {
                name = "<module>";
            }
            else
            {
                name = context.SourceUnit.Path;
            }

            _name = name;
            Debug.Assert(_name != null);
            TotemOptions to = ((TotemContext)context.SourceUnit.LanguageContext).TotemOptions;

            _document = context.SourceUnit.Document ?? Expression.SymbolDocument(name, TotemContext.LanguageGuid, TotemContext.VendorGuid);
        }
Esempio n. 3
0
        //The following method does not check the validaity of the span
        public static Expression AddDebugInfo(Expression expression, SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) {
            if (expression == null) {
                Debug.WriteLine("Null error ding: " + expression.ToString());
                throw new System.ArgumentNullException("expression");
            }

            var sequencePoint = Expression.DebugInfo(document,
                startLine, startColumn, endLine, endColumn);

            var clearance = Expression.ClearDebugInfo(document);
            //always attach a clearance
            if (expression.Type == typeof(void)) {
                return Expression.Block(
                    sequencePoint,
                    expression,
                    clearance
                );
            } else {
                //save the expression to a variable
                var p = Expression.Parameter(expression.Type, null);
                return Expression.Block(
                    new[] { p },
                    sequencePoint,
                    Expression.Assign(p, expression),
                    clearance,
                    p
                );
            }
        }
Esempio n. 4
0
 internal SpanDebugInfoExpression(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) : base(document)
 {
     this._startLine   = startLine;
     this._startColumn = startColumn;
     this._endLine     = endLine;
     this._endColumn   = endColumn;
 }
Esempio n. 5
0
        internal RubyMethodBody(MethodDeclaration/*!*/ ast, MSA.SymbolDocumentInfo document, RubyEncoding/*!*/ encoding) {
            Assert.NotNull(ast, encoding);

            _ast = ast;
            _document = document;
            _encoding = encoding;
        }
Esempio n. 6
0
 internal AstGenerator(CompilerContext/*!*/ context, SourceSpan span, string name, bool generator, bool print)
     : this(name, generator, print) {
     Assert.NotNull(context);
     _context = context;
     _binderState = new BinderState(Binder);
     _document = _context.SourceUnit.Document;
 }
Esempio n. 7
0
 internal AstGenerator(AstGenerator/*!*/ parent, string name, bool generator, bool print)
     : this(name, generator, false) {
     Assert.NotNull(parent);
     _context = parent.Context;
     _binderState = parent.BinderState;
     _document = _context.SourceUnit.Document;
 }
Esempio n. 8
0
 public UpdatePositionExpr(IScriptExtent extent, int sequencePoint, SymbolDocumentInfo debugSymbolDocument, bool checkBreakpoints)
 {
     this._extent = extent;
     this._checkBreakpoints = checkBreakpoints;
     this._debugSymbolDocument = debugSymbolDocument;
     this._sequencePoint = sequencePoint;
 }
Esempio n. 9
0
 public static Expression AddDebugInfo(Expression expression, SymbolDocumentInfo document, SourceLocation start, SourceLocation end)
 {
     if (document == null || !start.IsValid || !end.IsValid) {
         return expression;
     }
     return AddDebugInfo(expression, document, start.Line, start.Column, end.Line, end.Column);
 }
 internal SpanDebugInfoExpression(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) : base(document)
 {
     this._startLine = startLine;
     this._startColumn = startColumn;
     this._endLine = endLine;
     this._endColumn = endColumn;
 }
Esempio n. 11
0
        internal RubyMethodBody(MethodDeclaration /*!*/ ast, MSA.SymbolDocumentInfo document, RubyEncoding /*!*/ encoding)
        {
            Assert.NotNull(ast, encoding);

            _ast      = ast;
            _document = document;
            _encoding = encoding;
        }
Esempio n. 12
0
 internal DebugInfoExpression(Expression body, SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) {
     _expression = body;
     _document = document;
     _startLine = startLine;
     _startColumn = startColumn;
     _endLine = endLine;
     _endColumn = endColumn;
 }
Esempio n. 13
0
 internal DebugInfoExpression(Expression body, SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
 {
     _expression  = body;
     _document    = document;
     _startLine   = startLine;
     _startColumn = startColumn;
     _endLine     = endLine;
     _endColumn   = endColumn;
 }
Esempio n. 14
0
        public static DebugInfoExpression DebugInfo(Expression body, SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
        {
            ContractUtils.RequiresNotNull(body, "body");
            ContractUtils.RequiresNotNull(document, "document");

            ValidateSpan(startLine, startColumn, endLine, endColumn);

            return(new DebugInfoExpression(body, document, startLine, startColumn, endLine, endColumn));
        }
Esempio n. 15
0
 public static SymbolDocumentInfo Serialize(E.SymbolDocumentInfo document)
 {
     return(new SymbolDocumentInfo()
     {
         FileName = document.FileName,
         Language = document.Language,
         LanguageVendor = document.LanguageVendor,
         DocumentType = document.DocumentType,
     });
 }
Esempio n. 16
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> with the specified span.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <param name="startLine">The start line of this <see cref="DebugInfoExpression"/>. Must be greater than 0.</param>
        /// <param name="startColumn">The start column of this <see cref="DebugInfoExpression"/>. Must be greater than 0.</param>
        /// <param name="endLine">The end line of this <see cref="DebugInfoExpression"/>. Must be greater or equal than the start line.</param>
        /// <param name="endColumn">The end column of this <see cref="DebugInfoExpression"/>. If the end line is the same as the start line, it must be greater or equal than the start column. In any case, must be greater than 0.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/>.</returns>
        public static DebugInfoExpression DebugInfo(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
        {
            ArgumentNullException.ThrowIfNull(document);
            if (startLine == 0xfeefee && startColumn == 0 && endLine == 0xfeefee && endColumn == 0)
            {
                return(new ClearDebugInfoExpression(document));
            }

            ValidateSpan(startLine, startColumn, endLine, endColumn);
            return(new SpanDebugInfoExpression(document, startLine, startColumn, endLine, endColumn));
        }
Esempio n. 17
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> with the specified span.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <param name="startLine">The start line of this <see cref="DebugInfoExpression"/>. Must be greater than 0.</param>
        /// <param name="startColumn">The start column of this <see cref="DebugInfoExpression"/>. Must be greater than 0.</param>
        /// <param name="endLine">The end line of this <see cref="DebugInfoExpression"/>. Must be greater or equal than the start line.</param>
        /// <param name="endColumn">The end column of this <see cref="DebugInfoExpression"/>. If the end line is the same as the start line, it must be greater or equal than the start column. In any case, must be greater than 0.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/>.</returns>
        public static DebugInfoExpression DebugInfo(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
        {
            ContractUtils.RequiresNotNull(document, nameof(document));
            if (startLine == 0xfeefee && startColumn == 0 && endLine == 0xfeefee && endColumn == 0)
            {
                return new ClearDebugInfoExpression(document);
            }

            ValidateSpan(startLine, startColumn, endLine, endColumn);
            return new SpanDebugInfoExpression(document, startLine, startColumn, endLine, endColumn);
        }
Esempio n. 18
0
        private ISymbolDocumentWriter GetSymbolWriter(MethodBuilder method, SymbolDocumentInfo document) {
            ISymbolDocumentWriter result;
            if (_symbolWriters == null) {
                _symbolWriters = new Dictionary<SymbolDocumentInfo, ISymbolDocumentWriter>();
            }

            if (!_symbolWriters.TryGetValue(document, out result)) {
                result = ((ModuleBuilder)method.Module).DefineDocument(document.FileName, document.Language, document.LanguageVendor, SymbolGuids.DocumentType_Text);
                _symbolWriters.Add(document, result);
            }

            return result;
        }
 private ISymbolDocumentWriter GetSymbolWriter(MethodBuilder method, SymbolDocumentInfo document)
 {
     ISymbolDocumentWriter writer;
     if (this._symbolWriters == null)
     {
         this._symbolWriters = new Dictionary<SymbolDocumentInfo, ISymbolDocumentWriter>();
     }
     if (!this._symbolWriters.TryGetValue(document, out writer))
     {
         writer = ((ModuleBuilder) method.Module).DefineDocument(document.FileName, document.Language, document.LanguageVendor, SymbolGuids.DocumentType_Text);
         this._symbolWriters.Add(document, writer);
     }
     return writer;
 }
Esempio n. 20
0
        private MSA.Expression _sourcePathConstant; // lazy

        internal AstGenerator(RubyContext/*!*/ context, RubyCompilerOptions/*!*/ options, MSA.SymbolDocumentInfo document, RubyEncoding/*!*/ encoding,
            bool printInteractiveResult) {

            Assert.NotNull(context, options, encoding);
            _context = context;
            _compilerOptions = options;
            _debugCompiler = Snippets.Shared.SaveSnippets;
            _debugMode = context.DomainManager.Configuration.DebugMode;
            _traceEnabled = context.RubyOptions.EnableTracing;
            _document = document;
            _encoding = encoding;
            _profiler = context.RubyOptions.Profile ? Profiler.Instance : null;
            _savingToDisk = context.RubyOptions.SavePath != null;
            _printInteractiveResult = printInteractiveResult;
        }
Esempio n. 21
0
        private GenContext(string directory, AssemblyName aname, string extension, bool createDynInitHelper, string sourceName)
        {
            // TODO: Make this settable from a *debug* flag
            #if DEBUG
            _isDebuggable = true;
            #else
            _isDebuggable = false;
            #endif

            _assyGen = new AssemblyGen(aname, directory, extension, _isDebuggable);
            if ( createDynInitHelper )
                _dynInitHelper = new DynInitHelper(_assyGen, GenerateName());
            if (_isDebuggable)
                _docWriter = ModuleBuilder.DefineDocument(sourceName, ClojureContext.Default.LanguageGuid, ClojureContext.Default.VendorGuid, Guid.Empty);
            _docInfo = Expression.SymbolDocument(sourceName);
        }
Esempio n. 22
0
        internal AstGenerator(RubyContext /*!*/ context, RubyCompilerOptions /*!*/ options, MSA.SymbolDocumentInfo document, RubyEncoding /*!*/ encoding,
                              bool printInteractiveResult)
        {
            Assert.NotNull(context, options, encoding);
            _context                = context;
            _compilerOptions        = options;
            _debugMode              = context.DomainManager.Configuration.DebugMode;
            _traceEnabled           = context.RubyOptions.EnableTracing;
            _document               = document;
            _sequencePointClearance = (document != null) ? Ast.ClearDebugInfo(document) : null;
            _encoding               = encoding;
            _encodingConstant       = Ast.Constant(encoding);
            _profiler               = context.RubyOptions.Profile ? Profiler.Instance : null;
            _savingToDisk           = context.RubyOptions.SavePath != null;
            _printInteractiveResult = printInteractiveResult;
#if !SILVERLIGHT
            _debugCompiler = Snippets.Shared.SaveSnippets;
#endif
        }
Esempio n. 23
0
        internal AstGenerator(RubyContext/*!*/ context, RubyCompilerOptions/*!*/ options, MSA.SymbolDocumentInfo document, RubyEncoding/*!*/ encoding,
            bool printInteractiveResult) {

            Assert.NotNull(context, options, encoding);
            _context = context;
            _compilerOptions = options;
            _debugMode = context.DomainManager.Configuration.DebugMode;
            _traceEnabled = context.RubyOptions.EnableTracing;
            _document = document;
            _sequencePointClearance = (document != null) ? Ast.ClearDebugInfo(document) : null;
            _encoding = encoding;
            _encodingConstant = Ast.Constant(encoding);
            _profiler = context.RubyOptions.Profile ? Profiler.Instance : null;
            _savingToDisk = context.RubyOptions.SavePath != null;
            _printInteractiveResult = printInteractiveResult;
#if SILVERLIGHT
            _debugCompiler = false;
#else
            _debugCompiler = Snippets.Shared.SaveSnippets;
#endif
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> for clearing a sequence point.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/> for clearing a sequence point.</returns>
        public static DebugInfoExpression ClearDebugInfo(SymbolDocumentInfo document)
        {
            ContractUtils.RequiresNotNull(document, nameof(document));

            return new ClearDebugInfoExpression(document);
        }
Esempio n. 25
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. 26
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;
        }
Esempio n. 27
0
            public FunctionCall(SourceSpan functionLocation, FunctionType type, IEnumerable<string> identifiers, SymbolDocumentInfo document = null)
            {
                FunctionLocation = functionLocation;
                Type = type;
                Document = document ?? Expression.SymbolDocument("[CLR]");

                string temp = identifiers.First();
                foreach (var i in identifiers.Skip(1))
                    temp += "." + i;

                MethodName = temp;
            }
Esempio n. 28
0
 /// <summary>
 /// Wraps an expression in <see cref="DebugInfoExpression"/>s which indicate the <see cref="SouceSpan"/> where it is defined
 /// </summary>
 public static Expr SourceSpan(SymbolDocumentInfo document, SourceSpan span, Expr body)
 {
     if (document == null)
         return body;
     return new SpansExpression(document, span, body).Reduce();
 }
Esempio n. 29
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> with the specified span.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <param name="startLine">The start line of this <see cref="DebugInfoExpression" />. Must be greater than 0.</param>
        /// <param name="startColumn">The start column of this <see cref="DebugInfoExpression" />. Must be greater than 0.</param>
        /// <param name="endLine">The end line of this <see cref="DebugInfoExpression" />. Must be greater or equal than the start line.</param>
        /// <param name="endColumn">The end column of this <see cref="DebugInfoExpression" />. If the end line is the same as the start line, it must be greater or equal than the start column. In any case, must be greater than 0.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/>.</returns>
        public static DebugInfoExpression DebugInfo(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) {
            ContractUtils.RequiresNotNull(document, "document");
            if (startLine == 0xfeefee && startColumn == 0 && endLine == 0xfeefee && endColumn == 0) {
                return new ClearDebugInfoExpression(document);
            }

            ValidateSpan(startLine, startColumn, endLine, endColumn);
            return new SpanDebugInfoExpression(document, startLine, startColumn, endLine, endColumn);
        }
Esempio n. 30
0
        /// <summary>
        /// Creates a new PythonAst without a body.  ParsingFinished should be called afterwards to set
        /// the body.
        /// </summary>
        public PythonAst(bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context) {
            _isModule = isModule;
            _printExpressions = printExpressions;
            _languageFeatures = languageFeatures;
            _mode = ((PythonCompilerOptions)context.Options).CompilationMode ?? GetCompilationMode(context);
            _compilerContext = context;
            FuncCodeExpr = _functionCode;

            PythonCompilerOptions pco = context.Options as PythonCompilerOptions;
            Debug.Assert(pco != null);

            string name;
            if (!context.SourceUnit.HasPath || (pco.Module & ModuleOptions.ExecOrEvalCode) != 0) {
                name = "<module>";
            } else {
                name = context.SourceUnit.Path;
            }

            _name = name;
            Debug.Assert(_name != null);
            PythonOptions po = ((PythonContext)context.SourceUnit.LanguageContext).PythonOptions;

            if (po.EnableProfiler && _mode != CompilationMode.ToDisk) {
                _profiler = Profiler.GetProfiler(PyContext);
            }

            _document = context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid);
        }
Esempio n. 31
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;
        }
 public ExpressionDebugInfoAddingVisitor(string fileName)
 {
     this.symbolDoc = Expression.SymbolDocument(fileName);
 }
Esempio n. 33
0
 internal ClearDebugInfoExpression(SymbolDocumentInfo document)
     : base(document)
 {
 }
Esempio n. 34
0
 internal DebugInfoExpression(SymbolDocumentInfo document) {
     _document = document;
 }
Esempio n. 35
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> for clearing a sequence point.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/> for clearning a sequence point.</returns>
        public static DebugInfoExpression ClearDebugInfo(SymbolDocumentInfo document) {
            ContractUtils.RequiresNotNull(document, "document");

            return new ClearDebugInfoExpression(document);
        }
Esempio n. 36
0
        private void InitDebugging()
        {
            if (!_debugEnabled)
            {
                return;
            }

            _debugText = new StringBuilder();
            var instanceId = _parseCounter++;

            _debugAssemblyName = $"BfAssembly{instanceId}";

            _debugAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(
                new AssemblyName(_debugAssemblyName), AssemblyBuilderAccess.RunAndSave,
                _debugTempPath);

            var daType = typeof (DebuggableAttribute);
            var daCtor = daType.GetConstructor(new[] {typeof (DebuggableAttribute.DebuggingModes)});
            var daBuilder = new CustomAttributeBuilder(daCtor, new object[]
            {
                DebuggableAttribute.DebuggingModes.DisableOptimizations |
                DebuggableAttribute.DebuggingModes.Default
            });
            _debugAssembly.SetCustomAttribute(daBuilder);
            var module = _debugAssembly.DefineDynamicModule(_debugAssemblyName, true);
            _debugType = module.DefineType($"BfType{instanceId}", TypeAttributes.Public);

            //int[] memory, BfBuffer input, BfBuffer output
            _debugMethod = _debugType.DefineMethod("Execute",
                MethodAttributes.Public | MethodAttributes.Static,
                typeof (void), new[] {typeof (int[]), typeof (BfStream), typeof (BfStream) });
            _debugTempPath = Path.Combine(_debugTempPath, $"BfSource{instanceId}X.bf");
            _debugSymbols = Expression.SymbolDocument(_debugTempPath);
        }
Esempio n. 37
0
 // ===== ===== ===== ===== ===== ctor ===== ===== ===== ===== =====
 public GlobalGen(string filename, BinderFactory factory, ParameterExpression global)
 {
     _filename = filename;
     _factory = factory;
     _global = global;
     _docInfo = Expression.SymbolDocument(filename, Engine.Guid);
 }
Esempio n. 38
0
 internal DebugInfoExpression(SymbolDocumentInfo document)
 {
     Document = document;
 }
Esempio n. 39
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> for clearing a sequence point.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/> for clearing a sequence point.</returns>
        public static DebugInfoExpression ClearDebugInfo(SymbolDocumentInfo document)
        {
            ArgumentNullException.ThrowIfNull(document);

            return(new ClearDebugInfoExpression(document));
        }
Esempio n. 40
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. 41
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> That identifies the source code that was used to generate an <see cref="Expression"/>.
        /// </summary>
        /// <param name="body">The <see cref="Expression"/> that this <see cref="DebugInfoExpression"/> applies to.</param>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <param name="startLine">The start line of the code that was used to generate the wrapped expression. Must be greater than 0.</param>
        /// <param name="startColumn">The start column of the code that was used to generate the wrapped expression. Must be greater than 0.</param>
        /// <param name="endLine">The end line of the code that was used to generate the wrapped expression. Must be greater or equal than the start line.</param>
        /// <param name="endColumn">The end column of the code that was used to generate the wrapped expression. If the end line is the same as the start line, it must be greater or equal than the start column. In any case, must be greater than 0.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/>.</returns>
        public static DebugInfoExpression DebugInfo(Expression body, SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) {
            ContractUtils.RequiresNotNull(body, "body");
            ContractUtils.RequiresNotNull(document, "document");

            ValidateSpan(startLine, startColumn, endLine, endColumn);
            
            return new DebugInfoExpression(body, document, startLine, startColumn, endLine, endColumn);
        }
Esempio n. 42
0
 internal ClearDebugInfoExpression(SymbolDocumentInfo document)
     : base(document) {
 }
Esempio n. 43
0
        // This is the main entry point for turning an AST into compiled code.
        internal void Compile(CompiledScriptBlockData scriptBlock, bool optimize)
        {
            var body = scriptBlock.Ast;
            Diagnostics.Assert(body is ScriptBlockAst || body is FunctionDefinitionAst || body is FunctionMemberAst || body is CompilerGeneratedMemberFunctionAst,
                               "Caller to verify ast is correct type.");
            var ast = (Ast)body;
            Optimize = optimize;
            _compilingScriptCmdlet = scriptBlock.UsesCmdletBinding;

            var fileName = ast.Extent.File;
            if (fileName != null)
            {
                _debugSymbolDocument = Expression.SymbolDocument(fileName);
            }

            var details = VariableAnalysis.Analyze(body, !optimize, _compilingScriptCmdlet);
            LocalVariablesTupleType = details.Item1;
            var nameToIndexMap = details.Item2;

            if (!nameToIndexMap.TryGetValue(SpecialVariables.@switch, out _switchTupleIndex))
            {
                _switchTupleIndex = VariableAnalysis.ForceDynamic;
            }
            if (!nameToIndexMap.TryGetValue(SpecialVariables.@foreach, out _foreachTupleIndex))
            {
                _foreachTupleIndex = VariableAnalysis.ForceDynamic;
            }

            LocalVariablesParameter = Expression.Variable(LocalVariablesTupleType, "locals");

            var functionMemberAst = ast as FunctionMemberAst;
            if (functionMemberAst != null)
            {
                CompilingMemberFunction = true;
                MemberFunctionReturnType = functionMemberAst.GetReturnType();
                _memberFunctionType = (TypeDefinitionAst)functionMemberAst.Parent;
                SpecialMemberFunctionType = SpecialMemberFunctionType.None;
                if (functionMemberAst.Name.Equals(_memberFunctionType.Name, StringComparison.OrdinalIgnoreCase))
                {
                    // TODO: default argument support
                    var parameters = ((IParameterMetadataProvider)functionMemberAst.Body).Parameters;
                    if (parameters == null || parameters.Count == 0)
                    {
                        SpecialMemberFunctionType = functionMemberAst.IsStatic
                            ? SpecialMemberFunctionType.StaticConstructor
                            : SpecialMemberFunctionType.DefaultConstructor;
                    }
                }
            }
            else
            {
                var generatedMemberFunctionAst = ast as CompilerGeneratedMemberFunctionAst;
                if (generatedMemberFunctionAst != null)
                {
                    CompilingMemberFunction = true;
                    SpecialMemberFunctionType = generatedMemberFunctionAst.Type;
                    MemberFunctionReturnType = typeof(void);
                    _memberFunctionType = generatedMemberFunctionAst.DefiningType;
                }
            }

            body.Body.Accept(this);

            if (_sequencePoints.Count == 0)
            {
                // Uncommon, but possible if a script is empty, or if it only defines functions.
                // In this case, add the entire body as a sequence point.  Debugging won't stop
                // on this sequence point, but it makes it safe to access the CurrentPosition
                // property in FunctionContext (which can happen if there are exceptions
                // defining the functions.)
                _sequencePoints.Add(ast.Extent);
            }

            var compileInterpretChoice = (_stmtCount > 300) ? CompileInterpretChoice.NeverCompile : CompileInterpretChoice.CompileOnDemand;

            if (optimize)
            {
                scriptBlock.DynamicParamBlock = CompileTree(_dynamicParamBlockLambda, compileInterpretChoice);
                scriptBlock.BeginBlock = CompileTree(_beginBlockLambda, compileInterpretChoice);
                scriptBlock.ProcessBlock = CompileTree(_processBlockLambda, compileInterpretChoice);
                scriptBlock.EndBlock = CompileTree(_endBlockLambda, compileInterpretChoice);
                scriptBlock.LocalsMutableTupleType = LocalVariablesTupleType;
                scriptBlock.LocalsMutableTupleCreator = MutableTuple.TupleCreator(LocalVariablesTupleType);
                scriptBlock.NameToIndexMap = nameToIndexMap;
            }
            else
            {
                scriptBlock.UnoptimizedDynamicParamBlock = CompileTree(_dynamicParamBlockLambda, compileInterpretChoice);
                scriptBlock.UnoptimizedBeginBlock = CompileTree(_beginBlockLambda, compileInterpretChoice);
                scriptBlock.UnoptimizedProcessBlock = CompileTree(_processBlockLambda, compileInterpretChoice);
                scriptBlock.UnoptimizedEndBlock = CompileTree(_endBlockLambda, compileInterpretChoice);
                scriptBlock.UnoptimizedLocalsMutableTupleType = LocalVariablesTupleType;
                scriptBlock.UnoptimizedLocalsMutableTupleCreator = MutableTuple.TupleCreator(LocalVariablesTupleType);
            }

            // The sequence points are identical optimized or not.  Regardless, we want to ensure
            // that the list is unique no matter when the property is accessed, so make sure it is set just once.
            if (scriptBlock.SequencePoints == null)
            {
                scriptBlock.SequencePoints = _sequencePoints.ToArray();
            }
        }