/*
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.Collections.ObjectModel;
using dnSpy.Contracts.Debugger.Evaluation;
namespace dnSpy.Contracts.Debugger.Engine.Evaluation {
///
/// Expression evaluator
///
public abstract class DbgEngineExpressionEvaluator {
///
/// Creates evaluator state used to cache data that is needed to evaluate an expression
///
///
public abstract object? CreateExpressionEvaluatorState();
///
/// Evaluates an expression
///
/// Evaluation info
/// Expression to evaluate
/// Options
/// State created by or null to store the state in 's context
///
public abstract DbgEngineEvaluationResult Evaluate(DbgEvaluationInfo evalInfo, string expression, DbgEvaluationOptions options, object? state);
///
/// Assigns the value of an expression to another expression
///
/// Evaluation info
/// Target expression (lhs)
/// Source expression (rhs)
/// Options
///
public abstract DbgEngineEEAssignmentResult Assign(DbgEvaluationInfo evalInfo, string expression, string valueExpression, DbgEvaluationOptions options);
}
///
/// Evaluation result
///
public readonly struct DbgEngineEvaluationResult {
///
/// Gets the value or null if there was an error
///
public DbgEngineValue? Value { get; }
///
/// Gets the format specifiers, if any
///
public ReadOnlyCollection FormatSpecifiers { get; }
///
/// Gets the flags
///
public DbgEvaluationResultFlags Flags { get; }
///
/// Gets the error or null if none
///
public string? Error { get; }
static readonly ReadOnlyCollection emptyFormatSpecifiers = new ReadOnlyCollection(Array.Empty());
///
/// Constructor
///
/// Value
/// Format specifiers or null
/// Flags
public DbgEngineEvaluationResult(DbgEngineValue value, ReadOnlyCollection? formatSpecifiers, DbgEvaluationResultFlags flags) {
Value = value ?? throw new ArgumentNullException(nameof(value));
FormatSpecifiers = formatSpecifiers ?? emptyFormatSpecifiers;
Flags = flags;
Error = null;
}
///
/// Constructor
///
/// Error message
/// Flags
public DbgEngineEvaluationResult(string error, DbgEvaluationResultFlags flags = 0) {
Value = null;
FormatSpecifiers = emptyFormatSpecifiers;
Flags = flags;
Error = error ?? throw new ArgumentNullException(nameof(error));
}
}
///
/// Expression evaluator assignment result
///
public readonly struct DbgEngineEEAssignmentResult {
///
/// Error message or null
///
public string? Error { get; }
///
/// Gets the flags
///
public DbgEEAssignmentResultFlags Flags { get; }
///
/// true if the error is from the compiler and no debuggee code was executed
///
public bool IsCompilerError => (Flags & DbgEEAssignmentResultFlags.CompilerError) != 0;
///
/// Constructor
///
/// Result flags
/// Error message or null
public DbgEngineEEAssignmentResult(DbgEEAssignmentResultFlags flags, string? error) {
Flags = flags;
Error = error;
}
}
}