1/* Copyright (C) 2021 Free Software Foundation, Inc. 2 Contributed by Oracle. 3 4 This file is part of GNU Binutils. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21#ifndef _EXPRESSION_H 22#define _EXPRESSION_H 23 24#include <inttypes.h> 25 26class Experiment; 27class DataView; 28class DbeView; 29class Histable; 30 31class Expression 32{ 33public: 34 35 class Context 36 { 37 public: 38 Context (DbeView *_dbev, Experiment *_exp = 0); 39 Context (DbeView *_dbev, Experiment *_exp, DataView *_dview, long _eventId); 40 41 ~Context () { }; 42 43 void 44 put (DataView *d, long id) 45 { 46 dview = d; 47 eventId = id; 48 }; 49 50 void 51 put (Experiment *_exp) 52 { 53 exp = _exp; 54 }; 55 56 Experiment *exp; 57 DataView *dview; 58 DbeView *dbev; 59 long eventId; 60 }; 61 62 enum OpCode 63 { 64 OP_NONE, 65 OP_QWE, 66 OP_COLON, 67 OP_OR, 68 OP_AND, 69 OP_NOT, 70 OP_EQV, 71 OP_NEQV, 72 OP_BITOR, 73 OP_BITAND, 74 OP_BITXOR, 75 OP_BITNOT, 76 OP_EQ, 77 OP_NE, 78 OP_LT, 79 OP_GT, 80 OP_LE, 81 OP_GE, 82 OP_LS, 83 OP_RS, 84 OP_ADD, 85 OP_MINUS, 86 OP_MUL, 87 OP_DIV, 88 OP_REM, 89 OP_DEG, 90 OP_COMMA, 91 OP_IN, 92 OP_SOMEIN, 93 OP_ORDRIN, 94 OP_NUM, 95 OP_NAME, 96 OP_FUNC, 97 OP_FILE, 98 OP_JAVA, 99 OP_HASPROP, 100 OP_LIBRARY_IN, 101 OP_LIBRARY_SOMEIN, 102 OP_LIBRARY_ORDRIN 103 }; 104 105 enum FuncCode 106 { 107 FUNC_FNAME, 108 FUNC_DNAME 109 }; 110 111 enum JavaCode 112 { 113 JAVA_JGROUP, 114 JAVA_JPARENT 115 }; 116 117 Expression (OpCode, const Expression*, const Expression* = 0); 118 Expression (OpCode, uint64_t); 119 Expression (const Expression &rhs); 120 Expression (const Expression *rhs); 121 Expression &operator= (const Expression &rhs); 122 ~Expression (); 123 124 Expression * 125 copy () const 126 { 127 return new Expression (this); 128 } 129 void copy (const Expression *rhs); 130 131 uint64_t 132 eval (Context *ctx) 133 { 134 return bEval (ctx) ? v.val : 0; 135 }; 136 137 bool 138 passes (Context *ctx) 139 { 140 return bEval (ctx) ? v.val != 0 : true; 141 }; 142 143 bool 144 complete () 145 { 146 return op == OP_NUM; 147 }; 148 149 bool verifyObjectInExpr (Histable *obj); 150 Expression * 151 pEval (Context *ctx); // Partial evaluation to simplify expression 152 153private: 154 155 struct Value 156 { 157 158 Value (uint64_t _val = 0, Value *_next = 0) : val (_val), next (_next) 159 { 160 fn = 0; 161 } 162 uint64_t val; 163 uint64_t fn; 164 Value *next; 165 }; 166 167 bool getVal (int propId, Context *ctx); 168 bool bEval (Context *ctx); 169 bool hasLoadObject (); 170 171 OpCode op; 172 Value v; 173 Expression *arg0; 174 Expression *arg1; 175}; 176 177 178#endif /* _EXPRESSION_H */ 179