Debugger: Add model classes for expression representation.
- Add class ExpressionInfo to encapsulate the expression string and result type of a particular expression instance. - Add class ExpressionValues to map expression result values correlating to a function, thread and expression for later use in highlighting changes.
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014, Rene Gollent, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ExpressionInfo.h"
|
||||||
|
|
||||||
|
#include "Type.h"
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionInfo::ExpressionInfo()
|
||||||
|
:
|
||||||
|
fExpression(),
|
||||||
|
fResultType(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionInfo::ExpressionInfo(const ExpressionInfo& other)
|
||||||
|
:
|
||||||
|
fExpression(other.fExpression),
|
||||||
|
fResultType(other.fResultType)
|
||||||
|
{
|
||||||
|
if (fResultType != NULL)
|
||||||
|
fResultType->AcquireReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionInfo::~ExpressionInfo()
|
||||||
|
{
|
||||||
|
if (fResultType != NULL)
|
||||||
|
fResultType->ReleaseReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionInfo::ExpressionInfo(const BString& expression, Type* resultType)
|
||||||
|
:
|
||||||
|
fExpression(expression),
|
||||||
|
fResultType(resultType)
|
||||||
|
{
|
||||||
|
if (resultType != NULL)
|
||||||
|
resultType->AcquireReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ExpressionInfo::SetTo(const BString& expression, Type* resultType)
|
||||||
|
{
|
||||||
|
fExpression = expression;
|
||||||
|
if (fResultType != NULL)
|
||||||
|
fResultType->ReleaseReference();
|
||||||
|
|
||||||
|
fResultType = resultType;
|
||||||
|
if (fResultType != NULL)
|
||||||
|
fResultType->AcquireReference();
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014, Rene Gollent, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef EXPRESSION_INFO_H
|
||||||
|
#define EXPRESSION_INFO_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <Referenceable.h>
|
||||||
|
|
||||||
|
|
||||||
|
class Type;
|
||||||
|
|
||||||
|
|
||||||
|
class ExpressionInfo : public BReferenceable {
|
||||||
|
public:
|
||||||
|
ExpressionInfo();
|
||||||
|
ExpressionInfo(const ExpressionInfo& other);
|
||||||
|
ExpressionInfo(const BString& expression,
|
||||||
|
Type* resultType);
|
||||||
|
virtual ~ExpressionInfo();
|
||||||
|
|
||||||
|
void SetTo(const BString& expression,
|
||||||
|
Type* resultType);
|
||||||
|
|
||||||
|
const BString& Expression() const { return fExpression; }
|
||||||
|
Type* ResultType() const { return fResultType; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
BString fExpression;
|
||||||
|
Type* fResultType;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // EXPRESSION_INFO_H
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014, Rene Gollent, [email protected].
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ExpressionValues.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include "FunctionID.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct ExpressionValues::Key {
|
||||||
|
FunctionID* function;
|
||||||
|
Thread* thread;
|
||||||
|
BString expression;
|
||||||
|
|
||||||
|
Key(FunctionID* function, Thread* thread, const BString& expression)
|
||||||
|
:
|
||||||
|
function(function),
|
||||||
|
thread(thread),
|
||||||
|
expression(expression)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 HashValue() const
|
||||||
|
{
|
||||||
|
return function->HashValue() ^ thread->ID()
|
||||||
|
^ StringUtils::HashValue(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Key& other) const
|
||||||
|
{
|
||||||
|
return *function == *other.function
|
||||||
|
&& thread->ID() == other.thread->ID()
|
||||||
|
&& expression == other.expression;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct ExpressionValues::ValueEntry : Key {
|
||||||
|
BVariant value;
|
||||||
|
ValueEntry* next;
|
||||||
|
|
||||||
|
ValueEntry(FunctionID* function, Thread* thread, const BString& expression)
|
||||||
|
:
|
||||||
|
Key(function, thread, expression)
|
||||||
|
{
|
||||||
|
function->AcquireReference();
|
||||||
|
thread->AcquireReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
~ValueEntry()
|
||||||
|
{
|
||||||
|
function->ReleaseReference();
|
||||||
|
thread->ReleaseReference();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct ExpressionValues::ValueEntryHashDefinition {
|
||||||
|
typedef Key KeyType;
|
||||||
|
typedef ValueEntry ValueType;
|
||||||
|
|
||||||
|
size_t HashKey(const Key& key) const
|
||||||
|
{
|
||||||
|
return key.HashValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Hash(const ValueEntry* value) const
|
||||||
|
{
|
||||||
|
return value->HashValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Compare(const Key& key, const ValueEntry* value) const
|
||||||
|
{
|
||||||
|
return key == *value;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueEntry*& GetLink(ValueEntry* value) const
|
||||||
|
{
|
||||||
|
return value->next;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionValues::ExpressionValues()
|
||||||
|
:
|
||||||
|
fValues(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionValues::ExpressionValues(const ExpressionValues& other)
|
||||||
|
:
|
||||||
|
fValues(NULL)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// init
|
||||||
|
if (Init() != B_OK)
|
||||||
|
throw std::bad_alloc();
|
||||||
|
|
||||||
|
// clone all values
|
||||||
|
for (ValueTable::Iterator it = other.fValues->GetIterator();
|
||||||
|
ValueEntry* entry = it.Next();) {
|
||||||
|
if (SetValue(entry->function, entry->thread, entry->expression,
|
||||||
|
entry->value) != B_OK) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
_Cleanup();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionValues::~ExpressionValues()
|
||||||
|
{
|
||||||
|
_Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ExpressionValues::Init()
|
||||||
|
{
|
||||||
|
fValues = new(std::nothrow) ValueTable;
|
||||||
|
if (fValues == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
return fValues->Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ExpressionValues::GetValue(FunctionID* function, Thread* thread,
|
||||||
|
const BString* expression, BVariant& _value) const
|
||||||
|
{
|
||||||
|
ValueEntry* entry = fValues->Lookup(Key(function, thread, *expression));
|
||||||
|
if (entry == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_value = entry->value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ExpressionValues::HasValue(FunctionID* function, Thread* thread,
|
||||||
|
const BString* expression) const
|
||||||
|
{
|
||||||
|
return fValues->Lookup(Key(function, thread, *expression)) != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ExpressionValues::SetValue(FunctionID* function, Thread* thread,
|
||||||
|
const BString& expression, const BVariant& value)
|
||||||
|
{
|
||||||
|
ValueEntry* entry = fValues->Lookup(Key(function, thread, expression));
|
||||||
|
if (entry == NULL) {
|
||||||
|
entry = new(std::nothrow) ValueEntry(function, thread, expression);
|
||||||
|
if (entry == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
fValues->Insert(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->value = value;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ExpressionValues::_Cleanup()
|
||||||
|
{
|
||||||
|
if (fValues != NULL) {
|
||||||
|
ValueEntry* entry = fValues->Clear(true);
|
||||||
|
|
||||||
|
while (entry != NULL) {
|
||||||
|
ValueEntry* next = entry->next;
|
||||||
|
delete entry;
|
||||||
|
entry = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete fValues;
|
||||||
|
fValues = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014, Rene Gollent, [email protected].
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef EXPRESSION_VALUES_H
|
||||||
|
#define EXPRESSION_VALUES_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <Referenceable.h>
|
||||||
|
#include <util/OpenHashTable.h>
|
||||||
|
#include <Variant.h>
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionID;
|
||||||
|
class Thread;
|
||||||
|
|
||||||
|
|
||||||
|
class ExpressionValues : public BReferenceable {
|
||||||
|
public:
|
||||||
|
ExpressionValues();
|
||||||
|
ExpressionValues(const ExpressionValues& other);
|
||||||
|
// throws std::bad_alloc
|
||||||
|
virtual ~ExpressionValues();
|
||||||
|
|
||||||
|
status_t Init();
|
||||||
|
|
||||||
|
bool GetValue(FunctionID* function,
|
||||||
|
Thread* thread,
|
||||||
|
const BString* expression,
|
||||||
|
BVariant& _value) const;
|
||||||
|
inline bool GetValue(FunctionID* function,
|
||||||
|
Thread* thread,
|
||||||
|
const BString& expression,
|
||||||
|
BVariant& _value) const;
|
||||||
|
bool HasValue(FunctionID* function,
|
||||||
|
Thread* thread,
|
||||||
|
const BString* expression) const;
|
||||||
|
inline bool HasValue(FunctionID* function,
|
||||||
|
Thread* thread,
|
||||||
|
const BString& expression) const;
|
||||||
|
status_t SetValue(FunctionID* function,
|
||||||
|
Thread* thread,
|
||||||
|
const BString& expression,
|
||||||
|
const BVariant& value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Key;
|
||||||
|
struct ValueEntry;
|
||||||
|
struct ValueEntryHashDefinition;
|
||||||
|
|
||||||
|
typedef BOpenHashTable<ValueEntryHashDefinition> ValueTable;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ExpressionValues& operator=(const ExpressionValues& other);
|
||||||
|
|
||||||
|
void _Cleanup();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ValueTable* fValues;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ExpressionValues::GetValue(FunctionID* function, Thread* thread,
|
||||||
|
const BString& expression, BVariant& _value) const
|
||||||
|
{
|
||||||
|
return GetValue(function, thread, &expression, _value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ExpressionValues::HasValue(FunctionID* function, Thread* thread,
|
||||||
|
const BString& expression) const
|
||||||
|
{
|
||||||
|
return HasValue(function, thread, &expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // EXPRESSION_VALUES_H
|
||||||
Reference in New Issue
Block a user