2007-02-02 17:17:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.ir.ssa;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import com.ibm.wala.ssa.SSAInstruction;
|
2007-02-08 20:45:07 +00:00
|
|
|
import com.ibm.wala.types.TypeReference;
|
2011-06-30 15:45:58 +00:00
|
|
|
import com.ibm.wala.util.collections.Pair;
|
2007-02-02 17:17:13 +00:00
|
|
|
|
2007-02-14 03:07:33 +00:00
|
|
|
/**
|
|
|
|
* This abstract class provides helper functionality for recording
|
|
|
|
* lexical uses and/or definitions. It is used in lexical read and
|
|
|
|
* write instructions
|
|
|
|
*
|
|
|
|
* @author Julian Dolby (dolby@us.ibm.com)
|
|
|
|
*/
|
2007-02-02 17:17:13 +00:00
|
|
|
public abstract class AstLexicalAccess extends SSAInstruction {
|
|
|
|
|
2007-02-14 03:07:33 +00:00
|
|
|
/**
|
|
|
|
* A single lexical access.
|
|
|
|
*
|
|
|
|
* @author Julian Dolby (dolby@us.ibm.com)
|
|
|
|
*/
|
2007-02-02 17:17:13 +00:00
|
|
|
public static class Access {
|
2011-05-02 22:11:27 +00:00
|
|
|
/**
|
|
|
|
* name being accessed
|
|
|
|
*/
|
2007-02-02 17:17:13 +00:00
|
|
|
public final String variableName;
|
2011-04-27 17:06:06 +00:00
|
|
|
/**
|
|
|
|
* name of entity that defines the variable
|
|
|
|
*/
|
2007-02-02 17:17:13 +00:00
|
|
|
public final String variableDefiner;
|
2014-03-16 22:05:49 +00:00
|
|
|
/**
|
|
|
|
* type of the lexical value
|
|
|
|
*/
|
|
|
|
public final TypeReference type;
|
2011-05-02 22:11:27 +00:00
|
|
|
/**
|
|
|
|
* value number used for name where access is being performed (not in the declaring entity)
|
|
|
|
*/
|
2007-02-02 17:17:13 +00:00
|
|
|
public final int valueNumber;
|
|
|
|
|
2014-03-16 22:05:49 +00:00
|
|
|
public Access(String name, String definer, TypeReference type, int vn) {
|
2007-02-02 17:17:13 +00:00
|
|
|
variableName = name;
|
|
|
|
variableDefiner = definer;
|
2014-03-16 22:05:49 +00:00
|
|
|
this.type = type;
|
2011-04-27 17:06:06 +00:00
|
|
|
valueNumber = vn;
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 15:45:58 +00:00
|
|
|
public Pair<String,String> getName() {
|
|
|
|
return Pair.make(variableName, variableDefiner);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public int hashCode() {
|
|
|
|
return variableName.hashCode() * valueNumber;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public boolean equals(Object other) {
|
|
|
|
return (other instanceof Access) &&
|
|
|
|
variableName.equals( ((Access)other).variableName ) &&
|
|
|
|
valueNumber == ((Access)other).valueNumber &&
|
|
|
|
( variableDefiner == null?
|
|
|
|
((Access)other).variableDefiner == null:
|
|
|
|
variableDefiner.equals(((Access)other).variableDefiner) );
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public String toString() {
|
|
|
|
return "Access(" + variableName + "@" + variableDefiner + ":" + valueNumber + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Access[] accesses;
|
|
|
|
|
2011-04-12 17:49:06 +00:00
|
|
|
AstLexicalAccess(int iindex, Access[] accesses) {
|
|
|
|
super(iindex);
|
2007-02-02 17:17:13 +00:00
|
|
|
setAccesses( accesses );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAccesses(Access[] accesses) {
|
|
|
|
this.accesses = accesses;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Access[] getAccesses() {
|
|
|
|
return accesses;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Access getAccess(int i) {
|
|
|
|
return accesses[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getAccessCount() {
|
|
|
|
return accesses.length;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public boolean isFallThrough() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-08 20:45:07 +00:00
|
|
|
public Collection<TypeReference> getExceptionTypes() {
|
2007-02-02 17:17:13 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public int hashCode() {
|
|
|
|
int v = 1;
|
|
|
|
for(int i = 0; i < accesses.length; i++)
|
|
|
|
v *= accesses[i].variableName.hashCode();
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|