soot.jimple.toolkits.infoflow.CallLocalityContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soot Show documentation
Show all versions of soot Show documentation
A Java Optimization Framework
package soot.jimple.toolkits.infoflow;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.ArrayList;
import java.util.List;
import soot.EquivalentValue;
import soot.RefLikeType;
import soot.jimple.InstanceFieldRef;
import soot.jimple.ParameterRef;
import soot.jimple.Ref;
import soot.jimple.StaticFieldRef;
import soot.jimple.ThisRef;
/**
* CallLocalityContext written by Richard L. Halpert 2007-03-05 Acts as a container for the locality information collected
* about a call site by one of the Local Objects Analyses.
*/
public class CallLocalityContext {
List nodes;
List isNodeLocal;
public CallLocalityContext(List nodes) {
this.nodes = new ArrayList();
this.nodes.addAll(nodes);
isNodeLocal = new ArrayList(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
isNodeLocal.add(i, Boolean.FALSE);
}
}
public void setFieldLocal(EquivalentValue fieldRef) {
for (int i = 0; i < nodes.size(); i++) {
if (fieldRef.equals(nodes.get(i))) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.TRUE);
return;
}
}
nodes.add(fieldRef);
isNodeLocal.add(Boolean.TRUE);
// throw new RuntimeException("Field " + fieldRef + " is not present in CallLocalityContext\n" + toString());
// return false;
}
public void setFieldShared(EquivalentValue fieldRef) {
for (int i = 0; i < nodes.size(); i++) {
if (fieldRef.equals(nodes.get(i))) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.FALSE);
return;
}
}
nodes.add(fieldRef);
isNodeLocal.add(Boolean.FALSE);
// throw new RuntimeException("Field " + fieldRef + " is not present in CallLocalityContext\n" + toString());
// return false;
}
public void setAllFieldsLocal() {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof InstanceFieldRef) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.TRUE);
}
}
}
public void setAllFieldsShared() {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof InstanceFieldRef) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.FALSE);
}
}
}
public void setParamLocal(int index) {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof ParameterRef) {
ParameterRef pr = (ParameterRef) r;
if (pr.getIndex() == index) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.TRUE);
}
}
}
}
public void setParamShared(int index) {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof ParameterRef) {
ParameterRef pr = (ParameterRef) r;
if (pr.getIndex() == index) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.FALSE);
}
}
}
}
public void setAllParamsLocal() {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof ParameterRef) {
ParameterRef pr = (ParameterRef) r;
if (pr.getIndex() != -1) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.TRUE);
}
}
}
}
public void setAllParamsShared() {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof ParameterRef) {
ParameterRef pr = (ParameterRef) r;
if (pr.getIndex() != -1) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.FALSE);
}
}
}
}
public void setThisLocal() {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof ThisRef) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.TRUE);
}
}
}
public void setThisShared() {
for (int i = 0; i < nodes.size(); i++) {
Ref r = (Ref) ((EquivalentValue) nodes.get(i)).getValue();
if (r instanceof ThisRef) {
isNodeLocal.remove(i);
isNodeLocal.add(i, Boolean.FALSE);
}
}
}
public void setReturnLocal() {
setParamLocal(-1);
}
public void setReturnShared() {
setParamShared(-1);
}
public List