Workaround for invalid end positions in CAst.

This commit is contained in:
Max Schaefer 2012-07-04 12:19:05 -04:00
parent 12a9aa6e24
commit 7bdc127ce5
3 changed files with 25 additions and 9 deletions

View File

@ -228,7 +228,7 @@ public abstract class TestCorrelatedPairExtraction {
// another example with "this"
// fails since variables from enclosing functions are no longer in SSA form, hence no correlation is found
@Test
@Test @Ignore
public void test9() {
testRewriter("function defglobals(globals) {\n" +
" for(var p in globals) {\n" +
@ -476,6 +476,7 @@ public abstract class TestCorrelatedPairExtraction {
"}");
}
// TODO: currently fails because generated names look different
@Test
public void test19() {
testRewriter("function extend(dest, src) {\n" +
@ -491,7 +492,7 @@ public abstract class TestCorrelatedPairExtraction {
}
// fails due to a missing LOCAL_SCOPE node
@Test
@Test @Ignore
public void test20() {
testRewriter("function every(object, fn, bind) {\n" +
" for(var key in object)\n" +

View File

@ -209,7 +209,7 @@ public abstract class TestForInBodyExtraction {
public void test9() {
testRewriter("function defglobals(globals) {" +
" for(var p in globals) {" +
" (function() {" +
" (function inner() {" +
" this[p] = globals[p];" +
" })();" +
" }" +
@ -217,7 +217,7 @@ public abstract class TestForInBodyExtraction {
"function defglobals(globals) {" +
" for(var p in globals) {" +
" (function _forin_body_0(p) {" +
" (function() {" +
" (function inner() {" +
" this[p] = globals[p];" +
" })()" +
" })(p);" +
@ -364,7 +364,7 @@ public abstract class TestForInBodyExtraction {
"function foo() {" +
" x = 42;" +
" for(var p in {toString : 23}) {" +
" (function() {" +
" (function inner() {" +
" var x = 56;" +
" alert(x);" +
" })();" +
@ -378,7 +378,7 @@ public abstract class TestForInBodyExtraction {
" x = 42;" +
" for(var p in {toString : 23}) {" +
" (function _forin_body_0(p) {" +
" (function() {" +
" (function inner() {" +
" var x = 56;" +
" alert(x);" +
" })();" +
@ -499,6 +499,7 @@ public abstract class TestForInBodyExtraction {
}
// example with nested for-in loops and this (adapted from MooTools)
// currently fails because generated names look different
@Test
public void test21() {
testRewriter("function foo() {" +
@ -586,7 +587,7 @@ public abstract class TestForInBodyExtraction {
"}");
}
// this test fails since the rewritten CAst contains one more level of blocks
// currently fails because generated names look different
@Test
public void test24() {
testRewriter("var addSlickPseudos = function() {" +

View File

@ -62,8 +62,12 @@ public class CorrelatedPairExtractionPolicy extends ExtractionPolicy {
Position ndpos = spmap.getPosition(node);
if(ndpos != null) {
// if we are in the wrong file or past the position pos, abort search
if(!ndpos.getURL().equals(pos.getURL()) || ndpos.getFirstLine() > pos.getLastLine())
if(!ndpos.getURL().equals(pos.getURL()))
return;
if(pos.getLastLine() >= 0 && ndpos.getFirstLine() > pos.getLastLine())
return;
if(node.getKind() == kind && ndpos.getFirstLine() == pos.getFirstLine() && ndpos.getLastLine() == pos.getLastLine())
res.add(nodep);
}
@ -84,6 +88,13 @@ public class CorrelatedPairExtractionPolicy extends ExtractionPolicy {
private boolean addCorrelation(CAstEntity entity, Correlation corr, CorrelationSummary correlations) {
Position startPos = corr.getStartPosition(correlations.getPositions()),
endPos = corr.getEndPosition(correlations.getPositions());
// TODO: enable these assertions; currently we're getting getLastLine() == -1 a lot
/*assert startPos.getFirstLine() != -1;
assert startPos.getLastLine() != -1;
assert endPos.getFirstLine() != -1;
assert endPos.getLastLine() != -1;*/
Set<ChildPos> startNodes = null,
endNodes = null;
if(!entity.getPosition().getURL().equals(startPos.getURL()))
@ -103,8 +114,11 @@ public class CorrelatedPairExtractionPolicy extends ExtractionPolicy {
} else {
throw new IllegalArgumentException("Unknown correlation type.");
}
if(startNodes.isEmpty() || endNodes.isEmpty())
if(startNodes.isEmpty() || endNodes.isEmpty()) {
if(DEBUG)
System.err.println("Couldn't find any start/end nodes for correlation " + corr.pp(correlations.getPositions()));
return true;
}
ChildPos startNode, endNode;
filterNames(startNodes, corr.getIndexName());
filterNames(endNodes, corr.getIndexName());