Code Listener  [unstable] git snapshot
cl_filter.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Kamil Dudka <kdudka@redhat.com>
3  *
4  * This file is part of predator.
5  *
6  * predator 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 of the License, or
9  * any later version.
10  *
11  * predator 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 predator. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef H_GUARD_CL_FILTER_H
21 #define H_GUARD_CL_FILTER_H
22 
23 /**
24  * @file cl_filter.hh
25  * ClFilterBase - base class for all code listener @b filters
26  */
27 
28 #include "cl.hh"
29 
30 /**
31  * base class for all ICodeListener filters
32  *
33  * The class itself can't be instantiated. You always need to inherit the
34  * class. The only thing which has to be implemented in the derived class is
35  * a constructor, which calls the parent constructor with an instance of
36  * ICodeListener as the argument. All other methods which are not overridden
37  * will be forwarded to that instance of ICodeListener.
38  * @note design pattern @b filter
39  */
40 class ClFilterBase: public ICodeListener {
41  public:
42  /**
43  * @attention the slave ICodeListener will be deleted automatically on
44  * the object's destruction
45  */
46  virtual ~ClFilterBase() {
47  delete slave_;
48  }
49 
50  virtual void file_open(
51  const char *file_name)
52  {
53  slave_->file_open(file_name);
54  }
55 
56  virtual void file_close() {
57  slave_->file_close();
58  }
59 
60  virtual void fnc_open(
61  const struct cl_operand *fnc)
62  {
63  slave_->fnc_open(fnc);
64  }
65 
66  virtual void fnc_arg_decl(
67  int arg_id,
68  const struct cl_operand *arg_src)
69  {
70  slave_->fnc_arg_decl(arg_id, arg_src);
71  }
72 
73  virtual void fnc_close() {
74  slave_->fnc_close();
75  }
76 
77  virtual void bb_open(
78  const char *bb_name)
79  {
80  slave_->bb_open(bb_name);
81  }
82 
83  virtual void insn(
84  const struct cl_insn *cli)
85  {
86  slave_->insn(cli);
87  }
88 
89  virtual void insn_call_open(
90  const struct cl_loc *loc,
91  const struct cl_operand *dst,
92  const struct cl_operand *fnc)
93  {
94  slave_->insn_call_open(loc, dst, fnc);
95  }
96 
97  virtual void insn_call_arg(
98  int arg_id,
99  const struct cl_operand *arg_src)
100  {
101  slave_->insn_call_arg(arg_id, arg_src);
102  }
103 
104  virtual void insn_call_close() {
106  }
107 
108  virtual void insn_switch_open(
109  const struct cl_loc *loc,
110  const struct cl_operand *src)
111  {
112  slave_->insn_switch_open(loc, src);
113  }
114 
115  virtual void insn_switch_case(
116  const struct cl_loc *loc,
117  const struct cl_operand *val_lo,
118  const struct cl_operand *val_hi,
119  const char *label)
120  {
121  slave_->insn_switch_case(loc, val_lo, val_hi, label);
122  }
123 
124  virtual void insn_switch_close() {
126  }
127 
128  virtual void acknowledge() {
129  slave_->acknowledge();
130  }
131 
132  protected:
133  /**
134  * @param slave An instance of ICodeListener. All methods which are not
135  * overridden in the derived class will be forwarded to this instance.
136  * @copydoc ~ClFilterBase()
137  */
139  slave_(slave)
140  {
141  }
142 
143  private:
145 };
146 
147 #endif /* H_GUARD_CL_FILTER_H */