Skip to content

Commit 85159d8

Browse files
Various refactorings
1 parent 670d674 commit 85159d8

15 files changed

Lines changed: 52 additions & 126 deletions

File tree

docs/coding-conventions.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
## License Header
1+
## Style
2+
TODO: apply style tool
23

3-
## Naming
4-
5-
## Style (TODO: use style tool)
64
### Import
75
- Wildcard imports (`import x.y.*`) should not be used.
86
- Imports should be sorted (use `Ctrl+Alt+o` in IntelliJ IDEA)
@@ -26,17 +24,17 @@ class Graph {
2624
}
2725
```
2826

29-
### Output (use Logger)
30-
27+
### Output via Logger
28+
Always use logger to output messages.
3129

3230
### Annotation (@Override, @Nullable, @Nonnull, ...)
3331
Always add `@Override` annotation for overridden methods.
3432

35-
For the methods that may return `null`, add `@Nullable` annotation to their return values. For example, `public @Nullable X getX()`.
33+
For the methods that may return `null`, annotate them with `@Nullable`.
3634

3735
For the methods that require non-`null` arguments, add `@Nonnull` annotation to the specific parameters, For example, `void setX(@Nonnull x)`.
3836

39-
### Use Tai-e Library
37+
### Use Tai-e Util
4038
- Use `Sets`/`Maps` to create Sets/Maps.
4139
When creating Set/Map, use proper `Sets.newSet`/`Maps.newMap()` factory methods instead of `new HashSet/Map<>()`.
4240

docs/development-guide.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/pascal/taie/analysis/ResultProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public Set<String> analyze() {
118118
}
119119

120120
private void setOutput() {
121-
String output = getOptions().getString("file");
121+
String output = getOptions().getString("action-file");
122122
if (output != null) {
123123
try {
124124
out = new PrintStream(output);
@@ -131,7 +131,7 @@ private void setOutput() {
131131
}
132132

133133
private void readInputs() {
134-
String input = getOptions().getString("file");
134+
String input = getOptions().getString("action-file");
135135
Path path = Path.of(input);
136136
try {
137137
inputs = Maps.newMultiMap();

src/main/java/pascal/taie/analysis/graph/callgraph/CallGraph.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
* @param <CallSite> type of call sites
3535
* @param <Method> type of methods
3636
*/
37-
public interface CallGraph<CallSite, Method> extends Graph<Method>, StmtResult<Set<Method>> {
37+
public interface CallGraph<CallSite, Method>
38+
extends Graph<Method>, StmtResult<Set<Method>> {
3839

3940
/**
4041
* @return the call sites that invoke the given method.

src/main/java/pascal/taie/analysis/graph/callgraph/CallGraphBuilder.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import pascal.taie.ir.stmt.Invoke;
3232
import pascal.taie.language.classes.JMethod;
3333

34-
import java.util.List;
35-
3634
public class CallGraphBuilder extends ProgramAnalysis<CallGraph<Invoke, JMethod>> {
3735

3836
public static final String ID = "cg";
@@ -68,10 +66,9 @@ private static void logStatistics(CallGraph<Invoke, JMethod> callGraph) {
6866

6967
private static void processOptions(CallGraph<Invoke, JMethod> callGraph,
7068
AnalysisOptions options) {
71-
String action = options.getString("action");
72-
if ("dump".equals(action)) {
73-
String file = options.getString("file");
74-
CallGraphs.dumpCallGraph(callGraph, file);
69+
String dumpFile = options.getString("dump");
70+
if (dumpFile != null) {
71+
CallGraphs.dumpCallGraph(callGraph, dumpFile);
7572
}
7673
String methodsFile = options.getString("dump-methods");
7774
if (methodsFile != null) {

src/main/java/pascal/taie/analysis/graph/callgraph/PTABasedBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/**
3232
* Builds call graph based on pointer analysis results.
33-
* This builder assumes that pointer analysis have been done,
33+
* This builder assumes that pointer analysis has finished,
3434
* and it merely returns the (context-insensitive) call graph
3535
* obtained from pointer analysis result.
3636
*/

src/main/java/pascal/taie/analysis/pta/PointerAnalysis.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,23 @@ public PointerAnalysisResult analyze() {
7070
AnalysisOptions options = getOptions();
7171
HeapModel heapModel = new AllocationSiteBasedModel(options);
7272
ContextSelector selector = null;
73-
String pre = options.getString("pre");
73+
String advanced = options.getString("advanced");
7474
String cs = options.getString("cs");
75-
if (pre != null) {
75+
if (advanced != null) {
7676
// run context-insensitive analysis as pre-analysis
7777
PointerAnalysisResult preResult = runAnalysis(heapModel,
7878
ContextSelectorFactory.makeCISelector());
79-
if (pre.startsWith("scaler")) {
79+
if (advanced.startsWith("scaler")) {
8080
selector = Timer.runAndCount(() -> ContextSelectorFactory
81-
.makeGuidedSelector(Scaler.run(preResult, pre)),
81+
.makeGuidedSelector(Scaler.run(preResult, advanced)),
8282
"Scaler", Level.INFO);
83-
} else if (pre.startsWith("zipper")) {
83+
} else if (advanced.startsWith("zipper")) {
8484
selector = Timer.runAndCount(() -> ContextSelectorFactory
85-
.makeSelectiveSelector(cs, Zipper.run(preResult, pre)),
85+
.makeSelectiveSelector(cs, Zipper.run(preResult, advanced)),
8686
"Zipper", Level.INFO);
8787
} else {
88-
throw new IllegalArgumentException("Illegal pre-analysis argument: " + pre);
88+
throw new IllegalArgumentException(
89+
"Illegal advanced analysis argument: " + advanced);
8990
}
9091
}
9192
if (selector == null) {

src/main/java/pascal/taie/analysis/pta/plugin/ResultProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static void process(AnalysisOptions options,
9191
if (action == null) {
9292
return;
9393
}
94-
String file = options.getString("file");
94+
String file = options.getString("action-file");
9595
boolean taintEnabled = options.getString("taint-config") != null;
9696
switch (action) {
9797
case "dump":

src/main/java/pascal/taie/util/collection/BitSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ interface Action<R> {
348348
* Creates a new set.
349349
*/
350350
static BitSet newBitSet(boolean isSparse) {
351-
return isSparse ? new SparseBitSet() : new SimpleBitSet();
351+
return isSparse ? new SparseBitSet() : new RegularBitSet();
352352
}
353353

354354
/**

src/main/java/pascal/taie/util/collection/SimpleBitSet.java renamed to src/main/java/pascal/taie/util/collection/RegularBitSet.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import java.util.Arrays;
2626

2727
/**
28-
* Simple bit set implementation.
28+
* Regular bit set implementation.
2929
* This implementation is very similar to {@link java.util.Set} which uses
3030
* a {@code long[]} to store all the set bits.
3131
*/
32-
public class SimpleBitSet extends AbstractBitSet {
32+
public class RegularBitSet extends AbstractBitSet {
3333

3434
/* Used to shift left or right for a partial word mask */
3535
private static final long WORD_MASK = 0xffffffffffffffffL;
@@ -47,7 +47,7 @@ public class SimpleBitSet extends AbstractBitSet {
4747
/**
4848
* Creates a new bit set. All bits are initially {@code false}.
4949
*/
50-
public SimpleBitSet() {
50+
public RegularBitSet() {
5151
initWords(BITS_PER_WORD);
5252
}
5353

@@ -60,7 +60,7 @@ public SimpleBitSet() {
6060
* @throws NegativeArraySizeException if the specified initial size
6161
* is negative
6262
*/
63-
public SimpleBitSet(int nbits) {
63+
public RegularBitSet(int nbits) {
6464
// nbits can't be negative; size 0 is OK
6565
if (nbits < 0)
6666
throw new NegativeArraySizeException("nbits < 0: " + nbits);
@@ -290,7 +290,7 @@ public boolean intersects(BitSet set) {
290290
if (this == set) {
291291
return true;
292292
}
293-
if (!(set instanceof SimpleBitSet other)) {
293+
if (!(set instanceof RegularBitSet other)) {
294294
return super.intersects(set);
295295
}
296296
for (int i = Math.min(wordsInUse, other.wordsInUse) - 1; i >= 0; i--)
@@ -305,7 +305,7 @@ public boolean contains(BitSet set) {
305305
return true;
306306
}
307307

308-
if (!(set instanceof SimpleBitSet other)) {
308+
if (!(set instanceof RegularBitSet other)) {
309309
return super.contains(set);
310310
}
311311

@@ -329,7 +329,7 @@ public boolean and(BitSet set) {
329329
if (this == set) {
330330
return false;
331331
}
332-
if (!(set instanceof SimpleBitSet other)) {
332+
if (!(set instanceof RegularBitSet other)) {
333333
throw new UnsupportedOperationException(
334334
String.format("%s does not support AND with %s",
335335
this.getClass(), set.getClass()));
@@ -370,7 +370,7 @@ public boolean andNot(BitSet set) {
370370
clear();
371371
return changed;
372372
}
373-
if (!(set instanceof SimpleBitSet other)) {
373+
if (!(set instanceof RegularBitSet other)) {
374374
return super.andNot(set);
375375
}
376376

@@ -399,7 +399,7 @@ public boolean or(BitSet set) {
399399
if (this == set) {
400400
return false;
401401
}
402-
if (!(set instanceof SimpleBitSet other)) {
402+
if (!(set instanceof RegularBitSet other)) {
403403
return super.or(set);
404404
}
405405

@@ -440,11 +440,11 @@ public boolean or(BitSet set) {
440440

441441
@Override
442442
public BitSet orDiff(BitSet set) {
443-
SimpleBitSet diff = new SimpleBitSet();
443+
RegularBitSet diff = new RegularBitSet();
444444
if (this == set) {
445445
return diff;
446446
}
447-
if (!(set instanceof SimpleBitSet other)) {
447+
if (!(set instanceof RegularBitSet other)) {
448448
return super.orDiff(set);
449449
}
450450
if (wordsInUse < other.wordsInUse) {
@@ -478,7 +478,7 @@ public boolean xor(BitSet set) {
478478
clear();
479479
return changed;
480480
}
481-
if (!(set instanceof SimpleBitSet other)) {
481+
if (!(set instanceof RegularBitSet other)) {
482482
return super.xor(set);
483483
}
484484

@@ -522,7 +522,7 @@ public void setTo(BitSet set) {
522522
return;
523523
}
524524

525-
if (!(set instanceof SimpleBitSet other)) {
525+
if (!(set instanceof RegularBitSet other)) {
526526
super.setTo(set);
527527
return;
528528
}
@@ -614,7 +614,7 @@ public int hashCode() {
614614
*/
615615
@Override
616616
public boolean equals(Object obj) {
617-
if (!(obj instanceof SimpleBitSet set))
617+
if (!(obj instanceof RegularBitSet set))
618618
return false;
619619
if (this == obj)
620620
return true;
@@ -634,8 +634,8 @@ public boolean equals(Object obj) {
634634
}
635635

636636
@Override
637-
public SimpleBitSet copy() {
638-
SimpleBitSet copy = new SimpleBitSet();
637+
public RegularBitSet copy() {
638+
RegularBitSet copy = new RegularBitSet();
639639
copy.wordsInUse = wordsInUse;
640640
copy.words = Arrays.copyOf(words, wordsInUse);
641641
return copy;

0 commit comments

Comments
 (0)