aboutsummaryrefslogtreecommitdiff
path: root/gprofng/src/Expression.h
blob: 9083c575246698726ffd85c1b2fdd295f627d3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Copyright (C) 2021-2023 Free Software Foundation, Inc.
   Contributed by Oracle.

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#ifndef _EXPRESSION_H
#define _EXPRESSION_H

#include <inttypes.h>

class Experiment;
class DataView;
class DbeView;
class Histable;

class Expression
{
public:

  class Context
  {
  public:
    Context (DbeView *_dbev, Experiment *_exp = 0);
    Context (DbeView *_dbev, Experiment *_exp, DataView *_dview, long _eventId);

    ~Context () { };

    void
    put (DataView *d, long id)
    {
      dview = d;
      eventId = id;
    };

    void
    put (Experiment *_exp)
    {
      exp = _exp;
    };

    Experiment *exp;
    DataView *dview;
    DbeView *dbev;
    long eventId;
  };

  enum OpCode
  {
    OP_NONE,
    OP_QWE,
    OP_COLON,
    OP_OR,
    OP_AND,
    OP_NOT,
    OP_EQV,
    OP_NEQV,
    OP_BITOR,
    OP_BITAND,
    OP_BITXOR,
    OP_BITNOT,
    OP_EQ,
    OP_NE,
    OP_LT,
    OP_GT,
    OP_LE,
    OP_GE,
    OP_LS,
    OP_RS,
    OP_ADD,
    OP_MINUS,
    OP_MUL,
    OP_DIV,
    OP_REM,
    OP_DEG,
    OP_COMMA,
    OP_IN,
    OP_SOMEIN,
    OP_ORDRIN,
    OP_NUM,
    OP_NAME,
    OP_FUNC,
    OP_FILE,
    OP_JAVA,
    OP_HASPROP,
    OP_LIBRARY_IN,
    OP_LIBRARY_SOMEIN,
    OP_LIBRARY_ORDRIN
  };

  enum FuncCode
  {
    FUNC_FNAME,
    FUNC_DNAME
  };

  enum JavaCode
  {
    JAVA_JGROUP,
    JAVA_JPARENT
  };

  Expression (OpCode, const Expression*, const Expression* = 0);
  Expression (OpCode, uint64_t);
  Expression (const Expression &rhs);
  Expression (const Expression *rhs);
  Expression &operator= (const Expression &rhs);
  ~Expression ();

  Expression *
  copy () const
  {
    return new Expression (this);
  }
  void copy (const Expression *rhs);

  uint64_t
  eval (Context *ctx)
  {
    return bEval (ctx) ? v.val : 0;
  };

  bool
  passes (Context *ctx)
  {
    return bEval (ctx) ? v.val != 0 : true;
  };

  bool
  complete ()
  {
    return op == OP_NUM;
  };

  bool verifyObjectInExpr (Histable *obj);
  Expression *
  pEval (Context *ctx); // Partial evaluation to simplify expression

private:

  struct Value
  {

    Value (uint64_t _val = 0, Value *_next = 0) : val (_val), next (_next)
    {
      fn = 0;
    }
    uint64_t val;
    uint64_t fn;
    Value *next;
  };

  bool getVal (int propId, Context *ctx);
  bool bEval (Context *ctx);
  bool hasLoadObject ();

  OpCode op;
  Value v;
  Expression *arg0;
  Expression *arg1;
};


#endif /* _EXPRESSION_H */