vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / source_language / c_family / CLanguageFamily.cpp
blob707c09d5a57b51751480b6512571bbb2802ed440
1 /*
2 * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
7 #include "CLanguageFamily.h"
9 #include <new>
11 #include <stdlib.h>
13 #include "CLanguageExpressionEvaluator.h"
14 #include "CLanguageFamilySyntaxHighlighter.h"
15 #include "CLanguageTokenizer.h"
16 #include "ExpressionInfo.h"
17 #include "TeamTypeInformation.h"
18 #include "StringValue.h"
19 #include "Type.h"
20 #include "TypeLookupConstraints.h"
23 using CLanguage::ParseException;
26 CLanguageFamily::CLanguageFamily()
31 CLanguageFamily::~CLanguageFamily()
36 SyntaxHighlighter*
37 CLanguageFamily::GetSyntaxHighlighter() const
39 return new(std::nothrow) CLanguageFamilySyntaxHighlighter();
43 status_t
44 CLanguageFamily::EvaluateExpression(const BString& expression,
45 ValueNodeManager* manager, TeamTypeInformation* info,
46 ExpressionResult*& _output, ValueNode*& _neededNode)
48 _output = NULL;
49 _neededNode = NULL;
50 CLanguageExpressionEvaluator evaluator;
51 try {
52 _output = evaluator.Evaluate(expression, manager, info);
53 return B_OK;
54 } catch (ParseException ex) {
55 BString error;
56 error.SetToFormat("Parse error at position %" B_PRId32 ": %s",
57 ex.position, ex.message.String());
58 StringValue* value = new(std::nothrow) StringValue(error.String());
59 if (value == NULL)
60 return B_NO_MEMORY;
61 BReference<Value> valueReference(value, true);
62 _output = new(std::nothrow) ExpressionResult();
63 if (_output == NULL)
64 return B_NO_MEMORY;
65 _output->SetToPrimitive(value);
66 return B_BAD_DATA;
67 } catch (ValueNeededException ex) {
68 _neededNode = ex.value;
71 return B_OK;