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 18 namespace CLanguage { 19 struct Token; 20 class Tokenizer; 21 } 22 23 class BVariant; 24 class TeamTypeInformation; 25 class Type; 26 class ValueNode; 27 class ValueNodeChild; 28 class ValueNodeManager; 29 class Variable; 30 31 32 class ValueNeededException { 33 public: 34 ValueNeededException(ValueNode* node) 35 : 36 value(node) 37 { 38 } 39 40 ValueNode* value; 41 }; 42 43 44 class ExpressionResult; 45 class Number; 46 47 48 class CLanguageExpressionEvaluator { 49 50 public: 51 CLanguageExpressionEvaluator(); 52 ~CLanguageExpressionEvaluator(); 53 54 ExpressionResult* Evaluate(const char* expressionString, 55 ValueNodeManager* manager, 56 TeamTypeInformation* info); 57 58 private: 59 class InternalVariableID; 60 class Operand; 61 62 private: 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 89 private: 90 CLanguage::Tokenizer* fTokenizer; 91 TeamTypeInformation* fTypeInfo; 92 ValueNodeManager* fNodeManager; 93 }; 94 95 #endif // C_LANGUAGE_EXPRESSION_EVALUATOR_H 96