Skip to content

Commit

Permalink
Add spotless and format (#59)
Browse files Browse the repository at this point in the history
Fixes #56.
  • Loading branch information
khatchad authored Jun 21, 2023
1 parent ea1459c commit 6c10952
Show file tree
Hide file tree
Showing 124 changed files with 16,336 additions and 14,557 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ jobs:
run: |
cd ./IDE/com.ibm.wala.cast.lsp
mvn clean install -B -q -DskipTests
- name: Check formatting with spotless.
run: mvn spotless:check -B
- name: Build with Maven
run: mvn clean verify -B
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ install:
- mvn clean install -B -q -DskipTests
- popd
script:
- mvn spotless:check -B
- mvn clean verify -B
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ You must install the `jython-dev.jar` to your local maven repository.
1. Build Jython 3: `ant`. That will produce the file `jython3/dist/jython-dev.jar`.
1. Install the `jython-dev.jar` into your local maven repo (see [this post][SO post]):

```bash
mvn install:install-file \
```bash
mvn install:install-file \
-Dfile=./jython-dev.jar \
-DgroupId="org.python" \
-DartifactId="jython3" \
-Dversion="0.0.1-SNAPSHOT" \
-Dpackaging="jar" \
-DgeneratePom=true
```
```
### Installing IDE

1. Clone the [IDE repository][IDE].
Expand Down
5 changes: 3 additions & 2 deletions com.ibm.wala.cast.python.jython.test/pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down Expand Up @@ -48,8 +49,6 @@
</dependency>
</dependencies>
<build>
<sourceDirectory>test-source</sourceDirectory>
<testSourceDirectory>test-source</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -60,5 +59,7 @@
</configuration>
</plugin>
</plugins>
<sourceDirectory>test-source</sourceDirectory>
<testSourceDirectory>test-source</testSourceDirectory>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.ibm.wala.cast.python.jython.test;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import com.ibm.wala.cast.python.test.TestAssign;
import com.ibm.wala.cast.python.test.TestCalls;
import com.ibm.wala.cast.python.test.TestClasses;
Expand All @@ -15,22 +12,22 @@
import com.ibm.wala.cast.python.test.TestPrimitives;
import com.ibm.wala.cast.python.test.TestSlice;
import com.ibm.wala.cast.python.test.TestSource;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
TestAssign.class,
TestCalls.class,
TestClasses.class,
TestCollections.class,
TestComprehension.class,
TestFor.class,
TestLambda.class,
TestLibrary.class,
TestMulti.class,
TestPrimitives.class,
TestSlice.class,
TestSource.class
TestAssign.class,
TestCalls.class,
TestClasses.class,
TestCollections.class,
TestComprehension.class,
TestFor.class,
TestLambda.class,
TestLibrary.class,
TestMulti.class,
TestPrimitives.class,
TestSlice.class,
TestSource.class
})
public class Jython2Suite {

}
public class Jython2Suite {}
3 changes: 2 additions & 1 deletion com.ibm.wala.cast.python.jython/pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down Expand Up @@ -46,11 +47,11 @@
</dependency>
</dependencies>
<build>
<sourceDirectory>source</sourceDirectory>
<resources>
<resource>
<directory>data</directory>
</resource>
</resources>
<sourceDirectory>source</sourceDirectory>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
*****************************************************************************/
package com.ibm.wala.cast.python.loader;

import java.io.IOException;
import java.util.List;

import org.python.core.PyObject;

import com.ibm.wala.cast.ir.translator.ConstantFoldingRewriter;
import com.ibm.wala.cast.ir.translator.RewritingTranslatorToCAst;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
Expand All @@ -34,62 +29,84 @@
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import java.io.IOException;
import java.util.List;
import org.python.core.PyObject;

public class Python2Loader extends PythonLoader {
public Python2Loader(IClassHierarchy cha, IClassLoader parent) {
super(cha, parent);
}
public Python2Loader(IClassHierarchy cha, IClassLoader parent) {
super(cha, parent);
}

public Python2Loader(IClassHierarchy cha) {
super(cha);
}
public Python2Loader(IClassHierarchy cha) {
super(cha);
}

@Override
protected TranslatorToCAst getTranslatorToCAst(CAst ast, ModuleEntry M, List<Module> allModules) throws IOException {
RewritingTranslatorToCAst x = new RewritingTranslatorToCAst(M, new PythonModuleParser((SourceModule)M, typeDictionary, allModules) {
@Override
public CAstEntity translateToCAst() throws Error, IOException {
CAstEntity ce = super.translateToCAst();
return new AstConstantFolder().fold(ce);
}
});

x.addRewriter(new CAstRewriterFactory<NonCopyingContext,NoKey>() {
@Override
public PatternBasedRewriter createCAstRewriter(CAst ast) {
return new PatternBasedRewriter(ast, sliceAssign, (Segments s) -> { return rewriteSubscriptAssign(s); });
}
}, false);
@Override
protected TranslatorToCAst getTranslatorToCAst(CAst ast, ModuleEntry M, List<Module> allModules)
throws IOException {
RewritingTranslatorToCAst x =
new RewritingTranslatorToCAst(
M,
new PythonModuleParser((SourceModule) M, typeDictionary, allModules) {
@Override
public CAstEntity translateToCAst() throws Error, IOException {
CAstEntity ce = super.translateToCAst();
return new AstConstantFolder().fold(ce);
}
});

x.addRewriter(new CAstRewriterFactory<NonCopyingContext,NoKey>() {
@Override
public PatternBasedRewriter createCAstRewriter(CAst ast) {
return new PatternBasedRewriter(ast, sliceAssignOp, (Segments s) -> { return rewriteSubscriptAssignOp(s); });
}
}, false);
x.addRewriter(
new CAstRewriterFactory<NonCopyingContext, NoKey>() {
@Override
public PatternBasedRewriter createCAstRewriter(CAst ast) {
return new PatternBasedRewriter(
ast,
sliceAssign,
(Segments s) -> {
return rewriteSubscriptAssign(s);
});
}
},
false);

x.addRewriter(new CAstRewriterFactory<NonCopyingContext,NoKey>() {
@Override
public ConstantFoldingRewriter createCAstRewriter(CAst ast) {
return new ConstantFoldingRewriter(ast) {
@Override
protected Object eval(CAstOperator op, Object lhs, Object rhs) {
try {
PyObject x = Python2Interpreter.getInterp().eval(lhs + " " + op.getValue() + " " + rhs);
if (x.isNumberType()) {
System.err.println(lhs + " " + op.getValue() + " " + rhs + " -> " + x.asInt());
return x.asInt();
}
} catch (Exception e) {
// interpreter died for some reason, so no information.
}
return null;
}
};
}

}, false);
return x;
}
x.addRewriter(
new CAstRewriterFactory<NonCopyingContext, NoKey>() {
@Override
public PatternBasedRewriter createCAstRewriter(CAst ast) {
return new PatternBasedRewriter(
ast,
sliceAssignOp,
(Segments s) -> {
return rewriteSubscriptAssignOp(s);
});
}
},
false);

x.addRewriter(
new CAstRewriterFactory<NonCopyingContext, NoKey>() {
@Override
public ConstantFoldingRewriter createCAstRewriter(CAst ast) {
return new ConstantFoldingRewriter(ast) {
@Override
protected Object eval(CAstOperator op, Object lhs, Object rhs) {
try {
PyObject x =
Python2Interpreter.getInterp().eval(lhs + " " + op.getValue() + " " + rhs);
if (x.isNumberType()) {
System.err.println(lhs + " " + op.getValue() + " " + rhs + " -> " + x.asInt());
return x.asInt();
}
} catch (Exception e) {
// interpreter died for some reason, so no information.
}
return null;
}
};
}
},
false);
return x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

public class Python2LoaderFactory extends PythonLoaderFactory {

@Override
protected IClassLoader makeTheLoader(IClassHierarchy cha) {
return new Python2Loader(cha);
}

@Override
protected IClassLoader makeTheLoader(IClassHierarchy cha) {
return new Python2Loader(cha);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@
*****************************************************************************/
package com.ibm.wala.cast.python.parser;

import com.ibm.wala.cast.tree.CAstEntity;
import com.ibm.wala.cast.tree.impl.CAstTypeDictionaryImpl;
import com.ibm.wala.cast.util.CAstPrinter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.net.URL;

import com.ibm.wala.cast.tree.CAstEntity;
import com.ibm.wala.cast.tree.impl.CAstTypeDictionaryImpl;
import com.ibm.wala.cast.util.CAstPrinter;

public class PythonFileParser extends PythonParser<File> {

private final File fileName;

public PythonFileParser(File fileName, CAstTypeDictionaryImpl<String> types) {
super(types);
this.fileName = fileName;
}

protected String scriptName() {
return fileName.getName();
}

protected URL getParsedURL() throws IOException {
return fileName.toURI().toURL();
}

protected WalaPythonParser makeParser() throws IOException {
org.antlr.runtime.ANTLRFileStream file = new org.antlr.runtime.ANTLRFileStream(fileName.getAbsolutePath());
return new WalaPythonParser(file, fileName.getAbsolutePath(), "UTF-8");
}

public static void main(String[] args) throws Exception {
PythonParser<File> p = new PythonFileParser(new File(args[0]), new CAstTypeDictionaryImpl<String>());
CAstEntity script = p.translateToCAst();
System.err.println(script);
System.err.println(CAstPrinter.print(script));
}

@Override
protected Reader getReader() throws IOException {
return new FileReader(fileName);
}

private final File fileName;

public PythonFileParser(File fileName, CAstTypeDictionaryImpl<String> types) {
super(types);
this.fileName = fileName;
}

protected String scriptName() {
return fileName.getName();
}

protected URL getParsedURL() throws IOException {
return fileName.toURI().toURL();
}

protected WalaPythonParser makeParser() throws IOException {
org.antlr.runtime.ANTLRFileStream file =
new org.antlr.runtime.ANTLRFileStream(fileName.getAbsolutePath());
return new WalaPythonParser(file, fileName.getAbsolutePath(), "UTF-8");
}

public static void main(String[] args) throws Exception {
PythonParser<File> p =
new PythonFileParser(new File(args[0]), new CAstTypeDictionaryImpl<String>());
CAstEntity script = p.translateToCAst();
System.err.println(script);
System.err.println(CAstPrinter.print(script));
}

@Override
protected Reader getReader() throws IOException {
return new FileReader(fileName);
}
}
Loading

0 comments on commit 6c10952

Please sign in to comment.