/*
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 System.ComponentModel.Composition;
using System.Diagnostics;
using dnSpy.Contracts.Debugger.Evaluation;
using dnSpy.Contracts.Decompiler;
using dnSpy.Debugger.DotNet.Metadata;
namespace dnSpy.Contracts.Debugger.DotNet.Evaluation.ExpressionCompiler {
///
/// A .NET expression compiler. Use
/// to export an instance.
///
public abstract class DbgDotNetExpressionCompiler {
///
/// Compiles an expression
///
/// Evaluation info
/// .NET module references
/// Aliases
/// Expression
/// Options
///
public abstract DbgDotNetCompilationResult CompileExpression(DbgEvaluationInfo evalInfo, DbgModuleReference[] references, DbgDotNetAlias[] aliases, string expression, DbgEvaluationOptions options);
///
/// Compiles a type expression (compiles expressions)
///
/// Evaluation info
/// Type
/// .NET module references
/// Aliases
/// Expression
/// Options
///
public abstract DbgDotNetCompilationResult CompileTypeExpression(DbgEvaluationInfo evalInfo, DmdType type, DbgModuleReference[] references, DbgDotNetAlias[] aliases, string expression, DbgEvaluationOptions options);
///
/// Creates an assembly that is used to get all the locals
///
/// Evaluation info
/// .NET module references
/// Options
///
public abstract DbgDotNetCompilationResult CompileGetLocals(DbgEvaluationInfo evalInfo, DbgModuleReference[] references, DbgEvaluationOptions options);
///
/// Compiles an assignment
///
/// Evaluation info
/// .NET module references
/// Aliases
/// Target expression (lhs)
/// Expression (rhs)
/// Options
///
public abstract DbgDotNetCompilationResult CompileAssignment(DbgEvaluationInfo evalInfo, DbgModuleReference[] references, DbgDotNetAlias[] aliases, string target, string expression, DbgEvaluationOptions options);
///
/// Gets alias info
///
/// Alias name
/// Updated with alias info
///
public abstract bool TryGetAliasInfo(string aliasName, out DbgDotNetParsedAlias aliasInfo);
}
/// Metadata
public interface IDbgDotNetExpressionCompilerMetadata {
/// See
string LanguageGuid { get; }
/// See
string LanguageName { get; }
/// See
string LanguageDisplayName { get; }
/// See
string DecompilerGuid { get; }
/// See
double Order { get; }
}
///
/// Exports a instance
///
[MetadataAttribute, AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class ExportDbgDotNetExpressionCompilerAttribute : ExportAttribute, IDbgDotNetExpressionCompilerMetadata {
///
/// Constructor
///
/// Language GUID, see
/// Language name, see
/// Language's display name (shown in the UI)
/// Decompiler GUID, see or one of the decompiler GUIDs ()
/// Order, see
public ExportDbgDotNetExpressionCompilerAttribute(string languageGuid, string languageName, string languageDisplayName, string decompilerGuid, double order = double.MaxValue)
: base(typeof(DbgDotNetExpressionCompiler)) {
LanguageGuid = languageGuid ?? throw new ArgumentNullException(nameof(languageGuid));
LanguageName = languageName ?? throw new ArgumentNullException(nameof(languageName));
LanguageDisplayName = languageDisplayName ?? throw new ArgumentNullException(nameof(languageDisplayName));
DecompilerGuid = decompilerGuid ?? throw new ArgumentNullException(nameof(decompilerGuid));
Order = order;
}
///
/// Language GUID, see
///
public string LanguageGuid { get; }
///
/// Gets the language name, see
///
public string LanguageName { get; }
///
/// Gets the language's display name (shown in the UI)
///
public string LanguageDisplayName { get; }
///
/// Gets the decompiler GUID, see or one of the decompiler GUIDs ()
///
public string DecompilerGuid { get; }
///
/// Order
///
public double Order { get; }
}
///
/// Order of known expression compilers
///
public static class PredefinedDbgDotNetExpressionCompilerOrders {
///
/// Order of C# expression compiler
///
public const double CSharp = 1000000;
///
/// Order of Visual Basic expression compiler
///
public const double VisualBasic = 2000000;
}
///
/// Alias info
///
public struct DbgDotNetParsedAlias {
///
/// Alias kind
///
public DbgDotNetAliasKind Kind;
///
/// Id
///
public uint Id;
///
/// Constructor
///
/// Alias kind
/// Id
public DbgDotNetParsedAlias(DbgDotNetAliasKind kind, uint id) {
Kind = kind;
Id = id;
}
}
}