1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Apache License, Version 2.0, please send an email to
8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Apache License, Version 2.0.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
15 #if FEATURE_REFEMIT && FEATURE_PDBEMIT
18 using Microsoft.Scripting.Ast;
19 using Microsoft.Scripting.Ast.Compiler;
21 using System.Linq.Expressions;
22 using System.Linq.Expressions.Compiler;
25 using System.Collections.Generic;
26 using System.Diagnostics;
27 using System.Diagnostics.SymbolStore;
28 using System.Reflection;
29 using System.Reflection.Emit;
31 namespace System.Runtime.CompilerServices {
32 #if !FEATURE_CORE_DLR || SILVERLIGHT
33 using ILGenerator = OffsetTrackingILGenerator;
37 /// Generator of PDB debugging information for expression trees.
39 internal sealed class SymbolDocumentGenerator : DebugInfoGenerator {
40 private Dictionary<SymbolDocumentInfo, ISymbolDocumentWriter> _symbolWriters;
42 private ISymbolDocumentWriter GetSymbolWriter(MethodBuilder method, SymbolDocumentInfo document) {
43 ISymbolDocumentWriter result;
44 if (_symbolWriters == null) {
45 _symbolWriters = new Dictionary<SymbolDocumentInfo, ISymbolDocumentWriter>();
48 if (!_symbolWriters.TryGetValue(document, out result)) {
49 result = ((ModuleBuilder)method.Module).DefineDocument(document.FileName, document.Language, document.LanguageVendor, SymbolGuids.DocumentType_Text);
50 _symbolWriters.Add(document, result);
56 internal override void MarkSequencePoint(LambdaExpression method, MethodBase methodBase, ILGenerator ilg, DebugInfoExpression sequencePoint) {
57 MethodBuilder builder = methodBase as MethodBuilder;
58 if (builder != null) {
59 ilg.MarkSequencePoint(GetSymbolWriter(builder, sequencePoint.Document), sequencePoint.StartLine, sequencePoint.StartColumn, sequencePoint.EndLine, sequencePoint.EndColumn);
63 public override void MarkSequencePoint(LambdaExpression method, int ilOffset, DebugInfoExpression sequencePoint) {
64 throw Error.PdbGeneratorNeedsExpressionCompiler();
67 internal override void SetLocalName(LocalBuilder localBuilder, string name) {
68 localBuilder.SetLocalSymInfo(name);