xref: /haiku/src/kits/debugger/source_language/c_family/CLanguageFamily.cpp (revision 992ae400ec160a3e2ef6ad71c011cd688c9f2476)
1fce4895dSRene Gollent /*
2fce4895dSRene Gollent  * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
3fce4895dSRene Gollent  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4fce4895dSRene Gollent  * Distributed under the terms of the MIT License.
5fce4895dSRene Gollent  */
6fce4895dSRene Gollent 
7fce4895dSRene Gollent #include "CLanguageFamily.h"
8fce4895dSRene Gollent 
9fce4895dSRene Gollent #include <new>
10fce4895dSRene Gollent 
11fce4895dSRene Gollent #include <stdlib.h>
12fce4895dSRene Gollent 
13fce4895dSRene Gollent #include "CLanguageExpressionEvaluator.h"
14fce4895dSRene Gollent #include "CLanguageFamilySyntaxHighlighter.h"
15fce4895dSRene Gollent #include "CLanguageTokenizer.h"
16fce4895dSRene Gollent #include "ExpressionInfo.h"
17fce4895dSRene Gollent #include "TeamTypeInformation.h"
18fce4895dSRene Gollent #include "StringValue.h"
19fce4895dSRene Gollent #include "Type.h"
20fce4895dSRene Gollent #include "TypeLookupConstraints.h"
21fce4895dSRene Gollent 
22fce4895dSRene Gollent 
23fce4895dSRene Gollent using CLanguage::ParseException;
24fce4895dSRene Gollent 
25fce4895dSRene Gollent 
CLanguageFamily()26fce4895dSRene Gollent CLanguageFamily::CLanguageFamily()
27fce4895dSRene Gollent {
28fce4895dSRene Gollent }
29fce4895dSRene Gollent 
30fce4895dSRene Gollent 
~CLanguageFamily()31fce4895dSRene Gollent CLanguageFamily::~CLanguageFamily()
32fce4895dSRene Gollent {
33fce4895dSRene Gollent }
34fce4895dSRene Gollent 
35fce4895dSRene Gollent 
36fce4895dSRene Gollent SyntaxHighlighter*
GetSyntaxHighlighter() const37fce4895dSRene Gollent CLanguageFamily::GetSyntaxHighlighter() const
38fce4895dSRene Gollent {
39fce4895dSRene Gollent 	return new(std::nothrow) CLanguageFamilySyntaxHighlighter();
40fce4895dSRene Gollent }
41fce4895dSRene Gollent 
42fce4895dSRene Gollent 
43fce4895dSRene Gollent status_t
EvaluateExpression(const BString & expression,ValueNodeManager * manager,TeamTypeInformation * info,ExpressionResult * & _output,ValueNode * & _neededNode)44fce4895dSRene Gollent CLanguageFamily::EvaluateExpression(const BString& expression,
45fce4895dSRene Gollent 	ValueNodeManager* manager, TeamTypeInformation* info,
46fce4895dSRene Gollent 	ExpressionResult*& _output, ValueNode*& _neededNode)
47fce4895dSRene Gollent {
48fce4895dSRene Gollent 	_output = NULL;
49fce4895dSRene Gollent 	_neededNode = NULL;
50fce4895dSRene Gollent 	CLanguageExpressionEvaluator evaluator;
51fce4895dSRene Gollent 	try {
52fce4895dSRene Gollent 		_output = evaluator.Evaluate(expression, manager, info);
53fce4895dSRene Gollent 		return B_OK;
54*992ae400SMurai Takashi 	} catch (ParseException& ex) {
55fce4895dSRene Gollent 		BString error;
56fce4895dSRene Gollent 		error.SetToFormat("Parse error at position %" B_PRId32 ": %s",
57fce4895dSRene Gollent 			ex.position, ex.message.String());
58fce4895dSRene Gollent 		StringValue* value = new(std::nothrow) StringValue(error.String());
59fce4895dSRene Gollent 		if (value == NULL)
60fce4895dSRene Gollent 			return B_NO_MEMORY;
61fce4895dSRene Gollent 		BReference<Value> valueReference(value, true);
62fce4895dSRene Gollent 		_output = new(std::nothrow) ExpressionResult();
63fce4895dSRene Gollent 		if (_output == NULL)
64fce4895dSRene Gollent 			return B_NO_MEMORY;
65fce4895dSRene Gollent 		_output->SetToPrimitive(value);
66fce4895dSRene Gollent 		return B_BAD_DATA;
67*992ae400SMurai Takashi 	} catch (ValueNeededException& ex) {
68fce4895dSRene Gollent 		_neededNode = ex.value;
69fce4895dSRene Gollent 	}
70fce4895dSRene Gollent 
71fce4895dSRene Gollent 	return B_OK;
72fce4895dSRene Gollent }
73