|
| 1 | +/** |
| 2 | + * ***************************************************************************** |
| 3 | + * Copyright (c) 2018 Fraunhofer IEM, Paderborn, Germany |
| 4 | + * <p> |
| 5 | + * This program and the accompanying materials are made available under the |
| 6 | + * terms of the Eclipse Public License 2.0 which is available at |
| 7 | + * http://www.eclipse.org/legal/epl-2.0. |
| 8 | + * <p> |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * <p> |
| 11 | + * Contributors: |
| 12 | + * Johannes Spaeth - initial API and implementation |
| 13 | + * ***************************************************************************** |
| 14 | + */ |
| 15 | +package typestate; |
| 16 | + |
| 17 | +import boomerang.flowfunction.DefaultFlowFunctionFactory; |
| 18 | +import boomerang.flowfunction.IBackwardFlowFunction; |
| 19 | +import boomerang.flowfunction.IForwardFlowFunction; |
| 20 | +import boomerang.options.BoomerangOptions; |
| 21 | +import boomerang.scope.FrameworkScope; |
| 22 | +import boomerang.solver.BackwardBoomerangSolver; |
| 23 | +import boomerang.solver.ForwardBoomerangSolver; |
| 24 | +import boomerang.solver.Strategies; |
| 25 | +import boomerang.utils.MethodWrapper; |
| 26 | +import java.util.Collection; |
| 27 | + |
| 28 | +/** |
| 29 | + * Flow function factory that extends the {@link DefaultFlowFunctionFactory} by adding features to |
| 30 | + * deal with chained methods when applying the call-to-return flow. Intermediate representations |
| 31 | + * transform chained method calls into multiple statements and introduce new locals for each |
| 32 | + * intermediate call. Although the chained calls return the original objects (i.e. an alias), the |
| 33 | + * default flow function do not find the aliases. The extension in this flow function factory adds |
| 34 | + * the functionality to collect corresponding aliases, too. |
| 35 | + * |
| 36 | + * <p>For example, a program |
| 37 | + * |
| 38 | + * <pre>{@code |
| 39 | + * l.chain().chain(); |
| 40 | + * }</pre> |
| 41 | + * |
| 42 | + * is transformed into the intermediate representation |
| 43 | + * |
| 44 | + * <pre>{@code |
| 45 | + * $s0 = l.chain(); |
| 46 | + * $s1 = $s0.chain(); |
| 47 | + * }</pre> |
| 48 | + * |
| 49 | + * The extended flow functions make sure to collect $s0 and $s1 as alias s.t. the analysis can |
| 50 | + * collect the second call to chain(). |
| 51 | + */ |
| 52 | +public class ChainingFlowFunctionFactory extends DefaultFlowFunctionFactory { |
| 53 | + |
| 54 | + private final Collection<MethodWrapper> methodChains; |
| 55 | + |
| 56 | + public ChainingFlowFunctionFactory(Collection<MethodWrapper> methodChains) { |
| 57 | + this.methodChains = methodChains; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public IForwardFlowFunction createForwardFlowFunction( |
| 62 | + FrameworkScope frameworkScope, BoomerangOptions options, ForwardBoomerangSolver<?> solver) { |
| 63 | + Strategies strategies = createStrategies(frameworkScope, options, solver); |
| 64 | + |
| 65 | + return new ChainingForwardFlowFunction(strategies, methodChains); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public IBackwardFlowFunction createBackwardFlowFunction( |
| 70 | + FrameworkScope frameworkScope, BoomerangOptions options, BackwardBoomerangSolver<?> solver) { |
| 71 | + Strategies strategies = createStrategies(frameworkScope, options, solver); |
| 72 | + |
| 73 | + return new ChainingBackwardFlowFunction(options.allocationSite(), strategies, methodChains); |
| 74 | + } |
| 75 | +} |
0 commit comments