Coverage Summary for Class: Stack (org.ethereum.vm.program)
Class |
Class, %
|
Method, %
|
Line, %
|
Stack |
100%
(1/1)
|
100%
(6/6)
|
81.2%
(13/16)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.ethereum.vm.program;
21
22 import org.ethereum.vm.DataWord;
23 import org.ethereum.vm.program.listener.ProgramListener;
24 import org.ethereum.vm.program.listener.ProgramListenerAware;
25
26 public class Stack extends java.util.Stack<DataWord> implements ProgramListenerAware {
27
28 private ProgramListener traceListener;
29
30 @Override
31 public void setTraceListener(ProgramListener listener) {
32 this.traceListener = listener;
33 }
34
35 @Override
36 public synchronized DataWord pop() {
37 if (traceListener != null) {
38 traceListener.onStackPop();
39 }
40 return super.pop();
41 }
42
43 @Override
44 public DataWord push(DataWord item) {
45 if (traceListener != null) {
46 traceListener.onStackPush(item);
47 }
48 return super.push(item);
49 }
50
51 public void swap(int from, int to) {
52 if (isAccessible(from) && isAccessible(to) && (from != to)) {
53 if (traceListener != null) {
54 traceListener.onStackSwap(from, to);
55 }
56 DataWord tmp = get(from);
57 set(from, set(to, tmp));
58 }
59 }
60
61 private boolean isAccessible(int from) {
62 return from >= 0 && from < size();
63 }
64 }