Skip to content

Commit f781238

Browse files
committed
fix control-def highlighting
1 parent 704d4f3 commit f781238

12 files changed

+225938
-9
lines changed

pangor-js-diff/src/ca/ubc/ece/salt/pangor/js/diff/control/ControlCFGVisitor.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import org.mozilla.javascript.ast.FunctionNode;
1414
import org.mozilla.javascript.ast.Name;
1515

16-
import ca.ubc.ece.salt.gumtree.ast.ClassifiedASTNode.ChangeType;
1716
import ca.ubc.ece.salt.pangor.analysis.SourceCodeFileChange;
1817
import ca.ubc.ece.salt.pangor.analysis.flow.abstractdomain.Address;
18+
import ca.ubc.ece.salt.pangor.analysis.flow.abstractdomain.Change;
1919
import ca.ubc.ece.salt.pangor.analysis.flow.abstractdomain.Identifier;
2020
import ca.ubc.ece.salt.pangor.analysis.flow.abstractdomain.State;
2121
import ca.ubc.ece.salt.pangor.cfg.CFGEdge;
@@ -47,13 +47,13 @@ public void visit(CFGNode node) {
4747
public void visit(CFGEdge edge) {
4848

4949
/* If the condition has changed, it is a control flow change def. */
50-
if(edge.getCondition() != null) {
51-
AstNode condition = (AstNode)edge.getCondition();
52-
if(condition.getChangeType() != ChangeType.UNCHANGED
53-
&& condition.getChangeType() != ChangeType.UNKNOWN
54-
&& condition.getVersion() != null) {
55-
registerDefinitionFact(condition);
56-
}
50+
if(edge.getCondition() != null
51+
&& edge.getCondition().getVersion() != null
52+
&& Change.convU(edge.getCondition()).le ==
53+
Change.LatticeElement.CHANGED) {
54+
55+
registerDefinitionFact((AstNode)edge.getCondition());
56+
5757
}
5858

5959
visit((AstNode) edge.getCondition(), (State)edge.getBeforeState());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package ca.ubc.ece.salt.pangor.js.diff.main;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.util.HashMap;
6+
import java.util.LinkedList;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import ca.ubc.ece.salt.pangor.js.diff.main.SourceFile.DiffType;
11+
12+
public class DiffSearchMain {
13+
14+
public static void main(String[] args) throws Exception{
15+
DiffSearchMain metrics = new DiffSearchMain("./output/dataset_2016-08-26.csv");
16+
metrics.analyze();
17+
}
18+
19+
20+
private String datasetPath;
21+
private Map<FV, SourceFilePair> sourceFilePairs;
22+
23+
public DiffSearchMain(String datasetPath) {
24+
this.datasetPath = datasetPath;
25+
this.sourceFilePairs = new HashMap<FV, SourceFilePair>();
26+
}
27+
28+
private void analyze() throws Exception{
29+
30+
try(BufferedReader reader = new BufferedReader(new FileReader(datasetPath))) {
31+
32+
for (String line = reader.readLine();
33+
line != null;
34+
line = reader.readLine()) {
35+
36+
/* Read the feature vector. */
37+
String[] tokens = line.split(",");
38+
FV fv = new FV(tokens);
39+
40+
/* Get the source file pair for the feture vector. */
41+
SourceFilePair sfp = sourceFilePairs.get(fv);
42+
if(sfp == null) {
43+
sfp = new SourceFilePair(fv.project, fv.bfc, fv.file, fv.url);
44+
sourceFilePairs.put(fv, sfp);
45+
}
46+
47+
/* Store the feature vector. */
48+
if(fv.version.equals("SOURCE")) sfp.source.interpretFeatureVector(fv);
49+
else sfp.destination.interpretFeatureVector(fv);
50+
51+
}
52+
53+
}
54+
catch(Exception e) {
55+
System.err.println(e);
56+
}
57+
58+
Map<SourceFileDiffComparison, Integer> sem = new HashMap<SourceFileDiffComparison, Integer>();
59+
60+
/* Compute the metrics for each file. */
61+
List<SourceFileDiffComparison> destinationComparisons = new LinkedList<SourceFileDiffComparison>();
62+
for(SourceFilePair sfp : sourceFilePairs.values()) {
63+
64+
/* Destination */
65+
SourceFileDiffComparison destination = new SourceFileDiffComparison();
66+
destination.project = sfp.project;
67+
destination.commit = sfp.commit;
68+
destination.file = sfp.file;
69+
destination.url = sfp.url;
70+
destination.totalLines = sfp.destination.getTotalLines();
71+
destination.lineChanges = sfp.destination.getFactSize(DiffType.LINE);
72+
destination.astChanges = sfp.destination.getFactSize(DiffType.AST);
73+
destinationComparisons.add(destination);
74+
75+
Integer cnt = sem.get(destination.url);
76+
if(cnt == null) cnt = 1;
77+
sem.put(destination, cnt);
78+
79+
// if(destination.project.equals("pm2")) {
80+
// System.out.println(destination.url + " " + destination.project + " " + destination.file + " " + destination.commit + " " + destination.lineChanges);
81+
// }
82+
83+
}
84+
85+
for(Map.Entry<SourceFileDiffComparison, Integer> entry : sem.entrySet()) {
86+
if(entry.getValue() == 1 && entry.getKey().lineChanges > 10 && entry.getKey().lineChanges < 30) {
87+
System.out.println(entry.getKey().url + " " + entry.getKey().lineChanges);
88+
}
89+
}
90+
91+
// /* Print the metrics. */
92+
// System.out.println("\n--Destination Metrics--");
93+
// printMetrics(destinationComparisons);
94+
95+
}
96+
97+
}

pangor-js-diff/src/ca/ubc/ece/salt/pangor/js/diff/main/SourceFileDiffComparison.java

+8
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ public class SourceFileDiffComparison {
2626
public int valAstSubtraction;
2727
public int multiAstSubtraction;
2828

29+
@Override
30+
public boolean equals(Object o) {
31+
SourceFileDiffComparison a = this;
32+
SourceFileDiffComparison b = (SourceFileDiffComparison)o;
33+
if(a.url.equals(b.url)) return true;
34+
return false;
35+
}
36+
2937
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
var path = require('path'),
2+
utils = require('../utils');
3+
4+
module.exports = exec;
5+
6+
/**
7+
* Discovers all the options required to run the script
8+
* and if a custom exec has been passed in, then it will
9+
* also try to work out what extensions to monitor and
10+
* whether there's a special way of running that script.
11+
*
12+
* @param {Object} nodemonOptions
13+
* @param {Object} extensionMap
14+
* @return {Object} new and updated version of nodemonOptions
15+
*/
16+
function exec(nodemonOptions, extensionMap) {
17+
if (!extensionMap) {
18+
extensionMap = {};
19+
}
20+
21+
var options = utils.clone(nodemonOptions || {}),
22+
script = path.basename(options.script || ''),
23+
scriptExt = path.extname(script),
24+
extension = options.ext || scriptExt || 'js';
25+
26+
if (options.exec === undefined) {
27+
options.exec = 'node';
28+
} else {
29+
// allow variable substitution for {{filename}} and {{pwd}}
30+
options.exec = (options.exec || '').replace(/\{\{(filename|pwd)\}\}/, function (all, m) {
31+
if (m === 'filename') {
32+
return script || '';
33+
} else if (m === 'pwd') {
34+
return process.cwd() || '';
35+
}
36+
return all;
37+
});
38+
}
39+
40+
options.execArgs = [];
41+
42+
if (options.exec.indexOf(' ') !== -1) {
43+
var execOptions = options.exec.split(' ');
44+
options.exec = execOptions.splice(0, 1)[0];
45+
options.execArgs = execOptions;
46+
}
47+
48+
// TODO decide whether this extensionMap idea is useful or not
49+
if (extensionMap[extension] !== undefined) {
50+
options.exec = extensionMap[extension];
51+
}
52+
53+
if (options.exec === 'node' && options.nodeArgs && options.nodeArgs.length) {
54+
options.execArgs = options.execArgs.concat(options.nodeArgs);
55+
}
56+
57+
// note: indexOf('coffee') handles both .coffee and .litcoffee
58+
if (options.exec === 'node' && scriptExt.indexOf('coffee') !== -1) {
59+
options.exec = 'coffee';
60+
// ensure that we call: `coffee --nodejs ...`
61+
if (options.execArgs === undefined) {
62+
options.execArgs = [];
63+
}
64+
65+
if (options.execArgs.length && options.execArgs.indexOf('--nodejs') === -1) {
66+
options.execArgs.unshift('--nodejs');
67+
}
68+
}
69+
70+
if (options.exec === 'coffee') {
71+
// don't override user specified extension tracking
72+
if (!options.ext) {
73+
extension = '.coffee|.litcoffee|.js';
74+
}
75+
76+
// because windows can't find 'coffee', it needs the real file 'coffee.cmd'
77+
if (utils.isWindows) {
78+
options.exec += '.cmd';
79+
}
80+
}
81+
82+
// allow users to make a mistake on the extension to monitor
83+
// converts js,jade => .js$|.jade$
84+
// and 'js jade' => .js$|.jade$
85+
// BIG NOTE: user can't do this: nodemon -e *.js
86+
// because the terminal will automatically expand the glob against
87+
// the file system :(
88+
if (extension.indexOf(' ') !== -1 ||
89+
extension.indexOf(',') !== -1 ||
90+
extension.indexOf('*.') !== -1) {
91+
92+
extension = extension.replace(/\s+/g, '|') // convert spaces to pipes
93+
.replace(/,/g, '|') // convert commas to pipes
94+
.split('|') // split on those pipes
95+
.map(function (item) {
96+
return '.' + item.replace(/^[\*\.]+/, ''); // remove "*."
97+
}).join('$|'); // return regexp string like: .js$|.jade$
98+
}
99+
100+
// this final part ensures both multiple extension and
101+
// single extensions work
102+
extension += '$';
103+
104+
options.ext = extension;
105+
106+
return options;
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
var path = require('path'),
2+
utils = require('../utils');
3+
4+
module.exports = exec;
5+
6+
/**
7+
* Discovers all the options required to run the script
8+
* and if a custom exec has been passed in, then it will
9+
* also try to work out what extensions to monitor and
10+
* whether there's a special way of running that script.
11+
*
12+
* @param {Object} nodemonOptions
13+
* @param {Object} extensionMap
14+
* @return {Object} new and updated version of nodemonOptions
15+
*/
16+
function exec(nodemonOptions, extensionMap) {
17+
if (!extensionMap) {
18+
extensionMap = {};
19+
}
20+
21+
var options = utils.clone(nodemonOptions || {}),
22+
script = path.basename(options.script || '');
23+
scriptExt = path.extname(script),
24+
extension = options.ext || scriptExt || 'js';
25+
26+
if (options.exec === undefined) {
27+
options.exec = 'node';
28+
} else {
29+
// allow variable substitution for {{filename}} and {{pwd}}
30+
options.exec = (options.exec || '').replace(/\{\{(filename|pwd)\}\}/, function (all, m) {
31+
if (m === 'filename') {
32+
return script || '';
33+
} else if (m === 'pwd') {
34+
return process.cwd() || '';
35+
}
36+
return all;
37+
});
38+
}
39+
40+
options.execArgs = [];
41+
42+
if (options.exec.indexOf(' ') !== -1) {
43+
var execOptions = options.exec.split(' ');
44+
options.exec = execOptions.splice(0, 1)[0];
45+
options.execArgs = execOptions;
46+
}
47+
48+
// TODO decide whether this extensionMap idea is useful or not
49+
if (extensionMap[extension] !== undefined) {
50+
options.exec = extensionMap[extension];
51+
}
52+
53+
// note: indexOf('coffee') handles both .coffee and .litcoffee
54+
else if (options.exec === 'node' && scriptExt.indexOf('coffee') !== -1) {
55+
options.exec = 'coffee';
56+
// ensure that we call: `coffee --nodejs ...`
57+
if (options.execArgs === undefined) options.execArgs = [];
58+
59+
if (options.execArgs.indexOf('--nodejs') === -1) {
60+
options.execArgs.unshift('--nodejs');
61+
}
62+
}
63+
64+
else if (options.exec === 'node' && options.nodeArgs && options.nodeArgs.length) {
65+
options.execArgs = options.execArgs.concat(options.nodeArgs);
66+
}
67+
68+
if (options.exec === 'coffee') {
69+
// coffeescript requires --nodejs --debug
70+
// this code is a dance to get the order of the debug flags right when
71+
// combined with coffeescript
72+
if (options.nodeArgs) {
73+
options.execArgs = options.execArgs.concat(options.nodeArgs);
74+
}
75+
76+
// don't override user specified extension tracking
77+
if (!options.ext) {
78+
extension = '.coffee|.litcoffee|.js';
79+
}
80+
81+
// because windows can't find 'coffee', it needs the real file 'coffee.cmd'
82+
if (utils.isWindows) {
83+
options.exec += '.cmd';
84+
}
85+
}
86+
87+
// allow users to make a mistake on the extension to monitor
88+
// converts js,jade => .js$|.jade$
89+
// and 'js jade' => .js$|.jade$
90+
// BIG NOTE: user can't do this: nodemon -e *.js
91+
// because the terminal will automatically expand the glob against
92+
// the file system :(
93+
if (extension.indexOf(' ') !== -1 ||
94+
extension.indexOf(',') !== -1 ||
95+
extension.indexOf('*.') !== -1) {
96+
97+
extension = extension.replace(/\s+/g, '|') // convert spaces to pipes
98+
.replace(/,/g, '|') // convert commas to pipes
99+
.split('|') // split on those pipes
100+
.map(function (item) {
101+
return '.' + item.replace(/^[\*\.]+/, ''); // remove "*."
102+
}).join('$|'); // return regexp string like: .js$|.jade$
103+
}
104+
105+
// this final part ensures both multiple extension and
106+
// single extensions work
107+
extension += '$';
108+
109+
options.ext = extension;
110+
111+
return options;
112+
}

0 commit comments

Comments
 (0)