Skip to content

Commit d1065b7

Browse files
committed
added direct access example, table of contents
1 parent 43d622f commit d1065b7

File tree

2 files changed

+169
-14
lines changed

2 files changed

+169
-14
lines changed

README.md

Lines changed: 160 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010
![GitHub all releases](https://img.shields.io/github/downloads/polystat/polystat-cli/total)
1111

1212
# Polystat CLI
13+
- [Polystat CLI](#polystat-cli)
14+
- [Defects](#defects)
15+
- [Unanticipated mutual recursion](#unanticipated-mutual-recursion)
16+
- [Unjustified assumptions about methods of superclasses](#unjustified-assumptions-about-methods-of-superclasses)
17+
- [Direct Access to the Base Class State](#direct-access-to-the-base-class-state)
18+
- [Violation of the Liskov substitution principle](#violation-of-the-liskov-substitution-principle)
19+
- [Division by zero](#division-by-zero)
20+
- [Installation](#installation)
21+
- [With coursier](#with-coursier)
22+
- [Using a "fat" jar](#using-a-fat-jar)
23+
- [Basic usage](#basic)
24+
- [Running on big projects (hadoop)](#running-on-big-projects-hadoop)
25+
- [Full Usage Specification](#full)
26+
- [Notation](#notation)
27+
- [Input configuration](#input-configuration)
28+
- [Configuration options](#configuration-options)
29+
- [Output configuration](#output-configuration)
30+
- [`polystat list`](#polystat-list)
31+
- [Other Options](#other-options)
32+
- [Configuration File](#configuration-file)
33+
- [Development](#development)
1334

1435
This repository provides an alternative implementation to [Polystat](https://github.com/polystat/polystat). This tool's objective is to extend the functionality of the original implementation. These extensions include:
1536
* A precise [specification](#full) for the command-line interface.
@@ -26,10 +47,14 @@ This repository provides an alternative implementation to [Polystat](https://git
2647
⚠ WARNING ⚠: The tool is still in the early stages of development, so feature suggestions and bug reports are more than welcome!
2748

2849
# Defects
50+
2951
This section describes the defects that the Polystat CLI can detect by analyzing the EO intermediate representation produced by the translators, such as `j2eo` and `py2eo`.
3052

3153
## Unanticipated mutual recursion
32-
Comes from: [polsytat/odin](https://github.com/polystat/odin#mutual-recursion-analyzer)
54+
55+
[(Back to TOC)](#polystat-cli)
56+
57+
Comes from: [polystat/odin](https://github.com/polystat/odin#mutual-recursion-analyzer)
3358

3459
Unanticipated mutual recursion happens when a subclass redefines some of the methods of the superclass in such a way that one of the methods of the superclass becomes mutually-recursive with one of the redefined methods.
3560

@@ -270,6 +295,9 @@ class__Derived.new.this:
270295
```
271296

272297
## Unjustified assumptions about methods of superclasses
298+
299+
[(Back to TOC)](#polystat-cli)
300+
273301
If the superclass contains this defect, this means that the inlining of one its
274302
the methods is not safe, because doing so may lead to breaking changes in its subclasses.
275303

@@ -326,7 +354,7 @@ public class Test {
326354

327355
<summary>
328356

329-
Translation to EO (`j2eo` v0.5.3)</summary>
357+
Show translation to EO (generated with J2EO v0.5.3)</summary>
330358
```
331359
# 2022-06-20T16:48:51.476031558
332360
# j2eo team
@@ -605,32 +633,131 @@ Inlining calls in method ggg is not safe: doing so may break the behaviour of su
605633
```
606634

607635
## Direct Access to the Base Class State
636+
637+
[(Back to TOC)](#polystat-cli)
638+
608639
This defect means that the analyzed program contains the parts where the fields of the object are accessed directly. This probably means that the object with such fields breaks the incapsulation by exposing some of its private fields.
609640

610641
Comes from: [polystat/odin](https://github.com/polystat/odin#direct-access-to-the-base-class-state-analyzer)
611642

612-
__WARNING__: With the current latest version of `j2eo` (v0.5.3), the direct state access defect is not detected. It should work when [j2eo#114](https://github.com/polystat/j2eo/issues/114) is fixed.
643+
__WARNING__: With the current latest version of `j2eo` (v0.5.3), the direct state access defect is not detected. It should work when [j2eo#114](https://github.com/polystat/j2eo/issues/114) is fixed.
613644

614-
Sample input (simplified EO translation):
645+
__UPDATE__: Odin v0.4.5 introduced a workaround that made the Direct State Access defect detectable in some cases.
646+
647+
Sample input (Java):
648+
649+
```java
650+
class A {
651+
protected int state = 0;
652+
};
615653

654+
class B extends A {
655+
public int n(int x) {
656+
return this.state + x;
657+
}
658+
}
616659
```
617-
[] > a
618-
memory > state
619-
[self new_state] > update_state
620-
self.state.write new_state > @
621-
[] > b
622-
a > @
623-
[self new_state] > change_state_plus_two
624-
self.state.write (new_state.add 2) > @
660+
<details>
661+
<summary>
662+
663+
Show translation to EO (generated with J2EO v0.5.3)</summary>
664+
```python
665+
# 2022-07-01T15:16:39.276365661
666+
# j2eo team
667+
+alias stdlib.lang.class__Object
668+
+alias stdlib.primitives.prim__int
669+
670+
[] > class__A
671+
class__Object > super
672+
super > @
673+
[] > new
674+
[] > this
675+
class__Object.new > super
676+
super > @
677+
"class__A" > className
678+
[this] > init
679+
seq > @
680+
d580718781
681+
[] > d580718781
682+
this.state.write > @
683+
i_s1840976765
684+
[] > i_s1840976765
685+
l436532993 > @
686+
[] > l436532993
687+
prim__int.constructor_2 > @
688+
prim__int.new
689+
0
690+
prim__int.constructor_1 > state
691+
prim__int.new
692+
seq > @
693+
this
694+
# null :: null -> void
695+
[this] > constructor
696+
seq > @
697+
initialization
698+
s511717113
699+
this
700+
[] > initialization
701+
this.init > @
702+
this
703+
[] > s511717113
704+
super.constructor > @
705+
this.super
706+
707+
[] > class__B
708+
class__A > super
709+
super > @
710+
[] > new
711+
[] > this
712+
class__A.new > super
713+
super > @
714+
"class__B" > className
715+
[this] > init
716+
seq > @
717+
TRUE
718+
# n :: int -> int
719+
[this x] > n
720+
seq > @
721+
s1219161283
722+
[] > s1219161283
723+
b1552978964 > @
724+
[] > b1552978964
725+
f_a355790875.add > @
726+
s_r2028017635
727+
[] > f_a355790875
728+
t782378927.state > @
729+
[] > t782378927
730+
this > @
731+
[] > s_r2028017635
732+
x > @
733+
seq > @
734+
this
735+
# null :: null -> void
736+
[this] > constructor
737+
seq > @
738+
initialization
739+
s454325163
740+
this
741+
[] > initialization
742+
this.init > @
743+
this
744+
[] > s454325163
745+
super.constructor > @
746+
this.super
625747
```
748+
</details>
749+
626750

627751
Analyzer output:
628752

629753
```
630-
Method 'change_state_plus_two' of object 'b' directly accesses state 'state' of base class 'a'
754+
Method 'n' of object 'class__B.new.this' directly accesses state 'state' of base class 'class__A.new.this'
631755
```
632756

633757
## Violation of the Liskov substitution principle
758+
759+
[(Back to TOC)](#polystat-cli)
760+
634761
This defect means that some parts of the code violate the [Liskov substitution principle](https://github.com/polystat/odin#liskov-substitution-principle-violation-analyzer).
635762

636763
Comes from: [polystat/odin](https://github.com/polystat/odin#liskov-substitution-principle-violation-analyzer)
@@ -665,7 +792,7 @@ public class Test {
665792

666793
<summary>
667794

668-
Translation to EO (`j2eo` v0.5.3)</summary>
795+
Show translation to EO (generated with J2EO v0.5.3)</summary>
669796
```
670797
# 2022-06-20T16:48:51.463254529
671798
# j2eo team
@@ -824,6 +951,9 @@ Method g of object this violates the Liskov substitution principle as compared t
824951

825952

826953
## Division by zero
954+
955+
[(Back to TOC)](#polystat-cli)
956+
827957
The presence of this defect in the program means that some inputs may cause this program to fail with the ArithmeticException.
828958

829959
Comes from: [polystat/far](https://github.com/polystat/far)
@@ -849,6 +979,9 @@ Analyzer output:
849979
```
850980

851981
# <a name="installation"></a> Installation
982+
983+
[(Back to TOC)](#polystat-cli)
984+
852985
## With coursier
853986
If you have [coursier](https://get-coursier.io/docs/cli-installation) installed, then you can install the latest version of `polystat-cli` by running:
854987
```
@@ -877,6 +1010,8 @@ More about the arguments you can pass can be found [here](#basic) and [here](#fu
8771010

8781011
# <a name="basic"></a> Basic usage
8791012

1013+
[(Back to TOC)](#polystat-cli)
1014+
8801015
* If no arguments are provided to `polystat`, it will read the configuration from the [HOCON](https://github.com/lightbend/config/blob/main/HOCON.md) config file in the current working directory. The default name for this file is `.polystat.conf` in the current working directory.
8811016

8821017
```
@@ -928,6 +1063,9 @@ $ polystat eo --in tmp --sarif --to dir=polystat_out
9281063
```
9291064

9301065
# Running on big projects (hadoop)
1066+
1067+
[(Back to TOC)](#polystat-cli)
1068+
9311069
1. Clone the Hadoop `git` repository:
9321070
```sh
9331071
git clone https://github.com/apache/hadoop
@@ -961,6 +1099,9 @@ Executing these commands should create the following files:
9611099
3. `hadoop.json` should contain the aggregated SARIF output for all the files in the repository. This `.json` file contains a single [`sarifLog`](https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317478) object. This object has a property called [`runs`](https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317482), which is an array of `run` objects. Each [`run`](https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317484) object contains the name of the analyzed file and the [`results`](https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317507) property, which holds the results of all the analyzers that completed successfully.
9621100

9631101
# <a name="full"></a> Full Usage Specification
1102+
1103+
[(Back to TOC)](#polystat-cli)
1104+
9641105
This section covers all the options available in the CLI interface and their meanings.
9651106

9661107
## Notation
@@ -1025,6 +1166,8 @@ If it's not present in the current working directory, download one from Maven Ce
10251166
* `--config <path>` allows to configure Polystat from the specified HOCON config file. If not specified, reads configs from the file `.polystat.conf` in the current working directory.
10261167

10271168
# Configuration File
1169+
[(Back to TOC)](#polystat-cli)
1170+
10281171
This section covers all the keys that can be used in the HOCON configuration files. The most relevant version of the information presented in this section can be printed to console by running:
10291172
```
10301173
$ polystat list --config
@@ -1050,6 +1193,9 @@ The example of the working config file can be found [here](.polystat.conf).
10501193
* `polystat.outputs.files` - a list of files to write aggregated output to.
10511194
10521195
# Development
1196+
1197+
[(Back to TOC)](#polystat-cli)
1198+
10531199
Polystat CLI is an sbt Scala project. In order to build the project you need the following:
10541200
* [JDK](https://ru.wikipedia.org/wiki/Java_Development_Kit) 8+
10551201
* [sbt](https://www.scala-sbt.org/) 1.6.2

demos/DirectAccess.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A {
2+
protected int state = 0;
3+
};
4+
5+
class B extends A {
6+
public int n(int x) {
7+
return this.state + x;
8+
}
9+
}

0 commit comments

Comments
 (0)