move to incubator branch
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@770 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
e0db2777ff
commit
c6dd90d79f
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -1,6 +0,0 @@
|
|||
#*
|
||||
*#
|
||||
*~
|
||||
*.class
|
||||
bin
|
||||
build
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.ibm.wala.stringAnalysis</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,20 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: String Analysis Plug-in
|
||||
Bundle-SymbolicName: com.ibm.wala.stringAnalysis
|
||||
Bundle-Version: 1.0.0
|
||||
Bundle-Activator: com.ibm.wala.stringAnalysis.SaPlugin
|
||||
Bundle-Vendor: IBM
|
||||
Bundle-Localization: plugin
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
com.ibm.wala.automaton,
|
||||
com.ibm.wala.cast,
|
||||
com.ibm.wala.core
|
||||
Eclipse-LazyStart: true
|
||||
Export-Package: com.ibm.wala.stringAnalysis,
|
||||
com.ibm.wala.stringAnalysis.grammar,
|
||||
com.ibm.wala.stringAnalysis.ssa,
|
||||
com.ibm.wala.stringAnalysis.translator,
|
||||
com.ibm.wala.stringAnalysis.translator.repository,
|
||||
com.ibm.wala.stringAnalysis.util
|
|
@ -1,4 +0,0 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
=======================================================================
|
||||
DOMO String Analysis build file
|
||||
=======================================================================
|
||||
-->
|
||||
<project name="com.ibm.wala.stringAnalysis" default="jar" basedir=".">
|
||||
<!-- Software version details -->
|
||||
<property name="name" value="walasa" />
|
||||
<property name="module_name" value="com.ibm.wala.stringAnalysis" />
|
||||
<property name="Name" value="WALA String Analysis" />
|
||||
<property name="version" value="1-alpha" />
|
||||
|
||||
<!-- Compilation switches -->
|
||||
<property name="debug" value="true" />
|
||||
<property name="deprecation" value="false" />
|
||||
<property name="optimize" value="true" />
|
||||
<property name="javacFailOnError" value="true" />
|
||||
<property name="javacDebugInfo" value="on" />
|
||||
<property name="javacVerbose" value="false" />
|
||||
|
||||
|
||||
<!-- Set global properties for this build -->
|
||||
<property name="src" value="src" />
|
||||
<property name="src.tests" value="tests" />
|
||||
<property name="build" value="build" />
|
||||
<property name="build.result" value="${basedir}" />
|
||||
<property name="build.tests" value="${basedir}" />
|
||||
<property name="build.javadocs" value="${build}/javadocs" />
|
||||
<property name="publish.javadocs" value="javadocs/com.ibm.wala.stringAnalysis" />
|
||||
<property name="dist" value="dist" />
|
||||
<property name="etc" value="etc" />
|
||||
<property name="docs" value="docs" />
|
||||
<property name="lib" value="lib" />
|
||||
<property name="mainlib" value="../mainlib" />
|
||||
<property name="sharedlib" value="../sharedlib" />
|
||||
|
||||
<import file="${sharedlib}/scripts/common-targets.xml"/>
|
||||
|
||||
</project>
|
|
@ -1,64 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis;
|
||||
|
||||
import org.eclipse.ui.plugin.*;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The main plugin class to be used in the desktop.
|
||||
*/
|
||||
public class SaPlugin extends AbstractUIPlugin {
|
||||
|
||||
//The shared instance.
|
||||
private static SaPlugin plugin;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public SaPlugin() {
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called upon plug-in activation
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the plug-in is stopped
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
super.stop(context);
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance.
|
||||
*/
|
||||
public static SaPlugin getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path.
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return AbstractUIPlugin.imageDescriptorFromPlugin("com.ibm.domo.sa", path);
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
|
||||
public class CDVariable extends Variable {
|
||||
private int valueNumber;
|
||||
private CallGraph callGraph;
|
||||
private CGNode node;
|
||||
private CallSiteReference callSite;
|
||||
|
||||
public CDVariable(String name, int v, CallGraph cg, CGNode node, CallSiteReference callSite) {
|
||||
super(name);
|
||||
this.valueNumber = v;
|
||||
this.callGraph = cg;
|
||||
this.node = node;
|
||||
this.callSite = callSite;
|
||||
}
|
||||
|
||||
public int getValueNumber() {
|
||||
return valueNumber;
|
||||
}
|
||||
|
||||
public CallGraph getCallGraph() {
|
||||
return callGraph;
|
||||
}
|
||||
|
||||
public CGNode getCGNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public CallSiteReference getCallSiteReference() {
|
||||
return callSite;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
CDVariable v = (CDVariable) obj;
|
||||
return (valueNumber == v.getValueNumber())
|
||||
&& callGraph.equals(v.getCallGraph())
|
||||
&& node.equals(v.getCGNode())
|
||||
&& ((callSite==null) ? (v.getCallSiteReference()==null) : callSite.equals(v.getCallSiteReference()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String s = super.toString();
|
||||
s = s + "[" + valueNumber + "]" + "[CGNode:" + callGraph.getNumber(node) + "]";
|
||||
if (callSite != null) {
|
||||
s = s + "[CallSiteReference:" + System.identityHashCode(callSite) + "]";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
|
@ -1,393 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.DeepGrammarCopier;
|
||||
import com.ibm.wala.automaton.grammar.string.DeepRuleCopier;
|
||||
import com.ibm.wala.automaton.grammar.string.Grammars;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammarCopier;
|
||||
import com.ibm.wala.automaton.string.Automatons;
|
||||
import com.ibm.wala.automaton.string.DeepSymbolCopier;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.IStateTransitionSystem;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.SimpleSTSCopier;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
|
||||
public class ControlledGrammars extends Grammars {
|
||||
static public IRegularlyControlledGrammar useUniqueStates(IRegularlyControlledGrammar g1, IRegularlyControlledGrammar g2, Map m) {
|
||||
return useUniqueStates(g1, Automatons.collectStateNames(g2.getAutomaton()), m);
|
||||
}
|
||||
|
||||
static public IRegularlyControlledGrammar useUniqueStates(IRegularlyControlledGrammar g, Set baseNames, Map m) {
|
||||
final IAutomaton automaton = Automatons.useUniqueStates(g.getAutomaton(), baseNames, m);
|
||||
g = (IRegularlyControlledGrammar) g.copy(
|
||||
new RegularlyControlledGrammar.DeepCopier(){
|
||||
public IStateTransitionSystem copy(IStateTransitionSystem sts) {
|
||||
return automaton;
|
||||
}
|
||||
});
|
||||
return g;
|
||||
}
|
||||
|
||||
static public IRegularlyControlledGrammar useUniqueInputSymbols(IRegularlyControlledGrammar g1, IRegularlyControlledGrammar g2, Map m) {
|
||||
return useUniqueInputSymbols(g1, Automatons.collectInputSymbolNames(g2.getAutomaton()), m);
|
||||
}
|
||||
|
||||
static public IRegularlyControlledGrammar useUniqueInputSymbols(IRegularlyControlledGrammar g, Set baseNames, Map m) {
|
||||
final IAutomaton automaton = Automatons.useUniqueInputSymbols(g.getAutomaton(), baseNames, m);
|
||||
final Map ruleMap = new HashMap();
|
||||
for (Iterator i = g.getRuleMap().keySet().iterator(); i.hasNext(); ) {
|
||||
ISymbol symbol = (ISymbol) i.next();
|
||||
IProductionRule rule = g.getRule(symbol);
|
||||
ISymbol newSymbol = (ISymbol) m.get(symbol);
|
||||
ruleMap.put(newSymbol, rule);
|
||||
}
|
||||
final Set fails = new HashSet();
|
||||
for (Iterator i = g.getFails().iterator(); i.hasNext(); ) {
|
||||
ISymbol symbol = (ISymbol) i.next();
|
||||
ISymbol newSymbol = (ISymbol) m.get(symbol);
|
||||
fails.add(newSymbol);
|
||||
}
|
||||
|
||||
g = (IRegularlyControlledGrammar) g.copy(
|
||||
new RegularlyControlledGrammar.DeepCopier(){
|
||||
public IStateTransitionSystem copy(IStateTransitionSystem sts) {
|
||||
return automaton;
|
||||
}
|
||||
});
|
||||
g.getRuleMap().clear();
|
||||
g.getRuleMap().putAll(ruleMap);
|
||||
g.getFails().clear();
|
||||
g.getFails().addAll(fails);
|
||||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: reuse useUniqueVariables(RegularlyControlledGrammar,Set,Map)
|
||||
* replace all the variables
|
||||
* @param g
|
||||
* @param baseNames
|
||||
* @param m
|
||||
* @return
|
||||
*/
|
||||
static public GR useUniqueVariables(GR g, IVariableFactory varFactory, final Map m) {
|
||||
Set variables = g.getNonterminals();
|
||||
for (Iterator i = variables.iterator(); i.hasNext(); ) {
|
||||
IVariable v = (IVariable) i.next();
|
||||
IVariable newVar = varFactory.createVariable(variablePrefix);
|
||||
m.put(v, newVar);
|
||||
}
|
||||
|
||||
final Map ruleMap = new HashMap(g.getRuleMap());
|
||||
for (Iterator i = ruleMap.keySet().iterator(); i.hasNext(); ) {
|
||||
ISymbol isym = (ISymbol) i.next();
|
||||
GRule rule = (GRule) ruleMap.get(isym);
|
||||
IR ir = rule.getIR();
|
||||
SSAInstruction instruction = rule.getSSAInstruction();
|
||||
IVariable left = (IVariable) m.get(rule.getLeft());
|
||||
List right = new ArrayList();
|
||||
for (Iterator j = rule.getRight().iterator(); j.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) j.next();
|
||||
if (s instanceof IVariable && !(s instanceof LexicalVariable)) {
|
||||
right.add(m.get(s));
|
||||
}
|
||||
else {
|
||||
right.add(s);
|
||||
}
|
||||
}
|
||||
GRule newRule = null;
|
||||
if (rule instanceof GInvocationRule) {
|
||||
GInvocationRule crule = (GInvocationRule) rule;
|
||||
GInvocationRule newCRule = new GInvocationRule(crule.getGrammars(), ir, instruction, left, right);
|
||||
newCRule.getAliasRules().addAll(crule.getAliasRules());
|
||||
newRule = newCRule;
|
||||
}
|
||||
else {
|
||||
newRule = new GRule(ir, instruction, left, right);
|
||||
}
|
||||
ruleMap.put(isym, newRule);
|
||||
}
|
||||
List parameters = new ArrayList();
|
||||
for (Iterator i = g.getParameterVariables().iterator(); i.hasNext(); ) {
|
||||
IVariable v = (IVariable) i.next();
|
||||
parameters.add(m.get(v));
|
||||
}
|
||||
Set returns = new HashSet();
|
||||
for (Iterator i = g.getReturnSymbols().iterator(); i.hasNext(); ) {
|
||||
IVariable v = (IVariable) i.next();
|
||||
returns.add(m.get(v));
|
||||
}
|
||||
return new GR(g.getIR(), parameters, returns, g.getAutomaton(), g.getFails(), ruleMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: reuse useUniqueVariables(RegularlyControlledGrammar,Set,Map)
|
||||
* replace all the variables
|
||||
* @param g
|
||||
* @param baseNames
|
||||
* @param m
|
||||
* @return
|
||||
*/
|
||||
static public GR appendSuffixToVariables(GR g, String suffix) {
|
||||
final Map ruleMap = new HashMap(g.getRuleMap());
|
||||
for (Iterator i = ruleMap.keySet().iterator(); i.hasNext(); ) {
|
||||
ISymbol isym = (ISymbol) i.next();
|
||||
GRule rule = (GRule) ruleMap.get(isym);
|
||||
IR ir = rule.getIR();
|
||||
SSAInstruction instruction = rule.getSSAInstruction();
|
||||
IVariable left = rule.getLeft();
|
||||
if (!(left instanceof LexicalVariable)) {
|
||||
left = new Variable(rule.getLeft().getName() + suffix);
|
||||
}
|
||||
List right = new ArrayList();
|
||||
for (Iterator j = rule.getRight().iterator(); j.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) j.next();
|
||||
if (s instanceof IVariable && !(s instanceof LexicalVariable)) {
|
||||
IVariable r = new Variable(s.getName() + suffix);
|
||||
right.add(r);
|
||||
}
|
||||
else {
|
||||
right.add(s);
|
||||
}
|
||||
}
|
||||
GRule newRule = null;
|
||||
if (rule instanceof GInvocationRule) {
|
||||
GInvocationRule crule = (GInvocationRule) rule;
|
||||
GInvocationRule newCRule = new GInvocationRule(crule.getGrammars(), ir, instruction, left, right);
|
||||
newCRule.getAliasRules().addAll(crule.getAliasRules());
|
||||
newRule = newCRule;
|
||||
}
|
||||
else {
|
||||
newRule = new GRule(ir, instruction, left, right);
|
||||
}
|
||||
ruleMap.put(isym, newRule);
|
||||
}
|
||||
List parameters = new ArrayList();
|
||||
for (Iterator i = g.getParameterVariables().iterator(); i.hasNext(); ) {
|
||||
IVariable v = (IVariable) i.next();
|
||||
v = new Variable(v.getName() + suffix);
|
||||
parameters.add(v);
|
||||
}
|
||||
Set returns = new HashSet();
|
||||
for (Iterator i = g.getReturnSymbols().iterator(); i.hasNext(); ) {
|
||||
IVariable v = (IVariable) i.next();
|
||||
v = new Variable(v.getName() + suffix);
|
||||
returns.add(v);
|
||||
}
|
||||
return new GR(g.getIR(), parameters, returns, g.getAutomaton(), g.getFails(), ruleMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* replace all the variables
|
||||
* @param g
|
||||
* @param baseNames
|
||||
* @param m
|
||||
* @return
|
||||
*/
|
||||
static public RegularlyControlledGrammar useUniqueVariables(RegularlyControlledGrammar g, IVariableFactory varFactory, final Map m) {
|
||||
Set variables = g.getNonterminals();
|
||||
for (Iterator i = variables.iterator(); i.hasNext(); ) {
|
||||
IVariable v = (IVariable) i.next();
|
||||
IVariable newVar = varFactory.createVariable(variablePrefix);
|
||||
m.put(v, newVar);
|
||||
}
|
||||
|
||||
final Map ruleMap = new HashMap(g.getRuleMap());
|
||||
for (Iterator i = ruleMap.keySet().iterator(); i.hasNext(); ) {
|
||||
ISymbol isym = (ISymbol) i.next();
|
||||
IProductionRule rule = (IProductionRule) ruleMap.get(isym);
|
||||
IVariable left = (IVariable) m.get(rule.getLeft());
|
||||
List right = new ArrayList();
|
||||
for (Iterator j = rule.getRight().iterator(); j.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) j.next();
|
||||
if (s instanceof IVariable) {
|
||||
right.add(m.get(s));
|
||||
}
|
||||
else {
|
||||
right.add(s);
|
||||
}
|
||||
}
|
||||
IProductionRule newRule = new ProductionRule(left, right);
|
||||
ruleMap.put(isym, newRule);
|
||||
}
|
||||
return new RegularlyControlledGrammar(g.getAutomaton(), g.getFails(), ruleMap);
|
||||
}
|
||||
|
||||
static public void createSimpleUnion(IRegularlyControlledGrammar g1, IRegularlyControlledGrammar g2) {
|
||||
Automatons.createSimpleUnion(g1.getAutomaton(), g2.getAutomaton());
|
||||
g1.getFails().addAll(g2.getFails());
|
||||
g1.getRuleMap().putAll(g2.getRuleMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* create an union of the two regularly controlled grammar.
|
||||
* TODO: should refer formal definition of the union operator
|
||||
* @param g1
|
||||
* @param g2
|
||||
* @return an union of the two regularly controlled grammar
|
||||
*/
|
||||
static public IRegularlyControlledGrammar createUnion(IRegularlyControlledGrammar g1, IRegularlyControlledGrammar g2) {
|
||||
Map m = new HashMap();
|
||||
g2 = useUniqueInputSymbols(g2, g1, m);
|
||||
g2 = useUniqueStates(g2, g1, m);
|
||||
g1 = (IRegularlyControlledGrammar) g1.copy(SimpleGrammarCopier.defaultCopier);
|
||||
createSimpleUnion(g1, g2);
|
||||
return g1;
|
||||
}
|
||||
|
||||
/**
|
||||
* concatenate the two regularly controlled grammar without renaming in destructive manner.
|
||||
* @param g1
|
||||
* @param g2
|
||||
*/
|
||||
static public void createSimpleConcatenation(IRegularlyControlledGrammar g1, IRegularlyControlledGrammar g2) {
|
||||
Automatons.createSimpleConcatenation(g1.getAutomaton(), g2.getAutomaton());
|
||||
g1.getFails().addAll(g2.getFails());
|
||||
g1.getRuleMap().putAll(g2.getRuleMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* concatenate the two regularly controlled grammar after renaming.
|
||||
* @param g1
|
||||
* @param g2
|
||||
* @return a concatenation of the two grammar
|
||||
*/
|
||||
static public IRegularlyControlledGrammar createConcatenation(IRegularlyControlledGrammar g1, IRegularlyControlledGrammar g2) {
|
||||
Map m = new HashMap();
|
||||
g2 = useUniqueInputSymbols(g2, g1, m);
|
||||
g2 = useUniqueStates(g2, g1, m);
|
||||
g1 = (IRegularlyControlledGrammar) g1.copy(SimpleGrammarCopier.defaultCopier);
|
||||
createSimpleConcatenation(g1, g2);
|
||||
return g1;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a closure of the grammar.
|
||||
* @param g
|
||||
* @return a closure of the grammar
|
||||
*/
|
||||
static public IRegularlyControlledGrammar createClosure(IRegularlyControlledGrammar g) {
|
||||
RegularlyControlledGrammar rcg = (RegularlyControlledGrammar) g.copy(new RegularlyControlledGrammar.DeepCopier(SimpleGrammarCopier.defaultCopier, SimpleSTSCopier.defaultCopier));
|
||||
IAutomaton automaton = rcg.getAutomaton();
|
||||
IState initState = automaton.getInitialState();
|
||||
for (Iterator i = automaton.getFinalStates().iterator(); i.hasNext(); ){
|
||||
IState finalState = (IState) i.next();
|
||||
ISymbol isym = Automatons.createUniqueInputSymbol(automaton);
|
||||
ITransition transition = new Transition(finalState, initState, isym);
|
||||
automaton.getTransitions().add(transition);
|
||||
}
|
||||
return rcg;
|
||||
}
|
||||
|
||||
static public class RCGGraphvizLabelGenerator implements Automatons.IGraphvizLabelGenerator {
|
||||
private IRegularlyControlledGrammar rcg;
|
||||
public RCGGraphvizLabelGenerator(IRegularlyControlledGrammar rcg) {
|
||||
this.rcg = rcg;
|
||||
}
|
||||
|
||||
public String getLabel(ITransition t) {
|
||||
ISymbol input = t.getInputSymbol();
|
||||
IProductionRule rule = rcg.getRule(input);
|
||||
if (rule != null) {
|
||||
return rule.toString();
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public String toGraphviz(IRegularlyControlledGrammar rcg) {
|
||||
return Automatons.toGraphviz(rcg.getAutomaton(), new RCGGraphvizLabelGenerator(rcg));
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: should fix ControlledGrammars.compact().
|
||||
*/
|
||||
static public void compact(IRegularlyControlledGrammar rcg) {
|
||||
IAutomaton automaton = rcg.getAutomaton();
|
||||
Set<ITransition> transitions = automaton.getTransitions();
|
||||
Map<ISymbol,IProductionRule> ruleMap = rcg.getRuleMap();
|
||||
for (ITransition t : transitions) {
|
||||
if(!ruleMap.containsKey(t.getInputSymbol())) {
|
||||
t.setInputSymbol(Transition.EpsilonSymbol);
|
||||
}
|
||||
}
|
||||
Automatons.eliminateEpsilonTransitions(automaton);
|
||||
System.out.println(Automatons.toGraphviz(automaton));
|
||||
for (ISymbol s : ruleMap.keySet()) {
|
||||
System.out.println(s + " : " + ruleMap.get(s));
|
||||
}
|
||||
}
|
||||
|
||||
static public void inlineExpansion(GR gr) {
|
||||
Set<ITransition> transitions = new HashSet<ITransition>(gr.getAutomaton().getTransitions());
|
||||
for (ITransition t : transitions) {
|
||||
ISymbol input = t.getInputSymbol();
|
||||
GRule rule = gr.getRule(input);
|
||||
if (rule instanceof GInvocationRule) {
|
||||
GInvocationRule invoke = (GInvocationRule) rule;
|
||||
// InvocationSymbol invokeSym = (InvocationSymbol) invoke.getRight(0);
|
||||
final Map<ISymbol,ISymbol> m = new HashMap<ISymbol,ISymbol>(invoke.getAliasMap());
|
||||
for (GR g : invoke.getGrammars()) {
|
||||
Set<ISymbol> retSyms = g.getReturnSymbols();
|
||||
for (ISymbol retSym : retSyms) {
|
||||
m.put(retSym, invoke.getLeft());
|
||||
}
|
||||
inlineExpansion(g);
|
||||
g = (GR) g.copy(new DeepGrammarCopier(
|
||||
new DeepRuleCopier(
|
||||
new DeepSymbolCopier(){
|
||||
public ISymbol copy(ISymbol s) {
|
||||
if (m.containsKey(s)) {
|
||||
return m.get(s);
|
||||
}
|
||||
else {
|
||||
return super.copy(s);
|
||||
}
|
||||
}
|
||||
})));
|
||||
g = (GR) ControlledGrammars.useUniqueStates(g, gr, new HashMap());
|
||||
g = (GR) ControlledGrammars.useUniqueInputSymbols(g, gr, new HashMap());
|
||||
ITransition bridge = new Transition(t.getPreState(), g.getAutomaton().getInitialState());
|
||||
gr.getAutomaton().getTransitions().add(bridge);
|
||||
Set<IState> finalStates = g.getAutomaton().getFinalStates();
|
||||
for (IState finalState : finalStates) {
|
||||
bridge = new Transition(finalState, t.getPostState());
|
||||
gr.getAutomaton().getTransitions().add(bridge);
|
||||
}
|
||||
gr.getAutomaton().getTransitions().addAll(g.getAutomaton().getTransitions());
|
||||
gr.assignRules(g.getRuleMap());
|
||||
gr.getAutomaton().getTransitions().remove(t);
|
||||
gr.getRuleMap().remove(t.getInputSymbol());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.IRuleVisitor;
|
||||
import com.ibm.wala.automaton.grammar.string.ISimplify;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
|
||||
public class GInvocationRule extends GRule {
|
||||
private Set<GR> grammars;
|
||||
private Set<IProductionRule> aliasRules;
|
||||
private Map<ISymbol, ISymbol> aliasMap;
|
||||
|
||||
public GInvocationRule(Set<GR> grammars, IR ir, SSAInstruction ssai, IVariable left, ISymbol right[]) {
|
||||
super(ir, ssai, left, right);
|
||||
this.grammars = new HashSet<GR>(grammars);
|
||||
this.aliasRules = new HashSet<IProductionRule>();
|
||||
this.aliasMap = new HashMap<ISymbol,ISymbol>();
|
||||
}
|
||||
|
||||
public GInvocationRule(Set<GR> grammars, IR ir, SSAInstruction ssai, IVariable left, List right) {
|
||||
super(ir, ssai, left, right);
|
||||
this.grammars = new HashSet<GR>(grammars);
|
||||
this.aliasRules = new HashSet<IProductionRule>();
|
||||
this.aliasMap = new HashMap<ISymbol,ISymbol>();
|
||||
}
|
||||
|
||||
public GInvocationRule(Set<GR> grammars, GRule instruction) {
|
||||
super(instruction);
|
||||
this.grammars = new HashSet<GR>(grammars);
|
||||
this.aliasRules = new HashSet<IProductionRule>();
|
||||
this.aliasMap = new HashMap<ISymbol,ISymbol>();
|
||||
}
|
||||
|
||||
public GInvocationRule(GInvocationRule instruction) {
|
||||
super(instruction);
|
||||
this.grammars = new HashSet<GR>(instruction.getGrammars());
|
||||
this.aliasRules = new HashSet<IProductionRule>();
|
||||
this.aliasMap = new HashMap<ISymbol,ISymbol>();
|
||||
}
|
||||
|
||||
public Set<GR> getGrammars() {
|
||||
return grammars;
|
||||
}
|
||||
|
||||
public Set<IProductionRule> getAliasRules() {
|
||||
return aliasRules;
|
||||
}
|
||||
|
||||
public Map<ISymbol,ISymbol> getAliasMap() {
|
||||
return aliasMap;
|
||||
}
|
||||
|
||||
public void addAliasRule(IR ir, SSAInstruction instruction, int paramIndex, IVariable param, ISymbol value) {
|
||||
aliasMap.put(param, value);
|
||||
GRule grule1 = new GRule(ir, null, param, new ISymbol[]{value});
|
||||
aliasRules.add(grule1);
|
||||
if (paramIndex >= 0) {
|
||||
if (value instanceof IVariable) {
|
||||
GRule grule2 = new GRule(ir, instruction, (IVariable) value, new ISymbol[]{param});
|
||||
aliasRules.add(grule2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!super.equals(obj)) return false;
|
||||
GInvocationRule grule = (GInvocationRule) obj;
|
||||
return aliasRules.equals(grule.aliasRules) && grammars.equals(grule.grammars);
|
||||
}
|
||||
|
||||
public void traverse(IRuleVisitor visitor) {
|
||||
for (Iterator i = aliasRules.iterator(); i.hasNext(); ) {
|
||||
IProductionRule r = (IProductionRule) i.next();
|
||||
r.traverse(visitor);
|
||||
}
|
||||
for (Iterator i = grammars.iterator(); i.hasNext(); ) {
|
||||
IGrammar g = (IGrammar) i.next();
|
||||
g.traverseRules(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(Set history) {
|
||||
if (history.contains(this)) {
|
||||
return "...";
|
||||
}
|
||||
history.add(this);
|
||||
|
||||
StringBuffer callees = new StringBuffer();
|
||||
for (Iterator i = grammars.iterator(); i.hasNext(); ) {
|
||||
ISimplify g = (ISimplify) i.next();
|
||||
String s = null;
|
||||
if (g instanceof RegularlyControlledGrammar) {
|
||||
s = ((RegularlyControlledGrammar)g).toString(history);
|
||||
}
|
||||
else {
|
||||
s = g.toString();
|
||||
}
|
||||
callees.append(s);
|
||||
if (i.hasNext()) {
|
||||
callees.append(", ");
|
||||
}
|
||||
}
|
||||
return "{rule:" + super.toString() + ", callees:" + callees + "}";
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return toString(new HashSet());
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ISimplify;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbolVisitor;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Symbol;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class GR extends RegularlyControlledGrammar<GRule> {
|
||||
private IR ir;
|
||||
private Set<ISymbol> returnSymbols;
|
||||
private List<IVariable> parameterVariables;
|
||||
|
||||
public void traverseSymbols(ISymbolVisitor visitor) {
|
||||
super.traverseSymbols(visitor);
|
||||
for (Iterator i = returnSymbols.iterator(); i.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) i.next();
|
||||
s.traverse(visitor);
|
||||
}
|
||||
for (Iterator i = parameterVariables.iterator(); i.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) i.next();
|
||||
s.traverse(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSpecialVariables(List<IVariable> parameters, Set<ISymbol> returns) {
|
||||
this.returnSymbols = new HashSet<ISymbol>();
|
||||
this.parameterVariables = new ArrayList<IVariable>();
|
||||
if (returns != null) {
|
||||
this.returnSymbols.addAll(returns);
|
||||
}
|
||||
if (parameters != null) {
|
||||
this.parameterVariables.addAll(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public GR(IR ir, List<IVariable> parameters, Set<ISymbol> returns, IAutomaton automaton, Set<ISymbol> fails, Map<ISymbol,GRule> ruleMap) {
|
||||
super(automaton, fails, ruleMap);
|
||||
this.ir = ir;
|
||||
setSpecialVariables(parameters, returns);
|
||||
}
|
||||
|
||||
public GR(IR ir, List<IVariable> parameters, Set<ISymbol> returns, IAutomaton automaton, ISymbol fails[], ISymbol inputs[], GRule rules[]) {
|
||||
super(automaton, fails, inputs, rules);
|
||||
this.ir = ir;
|
||||
setSpecialVariables(parameters, returns);
|
||||
}
|
||||
|
||||
static public GR createGR(IR ir, Set<GRule> rules) {
|
||||
Map<ISymbol,GRule> ruleMap = new HashMap<ISymbol,GRule>();
|
||||
IAutomaton automaton = createAutomaton(rules, ruleMap);
|
||||
Set<ISymbol> fails = new HashSet<ISymbol>(SAUtil.collect(automaton.getTransitions(), new SAUtil.IElementMapper(){
|
||||
public Object map(Object obj) {
|
||||
ITransition t = (ITransition) obj;
|
||||
return t.getInputSymbol();
|
||||
}
|
||||
}));
|
||||
return new GR(ir, new ArrayList(), new HashSet(), automaton, fails, ruleMap);
|
||||
}
|
||||
|
||||
static private IAutomaton createAutomaton(Set<GRule> rules, Map<ISymbol,GRule> ruleMap) {
|
||||
IState initState = new State("s0");
|
||||
IState finalState = new State("s1");
|
||||
Set<IState> finalStates = new HashSet<IState>();
|
||||
finalStates.add(finalState);
|
||||
Set<ITransition> transitions = new HashSet<ITransition>();
|
||||
int i = 0;
|
||||
for(GRule r : rules) {
|
||||
String s = "i" + i;
|
||||
ISymbol input = new Symbol(s);
|
||||
ruleMap.put(input, r);
|
||||
ITransition t = new Transition(initState, finalState, input);
|
||||
transitions.add(t);
|
||||
i++;
|
||||
}
|
||||
IAutomaton a = new Automaton(initState, finalStates, transitions);
|
||||
return a;
|
||||
}
|
||||
|
||||
public GR(GR gr) {
|
||||
super(gr);
|
||||
this.ir = gr.getIR();
|
||||
setSpecialVariables(gr.getParameterVariables(), gr.getReturnSymbols());
|
||||
}
|
||||
|
||||
public IR getIR() {
|
||||
return ir;
|
||||
}
|
||||
|
||||
public SimpleGrammar<IProductionRule> toSimple() {
|
||||
return toCFG(new HashSet());
|
||||
}
|
||||
|
||||
private SimpleGrammar<IProductionRule> toCFG(Set history) {
|
||||
SimpleGrammar<IProductionRule> cfg = super.toSimple();
|
||||
Set<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
for (IProductionRule rule : cfg.getRules()) {
|
||||
if (rule instanceof GInvocationRule) {
|
||||
GInvocationRule crule = (GInvocationRule) rule;
|
||||
rules.addAll(crule.getAliasRules());
|
||||
for (Iterator ig = crule.getGrammars().iterator(); ig.hasNext(); ) {
|
||||
ISimplify g = (ISimplify) ig.next();
|
||||
if (!history.contains(g)) {
|
||||
history.add(g);
|
||||
if (g instanceof GR) {
|
||||
rules.addAll(((GR)g).toCFG(history).getRules());
|
||||
}
|
||||
else {
|
||||
rules.addAll(g.toSimple().getRules());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
rules.add(rule);
|
||||
}
|
||||
}
|
||||
return new ContextFreeGrammar(cfg.getStartSymbol(), rules);
|
||||
}
|
||||
|
||||
public Set<ISymbol> getReturnSymbols(){
|
||||
return this.returnSymbols;
|
||||
}
|
||||
|
||||
public List<IVariable> getParameterVariables() {
|
||||
return this.parameterVariables;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.ssa.*;
|
||||
|
||||
public class GRule extends ProductionRule {
|
||||
private IR ir;
|
||||
private SSAInstruction ssai;
|
||||
|
||||
public GRule(IR ir, SSAInstruction ssai, IVariable left, List right) {
|
||||
super(left, right);
|
||||
this.ir = ir;
|
||||
this.ssai = ssai;
|
||||
}
|
||||
|
||||
public GRule(IR ir, SSAInstruction ssai, IVariable left, ISymbol right[]) {
|
||||
super(left, right);
|
||||
this.ir = ir;
|
||||
this.ssai = ssai;
|
||||
}
|
||||
|
||||
public GRule(GRule instruction) {
|
||||
super(instruction);
|
||||
this.ir = instruction.getIR();
|
||||
this.ssai = instruction.getSSAInstruction();
|
||||
}
|
||||
|
||||
public SSAInstruction getSSAInstruction() {
|
||||
return ssai;
|
||||
}
|
||||
|
||||
public IR getIR() {
|
||||
return ir;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return super.hashCode() + (ssai==null ? 0 : ssai.hashCode());
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
GRule gi = (GRule) obj;
|
||||
return ((ssai==null) ? (gi.getSSAInstruction()==null) : ssai.equals(gi.getSSAInstruction()));
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "{ir:" + ir.getMethod().getName() + ", ssai:" + (ssai==null ? "null" : ssai.toString()) + ", rule:" + super.toString() + "}";
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
|
||||
public interface IControlledGrammar<T extends IProductionRule> extends IGrammar<T>, ISimplify {
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
|
||||
public interface IRegularlyControlledGrammar<T extends IProductionRule> extends IControlledGrammar<T> {
|
||||
|
||||
IAutomaton getAutomaton();
|
||||
|
||||
Set getFails();
|
||||
|
||||
Map<ISymbol,T> getRuleMap();
|
||||
|
||||
void assignRule(ISymbol state, T rule);
|
||||
|
||||
void assignRules(Map<ISymbol,T> ruleMap);
|
||||
|
||||
void assignRules(ISymbol states[], T rules[]);
|
||||
|
||||
T getRule(ISymbol symbol);
|
||||
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbolCopier;
|
||||
import com.ibm.wala.automaton.string.ISymbolVisitor;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class InvocationSymbol implements ISymbol {
|
||||
private List parameters;
|
||||
private ISymbol funcSymbol;
|
||||
private ISymbol recvSymbol;
|
||||
private IR ir;
|
||||
private SSAInstruction instruction;
|
||||
|
||||
private InvocationSymbol() {
|
||||
parameters = new ArrayList();
|
||||
funcSymbol = null;
|
||||
instruction = null;
|
||||
}
|
||||
|
||||
public InvocationSymbol(IR ir, SSAInstruction instruction, ISymbol funcSymbol, ISymbol recvSymbol, List parameters) {
|
||||
this();
|
||||
this.ir = ir;
|
||||
this.instruction = instruction;
|
||||
this.funcSymbol = funcSymbol;
|
||||
this.recvSymbol = recvSymbol;
|
||||
this.parameters.addAll(parameters);
|
||||
}
|
||||
|
||||
public InvocationSymbol(IR ir, SSAInstruction instruction, ISymbol funcSymbol, ISymbol recvSymbol, ISymbol parameters[]) {
|
||||
this(ir, instruction, funcSymbol, recvSymbol, SAUtil.list(parameters));
|
||||
}
|
||||
|
||||
public InvocationSymbol(IR ir, SSAInstruction instruction, String funcName, String recvName, ISymbol parameters[]) {
|
||||
this(ir, instruction, new StringSymbol(funcName), new StringSymbol(recvName), parameters);
|
||||
}
|
||||
|
||||
public ISymbol getFunction() {
|
||||
return funcSymbol;
|
||||
}
|
||||
|
||||
public ISymbol getReceiver() {
|
||||
return recvSymbol;
|
||||
}
|
||||
|
||||
public List getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public ISymbol getParameter(int index) {
|
||||
return (ISymbol) parameters.get(index);
|
||||
}
|
||||
|
||||
public SSAInstruction getInstruction() {
|
||||
return instruction;
|
||||
}
|
||||
|
||||
public IR getIR() {
|
||||
return ir;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return funcSymbol.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
public void setName(String name) {
|
||||
funcSymbol.setName(name);
|
||||
}
|
||||
*/
|
||||
|
||||
public boolean matches(ISymbol symbol, IMatchContext ctx) {
|
||||
if (symbol == null) return false;
|
||||
if (!getClass().equals(symbol.getClass())) return false;
|
||||
|
||||
InvocationSymbol isym = (InvocationSymbol) symbol;
|
||||
if (funcSymbol.matches(isym.funcSymbol, ctx)
|
||||
&& ((recvSymbol==isym.recvSymbol) || recvSymbol.matches(isym.recvSymbol, ctx))
|
||||
&& parameters.size()==isym.getParameters().size()) {
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
ISymbol s1 = (ISymbol) parameters.get(i);
|
||||
ISymbol s2 = (ISymbol) isym.getParameters().get(i);
|
||||
if (!s1.matches(s2,ctx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean possiblyMatches(ISymbol symbol, IMatchContext ctx) {
|
||||
if (symbol == null) return false;
|
||||
if (!getClass().equals(symbol.getClass())) return false;
|
||||
|
||||
InvocationSymbol isym = (InvocationSymbol) symbol;
|
||||
if (funcSymbol.possiblyMatches(isym.funcSymbol, ctx)
|
||||
&& ((recvSymbol==isym.recvSymbol) || recvSymbol.possiblyMatches(isym.recvSymbol, ctx))
|
||||
&& parameters.size()==isym.getParameters().size()) {
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
ISymbol s1 = (ISymbol) parameters.get(i);
|
||||
ISymbol s2 = (ISymbol) isym.getParameters().get(i);
|
||||
if (!s1.possiblyMatches(s2,ctx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void traverse(ISymbolVisitor visitor) {
|
||||
visitor.onVisit(this);
|
||||
funcSymbol.traverse(visitor);
|
||||
if (recvSymbol!=null) recvSymbol.traverse(visitor);
|
||||
for (Iterator i = parameters.iterator(); i.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) i.next();
|
||||
s.traverse(visitor);
|
||||
}
|
||||
visitor.onLeave(this);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw(new RuntimeException(e));
|
||||
}
|
||||
}
|
||||
|
||||
public ISymbol copy(ISymbolCopier copier) {
|
||||
InvocationSymbol s = (InvocationSymbol) copier.copy(this);
|
||||
s.funcSymbol = copier.copySymbolReference(s, funcSymbol);
|
||||
s.recvSymbol = copier.copySymbolReference(s, recvSymbol);
|
||||
s.parameters = new ArrayList(copier.copySymbolReferences(s, parameters));
|
||||
return s;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
/*
|
||||
return funcSymbol.hashCode()
|
||||
+ ((recvSymbol==null) ? 0 : recvSymbol.hashCode())
|
||||
+ parameters.hashCode();
|
||||
*/
|
||||
return funcSymbol.hashCode()
|
||||
+ ((recvSymbol==null) ? 0 : recvSymbol.hashCode());
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
if (!getClass().equals(obj.getClass())) return false;
|
||||
InvocationSymbol isym = (InvocationSymbol) obj;
|
||||
boolean r = funcSymbol.equals(isym.funcSymbol)
|
||||
&& ((recvSymbol==isym.recvSymbol) || recvSymbol.equals(isym.recvSymbol))
|
||||
&& parameters.equals(isym.parameters);
|
||||
return r;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer paramStr = new StringBuffer();
|
||||
for (Iterator i = parameters.iterator(); i.hasNext(); ) {
|
||||
ISymbol param = (ISymbol) i.next();
|
||||
paramStr.append(param.toString());
|
||||
if (i.hasNext()) {
|
||||
paramStr.append(", ");
|
||||
}
|
||||
}
|
||||
return "&" + recvSymbol + "." + funcSymbol.toString() + "(" + paramStr + ")";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class LexicalVariable extends Variable {
|
||||
public LexicalVariable(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.PrefixedSymbol;
|
||||
|
||||
public class MemberSymbol extends PrefixedSymbol {
|
||||
public MemberSymbol(ISymbol prefix, ISymbol symbol) {
|
||||
super(prefix, symbol);
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
|
||||
public class MemberVariable extends PrefixedSymbol implements IVariable {
|
||||
public MemberVariable(IVariable prefix, ISymbol member) {
|
||||
super(prefix, member);
|
||||
}
|
||||
|
||||
public IVariable getReceiver() {
|
||||
return (IVariable) getPrefix();
|
||||
}
|
||||
|
||||
public ISymbol getMember() {
|
||||
return getLocal();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getPrefix().toString() + "." + getLocal().toString();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public class MemberVariable extends VariableWrapper implements IVariable {
|
||||
private ISymbol member;
|
||||
|
||||
public MemberVariable(IVariable prefix, ISymbol member) {
|
||||
super(prefix);
|
||||
this.member = member;
|
||||
}
|
||||
|
||||
public ISymbol getMember() {
|
||||
return member;
|
||||
}
|
||||
|
||||
public IVariable getReceiver() {
|
||||
return getVariable();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "." + member.toString();
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -1,340 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.AbstractGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.Grammars;
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammarCopier;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammarCopier;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.ISTSCopier;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.IStateTransitionSystem;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.SimpleSTSCopier;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class RegularlyControlledGrammar<T extends IProductionRule> extends AbstractGrammar<T> implements IRegularlyControlledGrammar<T> {
|
||||
private IAutomaton automaton;
|
||||
private Set<ISymbol> fails;
|
||||
private Map<ISymbol,T> ruleMap;
|
||||
|
||||
private RegularlyControlledGrammar() {
|
||||
this.fails = new HashSet<ISymbol>();
|
||||
this.ruleMap = new HashMap<ISymbol,T>();
|
||||
setAutomaton(automaton);
|
||||
}
|
||||
|
||||
public RegularlyControlledGrammar(IAutomaton automaton, Set<ISymbol> fails, Map<ISymbol,T> ruleMap) {
|
||||
this();
|
||||
this.fails.addAll(fails);
|
||||
this.ruleMap.putAll(ruleMap);
|
||||
setAutomaton(automaton);
|
||||
}
|
||||
|
||||
public RegularlyControlledGrammar(IAutomaton automaton, ISymbol fails[], ISymbol ruleMapKeys[], T ruleMapVals[]) {
|
||||
this(automaton, SAUtil.set(fails), SAUtil.map(ruleMapKeys,ruleMapVals));
|
||||
}
|
||||
|
||||
public RegularlyControlledGrammar(IAutomaton automaton) {
|
||||
this();
|
||||
setAutomaton(automaton);
|
||||
}
|
||||
|
||||
public RegularlyControlledGrammar(IRegularlyControlledGrammar g) {
|
||||
this(g.getAutomaton(), g.getFails(), g.getRuleMap());
|
||||
}
|
||||
|
||||
private void setAutomaton(IAutomaton automaton) {
|
||||
// TODO: normalize?
|
||||
this.automaton = automaton;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#getAutomaton()
|
||||
*/
|
||||
public IAutomaton getAutomaton() {
|
||||
return automaton;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#getFails()
|
||||
*/
|
||||
public Set<ISymbol> getFails() {
|
||||
return fails;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#getRuleMap()
|
||||
*/
|
||||
public Map<ISymbol,T> getRuleMap() {
|
||||
return ruleMap;
|
||||
}
|
||||
|
||||
public IVariable getStartSymbol() {
|
||||
IState initState = automaton.getInitialState();
|
||||
Set<ITransition> transitions = automaton.getTransitions(initState);
|
||||
Set<IVariable> variables = new HashSet();
|
||||
for (Iterator i = transitions.iterator(); i.hasNext(); ) {
|
||||
ITransition t = (ITransition) i.next();
|
||||
ISymbol isym = t.getInputSymbol();
|
||||
//Assertions._assert(isym!=null, "the automaton should be epsilon-free");
|
||||
if (isym != null) {
|
||||
IProductionRule rule = (IProductionRule) ruleMap.get(isym);
|
||||
IVariable v = rule.getLeft();
|
||||
variables.add(v);
|
||||
}
|
||||
}
|
||||
//Assertions._assert(variables.size()==1, "the automaton should have only an initial input symbol");
|
||||
if (variables.size()==1) {
|
||||
return (IVariable)(new ArrayList(variables)).get(0);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<T> getRules() {
|
||||
return new HashSet<T>(ruleMap.values());
|
||||
}
|
||||
|
||||
public Set<T> getRules(IVariable v) {
|
||||
return Grammars.getRules(this, v);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#assignRule(com.ibm.capa.util.automaton.string.IState, com.ibm.capa.util.grammar.string.IProductionRule)
|
||||
*/
|
||||
public void assignRule(ISymbol symbol, T rule) {
|
||||
ruleMap.put(symbol, rule);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#assignRules(java.util.Map)
|
||||
*/
|
||||
public void assignRules(Map<ISymbol,T> ruleMap) {
|
||||
this.ruleMap.putAll(ruleMap);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#assignRules(com.ibm.capa.util.automaton.string.IState[], com.ibm.capa.util.grammar.string.IProductionRule[])
|
||||
*/
|
||||
public void assignRules(ISymbol symbols[], T rules[]) {
|
||||
assignRules(SAUtil.map(symbols, rules));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.domo.sa.grammar.IRegularControlledGrammar#getRule(com.ibm.capa.util.automaton.string.IState)
|
||||
*/
|
||||
public T getRule(ISymbol symbol) {
|
||||
return ruleMap.get(symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* approximate the regular controlled grammar by a context-free grammar.
|
||||
*/
|
||||
public SimpleGrammar<IProductionRule> toSimple() {
|
||||
Set<IProductionRule> rules = new HashSet<IProductionRule>(ruleMap.values());
|
||||
// IState initState = automaton.getInitialState();
|
||||
IVariable startVar = getStartSymbol();
|
||||
ContextFreeGrammar<IProductionRule> cfg = new ContextFreeGrammar<IProductionRule>(startVar, rules);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static public interface ICopier extends IGrammarCopier, ISTSCopier {
|
||||
Map copyRuleMap(Map map);
|
||||
}
|
||||
|
||||
static public class DeepCopier implements ICopier {
|
||||
private ISTSCopier sCopier;
|
||||
private IGrammarCopier gCopier;
|
||||
|
||||
public DeepCopier() {
|
||||
this(SimpleGrammarCopier.defaultCopier, SimpleSTSCopier.defaultCopier);
|
||||
}
|
||||
|
||||
public DeepCopier(IGrammarCopier gCopier, ISTSCopier sCopier) {
|
||||
this.sCopier = sCopier;
|
||||
this.gCopier = gCopier;
|
||||
}
|
||||
|
||||
public Map copyRuleMap(Map map) {
|
||||
Map m = new HashMap();
|
||||
for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) i.next();
|
||||
IProductionRule r = (IProductionRule) map.get(s);
|
||||
s = s.copy(gCopier);
|
||||
r = r.copy(gCopier);
|
||||
m.put(s, r);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
public IGrammar copy(IGrammar grammar) {
|
||||
return grammar.copy(gCopier);
|
||||
}
|
||||
|
||||
public IProductionRule copy(IProductionRule rule) {
|
||||
return rule.copy(gCopier);
|
||||
}
|
||||
|
||||
public Collection copyRules(Collection rules) {
|
||||
return gCopier.copyRules(rules);
|
||||
}
|
||||
|
||||
public ISymbol copy(ISymbol symbol) {
|
||||
return symbol.copy(gCopier);
|
||||
}
|
||||
|
||||
public Collection copySymbols(Collection symbols) {
|
||||
return gCopier.copySymbols(symbols);
|
||||
}
|
||||
|
||||
public String copyName(String name) {
|
||||
return gCopier.copyName(name);
|
||||
}
|
||||
|
||||
public String copyStateName(String name) {
|
||||
return sCopier.copyStateName(name);
|
||||
}
|
||||
|
||||
public ISymbol copySymbolReference(ISymbol parent, ISymbol symbol) {
|
||||
return gCopier.copySymbolReference(parent, symbol);
|
||||
}
|
||||
|
||||
public Collection copySymbolReferences(ISymbol parent, Collection symbols) {
|
||||
return gCopier.copySymbolReferences(parent, symbols);
|
||||
}
|
||||
|
||||
public IStateTransitionSystem copy(IStateTransitionSystem sts) {
|
||||
return sts.copy(sCopier);
|
||||
}
|
||||
|
||||
public ITransition copy(ITransition transition) {
|
||||
return transition.copy(sCopier);
|
||||
}
|
||||
|
||||
public Collection copyTransitions(Collection transitions) {
|
||||
return sCopier.copyTransitions(transitions);
|
||||
}
|
||||
|
||||
public IState copy(IState state) {
|
||||
return state.copy(sCopier);
|
||||
}
|
||||
|
||||
public Collection copyStates(Collection states) {
|
||||
return sCopier.copyStates(states);
|
||||
}
|
||||
|
||||
public IState copyStateReference(IState parent, IState state) {
|
||||
return sCopier.copyStateReference(parent, state);
|
||||
}
|
||||
|
||||
public Collection copyStateReferences(IState parent, Collection c) {
|
||||
return sCopier.copyStateReferences(parent, c);
|
||||
}
|
||||
}
|
||||
|
||||
public IGrammar<T> copy(final IGrammarCopier<T> copier) {
|
||||
IGrammar<T> g = copier.copy(this);
|
||||
if (!getClass().isInstance(g)) {
|
||||
return g;
|
||||
}
|
||||
ICopier thisCopier = null;
|
||||
if (copier instanceof ICopier) {
|
||||
thisCopier = (ICopier) copier;
|
||||
}
|
||||
else {
|
||||
thisCopier = new DeepCopier(copier, SimpleSTSCopier.defaultCopier);
|
||||
}
|
||||
RegularlyControlledGrammar<T> rg = (RegularlyControlledGrammar<T>) g;
|
||||
rg.ruleMap = new HashMap(thisCopier.copyRuleMap(ruleMap));
|
||||
rg.automaton = (IAutomaton) automaton.copy(thisCopier);
|
||||
rg.fails = new HashSet(thisCopier.copySymbols(fails));
|
||||
return g;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return automaton.hashCode() + fails.hashCode() + ruleMap.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
if (!getClass().equals(obj.getClass())) return false;
|
||||
IRegularlyControlledGrammar g = (IRegularlyControlledGrammar) obj;
|
||||
return automaton.equals(g.getAutomaton())
|
||||
&& fails.equals(g.getFails())
|
||||
&& ruleMap.equals(g.getRuleMap());
|
||||
}
|
||||
|
||||
public String toString(Set history) {
|
||||
if (history.contains(this)) {
|
||||
return "...";
|
||||
}
|
||||
history.add(this);
|
||||
|
||||
StringBuffer rulesStr = new StringBuffer();
|
||||
List rules = new ArrayList();
|
||||
for (Iterator i = ruleMap.keySet().iterator(); i.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) i.next();
|
||||
IProductionRule r = (IProductionRule) ruleMap.get(s);
|
||||
rules.add(new Object[]{s,r});
|
||||
}
|
||||
Collections.sort(rules, new Comparator(){
|
||||
public int compare(Object o1, Object o2) {
|
||||
Object pair1[] = (Object[]) o1;
|
||||
Object pair2[] = (Object[]) o2;
|
||||
IProductionRule r1 = (IProductionRule) pair1[1];
|
||||
IProductionRule r2 = (IProductionRule) pair2[1];
|
||||
return r1.getLeft().getName().compareTo(r2.getLeft().getName());
|
||||
}
|
||||
});
|
||||
for (Iterator i = rules.iterator(); i.hasNext(); ) {
|
||||
Object pair[] = (Object[])i.next();
|
||||
ISymbol s = (ISymbol) pair[0];
|
||||
IProductionRule r = (IProductionRule) pair[1];
|
||||
if (r instanceof GInvocationRule) {
|
||||
GInvocationRule grule = (GInvocationRule) r;
|
||||
rulesStr.append(s.toString() + ": " + grule.toString(history));
|
||||
}
|
||||
else {
|
||||
rulesStr.append(s.toString() + ": " + r.toString());
|
||||
}
|
||||
if (i.hasNext()) {
|
||||
rulesStr.append(", ");
|
||||
}
|
||||
}
|
||||
return "{rules:" + "{" + rulesStr + "}"
|
||||
+ ", automaton:" + automaton.toString()
|
||||
+ ", fails:" + fails.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return toString(new HashSet());
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.grammar;
|
||||
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.VariableWrapper;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class UpdatedObject extends VariableWrapper implements IVariable {
|
||||
private IR ir;
|
||||
private int pc;
|
||||
|
||||
public UpdatedObject(IVariable v, IR ir, int pc) {
|
||||
super(v);
|
||||
this.ir = ir;
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public UpdatedObject(IVariable v, IR ir) {
|
||||
super(v);
|
||||
this.ir = ir;
|
||||
this.pc = -1;
|
||||
}
|
||||
|
||||
public UpdatedObject(IVariable v, IR ir, SSAInstruction instruction) {
|
||||
super(v);
|
||||
this.ir = ir;
|
||||
this.pc = SAUtil.Domo.findPC(this.ir,instruction);
|
||||
}
|
||||
|
||||
public void setIR(IR ir) {
|
||||
this.ir = ir;
|
||||
}
|
||||
|
||||
public void setPC(int pc) {
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public IR getIR() {
|
||||
return ir;
|
||||
}
|
||||
|
||||
public int getPC() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return super.hashCode()
|
||||
+ ((ir == null) ? 0 : ir.hashCode())
|
||||
+ pc;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
UpdatedObject uo = (UpdatedObject) obj;
|
||||
if (ir == null) {
|
||||
return (uo.ir == null) && (pc == uo.pc);
|
||||
}
|
||||
else {
|
||||
return ir.equals(uo.ir) && (pc == uo.pc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "_" + pc;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return super.getName() + "_" + pc;
|
||||
}
|
||||
|
||||
public boolean matches(ISymbol symbol, IMatchContext context) {
|
||||
if (!getClass().equals(symbol.getClass())) return false;
|
||||
if (this == symbol) return true;
|
||||
UpdatedObject uo = (UpdatedObject) symbol;
|
||||
if (super.matches(uo, context)) {
|
||||
if (ir == null) {
|
||||
return (uo.ir == null) && (pc == uo.pc);
|
||||
}
|
||||
else {
|
||||
return ir.equals(uo.ir) && (pc == uo.pc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.ssa;
|
||||
|
||||
import com.ibm.wala.cast.ir.ssa.*;
|
||||
import com.ibm.wala.ssa.*;
|
||||
|
||||
public class SAProcessingInstructionVisitor
|
||||
implements AstInstructionVisitor
|
||||
{
|
||||
public interface Processor {
|
||||
public void onUnsupportedInstruction(SSAInstruction instruction);
|
||||
public void onSSAAbstractInvokeInstruction(SSAAbstractInvokeInstruction instruction);
|
||||
public void onSSABinaryOpInstruction(SSABinaryOpInstruction instruction);
|
||||
public void onSSAAbstractUnaryInstruction(SSAAbstractUnaryInstruction instruction);
|
||||
public void onSSANewInstruction(SSANewInstruction instruction);
|
||||
public void onSSAPhiInstruction(SSAPhiInstruction instruction);
|
||||
public void onSSAConditionalBranchInstruction(SSAConditionalBranchInstruction instruction);
|
||||
public void onSSAReturnInstruction(SSAReturnInstruction instruction);
|
||||
public void onAstLexicalRead(AstLexicalRead instruction);
|
||||
public void onAstLexicalWrite(AstLexicalWrite instruction);
|
||||
public void onSSAPutInstruction(SSAPutInstruction instruction);
|
||||
public void onSSAGetInstruction(SSAGetInstruction instruction);
|
||||
}
|
||||
|
||||
protected final Processor processor;
|
||||
|
||||
public SAProcessingInstructionVisitor(Processor processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
public void visitGoto(SSAGotoInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitArrayLoad(SSAArrayLoadInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitArrayStore(SSAArrayStoreInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
|
||||
}
|
||||
|
||||
public void visitBinaryOp(SSABinaryOpInstruction instruction) {
|
||||
processor.onSSABinaryOpInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitUnaryOp(SSAUnaryOpInstruction instruction) {
|
||||
processor.onSSAAbstractUnaryInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitConversion(SSAConversionInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitComparison(SSAComparisonInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitConditionalBranch(SSAConditionalBranchInstruction instruction) {
|
||||
processor.onSSAConditionalBranchInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitSwitch(SSASwitchInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitReturn(SSAReturnInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitGet(SSAGetInstruction instruction) {
|
||||
processor.onSSAGetInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitPut(SSAPutInstruction instruction) {
|
||||
processor.onSSAPutInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitInvoke(SSAInvokeInstruction instruction) {
|
||||
processor.onSSAAbstractInvokeInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitNew(SSANewInstruction instruction) {
|
||||
processor.onSSANewInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitArrayLength(SSAArrayLengthInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitThrow(SSAThrowInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitMonitor(SSAMonitorInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitCheckCast(SSACheckCastInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitInstanceof(SSAInstanceofInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitPhi(SSAPhiInstruction instruction) {
|
||||
processor.onSSAPhiInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitPi(SSAPiInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitGetCaughtException(SSAGetCaughtExceptionInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitLoadClass(SSALoadClassInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitEachElementGet(EachElementGetInstruction instruction) {
|
||||
processor.onSSAAbstractUnaryInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitEachElementHasNext(EachElementHasNextInstruction instruction) {
|
||||
processor.onSSAAbstractUnaryInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitAstLexicalRead(AstLexicalRead instruction) {
|
||||
processor.onAstLexicalRead(instruction);
|
||||
}
|
||||
|
||||
public void visitAstLexicalWrite(AstLexicalWrite instruction) {
|
||||
processor.onAstLexicalWrite(instruction);
|
||||
}
|
||||
|
||||
public void visitAstGlobalRead(AstGlobalRead instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitAstGlobalWrite(AstGlobalWrite instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitNonExceptingThrow(NonExceptingThrowInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void visitAssert(AstAssertInstruction instruction) {
|
||||
processor.onUnsupportedInstruction(instruction);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.ssa;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.util.*;
|
||||
|
||||
public class SSAInstructionProcessor {
|
||||
private List instructions;
|
||||
|
||||
private SSAInstructionProcessor() {
|
||||
instructions = new ArrayList();
|
||||
}
|
||||
|
||||
public SSAInstructionProcessor(List instructions) {
|
||||
this();
|
||||
this.instructions.addAll(instructions);
|
||||
}
|
||||
|
||||
public SSAInstructionProcessor(SSAInstruction instructions[]) {
|
||||
this(SAUtil.list(instructions));
|
||||
}
|
||||
|
||||
public void eachInstruction(SSAInstruction.IVisitor visitor) {
|
||||
for (Iterator i = instructions.iterator(); i.hasNext(); ) {
|
||||
SSAInstruction instruction = (SSAInstruction) i.next();
|
||||
if (instruction != null) {
|
||||
instruction.visit(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void eachInstruction(SSAInstruction instructions[], SSAInstruction.IVisitor visitor) {
|
||||
(new SSAInstructionProcessor(instructions)).eachInstruction(visitor);
|
||||
}
|
||||
|
||||
static public void eachInstruction(List instructions, SSAInstruction.IVisitor visitor) {
|
||||
(new SSAInstructionProcessor(instructions)).eachInstruction(visitor);
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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
|
||||
*****************************************************************************/
|
||||
/**
|
||||
* translator from Callgraph to GR.
|
||||
*/
|
||||
package com.ibm.wala.stringAnalysis.translator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Symbol;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SSAPhiInstruction;
|
||||
import com.ibm.wala.ssa.SSAPiInstruction;
|
||||
import com.ibm.wala.ssa.SSACFG.BasicBlock;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
|
||||
public class BB2GR implements IBB2Grammar {
|
||||
ISSA2Rule ssa2rule;
|
||||
|
||||
public BB2GR(ISSA2Rule ssa2rule) {
|
||||
this.ssa2rule = ssa2rule;
|
||||
}
|
||||
|
||||
public IGrammar translate(IBasicBlock bb, TranslationContext ctx) {
|
||||
List rules = new ArrayList();
|
||||
List phis = new ArrayList();
|
||||
int first = bb.getFirstInstructionIndex();
|
||||
int last = bb.getLastInstructionIndex();
|
||||
SSAInstruction instructions[] = ctx.getIR().getInstructions();
|
||||
|
||||
if (bb instanceof BasicBlock) {
|
||||
for (Iterator i = ((BasicBlock)bb).iteratePhis(); i.hasNext(); ) {
|
||||
SSAPhiInstruction phi = (SSAPhiInstruction) i.next();
|
||||
Collection rs = ssa2rule.translate(phi, ctx);
|
||||
phis.add(rs);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = first; i <= last; i++) {
|
||||
Collection rs = ssa2rule.translate(instructions[i], ctx);
|
||||
rules.addAll(rs);
|
||||
}
|
||||
if (bb instanceof BasicBlock) {
|
||||
for (Iterator i = ((BasicBlock)bb).iteratePis(); i.hasNext(); ) {
|
||||
SSAPiInstruction pi = (SSAPiInstruction) i.next();
|
||||
Collection rs = ssa2rule.translate(pi, ctx);
|
||||
rules.addAll(rs);
|
||||
}
|
||||
}
|
||||
|
||||
Map ruleMap = new HashMap();
|
||||
Set fails = new HashSet();
|
||||
IState initState = new State("s" + System.identityHashCode(bb) + "[0]");
|
||||
IState preState = initState;
|
||||
Set finalStates = new HashSet();
|
||||
Set states = new HashSet();
|
||||
Set transitions = new HashSet();
|
||||
int idx = 1;
|
||||
for (Iterator i = phis.iterator(); i.hasNext(); ) {
|
||||
Collection rs = (Collection) i.next();
|
||||
IState nextState = new State("s" + System.identityHashCode(bb) + "[" + (idx) + "]");
|
||||
idx ++;
|
||||
for (Iterator j = rs.iterator(); j.hasNext(); ) {
|
||||
IProductionRule rule = (IProductionRule) j.next();
|
||||
IState state = new State("s" + System.identityHashCode(bb) + "[" + Integer.toString(idx) + "]");
|
||||
states.add(state);
|
||||
ISymbol input = new Symbol("p" + System.identityHashCode(bb) + "[" + Integer.toString(idx) + "]");
|
||||
ITransition transition = new Transition(preState, state, input);
|
||||
ruleMap.put(input, rule);
|
||||
transitions.add(transition);
|
||||
ITransition nextTransition = new Transition(state, nextState);
|
||||
transitions.add(nextTransition);
|
||||
idx ++;
|
||||
}
|
||||
preState = nextState;
|
||||
}
|
||||
for (Iterator i = rules.iterator(); i.hasNext(); ) {
|
||||
IProductionRule rule = (IProductionRule) i.next();
|
||||
IState state = new State("s" + System.identityHashCode(bb) + "[" + Integer.toString(idx) + "]");
|
||||
states.add(state);
|
||||
ISymbol input = new Symbol("p" + System.identityHashCode(bb) + "[" + Integer.toString(idx) + "]");
|
||||
ITransition transition = new Transition(preState, state, input);
|
||||
ruleMap.put(input, rule);
|
||||
transitions.add(transition);
|
||||
preState = state;
|
||||
idx ++;
|
||||
}
|
||||
finalStates.add(preState);
|
||||
IAutomaton automaton = new Automaton(initState, finalStates, transitions);
|
||||
IGrammar gr = new GR(ctx.getIR(), null, null, automaton, fails, ruleMap);
|
||||
return gr;
|
||||
}
|
||||
|
||||
public ISSA2Rule getSSA2Rule() {
|
||||
return ssa2rule;
|
||||
}
|
||||
}
|
|
@ -1,247 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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
|
||||
*****************************************************************************/
|
||||
/**
|
||||
* translator from Callgraph to GR.
|
||||
*/
|
||||
package com.ibm.wala.stringAnalysis.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.intset.OrdinalSet;
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.classLoader.*;
|
||||
import com.ibm.wala.ipa.callgraph.*;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.*;
|
||||
import com.ibm.wala.shrikeBT.IInvokeInstruction;
|
||||
import com.ibm.wala.ssa.*;
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class CG2GR implements ICG2Grammar {
|
||||
private IIR2Grammar ir2gr;
|
||||
private ICalleeResolver calleeResolver;
|
||||
|
||||
static private class DefaultFunctionNameResolver implements IFunctionNameResolver {
|
||||
public Set resolve(PropagationCallGraphBuilder builder, CallGraph cg, CGNode node, GR gr, InvocationSymbol invoke) {
|
||||
return SAUtil.set(new ISymbol[]{invoke});
|
||||
}
|
||||
}
|
||||
|
||||
private static ICalleeResolver defaultCalleeResolver = new FunctionNameCalleeResolver(new DefaultFunctionNameResolver());
|
||||
|
||||
public CG2GR(IIR2Grammar ir2gr, ICalleeResolver calleeResolver) {
|
||||
this.ir2gr = ir2gr;
|
||||
this.calleeResolver = calleeResolver;
|
||||
}
|
||||
|
||||
public CG2GR(IIR2Grammar ir2gr) {
|
||||
this(ir2gr, defaultCalleeResolver);
|
||||
}
|
||||
|
||||
public ISimplify translate(PropagationCallGraphBuilder callGraphBuilder) {
|
||||
CallGraph cg = callGraphBuilder.getCallGraph();
|
||||
CalleeMap node2gr = new CalleeMap();
|
||||
Collection entryPoints = cg.getEntrypointNodes();
|
||||
if (entryPoints.isEmpty()) {
|
||||
entryPoints.add(cg.getFakeRootNode());
|
||||
}
|
||||
for (Iterator i = entryPoints.iterator(); i.hasNext(); ) {
|
||||
CGNode entryPoint = (CGNode) i.next();
|
||||
createGRMap(callGraphBuilder, null, entryPoint, null, null, node2gr, new HashSet());
|
||||
}
|
||||
replaceInvocationWithGR(callGraphBuilder, cg, node2gr);
|
||||
IRegularlyControlledGrammar ggr = null;
|
||||
for (Iterator i = cg.getEntrypointNodes().iterator(); i.hasNext(); ) {
|
||||
CGNode entryPoint = (CGNode) i.next();
|
||||
GR gr = (GR) node2gr.get(new CalleeNode(cg,null,entryPoint,null,null));
|
||||
if (ggr == null) {
|
||||
ggr = gr;
|
||||
}
|
||||
else {
|
||||
ggr = ControlledGrammars.createUnion(ggr, gr);
|
||||
}
|
||||
Trace.println("-- CG2GR#translate: ggr =");
|
||||
Trace.println(SAUtil.prettyFormat(ggr));
|
||||
}
|
||||
Assertions._assert(ggr != null);
|
||||
return new GR(null, null, null, ggr.getAutomaton(), ggr.getFails(), ggr.getRuleMap());
|
||||
}
|
||||
|
||||
private void createGRMap(PropagationCallGraphBuilder cgbuilder, CGNode caller, CGNode callee, CallSiteReference callSite, InstanceKey ikey, CalleeMap node2gr, Set history) {
|
||||
CallGraph cg = cgbuilder.getCallGraph();
|
||||
IR ir = SAUtil.Domo.getIR(cg, callee);
|
||||
CalleeNode cnode = new CalleeNode(cg, caller, callee, callSite, ikey);
|
||||
if (history.contains(cnode)) {
|
||||
return ;
|
||||
}
|
||||
history.add(cnode);
|
||||
GR gr = (GR) ir2gr.translate(new TranslationContext(ir, callee, callSite, cgbuilder));
|
||||
node2gr.put(cnode, gr);
|
||||
Trace.println("-- CG2GR#createGRMap: cnode = " + cnode + ", gr =");
|
||||
Trace.println(SAUtil.prettyFormat(gr));
|
||||
// TODO: can I use ir.iterateCallSites()?
|
||||
for (Iterator i = ir.iterateAllInstructions(); i.hasNext(); ) {
|
||||
SSAInstruction instruction = (SSAInstruction) i.next();
|
||||
if (!(instruction instanceof SSAAbstractInvokeInstruction)) {
|
||||
continue;
|
||||
}
|
||||
SSAAbstractInvokeInstruction invoke = (SSAAbstractInvokeInstruction) instruction;
|
||||
if (invoke.getInvocationCode() == IInvokeInstruction.Dispatch.STATIC) {
|
||||
continue;
|
||||
}
|
||||
PointerKey pkey = cgbuilder.getPointerKeyForLocal(cnode.callee, invoke.getReceiver());
|
||||
OrdinalSet ikeys = cgbuilder.getPointerAnalysis().getPointsToSet(pkey);
|
||||
for (Iterator iterIKey = ikeys.iterator(); iterIKey.hasNext(); ) {
|
||||
InstanceKey nextIKey = (InstanceKey) iterIKey.next();
|
||||
CGNode nextNode = cgbuilder.getTargetForCall(cnode.callee, invoke.getCallSite(), nextIKey);
|
||||
if (nextNode == null) continue; // TODO: should remove this code?
|
||||
Assertions._assert(nextNode != null, "no target for " + nextIKey + " at " + invoke + " in " + callee);
|
||||
Trace.println("getTargetForCall in createGRMap(): #node=" + cg.getNumber(nextNode) + ": " + nextNode);
|
||||
Trace.println(" : #ikey=" + nextIKey);
|
||||
Trace.println(" : #site=" + invoke.getCallSite());
|
||||
createGRMap(cgbuilder, cnode.callee, nextNode, invoke.getCallSite(), nextIKey, node2gr, history);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceInvocationWithGR(PropagationCallGraphBuilder builder, CallGraph cg, final CalleeMap node2gr){
|
||||
for (Iterator i = node2gr.getCalleeNodes().iterator(); i.hasNext(); ) {
|
||||
CalleeNode cnode = (CalleeNode) i.next();
|
||||
GR gr = (GR) node2gr.get(cnode);
|
||||
Trace.println("-- CG2GR#replaceInvocationWithGR:");
|
||||
Trace.println("processing " + gr.getIR().getMethod());
|
||||
Trace.println("-- CG2GR#replaceInvocationWithGR: gr =" + SAUtil.prettyFormat(gr));
|
||||
for (Iterator k = gr.getRuleMap().keySet().iterator(); k.hasNext(); ) {
|
||||
ISymbol label = (ISymbol) k.next();
|
||||
GRule rule = (GRule) gr.getRule(label);
|
||||
if (rule.getSSAInstruction() instanceof SSAAbstractInvokeInstruction) {
|
||||
replaceInvokeInstruction(builder, cg, cnode.callee, gr, label, rule, node2gr);
|
||||
}
|
||||
}
|
||||
Trace.println("-- CG2GR#replaceInvocationWithGR: gr =" + SAUtil.prettyFormat(gr));
|
||||
}
|
||||
}
|
||||
|
||||
private Set getCallTargets(CalleeMap node2gr, CGNode caller, CallSiteReference callSite) {
|
||||
Set s = new HashSet();
|
||||
for (Iterator i = node2gr.getCalleeNodes().iterator(); i.hasNext(); ) {
|
||||
CalleeNode cnode = (CalleeNode) i.next();
|
||||
if ( ((cnode.caller==null) ? (caller==null) : cnode.caller.equals(caller))
|
||||
&& ((cnode.callSite==null) ? (callSite==null) : cnode.callSite.equals(callSite)) ) {
|
||||
s.add(node2gr.get(cnode));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected Set resolveCallees(PropagationCallGraphBuilder builder, CallGraph cg, CGNode node, GR gr, GRule rule, CalleeMap node2gr) {
|
||||
return calleeResolver.resolve(builder, cg, node, gr, rule, node2gr);
|
||||
}
|
||||
|
||||
private void replaceInvokeInstruction(PropagationCallGraphBuilder builder, CallGraph cg, CGNode node, GR gr, ISymbol label, GRule rule, final CalleeMap node2gr) {
|
||||
SSAAbstractInvokeInstruction invoke = (SSAAbstractInvokeInstruction) rule.getSSAInstruction();
|
||||
Trace.println("instruction: " + invoke + "[" + invoke.getClass() + "]");
|
||||
Set callees = getCallTargets(node2gr, node, invoke.getCallSite());
|
||||
if (callees.isEmpty()) {
|
||||
Trace.println("callees are not found for: " + rule);
|
||||
Set grammars = resolveCallees(builder, cg, node, gr, rule, node2gr);
|
||||
GInvocationRule crule = new GInvocationRule(grammars, rule);
|
||||
Trace.println("created composite rule for: " + rule);
|
||||
Trace.println(SAUtil.prettyFormat(crule));
|
||||
gr.getRuleMap().put(label, crule);
|
||||
}
|
||||
else{
|
||||
GInvocationRule crule = createCompositeRuleFromGR(builder, gr, rule, callees);
|
||||
Trace.println("created composite rule for: " + rule);
|
||||
Trace.println(SAUtil.prettyFormat(crule));
|
||||
gr.getRuleMap().put(label, crule);
|
||||
}
|
||||
}
|
||||
|
||||
private GInvocationRule createCompositeRuleFromGR(PropagationCallGraphBuilder builder, final GR caller, final GRule rule, Set callees) {
|
||||
InvocationSymbol invokeSymbol = (InvocationSymbol) rule.getRight(0);
|
||||
final GInvocationRule crule = new GInvocationRule(callees, rule);
|
||||
for (Iterator i = callees.iterator(); i.hasNext(); ) {
|
||||
GR callee = (GR) i.next();
|
||||
|
||||
// calculate production rules for function parameters.
|
||||
List params = callee.getParameterVariables();
|
||||
if (!params.isEmpty()) {
|
||||
Trace.println("invoke: " + rule);
|
||||
Trace.println(" " + rule.getSSAInstruction().getClass());
|
||||
Trace.println("callee: " + callee.getIR().getMethod() + " : #params=" + params.size());
|
||||
ListIterator iparams = params.listIterator();
|
||||
{
|
||||
int idx = iparams.nextIndex();
|
||||
IVariable lhs0 = (IVariable) iparams.next(); // 0th parameter of IR represents 'this'.
|
||||
IVariable rhs0 = (IVariable) invokeSymbol.getReceiver();
|
||||
if (rhs0 != null) {
|
||||
Trace.println(" add alias rule (for receiver): " + lhs0 + " <-> " + rhs0);
|
||||
crule.addAliasRule(callee.getIR(), null, idx, lhs0, rhs0);
|
||||
}
|
||||
}
|
||||
while (iparams.hasNext()) {
|
||||
int idx = iparams.nextIndex();
|
||||
IVariable lhs = (IVariable) iparams.next();
|
||||
ISymbol rhs = null;
|
||||
if (idx-1 < invokeSymbol.getParameters().size()) {
|
||||
rhs = invokeSymbol.getParameter(idx-1);
|
||||
}
|
||||
else {
|
||||
rhs = ir2gr.getBB2Grammar().getSSA2Rule().getDefaultParameterValueSymbol();
|
||||
}
|
||||
Trace.println(" add alias rule: " + lhs + " <-> " + rhs);
|
||||
crule.addAliasRule(callee.getIR(), null, idx, lhs, rhs);
|
||||
}
|
||||
}
|
||||
|
||||
// calculate production rules for user defined function calls.
|
||||
final IVariable lhs = rule.getLeft();
|
||||
Set rhss = callee.getReturnSymbols();
|
||||
for (Iterator irhss = rhss.iterator(); irhss.hasNext(); ) {
|
||||
ISymbol rhs = (ISymbol) irhss.next();
|
||||
Trace.println(" add alias rule: " + lhs + " <-> " + rhs);
|
||||
crule.addAliasRule(caller.getIR(), rule.getSSAInstruction(), -1, lhs, rhs);
|
||||
}
|
||||
}
|
||||
Trace.println("created composite rule: ");
|
||||
Trace.println(SAUtil.prettyFormat(crule));
|
||||
return crule;
|
||||
}
|
||||
|
||||
public IIR2Grammar getIR2Grammar() {
|
||||
return ir2gr;
|
||||
}
|
||||
|
||||
/*
|
||||
static public List getIR(
|
||||
CallGraphBuilder builder,
|
||||
Pattern signature, Pattern context) {
|
||||
CallGraph cg = builder.getCallGraph();
|
||||
List irs = new ArrayList();
|
||||
for (Iterator x = cg.iterateNodes(); x.hasNext();) {
|
||||
CGNode N = (CGNode) x.next();
|
||||
IMethod m = N.getMethod();
|
||||
Context c = N.getContext();
|
||||
if (signature.matcher(m.getSignature()).matches()
|
||||
&& context.matcher(c.toString()).matches()) {
|
||||
IR ir = ((SSAContextInterpreter) cg.getInterpreter(N)).getIR(N,
|
||||
builder.getWarnings());
|
||||
irs.add(ir);
|
||||
}
|
||||
}
|
||||
return irs;
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.stringAnalysis.translator.repository.ITranslator;
|
||||
|
||||
public class CallEnv {
|
||||
final public Set terminals;
|
||||
final public IProductionRule invokeRule;
|
||||
final public ITranslator translator;
|
||||
|
||||
public CallEnv(IProductionRule invokeRule, ITranslator translator, Set terminals) {
|
||||
this.invokeRule = invokeRule;
|
||||
this.terminals = terminals;
|
||||
this.translator = translator;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
|
||||
public class CalleeMap {
|
||||
private Map cnode2gr;
|
||||
private Map gr2cnodes;
|
||||
private Set entryGRs;
|
||||
|
||||
public CalleeMap() {
|
||||
cnode2gr = new HashMap();
|
||||
gr2cnodes = new HashMap();
|
||||
entryGRs = new HashSet();
|
||||
}
|
||||
|
||||
public void put(CalleeNode cnode, GR gr) {
|
||||
cnode2gr.put(cnode, gr);
|
||||
Set s = (Set) gr2cnodes.get(gr);
|
||||
if (s == null) {
|
||||
s = new HashSet();
|
||||
gr2cnodes.put(gr, s);
|
||||
}
|
||||
s.add(cnode);
|
||||
|
||||
if (cnode.caller == null) {
|
||||
entryGRs.add(gr);
|
||||
}
|
||||
}
|
||||
|
||||
public GR get(CalleeNode cnode) {
|
||||
return (GR) cnode2gr.get(cnode);
|
||||
}
|
||||
|
||||
public Set get(GR gr) {
|
||||
return (Set) gr2cnodes.get(gr);
|
||||
}
|
||||
|
||||
public Set getGRs() {
|
||||
return gr2cnodes.keySet();
|
||||
}
|
||||
|
||||
public Set getCalleeNodes() {
|
||||
return cnode2gr.keySet();
|
||||
}
|
||||
|
||||
public Set getEntryGRs() {
|
||||
return entryGRs;
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
||||
|
||||
public class CalleeNode {
|
||||
public CallSiteReference callSite; // null is ok.
|
||||
public CGNode callee; // target
|
||||
public CGNode caller;
|
||||
public InstanceKey ikey;
|
||||
public CallGraph cg;
|
||||
|
||||
public CalleeNode(CallGraph cg, CGNode caller, CGNode callee, CallSiteReference callSite, InstanceKey ikey) {
|
||||
this.cg = cg;
|
||||
this.callee = callee;
|
||||
this.caller = caller;
|
||||
this.callSite = callSite;
|
||||
this.ikey = ikey;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return cg.hashCode()
|
||||
+ ((caller==null) ? 0 : caller.hashCode())
|
||||
+ callee.hashCode()
|
||||
+ ((callSite==null) ? 0 : callSite.hashCode())
|
||||
+ ((ikey==null) ? 0 : ikey.hashCode());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
int callSiteId = 0;
|
||||
int callerId = 0;
|
||||
int calleeId = 0;
|
||||
if (callSite != null) {
|
||||
callSiteId = System.identityHashCode(callSite);
|
||||
}
|
||||
callerId = ((caller==null) ? -1 : cg.getNumber(caller));
|
||||
calleeId = ((callee==null) ? -1 : cg.getNumber(callee));
|
||||
return "{caller=" + callerId + ", callee=" + calleeId + ", callSite=" + callSiteId + ", ikey=" + ikey + "}";
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (getClass().equals(obj.getClass())) {
|
||||
CalleeNode other = (CalleeNode) obj;
|
||||
return cg.equals(other.cg)
|
||||
&& ((caller==null) ? (other.caller==null) : caller.equals(other.caller))
|
||||
&& callee.equals(other.callee)
|
||||
&& ((ikey==null) ? (other.ikey==null) : ikey.equals(other.ikey))
|
||||
&& ((callSite==null) ? (other.callSite==null) : callSite.equals(other.callSite));
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GRule;
|
||||
import com.ibm.wala.stringAnalysis.grammar.InvocationSymbol;
|
||||
|
||||
public class FunctionNameCalleeResolver implements ICalleeResolver {
|
||||
private IFunctionNameResolver functionNameResolver;
|
||||
|
||||
public FunctionNameCalleeResolver(IFunctionNameResolver resolver) {
|
||||
functionNameResolver = resolver;
|
||||
}
|
||||
|
||||
public Set<GR> resolve(PropagationCallGraphBuilder builder, CallGraph cg, CGNode node, GR gr, GRule rule, CalleeMap calleeMap) {
|
||||
Set<GR> grammars = new HashSet<GR>();
|
||||
ISymbol sym = (ISymbol) rule.getRight(0);
|
||||
if (!(sym instanceof InvocationSymbol)) {
|
||||
Set<GRule> rules = new HashSet<GRule>();
|
||||
rules.add(rule);
|
||||
GR g = GR.createGR(gr.getIR(), rules);
|
||||
grammars.add(g);
|
||||
return grammars;
|
||||
}
|
||||
InvocationSymbol isym = (InvocationSymbol) sym;
|
||||
Set<InvocationSymbol> msyms = functionNameResolver.resolve(builder, cg, node, gr, isym);
|
||||
for (InvocationSymbol msym : msyms) {
|
||||
Set<GRule> rules = new HashSet<GRule>();
|
||||
GRule newRule = new GRule(gr.getIR(), msym.getInstruction(), rule.getLeft(), new ISymbol[]{msym});
|
||||
rules.add(newRule);
|
||||
GR g = GR.createGR(gr.getIR(), rules);
|
||||
grammars.add(g);
|
||||
}
|
||||
return grammars;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.repository.ITranslatorRepository;
|
||||
|
||||
public class GR2CFG implements ICFGSolver {
|
||||
private IConstraintSolver solver;
|
||||
|
||||
static public class ConstraintSolver extends SimpleConstraintSolver {
|
||||
public ConstraintSolver(ITranslatorRepository translators) {
|
||||
super(translators);
|
||||
}
|
||||
}
|
||||
|
||||
public GR2CFG(ITranslatorRepository translators) {
|
||||
solver = new ConstraintSolver(translators);
|
||||
}
|
||||
|
||||
public IContextFreeGrammar solve(ISimplify grammar, IVariable startSymbol) {
|
||||
return new ContextFreeGrammar(solver.solve(grammar, startSymbol));
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammar;
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
|
||||
public interface IBB2Grammar {
|
||||
ISSA2Rule getSSA2Rule();
|
||||
IGrammar translate(IBasicBlock bb, TranslationContext ctx);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.ISimplify;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
|
||||
public interface ICFGSolver {
|
||||
IContextFreeGrammar solve(ISimplify grammar, IVariable startSymbol);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.*;
|
||||
|
||||
public interface ICG2Grammar {
|
||||
IIR2Grammar getIR2Grammar();
|
||||
ISimplify translate(PropagationCallGraphBuilder callGraphBuilder);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GRule;
|
||||
|
||||
public interface ICalleeResolver {
|
||||
public Set<GR> resolve(PropagationCallGraphBuilder builder, CallGraph cg, CGNode node, GR gr, GRule rule, CalleeMap calleeMap);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
|
||||
public interface IConstraintSolver {
|
||||
SimpleGrammar solve(ISimplify grammar, IVariable startSymbol);
|
||||
SimpleGrammar solve(SimpleGrammar grammar, IVariableFactory<IVariable> varFactory, Stack<CallEnv> callStack);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.ipa.callgraph.*;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.*;
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
|
||||
public interface IFunctionNameResolver {
|
||||
Set<InvocationSymbol> resolve(PropagationCallGraphBuilder builder, CallGraph cg, CGNode node, GR gr, InvocationSymbol invoke);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
|
||||
public interface IIR2Grammar {
|
||||
IBB2Grammar getBB2Grammar();
|
||||
GR translate(TranslationContext ctx);
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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
|
||||
*****************************************************************************/
|
||||
/**
|
||||
* translator from IR to GR.
|
||||
*/
|
||||
package com.ibm.wala.stringAnalysis.translator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSACFG;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SSAReturnInstruction;
|
||||
import com.ibm.wala.stringAnalysis.grammar.ControlledGrammars;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.IRegularlyControlledGrammar;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public class IR2GR implements IIR2Grammar {
|
||||
IBB2Grammar bb2gr = null;
|
||||
|
||||
public IR2GR(IBB2Grammar bb2gr) {
|
||||
this.bb2gr = bb2gr;
|
||||
}
|
||||
|
||||
public GR translate(TranslationContext ctx) {
|
||||
Trace.println("invoking IR2GR#translate with a IR:");
|
||||
Trace.println(ctx.getIR());
|
||||
SSACFG cfg = ctx.getIR().getControlFlowGraph();
|
||||
IBasicBlock bb0 = cfg.getBasicBlock(0);
|
||||
|
||||
Map<IBasicBlock,GR> map = new HashMap<IBasicBlock,GR>();
|
||||
|
||||
Trace.println("invoking IR2GR#createTranslationMap");
|
||||
createTranslationMap(ctx, cfg, bb0, map);
|
||||
Trace.println("IR2GR#createTranslationMap returns a map: " + map);
|
||||
|
||||
// All the variables, states and input symbols should have unique names.
|
||||
// This depends on SSA2Rule and BB2GR.
|
||||
Trace.println("invoking IR2GR#useUniqueSymbols with a map: " + map);
|
||||
useUniqueSymbols(map);
|
||||
Trace.println("IR2GR#useUniqueSymbols returns a map: " + map);
|
||||
|
||||
Trace.println("IR2GR#translate with a map: " + map);
|
||||
translate(cfg, bb0, map);
|
||||
Trace.println("IR2GR#translate returns a map: " + map);
|
||||
|
||||
GR gr = map.get(bb0);
|
||||
|
||||
gr.getParameterVariables().addAll(getParameterVariables(ctx));
|
||||
gr.getReturnSymbols().addAll(getReturnSymbols(ctx));
|
||||
Trace.println("IR2GR#translate result: " + SAUtil.prettyFormat(gr.toString()));
|
||||
|
||||
gr = bb2gr.getSSA2Rule().postTranslate(gr);
|
||||
|
||||
return gr;
|
||||
}
|
||||
|
||||
private void createTranslationMap(TranslationContext ctx, SSACFG cfg, IBasicBlock bb, Map map) {
|
||||
if (map.containsKey(bb)) {
|
||||
return ;
|
||||
}
|
||||
GR bgr = (GR) bb2gr.translate(bb, ctx);
|
||||
Assertions._assert(bgr != null);
|
||||
map.put(bb, bgr);
|
||||
for (Iterator i = cfg.getSuccNodes(bb); i.hasNext(); ) {
|
||||
IBasicBlock nbb = (IBasicBlock) i.next();
|
||||
createTranslationMap(ctx, cfg, nbb, map);
|
||||
}
|
||||
}
|
||||
|
||||
private List getParameterVariables(TranslationContext ctx){
|
||||
IR ir = ctx.getIR();
|
||||
List parameters = new ArrayList();
|
||||
int vals[] = ir.getParameterValueNumbers();
|
||||
for (int i = 0; i < vals.length; i++) {
|
||||
IVariable var = (IVariable) bb2gr.getSSA2Rule().getValueSymbol(vals[i], null, ctx);
|
||||
parameters.add(var);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Set getReturnSymbols(TranslationContext ctx) {
|
||||
IR ir = ctx.getIR();
|
||||
Set returns = new HashSet();
|
||||
for(Iterator i = ir.iterateAllInstructions(); i.hasNext(); ) {
|
||||
SSAInstruction instruction = (SSAInstruction)i.next();
|
||||
if (instruction instanceof SSAReturnInstruction) {
|
||||
int v = instruction.getUse(0);
|
||||
if (v >= 0) {
|
||||
ISymbol s = bb2gr.getSSA2Rule().getValueSymbol(v, instruction, ctx);
|
||||
returns.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returns;
|
||||
}
|
||||
|
||||
private void useUniqueSymbols(Map map) {
|
||||
Set names = new HashSet();
|
||||
for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
|
||||
IBasicBlock bb = (IBasicBlock) i.next();
|
||||
GR gr = (GR) map.get(bb);
|
||||
Map replaceState = new HashMap();
|
||||
IRegularlyControlledGrammar g =
|
||||
ControlledGrammars.useUniqueStates(gr, names, replaceState);
|
||||
names.addAll(replaceState.values());
|
||||
Map replaceSymbol = new HashMap();
|
||||
g = ControlledGrammars.useUniqueInputSymbols(g, names, replaceSymbol);
|
||||
names.addAll(replaceSymbol.values());
|
||||
gr = new GR(gr.getIR(), gr.getParameterVariables(), gr.getReturnSymbols(),
|
||||
g.getAutomaton(), g.getFails(), g.getRuleMap());
|
||||
map.put(bb, gr);
|
||||
}
|
||||
}
|
||||
|
||||
private void translate(SSACFG cfg, IBasicBlock bb0, Map map) {
|
||||
IBasicBlock exitBB = cfg.exit();
|
||||
GR exitGR = (GR) map.get(exitBB);
|
||||
Set finalStates = exitGR.getAutomaton().getFinalStates();
|
||||
Map ruleMap = new HashMap();
|
||||
Set fails = new HashSet();
|
||||
Set transitions = new HashSet();
|
||||
for (Iterator i = map.keySet().iterator(); i.hasNext(); ){
|
||||
IBasicBlock bb = (IBasicBlock) i.next();
|
||||
GR gr = (GR) map.get(bb);
|
||||
fails.addAll(gr.getFails());
|
||||
ruleMap.putAll(gr.getRuleMap());
|
||||
transitions.addAll(gr.getAutomaton().getTransitions());
|
||||
for (Iterator j = cfg.getSuccNodes(bb); j.hasNext(); ) {
|
||||
IBasicBlock nbb = (IBasicBlock) j.next();
|
||||
GR ngr = (GR) map.get(nbb);
|
||||
IState succInitState = ngr.getAutomaton().getInitialState();
|
||||
for (Iterator k = gr.getAutomaton().getFinalStates().iterator(); k.hasNext(); ) {
|
||||
IState finalState = (IState) k.next();
|
||||
ITransition succTrans = new Transition(finalState, succInitState);
|
||||
transitions.add(succTrans);
|
||||
}
|
||||
}
|
||||
}
|
||||
GR gr0 = (GR) map.get(bb0);
|
||||
gr0.getAutomaton().getTransitions().addAll(transitions);
|
||||
gr0.getAutomaton().getFinalStates().clear();
|
||||
gr0.getAutomaton().getFinalStates().addAll(finalStates);
|
||||
gr0.getFails().addAll(fails);
|
||||
gr0.getRuleMap().putAll(ruleMap);
|
||||
}
|
||||
|
||||
public IBB2Grammar getBB2Grammar() {
|
||||
return bb2gr;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
|
||||
public interface ISSA2Rule {
|
||||
Collection<IProductionRule> translate(SSAInstruction instruction, TranslationContext ctx);
|
||||
GR postTranslate(GR gr);
|
||||
|
||||
ISymbol getDefaultParameterValueSymbol();
|
||||
ISymbol getValueSymbol(int v, SSAInstruction instruction, TranslationContext ctx);
|
||||
IProductionRule createRule(IR ir, SSAInstruction instruction, IVariable left, ISymbol right[]);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class RuleAdder implements ISimplify {
|
||||
private Set rules;
|
||||
private ISimplify cfg;
|
||||
|
||||
public RuleAdder(ISimplify cfg, Set rules) {
|
||||
this.cfg = cfg;
|
||||
this.rules = new HashSet(rules);
|
||||
}
|
||||
|
||||
public RuleAdder(ISimplify cfg, IProductionRule rules[]) {
|
||||
this(cfg, SAUtil.set(rules));
|
||||
}
|
||||
|
||||
public SimpleGrammar toSimple() {
|
||||
SimpleGrammar cfg = this.cfg.toSimple();
|
||||
cfg.getRules().addAll(rules);
|
||||
return cfg;
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.DeepGrammarCopier;
|
||||
import com.ibm.wala.automaton.grammar.string.DeepRuleCopier;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.string.DeepSymbolCopier;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalAccess;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalRead;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalWrite;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GRule;
|
||||
import com.ibm.wala.stringAnalysis.grammar.LexicalVariable;
|
||||
|
||||
public class SSA2LexicalRule extends SSA2RuleFilter {
|
||||
private Map<ISymbol,LexicalVariable> lexicalMap;
|
||||
|
||||
public SSA2LexicalRule(ISSA2Rule ssa2rule) {
|
||||
super(ssa2rule);
|
||||
this.lexicalMap = new HashMap<ISymbol,LexicalVariable>();
|
||||
}
|
||||
|
||||
protected void translateAstLexicalRead(AstLexicalRead instruction, TranslationContext ctx, Collection rules) {
|
||||
AstLexicalAccess.Access accesses[] = instruction.getAccesses();
|
||||
for (int i = 0; i < accesses.length; i++) {
|
||||
IVariable left = (IVariable) getValueSymbol(accesses[i].valueNumber, instruction, ctx);
|
||||
// TODO: the lexical variable is identified by its name and definer's name at this moment.
|
||||
String name = accesses[i].variableName;
|
||||
if (accesses[i].variableDefiner != null) {
|
||||
name = name + "@" + accesses[i].variableDefiner;
|
||||
}
|
||||
LexicalVariable right = new LexicalVariable(name);
|
||||
lexicalMap.put(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateAstLexicalWrite(AstLexicalWrite instruction, TranslationContext ctx, Collection rules) {
|
||||
AstLexicalAccess.Access accesses[] = instruction.getAccesses();
|
||||
for (int i = 0; i < accesses.length; i++) {
|
||||
String name = accesses[i].variableName;
|
||||
if (accesses[i].variableDefiner != null) {
|
||||
name = name + "@" + accesses[i].variableDefiner;
|
||||
}
|
||||
LexicalVariable left = new LexicalVariable(name);
|
||||
ISymbol right = getValueSymbol(accesses[i].valueNumber, instruction, ctx);
|
||||
if (lexicalMap.containsKey(right)) {
|
||||
LexicalVariable prevLeft = lexicalMap.get(right);
|
||||
rules.add(new GRule(ctx.getIR(), instruction, left, new ISymbol[]{prevLeft}));
|
||||
//rules.add(new GRule(ctx.getIR(), instruction, prevLeft, new ISymbol[]{left}));
|
||||
}
|
||||
else {
|
||||
lexicalMap.put(right, left);
|
||||
rules.add(new GRule(ctx.getIR(), instruction, left, new ISymbol[]{right}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<IProductionRule> translate(SSAInstruction instruction, TranslationContext ctx) {
|
||||
if (instruction instanceof AstLexicalRead) {
|
||||
Collection<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
translateAstLexicalRead((AstLexicalRead)instruction, ctx, rules);
|
||||
return rules;
|
||||
}
|
||||
else if (instruction instanceof AstLexicalWrite) {
|
||||
Collection<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
translateAstLexicalWrite((AstLexicalWrite)instruction, ctx, rules);
|
||||
return rules;
|
||||
}
|
||||
else {
|
||||
return super.translate(instruction, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public GR postTranslate(GR gr) {
|
||||
gr = super.postTranslate(gr);
|
||||
gr = (GR) gr.copy(new DeepGrammarCopier(new DeepRuleCopier(new DeepSymbolCopier(){
|
||||
public ISymbol copy(ISymbol s) {
|
||||
//System.err.println(s);
|
||||
if (lexicalMap.containsKey(s)) {
|
||||
System.err.println(s + " -> " + lexicalMap.get(s));
|
||||
return lexicalMap.get(s);
|
||||
}
|
||||
else {
|
||||
return super.copy(s);
|
||||
}
|
||||
}
|
||||
})));
|
||||
return gr;
|
||||
}
|
||||
}
|
|
@ -1,456 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Symbol;
|
||||
import com.ibm.wala.cast.ir.ssa.AbstractReflectiveGet;
|
||||
import com.ibm.wala.cast.ir.ssa.AbstractReflectivePut;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalAccess;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalRead;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalWrite;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.AllocationSiteKey;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
||||
import com.ibm.wala.shrikeBT.BinaryOpInstruction;
|
||||
import com.ibm.wala.ssa.ConstantValue;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
|
||||
import com.ibm.wala.ssa.SSAAbstractUnaryInstruction;
|
||||
import com.ibm.wala.ssa.SSABinaryOpInstruction;
|
||||
import com.ibm.wala.ssa.SSAConditionalBranchInstruction;
|
||||
import com.ibm.wala.ssa.SSAFieldAccessInstruction;
|
||||
import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction;
|
||||
import com.ibm.wala.ssa.SSAGetInstruction;
|
||||
import com.ibm.wala.ssa.SSAGotoInstruction;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SSANewInstruction;
|
||||
import com.ibm.wala.ssa.SSAPhiInstruction;
|
||||
import com.ibm.wala.ssa.SSAPutInstruction;
|
||||
import com.ibm.wala.ssa.SSAReturnInstruction;
|
||||
import com.ibm.wala.ssa.Value;
|
||||
import com.ibm.wala.stringAnalysis.grammar.CDVariable;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GRule;
|
||||
import com.ibm.wala.stringAnalysis.grammar.InvocationSymbol;
|
||||
import com.ibm.wala.stringAnalysis.grammar.LexicalVariable;
|
||||
import com.ibm.wala.stringAnalysis.grammar.MemberSymbol;
|
||||
import com.ibm.wala.stringAnalysis.grammar.MemberVariable;
|
||||
import com.ibm.wala.stringAnalysis.ssa.SAProcessingInstructionVisitor;
|
||||
import com.ibm.wala.stringAnalysis.ssa.SSAInstructionProcessor;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.intset.OrdinalSet;
|
||||
|
||||
public abstract class SSA2Rule implements ISSA2Rule {
|
||||
protected String symbolSeparator = ":";
|
||||
private boolean approximateMembers;
|
||||
|
||||
static protected class ConstantSymbol extends Symbol {
|
||||
public ConstantSymbol(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
|
||||
static protected ConstantSymbol NULL_SYMBOL = new ConstantSymbol("#null");
|
||||
static protected ConstantSymbol UNDEFINED_SYMBOL = new ConstantSymbol("#undefined");
|
||||
static protected ConstantSymbol NAN_SYMBOL = new ConstantSymbol("#NaN");
|
||||
static protected ConstantSymbol DEFAULT_PARAMETER_VALUE_SYMBOL = NULL_SYMBOL;
|
||||
|
||||
public SSA2Rule(boolean approximateMembers) {
|
||||
this.approximateMembers = approximateMembers;
|
||||
}
|
||||
|
||||
public SSA2Rule() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public ISymbol getDefaultParameterValueSymbol() {
|
||||
return DEFAULT_PARAMETER_VALUE_SYMBOL;
|
||||
}
|
||||
|
||||
public Set<ISymbol> analyzeValueSymbol(int v, SSAInstruction instruction, TranslationContext ctx) {
|
||||
PointerKey pkey = null;
|
||||
if (ctx.getCGNode() != null) {
|
||||
pkey = ctx.getCGBuilder().getPointerKeyForLocal(ctx.getCGNode(), v);
|
||||
}
|
||||
Set syms = new HashSet();
|
||||
if (pkey != null) {
|
||||
OrdinalSet ikeys = ctx.getCGBuilder().getPointerAnalysis().getPointsToSet(pkey);
|
||||
for (Iterator i = ikeys.iterator(); i.hasNext(); ) {
|
||||
InstanceKey ikey = (InstanceKey) i.next();
|
||||
ISymbol s = getInstanceKeySymbol(ikey, ctx);
|
||||
if (s == null) {
|
||||
syms.clear();
|
||||
return syms;
|
||||
}
|
||||
else {
|
||||
syms.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return syms;
|
||||
}
|
||||
|
||||
public ISymbol getValueSymbol(int v, SSAInstruction instruction, TranslationContext ctx) {
|
||||
if (v < 0) {
|
||||
return null;
|
||||
}
|
||||
Value val = ctx.getIR().getSymbolTable().getValue(v);
|
||||
return getValueSymbol(v, val, ctx);
|
||||
}
|
||||
|
||||
public ISymbol getValueSymbol(int v, Value val, TranslationContext ctx) {
|
||||
if (val instanceof ConstantValue) {
|
||||
ConstantValue cval = (ConstantValue) val;
|
||||
Object obj = cval.getValue();
|
||||
ISymbol s = getObjectSymbol(obj);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
PropagationCallGraphBuilder cgbuilder = ctx.getCGBuilder();
|
||||
String names[] = ctx.getLocalNameTable().getLocalNames(v);
|
||||
String vstr = "";
|
||||
if (names.length==1) {
|
||||
vstr = names[0];
|
||||
}
|
||||
return new CDVariable(vstr, v, cgbuilder.getCallGraph(), ctx.getCGNode(), ctx.getCallSiteReference());
|
||||
}
|
||||
|
||||
public ISymbol getInstanceKeySymbol(InstanceKey ikey, TranslationContext ctx) {
|
||||
if (ikey instanceof ConstantKey) {
|
||||
ConstantKey ckey = (ConstantKey) ikey;
|
||||
ISymbol s = getObjectSymbol(ckey.getValue());
|
||||
return s;
|
||||
}
|
||||
else if (ikey instanceof AllocationSiteKey) {
|
||||
/*
|
||||
AllocationSiteKey akey = (AllocationSiteKey) ikey;
|
||||
NewSiteReference sref = akey.getSite();
|
||||
SSANewInstruction newInstruction = ctx.getIR().getNew(sref);
|
||||
return getValueSymbol(newInstruction.getDef(0), newInstruction, ctx);
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected ISymbol getObjectSymbol(Object obj) {
|
||||
if (obj == null) {
|
||||
return NULL_SYMBOL;
|
||||
}
|
||||
else if (obj instanceof String) {
|
||||
return new StringSymbol((String)obj);
|
||||
}
|
||||
else if (obj instanceof Number) {
|
||||
Number num = (Number) obj;
|
||||
return new NumberSymbol(num.toString());
|
||||
}
|
||||
else {
|
||||
Trace.println("unsupported type of the constant: " + obj.getClass());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected ISymbol getSymbol(String s) {
|
||||
return new Symbol(s);
|
||||
}
|
||||
|
||||
protected List getValueSymbols(int v[], SSAInstruction instruction, TranslationContext ctx) {
|
||||
List l = new ArrayList();
|
||||
for (int i = 0; i < v.length; i++) {
|
||||
l.add(getValueSymbol(v[i], instruction, ctx));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
protected MemberSymbol getMemberSymbol(int objv, int memv, SSAInstruction instruction, IR ir, TranslationContext ctx) {
|
||||
return new MemberSymbol(
|
||||
getValueSymbol(objv, instruction, ctx),
|
||||
getValueSymbol(memv, instruction, ctx));
|
||||
}
|
||||
|
||||
protected MemberVariable getMemberVariable(int objv, int memv, SSAInstruction instruction, TranslationContext ctx) {
|
||||
IVariable s1 = (IVariable) getValueSymbol(objv, instruction, ctx);
|
||||
ISymbol s2 = (ISymbol) getValueSymbol(memv, instruction, ctx);
|
||||
return new MemberVariable(s1, s2);
|
||||
}
|
||||
|
||||
protected MemberVariable getMemberVariable(int objv, SSAFieldAccessInstruction instruction, TranslationContext ctx) {
|
||||
IVariable s1 = (IVariable) getValueSymbol(objv, instruction, ctx);
|
||||
return new MemberVariable(s1, new Symbol(instruction.getDeclaredField().getName().toString()));
|
||||
}
|
||||
|
||||
protected InvocationSymbol getInvocationSymbol(ISymbol f, ISymbol recv, int params[], SSAInstruction instruction, TranslationContext ctx) {
|
||||
InvocationSymbol isym = new InvocationSymbol(ctx.getIR(), instruction, f, recv,
|
||||
getValueSymbols(params, instruction, ctx));
|
||||
return isym;
|
||||
}
|
||||
|
||||
protected String getOperatorName(BinaryOpInstruction.IOperator opCode) {
|
||||
return opCode.toString();
|
||||
}
|
||||
|
||||
private InvocationSymbol getOpSymbol(BinaryOpInstruction.IOperator opCode, int params[], SSAInstruction instruction, TranslationContext ctx){
|
||||
ISymbol op = new Symbol("op(" + getOperatorName(opCode) + ")");
|
||||
InvocationSymbol isym = new InvocationSymbol(ctx.getIR(), instruction, op, null, getValueSymbols(params, instruction, ctx));
|
||||
return isym;
|
||||
}
|
||||
|
||||
public IProductionRule createRule(IR ir, SSAInstruction instruction, IVariable left, ISymbol right[]) {
|
||||
return new GRule(ir, instruction, left, right);
|
||||
}
|
||||
|
||||
protected IProductionRule createRule(IR ir, SSAInstruction instruction, IVariable left, ISymbol right) {
|
||||
return createRule(ir, instruction, left, new ISymbol[]{right});
|
||||
}
|
||||
|
||||
protected class BaseTranslatingProcessor
|
||||
implements SAProcessingInstructionVisitor.Processor
|
||||
{
|
||||
protected final TranslationContext context;
|
||||
protected final Collection rules;
|
||||
|
||||
protected BaseTranslatingProcessor(TranslationContext ctx, Collection rules) {
|
||||
this.context = ctx;
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
public void onUnsupportedInstruction(SSAInstruction instruction) {
|
||||
Assertions._assert(
|
||||
(instruction instanceof SSAReturnInstruction)
|
||||
|| (instruction instanceof SSAGotoInstruction)
|
||||
|| (instruction instanceof SSAGetCaughtExceptionInstruction));
|
||||
}
|
||||
|
||||
public void onSSAAbstractInvokeInstruction(SSAAbstractInvokeInstruction instruction) {
|
||||
translateInvokeInstruction(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSABinaryOpInstruction(SSABinaryOpInstruction instruction) {
|
||||
translateBinaryOpInstruction(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSAAbstractUnaryInstruction(SSAAbstractUnaryInstruction instruction) {
|
||||
translateUnaryInstruction(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSANewInstruction(SSANewInstruction instruction) {
|
||||
translateNewInstruction(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSAPhiInstruction(SSAPhiInstruction instruction) {
|
||||
translatePhiInstruction(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSAGetInstruction(SSAGetInstruction instruction) {
|
||||
translateGet(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSAPutInstruction(SSAPutInstruction instruction) {
|
||||
translatePut(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onSSAConditionalBranchInstruction(SSAConditionalBranchInstruction instruction) {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
public void onSSAReturnInstruction(SSAReturnInstruction instruction) {
|
||||
//System.out.println("TODO: " + instruction + " : " + instruction.getClass());
|
||||
// TODO:
|
||||
}
|
||||
|
||||
public void onAstLexicalRead(AstLexicalRead instruction) {
|
||||
translateAstLexicalRead(instruction, context, rules);
|
||||
}
|
||||
|
||||
public void onAstLexicalWrite(AstLexicalWrite instruction) {
|
||||
translateAstLexicalWrite(instruction, context, rules);
|
||||
}
|
||||
};
|
||||
|
||||
protected SAProcessingInstructionVisitor
|
||||
createTranslatorVisitor(TranslationContext ctx, Collection rules)
|
||||
{
|
||||
return new SAProcessingInstructionVisitor(
|
||||
new BaseTranslatingProcessor(ctx, rules));
|
||||
}
|
||||
|
||||
public Collection<IProductionRule> translate(SSAInstruction instruction, TranslationContext ctx) {
|
||||
final Collection<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
SSAInstructionProcessor.eachInstruction(
|
||||
new SSAInstruction[]{instruction},
|
||||
createTranslatorVisitor(ctx, rules));
|
||||
return rules;
|
||||
}
|
||||
|
||||
protected void translatePhiInstruction(SSAPhiInstruction instruction, TranslationContext ctx, Collection rules) {
|
||||
int nuses = instruction.getNumberOfUses();
|
||||
for( int i = 0; i < nuses; i++ ){
|
||||
IVariable left = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
ISymbol right = getValueSymbol(instruction.getUse(i), instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left, right));
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateNewInstruction(SSANewInstruction instruction, TranslationContext ctx, Collection rules) {
|
||||
/** TODO
|
||||
* Do nothing with NewInstruction in order to avoid an unnecessary
|
||||
* production rule "vXX -> []."
|
||||
* It should be confirmed if this is a "correct" workaround.
|
||||
*/
|
||||
// IVariable left = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
// ISymbol right[] = new Symbol[0];
|
||||
// rules.add(createRule(ctx.getIR(), instruction, left, right));
|
||||
}
|
||||
|
||||
protected void translatePut(SSAPutInstruction instruction, TranslationContext ctx, Collection rules) {
|
||||
IVariable left1 = getMemberVariable(instruction.getRef(), instruction, ctx);
|
||||
ISymbol right1 = getValueSymbol(instruction.getUse(1), instruction, ctx); // obtain propWrite#value
|
||||
rules.add(createRule(ctx.getIR(), instruction, left1, right1));
|
||||
|
||||
if (approximateMembers) {
|
||||
IVariable left2 = (IVariable) getValueSymbol(instruction.getRef(), instruction, ctx);
|
||||
ISymbol right2 = right1;
|
||||
rules.add(createRule(ctx.getIR(), instruction, left2, right2));
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateGet(SSAGetInstruction instruction, TranslationContext ctx, Collection rules) {
|
||||
if (instruction.hasDef()) {
|
||||
IVariable left1 = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
IVariable right1 = getMemberVariable(instruction.getRef(), instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left1, right1));
|
||||
|
||||
if (approximateMembers) {
|
||||
IVariable left2 = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
Set rights2 = analyzeValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
if (rights2.isEmpty()) {
|
||||
ISymbol right2 = getValueSymbol(instruction.getRef(), instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left2, right2));
|
||||
}
|
||||
else {
|
||||
for (Iterator i = rights2.iterator(); i.hasNext(); ) {
|
||||
ISymbol right2 = (ISymbol) i.next();
|
||||
rules.add(createRule(ctx.getIR(), instruction, left2, right2));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("no lhs: (" + instruction.getClass() + ") "
|
||||
+ instruction.toString(ctx.getIR().getSymbolTable(),null));
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateReflectivePut(AbstractReflectivePut instruction, TranslationContext ctx, Collection rules) {
|
||||
IVariable left1 = getMemberVariable(instruction.getObjectRef(), instruction.getMemberRef(), instruction, ctx);
|
||||
ISymbol right1 = getValueSymbol(instruction.getUse(2), instruction, ctx); // obtain propWrite#value
|
||||
rules.add(createRule(ctx.getIR(), instruction, left1, right1));
|
||||
|
||||
if (approximateMembers) {
|
||||
IVariable left2 = (IVariable) getValueSymbol(instruction.getObjectRef(), instruction, ctx);
|
||||
ISymbol right2 = right1;
|
||||
rules.add(createRule(ctx.getIR(), instruction, left2, right2));
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateReflectiveGet(AbstractReflectiveGet instruction, TranslationContext ctx, Collection rules) {
|
||||
if (instruction.hasDef()) {
|
||||
IVariable left1 = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
IVariable right1 = getMemberVariable(instruction.getObjectRef(), instruction.getMemberRef(), instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left1, right1));
|
||||
|
||||
if (approximateMembers) {
|
||||
IVariable left2 = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
Set rights2 = analyzeValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
if (rights2.isEmpty()) {
|
||||
ISymbol right2 = getValueSymbol(instruction.getObjectRef(), instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left2, right2));
|
||||
}
|
||||
else {
|
||||
for (Iterator i = rights2.iterator(); i.hasNext(); ) {
|
||||
ISymbol right2 = (ISymbol) i.next();
|
||||
rules.add(createRule(ctx.getIR(), instruction, left2, right2));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("no lhs: (" + instruction.getClass() + ") "
|
||||
+ instruction.toString(ctx.getIR().getSymbolTable(),null));
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateUnaryInstruction(SSAAbstractUnaryInstruction instruction, TranslationContext ctx, Collection rules) {
|
||||
IVariable left = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
int v = instruction.getUse(0);
|
||||
ISymbol right = getValueSymbol(v, instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left, right));
|
||||
}
|
||||
|
||||
protected void translateBinaryOpInstruction(SSABinaryOpInstruction instruction, TranslationContext ctx, Collection rules) {
|
||||
IVariable left = (IVariable) getValueSymbol(instruction.getDef(0), instruction, ctx);
|
||||
int params[] = new int[instruction.getNumberOfUses()];
|
||||
for( int i = 0; i < params.length; i++ ){
|
||||
params[i] = instruction.getUse(i);
|
||||
}
|
||||
ISymbol right = getOpSymbol(instruction.getOperator(), params, instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left, right));
|
||||
}
|
||||
|
||||
abstract protected void translateInvokeInstruction(SSAAbstractInvokeInstruction instruction, TranslationContext ctx, Collection rules);
|
||||
|
||||
protected void translateAstLexicalRead(AstLexicalRead instruction, TranslationContext ctx, Collection rules) {
|
||||
AstLexicalAccess.Access accesses[] = instruction.getAccesses();
|
||||
for (int i = 0; i < accesses.length; i++) {
|
||||
IVariable left = (IVariable) getValueSymbol(accesses[i].valueNumber, instruction, ctx);
|
||||
// TODO: the lexical variable is identified by its name and definer's name at this moment.
|
||||
String name = accesses[i].variableName;
|
||||
if (accesses[i].variableDefiner != null) {
|
||||
name = name + "@" + accesses[i].variableDefiner;
|
||||
}
|
||||
ISymbol right = new LexicalVariable(name);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left, right));
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateAstLexicalWrite(AstLexicalWrite instruction, TranslationContext ctx, Collection rules) {
|
||||
AstLexicalAccess.Access accesses[] = instruction.getAccesses();
|
||||
for (int i = 0; i < accesses.length; i++) {
|
||||
String name = accesses[i].variableName;
|
||||
if (accesses[i].variableDefiner != null) {
|
||||
name = name + "@" + accesses[i].variableDefiner;
|
||||
}
|
||||
IVariable left = new LexicalVariable(name);
|
||||
ISymbol right = getValueSymbol(accesses[i].valueNumber, instruction, ctx);
|
||||
rules.add(createRule(ctx.getIR(), instruction, left, right));
|
||||
}
|
||||
}
|
||||
|
||||
public GR postTranslate(GR gr) {
|
||||
return gr;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
|
||||
public class SSA2RuleFilter implements ISSA2Rule {
|
||||
private ISSA2Rule ssa2rule;
|
||||
|
||||
public SSA2RuleFilter(ISSA2Rule ssa2rule) {
|
||||
this.ssa2rule = ssa2rule;
|
||||
}
|
||||
|
||||
public IProductionRule createRule(IR ir, SSAInstruction instruction,
|
||||
IVariable left, ISymbol[] right) {
|
||||
return ssa2rule.createRule(ir, instruction, left, right);
|
||||
}
|
||||
|
||||
public ISymbol getDefaultParameterValueSymbol() {
|
||||
return ssa2rule.getDefaultParameterValueSymbol();
|
||||
}
|
||||
|
||||
public ISymbol getValueSymbol(int v, SSAInstruction instruction, TranslationContext ctx) {
|
||||
return ssa2rule.getValueSymbol(v, instruction, ctx);
|
||||
}
|
||||
|
||||
public GR postTranslate(GR gr) {
|
||||
return ssa2rule.postTranslate(gr);
|
||||
}
|
||||
|
||||
public Collection<IProductionRule> translate(SSAInstruction instruction, TranslationContext ctx){
|
||||
return ssa2rule.translate(instruction, ctx);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
|
||||
public abstract class SSA2RuleSelector extends SSA2RuleFilter {
|
||||
public SSA2RuleSelector(ISSA2Rule ssa2rule) {
|
||||
super(ssa2rule);
|
||||
}
|
||||
|
||||
abstract public boolean accept(SSAInstruction instruction, TranslationContext ctx);
|
||||
|
||||
public Collection<IProductionRule> translate(SSAInstruction instruction, TranslationContext ctx) {
|
||||
if (accept(instruction, ctx)) {
|
||||
return super.translate(instruction, ctx);
|
||||
}
|
||||
else {
|
||||
return new HashSet<IProductionRule>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.ssa.*;
|
||||
|
||||
public class SelectingSSA2Rule extends SSA2RuleFilter {
|
||||
Set<SSAInstruction> selected;
|
||||
|
||||
public SelectingSSA2Rule(ISSA2Rule ssa2rule, Set<SSAInstruction> selected) {
|
||||
super(ssa2rule);
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public Collection<IProductionRule> translate(SSAInstruction instruction, TranslationContext ctx) {
|
||||
if (selected.contains(instruction)) {
|
||||
return super.translate(instruction, ctx);
|
||||
}
|
||||
else {
|
||||
return new HashSet<IProductionRule>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,444 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.DeepRuleCopier;
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ISimplify;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleRuleCopier;
|
||||
import com.ibm.wala.automaton.string.Automatons;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.MatchContext;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.VariableReplacer;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GInvocationRule;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.IRegularlyControlledGrammar;
|
||||
import com.ibm.wala.stringAnalysis.grammar.InvocationSymbol;
|
||||
import com.ibm.wala.stringAnalysis.grammar.UpdatedObject;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public class SideEffectSolver implements ISimplify {
|
||||
private IRegularlyControlledGrammar gr;
|
||||
private Set<String> setOperations;
|
||||
private Set<String> getOperations;
|
||||
|
||||
static private class LastUpdatedObject extends UpdatedObject {
|
||||
public LastUpdatedObject(IVariable v) {
|
||||
super(v, null, -1);
|
||||
}
|
||||
}
|
||||
|
||||
static private class Env extends HashMap<IVariable, UpdatedObject> {
|
||||
public Env(Env env) {
|
||||
super(env);
|
||||
}
|
||||
|
||||
public Env() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
static private class SolverContext {
|
||||
Map<Integer, Map<IState, Set<Env>>> history;
|
||||
Map<IGrammar, Set<IProductionRule>> arules;
|
||||
Map<IGrammar, Set<IProductionRule>> drules;
|
||||
Map<IVariable, Set<UpdatedObject>> lastVars;
|
||||
|
||||
public SolverContext() {
|
||||
history = new HashMap<Integer,Map<IState,Set<Env>>>();
|
||||
arules = new HashMap<IGrammar,Set<IProductionRule>>();
|
||||
drules = new HashMap<IGrammar,Set<IProductionRule>>();
|
||||
lastVars = new HashMap<IVariable, Set<UpdatedObject>>();
|
||||
}
|
||||
|
||||
private Integer getGRKey(IRegularlyControlledGrammar gr) {
|
||||
return new Integer(System.identityHashCode(gr));
|
||||
}
|
||||
|
||||
public void put(IRegularlyControlledGrammar gr) {
|
||||
history.put(getGRKey(gr), new HashMap<IState,Set<Env>>());
|
||||
}
|
||||
|
||||
public void put(IRegularlyControlledGrammar gr, IState state, Env env) {
|
||||
Integer grk = getGRKey(gr);
|
||||
Map<IState,Set<Env>> m = history.get(grk);
|
||||
if (m == null) {
|
||||
m = new HashMap<IState,Set<Env>>();
|
||||
history.put(grk, m);
|
||||
}
|
||||
Set<Env> envs = m.get(state);
|
||||
if (envs == null) {
|
||||
envs = new HashSet<Env>();
|
||||
m.put(state, envs);
|
||||
}
|
||||
envs.add(env);
|
||||
}
|
||||
|
||||
public boolean contains(IRegularlyControlledGrammar gr) {
|
||||
return history.containsKey(gr);
|
||||
}
|
||||
|
||||
public boolean contains(IRegularlyControlledGrammar gr, IState state, Env env) {
|
||||
Map<IState,Set<Env>> m = history.get(getGRKey(gr));
|
||||
if (m == null) return false;
|
||||
Set<Env> envs = m.get(state);
|
||||
if (envs == null) return false;
|
||||
return envs.contains(env);
|
||||
}
|
||||
|
||||
public void addRule(IGrammar g, IProductionRule rule) {
|
||||
Set<IProductionRule> s = arules.get(g);
|
||||
if (s == null) {
|
||||
s = new HashSet<IProductionRule>();
|
||||
arules.put(g, s);
|
||||
}
|
||||
Trace.println("add: " + rule);
|
||||
s.add(rule);
|
||||
}
|
||||
|
||||
public void removeRule(IGrammar g, IProductionRule rule) {
|
||||
Set<IProductionRule> s = drules.get(g);
|
||||
if (s == null) {
|
||||
s = new HashSet<IProductionRule>();
|
||||
drules.put(g, s);
|
||||
}
|
||||
Trace.println("remove: " + rule);
|
||||
s.add(rule);
|
||||
}
|
||||
|
||||
public void addLastVar(IVariable v, UpdatedObject uo) {
|
||||
Set<UpdatedObject> s = lastVars.get(v);
|
||||
if (s == null) {
|
||||
s = new HashSet<UpdatedObject>();
|
||||
lastVars.put(v, s);
|
||||
}
|
||||
s.add(uo);
|
||||
}
|
||||
|
||||
public void addLastVarMap(Env m) {
|
||||
for (IVariable v : m.keySet()) {
|
||||
UpdatedObject uo = m.get(v);
|
||||
addLastVar(v, uo);
|
||||
}
|
||||
}
|
||||
|
||||
public void translateGrammars(SimpleGrammar cfg) {
|
||||
for (Iterator i = drules.keySet().iterator(); i.hasNext(); ) {
|
||||
IGrammar g = (IGrammar) i.next();
|
||||
Set rs = (Set) drules.get(g);
|
||||
if (rs != null) {
|
||||
cfg.getRules().removeAll(rs);
|
||||
}
|
||||
}
|
||||
for (Iterator i = arules.keySet().iterator(); i.hasNext(); ) {
|
||||
IGrammar g = (IGrammar) i.next();
|
||||
Set rs = (Set) arules.get(g);
|
||||
if (rs != null) {
|
||||
cfg.getRules().addAll(rs);
|
||||
}
|
||||
}
|
||||
Set<IProductionRule> newRules = new HashSet<IProductionRule>();
|
||||
for (Iterator<IProductionRule> i = cfg.getRules().iterator(); i.hasNext(); ) {
|
||||
IProductionRule rule = i.next();
|
||||
if (rule.getRight().size() != 1) continue;
|
||||
if (!(rule.getRight(0) instanceof InvocationSymbol)) continue;
|
||||
InvocationSymbol invoke = (InvocationSymbol) rule.getRight(0);
|
||||
if (invoke.getParameters().size() < 2) continue;
|
||||
ISymbol s = invoke.getParameter(1);
|
||||
if (s instanceof LastUpdatedObject) {
|
||||
LastUpdatedObject luo = (LastUpdatedObject) s;
|
||||
Set<UpdatedObject> vs = lastVars.get(luo.getVariable());
|
||||
i.remove();
|
||||
if (vs == null) {
|
||||
// TODO: if a target node is not updated, there is no corresponding rule.
|
||||
}
|
||||
else {
|
||||
for (IVariable v : vs) {
|
||||
IMatchContext m = new MatchContext();
|
||||
m.put(luo, v);
|
||||
InvocationSymbol invoke2 = (InvocationSymbol) VariableReplacer.replace(invoke, m);
|
||||
IProductionRule r = new ProductionRule(rule.getLeft(), invoke2);
|
||||
newRules.add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg.getRules().addAll(newRules);
|
||||
}
|
||||
}
|
||||
|
||||
public SideEffectSolver(IRegularlyControlledGrammar gr, Set<String> setOperations, Set<String> getOperations) {
|
||||
this.gr = gr;
|
||||
this.setOperations = new HashSet<String>(setOperations);
|
||||
this.getOperations = new HashSet<String>(getOperations);
|
||||
}
|
||||
|
||||
public SideEffectSolver(IRegularlyControlledGrammar gr, String setOperations[], String getOperations[]) {
|
||||
this(gr, SAUtil.set(setOperations), SAUtil.set(getOperations));
|
||||
}
|
||||
|
||||
public SimpleGrammar toSimple() {
|
||||
SolverContext ctx = new SolverContext();
|
||||
translateGR((IRegularlyControlledGrammar)gr, ctx);
|
||||
SimpleGrammar<IProductionRule> cfg = gr.toSimple();
|
||||
ctx.translateGrammars(cfg);
|
||||
Trace.println("-- after solving side effects");
|
||||
for (IProductionRule r : cfg.getRules()) {
|
||||
Trace.println(r.getLeft() + " -> " + r.getRight() + " : " + r);
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
protected Set<Env> translateGR(IRegularlyControlledGrammar gr, SolverContext ctx) {
|
||||
if (ctx.contains(gr)) {
|
||||
return new HashSet<Env>();
|
||||
}
|
||||
Trace.println("SideEffectSolver#translateGR --");
|
||||
Trace.println("flow: ");
|
||||
Trace.println(Automatons.toGraphviz(gr.getAutomaton()));
|
||||
Trace.println("ruleMap: " + gr.getRuleMap());
|
||||
Set<Env> envs = translateGR(gr, gr.getAutomaton().getInitialState(), new Env(), ctx);
|
||||
for (Env m : envs) {
|
||||
ctx.addLastVarMap(m);
|
||||
}
|
||||
Trace.println("exit:");
|
||||
return envs;
|
||||
}
|
||||
|
||||
private Set<Env> translateGR(IRegularlyControlledGrammar gr, IState state, Env env, SolverContext ctx) {
|
||||
IAutomaton flow = gr.getAutomaton();
|
||||
|
||||
Stack<IState> stackState = new Stack<IState>();
|
||||
Stack<Env> stackEnv = new Stack<Env>();
|
||||
stackState.push(state);
|
||||
stackEnv.push(env);
|
||||
|
||||
Set<Env> envs = new HashSet<Env>();
|
||||
|
||||
while (!stackState.isEmpty()) {
|
||||
IState s = stackState.pop();
|
||||
Env e = new Env(stackEnv.pop());
|
||||
|
||||
if (ctx.contains(gr, s, e)) {
|
||||
Trace.println("skip:");
|
||||
continue;
|
||||
}
|
||||
ctx.put(gr, s, e);
|
||||
|
||||
Set<ITransition> nextTransitions = flow.getTransitions(s);
|
||||
if (nextTransitions.isEmpty()) {
|
||||
envs.add(e);
|
||||
}
|
||||
else {
|
||||
for (ITransition t : nextTransitions) {
|
||||
Trace.println("transition: " + t.getInputSymbol());
|
||||
IProductionRule rule = gr.getRule(t.getInputSymbol());
|
||||
Set<Env> es = new HashSet<Env>();
|
||||
if (rule == null) {
|
||||
es.add(e);
|
||||
}
|
||||
else {
|
||||
Set<Env> ess = translateRule(gr, rule, e, ctx);
|
||||
es.addAll(ess);
|
||||
}
|
||||
for (Env nextEnv : es) {
|
||||
stackState.push(t.getPostState());
|
||||
stackEnv.push(nextEnv);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return envs;
|
||||
}
|
||||
|
||||
private Set translateRule(IGrammar g, Env env, SolverContext ctx) {
|
||||
Set envs = new HashSet();
|
||||
for (Iterator i = g.getRules().iterator(); i.hasNext(); ) {
|
||||
IProductionRule rule = (IProductionRule) i.next();
|
||||
Set es = translateRule(g, rule, env, ctx);
|
||||
envs.addAll(es);
|
||||
}
|
||||
return envs;
|
||||
}
|
||||
|
||||
private Set<Env> translateRule(IGrammar g, IProductionRule rule, Env env, SolverContext ctx) {
|
||||
if (rule instanceof GInvocationRule) {
|
||||
return translateInvokeRule(g, rule, env, ctx);
|
||||
}
|
||||
else {
|
||||
Set<Env> envs = new HashSet<Env>();
|
||||
List right = rule.getRight();
|
||||
if (right.size()>0 && right.get(0) instanceof InvocationSymbol) {
|
||||
InvocationSymbol invoke = (InvocationSymbol) right.get(0);
|
||||
if (invoke.getReceiver() instanceof IVariable) {
|
||||
solveSideEffect(g, rule, invoke, env, ctx);
|
||||
}
|
||||
else {
|
||||
replaceRhs(g, rule, env, ctx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
replaceRhs(g, rule, env, ctx);
|
||||
}
|
||||
envs.add(env);
|
||||
return envs;
|
||||
}
|
||||
}
|
||||
|
||||
// private Set<Env> translateSpecialRule(IGrammar g, IProductionRule rule, Env env, SolverContext ctx) {
|
||||
// Set<Env> envs = new HashSet<Env>();
|
||||
// return envs;
|
||||
// }
|
||||
|
||||
private Set<Env> translateInvokeRule(IGrammar g, IProductionRule rule, Env env, SolverContext ctx) {
|
||||
Set<Env> envs = new HashSet<Env>();
|
||||
|
||||
replaceRhs(g, rule, env, ctx);
|
||||
GInvocationRule crule = (GInvocationRule) rule;
|
||||
|
||||
Set<IProductionRule> aliasRules = new HashSet<IProductionRule>(crule.getAliasRules());
|
||||
Set<IProductionRule> newAliasRules = new HashSet<IProductionRule>();
|
||||
for (Iterator i = crule.getAliasRules().iterator(); i.hasNext(); ) {
|
||||
IProductionRule alias = (IProductionRule) i.next();
|
||||
Trace.println("alias: " + alias);
|
||||
alias = alias.copy(new DeepRuleCopier(new VariableReplacer(env)));
|
||||
newAliasRules.add(alias);
|
||||
Trace.println("-> " + alias);
|
||||
}
|
||||
crule.getAliasRules().clear();
|
||||
crule.getAliasRules().addAll(newAliasRules);
|
||||
|
||||
for (Iterator j = crule.getGrammars().iterator(); j.hasNext(); ) {
|
||||
IGrammar gg = (IGrammar) j.next();
|
||||
if (gg instanceof IRegularlyControlledGrammar) {
|
||||
IRegularlyControlledGrammar gr = (GR) gg;
|
||||
Set es = translateGR(gr, ctx);
|
||||
for (Iterator k = aliasRules.iterator(); k.hasNext(); ) {
|
||||
IProductionRule alias = (IProductionRule) k.next();
|
||||
Assertions._assert(alias.getRight().size()==1);
|
||||
IVariable left = (IVariable) alias.getLeft();
|
||||
ISymbol right = (ISymbol) alias.getRight(0);
|
||||
if (!(right instanceof IVariable)) {
|
||||
continue;
|
||||
}
|
||||
for (Iterator l = es.iterator(); l.hasNext(); ) {
|
||||
Map e = (Map) l.next();
|
||||
IVariable lv = (IVariable) e.get(left);
|
||||
if (lv != null) {
|
||||
UpdatedObject nv = new UpdatedObject((IVariable)right, crule.getIR(), crule.getSSAInstruction());
|
||||
IProductionRule r = new ProductionRule(nv, lv);
|
||||
crule.getAliasRules().add(r);
|
||||
Trace.println("add(alias): " + r);
|
||||
env.put((IVariable)right, nv);
|
||||
}
|
||||
}
|
||||
}
|
||||
envs.add(env);
|
||||
}
|
||||
else {
|
||||
Set es = translateRule(gg, env, ctx);
|
||||
envs.addAll(es);
|
||||
}
|
||||
}
|
||||
|
||||
return envs;
|
||||
}
|
||||
|
||||
private void solveSideEffect(IGrammar g, IProductionRule rule, InvocationSymbol invoke, Map env, SolverContext ctx) {
|
||||
IVariable recv = (IVariable) invoke.getReceiver();
|
||||
if (recv instanceof UpdatedObject) {
|
||||
return ;
|
||||
}
|
||||
|
||||
String funcName = invoke.getFunction().getName();
|
||||
if (getOperations.contains(funcName)) {
|
||||
Trace.println(rule);
|
||||
// b = recv.getXxxx(...) -> b = getXxxx(recv, ...)
|
||||
replaceRhs(g, rule, env, ctx);
|
||||
// b = recv.getXxxx(...) -> recv' = getXxxx^r(recv,last(b),...)
|
||||
IProductionRule rr2 = replaceRhs(rule, env);
|
||||
IVariable b = rr2.getLeft();
|
||||
UpdatedObject nextRecv = new UpdatedObject(recv, invoke.getIR(), invoke.getInstruction());
|
||||
InvocationSymbol invoke2 = (InvocationSymbol) rr2.getRight(0);
|
||||
List params = invoke2.getParameters();
|
||||
params.add(1, new LastUpdatedObject(b));
|
||||
ISymbol func = new StringSymbol(invoke2.getFunction().getName() + "^r");
|
||||
invoke2 = new InvocationSymbol(
|
||||
invoke2.getIR(), invoke2.getInstruction(),
|
||||
func, invoke2.getReceiver(),
|
||||
params);
|
||||
rr2.setLeft(nextRecv);
|
||||
rr2.getRight().clear();
|
||||
rr2.getRight().add(invoke2);
|
||||
env.put(recv, nextRecv);
|
||||
ctx.addRule(g, rr2);
|
||||
Trace.println("-> " + rr2);
|
||||
}
|
||||
else if (setOperations.contains(funcName)) {
|
||||
// recv.setXxxx(...) -> recv' = setXxxx(recv,...)
|
||||
Trace.println(rule);
|
||||
IProductionRule rr = replaceRhs(rule, env);
|
||||
UpdatedObject nextRecv = new UpdatedObject(recv, invoke.getIR(), invoke.getInstruction());
|
||||
rr.setLeft(nextRecv);
|
||||
env.put(recv, nextRecv);
|
||||
ctx.addRule(g, rr);
|
||||
ctx.removeRule(g, rule);
|
||||
Trace.println("-> " + rr);
|
||||
}
|
||||
else {
|
||||
replaceRhs(g, rule, env, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceRhs(IGrammar g, IProductionRule rule, Map env, SolverContext ctx) {
|
||||
IProductionRule rr = replaceRhs(rule, env);
|
||||
if (!rr.equals(rule)) {
|
||||
ctx.removeRule(g, rule);
|
||||
ctx.addRule(g, rr);
|
||||
}
|
||||
}
|
||||
|
||||
private IProductionRule replaceRhs(IProductionRule rule, Map env) {
|
||||
List newRights = new ArrayList();
|
||||
IMatchContext ctx = new MatchContext(env);
|
||||
|
||||
rule = rule.copy(SimpleRuleCopier.defaultCopier);
|
||||
for (Iterator i = rule.getRight().iterator(); i.hasNext(); ) {
|
||||
ISymbol right = (ISymbol) i.next();
|
||||
right = VariableReplacer.replace(right, ctx);
|
||||
newRights.add(right);
|
||||
}
|
||||
rule.getRight().clear();
|
||||
rule.getRight().addAll(newRights);
|
||||
|
||||
return rule;
|
||||
}
|
||||
}
|
|
@ -1,345 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.repository.ITranslator;
|
||||
import com.ibm.wala.stringAnalysis.translator.repository.ITranslatorRepository;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
import com.ibm.wala.util.debug.*;
|
||||
|
||||
abstract public class SimpleConstraintSolver implements IConstraintSolver {
|
||||
ITranslatorRepository translators;
|
||||
|
||||
static protected int MAX_CYCLE = 3;
|
||||
|
||||
static public class TranslationError extends UnimplementedError {
|
||||
public TranslationError(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
static protected interface ISubstitution extends ISymbolCopier {
|
||||
Set<IProductionRule> getRules();
|
||||
}
|
||||
|
||||
static protected class Substitution extends DeepSymbolCopier {
|
||||
protected Set<IProductionRule> rules;
|
||||
|
||||
public Substitution() {
|
||||
rules = new HashSet<IProductionRule>();
|
||||
}
|
||||
|
||||
public Set<IProductionRule> getRules() {
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
|
||||
static protected class SimpleSubstitution extends Substitution implements ISubstitution {
|
||||
public SimpleSubstitution() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ISymbol copy(ISymbol s) {
|
||||
if (s instanceof IGrammarSymbol) {
|
||||
IGrammarSymbol gsym = (IGrammarSymbol) s;
|
||||
SimpleGrammar sg = (SimpleGrammar) gsym.getGrammar();
|
||||
rules.addAll(sg.toSimple().getRules());
|
||||
return gsym.getGrammar().getStartSymbol();
|
||||
}
|
||||
else {
|
||||
return super.copy(s);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection copySymbols(Collection c) {
|
||||
ArrayList<ISymbol> l = new ArrayList<ISymbol>();
|
||||
Collection<ISymbol> ss = super.copySymbols(c);
|
||||
for (ISymbol s : ss) {
|
||||
if (s instanceof StringSymbol) {
|
||||
l.addAll(((StringSymbol)s).toCharSymbols());
|
||||
}
|
||||
else {
|
||||
l.add(s);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
protected SimpleGrammar substituteGrammars(SimpleGrammar g) {
|
||||
return substituteGrammars(g, new SimpleSubstitution());
|
||||
}
|
||||
|
||||
protected SimpleGrammar substituteGrammars(SimpleGrammar g, Substitution subst) {
|
||||
SimpleGrammar g2 = (SimpleGrammar) g.copy(new DeepGrammarCopier(new DeepRuleCopier(subst)));
|
||||
g2.addRules(subst.getRules());
|
||||
return g2;
|
||||
}
|
||||
|
||||
|
||||
public SimpleConstraintSolver(ITranslatorRepository translators) {
|
||||
this.translators = translators;
|
||||
}
|
||||
|
||||
|
||||
private List splitStringSymbols(List symbols, final List newRules, final IVariableFactory varFactory) {
|
||||
List newSymbols = new ArrayList();
|
||||
for (Iterator i = symbols.iterator(); i.hasNext(); ) {
|
||||
ISymbol s = (ISymbol) i.next();
|
||||
if (s instanceof StringSymbol) {
|
||||
List chars = ((StringSymbol)s).toCharSymbols();
|
||||
IVariable v = varFactory.createVariable(Grammars.variablePrefix);
|
||||
IProductionRule r = new ProductionRule(v, chars);
|
||||
newRules.add(r);
|
||||
s = v;
|
||||
}
|
||||
newSymbols.add(s);
|
||||
}
|
||||
return newSymbols;
|
||||
}
|
||||
|
||||
private SimpleGrammar splitStringSymbols(SimpleGrammar cfg, final IVariableFactory varFactory) {
|
||||
final List newRules = new ArrayList();
|
||||
cfg.traverseRules(new IRuleVisitor(){
|
||||
public void onVisit(IProductionRule rule) {
|
||||
// IVariable var = rule.getLeft();
|
||||
List right = rule.getRight();
|
||||
if (!right.isEmpty() && (right.get(0) instanceof InvocationSymbol)) {
|
||||
InvocationSymbol invoke = (InvocationSymbol) right.get(0);
|
||||
List params = invoke.getParameters();
|
||||
List newParams = splitStringSymbols(params, newRules, varFactory);
|
||||
params.clear();
|
||||
params.addAll(newParams);
|
||||
}
|
||||
else {
|
||||
List newSymbols = splitStringSymbols(right, newRules, varFactory);
|
||||
rule.getRight().clear();
|
||||
rule.getRight().addAll(newSymbols);
|
||||
}
|
||||
}
|
||||
});
|
||||
cfg = (SimpleGrammar) cfg.copy(SimpleGrammarCopier.defaultCopier);
|
||||
cfg.getRules().addAll(newRules);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar solve(ISimplify grammar, IVariable startSymbol) {
|
||||
SimpleGrammar cfg = grammar.toSimple();
|
||||
Grammars.refreshProductionRules(cfg);
|
||||
|
||||
// TODO: refactoring
|
||||
for (Iterator i = cfg.getRules().iterator(); i.hasNext(); ) {
|
||||
IProductionRule rule = (IProductionRule) i.next();
|
||||
if (rule.getRight().size() == 1) {
|
||||
if (rule.getLeft().equals(rule.getRight(0))) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Trace.println("-- GR2CFG#translate: cfg1 =");
|
||||
Trace.println(Grammars.toRuleChain(cfg, startSymbol));
|
||||
if (startSymbol != null) {
|
||||
cfg.setStartSymbol(startSymbol);
|
||||
}
|
||||
else {
|
||||
startSymbol = cfg.getStartSymbol();
|
||||
}
|
||||
Grammars.eliminateDanglingVariables(cfg);
|
||||
Grammars.eliminateUselessRules(cfg);
|
||||
|
||||
Trace.println("-- GR2CFG#translate: cfg2 =");
|
||||
Trace.println(SAUtil.prettyFormat(cfg));
|
||||
|
||||
IVariableFactory<IVariable> varFactory = new FreshVariableFactory(SimpleVariableFactory.defaultFactory, cfg);
|
||||
cfg = splitStringSymbols(cfg, varFactory);
|
||||
return solve(cfg, varFactory, new Stack());
|
||||
}
|
||||
|
||||
|
||||
static protected class CyclicException extends Exception {
|
||||
final public List<CallEnv> cyclicCalls;
|
||||
|
||||
public CyclicException(List<CallEnv> cyclicCalls) {
|
||||
super();
|
||||
this.cyclicCalls = cyclicCalls;
|
||||
}
|
||||
}
|
||||
|
||||
protected Set<IProductionRule> cyclicRules(SimpleGrammar g, IVariable v) {
|
||||
Set<IProductionRule> rules = cyclicRules(g, v, v, new HashSet<IVariable>());
|
||||
return rules;
|
||||
}
|
||||
|
||||
protected Set<IProductionRule> cyclicRules(SimpleGrammar g, IVariable v, IVariable cur, Set<IVariable> h) {
|
||||
Set<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
if (h.contains(cur)) {
|
||||
return rules;
|
||||
}
|
||||
h.add(cur);
|
||||
for (Iterator<IProductionRule> i = g.getRules(cur).iterator(); i.hasNext(); ) {
|
||||
IProductionRule r = i.next();
|
||||
for (Iterator<ISymbol> j = r.getRight().iterator(); j.hasNext(); ) {
|
||||
ISymbol s = j.next();
|
||||
final Set<IVariable> nx = new HashSet<IVariable>();
|
||||
s.traverse(new ISymbolVisitor(){
|
||||
public void onLeave(ISymbol symbol) {
|
||||
if (symbol instanceof IVariable) {
|
||||
nx.add((IVariable)symbol);
|
||||
}
|
||||
}
|
||||
public void onVisit(ISymbol symbol) {
|
||||
}
|
||||
});
|
||||
for (Iterator<IVariable> k = nx.iterator(); k.hasNext(); ) {
|
||||
IVariable nv = k.next();
|
||||
if (nv.equals(v)) {
|
||||
rules.add(r);
|
||||
}
|
||||
else {
|
||||
rules.addAll(cyclicRules(g, v, nv, h));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
protected SimpleGrammar[] splitGrammar(SimpleGrammar cfg, IVariable start) {
|
||||
Set<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
Grammars.collectReachableRules(cfg, start, rules);
|
||||
Set<IProductionRule> others = new HashSet<IProductionRule>(cfg.getRules());
|
||||
for (Iterator<IProductionRule> i = others.iterator(); i.hasNext(); ) {
|
||||
IProductionRule prod = i.next();
|
||||
if (prod.getLeft().equals(start)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
SimpleGrammar g1 = new SimpleGrammar(start, rules);
|
||||
SimpleGrammar g2 = new SimpleGrammar(cfg.getStartSymbol(), others);
|
||||
Grammars.eliminateUselessRules(g2);
|
||||
return new SimpleGrammar[]{g1, g2};
|
||||
}
|
||||
|
||||
protected SimpleGrammar[] splitCyclicRules(SimpleGrammar g) {
|
||||
Set<IProductionRule> cyclicRules = cyclicRules(g, g.getStartSymbol());
|
||||
SimpleGrammar g1 = new SimpleGrammar(g.getStartSymbol(), g.getRules());
|
||||
g1.getRules().removeAll(cyclicRules);
|
||||
SimpleGrammar g2 = new SimpleGrammar(g.getStartSymbol(), cyclicRules);
|
||||
return new SimpleGrammar[]{g1, g2};
|
||||
}
|
||||
|
||||
public SimpleGrammar solve(SimpleGrammar g, IVariableFactory<IVariable> varFactory, Stack<CallEnv> callStack) {
|
||||
Trace.println("-- solving: g =");
|
||||
Trace.println(SAUtil.prettyFormat(g));
|
||||
|
||||
g = (SimpleGrammar) g.copy(SimpleGrammarCopier.defaultCopier);
|
||||
Grammars.eliminateUselessRules(g);
|
||||
Trace.println("-- eliminate useless rules: g =");
|
||||
Trace.println(SAUtil.prettyFormat(g));
|
||||
|
||||
IProductionRule invokeRule = null;
|
||||
InvocationSymbol invoke = null;
|
||||
for (Iterator i = g.getRules().iterator(); i.hasNext(); ) {
|
||||
IProductionRule rule = (IProductionRule) i.next();
|
||||
if (rule.getRight().size() > 0
|
||||
&& (rule.getRight(0) instanceof InvocationSymbol)) {
|
||||
invoke = (InvocationSymbol) rule.getRight(0);
|
||||
invokeRule = rule;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (invoke == null) {
|
||||
return g;
|
||||
}
|
||||
|
||||
ISymbol func = invoke.getFunction();
|
||||
if (func instanceof IVariable) {
|
||||
Trace.println("the function name should be resolved by CG2Simple: " + func);
|
||||
throw(new TranslationError("the function name should be resolved by CG2Simple: " + func));
|
||||
}
|
||||
String funcName = func.getName();
|
||||
List params = invoke.getParameters();
|
||||
ISymbol recv = invoke.getReceiver();
|
||||
ITranslator translator = translators.getTranslator(funcName);
|
||||
if (translator == null) {
|
||||
Trace.println("can't find a translator for " + funcName);
|
||||
throw(new RuntimeException("can't find a translator for " + funcName));
|
||||
}
|
||||
|
||||
SimpleGrammar g1[] = splitGrammar(g, invokeRule.getLeft());
|
||||
SimpleGrammar targetGrammar = g1[0]; // target grammar
|
||||
SimpleGrammar otherRules = g1[1]; // other rules
|
||||
|
||||
Trace.println("-- applying the translator " + funcName + " to the grammar:");
|
||||
Trace.println(SAUtil.prettyFormat(targetGrammar));
|
||||
Trace.println("-- other rules:");
|
||||
Trace.println(SAUtil.prettyFormat(otherRules));
|
||||
|
||||
SimpleGrammar g2[] = splitCyclicRules(targetGrammar);
|
||||
SimpleGrammar nonCyclicTarget = g2[0]; // grammar without cyclic rules
|
||||
SimpleGrammar cyclicRules = g2[1]; // cyclic rules
|
||||
|
||||
if (translator.acceptCyclic() || cyclicRules.getRules().isEmpty()) {
|
||||
return substituteGrammars(
|
||||
translator.solve(
|
||||
this, funcName, recv, params,
|
||||
invokeRule, targetGrammar, otherRules,
|
||||
callStack, varFactory));
|
||||
}
|
||||
else {
|
||||
Trace.println("-- extracted non cyclic grammar:");
|
||||
Trace.println(SAUtil.prettyFormat(nonCyclicTarget));
|
||||
Trace.println("-- cyclic rules:");
|
||||
Trace.println(SAUtil.prettyFormat(cyclicRules));
|
||||
|
||||
SimpleGrammar translated = solve(nonCyclicTarget, varFactory, callStack);
|
||||
Trace.println("-- translated:");
|
||||
Trace.println(SAUtil.prettyFormat(translated));
|
||||
|
||||
for (int i = 0; i < MAX_CYCLE; i++) {
|
||||
SimpleGrammar base = translator.toComparable(translated);
|
||||
Trace.println("-- base:");
|
||||
Trace.println(SAUtil.prettyFormat(base));
|
||||
|
||||
IVariable v = varFactory.createVariable(Grammars.variablePrefix);
|
||||
IMatchContext ctx = new MatchContext();
|
||||
ctx.put(targetGrammar.getStartSymbol(), v);
|
||||
SimpleGrammar cyclicGrammar = (SimpleGrammar) cyclicRules.copy(new DeepGrammarCopier(new DeepRuleCopier(new VariableReplacer(ctx))));
|
||||
SimpleGrammar base2 = (SimpleGrammar) base.copy(new DeepGrammarCopier(new DeepRuleCopier(new VariableReplacer(ctx))));
|
||||
cyclicGrammar.addRules(nonCyclicTarget.getRules());
|
||||
cyclicGrammar.addRules(base2.getRules());
|
||||
cyclicGrammar.setStartSymbol(targetGrammar.getStartSymbol());
|
||||
Trace.println("-- cyclic grammar:");
|
||||
Trace.println(SAUtil.prettyFormat(cyclicGrammar));
|
||||
|
||||
translated = solve(cyclicGrammar, varFactory, callStack);
|
||||
if (translator.isFixpoint(base, translated)) {
|
||||
Trace.println("-- found a fixpoint:");
|
||||
Trace.println(SAUtil.prettyFormat(base));
|
||||
|
||||
otherRules.addRules(base.getRules());
|
||||
SimpleGrammar g3 = solve(otherRules, varFactory, callStack);
|
||||
Trace.println("-- solved (" + funcName + "):");
|
||||
Trace.println(SAUtil.prettyFormat(g3));
|
||||
return g3;
|
||||
}
|
||||
}
|
||||
throw(new UnimplementedError());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.stringAnalysis.util.LocalNameTable;
|
||||
|
||||
public class TranslationContext {
|
||||
private IR ir;
|
||||
private CallSiteReference callSite;
|
||||
private CGNode node;
|
||||
private PropagationCallGraphBuilder cgbuilder;
|
||||
private LocalNameTable ltable;
|
||||
|
||||
public TranslationContext(IR ir, CGNode node, CallSiteReference callSite, PropagationCallGraphBuilder cgbuilder){
|
||||
this.ir = ir;
|
||||
this.node = node;
|
||||
this.callSite = callSite;
|
||||
this.cgbuilder = cgbuilder;
|
||||
this.ltable = new LocalNameTable(ir);
|
||||
}
|
||||
|
||||
public TranslationContext(TranslationContext ctx) {
|
||||
this(ctx.getIR(), ctx.getCGNode(), ctx.getCallSiteReference(), ctx.getCGBuilder());
|
||||
}
|
||||
|
||||
public IR getIR(){
|
||||
return this.ir;
|
||||
}
|
||||
|
||||
public CGNode getCGNode(){
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public int getInstructionIndex(SSAInstruction instruction) {
|
||||
SSAInstruction instructions[] = ir.getInstructions();
|
||||
for (int i = 0; i < instructions.length; i++) {
|
||||
if (instruction.equals(instructions[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public CallSiteReference getCallSiteReference() {
|
||||
return this.callSite;
|
||||
}
|
||||
|
||||
public PropagationCallGraphBuilder getCGBuilder(){
|
||||
return this.cgbuilder;
|
||||
}
|
||||
|
||||
public LocalNameTable getLocalNameTable() {
|
||||
return this.ltable;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.regex.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
public class VariableDefiner extends RuleAdder {
|
||||
static private StringPatternCompiler compiler = new StringPatternCompiler();
|
||||
|
||||
public VariableDefiner(ISimplify cfg, IVariable v, IPattern pat) {
|
||||
this(cfg, new IVariable[]{v}, new IPattern[]{pat});
|
||||
}
|
||||
|
||||
public VariableDefiner(ISimplify cfg, Map<IVariable,IPattern> defs) {
|
||||
this(cfg.toSimple(), defs);
|
||||
}
|
||||
|
||||
public VariableDefiner(ISimplify cfg, IVariable v[], IPattern pat[]) {
|
||||
this(cfg.toSimple(), SAUtil.map(v, pat));
|
||||
}
|
||||
|
||||
private VariableDefiner(SimpleGrammar g, Map<IVariable,IPattern> defs) {
|
||||
super(g, createRules(g, defs));
|
||||
}
|
||||
|
||||
static private Set<IProductionRule> createRules(IGrammar g, Map<IVariable, IPattern> defs) {
|
||||
Set<IProductionRule> rules = new HashSet<IProductionRule>();
|
||||
for (IVariable v : defs.keySet()) {
|
||||
IPattern pat = defs.get(v);
|
||||
IAutomaton fst = compiler.compile(pat);
|
||||
Automatons.eliminateEpsilonTransitions(fst);
|
||||
IContextFreeGrammar cfg = Grammars.toCFG(fst);
|
||||
Map m = new HashMap();
|
||||
Grammars.useUniqueVariables(cfg, g, m);
|
||||
IMatchContext ctx = new MatchContext();
|
||||
ctx.put(cfg.getStartSymbol(), v);
|
||||
cfg = (IContextFreeGrammar) cfg.copy(new DeepGrammarCopier(new DeepRuleCopier(new VariableReplacer(ctx))));
|
||||
rules.addAll(cfg.getRules());
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,177 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Addcslashes extends Transducer {
|
||||
|
||||
private int charlistVarIndex;
|
||||
|
||||
private CharSymbol[] charSyms;
|
||||
|
||||
private final CharSymbol backslashe = new CharSymbol("\\");
|
||||
|
||||
// private final CharSymbol[] octChars = (CharSymbol[]) new StringSymbol(
|
||||
// "01234567").toCharSymbols().toArray(new CharSymbol[0]);
|
||||
|
||||
public Addcslashes(int target, int charlist) {
|
||||
super(target);
|
||||
this.charlistVarIndex = charlist;
|
||||
}
|
||||
|
||||
public Addcslashes(int charlist) {
|
||||
this.charlistVarIndex = charlist;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set<ITransition> transitions = new HashSet<ITransition>();
|
||||
IState s0 = new State("s0");
|
||||
IState s1 = new State("s1");
|
||||
IState initState = s0;
|
||||
Set<IState> finalStates = new HashSet<IState>();
|
||||
finalStates.add(s0);
|
||||
finalStates.add(s1);
|
||||
|
||||
charSyms = getCharSymbols();
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] {
|
||||
backslashe, v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
CharSymbol charSym = (CharSymbol) symbol;
|
||||
int charVal = charSym.charValue();
|
||||
if (126 < charVal || charVal < 32) {
|
||||
DecimalFormat df = new DecimalFormat("000");
|
||||
List octalStringSym = new StringSymbol(df.format(Double
|
||||
.parseDouble(Integer.toOctalString(charVal)))).toCharSymbols();
|
||||
octalStringSym.add(0, backslashe);
|
||||
return octalStringSym;
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = containsCharSymbols(symbol, charSyms);
|
||||
if (r)
|
||||
System.err.println("(containsCharSymbols(symbol, charSyms) " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !containsCharSymbols(symbol, charSyms);
|
||||
if (r)
|
||||
System.err.println("(!containsCharSymbols(symbol, charSyms) "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
protected boolean containsCharSymbols(ISymbol symbol, CharSymbol[] charSyms) {
|
||||
for (int i = 0; i < charSyms.length; i++) {
|
||||
if (symbol.equals(charSyms[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private CharSymbol[] getCharSymbols() {
|
||||
Variable charlistVar = (Variable) params.get(charlistVarIndex);
|
||||
List<CharSymbol> charlist = new ArrayList<CharSymbol>();
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(charlistVar)) {
|
||||
charlist = rule.getRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
String str = list2Str(charlist);
|
||||
int doubleDotIndex = str.indexOf("..");
|
||||
if (doubleDotIndex > 0) {
|
||||
List<CharSymbol> charlist2 = new ArrayList<CharSymbol>();
|
||||
do {
|
||||
for (int i = 0; i < doubleDotIndex - 1; i++) {
|
||||
charlist2.add((CharSymbol) charlist.get(i));
|
||||
}
|
||||
char startChar = str.charAt(doubleDotIndex - 1);
|
||||
char endChar = str.charAt(doubleDotIndex + 2);
|
||||
if (startChar > endChar) {
|
||||
charlist2.add(new CharSymbol((char) startChar));
|
||||
charlist2.add(new CharSymbol("."));
|
||||
}
|
||||
else {
|
||||
int charSymsLen = endChar - startChar + 1;
|
||||
for (int i = 0; i < charSymsLen; i++) {
|
||||
charlist2.add(new CharSymbol((char) (startChar + i)));
|
||||
}
|
||||
if ((startChar <= 'Z') && (endChar >= 'a')) {
|
||||
charlist2.add(new CharSymbol("\t"));
|
||||
charlist2.add(new CharSymbol("\n"));
|
||||
charlist2.add(new CharSymbol("\r"));
|
||||
}
|
||||
}
|
||||
doubleDotIndex += 3;
|
||||
if (str.length() > doubleDotIndex) {
|
||||
str = str.substring(doubleDotIndex);
|
||||
charlist = charlist.subList(doubleDotIndex, charlist.size());
|
||||
doubleDotIndex = str.indexOf("..");
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
} while (doubleDotIndex > 0);
|
||||
charlist.addAll(charlist2);
|
||||
}
|
||||
CharSymbol[] charSyms = (CharSymbol[]) charlist.toArray(new CharSymbol[0]);
|
||||
return charSyms;
|
||||
}
|
||||
|
||||
private String list2Str(List charlist) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Iterator charlistIte = charlist.iterator();
|
||||
while (charlistIte.hasNext()) {
|
||||
CharSymbol chr = (CharSymbol) charlistIte.next();
|
||||
sb.append(chr.charValue());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Addslashes extends Transducer {
|
||||
|
||||
public Addslashes(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Addslashes() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
final List quoteChars = new StringSymbol("'\"\\").toCharSymbols();
|
||||
|
||||
Set<ITransition> transitions = new HashSet<ITransition>();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set<IState> finalStates = new HashSet<IState>();
|
||||
finalStates.add(s0);
|
||||
|
||||
CharSymbol backSlash = new CharSymbol("\\");
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] {
|
||||
backSlash, v }, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = containsQuoteStr(symbol, quoteChars);
|
||||
if (r)
|
||||
System.err.println("(containsQuoteStr(symbol, quoteChars): accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !containsQuoteStr(symbol, quoteChars);
|
||||
if (r)
|
||||
System.err.println("(!containsQuoteStr(symbol, quoteChars): accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
protected boolean containsQuoteStr(ISymbol symbol, List quoteChars) {
|
||||
Iterator quoteIte = quoteChars.iterator();
|
||||
while (quoteIte.hasNext()) {
|
||||
CharSymbol quoteChar = (CharSymbol) quoteIte.next();
|
||||
if (symbol.equals(quoteChar)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public abstract class BasicTranslator implements ITranslator, Cloneable {
|
||||
static protected int TARGET_RECV = -1;
|
||||
static protected int TARGET_ALL = -2;
|
||||
|
||||
protected int target;
|
||||
|
||||
protected String funcName;
|
||||
|
||||
protected ISymbol recv;
|
||||
|
||||
protected List params;
|
||||
|
||||
protected IProductionRule rule;
|
||||
|
||||
protected IVariableFactory varFactory;
|
||||
|
||||
protected SimpleGrammar grammar;
|
||||
|
||||
protected IConstraintSolver translator;
|
||||
|
||||
public BasicTranslator() {
|
||||
this.target = -1;
|
||||
}
|
||||
|
||||
public BasicTranslator(int target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public SimpleGrammar solve(final IConstraintSolver solver,
|
||||
final String funcName,
|
||||
final ISymbol recv,
|
||||
final List params,
|
||||
IProductionRule invokeRule,
|
||||
SimpleGrammar targetGrammar,
|
||||
SimpleGrammar otherRules,
|
||||
Stack<CallEnv> callStack,
|
||||
IVariableFactory varFactory) {
|
||||
SimpleGrammar pre = prepare(solver, funcName, recv, params, invokeRule, targetGrammar, varFactory);
|
||||
Trace.println("-- prepared grammar for " + funcName + ":");
|
||||
Trace.println(SAUtil.prettyFormat(pre));
|
||||
if (!pre.getStartSymbol().equals(targetGrammar.getStartSymbol())) {
|
||||
IProductionRule r = new ProductionRule(targetGrammar.getStartSymbol(), pre.getStartSymbol());
|
||||
otherRules.addRule(r);
|
||||
}
|
||||
|
||||
SimpleGrammar target = solver.solve(pre, varFactory, callStack);
|
||||
Trace.println("-- target grammar without function applications:");
|
||||
Trace.println(SAUtil.prettyFormat(target));
|
||||
assert(target.getStartSymbol().equals(pre.getStartSymbol()));
|
||||
|
||||
SimpleGrammar translatedGrammar = translate(target);
|
||||
if (!translatedGrammar.getStartSymbol().equals(target.getStartSymbol())) {
|
||||
IProductionRule r = new ProductionRule(target.getStartSymbol(), translatedGrammar.getStartSymbol());
|
||||
otherRules.addRule(r);
|
||||
}
|
||||
// TODO: should fix.
|
||||
//translatedGrammar = substituteGrammars(translatedGrammar);
|
||||
|
||||
Trace.println("-- grammar translated by " + funcName + ":");
|
||||
Trace.println(SAUtil.prettyFormat(translatedGrammar));
|
||||
|
||||
otherRules.addRules(translatedGrammar.getRules());
|
||||
SimpleGrammar g3 = solver.solve(otherRules, varFactory, callStack);
|
||||
Grammars.eliminateUselessRules(g3);
|
||||
Trace.println("-- solved (" + funcName + "):");
|
||||
Trace.println(SAUtil.prettyFormat(g3));
|
||||
|
||||
return g3;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(final IConstraintSolver translator,
|
||||
final String funcName, final ISymbol recv,
|
||||
final List params, IProductionRule rule,
|
||||
SimpleGrammar grammar,
|
||||
IVariableFactory varFactory) {
|
||||
this.funcName = funcName;
|
||||
this.recv = recv;
|
||||
this.params = params;
|
||||
this.rule = rule;
|
||||
this.varFactory = varFactory;
|
||||
this.translator = translator;
|
||||
this.grammar = grammar;
|
||||
SimpleGrammar g2 = (SimpleGrammar) grammar.copy(SimpleGrammarCopier.defaultCopier);
|
||||
if (target >= 0) {
|
||||
setStartSymbol(g2, (ISymbol) params.get(target), varFactory);
|
||||
}
|
||||
else if (target == TARGET_RECV){
|
||||
setStartSymbol(g2, recv, varFactory);
|
||||
}
|
||||
else if (target == TARGET_ALL) {
|
||||
setStartSymbol(g2, rule.getLeft(), varFactory);
|
||||
}
|
||||
else {
|
||||
throw(new RuntimeException("unsupported target"));
|
||||
}
|
||||
return g2;
|
||||
}
|
||||
|
||||
abstract public SimpleGrammar translate(SimpleGrammar g);
|
||||
|
||||
|
||||
public ITranslator copy() {
|
||||
return (ITranslator) clone();
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
throw (new RuntimeException(e));
|
||||
}
|
||||
}
|
||||
|
||||
protected void setStartSymbol(SimpleGrammar cfg, ISymbol symbol, IVariableFactory varFactory) {
|
||||
if (symbol instanceof IVariable) {
|
||||
cfg.setStartSymbol((IVariable) symbol);
|
||||
}
|
||||
else {
|
||||
IVariable v = varFactory.createVariable(Grammars.variablePrefix);
|
||||
if (symbol instanceof StringSymbol) {
|
||||
StringSymbol ss = (StringSymbol) symbol;
|
||||
cfg.addRule(new ProductionRule(v, ss.toCharSymbols()));
|
||||
}
|
||||
else {
|
||||
cfg.addRule(new ProductionRule(v, symbol));
|
||||
}
|
||||
cfg.setStartSymbol(v);
|
||||
}
|
||||
}
|
||||
|
||||
protected IVariable createVariable() {
|
||||
return varFactory.createVariable(Grammars.variablePrefix);
|
||||
}
|
||||
|
||||
static public interface IParamConv {
|
||||
ISymbol convert(SimpleGrammar g);
|
||||
ISymbol convert(IValueSymbol s);
|
||||
}
|
||||
|
||||
static public class StringParamConv implements IParamConv {
|
||||
private Set<String> vals = new HashSet<String>();
|
||||
public ISymbol convert(SimpleGrammar sg) {
|
||||
IContextFreeGrammar cfg = new ContextFreeGrammar(sg);
|
||||
Set strs = Grammars.stringValues(cfg, sg.getStartSymbol());
|
||||
if (strs == null) {
|
||||
CFGSymbol cfgSym = new CFGSymbol(cfg);
|
||||
return cfgSym;
|
||||
}
|
||||
else {
|
||||
vals.addAll(strs);
|
||||
if (strs.size() == 1) {
|
||||
String str = (String) strs.iterator().next();
|
||||
StringSymbol ss = new StringSymbol(str);
|
||||
return ss;
|
||||
}
|
||||
else {
|
||||
CFGSymbol cfgSym = new CFGSymbol(cfg);
|
||||
return cfgSym;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ISymbol convert(IValueSymbol s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
public Set<String> getValues() {
|
||||
return vals;
|
||||
}
|
||||
}
|
||||
|
||||
protected ISymbol solveParameter(int n, IParamConv conv) {
|
||||
ISymbol s = (ISymbol) params.get(n);
|
||||
Trace.println("solveParameter( " + n + " -> " + s);
|
||||
if (s instanceof IVariable) {
|
||||
SimpleGrammar g = new SimpleGrammar(grammar);
|
||||
SimpleGrammar sg = translator.solve(g, (IVariable) s);
|
||||
Grammars.eliminateUselessRules(sg);
|
||||
return conv.convert(sg);
|
||||
}
|
||||
else if (s instanceof IValueSymbol) {
|
||||
return conv.convert((IValueSymbol)s);
|
||||
}
|
||||
else {
|
||||
throw (new RuntimeException("unexpected parameter symbol: " + s));
|
||||
}
|
||||
}
|
||||
|
||||
protected ISymbol solveParameter(int n) {
|
||||
return solveParameter(n, new StringParamConv());
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Bin2hex extends StringTranslator {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar cfg,
|
||||
IVariableFactory varFactory) {
|
||||
super.prepare(translator, funcName, recv, params, rule, cfg, varFactory);
|
||||
IVariable S = cfg.getStartSymbol();
|
||||
IVariable AN = varFactory.createVariable("AN");
|
||||
ContextFreeGrammar newCfg = new ContextFreeGrammar(S,
|
||||
new IProductionRule[] { new ProductionRule(S, new ISymbol[] { AN }),
|
||||
new ProductionRule(S, new ISymbol[] { AN, S }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("0") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("1") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("2") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("3") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("4") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("5") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("6") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("7") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("8") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("9") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("a") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("b") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("c") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("d") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("e") }),
|
||||
new ProductionRule(AN, new ISymbol[] { new CharSymbol("f") }) });
|
||||
return newCfg;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class CharAt extends Transducer {
|
||||
private int paramIndex;
|
||||
|
||||
public CharAt(int target, int paramIndex) {
|
||||
super(target);
|
||||
this.paramIndex = paramIndex;
|
||||
}
|
||||
|
||||
public CharAt(int paramIndex) {
|
||||
super();
|
||||
this.paramIndex = paramIndex;
|
||||
}
|
||||
|
||||
public CharAt() {
|
||||
this(1);
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
ISymbol s = (ISymbol) params.get(paramIndex);
|
||||
if (s instanceof NumberSymbol) {
|
||||
NumberSymbol ns = (NumberSymbol) s;
|
||||
int idx = ns.intValue();
|
||||
IState initState = new State("s0");
|
||||
IState curState = initState;
|
||||
Set finalStates = new HashSet();
|
||||
Set transitions = new HashSet();
|
||||
int i;
|
||||
IState nextState = null;
|
||||
ITransition t = null;
|
||||
for (i = 0; i < idx; i++) {
|
||||
nextState = new State("s" + (i + 1));
|
||||
t = new Transition(curState, nextState, new Variable("c"));
|
||||
transitions.add(t);
|
||||
curState = nextState;
|
||||
}
|
||||
nextState = new State("s" + (i + 1));
|
||||
t = new Transition(curState, nextState, new Variable("c"),
|
||||
new ISymbol[] { new Variable("c") });
|
||||
transitions.add(t);
|
||||
t = new Transition(nextState, nextState, new Variable("c"));
|
||||
transitions.add(t);
|
||||
finalStates.add(nextState);
|
||||
|
||||
IAutomaton a = new Automaton(initState, finalStates, transitions);
|
||||
return a;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
|
||||
public abstract class CharTranslator extends Homomorphism {
|
||||
public CharTranslator(int n) {
|
||||
super(n);
|
||||
}
|
||||
|
||||
public CharTranslator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Set<Rule> getRuleSet() {
|
||||
Rule r = new Rule() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
assert (symbol instanceof CharSymbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
assert (symbol instanceof CharSymbol);
|
||||
CharSymbol csym = (CharSymbol) symbol;
|
||||
char cs[] = translate(csym.charValue());
|
||||
String s = new String(cs);
|
||||
return StringSymbol.toCharSymbols(s);
|
||||
}
|
||||
};
|
||||
Set<Rule> rs = new HashSet<Rule>();
|
||||
rs.add(r);
|
||||
return rs;
|
||||
}
|
||||
|
||||
protected abstract char[] translate(char c);
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Chr extends Transducer {
|
||||
|
||||
public Chr(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Chr() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set<ITransition> transitions = new HashSet<ITransition>();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set<IState> finalStates = new HashSet<IState>();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = null;
|
||||
if (symbol instanceof NumberSymbol) {
|
||||
try {
|
||||
newOutputs = generateAsciiCharacter(((NumberSymbol) symbol)
|
||||
.intValue());
|
||||
}
|
||||
catch (AsciiOutOfBoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return newOutputs;
|
||||
}
|
||||
}, null);
|
||||
transitions.add(t);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
protected List generateAsciiCharacter(int argInt)
|
||||
throws AsciiOutOfBoundException {
|
||||
Charset asciiCharset = Charset.forName("US-ASCII");
|
||||
CharsetDecoder decoder = asciiCharset.newDecoder();
|
||||
if (!(0 <= argInt && argInt <= 127)) {
|
||||
throw new AsciiOutOfBoundException(argInt);
|
||||
}
|
||||
byte b1 = (byte) argInt;
|
||||
byte[] b = { b1 };
|
||||
ByteBuffer asciiBytes = ByteBuffer.wrap(b);
|
||||
CharBuffer cBuf = null;
|
||||
try {
|
||||
cBuf = decoder.decode(asciiBytes);
|
||||
}
|
||||
catch (CharacterCodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(cBuf.toString());
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected class AsciiOutOfBoundException extends Exception {
|
||||
public AsciiOutOfBoundException(int i) {
|
||||
super("AsciiOutOfBoundException");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Chunksplit extends Transducer {
|
||||
|
||||
private int chunkLenNumIndex;
|
||||
|
||||
private int endStrIndex;
|
||||
|
||||
public Chunksplit(int target, int len, int end) {
|
||||
super(target);
|
||||
this.chunkLenNumIndex = len;
|
||||
this.endStrIndex = end;
|
||||
}
|
||||
|
||||
public Chunksplit(int len, int end) {
|
||||
this.chunkLenNumIndex = len;
|
||||
this.endStrIndex = end;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
// int chunkLen = 76;
|
||||
List endStrList = new StringSymbol("\r\n").toCharSymbols();
|
||||
|
||||
if (params.size() > chunkLenNumIndex) {
|
||||
// NumberSymbol chunkLenNum = (NumberSymbol) params.get(chunkLenNumIndex);
|
||||
// chunkLen = chunkLenNum.intValue();
|
||||
}
|
||||
if (params.size() > endStrIndex) {
|
||||
Variable endStrVar = (Variable) params.get(endStrIndex);
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(endStrVar)) {
|
||||
endStrList = rule.getRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final CharSymbol[] endStrChars = (CharSymbol[]) endStrList
|
||||
.toArray(new CharSymbol[0]);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t0 = new Transition(s0, s0, v, new ISymbol[] { v });
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List resultOutputs = new ArrayList();
|
||||
resultOutputs.add(symbol);
|
||||
for (int i = 0; i < endStrChars.length; i++) {
|
||||
resultOutputs.add(endStrChars[i]);
|
||||
}
|
||||
return resultOutputs;
|
||||
}
|
||||
}, null);
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Concatenate extends StringTranslator {
|
||||
private IntRange ranges[];
|
||||
|
||||
public Concatenate(IntRange ranges[]) {
|
||||
super(TARGET_ALL);
|
||||
this.ranges = ranges;
|
||||
}
|
||||
|
||||
public Concatenate() {
|
||||
this(new IntRange[] { new IntRange(0, -1) });
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar g,
|
||||
IVariableFactory varFactory) {
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params,
|
||||
rule, g, varFactory);
|
||||
List l = new ArrayList();
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
for (Iterator r = ranges[i].iteratorFor(params); r.hasNext();) {
|
||||
ISymbol s = (ISymbol) r.next();
|
||||
l.add(s);
|
||||
}
|
||||
}
|
||||
IProductionRule newRule = new ProductionRule(rule.getLeft(), l);
|
||||
g2.getRules().remove(rule);
|
||||
g2.getRules().add(newRule);
|
||||
return g2;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Explode extends Transducer {
|
||||
|
||||
private int delimiterVarIndex;
|
||||
|
||||
public Explode(int target, int delimiter) {
|
||||
super(target);
|
||||
this.delimiterVarIndex = delimiter;
|
||||
}
|
||||
|
||||
public Explode(int delimiter) {
|
||||
super();
|
||||
this.delimiterVarIndex = delimiter;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Variable delimiterVar = (Variable) params.get(delimiterVarIndex);
|
||||
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List delimiterList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(delimiterVar)) {
|
||||
delimiterList = rule.getRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// final CharSymbol delimiter = new CharSymbol(" ");
|
||||
final CharSymbol[] delimiter = (CharSymbol[]) delimiterList
|
||||
.toArray(new CharSymbol[0]);
|
||||
final CharSymbol firstSubDelimiter = delimiter[0];
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState s1 = new State("s1");
|
||||
IState s2 = new State("s2");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s1);
|
||||
finalStates.add(s2);
|
||||
|
||||
ITransition t0 = new Transition(s0, s1, Transition.EpsilonSymbol);
|
||||
ITransition t1 = new Transition(s0, s2, Transition.EpsilonSymbol);
|
||||
transitions.add(t0);
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new FilteredTransition(s1, s1, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(firstSubDelimiter);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition1: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
ITransition t3 = new FilteredTransition(s2, s2, v, new ISymbol[] {}, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(firstSubDelimiter);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition2: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t2);
|
||||
transitions.add(t3);
|
||||
|
||||
final int delimiterLen = delimiter.length;
|
||||
int stateIndex = 3;
|
||||
IState state1 = s1;
|
||||
IState state2 = s2;
|
||||
final IState startState1 = s1;
|
||||
final IState startState2 = s2;
|
||||
|
||||
for (int i = 0; i < delimiterLen - 1; i++) {
|
||||
final IState firstDelimiterState1 = new State("s3");
|
||||
final IState firstDelimiterState2 = new State("s4");
|
||||
final int index = i;
|
||||
|
||||
IState nextState = new State("s" + stateIndex);
|
||||
if (index == 0) {
|
||||
nextState = firstDelimiterState1;
|
||||
}
|
||||
transitions = generateTransition(transitions, state1, nextState,
|
||||
startState1, firstDelimiterState1, delimiter, index, false);
|
||||
state1 = nextState;
|
||||
finalStates.add(state1);
|
||||
stateIndex++;
|
||||
nextState = new State("s" + stateIndex);
|
||||
if (index == 0) {
|
||||
nextState = firstDelimiterState2;
|
||||
}
|
||||
transitions = generateTransition(transitions, state2, nextState,
|
||||
startState2, firstDelimiterState2, delimiter, index, true);
|
||||
state2 = nextState;
|
||||
finalStates.add(state1);
|
||||
stateIndex++;
|
||||
}
|
||||
|
||||
IState nextState = new State("s" + stateIndex);
|
||||
final CharSymbol subDelimiter = delimiter[delimiterLen - 1];
|
||||
transitions = generateNextTransition(transitions, state1, nextState,
|
||||
subDelimiter);
|
||||
state1 = nextState;
|
||||
ITransition t4 = new Transition(state1, state1, v, new ISymbol[] {});
|
||||
stateIndex++;
|
||||
finalStates.add(state1);
|
||||
nextState = new State("s" + stateIndex);
|
||||
transitions = generateNextTransition(transitions, state2, nextState,
|
||||
subDelimiter);
|
||||
state2 = nextState;
|
||||
ITransition t5 = new Transition(state2, s0, Transition.EpsilonSymbol);
|
||||
finalStates.add(state2);
|
||||
transitions.add(t4);
|
||||
transitions.add(t5);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
private Set generateTransition(Set transitions, IState state,
|
||||
IState nextState, IState startState,
|
||||
IState firstDelimiterState,
|
||||
final CharSymbol[] delimiter, final int index,
|
||||
final boolean isEpsilonState) {
|
||||
final CharSymbol firstSubDelimiter = delimiter[0];
|
||||
final CharSymbol subDelimiter = delimiter[index];
|
||||
final CharSymbol nextSubDelimiter = delimiter[index + 1];
|
||||
|
||||
Variable v = new Variable("v");
|
||||
|
||||
transitions = generateNextTransition(transitions, state, nextState,
|
||||
subDelimiter);
|
||||
|
||||
ITransition ta = new FilteredTransition(nextState, startState, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = new ArrayList();
|
||||
if (!isEpsilonState) {
|
||||
for (int j = 0; j < index + 1; j++) {
|
||||
newOutputs.add(delimiter[j]);
|
||||
}
|
||||
newOutputs.add(symbol);
|
||||
}
|
||||
return newOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!symbol.equals(nextSubDelimiter))
|
||||
&& (!symbol.equals(firstSubDelimiter));
|
||||
if (r)
|
||||
System.err.println("(in filtered transition3: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
ITransition tb = new FilteredTransition(nextState, firstDelimiterState, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = new ArrayList();
|
||||
if (!isEpsilonState) {
|
||||
for (int j = 0; j < index + 1; j++) {
|
||||
newOutputs.add(delimiter[j]);
|
||||
}
|
||||
}
|
||||
return newOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!symbol.equals(nextSubDelimiter))
|
||||
&& symbol.equals(firstSubDelimiter);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition4: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(tb);
|
||||
return transitions;
|
||||
}
|
||||
|
||||
private Set generateNextTransition(Set transitions, IState state,
|
||||
IState nextState,
|
||||
final CharSymbol subDelimiter) {
|
||||
Variable v = new Variable("v");
|
||||
ITransition t = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(subDelimiter);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition5: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t);
|
||||
return transitions;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
abstract public class Homomorphism extends Transducer {
|
||||
static protected interface Rule
|
||||
extends FilteredTransition.IFilter, FilteredTransition.ICondition {
|
||||
}
|
||||
|
||||
public Homomorphism(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Homomorphism() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
IState s = new State("s0");
|
||||
IVariable x = new Variable("x");
|
||||
Set<IState> finalStates = new HashSet<IState>();
|
||||
finalStates.add(s);
|
||||
Set<ITransition> transitions = new HashSet<ITransition>();
|
||||
for (Homomorphism.Rule r : getRuleSet()) {
|
||||
ITransition t = new FilteredTransition(s, s, x, new ISymbol[] { x }, r,
|
||||
r);
|
||||
transitions.add(t);
|
||||
}
|
||||
IAutomaton fst = new Automaton(s, finalStates, transitions);
|
||||
return fst;
|
||||
}
|
||||
|
||||
abstract protected Set<Homomorphism.Rule> getRuleSet();
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Htmlspecialchars extends Transducer {
|
||||
|
||||
private int quoteStyIndex;
|
||||
|
||||
public Htmlspecialchars(int target, int quote) {
|
||||
super(target);
|
||||
this.quoteStyIndex = quote;
|
||||
}
|
||||
|
||||
public Htmlspecialchars(int quote) {
|
||||
super();
|
||||
this.quoteStyIndex = quote;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
final ISymbol ampersandChar = new CharSymbol('&');
|
||||
final ISymbol lessThanChar = new CharSymbol('<');
|
||||
final ISymbol greaterThanChar = new CharSymbol('>');
|
||||
final ISymbol doubleQuoteChar = new CharSymbol('\"');
|
||||
final ISymbol singleQuoteChar = new CharSymbol('\'');
|
||||
|
||||
String quoteType = "";
|
||||
if (params.size() > quoteStyIndex) {
|
||||
Variable quoteStyVar = (Variable) params.get(quoteStyIndex);
|
||||
List quoteStyList = new ArrayList();
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule varRule = (ProductionRule) rulesIte.next();
|
||||
if (varRule.getLeft().equals(quoteStyVar)) {
|
||||
quoteStyList = varRule.getRight();
|
||||
}
|
||||
}
|
||||
Iterator quoteStyIte = quoteStyList.iterator();
|
||||
while (quoteStyIte.hasNext()) {
|
||||
CharSymbol c = (CharSymbol) quoteStyIte.next();
|
||||
quoteType += c.charValue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
quoteType = "ENT_COMPAT";
|
||||
}
|
||||
final String finalQuoteType = quoteType;
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
// List resultOutputs = new ArrayList();
|
||||
CharSymbol c = (CharSymbol) outputs.get(0);
|
||||
if (c.equals(ampersandChar)) {
|
||||
return new StringSymbol("&").toCharSymbols();
|
||||
}
|
||||
if (c.equals(lessThanChar)) {
|
||||
return new StringSymbol("<").toCharSymbols();
|
||||
}
|
||||
if (c.equals(greaterThanChar)) {
|
||||
return new StringSymbol(">").toCharSymbols();
|
||||
}
|
||||
if (c.equals(doubleQuoteChar)
|
||||
&& (finalQuoteType.equals("ENT_QUOTES") || finalQuoteType
|
||||
.equals("ENT_COMPAT"))) {
|
||||
return new StringSymbol(""").toCharSymbols();
|
||||
}
|
||||
if (c.equals(singleQuoteChar)
|
||||
&& finalQuoteType.equals("ENT_QUOTES")) {
|
||||
return new StringSymbol("'").toCharSymbols();
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
}, null);
|
||||
transitions.add(t0);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class HtmlspecialcharsDecode extends Transducer {
|
||||
|
||||
private int quoteStyIndex;
|
||||
|
||||
public HtmlspecialcharsDecode(int target, int quote) {
|
||||
super(target);
|
||||
this.quoteStyIndex = quote;
|
||||
}
|
||||
|
||||
public HtmlspecialcharsDecode(int quote) {
|
||||
super();
|
||||
this.quoteStyIndex = quote;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
final ISymbol ampersandChar = new CharSymbol('&');
|
||||
CharSymbol[] ampersandChars = (CharSymbol[]) new StringSymbol("&&")
|
||||
.toCharSymbols().toArray(new CharSymbol[0]);
|
||||
CharSymbol[] lessThanChars = (CharSymbol[]) new StringSymbol("<<")
|
||||
.toCharSymbols().toArray(new CharSymbol[0]);
|
||||
CharSymbol[] greaterThanChars = (CharSymbol[]) new StringSymbol(">>")
|
||||
.toCharSymbols().toArray(new CharSymbol[0]);
|
||||
CharSymbol[] doubleQuoteChars = (CharSymbol[]) new StringSymbol(
|
||||
"\""").toCharSymbols().toArray(new CharSymbol[0]);
|
||||
CharSymbol[] singleQuoteChars = (CharSymbol[]) new StringSymbol(
|
||||
"\''").toCharSymbols().toArray(new CharSymbol[0]);
|
||||
|
||||
String quoteType = "";
|
||||
if (params.size() > quoteStyIndex) {
|
||||
Variable quoteStyVar = (Variable) params.get(quoteStyIndex);
|
||||
List quoteStyList = new ArrayList();
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule varRule = (ProductionRule) rulesIte.next();
|
||||
if (varRule.getLeft().equals(quoteStyVar)) {
|
||||
quoteStyList = varRule.getRight();
|
||||
}
|
||||
}
|
||||
Iterator quoteStyIte = quoteStyList.iterator();
|
||||
while (quoteStyIte.hasNext()) {
|
||||
CharSymbol c = (CharSymbol) quoteStyIte.next();
|
||||
quoteType += c.charValue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
quoteType = "ENT_COMPAT";
|
||||
}
|
||||
|
||||
List charSymbolArrayList = new ArrayList();
|
||||
charSymbolArrayList.add(ampersandChars);
|
||||
charSymbolArrayList.add(lessThanChars);
|
||||
charSymbolArrayList.add(greaterThanChars);
|
||||
if (quoteType.equals("ENT_COMPAT")) {
|
||||
charSymbolArrayList.add(doubleQuoteChars);
|
||||
}
|
||||
if (quoteType.equals("ENT_QUOTES")) {
|
||||
charSymbolArrayList.add(doubleQuoteChars);
|
||||
charSymbolArrayList.add(singleQuoteChars);
|
||||
}
|
||||
final CharSymbol[] secondChars = getSecondChars(charSymbolArrayList);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
IState s1 = new State("s1");
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
finalStates.add(s1);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(ampersandChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s1, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(ampersandChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new FilteredTransition(s1, s0, v, new ISymbol[] {
|
||||
ampersandChar, v }, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !containsChar(symbol, secondChars);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t2);
|
||||
IState state = s1;
|
||||
IState nextState = s1;
|
||||
int i = 1;
|
||||
Iterator charSymIte = charSymbolArrayList.iterator();
|
||||
while (charSymIte.hasNext()) {
|
||||
final CharSymbol[] charSym = (CharSymbol[]) charSymIte.next();
|
||||
for (int j = 2; j < charSym.length; j++) {
|
||||
final CharSymbol finalChar = charSym[j];
|
||||
final int index = j;
|
||||
if (index == 2) {
|
||||
state = s1;
|
||||
}
|
||||
if (index > 2) {
|
||||
ITransition tb = new FilteredTransition(state, s0, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
return generateNewOutputs(symbol, charSym, index);
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(finalChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(tb);
|
||||
}
|
||||
if (index < charSym.length - 1) {
|
||||
nextState = new State("s" + (i + 1));
|
||||
ITransition ta = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(finalChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
i++;
|
||||
}
|
||||
if (index == charSym.length - 1) {
|
||||
ITransition ta = new FilteredTransition(state, s0, v,
|
||||
new ISymbol[] { charSym[0] }, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(finalChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
}
|
||||
}
|
||||
}
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
private CharSymbol[] getSecondChars(List charSymbolArrayList) {
|
||||
CharSymbol[] secondChars = new CharSymbol[charSymbolArrayList.size()];
|
||||
Iterator charSymIte = charSymbolArrayList.iterator();
|
||||
int index = 0;
|
||||
while (charSymIte.hasNext()) {
|
||||
CharSymbol[] sym = (CharSymbol[]) charSymIte.next();
|
||||
secondChars[index] = sym[2];
|
||||
index++;
|
||||
}
|
||||
return secondChars;
|
||||
}
|
||||
|
||||
protected List generateNewOutputs(ISymbol symbol, CharSymbol[] charSym,
|
||||
int index) {
|
||||
List newOutputs = new ArrayList();
|
||||
for (int i = 1; i < index; i++) {
|
||||
newOutputs.add(charSym[i]);
|
||||
}
|
||||
newOutputs.add(symbol);
|
||||
return newOutputs;
|
||||
}
|
||||
|
||||
protected boolean containsChar(ISymbol symbol, CharSymbol[] chars) {
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (symbol.equals(chars[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.stringAnalysis.translator.CallEnv;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public interface ITranslator {
|
||||
ITranslator copy();
|
||||
SimpleGrammar solve(IConstraintSolver solver,
|
||||
String funcName, ISymbol recv,
|
||||
List params, IProductionRule invokeRule,
|
||||
SimpleGrammar targetGrammar,
|
||||
SimpleGrammar otherRules,
|
||||
Stack<CallEnv> callStack,
|
||||
IVariableFactory varFactory);
|
||||
boolean acceptCyclic();
|
||||
SimpleGrammar translateCyclic(SimpleGrammar g, Set terminals);
|
||||
Set possibleOutputs(Set terminals);
|
||||
SimpleGrammar toComparable(SimpleGrammar target);
|
||||
boolean isFixpoint(SimpleGrammar target, SimpleGrammar translatedGrammar);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
|
||||
|
||||
public interface ITranslatorRepository {
|
||||
public ITranslator getTranslator(String funcName);
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Implode extends StringTranslator {
|
||||
// private IntRange ranges[];
|
||||
|
||||
private int glueVarIndex;
|
||||
|
||||
private int piecesVarIndex;
|
||||
|
||||
public Implode(int glue, int pieces) {
|
||||
super(pieces);
|
||||
this.piecesVarIndex = pieces;
|
||||
this.glueVarIndex = glue;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params, IProductionRule rule,
|
||||
SimpleGrammar g, IVariableFactory varFactory) {
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params, rule,
|
||||
g, varFactory);
|
||||
|
||||
Variable piecesVar = (Variable) params.get(piecesVarIndex);
|
||||
Variable glueVar = (Variable) params.get(glueVarIndex);
|
||||
|
||||
Set rules = (Set) g2.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List pieces = new ArrayList();
|
||||
List ruleList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule g2Rule = (ProductionRule) rulesIte.next();
|
||||
IVariable left = g2Rule.getLeft();
|
||||
List right = g2Rule.getRight();
|
||||
if (left.equals(piecesVar)) {
|
||||
pieces.add(right.get(0));
|
||||
ruleList.add(g2Rule);
|
||||
}
|
||||
}
|
||||
|
||||
List l = new ArrayList();
|
||||
Iterator piecesIte = pieces.iterator();
|
||||
while (piecesIte.hasNext()) {
|
||||
ISymbol s = (ISymbol) piecesIte.next();
|
||||
l.add(s);
|
||||
l.add(glueVar);
|
||||
}
|
||||
l.remove(l.size() - 1);
|
||||
|
||||
IProductionRule newRule = new ProductionRule(g2.getStartSymbol(), l);
|
||||
Iterator ruleListIte = ruleList.iterator();
|
||||
while (ruleListIte.hasNext()) {
|
||||
g2.getRules().remove(ruleListIte.next());
|
||||
}
|
||||
g2.getRules().add(newRule);
|
||||
return g2;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class IntRange {
|
||||
private int beg, end;
|
||||
|
||||
public IntRange(int beg, int end) {
|
||||
this.beg = beg;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public IntRange(int beg) {
|
||||
this(beg, beg + 1);
|
||||
}
|
||||
|
||||
public Iterator iteratorFor(Object ary[]) {
|
||||
List l = new ArrayList();
|
||||
int max = end;
|
||||
if (max < 0) {
|
||||
max = ary.length;
|
||||
}
|
||||
for (int i = beg; i < max; i++) {
|
||||
l.add(ary[i]);
|
||||
}
|
||||
return l.iterator();
|
||||
}
|
||||
|
||||
public Iterator iteratorFor(List list) {
|
||||
List l = new ArrayList();
|
||||
int max = end;
|
||||
if (max < 0) {
|
||||
max = list.size();
|
||||
}
|
||||
for (int i = beg; i < max; i++) {
|
||||
l.add(list.get(i));
|
||||
}
|
||||
return l.iterator();
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Ltrim extends Transducer {
|
||||
public Ltrim(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Ltrim() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
List spaceChars = new StringSymbol(" ").toCharSymbols();
|
||||
final ISymbol spaceChar = (ISymbol) spaceChars.get(0);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
IState s1 = new State("s1");
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s1);
|
||||
|
||||
ITransition t0 = new Transition(s0, s0, spaceChar, new ISymbol[] {});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s1, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(spaceChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new Transition(s1, s1, v, new ISymbol[] { v });
|
||||
transitions.add(t2);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Nl2br extends Transducer {
|
||||
|
||||
public Nl2br(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Nl2br() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
final ISymbol brChar = new CharSymbol('\n');
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
IState s1 = new State("s1");
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
finalStates.add(s1);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(brChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
return new StringSymbol("<br />").toCharSymbols();
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(brChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Numberformat extends StringTranslator {
|
||||
|
||||
private int decimalsNumIndex;
|
||||
|
||||
private int decPointVarIndex;
|
||||
|
||||
private int sepVarIndex;
|
||||
|
||||
public Numberformat(int decimals, int dec, int sep) {
|
||||
this.decimalsNumIndex = decimals;
|
||||
this.decPointVarIndex = dec;
|
||||
this.sepVarIndex = sep;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params, IProductionRule rule,
|
||||
SimpleGrammar g, IVariableFactory varFactory) {
|
||||
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params, rule,
|
||||
g, varFactory);
|
||||
|
||||
CharSymbol decPoint = new CharSymbol("");
|
||||
CharSymbol sep = new CharSymbol(",");
|
||||
int decimal = 0;
|
||||
|
||||
if (params.size() > decimalsNumIndex) {
|
||||
NumberSymbol decimalNum = (NumberSymbol) params.get(decimalsNumIndex);
|
||||
decimal = decimalNum.intValue();
|
||||
decPoint = new CharSymbol(".");
|
||||
}
|
||||
if (params.size() > decPointVarIndex) {
|
||||
Variable decPointVar = (Variable) params.get(decPointVarIndex);
|
||||
Variable sepVar = (Variable) params.get(sepVarIndex);
|
||||
|
||||
Set rules = (Set) g2.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule varRule = (ProductionRule) rulesIte.next();
|
||||
IVariable left = varRule.getLeft();
|
||||
List right = varRule.getRight();
|
||||
if (left.equals(decPointVar)) {
|
||||
decPoint = (CharSymbol) right.get(0);
|
||||
}
|
||||
else if (left.equals(sepVar)) {
|
||||
sep = (CharSymbol) right.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IVariable G0 = g2.getStartSymbol();
|
||||
IVariable G1 = varFactory.createVariable("G1");
|
||||
IVariable G2 = varFactory.createVariable("G2");
|
||||
IVariable N = varFactory.createVariable("N");
|
||||
ISymbol[] syms = new ISymbol[] { N, G1, N };
|
||||
if (params.size() > decimalsNumIndex && decimal != 0) {
|
||||
syms = new ISymbol[] { N, G1, decPoint, G2 };
|
||||
}
|
||||
ContextFreeGrammar g3 = new ContextFreeGrammar(G0, new IProductionRule[] {
|
||||
// new ProductionRule(G0, new ISymbol[] { N, G1, N}),
|
||||
new ProductionRule(G0, syms),
|
||||
new ProductionRule(G1, new ISymbol[] { N }),
|
||||
new ProductionRule(G1, new ISymbol[] { sep }),
|
||||
new ProductionRule(G1, new ISymbol[] { G1, G1 }),
|
||||
new ProductionRule(G2, new ISymbol[] { N }),
|
||||
new ProductionRule(G2, new ISymbol[] { N, G2 }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("0") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("1") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("2") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("3") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("4") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("5") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("6") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("7") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("8") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("9") }), });
|
||||
return g3;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar g) {
|
||||
return g;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar g, Set terminals) {
|
||||
return translate(g);
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Quotemeta extends Transducer {
|
||||
|
||||
public Quotemeta(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Quotemeta() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
final List quoteChars = new StringSymbol(".\\+*?[^]($)").toCharSymbols();
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
CharSymbol backSlash = new CharSymbol("\\");
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] {
|
||||
backSlash, v }, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = containsQuoteStr(symbol, quoteChars);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !containsQuoteStr(symbol, quoteChars);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
protected boolean containsQuoteStr(ISymbol symbol, List quoteChars) {
|
||||
Iterator quoteIte = quoteChars.iterator();
|
||||
while (quoteIte.hasNext()) {
|
||||
CharSymbol quoteChar = (CharSymbol) quoteIte.next();
|
||||
if (symbol.equals(quoteChar)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class RetInteger extends StringTranslator {
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar g,
|
||||
IVariableFactory varFactory) {
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params,
|
||||
rule, g, varFactory);
|
||||
IVariable S = g2.getStartSymbol();
|
||||
IVariable N = varFactory.createVariable("N");
|
||||
ContextFreeGrammar g3 = new ContextFreeGrammar(S, new IProductionRule[] {
|
||||
new ProductionRule(S, new ISymbol[] { N }),
|
||||
new ProductionRule(S, new ISymbol[] { N, S }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("0") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("1") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("2") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("3") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("4") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("5") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("6") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("7") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("8") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("9") }), });
|
||||
return g3;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class RetIntegerWithNegativeValue extends StringTranslator {
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar g,
|
||||
IVariableFactory varFactory) {
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params,
|
||||
rule, g, varFactory);
|
||||
IVariable S = g2.getStartSymbol();
|
||||
IVariable Z = varFactory.createVariable("Z");
|
||||
IVariable N = varFactory.createVariable("N");
|
||||
|
||||
ContextFreeGrammar g3 = new ContextFreeGrammar(S, new IProductionRule[] {
|
||||
new ProductionRule(S, new ISymbol[] { Z }),
|
||||
new ProductionRule(S, new ISymbol[] { new CharSymbol("-"), Z }),
|
||||
new ProductionRule(Z, new ISymbol[] { N }),
|
||||
new ProductionRule(Z, new ISymbol[] { N, Z }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("0") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("1") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("2") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("3") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("4") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("5") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("6") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("7") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("8") }),
|
||||
new ProductionRule(N, new ISymbol[] { new CharSymbol("9") }), });
|
||||
return g3;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
|
||||
public class Rtrim extends Ltrim {
|
||||
Strrev strrev = new Strrev();
|
||||
|
||||
public Rtrim(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Rtrim() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar sg) {
|
||||
sg = strrev.prepare(translator, funcName, recv, params, rule, sg,
|
||||
varFactory);
|
||||
sg = super.translate(sg);
|
||||
sg = strrev.prepare(translator, funcName, recv, params, rule, sg,
|
||||
varFactory);
|
||||
return sg;
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.Automatons;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Split extends Transducer {
|
||||
// private int sepIndex;
|
||||
|
||||
// private int limIndex;
|
||||
|
||||
// static private int defaultLimIndex = 2;
|
||||
|
||||
public Split(int target, int sepIndex, int limIndex) {
|
||||
super(target);
|
||||
// this.sepIndex = sepIndex;
|
||||
// this.limIndex = limIndex;
|
||||
}
|
||||
|
||||
public Split(int target, int sepIndex) {
|
||||
super(target);
|
||||
// this.sepIndex = sepIndex;
|
||||
// this.limIndex = defaultLimIndex;
|
||||
}
|
||||
|
||||
public Split(int sepIndex) {
|
||||
super();
|
||||
// this.sepIndex = sepIndex;
|
||||
// this.limIndex = defaultLimIndex;
|
||||
}
|
||||
|
||||
public Split() {
|
||||
this(1);
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
// ISymbol sepSym = (ISymbol) params.get(sepIndex);
|
||||
String sep = ":"; // TODO: should obtain this from 'sepSym'.
|
||||
// ISymbol limSym = (ISymbol) params.get(limIndex);
|
||||
IState s0 = new State("s0");
|
||||
IState s1 = new State("s1");
|
||||
IState s2 = new State("s2");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
Set transitions = new HashSet();
|
||||
|
||||
final List sepChars = (new StringSymbol(sep)).toCharSymbols();
|
||||
IAutomaton a1 = Automatons.createAutomaton(sepChars);
|
||||
|
||||
final ISymbol sepChars0 = (ISymbol) sepChars.get(0);
|
||||
ITransition t0 = new Transition(s0, s1, Transition.EpsilonSymbol);
|
||||
ITransition t1 = new FilteredTransition(s1, s1, new Variable("c"),
|
||||
new ISymbol[] { new Variable("c") }, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(sepChars0);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
ITransition t2 = new Transition(s0, s2, Transition.EpsilonSymbol);
|
||||
ITransition t3 = new FilteredTransition(s2, s2, new Variable("c"),
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(sepChars0);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
transitions.add(t1);
|
||||
transitions.add(t2);
|
||||
transitions.add(t3);
|
||||
finalStates.add(s2);
|
||||
IAutomaton a2 = new Automaton(initState, finalStates, transitions);
|
||||
|
||||
Map m = new HashMap();
|
||||
IAutomaton a3 = Automatons.createConcatenation(a2, a1, m);
|
||||
for (Iterator i = a3.getFinalStates().iterator(); i.hasNext();) {
|
||||
IState fin = (IState) i.next();
|
||||
ITransition tt1 = new Transition(fin, s1, Transition.EpsilonSymbol);
|
||||
a3.getTransitions().add(tt1);
|
||||
ITransition tt2 = new Transition(fin, s0, Transition.EpsilonSymbol);
|
||||
a3.getTransitions().add(tt2);
|
||||
}
|
||||
|
||||
a3.getFinalStates().clear();
|
||||
IState finalState = Automatons.createUniqueState(a3);
|
||||
ITransition t = new Transition(s1, finalState, Transition.EpsilonSymbol);
|
||||
a3.getFinalStates().add(finalState);
|
||||
a3.getTransitions().add(t);
|
||||
ITransition anyChar = new Transition(finalState, finalState,
|
||||
new Variable("a"));
|
||||
a3.getTransitions().add(anyChar);
|
||||
Automatons.eliminateEpsilonTransitions(a3);
|
||||
System.err.println(Automatons.toGraphviz(a3));
|
||||
System.err.println(a3.translate(StringSymbol.toCharSymbols("a:b:c")));
|
||||
return a3;
|
||||
}
|
||||
}
|
|
@ -1,370 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Sprintf extends Transducer {
|
||||
|
||||
// private int argsVarIndex;
|
||||
|
||||
public Sprintf(int target, int args1, int args2) {
|
||||
super(target);
|
||||
// this.argsVarIndex = args1;
|
||||
}
|
||||
|
||||
public Sprintf(int args1, int args2) {
|
||||
// this.argsVarIndex = args1;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
String[] args = getStrArgs();
|
||||
|
||||
final CharSymbol percentChar = new CharSymbol("%");
|
||||
final CharSymbol plusChar = new CharSymbol("+");
|
||||
final CharSymbol dChar = new CharSymbol("d");
|
||||
final CharSymbol[] typeSpecifier = (CharSymbol[]) new StringSymbol(
|
||||
"dsfoxXbeuc").toCharSymbols().toArray(new CharSymbol[0]);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState state = new State("s0");
|
||||
IState initState = state;
|
||||
Set finalStates = new HashSet();
|
||||
int stateIndex = 1;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
IState s1 = new State("s" + (stateIndex++));
|
||||
IState s2 = new State("s" + (stateIndex++));
|
||||
IState s3 = new State("s" + (stateIndex++));
|
||||
IState s4 = new State("s" + (stateIndex++));
|
||||
IState s5 = new State("s" + (stateIndex++));
|
||||
finalStates.add(s1);
|
||||
finalStates.add(s2);
|
||||
finalStates.add(s3);
|
||||
finalStates.add(s4);
|
||||
finalStates.add(s5);
|
||||
final String arg = args[i];
|
||||
ITransition t0 = new FilteredTransition(state, state, v,
|
||||
new ISymbol[] { v }, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(percentChar);
|
||||
if (r)
|
||||
System.err.println("(!symbol.equals(percentChar): accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(state, s1, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(percentChar);
|
||||
if (r)
|
||||
System.err.println("(symbol.equals(percentChar) " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new FilteredTransition(s1, s2, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(plusChar);
|
||||
if (r)
|
||||
System.err.println("(symbol.equals(plusChar) " + symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t2);
|
||||
ITransition t3 = new FilteredTransition(s2, s4, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
if (symbol.equals(dChar)) {
|
||||
return formatSignSpecifier(arg);
|
||||
}
|
||||
if (symbol.equals(percentChar)) {
|
||||
return outputs;
|
||||
}
|
||||
outputs.clear();
|
||||
return outputs;
|
||||
}
|
||||
}, null);
|
||||
transitions.add(t3);
|
||||
ITransition t4 = new FilteredTransition(s1, s3, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
// List newOutputs = new ArrayList();
|
||||
if (symbol.equals(typeSpecifier[0])) {
|
||||
return formatStandardInteger(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[1])) {
|
||||
return formatString(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[2])) {
|
||||
return formatFloatingPoint(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[3])) {
|
||||
return formatOctal(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[4])) {
|
||||
return formatHexadecimalLowerCase(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[5])) {
|
||||
return formatHexadecimalUpperCase(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[6])) {
|
||||
return formatBinary(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[7])) {
|
||||
return formatScientificNotation(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[8])) {
|
||||
return formatUnsignedInteger(arg);
|
||||
}
|
||||
if (symbol.equals(typeSpecifier[9])) {
|
||||
return printAsciiCharacter(arg);
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!symbol.equals(percentChar))
|
||||
&& (!symbol.equals(plusChar));
|
||||
if (r)
|
||||
System.err
|
||||
.println("(!symbol.equals(percentChar)) && (!symbol.equals(plusChar): accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t4);
|
||||
ITransition t5 = new FilteredTransition(s1, state, v,
|
||||
new ISymbol[] { v }, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(percentChar);
|
||||
if (r)
|
||||
System.err.println("(symbol.equals(percentChar): accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t5);
|
||||
ITransition t6 = new Transition(s3, s5, Transition.EpsilonSymbol);
|
||||
ITransition t7 = new Transition(s4, s5, Transition.EpsilonSymbol);
|
||||
transitions.add(t6);
|
||||
transitions.add(t7);
|
||||
state = s5;
|
||||
}
|
||||
|
||||
ITransition t = new Transition(state, state, v, new ISymbol[] { v });
|
||||
transitions.add(t);
|
||||
finalStates.add(state);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
private String[] getStrArgs() {
|
||||
int argsLen = params.size() - 1;
|
||||
String[] args = new String[argsLen];
|
||||
Variable[] argVars = new Variable[argsLen];
|
||||
for (int i = 0; i < argsLen; i++) {
|
||||
argVars[i] = (Variable) params.get(i + 1);
|
||||
}
|
||||
Set rules = (Set) grammar.getRules();
|
||||
for (int i = 0; i < argsLen; i++) {
|
||||
Iterator rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
List right = new ArrayList();
|
||||
if (rule.getLeft().equals(argVars[i])) {
|
||||
right = rule.getRight();
|
||||
}
|
||||
if (!right.isEmpty()) {
|
||||
Iterator rightIte = right.iterator();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (rightIte.hasNext()) {
|
||||
CharSymbol charSym = (CharSymbol) rightIte.next();
|
||||
sb.append(charSym.charValue());
|
||||
}
|
||||
args[i] = sb.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
protected List printAsciiCharacter(String arg) {
|
||||
int argInt = 0;
|
||||
if (isNumber(arg)) {
|
||||
argInt = Integer.parseInt(arg);
|
||||
}
|
||||
Charset asciiCharset = Charset.forName("US-ASCII");
|
||||
CharsetDecoder decoder = asciiCharset.newDecoder();
|
||||
if (!(0 <= argInt && argInt <= 127)) {
|
||||
return new ArrayList();
|
||||
}
|
||||
byte b1 = (byte) argInt;
|
||||
byte[] b = { b1 };
|
||||
ByteBuffer asciiBytes = ByteBuffer.wrap(b);
|
||||
CharBuffer cBuf = null;
|
||||
try {
|
||||
cBuf = decoder.decode(asciiBytes);
|
||||
}
|
||||
catch (CharacterCodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(cBuf.toString());
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatSignSpecifier(String arg) {
|
||||
int argInt = 0;
|
||||
if (isNumber(arg)) {
|
||||
argInt = Integer.parseInt(arg);
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(String.valueOf(argInt));
|
||||
if (argInt >= 0) {
|
||||
strSym = new StringSymbol("+" + String.valueOf((argInt)));
|
||||
}
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatUnsignedInteger(String arg) {
|
||||
int argInt = 0;
|
||||
if (isNumber(arg)) {
|
||||
argInt = Integer.parseInt(arg);
|
||||
}
|
||||
double argDouble = argInt;
|
||||
if (argInt < 0) {
|
||||
argDouble = argInt + Math.pow(2, 32);
|
||||
System.out.println(argDouble);
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat("0");
|
||||
StringSymbol strSym = new StringSymbol(df.format(argDouble));
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatScientificNotation(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat("0.00000E0");
|
||||
String argStr = df.format(Double.parseDouble(arg));
|
||||
int ePos = argStr.indexOf("E");
|
||||
int minusPos = argStr.indexOf("-");
|
||||
if (minusPos < 0) {
|
||||
StringBuffer sb = new StringBuffer(argStr);
|
||||
sb.replace(ePos, ePos + 1, "e");
|
||||
sb.insert(ePos + 1, "+");
|
||||
argStr = sb.toString();
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(argStr);
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatBinary(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(Integer.toBinaryString(Integer
|
||||
.parseInt(arg)));
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatHexadecimalUpperCase(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
String argStr = Integer.toHexString(Integer.parseInt(arg));
|
||||
StringSymbol strSym = new StringSymbol(argStr.toUpperCase());
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatHexadecimalLowerCase(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(Integer.toHexString(Integer
|
||||
.parseInt(arg)));
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatOctal(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
StringSymbol strSym = new StringSymbol(Integer.toOctalString(Integer
|
||||
.parseInt(arg)));
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatFloatingPoint(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat("0.000000");
|
||||
StringSymbol strSym = new StringSymbol(df.format(Double.parseDouble(arg)));
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatString(String arg) {
|
||||
StringSymbol strSym = new StringSymbol(arg);
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
protected List formatStandardInteger(String arg) {
|
||||
if (!isNumber(arg)) {
|
||||
arg = "0";
|
||||
}
|
||||
BigDecimal bigDecimal = new BigDecimal(arg);
|
||||
StringSymbol strSym = new StringSymbol(String
|
||||
.valueOf(bigDecimal.intValue()));
|
||||
return strSym.toCharSymbols();
|
||||
}
|
||||
|
||||
private boolean isNumber(String arg) {
|
||||
char[] charArray = arg.toCharArray();
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
if (Character.isDigit(charArray[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class StrRepeat extends StringTranslator {
|
||||
private int repNumIndex;
|
||||
|
||||
public StrRepeat(int target, int rep) {
|
||||
super(target);
|
||||
this.repNumIndex = rep;
|
||||
}
|
||||
|
||||
public StrRepeat(int rep) {
|
||||
super();
|
||||
this.repNumIndex = rep;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar g,
|
||||
IVariableFactory varFactory) {
|
||||
NumberSymbol repNumSym = (NumberSymbol) params.get(repNumIndex);
|
||||
int repNum = repNumSym.intValue();
|
||||
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params, rule, g, varFactory);
|
||||
List<ISymbol> l = new ArrayList<ISymbol>();
|
||||
for (int i = 0; i < repNum; i++) {
|
||||
l.add(g2.getStartSymbol());
|
||||
}
|
||||
|
||||
IVariable v = createVariable();
|
||||
IProductionRule newRule = new ProductionRule(v, l);
|
||||
g2.getRules().add(newRule);
|
||||
g2.setStartSymbol(v);
|
||||
return g2;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strchr extends Transducer {
|
||||
|
||||
private int needleVarIndex;
|
||||
|
||||
public Strchr(int target, int needle) {
|
||||
super(target);
|
||||
this.needleVarIndex = needle;
|
||||
}
|
||||
|
||||
public Strchr(int needle) {
|
||||
super();
|
||||
this.needleVarIndex = needle;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Variable needleVar = (Variable) params.get(needleVarIndex);
|
||||
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List needleList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(needleVar)) {
|
||||
needleList = rule.getRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final CharSymbol needleChar = (CharSymbol) needleList.get(0);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState s1 = new State("s1");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s1);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(needleChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition1: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
|
||||
ITransition t1 = new FilteredTransition(s0, s1, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(needleChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition2: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new Transition(s1, s1, v, new ISymbol[] {});
|
||||
transitions.add(t2);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.CFLReachability;
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.Grammars;
|
||||
import com.ibm.wala.automaton.grammar.string.IContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
|
||||
public abstract class StringTranslator extends BasicTranslator {
|
||||
public boolean isFixpoint(SimpleGrammar target,
|
||||
SimpleGrammar translatedGrammar) {
|
||||
IContextFreeGrammar cfg = new ContextFreeGrammar(target);
|
||||
IAutomaton fst = Grammars.toAutomaton(cfg);
|
||||
return CFLReachability.containsAll(fst, new ContextFreeGrammar(
|
||||
translatedGrammar));
|
||||
}
|
||||
|
||||
public StringTranslator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public StringTranslator(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
|
||||
public SimpleGrammar toComparable(SimpleGrammar target) {
|
||||
IContextFreeGrammar cfg = new ContextFreeGrammar(target);
|
||||
Grammars.RegularApproximation.approximateToRegular(cfg);
|
||||
return cfg.toSimple();
|
||||
}
|
||||
|
||||
protected IVariable createVariable() {
|
||||
return varFactory.createVariable(Grammars.variablePrefix);
|
||||
}
|
||||
}
|
|
@ -1,353 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition.ICondition;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
public class StripCSlashes extends Transducer {
|
||||
public StripCSlashes(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public StripCSlashes() {
|
||||
super();
|
||||
}
|
||||
|
||||
private static final CharSymbol SYM_BSLASH = new CharSymbol('\\');
|
||||
private static final ICondition IS_BSLASH = new ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
// Optimize for CharSymbol
|
||||
if (symbol instanceof CharSymbol) {
|
||||
char c = ((CharSymbol)symbol).charValue();
|
||||
return (c == '\\');
|
||||
}
|
||||
return symbol.equals(SYM_BSLASH);
|
||||
}
|
||||
};
|
||||
private static final ICondition NOT_BSLASH = new ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
return !IS_BSLASH.accept(symbol, ctx);
|
||||
}
|
||||
};
|
||||
protected static class IsChar implements ICondition {
|
||||
private final char c;
|
||||
public IsChar(char c) {
|
||||
this.c = c;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.capa.util.automaton.string.FilteredTransition.ICondition#accept(com.ibm.capa.util.automaton.string.ISymbol, com.ibm.capa.util.automaton.string.IMatchContext)
|
||||
*/
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
// Optimize for CharSymbol
|
||||
if (symbol instanceof CharSymbol) {
|
||||
char d = ((CharSymbol)symbol).charValue();
|
||||
return c == d;
|
||||
}
|
||||
String name = symbol.getName();
|
||||
return ((name.length() == 1) && (name.charAt(0) == c));
|
||||
}
|
||||
}
|
||||
private static final IsChar IS_SMALL_X = new IsChar('x');
|
||||
private static final IsChar[] IS_HEX;
|
||||
private static final IsChar[] IS_OCTAL;
|
||||
static {
|
||||
char[] hex = "0123456789abcdefABCDEF".toCharArray();
|
||||
IS_HEX = new IsChar[hex.length];
|
||||
int i = 0;
|
||||
for (char c : hex) {
|
||||
IS_HEX[i++] = new IsChar(c);
|
||||
}
|
||||
IS_OCTAL = new IsChar[8];
|
||||
for (i=0; i<8; i++)
|
||||
IS_OCTAL[i] = IS_HEX[i];
|
||||
}
|
||||
private static final ICondition NOT_HEX = new ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
char d;
|
||||
if (symbol instanceof CharSymbol) {
|
||||
d = ((CharSymbol)symbol).charValue();
|
||||
} else {
|
||||
String name = symbol.getName();
|
||||
if (name.length() != 1)
|
||||
return false;
|
||||
d = name.charAt(0);
|
||||
}
|
||||
if (d >= '0' && d <= '9')
|
||||
return false;
|
||||
if (d >= 'a' && d <= 'f')
|
||||
return false;
|
||||
if (d >= 'A' && d <= 'F')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private static final ICondition NOT_OCTAL = new ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
char d;
|
||||
if (symbol instanceof CharSymbol) {
|
||||
d = ((CharSymbol)symbol).charValue();
|
||||
} else {
|
||||
String name = symbol.getName();
|
||||
if (name.length() != 1)
|
||||
return false;
|
||||
d = name.charAt(0);
|
||||
}
|
||||
if (d >= '0' && d <= '7')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private static final ICondition NOT_SPECIAL = new ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
char d;
|
||||
if (symbol instanceof CharSymbol) {
|
||||
d = ((CharSymbol)symbol).charValue();
|
||||
} else {
|
||||
String name = symbol.getName();
|
||||
if (name.length() != 1)
|
||||
return false;
|
||||
d = name.charAt(0);
|
||||
}
|
||||
if (d >= '0' && d <= '7') // Octal digit
|
||||
return false;
|
||||
switch (d) {
|
||||
case 'n':
|
||||
case 'r':
|
||||
case 'a':
|
||||
case 't':
|
||||
case 'v':
|
||||
case 'b':
|
||||
case 'f':
|
||||
case '\\':
|
||||
case 'x':
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private static class UnquoteMetaTransition extends FilteredTransition {
|
||||
private UnquoteMetaTransition(IState s0, IState s1, ISymbol in, char c, char out) {
|
||||
super(s0, s1, in, new CharSymbol[] {new CharSymbol(out)}, null, new IsChar(c));
|
||||
}
|
||||
private static class LF extends UnquoteMetaTransition {
|
||||
private LF(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 'n', (char)10);
|
||||
}
|
||||
}
|
||||
private static class CR extends UnquoteMetaTransition {
|
||||
private CR(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 'r', (char)13);
|
||||
}
|
||||
}
|
||||
private static class ALARM extends UnquoteMetaTransition {
|
||||
private ALARM(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 'a', (char)7);
|
||||
}
|
||||
}
|
||||
private static class TAB extends UnquoteMetaTransition {
|
||||
private TAB(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 't', (char)9);
|
||||
}
|
||||
}
|
||||
private static class VTAB extends UnquoteMetaTransition {
|
||||
private VTAB(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 'v', (char)11);
|
||||
}
|
||||
}
|
||||
private static class BSPACE extends UnquoteMetaTransition {
|
||||
private BSPACE(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 'b', (char)8);
|
||||
}
|
||||
}
|
||||
private static class FORMFEED extends UnquoteMetaTransition {
|
||||
private FORMFEED(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, 'f', (char)12);
|
||||
}
|
||||
}
|
||||
private static class BSLASH extends UnquoteMetaTransition {
|
||||
private BSLASH(IState s0, IState s1, ISymbol in) {
|
||||
super(s0, s1, in, '\\', '\\');
|
||||
}
|
||||
}
|
||||
public static ITransition[] makeTransitions(IState s0, IState s1, ISymbol in) {
|
||||
return new ITransition[] {
|
||||
new ALARM(s0, s1, in),
|
||||
new BSLASH(s0, s1, in),
|
||||
new BSPACE(s0, s1, in),
|
||||
new CR(s0, s1, in),
|
||||
new FORMFEED(s0, s1, in),
|
||||
new LF(s0, s1, in),
|
||||
new TAB(s0, s1, in),
|
||||
new VTAB(s0, s1, in),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
protected int hexToInt(char c) {
|
||||
if (c >= '0' && c <= '9')
|
||||
return (int)(c - '0');
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return (int)(c - 'a' + 10);
|
||||
if (c >= 'A' && c <= 'F')
|
||||
return (int)(c - 'A' + 10);
|
||||
Assertions.UNREACHABLE("Not a hex digit: " + c);
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set<ITransition> transitions = new HashSet<ITransition>();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set<IState> finalStates = new HashSet<IState>();
|
||||
finalStates.add(s0);
|
||||
|
||||
/* Step 1. Add Transitions for normal cases */
|
||||
// Transition for non-backslash characters
|
||||
// s0 -([^\])-> s0
|
||||
ITransition t = new FilteredTransition(s0, s0, v, new ISymbol[] { v }, null, NOT_BSLASH);
|
||||
transitions.add(t);
|
||||
|
||||
// Transition for backslash at the end of input
|
||||
// s0 -(\$END-OF-STRING)-> sX
|
||||
IState sX = new State("sX");
|
||||
t = new FilteredTransition(s0, sX, v, new ISymbol[] { v }, null, IS_BSLASH);
|
||||
transitions.add(t);
|
||||
finalStates.add(sX);
|
||||
|
||||
/* Step 2. Add Transitions for striping backslashes */
|
||||
// Transition for backslash not at the end of input
|
||||
// s0 -(\)-> s1
|
||||
IState s1 = new State("s1");
|
||||
t = new FilteredTransition(s0, s1, v, new ISymbol[] {}, null, IS_BSLASH);
|
||||
transitions.add(t);
|
||||
|
||||
/* Step 2-1. Add Transitions for non-meta characters */
|
||||
// Transition for non-meta characters
|
||||
// s1 -(.)-> s0, output the input
|
||||
t = new FilteredTransition(s1, s0, v, new ISymbol[] { v }, null, NOT_SPECIAL);
|
||||
transitions.add(t);
|
||||
|
||||
/* Step 2-2. Add Transitions for convertiong meta-characters */
|
||||
// Transtions for meta-characters
|
||||
// s1 -(n)-> s0, output '\n';
|
||||
// s1 -(r)-> s0, output '\r';
|
||||
// ...
|
||||
ITransition[] metaCharTrans = UnquoteMetaTransition.makeTransitions(s1, s0, v);
|
||||
for (ITransition tr : metaCharTrans) {
|
||||
transitions.add(tr);
|
||||
}
|
||||
|
||||
/* Step 2-3. Add Transitions for convertiong hex values */
|
||||
// Transition for small 'x' after '\'
|
||||
// s1 -(x)-> sx
|
||||
IState sx = new State("sx");
|
||||
t = new FilteredTransition(s1, sx, v, new ISymbol[]{}, null, IS_SMALL_X);
|
||||
transitions.add(t);
|
||||
|
||||
// Transitions for hex characters after "\x"
|
||||
// sx -(0)-> sx0
|
||||
// ...
|
||||
// sx -(F)-> sxF
|
||||
for (IsChar cond: IS_HEX) {
|
||||
char c = cond.c;
|
||||
IState sxc = new State("sx" + c);
|
||||
t = new FilteredTransition(sx, sxc, v, new ISymbol[]{}, null, cond);
|
||||
transitions.add(t);
|
||||
// Transitions for another hex
|
||||
// sxc -(0)-> s0; output hex-value of the two characters
|
||||
// ..
|
||||
// sxc -(F)-> s0; output hex-value of the two characters
|
||||
for (IsChar cond2: IS_HEX) {
|
||||
int val = hexToInt(c)*16 + hexToInt(cond2.c);
|
||||
ISymbol out = new CharSymbol((char)val);
|
||||
t = new FilteredTransition(sxc, s0, v, new ISymbol[] {out}, null, cond2);
|
||||
transitions.add(t);
|
||||
}
|
||||
|
||||
// Transitions for non-hex characters
|
||||
// sxc -(.)-> s0; output hex-value of c and the input
|
||||
int val = hexToInt(c);
|
||||
ISymbol hexOut = new CharSymbol((char)val);
|
||||
t = new FilteredTransition(sxc, s0, v, new ISymbol[] { hexOut, v }, null, NOT_HEX);
|
||||
transitions.add(t);
|
||||
}
|
||||
/* End of tep 2-3 */
|
||||
|
||||
/* Step 2-4. Add Transitions for convertiong octal values */
|
||||
// Transitions for octal digits after '\'
|
||||
// s1 -(0)-> sO0
|
||||
// ...
|
||||
// s1 -(7)-> sO7
|
||||
for (IsChar cond: IS_OCTAL) {
|
||||
char c = cond.c;
|
||||
String nm = "sO" + c;
|
||||
IState sOc = new State(nm);
|
||||
t = new FilteredTransition(s1, sOc, v, new ISymbol[]{}, null, cond);
|
||||
transitions.add(t);
|
||||
|
||||
// Transitions for sequence of two octal digits
|
||||
// sOc -(0)-> sOc0
|
||||
// ...
|
||||
// sOc -(7)-> sOc7
|
||||
for (IsChar cond2: IS_OCTAL) {
|
||||
char c2 = cond2.c;
|
||||
IState sOc_c2 = new State(nm + c2);
|
||||
t = new FilteredTransition(sOc, sOc_c2, v, new ISymbol[]{}, null, cond2);
|
||||
transitions.add(t);
|
||||
// Transitions for sequence of three octal digits
|
||||
// sOc_c2 -(0)-> s0; output octal value of the three-character sequence
|
||||
// ...
|
||||
// sOc_c2 -(7)-> s0; output octal value of the three-character sequence
|
||||
for (IsChar cond3: IS_OCTAL) {
|
||||
char c3 = cond3.c;
|
||||
int val = (c - '0')*8*8 + (c2 - '0')*8 + (c3 - '0');
|
||||
ISymbol out = new CharSymbol((char)val);
|
||||
t = new FilteredTransition(sOc_c2, s0, v, new ISymbol[]{out}, null, cond3);
|
||||
transitions.add(t);
|
||||
}
|
||||
// Transition for non-octal characters after two octal digits
|
||||
// sOc_c2 -(.)-> s0; output octal value of the two-character sequence and the input
|
||||
int val = (c - '0')*8 + (c2 - '0');
|
||||
ISymbol out = new CharSymbol((char)val);
|
||||
t = new FilteredTransition(sOc_c2, s0, v, new ISymbol[]{out, v}, null, NOT_OCTAL);
|
||||
transitions.add(t);
|
||||
}
|
||||
// Transition for non-octal characters after one octal digits
|
||||
// sOc -(.)-> s0; output octal value of the digit and the input
|
||||
int val = (c - '0');
|
||||
ISymbol out = new CharSymbol((char)val);
|
||||
t = new FilteredTransition(sOc, s0, v, new ISymbol[]{out, v}, null, NOT_OCTAL);
|
||||
transitions.add(t);
|
||||
}
|
||||
/* End of Step 2-4 */
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Stripslashes extends Transducer {
|
||||
|
||||
public Stripslashes(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Stripslashes() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
final CharSymbol slashe = new CharSymbol("\\");
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(slashe);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition:accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(slashe);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition:accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Striptags extends Transducer {
|
||||
|
||||
public Striptags(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Striptags() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
IState s1 = new State("s1");
|
||||
IState s2 = new State("s2");
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
finalStates.add(s1);
|
||||
finalStates.add(s2);
|
||||
|
||||
final ISymbol lessThanChar = new CharSymbol('<');
|
||||
final ISymbol greaterThanChar = new CharSymbol('>');
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(lessThanChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s1, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(lessThanChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new FilteredTransition(s1, s1, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!symbol.equals(lessThanChar))
|
||||
&& (!symbol.equals(greaterThanChar));
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t2);
|
||||
ITransition t3 = new FilteredTransition(s1, s0, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(greaterThanChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t3);
|
||||
ITransition t4 = new FilteredTransition(s1, s2, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(lessThanChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t4);
|
||||
ITransition t5 = new Transition(s2, s2, v, new ISymbol[] {});
|
||||
transitions.add(t5);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strireplace extends Transducer {
|
||||
|
||||
private int repStrIndex;
|
||||
|
||||
private int searchStrIndex;
|
||||
|
||||
public Strireplace(int target, int search, int replace) {
|
||||
super(target);
|
||||
this.repStrIndex = replace;
|
||||
this.searchStrIndex = search;
|
||||
}
|
||||
|
||||
public Strireplace(int search, int replace) {
|
||||
super();
|
||||
this.repStrIndex = replace;
|
||||
this.searchStrIndex = search;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Variable repStrVar = (Variable) params.get(repStrIndex);
|
||||
Variable searchStrVar = (Variable) params.get(searchStrIndex);
|
||||
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List repStrList = new ArrayList();
|
||||
List searchStrList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
IVariable left = rule.getLeft();
|
||||
List right = rule.getRight();
|
||||
if (left.equals(repStrVar)) {
|
||||
repStrList = right;
|
||||
}
|
||||
else if (left.equals(searchStrVar)) {
|
||||
searchStrList = right;
|
||||
}
|
||||
}
|
||||
|
||||
final CharSymbol[] repChars = (CharSymbol[]) repStrList
|
||||
.toArray(new CharSymbol[0]);
|
||||
final CharSymbol[] searchChars = (CharSymbol[]) searchStrList
|
||||
.toArray(new CharSymbol[0]);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !isEquals(symbol, searchChars[0]);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
|
||||
IState state = s0;
|
||||
IState searchFirstState = new State("s1");
|
||||
final CharSymbol searchFirstChar = searchChars[0];
|
||||
final int searchCharsLen = searchChars.length;
|
||||
for (int i = 0; i < searchCharsLen - 1; i++) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
if (i == 0) {
|
||||
nextState = searchFirstState;
|
||||
}
|
||||
final CharSymbol searchChar = searchChars[i];
|
||||
final CharSymbol nextSearchChar = searchChars[i + 1];
|
||||
final int index = i;
|
||||
ITransition ta = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = isEquals(symbol, searchChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
|
||||
List subSearchCharSymsList = generateCharSymsList(searchChars, index);
|
||||
Iterator symsListIte = subSearchCharSymsList.iterator();
|
||||
while (symsListIte.hasNext()) {
|
||||
final CharSymbol[] subSearchChars = (CharSymbol[]) symsListIte.next();
|
||||
ITransition tb = new FilteredTransition(nextState, s0, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = new ArrayList();
|
||||
for (int j = 0; j < index + 1; j++) {
|
||||
newOutputs.add(subSearchChars[j]);
|
||||
}
|
||||
newOutputs.add(symbol);
|
||||
return newOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!isEquals(symbol, nextSearchChar))
|
||||
&& (!isEquals(symbol, searchFirstChar));
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(tb);
|
||||
ITransition tc = new FilteredTransition(nextState, searchFirstState, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = new ArrayList();
|
||||
for (int j = 0; j < index + 1; j++) {
|
||||
newOutputs.add(subSearchChars[j]);
|
||||
}
|
||||
return newOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!isEquals(symbol, nextSearchChar))
|
||||
&& isEquals(symbol, searchFirstChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(tc);
|
||||
}
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
}
|
||||
|
||||
ITransition t1 = new FilteredTransition(state, s0, v, repChars, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = isEquals(symbol, searchChars[searchCharsLen - 1]);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
private List generateCharSymsList(CharSymbol[] searchChars, int index) {
|
||||
List searchCharList = new ArrayList();
|
||||
for (int i = 0; i < index + 1; i++) {
|
||||
searchCharList.add(searchChars[i]);
|
||||
}
|
||||
return getCharSymbolsList(searchCharList);
|
||||
}
|
||||
|
||||
private List getCharSymbolsList(List searchCharList) {
|
||||
List charSymbolsList = new ArrayList();
|
||||
CharSymbol[] symbols = (CharSymbol[]) searchCharList
|
||||
.toArray(new CharSymbol[0]);
|
||||
for (int i = 0; i < (int) Math.pow(2.0, symbols.length); i++) {
|
||||
CharSymbol[] result = new CharSymbol[symbols.length];
|
||||
for (int index = 0, length = symbols.length; index < length; index++) {
|
||||
char chr = (i & 1 << (length - 1 - index)) > 0 ? Character
|
||||
.toUpperCase(symbols[index].charValue()) : Character
|
||||
.toLowerCase(symbols[index].charValue());
|
||||
result[index] = new CharSymbol(chr);
|
||||
}
|
||||
charSymbolsList.add(result);
|
||||
}
|
||||
return charSymbolsList;
|
||||
}
|
||||
|
||||
protected boolean isEquals(ISymbol symbol, CharSymbol searchChar) {
|
||||
CharSymbol uChar = new CharSymbol(Character.toUpperCase(searchChar
|
||||
.charValue()));
|
||||
CharSymbol lChar = new CharSymbol(Character.toLowerCase(searchChar
|
||||
.charValue()));
|
||||
if ((symbol.equals(uChar)) || (symbol.equals(lChar))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Stristr extends Transducer {
|
||||
|
||||
private int needleStrIndex;
|
||||
|
||||
public Stristr(int target, int needle) {
|
||||
super(target);
|
||||
this.needleStrIndex = needle;
|
||||
}
|
||||
|
||||
public Stristr(int needle) {
|
||||
super();
|
||||
this.needleStrIndex = needle;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
final Variable needleVar = (Variable) params.get(needleStrIndex);
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List needleList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(needleVar)) {
|
||||
needleList = rule.getRight();
|
||||
}
|
||||
}
|
||||
final CharSymbol[] needleChars = (CharSymbol[]) needleList
|
||||
.toArray(new CharSymbol[0]);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] {}, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !isEquals(symbol, needleChars[0]);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
IState state = s0;
|
||||
int lastIndex = needleChars.length;
|
||||
for (int i = 0; i < lastIndex - 1; i++) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
final CharSymbol needleChar = needleChars[i];
|
||||
// final CharSymbol nextNeedleChar = needleChars[i + 1];
|
||||
ITransition ta = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = isEquals(symbol, needleChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
ITransition tb = new Transition(nextState, s0, Transition.EpsilonSymbol);
|
||||
transitions.add(tb);
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
}
|
||||
|
||||
IState nextState = new State("s" + lastIndex);
|
||||
List charSymbolsList = getCharSymbolsList(needleList);
|
||||
Iterator charSymbolsIte = charSymbolsList.iterator();
|
||||
while (charSymbolsIte.hasNext()) {
|
||||
CharSymbol[] newNeedleChars = (CharSymbol[]) charSymbolsIte
|
||||
.next();
|
||||
final CharSymbol needleChar = needleChars[lastIndex - 1];
|
||||
ITransition t = new FilteredTransition(state, nextState, v, newNeedleChars,
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = isEquals(symbol, needleChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t);
|
||||
}
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
ITransition t1 = new Transition(state, state, v, new ISymbol[] { v });
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
private List getCharSymbolsList(List needleList) {
|
||||
List charSymbolsList = new ArrayList();
|
||||
CharSymbol[] symbols = (CharSymbol[]) needleList.toArray(new CharSymbol[0]);
|
||||
for (int i = 0; i < (int) Math.pow(2.0, symbols.length); i++) {
|
||||
CharSymbol[] result = new CharSymbol[symbols.length];
|
||||
for (int index = 0, length = symbols.length; index < length; index++) {
|
||||
char chr = (i & 1 << (length - 1 - index)) > 0 ? Character
|
||||
.toUpperCase(symbols[index].charValue()) : Character
|
||||
.toLowerCase(symbols[index].charValue());
|
||||
result[index] = new CharSymbol(chr);
|
||||
}
|
||||
charSymbolsList.add(result);
|
||||
}
|
||||
return charSymbolsList;
|
||||
}
|
||||
|
||||
protected boolean isEquals(ISymbol symbol, CharSymbol needleChar) {
|
||||
CharSymbol uChar = new CharSymbol(Character.toUpperCase(needleChar
|
||||
.charValue()));
|
||||
CharSymbol lChar = new CharSymbol(Character.toLowerCase(needleChar
|
||||
.charValue()));
|
||||
if ((symbol.equals(uChar)) || (symbol.equals(lChar))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.StringSymbol;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Strpad extends StringTranslator {
|
||||
private int target; // TODO: should reuse super.target.
|
||||
|
||||
private int lenNumIndex;
|
||||
|
||||
private int strNumIndex;
|
||||
|
||||
private int typeNumIndex;
|
||||
|
||||
public Strpad(int target, int len, int str, int type) {
|
||||
super(TARGET_ALL);
|
||||
this.target = target;
|
||||
this.lenNumIndex = len;
|
||||
this.strNumIndex = str;
|
||||
this.typeNumIndex = type;
|
||||
}
|
||||
|
||||
public Strpad(int len, int str, int type) {
|
||||
super(TARGET_ALL);
|
||||
this.target = -1;
|
||||
this.lenNumIndex = len;
|
||||
this.strNumIndex = str;
|
||||
this.typeNumIndex = type;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar g,
|
||||
IVariableFactory varFactory) {
|
||||
NumberSymbol lenNumSym = (NumberSymbol) params.get(lenNumIndex);
|
||||
Variable targetVar = (Variable) params.get(target);
|
||||
Variable strVar = new Variable("");
|
||||
Variable typeVar = new Variable("");
|
||||
if (params.size() > strNumIndex) {
|
||||
strVar = (Variable) params.get(strNumIndex);
|
||||
}
|
||||
if (params.size() > typeNumIndex) {
|
||||
typeVar = (Variable) params.get(typeNumIndex);
|
||||
}
|
||||
int length = lenNumSym.intValue();
|
||||
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params,
|
||||
rule, g, varFactory);
|
||||
|
||||
List strVarList = new ArrayList();
|
||||
List targetVars = new ArrayList();
|
||||
List typeVars = new ArrayList();
|
||||
Set rules = (Set) g2.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
ProductionRule strRule = null;
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule varRule = (ProductionRule) rulesIte.next();
|
||||
IVariable left = varRule.getLeft();
|
||||
List right = varRule.getRight();
|
||||
if (left.equals(strVar)) {
|
||||
strVarList = right;
|
||||
strRule = varRule;
|
||||
}
|
||||
else if (left.equals(targetVar)) {
|
||||
targetVars = right;
|
||||
}
|
||||
else if (left.equals(typeVar)) {
|
||||
typeVars = right;
|
||||
}
|
||||
}
|
||||
if (typeVars.isEmpty()) {
|
||||
typeVars = new StringSymbol("STR_PAD_RIGHT").toCharSymbols();
|
||||
}
|
||||
if (strVarList.isEmpty()) {
|
||||
strVarList = new StringSymbol(" ").toCharSymbols();
|
||||
}
|
||||
CharSymbol[] typeChars = (CharSymbol[]) typeVars
|
||||
.toArray(new CharSymbol[0]);
|
||||
String type = "";
|
||||
for (int i = 0; i < typeChars.length; i++) {
|
||||
type += typeChars[i].value();
|
||||
}
|
||||
List newStrVars = new ArrayList();
|
||||
for (int i = 0; i < (length - targetVars.size()); i++) {
|
||||
int index = i;
|
||||
if (i >= strVarList.size()) {
|
||||
index = i % strVarList.size();
|
||||
}
|
||||
newStrVars.add(strVarList.get(index));
|
||||
}
|
||||
|
||||
Variable postStrVar = null;
|
||||
g2.getRules().remove(strRule);
|
||||
if (type.equals("STR_PAD_BOTH")) {
|
||||
g2.getRules().add(
|
||||
new ProductionRule(strVar, newStrVars.subList(0,
|
||||
newStrVars.size() / 2)));
|
||||
postStrVar = new Variable("post" + strVar.getName());
|
||||
g2.getRules().add(
|
||||
new ProductionRule(postStrVar, newStrVars.subList(
|
||||
newStrVars.size() / 2, newStrVars.size())));
|
||||
}
|
||||
else {
|
||||
g2.getRules().add(new ProductionRule(strVar, newStrVars));
|
||||
}
|
||||
List l = new ArrayList();
|
||||
if (type.equals("STR_PAD_RIGHT")) {
|
||||
l.add(targetVar);
|
||||
l.add(strVar);
|
||||
}
|
||||
else if (type.equals("STR_PAD_LEFT")) {
|
||||
l.add(strVar);
|
||||
l.add(targetVar);
|
||||
}
|
||||
else if (type.equals("STR_PAD_BOTH")) {
|
||||
l.add(strVar);
|
||||
l.add(targetVar);
|
||||
if (postStrVar != null) {
|
||||
l.add(postStrVar);
|
||||
}
|
||||
}
|
||||
|
||||
IProductionRule newRule = new ProductionRule(rule.getLeft(), l);
|
||||
g2.getRules().remove(rule);
|
||||
g2.getRules().add(newRule);
|
||||
return g2;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strpbrk extends Transducer {
|
||||
|
||||
private int chrListVarIndex;
|
||||
|
||||
public Strpbrk(int target, int chr) {
|
||||
super(target);
|
||||
this.chrListVarIndex = chr;
|
||||
}
|
||||
|
||||
public Strpbrk(int chr) {
|
||||
super();
|
||||
this.chrListVarIndex = chr;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Variable chrListVar = (Variable) params.get(chrListVarIndex);
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List chrList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(chrListVar)) {
|
||||
chrList = rule.getRight();
|
||||
}
|
||||
}
|
||||
final CharSymbol[] chrListChars = (CharSymbol[]) chrList
|
||||
.toArray(new CharSymbol[0]);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
IState s1 = new State("s1");
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
finalStates.add(s1);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] {},
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !containsCharList(symbol, chrListChars);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(s0, s1, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = containsCharList(symbol, chrListChars);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
ITransition t2 = new Transition(s1, s1, v, new ISymbol[] { v });
|
||||
transitions.add(t2);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
protected boolean containsCharList(ISymbol symbol, CharSymbol[] chrListChars) {
|
||||
for (int i = 0; i < chrListChars.length; i++) {
|
||||
if (symbol.equals(chrListChars[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
|
||||
public class Strrchr extends Strchr {
|
||||
|
||||
private Strrev strrev = new Strrev();
|
||||
|
||||
public Strrchr(int needle) {
|
||||
super(needle);
|
||||
}
|
||||
|
||||
public Strrchr(int target, int needle) {
|
||||
super(target, needle);
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar sg) {
|
||||
sg = strrev.prepare(translator, funcName, recv, params, rule, sg,
|
||||
varFactory);
|
||||
sg = super.translate(sg);
|
||||
sg = strrev.prepare(translator, funcName, recv, params, rule, sg,
|
||||
varFactory);
|
||||
return sg;
|
||||
}
|
||||
}
|
|
@ -1,181 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strreplace extends Transducer {
|
||||
|
||||
private int repStrIndex;
|
||||
|
||||
private int searchStrIndex;
|
||||
|
||||
public Strreplace(int target, int search, int replace) {
|
||||
super(target);
|
||||
this.repStrIndex = replace;
|
||||
this.searchStrIndex = search;
|
||||
}
|
||||
|
||||
public Strreplace(int search, int replace) {
|
||||
super();
|
||||
this.repStrIndex = replace;
|
||||
this.searchStrIndex = search;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Variable repStrVar = (Variable) params.get(repStrIndex);
|
||||
Variable searchStrVar = (Variable) params.get(searchStrIndex);
|
||||
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List repStrList = new ArrayList();
|
||||
List searchStrList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
IVariable left = rule.getLeft();
|
||||
List right = rule.getRight();
|
||||
if (left.equals(repStrVar)) {
|
||||
repStrList = right;
|
||||
}
|
||||
else if (left.equals(searchStrVar)) {
|
||||
searchStrList = right;
|
||||
}
|
||||
}
|
||||
|
||||
final CharSymbol[] repChars = (CharSymbol[]) repStrList
|
||||
.toArray(new CharSymbol[0]);
|
||||
final CharSymbol[] searchChars = (CharSymbol[]) searchStrList
|
||||
.toArray(new CharSymbol[0]);
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(searchChars[0]);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
|
||||
IState state = s0;
|
||||
IState searchFirstState = new State("s1");
|
||||
final CharSymbol searchFirstChar = searchChars[0];
|
||||
final int searchCharsLen = searchChars.length;
|
||||
for (int i = 0; i < searchCharsLen - 1; i++) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
if (i == 0) {
|
||||
nextState = searchFirstState;
|
||||
}
|
||||
final CharSymbol searchChar = searchChars[i];
|
||||
final CharSymbol nextSearchChar = searchChars[i + 1];
|
||||
final int index = i;
|
||||
ITransition ta = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(searchChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
ITransition tb = new FilteredTransition(nextState, s0, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = new ArrayList();
|
||||
for (int j = 0; j < index + 1; j++) {
|
||||
newOutputs.add(searchChars[j]);
|
||||
}
|
||||
newOutputs.add(symbol);
|
||||
return newOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!symbol.equals(nextSearchChar))
|
||||
&& (!symbol.equals(searchFirstChar));
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(tb);
|
||||
ITransition tc = new FilteredTransition(nextState, searchFirstState, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List newOutputs = new ArrayList();
|
||||
for (int j = 0; j < index + 1; j++) {
|
||||
newOutputs.add(searchChars[j]);
|
||||
}
|
||||
return newOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (!symbol.equals(nextSearchChar))
|
||||
&& symbol.equals(searchFirstChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(tc);
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
}
|
||||
|
||||
ITransition t1 = new FilteredTransition(state, s0, v, repChars, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(searchChars[searchCharsLen - 1]);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Strrev extends StringTranslator {
|
||||
public Strrev() {
|
||||
super(TARGET_ALL);
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params, IProductionRule rule,
|
||||
SimpleGrammar g, IVariableFactory varFactory) {
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params, rule,
|
||||
g, varFactory);
|
||||
Variable target = (Variable) params.get(0);
|
||||
Set rules = (Set) g2.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List targetList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule varRule = (ProductionRule) rulesIte.next();
|
||||
if (varRule.getLeft().equals(target)) {
|
||||
targetList = varRule.getRight();
|
||||
g2.getRules().remove(varRule);
|
||||
break;
|
||||
}
|
||||
}
|
||||
List revTargetList = new ArrayList();
|
||||
for (int i = targetList.size() - 1; i >= 0; i--) {
|
||||
revTargetList.add(targetList.get(i));
|
||||
}
|
||||
g2.getRules().add(new ProductionRule(target, revTargetList));
|
||||
g2.setStartSymbol(target);
|
||||
return g2;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strrot13 extends Transducer {
|
||||
|
||||
public Strrot13(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public Strrot13() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
ITransition t1 = new FilteredTransition(s0, s0, v, new ISymbol[] { v },
|
||||
new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
// List resultOutputs = new ArrayList();
|
||||
if (symbol instanceof CharSymbol) {
|
||||
char sym = ((CharSymbol) symbol).charValue();
|
||||
if (Character.isLetter(sym)) {
|
||||
if (Character.isLowerCase(sym)) {
|
||||
return generateOutputs("a", "z", sym);
|
||||
}
|
||||
return generateOutputs("A", "Z", sym);
|
||||
}
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
private List generateOutputs(String start, String end, char sym) {
|
||||
List outputs = new ArrayList();
|
||||
CharSymbol newSym = new CharSymbol((char) (sym + 13));
|
||||
int endVal = new CharSymbol(end).charValue();
|
||||
int symToEnd = endVal - sym;
|
||||
if (symToEnd < 13) {
|
||||
int startVal = new CharSymbol(start).charValue();
|
||||
newSym = new CharSymbol((char) (startVal + 12 - symToEnd));
|
||||
}
|
||||
outputs.add(newSym);
|
||||
return outputs;
|
||||
}
|
||||
}, null);
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Strshuffle extends StringTranslator {
|
||||
|
||||
private int target;
|
||||
|
||||
public Strshuffle(int target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Strshuffle() {
|
||||
this.target = -1;
|
||||
}
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params,
|
||||
IProductionRule rule, SimpleGrammar cfg,
|
||||
IVariableFactory varFactory) {
|
||||
super.prepare(translator, funcName, recv, params, rule, cfg, varFactory);
|
||||
|
||||
ISymbol sym = (target >= 0) ? (ISymbol) params.get(target) : recv;
|
||||
|
||||
Set rules = (Set) cfg.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List targetList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule varRule = (ProductionRule) rulesIte.next();
|
||||
if (varRule.getLeft().equals(sym)) {
|
||||
targetList = varRule.getRight();
|
||||
cfg.getRules().remove(varRule);
|
||||
break;
|
||||
}
|
||||
}
|
||||
IProductionRule[] newRules = new IProductionRule[targetList.size() + 2];
|
||||
newRules[0] = new ProductionRule(new Variable("G"),
|
||||
new ISymbol[] { new Variable("A") });
|
||||
newRules[1] = new ProductionRule(new Variable("G"), new ISymbol[] {
|
||||
new Variable("A"), new Variable("G") });
|
||||
Iterator targetListIte = targetList.iterator();
|
||||
int index = 2;
|
||||
while (targetListIte.hasNext()) {
|
||||
CharSymbol chr = (CharSymbol) targetListIte.next();
|
||||
newRules[index] = new ProductionRule(new Variable("A"),
|
||||
new ISymbol[] { chr });
|
||||
index++;
|
||||
}
|
||||
ContextFreeGrammar newCfg = new ContextFreeGrammar(new Variable("G"),
|
||||
newRules);
|
||||
return newCfg;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar cfg) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar cfg, Set terminals) {
|
||||
return translate(cfg);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strsplit extends Transducer {
|
||||
|
||||
private int splitLenNumIndex;
|
||||
|
||||
public Strsplit(int target, int splitLen) {
|
||||
super(target);
|
||||
this.splitLenNumIndex = splitLen;
|
||||
}
|
||||
|
||||
public Strsplit(int splitLen) {
|
||||
super();
|
||||
this.splitLenNumIndex = splitLen;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
int splitLen = 1;
|
||||
|
||||
if (params.size() > splitLenNumIndex) {
|
||||
NumberSymbol splitLenNum = (NumberSymbol) params.get(splitLenNumIndex);
|
||||
splitLen = splitLenNum.intValue();
|
||||
}
|
||||
|
||||
IState s0 = new State("s0");
|
||||
IState s1 = new State("s1");
|
||||
IState s2 = new State("s2");
|
||||
// IState s3 = new State("s3");
|
||||
// IState s4 = new State("s4");
|
||||
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
Set transitions = new HashSet();
|
||||
|
||||
ITransition t0 = new Transition(s0, s1, Transition.EpsilonSymbol);
|
||||
ITransition t1 = new Transition(s0, s2, Transition.EpsilonSymbol);
|
||||
transitions.add(t0);
|
||||
transitions.add(t1);
|
||||
|
||||
IState state1 = s1;
|
||||
IState state2 = s2;
|
||||
int stateNumber = 3;
|
||||
for (int i = 0; i < splitLen; i++) {
|
||||
IState nextState1 = new State("s" + stateNumber);
|
||||
ITransition ta = new Transition(state1, nextState1, v, new ISymbol[] { v });
|
||||
transitions.add(ta);
|
||||
state1 = nextState1;
|
||||
finalStates.add(state1);
|
||||
stateNumber++;
|
||||
|
||||
IState nextState2 = new State("s" + stateNumber);
|
||||
ITransition tb = new Transition(state2, nextState2, v, new ISymbol[] {});
|
||||
transitions.add(tb);
|
||||
state2 = nextState2;
|
||||
finalStates.add(state2);
|
||||
stateNumber++;
|
||||
}
|
||||
|
||||
ITransition t3 = new Transition(state1, s0, Transition.EpsilonSymbol);
|
||||
transitions.add(t3);
|
||||
ITransition t4 = new Transition(state2, s0, Transition.EpsilonSymbol);
|
||||
transitions.add(t4);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strstr extends Transducer {
|
||||
|
||||
private int needleStrIndex;
|
||||
|
||||
public Strstr(int target, int needle) {
|
||||
super(target);
|
||||
this.needleStrIndex = needle;
|
||||
}
|
||||
|
||||
public Strstr(int needle) {
|
||||
super();
|
||||
this.needleStrIndex = needle;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState s0 = new State("s0");
|
||||
IState initState = s0;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(s0);
|
||||
|
||||
final Variable needleVar = (Variable) params.get(needleStrIndex);
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List needleList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(needleVar)) {
|
||||
needleList = rule.getRight();
|
||||
}
|
||||
}
|
||||
final CharSymbol[] needleChars = (CharSymbol[]) needleList
|
||||
.toArray(new CharSymbol[0]);
|
||||
|
||||
ITransition t0 = new FilteredTransition(s0, s0, v, new ISymbol[] {}, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !symbol.equals(needleChars[0]);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
IState state = s0;
|
||||
int lastIndex = needleChars.length;
|
||||
for (int i = 0; i < lastIndex - 1; i++) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
final CharSymbol needleChar = needleChars[i];
|
||||
// final CharSymbol nextNeedleChar = needleChars[i + 1];
|
||||
ITransition ta = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] {}, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(needleChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(ta);
|
||||
ITransition tb = new Transition(nextState, s0, Transition.EpsilonSymbol);
|
||||
transitions.add(tb);
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
}
|
||||
|
||||
IState nextState = new State("s" + lastIndex);
|
||||
final CharSymbol needleChar = needleChars[lastIndex - 1];
|
||||
ITransition t = new FilteredTransition(state, nextState, v, needleChars,
|
||||
null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = symbol.equals(needleChar);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept " + symbol
|
||||
+ ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
finalStates.add(state);
|
||||
ITransition t1 = new Transition(state, state, v, new ISymbol[] { v });
|
||||
transitions.add(t1);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ContextFreeGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.grammar.string.SimpleGrammar;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.IVariableFactory;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.stringAnalysis.translator.IConstraintSolver;
|
||||
|
||||
public class Strtok extends StringTranslator {
|
||||
|
||||
public SimpleGrammar prepare(IConstraintSolver translator, String funcName,
|
||||
ISymbol recv, List params, IProductionRule rule,
|
||||
SimpleGrammar g, IVariableFactory varFactory) {
|
||||
SimpleGrammar g2 = super.prepare(translator, funcName, recv, params, rule,
|
||||
g, varFactory);
|
||||
|
||||
List tokenList = getTokenList();
|
||||
|
||||
IVariable S = g2.getStartSymbol();
|
||||
IVariable G = varFactory.createVariable("G");
|
||||
List productionRuleList = new ArrayList();
|
||||
|
||||
productionRuleList.add(new ProductionRule(S, new ISymbol[] { G }));
|
||||
productionRuleList.add(new ProductionRule(S, new ISymbol[] { G, S }));
|
||||
for (int i = 0; i < 256; i++) {
|
||||
CharSymbol chr = new CharSymbol((char) i);
|
||||
if (!tokenList.contains(chr)) {
|
||||
productionRuleList.add(new ProductionRule(G, new ISymbol[] { chr }));
|
||||
}
|
||||
}
|
||||
IProductionRule[] productionRules = (ProductionRule[]) productionRuleList
|
||||
.toArray(new ProductionRule[0]);
|
||||
ContextFreeGrammar g3 = new ContextFreeGrammar(S, productionRules);
|
||||
return g3;
|
||||
}
|
||||
|
||||
private List getTokenList() {
|
||||
Variable tokenVar = (Variable) params.get(params.size() - 1);
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
List tokenList = new ArrayList();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(tokenVar)) {
|
||||
tokenList = rule.getRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return tokenList;
|
||||
}
|
||||
|
||||
public SimpleGrammar translate(SimpleGrammar g) {
|
||||
return g;
|
||||
}
|
||||
|
||||
public boolean acceptCyclic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set possibleOutputs(Set terminals) {
|
||||
return terminals;
|
||||
}
|
||||
|
||||
public SimpleGrammar translateCyclic(SimpleGrammar g, Set terminals) {
|
||||
return translate(g);
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Strtr extends Transducer {
|
||||
|
||||
private int fromStrIndex;
|
||||
|
||||
private int toStrIndex;
|
||||
|
||||
public Strtr(int target, int from, int to) {
|
||||
super(target);
|
||||
fromStrIndex = from;
|
||||
toStrIndex = to;
|
||||
}
|
||||
|
||||
public Strtr() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
Variable fromSym = (Variable) params.get(fromStrIndex);
|
||||
Variable toSym = (Variable) params.get(toStrIndex);
|
||||
List fromList = new ArrayList();
|
||||
List toList = new ArrayList();
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
IVariable left = rule.getLeft();
|
||||
if (left.equals(fromSym)) {
|
||||
fromList = rule.getRight();
|
||||
}
|
||||
else if (left.equals(toSym)) {
|
||||
toList = rule.getRight();
|
||||
}
|
||||
}
|
||||
CharSymbol[] toCharSyms = (CharSymbol[]) toList
|
||||
.toArray(new CharSymbol[0]);
|
||||
final List fromFinalList = fromList.subList(0, toCharSyms.length);
|
||||
Set transitions = new HashSet();
|
||||
IState initState = new State("s0");
|
||||
IState state = initState;
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(state);
|
||||
|
||||
for (int i = 0; i < toCharSyms.length; i++) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
finalStates.add(nextState);
|
||||
ITransition t0 = new FilteredTransition(state, state, v,
|
||||
new ISymbol[] { v }, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = !(fromFinalList.contains(symbol));
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
ITransition t1 = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] { toCharSyms[i] }, null,
|
||||
new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = fromFinalList.contains(symbol);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
state = nextState;
|
||||
}
|
||||
ITransition t0 = new Transition(state, state, v, new ISymbol[] { v });
|
||||
transitions.add(t0);
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Substr extends Transducer {
|
||||
private int begParamIndex;
|
||||
|
||||
private int lenParamIndex;
|
||||
|
||||
public Substr(int target, int beg, int n) {
|
||||
super(target);
|
||||
begParamIndex = beg;
|
||||
lenParamIndex = n;
|
||||
}
|
||||
|
||||
public Substr(int beg, int n) {
|
||||
super();
|
||||
begParamIndex = beg;
|
||||
lenParamIndex = n;
|
||||
}
|
||||
|
||||
public Substr() {
|
||||
this(1, 2);
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
FilteredTransition.ICondition anyChar = new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
return !(symbol instanceof IVariable);
|
||||
}
|
||||
};
|
||||
|
||||
NumberSymbol symBeg = (NumberSymbol) params.get(begParamIndex);
|
||||
NumberSymbol symNum = (NumberSymbol) params.get(lenParamIndex);
|
||||
|
||||
int beg = symBeg.intValue();
|
||||
int num = symNum.intValue();
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState initState = new State("s0");
|
||||
IState state = initState;
|
||||
int i = 0;
|
||||
while (i < beg) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition t = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[0], null, anyChar);
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
while (i < beg + num) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition t = new Transition(state, nextState, v, new ISymbol[] { v });
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
transitions.add(new Transition(state, state, v, new ISymbol[] {}));
|
||||
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(state);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.ProductionRule;
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.CharSymbol;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class SubstrReplace extends Transducer {
|
||||
private int begParamIndex;
|
||||
|
||||
private int lenParamIndex;
|
||||
|
||||
private int repParamIndex;
|
||||
|
||||
public SubstrReplace(int target, int rep, int beg, int len) {
|
||||
super(target);
|
||||
repParamIndex = rep;
|
||||
begParamIndex = beg;
|
||||
lenParamIndex = len;
|
||||
}
|
||||
|
||||
public SubstrReplace(int rep, int beg, int len) {
|
||||
repParamIndex = rep;
|
||||
begParamIndex = beg;
|
||||
lenParamIndex = len;
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
|
||||
NumberSymbol symBeg = (NumberSymbol) params.get(begParamIndex);
|
||||
NumberSymbol symNum = null;
|
||||
|
||||
Set rules = (Set) grammar.getRules();
|
||||
Iterator rulesIte = rules.iterator();
|
||||
|
||||
if (params.size() > lenParamIndex) {
|
||||
ISymbol lenParam = (ISymbol) params.get(lenParamIndex);
|
||||
if (lenParam instanceof NumberSymbol) {
|
||||
symNum = (NumberSymbol) params.get(lenParamIndex);
|
||||
}
|
||||
else {
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(lenParam)) {
|
||||
NumberSymbol lenNumSym = (NumberSymbol) rule.getRight().get(0);
|
||||
symNum = new NumberSymbol(lenNumSym.intValue() * -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Variable strRep = (Variable) params.get(repParamIndex);
|
||||
|
||||
int beg = symBeg.intValue();
|
||||
List rep = new ArrayList();
|
||||
|
||||
rulesIte = rules.iterator();
|
||||
while (rulesIte.hasNext()) {
|
||||
ProductionRule rule = (ProductionRule) rulesIte.next();
|
||||
if (rule.getLeft().equals(strRep)) {
|
||||
rep = rule.getRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Set transitions = new HashSet();
|
||||
IState initState = new State("s0");
|
||||
IState state = initState;
|
||||
int i = 0;
|
||||
while (i < beg) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition t = new Transition(state, nextState, v, new ISymbol[] { v });
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
while (i == beg) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
final List finalRep = rep;
|
||||
final NumberSymbol finalSymNum = symNum;
|
||||
ITransition t0 = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[] { v }, new FilteredTransition.IFilter() {
|
||||
public List invoke(ISymbol symbol, List outputs) {
|
||||
List resultOutputs = new ArrayList();
|
||||
Iterator finalRepIte = finalRep.iterator();
|
||||
while (finalRepIte.hasNext()) {
|
||||
resultOutputs.add(finalRepIte.next());
|
||||
}
|
||||
resultOutputs.add(outputs.get(0));
|
||||
// Iterator ite = resultOutputs.iterator();
|
||||
return resultOutputs;
|
||||
}
|
||||
}, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
int num = finalSymNum.intValue();
|
||||
boolean r = ((finalSymNum != null) && ((num == 0) || (num < 0)));
|
||||
if (r)
|
||||
System.err.println("(in filtered transition2: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t0);
|
||||
CharSymbol[] repCharSyms = (CharSymbol[]) rep
|
||||
.toArray(new CharSymbol[0]);
|
||||
ITransition t1 = new FilteredTransition(state, nextState, v,
|
||||
repCharSyms, null, new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
boolean r = (finalSymNum == null)
|
||||
|| (finalSymNum.intValue() != 0);
|
||||
if (r)
|
||||
System.err.println("(in filtered transition2: accept "
|
||||
+ symbol + ")");
|
||||
return r;
|
||||
}
|
||||
});
|
||||
transitions.add(t1);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
// i > beg
|
||||
if (symNum != null) {
|
||||
int num = symNum.intValue();
|
||||
if (num >= 0) {
|
||||
while (i < beg + num) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition t = new Transition(state, nextState, v,
|
||||
new ISymbol[] {});
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
transitions.add(new Transition(state, state, v, new ISymbol[] { v }));
|
||||
}
|
||||
else {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition ta = new Transition(state, state, v, new ISymbol[] {});
|
||||
transitions.add(ta);
|
||||
ITransition tb = new Transition(state, nextState, v,
|
||||
new ISymbol[] { v });
|
||||
transitions.add(tb);
|
||||
ITransition tc = new Transition(nextState, nextState, v,
|
||||
new ISymbol[] { v });
|
||||
transitions.add(tc);
|
||||
state = nextState;
|
||||
}
|
||||
}
|
||||
else {
|
||||
transitions.add(new Transition(state, state, v, new ISymbol[] {}));
|
||||
}
|
||||
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(state);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.string.Automaton;
|
||||
import com.ibm.wala.automaton.string.FilteredTransition;
|
||||
import com.ibm.wala.automaton.string.IAutomaton;
|
||||
import com.ibm.wala.automaton.string.IMatchContext;
|
||||
import com.ibm.wala.automaton.string.IState;
|
||||
import com.ibm.wala.automaton.string.ISymbol;
|
||||
import com.ibm.wala.automaton.string.ITransition;
|
||||
import com.ibm.wala.automaton.string.IVariable;
|
||||
import com.ibm.wala.automaton.string.NumberSymbol;
|
||||
import com.ibm.wala.automaton.string.State;
|
||||
import com.ibm.wala.automaton.string.Transition;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
|
||||
public class Substring extends Transducer {
|
||||
private int begParamIndex;
|
||||
|
||||
private int endParamIndex;
|
||||
|
||||
public Substring(int target, int beg, int end) {
|
||||
super(target);
|
||||
this.begParamIndex = beg;
|
||||
this.endParamIndex = end;
|
||||
}
|
||||
|
||||
public Substring(int beg, int end) {
|
||||
super();
|
||||
this.begParamIndex = beg;
|
||||
this.endParamIndex = end;
|
||||
}
|
||||
|
||||
public Substring() {
|
||||
this(1, 2);
|
||||
}
|
||||
|
||||
public IAutomaton getTransducer() {
|
||||
Variable v = new Variable("v");
|
||||
FilteredTransition.ICondition anyChar = new FilteredTransition.ICondition() {
|
||||
public boolean accept(ISymbol symbol, IMatchContext ctx) {
|
||||
return !(symbol instanceof IVariable);
|
||||
}
|
||||
};
|
||||
|
||||
NumberSymbol symBeg = (NumberSymbol) params.get(begParamIndex);
|
||||
NumberSymbol symEnd = (NumberSymbol) params.get(endParamIndex);
|
||||
|
||||
int beg = symBeg.intValue();
|
||||
int end = symEnd.intValue();
|
||||
|
||||
Set transitions = new HashSet();
|
||||
IState initState = new State("s0");
|
||||
IState state = initState;
|
||||
int i = 0;
|
||||
while (i < beg) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition t = new FilteredTransition(state, nextState, v,
|
||||
new ISymbol[0], null, anyChar);
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
while (i < end) {
|
||||
IState nextState = new State("s" + (i + 1));
|
||||
ITransition t = new Transition(state, nextState, v, new ISymbol[] { v });
|
||||
transitions.add(t);
|
||||
state = nextState;
|
||||
i++;
|
||||
}
|
||||
transitions.add(new Transition(state, state, v, new ISymbol[] {}));
|
||||
|
||||
Set finalStates = new HashSet();
|
||||
finalStates.add(state);
|
||||
|
||||
Automaton transducer = new Automaton(initState, finalStates, transitions);
|
||||
return transducer;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
public class ToLocaleLowerCase extends CharTranslator {
|
||||
public ToLocaleLowerCase(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public ToLocaleLowerCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected char[] translate(char c) {
|
||||
return new char[] { Character.toLowerCase(c) };
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
public class ToLocaleUpperCase extends CharTranslator {
|
||||
public ToLocaleUpperCase(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public ToLocaleUpperCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected char[] translate(char c) {
|
||||
return new char[] { Character.toUpperCase(c) };
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
public class ToLowerCase extends CharTranslator {
|
||||
public ToLowerCase(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public ToLowerCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected char[] translate(char c) {
|
||||
return new char[] { Character.toLowerCase(c) };
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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.stringAnalysis.translator.repository;
|
||||
|
||||
public class ToUpperCase extends CharTranslator {
|
||||
public ToUpperCase(int target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public ToUpperCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected char[] translate(char c) {
|
||||
return new char[] { Character.toUpperCase(c) };
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue