xref: /haiku/src/kits/debugger/source_language/c_family/CLanguageFamily.cpp (revision 15fb7d88e971c4d6c787c6a3a5c159afb1ebf77b)
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  */
6 
7 #include "CLanguageFamily.h"
8 
9 #include <new>
10 
11 #include <stdlib.h>
12 
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"
21 
22 
23 using CLanguage::ParseException;
24 
25 
26 CLanguageFamily::CLanguageFamily()
27 {
28 }
29 
30 
31 CLanguageFamily::~CLanguageFamily()
32 {
33 }
34 
35 
36 SyntaxHighlighter*
37 CLanguageFamily::GetSyntaxHighlighter() const
38 {
39 	return new(std::nothrow) CLanguageFamilySyntaxHighlighter();
40 }
41 
42 
43 status_t
44 CLanguageFamily::EvaluateExpression(const BString& expression,
45 	ValueNodeManager* manager, TeamTypeInformation* info,
46 	ExpressionResult*& _output, ValueNode*& _neededNode)
47 {
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;
69 	}
70 
71 	return B_OK;
72 }
73