1/* 2 * Copyright 2006-2014 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan A��mus <superstippi@gmx.de> 7 * Rene Gollent <rene@gollent.com> 8 * John Scipione <jscipione@gmail.com> 9 * Ingo Weinhold <bonefish@cs.tu-berlin.de> 10 */ 11#ifndef C_LANGUAGE_EXPRESSION_EVALUATOR_H 12#define C_LANGUAGE_EXPRESSION_EVALUATOR_H 13 14 15#include <String.h> 16 17 18namespace CLanguage { 19 struct Token; 20 class Tokenizer; 21} 22 23class BVariant; 24class TeamTypeInformation; 25class Type; 26class ValueNode; 27class ValueNodeChild; 28class ValueNodeManager; 29class Variable; 30 31 32class ValueNeededException { 33public: 34 ValueNeededException(ValueNode* node) 35 : 36 value(node) 37 { 38 } 39 40 ValueNode* value; 41}; 42 43 44class ExpressionResult; 45class Number; 46 47 48class CLanguageExpressionEvaluator { 49 50public: 51 CLanguageExpressionEvaluator(); 52 ~CLanguageExpressionEvaluator(); 53 54 ExpressionResult* Evaluate(const char* expressionString, 55 ValueNodeManager* manager, 56 TeamTypeInformation* info); 57 58private: 59 class InternalVariableID; 60 class Operand; 61 62private: 63 Operand _ParseSum(); 64 Operand _ParseProduct(); 65 Operand _ParseUnary(); 66 Operand _ParseIdentifier(ValueNode* parentNode = NULL); 67 Operand _ParseAtom(); 68 69 void _EatToken(int32 type); 70 71 Operand _ParseType(Type* baseType); 72 // the passed in Type object 73 // is expected to be the initial 74 // base type that was recognized by 75 // e.g. ParseIdentifier. This function then 76 // takes care of handling any modifiers 77 // that go with it, and returns a 78 // corresponding final type. 79 80 void _RequestValueIfNeeded( 81 const CLanguage::Token& token, 82 ValueNodeChild* child); 83 84 void _GetNodeChildForPrimitive( 85 const CLanguage::Token& token, 86 const BVariant& value, 87 ValueNodeChild*& _output) const; 88 89private: 90 CLanguage::Tokenizer* fTokenizer; 91 TeamTypeInformation* fTypeInfo; 92 ValueNodeManager* fNodeManager; 93}; 94 95#endif // C_LANGUAGE_EXPRESSION_EVALUATOR_H 96