vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / model / ExpressionInfo.cpp
blob74c7083367f6a93ccd31bf366ce3ae9f40958d37
1 /*
2 * Copyright 2014, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "ExpressionInfo.h"
9 #include "Type.h"
10 #include "Value.h"
11 #include "ValueNode.h"
14 // #pragma mark - ExpressionResult
17 ExpressionResult::ExpressionResult()
19 fResultKind(EXPRESSION_RESULT_KIND_UNKNOWN),
20 fPrimitiveValue(NULL),
21 fValueNodeValue(NULL),
22 fTypeResult(NULL)
27 ExpressionResult::~ExpressionResult()
29 if (fPrimitiveValue != NULL)
30 fPrimitiveValue->ReleaseReference();
32 if (fValueNodeValue != NULL)
33 fValueNodeValue->ReleaseReference();
35 if (fTypeResult != NULL)
36 fTypeResult->ReleaseReference();
40 void
41 ExpressionResult::SetToPrimitive(Value* value)
43 _Unset();
45 fPrimitiveValue = value;
46 if (fPrimitiveValue != NULL) {
47 fPrimitiveValue->AcquireReference();
48 fResultKind = EXPRESSION_RESULT_KIND_PRIMITIVE;
53 void
54 ExpressionResult::SetToValueNode(ValueNodeChild* child)
56 _Unset();
58 fValueNodeValue = child;
59 if (fValueNodeValue != NULL) {
60 fValueNodeValue->AcquireReference();
61 fResultKind = EXPRESSION_RESULT_KIND_VALUE_NODE;
64 // if the child has a node with a resolved value, store
65 // it as a primitive, so the consumer of the expression
66 // can use it as-is if desired.
68 ValueNode* node = child->Node();
69 if (node == NULL)
70 return;
72 fPrimitiveValue = node->GetValue();
73 if (fPrimitiveValue != NULL)
74 fPrimitiveValue->AcquireReference();
78 void
79 ExpressionResult::SetToType(Type* type)
81 _Unset();
83 fTypeResult = type;
84 if (fTypeResult != NULL) {
85 fTypeResult->AcquireReference();
86 fResultKind = EXPRESSION_RESULT_KIND_TYPE;
91 void
92 ExpressionResult::_Unset()
94 if (fPrimitiveValue != NULL) {
95 fPrimitiveValue->ReleaseReference();
96 fPrimitiveValue = NULL;
99 if (fValueNodeValue != NULL) {
100 fValueNodeValue->ReleaseReference();
101 fValueNodeValue = NULL;
104 if (fTypeResult != NULL) {
105 fTypeResult->ReleaseReference();
106 fTypeResult = NULL;
109 fResultKind = EXPRESSION_RESULT_KIND_UNKNOWN;
113 // #pragma mark - ExpressionInfo
116 ExpressionInfo::ExpressionInfo()
118 fExpression()
123 ExpressionInfo::ExpressionInfo(const ExpressionInfo& other)
125 fExpression(other.fExpression)
130 ExpressionInfo::~ExpressionInfo()
135 ExpressionInfo::ExpressionInfo(const BString& expression)
137 fExpression(expression)
142 void
143 ExpressionInfo::SetTo(const BString& expression)
145 fExpression = expression;
149 void
150 ExpressionInfo::AddListener(Listener* listener)
152 fListeners.Add(listener);
156 void
157 ExpressionInfo::RemoveListener(Listener* listener)
159 fListeners.Remove(listener);
163 void
164 ExpressionInfo::NotifyExpressionEvaluated(status_t result,
165 ExpressionResult* value)
167 for (ListenerList::Iterator it = fListeners.GetIterator();
168 Listener* listener = it.Next();) {
169 listener->ExpressionEvaluated(this, result, value);
174 // #pragma mark - ExpressionInfo::Listener
177 ExpressionInfo::Listener::~Listener()