/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using dnlib.DotNet; namespace dnSpy.Contracts.Decompiler { /// /// Method scope /// public sealed class MethodDebugScope { /// /// Gets the span of this scope /// public ILSpan Span { get; } /// /// Gets all child scopes /// public MethodDebugScope[] Scopes { get; } /// /// Gets all new locals in the scope /// public SourceLocal[] Locals { get; } /// /// Gets all new imports in the scope /// public ImportInfo[] Imports { get; } /// /// Gets all new constants in the scope /// public MethodDebugConstant[] Constants { get; } /// /// Constructor /// /// Scope span /// Child scopes /// Locals /// Imports /// Constants public MethodDebugScope(ILSpan span, MethodDebugScope[] scopes, SourceLocal[] locals, ImportInfo[] imports, MethodDebugConstant[] constants) { Span = span; Scopes = scopes ?? throw new ArgumentNullException(nameof(scopes)); Locals = locals ?? throw new ArgumentNullException(nameof(locals)); Imports = imports ?? throw new ArgumentNullException(nameof(imports)); Constants = constants ?? throw new ArgumentNullException(nameof(constants)); } } /// /// Import kind /// public enum ImportInfoKind { /// /// Namespace import /// Namespace, /// /// Type import /// Type, /// /// Namespace or type import /// NamespaceOrType, /// /// C#: extern alias /// Assembly, /// /// VB: XML import /// XmlNamespace, /// /// VB: token of method with imports /// MethodToken, /// /// VB: containing namespace /// CurrentNamespace, /// /// VB: root namespace /// DefaultNamespace, } /// /// Visual Basic import scope kind /// public enum VBImportScopeKind { /// /// Unspecified scope /// None, /// /// File scope /// File, /// /// Project scope /// Project, } /// /// Import info /// public readonly struct ImportInfo { /// /// Target kind /// public ImportInfoKind TargetKind { get; } /// /// Gets the VB import scope kind /// public VBImportScopeKind VBImportScopeKind { get; } /// /// Target /// public string? Target { get; } /// /// Alias /// public string? Alias { get; } /// /// Extern alias /// public string? ExternAlias { get; } /// /// Constructor /// /// Target kind /// Target string /// Alias /// Extern alias /// VB import scope kind public ImportInfo(ImportInfoKind targetKind, string? target = null, string? alias = null, string? externAlias = null, VBImportScopeKind importScopeKind = VBImportScopeKind.None) { TargetKind = targetKind; Target = target; Alias = alias; ExternAlias = externAlias; VBImportScopeKind = importScopeKind; } #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public static ImportInfo CreateNamespace(string @namespace) => new ImportInfo(ImportInfoKind.Namespace, target: @namespace); public static ImportInfo CreateNamespace(string @namespace, string externAlias) => new ImportInfo(ImportInfoKind.Namespace, target: @namespace, externAlias: externAlias); public static ImportInfo CreateType(string type) => new ImportInfo(ImportInfoKind.Type, target: type); public static ImportInfo CreateNamespaceAlias(string @namespace, string alias) => new ImportInfo(ImportInfoKind.Namespace, target: @namespace, alias: alias); public static ImportInfo CreateTypeAlias(string type, string alias) => new ImportInfo(ImportInfoKind.Type, target: type, alias: alias); public static ImportInfo CreateNamespaceAlias(string @namespace, string alias, string externAlias) => new ImportInfo(ImportInfoKind.Namespace, target: @namespace, alias: alias, externAlias: externAlias); public static ImportInfo CreateAssembly(string externAlias) => new ImportInfo(ImportInfoKind.Assembly, externAlias: externAlias); public static ImportInfo CreateAssembly(string externAlias, string assembly) => new ImportInfo(ImportInfoKind.Assembly, externAlias: externAlias, target: assembly); public static ImportInfo CreateCurrentNamespace() => new ImportInfo(ImportInfoKind.CurrentNamespace, target: string.Empty); public static ImportInfo CreateNamespaceOrType(string namespaceOrType, string alias, VBImportScopeKind importScopeKind) => new ImportInfo(ImportInfoKind.NamespaceOrType, target: namespaceOrType, alias: alias, importScopeKind: importScopeKind); public static ImportInfo CreateXmlNamespace(string xmlNamespace, string alias, VBImportScopeKind importScopeKind) => new ImportInfo(ImportInfoKind.XmlNamespace, target: xmlNamespace, alias: alias, importScopeKind: importScopeKind); public static ImportInfo CreateType(string type, VBImportScopeKind importScopeKind) => new ImportInfo(ImportInfoKind.Type, target: type, importScopeKind: importScopeKind); public static ImportInfo CreateNamespace(string @namespace, VBImportScopeKind importScopeKind) => new ImportInfo(ImportInfoKind.Namespace, target: @namespace, importScopeKind: importScopeKind); public static ImportInfo CreateMethodToken(string token, VBImportScopeKind importScopeKind) => new ImportInfo(ImportInfoKind.MethodToken, target: token, importScopeKind: importScopeKind); public static ImportInfo CreateDefaultNamespace(string @namespace) => new ImportInfo(ImportInfoKind.DefaultNamespace, target: @namespace); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } /// /// A constant value /// public readonly struct MethodDebugConstant { /// /// Gets the name of the constant /// public string Name { get; } /// /// Gets the type of the constant /// public TypeSig Type { get; } /// /// Gets the constant value /// public object Value { get; } /// /// Constructor /// /// Name of constant /// Type of constant /// Constant value public MethodDebugConstant(string name, TypeSig type, object value) { Name = name ?? throw new ArgumentNullException(nameof(name)); Type = type ?? throw new ArgumentNullException(nameof(type)); Value = value; } } }