git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@636 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
79548e63d0
commit
7c28bcd479
|
@ -0,0 +1,7 @@
|
|||
<?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>
|
|
@ -0,0 +1,6 @@
|
|||
#*
|
||||
*#
|
||||
*~
|
||||
*.class
|
||||
bin
|
||||
build
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.ibm.wala.stringAnalysis.js.test</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>
|
|
@ -0,0 +1,21 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Test Plug-in
|
||||
Bundle-SymbolicName: com.ibm.domo.sa.js.test
|
||||
Bundle-Version: 1.0.0
|
||||
Bundle-Activator: com.ibm.wala.stringAnalysis.js.test.TestPlugin
|
||||
Bundle-Vendor: IBM
|
||||
Bundle-Localization: plugin
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.junit,
|
||||
com.ibm.domo.sa,
|
||||
com.ibm.capa.util.automaton,
|
||||
com.ibm.domo.js,
|
||||
com.ibm.wala.cast,
|
||||
com.ibm.domo.sa.js,
|
||||
com.ibm.domo.sa.test,
|
||||
com.ibm.domo.js.test,
|
||||
com.ibm.wala.core,
|
||||
com.ibm.wala.core.tests
|
||||
Eclipse-AutoStart: true
|
|
@ -0,0 +1,4 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
=======================================================================
|
||||
CAPA Util build file
|
||||
=======================================================================
|
||||
-->
|
||||
<project name="com.ibm.domo.sa.js.test" default="jar" basedir=".">
|
||||
<!-- Software version details -->
|
||||
<property name="name" value="domosajstest" />
|
||||
<property name="module_name" value="com.ibm.domo.sa.js.test" />
|
||||
<property name="Name" value="DOMO String Analysis for JavaScript" />
|
||||
<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="src" />
|
||||
<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.domo.sa.js.test" />
|
||||
<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" />
|
||||
|
||||
<property name="templates" value="../com.ibm.safe/templates"/>
|
||||
<property name="specifications" value="../com.ibm.safe/specifications"/>
|
||||
|
||||
<property name="excluded-tests-file" value="excluded-tests.txt" />
|
||||
|
||||
<property name="cvsroot" value="/gsa/watgsa/home/d/o/dolby/cvs/JTD"/>
|
||||
|
||||
<import file="${sharedlib}/scripts/common-tests-targets.xml"/>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test;
|
||||
|
||||
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 TestPlugin extends AbstractUIPlugin {
|
||||
|
||||
//The shared instance.
|
||||
private static TestPlugin plugin;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public TestPlugin() {
|
||||
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 TestPlugin 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.test", path);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
function foo(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
a = "strA";
|
||||
b = "strB";
|
||||
c = foo(a, b);
|
|
@ -0,0 +1,15 @@
|
|||
function puts(doc, x){
|
||||
doc.write(x);
|
||||
}
|
||||
|
||||
document.write("a");
|
||||
if (condition) {
|
||||
puts(document, "b");
|
||||
//document.write("b");
|
||||
}
|
||||
else {
|
||||
puts(document, "B");
|
||||
//document.write("B");
|
||||
}
|
||||
document.write("c");
|
||||
result = document;
|
|
@ -0,0 +1,15 @@
|
|||
function foo(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
function bar(n, bx, by) {
|
||||
var s = bx;
|
||||
for (var i=0; i<n; i++) {
|
||||
s = foo(s, by);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
a = "strA";
|
||||
b = "strB";
|
||||
c = bar(10, a, b);
|
|
@ -0,0 +1,138 @@
|
|||
function foo(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
function bar(n, s) {
|
||||
if (n == 0) {
|
||||
return s;
|
||||
}
|
||||
return "a" + bar(n-1, s) + "b";
|
||||
}
|
||||
|
||||
// simple concatenation
|
||||
a = "strA";
|
||||
b = "strB";
|
||||
r1 = foo(a, b);
|
||||
document.write("r1: " + r1 + "<br/>");
|
||||
|
||||
// conditional branch
|
||||
if (a == "strA") {
|
||||
r2 = foo("a", a);
|
||||
}
|
||||
else {
|
||||
r2 = foo("b", b);
|
||||
}
|
||||
document.write("r2: " + r2 + "<br/>");
|
||||
|
||||
// for-loop statement
|
||||
r3 = a;
|
||||
for (var i = 0; i<10; i++) {
|
||||
r3 = r3 + b;
|
||||
}
|
||||
document.write("r3: " + r3 + "<br/>");
|
||||
|
||||
// while-loop
|
||||
r4 = a;
|
||||
while (r4.length<20) {
|
||||
r4 = r4 + b;
|
||||
}
|
||||
document.write("r4: " + r4 + "<br/>");
|
||||
|
||||
// recursive function
|
||||
r5 = bar(5, a);
|
||||
document.write("r5: " + r5 + "<br/>");
|
||||
|
||||
// array
|
||||
r10 = ["ARY", a, b];
|
||||
r11 = r10[1];
|
||||
|
||||
// associative array
|
||||
r20 = {"KA":a, "KB":b, "KC":"ASSOC"};
|
||||
r21 = r20["KC"];
|
||||
|
||||
// constructor & property
|
||||
function FooClass(){
|
||||
this.name = "foo";
|
||||
this.code = 123;
|
||||
}
|
||||
var fooObj = new FooClass();
|
||||
rProp1 = fooObj.name;
|
||||
document.write("rProp1: " + rProp1 + "<br/>");
|
||||
|
||||
// closure
|
||||
function myFunc1() {
|
||||
var lvar = "local variable";
|
||||
var f = function(){ return lvar; };
|
||||
return f;
|
||||
}
|
||||
|
||||
myFunc2 = function() {
|
||||
var lvar = "local variable";
|
||||
var f = function(){ return lvar; };
|
||||
var g = function(){
|
||||
var lvar = "local variable2";
|
||||
return function(){ return lvar; };
|
||||
};
|
||||
return [f,g];
|
||||
}
|
||||
|
||||
// pre-defined functions
|
||||
rSubstr1 = a.substring(0, 3);
|
||||
document.write("rSubstr1: " + rSubstr1 + "<br/>");
|
||||
|
||||
if (a.length > 4) {
|
||||
rSubstr2 = a.substring(0, 3);
|
||||
}
|
||||
else {
|
||||
rSubstr2 = b.substring(3, 4);
|
||||
}
|
||||
document.write("rSubstr2: " + rSubstr2 + "<br/>");
|
||||
|
||||
rSubstr3 = a.substr(1,3);
|
||||
document.write("rSubstr3: " + rSubstr3 + "<br/>");
|
||||
|
||||
rToUpperCase1 = a.toUpperCase();
|
||||
document.write("rToUpperCase1: " + rToUpperCase1 + "<br/>");
|
||||
|
||||
rToLowerCase1 = a.toLowerCase();
|
||||
document.write("rToLowerCase1: " + rToLowerCase1 + "<br/>");
|
||||
|
||||
rToLocaleUpperCase1 = a.toLocaleUpperCase();
|
||||
document.write("rToLocaleUpperCase1: " + rToLocaleUpperCase1 + "<br/>");
|
||||
|
||||
rToLocaleLowerCase1 = a.toLocaleLowerCase();
|
||||
document.write("rToLocaleLowerCase1: " + rToLocaleLowerCase1 + "<br/>");
|
||||
|
||||
rIndexOf1 = a.indexOf("r");
|
||||
document.write("rIndexOf1: " + rIndexOf1 + "<br/>");
|
||||
|
||||
rConcat1 = a.concat(b,b,b);
|
||||
document.write("rConcat1: " + rConcat1 + "<br/>");
|
||||
|
||||
rCharAt1 = a.charAt(1);
|
||||
document.write("rCharAt1: " + rCharAt1 + "<br/>");
|
||||
|
||||
rCharAt2 = a.charAt(4);
|
||||
document.write("rCharAt2: " + rCharAt2 + "<br/>");
|
||||
|
||||
rSplit1 = "a:b:c".split(":");
|
||||
document.write("rSplit1: " + rSplit1 + "<br/>");
|
||||
|
||||
// for-loop with function calls
|
||||
r40 = "abcdefg";
|
||||
for (var i = 0; i < 1; i++) {
|
||||
r40 = r40.substr(1, 3);
|
||||
}
|
||||
rCyclic1 = r40;
|
||||
document.write("rSplitCyclic1: " + rCyclic1 + "<br/>");
|
||||
|
||||
// non-constant parameters
|
||||
var s40 = "abc"
|
||||
if (cond) {
|
||||
s40 = s40.substr(1,2);
|
||||
}
|
||||
else {
|
||||
s40 = s40.substr(0,2);
|
||||
}
|
||||
r40 = "abc".replace("c",s40);
|
||||
document.write("r40: " + r40 + "<br />");
|
|
@ -0,0 +1,79 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ssa.*;
|
||||
import com.ibm.wala.ssa.SSACFG.BasicBlock;
|
||||
import com.ibm.wala.stringAnalysis.js.translator.JSSSA2Rule;
|
||||
import com.ibm.wala.stringAnalysis.translator.*;
|
||||
|
||||
public class TestBB2GR extends TestJSTranslatorBase {
|
||||
private Set getInstructions(TranslationContext ctx, BasicBlock bb) {
|
||||
Set l = new HashSet();
|
||||
SSAInstruction instructions[] = ctx.getIR().getInstructions();
|
||||
int first = bb.getFirstInstructionIndex();
|
||||
int last = bb.getLastInstructionIndex();
|
||||
for (int i = first; i <= last; i++) {
|
||||
l.add(instructions[i]);
|
||||
}
|
||||
for (Iterator i = bb.iteratePhis(); i.hasNext(); ) {
|
||||
SSAPhiInstruction phi = (SSAPhiInstruction) i.next();
|
||||
l.add(phi);
|
||||
}
|
||||
for (Iterator i = bb.iteratePis(); i.hasNext(); ) {
|
||||
SSAPiInstruction pi = (SSAPiInstruction) i.next();
|
||||
l.add(pi);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private int getNumberOfRules(TranslationContext ctx, BasicBlock bb, ISSA2Rule ssa2rule) {
|
||||
Set l = getInstructions(ctx, bb);
|
||||
return getNumberOfRules(ctx, l, ssa2rule);
|
||||
}
|
||||
|
||||
private int getNumberOfRules(TranslationContext ctx, Set instructions, ISSA2Rule ssa2rule) {
|
||||
int n = 0;
|
||||
for (Iterator i = instructions.iterator(); i.hasNext(); ) {
|
||||
SSAInstruction instruction = (SSAInstruction) i.next();
|
||||
n = n + ssa2rule.translate(instruction, ctx).size();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public void testTranslate() {
|
||||
for (ListIterator i = getIRs().listIterator(); i.hasNext(); ) {
|
||||
int idx = i.nextIndex();
|
||||
IR ir = (IR) i.next();
|
||||
CGNode node = (CGNode) getCGNodes().get(idx);
|
||||
SSA2Rule ssa2rule = new JSSSA2Rule();
|
||||
BB2GR bb2gr = new BB2GR(ssa2rule);
|
||||
SSACFG cfg = ir.getControlFlowGraph();
|
||||
TranslationContext ctx = new TranslationContext(ir, node, null, getCallGraphBuilder());
|
||||
for (Iterator n = cfg.iterateNodes(); n.hasNext(); ) {
|
||||
IBasicBlock bb = (IBasicBlock) n.next();
|
||||
IGrammar gr = bb2gr.translate(bb, ctx);
|
||||
assertNotNull(gr);
|
||||
int nr = getNumberOfRules(ctx, (BasicBlock)bb, ssa2rule);
|
||||
Set rules = gr.getRules();
|
||||
assertEquals(nr, rules.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
import com.ibm.wala.stringAnalysis.js.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.util.*;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public class TestCG2GR extends TestJSTranslatorBase {
|
||||
|
||||
public void testTranslate() {
|
||||
SSA2Rule ssa2rule = new JSSSA2Rule();
|
||||
BB2GR bb2gr = new BB2GR(ssa2rule);
|
||||
IR2GR ir2gr = new IR2GR(bb2gr);
|
||||
CG2GR cg2gr = new CG2GR(ir2gr, new FunctionNameCalleeResolver(new JSFunctionNameResolver()));
|
||||
ISimplify g = cg2gr.translate(getCallGraphBuilder());
|
||||
assertTrue(g instanceof GR);
|
||||
GR gr = (GR) g;
|
||||
//Trace.println("--- GR:");
|
||||
//Trace.println(SAUtil.prettyFormat(gr));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
import com.ibm.wala.stringAnalysis.js.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public class TestGR2CFG extends TestJSTranslatorBase {
|
||||
private GR gr;
|
||||
private GR2CFG gr2cfg;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ISSA2Rule ssa2rule = createSSA2Rule();
|
||||
BB2GR bb2gr = new BB2GR(ssa2rule);
|
||||
IR2GR ir2gr = new IR2GR(bb2gr);
|
||||
CG2GR cg2gr = new CG2GR(ir2gr, new FunctionNameCalleeResolver(new JSFunctionNameResolver()));
|
||||
gr2cfg = new GR2CFG(new JSTranslatorRepository());
|
||||
ISimplify g = cg2gr.translate(getCallGraphBuilder());
|
||||
assertTrue(g instanceof GR);
|
||||
gr = (GR) g;
|
||||
}
|
||||
|
||||
protected ISSA2Rule createSSA2Rule() {
|
||||
return new JSSSA2Rule();
|
||||
}
|
||||
|
||||
protected IContextFreeGrammar verifyCFG(IVariable v, String pattern) {
|
||||
return verifyCFG(v, pattern(pattern));
|
||||
}
|
||||
|
||||
protected IContextFreeGrammar verifyCFG(IVariable v, IAutomaton pattern) {
|
||||
IContextFreeGrammar cfg = gr2cfg.solve(gr, v);
|
||||
Trace.println("-- context-free grammar for " + v + ": ");
|
||||
Trace.println(SAUtil.prettyFormat(cfg));
|
||||
Trace.println("-- context-free grammar for " + v + ": ");
|
||||
Grammars.normalize(cfg, null);
|
||||
Trace.println(SAUtil.prettyFormat(cfg));
|
||||
super.verifyCFG(pattern, cfg);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public void testConcat() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("r1"), "strAstrB");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA" + "strB")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA" + "strB" + "strB")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strAstrB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA(strB)*")));
|
||||
}
|
||||
|
||||
|
||||
public void testConditionalBranch() {
|
||||
IVariable r2 = new LexicalVariable("r2");
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("r2"), "astrA|bstrB");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("a" + "strA")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("b" + "strB")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("a" + "strB")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("b" + "strA")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("astrA|bstrB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("(a|b)(strA|strB)")));
|
||||
}
|
||||
|
||||
|
||||
public void testForLoop() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("r3"), "strA(strB)*");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA" + "strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA" + "strB" + "strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA(strB)*")));
|
||||
}
|
||||
|
||||
public void testWhileLoop() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("r4"), "strA(strB)*");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA" + "strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA" + "strB" + "strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA(strB)*")));
|
||||
}
|
||||
|
||||
public void testRecursiveFunction() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("r5"), "a*strAb*");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("astrAb")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("aastrAbb")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strAa")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("bstrA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("bstrAa")));
|
||||
}
|
||||
|
||||
public void testArray1() {
|
||||
IContextFreeGrammar cfg2 = verifyCFG(new LexicalVariable("r11"), "ARY|strA|strB");
|
||||
assertTrue(CFLReachability.containsSome(cfg2, pattern("ARY")));
|
||||
assertTrue(CFLReachability.containsSome(cfg2, pattern("strA")));
|
||||
assertTrue(CFLReachability.containsSome(cfg2, pattern("strB")));
|
||||
}
|
||||
|
||||
public void testAssocArray1() {
|
||||
//TODO:
|
||||
//assertTrue(CFLReachability.containsAll(pattern("strA|strB|ASSOC"), cfg));
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("r21"), "ASSOC");
|
||||
}
|
||||
|
||||
public void testSubstring1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rSubstr1"), "str");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("str")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
}
|
||||
|
||||
public void testSubstring2() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rSubstr2"), "str|B");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("str")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("B")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strB")));
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("str|B")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA|strB")));
|
||||
}
|
||||
|
||||
public void testSubstr3() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rSubstr3"), "trA");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("trA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("str")));
|
||||
}
|
||||
|
||||
public void testToUpperCase1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rToUpperCase1"), "STRA");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("STRA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("stra")));
|
||||
}
|
||||
|
||||
public void testToLowerCase1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rToLowerCase1"), "stra");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("stra")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("STRA")));
|
||||
}
|
||||
|
||||
public void testToLocaleUpperCase1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rToLocaleUpperCase1"), "STRA");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("STRA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("stra")));
|
||||
}
|
||||
|
||||
public void testToLocaleLowerCase1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rToLocaleLowerCase1"), "stra");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("stra")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("strA")));
|
||||
assertFalse(CFLReachability.containsSome(cfg, pattern("STRA")));
|
||||
}
|
||||
|
||||
public void testConcat1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rConcat1"), "strA(strB)*");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("strAstrBstrBstrB")));
|
||||
assertTrue(CFLReachability.containsAll(pattern("strAstrBstrBstrB"), cfg));
|
||||
}
|
||||
|
||||
public void testCharAt1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rCharAt1"), "t");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("t")));
|
||||
}
|
||||
|
||||
public void testCharAt2() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rCharAt2"), "");
|
||||
assertTrue(CFLReachability.containsSome(cfg, pattern("")));
|
||||
assertFalse(CFLReachability.containsAll(pattern("."), cfg));
|
||||
}
|
||||
|
||||
public void testSplit1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rSplit1"), "a|b|c|()");
|
||||
}
|
||||
|
||||
public void testProp1() {
|
||||
/*
|
||||
IAutomaton spec =
|
||||
Automatons.createUnion(
|
||||
pattern("foo"),
|
||||
Automatons.createAutomaton(new ISymbol[]{new NumberSymbol(123.0)}));
|
||||
*/
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rProp1"), pattern("foo"));
|
||||
}
|
||||
|
||||
public void testCyclic1() {
|
||||
IContextFreeGrammar cfg = verifyCFG(new LexicalVariable("rCyclic1"), "(abcdefg)|(bcd)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
import com.ibm.wala.automaton.grammar.string.IGrammar;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.automaton.string.Variable;
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ssa.IR;
|
||||
import com.ibm.wala.ssa.SSACFG;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SSAPhiInstruction;
|
||||
import com.ibm.wala.ssa.SSAPiInstruction;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GR;
|
||||
import com.ibm.wala.stringAnalysis.grammar.GRule;
|
||||
import com.ibm.wala.stringAnalysis.js.translator.JSSSA2Rule;
|
||||
import com.ibm.wala.stringAnalysis.translator.BB2GR;
|
||||
import com.ibm.wala.stringAnalysis.translator.IR2GR;
|
||||
import com.ibm.wala.stringAnalysis.translator.SSA2Rule;
|
||||
import com.ibm.wala.stringAnalysis.translator.TranslationContext;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestIR2GR extends TestJSTranslatorBase {
|
||||
public void testTranslate() {
|
||||
for (ListIterator i = getIRs().listIterator(); i.hasNext(); ) {
|
||||
int idx = i.nextIndex();
|
||||
IR ir = (IR) i.next();
|
||||
CGNode node = (CGNode) getCGNodes().get(idx);
|
||||
TranslationContext ctx = new TranslationContext(ir, node, null, getCallGraphBuilder());
|
||||
SSA2Rule ssa2rule = new JSSSA2Rule();
|
||||
BB2GR bb2gr = new BB2GR(ssa2rule);
|
||||
IR2GR ir2gr = new IR2GR(bb2gr);
|
||||
IGrammar g = ir2gr.translate(ctx);
|
||||
assertTrue(g instanceof GR);
|
||||
GR gr = (GR) g;
|
||||
SSAInstruction instructions[] = ir.getInstructions();
|
||||
|
||||
Trace.println("--- IR:");
|
||||
Trace.println(ir);
|
||||
Trace.println("");
|
||||
Trace.println("--- GR:");
|
||||
Trace.println(SAUtil.prettyFormat(gr));
|
||||
|
||||
int ni = 0;
|
||||
for (int j = 0; j<instructions.length; j++) {
|
||||
if (instructions[j] != null) {
|
||||
Collection translated = ssa2rule.translate(instructions[j], ctx);
|
||||
ni += translated.size();
|
||||
int def = instructions[j].getDef();
|
||||
List rules = new ArrayList(gr.getRules(new Variable("v" + def)));
|
||||
for (Iterator k = rules.iterator(); k.hasNext(); ) {
|
||||
IProductionRule rule = (IProductionRule) k.next();
|
||||
assertTrue(rule instanceof GRule);
|
||||
GRule grule = (GRule) rule;
|
||||
assertEquals(instructions[j], grule.getSSAInstruction());
|
||||
}
|
||||
}
|
||||
}
|
||||
int nrp = 0;
|
||||
int nip = 0;
|
||||
int nr = g.getRules().size();
|
||||
for (Iterator j = gr.getRules().iterator(); j.hasNext(); ) {
|
||||
GRule grule = (GRule) j.next();
|
||||
if (grule.getSSAInstruction() instanceof SSAPhiInstruction) {
|
||||
nrp ++;
|
||||
}
|
||||
else if (grule.getSSAInstruction() instanceof SSAPiInstruction) {
|
||||
nrp ++;
|
||||
}
|
||||
}
|
||||
assertEquals(ni, nr - nrp);
|
||||
|
||||
for (Iterator j = ir.iteratePhis(); j.hasNext(); ) {
|
||||
SSAPhiInstruction phi = (SSAPhiInstruction) j.next();
|
||||
Set<Integer> s = new HashSet<Integer>();
|
||||
for (int k = 0; k < phi.getNumberOfUses(); k++) {
|
||||
s.add(phi.getUse(k));
|
||||
}
|
||||
nip += s.size();
|
||||
}
|
||||
for (Iterator j = ir.iteratePis(); j.hasNext(); ) {
|
||||
SSAPiInstruction pi = (SSAPiInstruction) j.next();
|
||||
Set<Integer> s = new HashSet<Integer>();
|
||||
for (int k = 0; k < pi.getNumberOfUses(); k++) {
|
||||
s.add(pi.getUse(k));
|
||||
}
|
||||
nip += s.size();
|
||||
}
|
||||
assertEquals(ni + nip, nr);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.stringAnalysis.test.translator.TestTranslatorBase;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.cast.js.test.*;
|
||||
import com.ibm.wala.classLoader.*;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.*;
|
||||
|
||||
abstract public class TestJSTranslatorBase extends TestTranslatorBase {
|
||||
static private ClassLoader loader =
|
||||
TestJSTranslatorBase.class.getClassLoader();
|
||||
|
||||
protected PropagationCallGraphBuilder makeCallGraphBuilder() {
|
||||
return makeCallGraphBuilder("test.js");
|
||||
}
|
||||
|
||||
protected PropagationCallGraphBuilder makeCallGraphBuilder(String testFile) {
|
||||
try {
|
||||
URL url = loader.getResource("com/ibm/wala/stringAnalysis/js/test/example/" + testFile);
|
||||
PropagationCallGraphBuilder builder =
|
||||
Util.makeCGBuilder(
|
||||
new SourceFileModule[]{
|
||||
Util.makeSourceModule(url, testFile) });
|
||||
builder.makeCallGraph( builder.getOptions() );
|
||||
return builder;
|
||||
} catch (IOException e) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import com.ibm.wala.stringAnalysis.translator.*;
|
||||
|
||||
public class TestLexicalGR2CFG extends TestGR2CFG {
|
||||
protected ISSA2Rule createSSA2Rule() {
|
||||
//return new SSA2LexicalRule(super.createSSA2Rule());
|
||||
return super.createSSA2Rule();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.automaton.grammar.string.IProductionRule;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalRead;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalWrite;
|
||||
import com.ibm.wala.cast.js.ssa.JavaScriptPropertyRead;
|
||||
import com.ibm.wala.cast.js.ssa.JavaScriptPropertyWrite;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.impl.FakeRootClass;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
||||
import com.ibm.wala.ssa.*;
|
||||
import com.ibm.wala.stringAnalysis.grammar.InvocationSymbol;
|
||||
import com.ibm.wala.stringAnalysis.js.ssa.SAJSProcessingInstructionVisitor;
|
||||
import com.ibm.wala.stringAnalysis.js.translator.JSSSA2Rule;
|
||||
import com.ibm.wala.stringAnalysis.ssa.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.SSA2Rule;
|
||||
import com.ibm.wala.stringAnalysis.translator.TranslationContext;
|
||||
|
||||
public class TestSSA2Rule extends TestJSTranslatorBase {
|
||||
public IProductionRule firstRule(Collection rules) {
|
||||
return (IProductionRule) (new ArrayList(rules)).get(0);
|
||||
}
|
||||
|
||||
public void testTranslate() {
|
||||
final PropagationCallGraphBuilder cgbuilder = getCallGraphBuilder();
|
||||
final SSA2Rule s2r = new JSSSA2Rule();
|
||||
for (ListIterator i = getIRs().listIterator(); i.hasNext(); ) {
|
||||
int idx = i.nextIndex();
|
||||
final IR ir = (IR) i.next();
|
||||
final CGNode node = (CGNode) getCGNodes().get(idx);
|
||||
final TranslationContext ctx = new TranslationContext(ir, node, null, cgbuilder);
|
||||
SSAInstructionProcessor.eachInstruction(
|
||||
ir.getInstructions(),
|
||||
new SAJSProcessingInstructionVisitor(
|
||||
new SAJSProcessingInstructionVisitor.Processor() {
|
||||
public void onUnsupportedInstruction(SSAInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), 0);
|
||||
}
|
||||
|
||||
public void onSSAAbstractInvokeInstruction(SSAAbstractInvokeInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
if (instruction.getDeclaredTarget().getDeclaringClass().equals(FakeRootClass.FAKE_ROOT_CLASS)) {
|
||||
assertEquals(rules.size(), 0);
|
||||
}
|
||||
else {
|
||||
assertEquals(rules.size(), 1);
|
||||
IProductionRule rule = firstRule(rules);
|
||||
Trace.println(rule);
|
||||
assertTrue(rule.getRight(0) instanceof InvocationSymbol);
|
||||
InvocationSymbol isym = (InvocationSymbol) rule.getRight(0);
|
||||
assertEquals(instruction.getNumberOfParameters()-1, isym.getParameters().size());
|
||||
}
|
||||
}
|
||||
|
||||
public void onSSABinaryOpInstruction(SSABinaryOpInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), 1);
|
||||
|
||||
IProductionRule rule = firstRule(rules);
|
||||
Trace.println(rule);
|
||||
assertEquals(1, rule.getRight().size());
|
||||
assertTrue(rule.getRight(0) instanceof InvocationSymbol);
|
||||
InvocationSymbol isym = (InvocationSymbol) rule.getRight(0);
|
||||
assertEquals(2, isym.getParameters().size());
|
||||
}
|
||||
|
||||
public void onSSAAbstractUnaryInstruction(SSAAbstractUnaryInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), 1);
|
||||
|
||||
IProductionRule rule = firstRule(rules);
|
||||
Trace.println(rule);
|
||||
assertEquals(1, rule.getRight().size());
|
||||
assertTrue(rule.getRight(0) instanceof InvocationSymbol);
|
||||
InvocationSymbol isym = (InvocationSymbol) rule.getRight(0);
|
||||
assertEquals(1, isym.getParameters().size());
|
||||
}
|
||||
|
||||
public void onJavaScriptPropertyRead(JavaScriptPropertyRead instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertTrue(rules.size() > 1);
|
||||
}
|
||||
|
||||
public void onSSAGetInstruction(SSAGetInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertTrue(rules.size() > 1);
|
||||
}
|
||||
|
||||
public void onJavaScriptPropertyWrite(JavaScriptPropertyWrite instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(2, rules.size());
|
||||
|
||||
IProductionRule rule = firstRule(rules);
|
||||
Trace.println(rule);
|
||||
assertEquals(1, rule.getRight().size());
|
||||
}
|
||||
|
||||
public void onSSAPutInstruction(SSAPutInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(2, rules.size());
|
||||
|
||||
IProductionRule rule = firstRule(rules);
|
||||
Trace.println(rule);
|
||||
assertEquals(1, rule.getRight().size());
|
||||
}
|
||||
|
||||
public void onSSANewInstruction(SSANewInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), 0);
|
||||
|
||||
// TODO: how do we handle the "NEW" instruction?
|
||||
// Currently, it is considered as an empty set.
|
||||
//IProductionRule rule = firstRule(rules);
|
||||
//Trace.println(rule);
|
||||
//assertEquals(0, rule.getRight().size());
|
||||
}
|
||||
|
||||
public void onSSAPhiInstruction(SSAPhiInstruction instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), 2);
|
||||
|
||||
IProductionRule rule = firstRule(rules);
|
||||
Trace.println(rule);
|
||||
assertEquals(2, rule.getRight().size());
|
||||
}
|
||||
|
||||
public void onSSAConditionalBranchInstruction(SSAConditionalBranchInstruction instruction) {
|
||||
onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void onSSAReturnInstruction(SSAReturnInstruction instruction) {
|
||||
onUnsupportedInstruction(instruction);
|
||||
}
|
||||
|
||||
public void onAstLexicalRead(AstLexicalRead instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), instruction.getAccessCount());
|
||||
}
|
||||
|
||||
public void onAstLexicalWrite(AstLexicalWrite instruction) {
|
||||
Collection rules = s2r.translate(instruction, ctx);
|
||||
assertEquals(rules.size(), instruction.getAccessCount());
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/******************************************************************************
|
||||
* 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.js.test.translator;
|
||||
|
||||
import com.ibm.wala.stringAnalysis.grammar.*;
|
||||
import com.ibm.wala.stringAnalysis.js.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.translator.*;
|
||||
import com.ibm.wala.stringAnalysis.util.SAUtil;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.automaton.grammar.string.*;
|
||||
import com.ibm.wala.automaton.string.*;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.*;
|
||||
|
||||
public class TestSideEffect extends TestJSTranslatorBase {
|
||||
private GR gr;
|
||||
private GR2CFG gr2cfg;
|
||||
private ISimplify approximation;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
SSA2Rule ssa2rule = new JSSSA2Rule();
|
||||
BB2GR bb2gr = new BB2GR(ssa2rule);
|
||||
IR2GR ir2gr = new IR2GR(bb2gr);
|
||||
CG2GR cg2gr = new CG2GR(ir2gr, new FunctionNameCalleeResolver(new JSFunctionNameResolver()));
|
||||
gr2cfg = new GR2CFG(new JSTranslatorRepository());
|
||||
gr = (GR) cg2gr.translate(getCallGraphBuilder());
|
||||
ControlledGrammars.inlineExpansion(gr);
|
||||
approximation = new SideEffectSolver(gr, new String[]{"write"}, new String[]{});
|
||||
approximation = new RuleAdder(approximation, new IProductionRule[]{
|
||||
new ProductionRule(new LexicalVariable("document"), new ISymbol[]{}),
|
||||
});
|
||||
}
|
||||
|
||||
protected PropagationCallGraphBuilder makeCallGraphBuilder() {
|
||||
return makeCallGraphBuilder("output.js");
|
||||
}
|
||||
|
||||
public void testSideEffectSolver1() {
|
||||
Trace.println("-- gr:");
|
||||
Trace.println(SAUtil.prettyFormat(gr));
|
||||
IContextFreeGrammar cfg = gr2cfg.solve(approximation, new LexicalVariable("result"));
|
||||
Trace.println(SAUtil.prettyFormat(cfg));
|
||||
|
||||
IAutomaton abc = pattern("a(b|B)c");
|
||||
verifyCFG(abc, cfg);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue