Skip to content

Commit 7207c61

Browse files
committed
Added sample prolog for reference.
1 parent e1b9e37 commit 7207c61

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

core/prolog/query_example.pl

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
%% %%%%%%%%%%%%%%%%%%%%
2+
%% Define the possible predicates.
3+
%% %%%%%%%%%%%%%%%%%%%%
4+
5+
% destination_protected_dereference := protected a dereferenced variable by adding a branch condition
6+
% arg1 := the function identifier
7+
% arg2 := the name of the identifier (variable, field, or function return value) being dereferenced.
8+
%:- multifile(destination_protected_dereference/2).
9+
destination_protected_dereference(_,_) :- fail.
10+
11+
% source_unprotected_dereference := unprotected a dereferenced variable by removing a branch condition
12+
% arg1 := the function identifier
13+
% arg2 := the name of the identifier (variable, field, or function return value) being dereferenced.
14+
%:- multifile(source_unprotected_dereference/2).
15+
source_unprotected_dereference(_,_) :- fail.
16+
17+
%% %%%%%%%%%%%%%%%%%%%%
18+
%% Define the rules.
19+
%% %%%%%%%%%%%%%%%%%%%%
20+
21+
% Alert for when a variable is protected by a conditional
22+
alert_undefined_protected(X, Y) :- destination_protected_dereference(X, Y), \+ source_unprotected_dereference(X, Y).
23+
24+
%% %%%%%%%%%%%%%%%%%%%%
25+
%% Create some facts for testing.
26+
%% %%%%%%%%%%%%%%%%%%%%
27+
28+
source_unprotected_dereference('script.~anonymous~', 'error').
29+
destination_protected_dereference('script.~anonymous~', 'error').
30+
31+
destination_protected_dereference('script.getName', 'error').
32+
33+
destination_protected_dereference('script.getEMail', 'error').
34+
35+
%% %%%%%%%%%%%%%%%%%%%%
36+
%% Query the rules to find instances.
37+
%% %%%%%%%%%%%%%%%%%%%%
38+
39+
?- findall([X,Y], alert_undefined_protected(X,Y),Z).

core/src/ca/ubc/ece/salt/pangor/analysis/CommitAnalysis.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import ca.ubc.ece.salt.pangor.cfg.CFGFactory;
1313

1414
/**
15-
* Gathers facts about one commit and synthesizes alerts based on those facts.
15+
* Gathers facts about one commit and runs queries in prolog against those
16+
* facts to synthesize alerts.
1617
*
1718
* @param <A> The type of alert the data set stores.
1819
* @param <DS> The type of data set that stores the analysis results.

java-classify/test/src/ca/ubc/ece/salt/pangor/java/test/methodrename/TestRenameRefactoringBatchAnalysis.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import ca.ubc.ece.salt.pangor.analysis.CommitAnalysis;
88
import ca.ubc.ece.salt.pangor.analysis.classify.ClassifierAlert;
99
import ca.ubc.ece.salt.pangor.analysis.classify.ClassifierDataSet;
10-
import ca.ubc.ece.salt.pangor.analysis.simple.SimpleCFGFactory;
1110
import ca.ubc.ece.salt.pangor.batch.GitProjectAnalysis;
1211
import ca.ubc.ece.salt.pangor.java.analysis.ClassAnalysis;
1312
import ca.ubc.ece.salt.pangor.java.analysis.methodrename.RenameMethodDstAnalysis;
1413
import ca.ubc.ece.salt.pangor.java.analysis.methodrename.RenameMethodSrcAnalysis;
14+
import ca.ubc.ece.salt.pangor.java.cfg.JavaCFGFactory;
1515

1616
public class TestRenameRefactoringBatchAnalysis {
1717

@@ -30,7 +30,7 @@ public void test() throws IOException, Exception {
3030
new RenameMethodDstAnalysis());
3131

3232
/* The SimpleCFGFactory doesn't do anything, so it is generic to any file type. */
33-
SimpleCFGFactory cfgFactory = new SimpleCFGFactory();
33+
JavaCFGFactory cfgFactory = new JavaCFGFactory();
3434

3535
/* Set up the commit analysis (analyzes one commit). */
3636
CommitAnalysis<ClassifierAlert, ClassifierDataSet,
@@ -43,7 +43,9 @@ public void test() throws IOException, Exception {
4343

4444
/* Set up the project analysis (analyzes one project). */
4545
GitProjectAnalysis projectAnalysis = GitProjectAnalysis.fromURI(
46-
"https://github.com/naman14/Timber.git", "./repositories/",
46+
// "https://github.com/naman14/Timber.git", "./repositories/",
47+
// "https://github.com/apache/tez.git", "./repositories/",
48+
"https://github.com/apache/commons-math.git", "./repositories/",
4749
"^.*$", commitAnalysis);
4850

4951
/* Run the analysis. */

java/src/ca/ubc/ece/salt/pangor/java/cfg/JavaCFGFactory.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import ca.ubc.ece.salt.pangor.cfg.CFG;
1515
import ca.ubc.ece.salt.pangor.cfg.CFGFactory;
1616
import ca.ubc.ece.salt.pangor.cfg.CFGNode;
17-
import ca.ubc.ece.salt.pangor.java.analysis.MethodVisitor;
1817
import fr.labri.gumtree.gen.jdt.JdtTreeGenerator;
1918
import fr.labri.gumtree.io.TreeGenerator;
2019

@@ -39,12 +38,12 @@ public List<CFG> createCFGs(ClassifiedASTNode root) {
3938
List<CFG> cfgs = new LinkedList<CFG>();
4039

4140
/* Get the list of methods in the class. */
42-
List<MethodDeclaration> methods = MethodVisitor.getMethodDeclarations(cu);
41+
// List<MethodDeclaration> methods = MethodVisitor.getMethodDeclarations(cu);
4342

4443
/* For each function, generate its CFG. */
45-
for(MethodDeclaration method : methods) {
46-
cfgs.add(JavaCFGFactory.buildMethodCFG(method));
47-
}
44+
// for(MethodDeclaration method : methods) {
45+
// cfgs.add(JavaCFGFactory.buildMethodCFG(method));
46+
// }
4847

4948
return cfgs;
5049

0 commit comments

Comments
 (0)