-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bfb82d8
Showing
74 changed files
with
3,823 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>sacha</groupId> | ||
<artifactId>infra</artifactId> | ||
<version>0.1</version> | ||
<name>sacha infra</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
<version>1.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>fr.inria.gforge.spoon</groupId> | ||
<artifactId>spoon-core</artifactId> | ||
<version>4.2.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>srcs/main</sourceDirectory> | ||
<outputDirectory>bin</outputDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
<excludes> | ||
<exclude>**/*.*</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>1.1</version> | ||
<executions> | ||
<execution> | ||
<id>add-source</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>srcs/framework</source> | ||
<source>srcs/processors</source> | ||
<source>srcs/utils</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package bcornu.resi; | ||
|
||
public class AbnormalExecutionError extends Error { | ||
|
||
public AbnormalExecutionError(){ | ||
super(); | ||
} | ||
|
||
public AbnormalExecutionError(String string) { | ||
super(string); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package bcornu.resi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Stack; | ||
|
||
import bcornu.resi.context.MethodeContext; | ||
import bcornu.resi.strategies.NoStrat; | ||
|
||
|
||
@SuppressWarnings("all") | ||
public class CallChecker { | ||
|
||
public static Strategy strat; | ||
|
||
private static Stack<List<Object>> stack = new Stack<List<Object>>(); | ||
|
||
private static Strategy getStrat(){ | ||
return strat==null?new NoStrat():strat; | ||
} | ||
|
||
public static <T> T isCalled(T o, Class clazz) { | ||
if (o == null && ExceptionStack.isStoppable(NullPointerException.class)) | ||
return null; | ||
return getStrat().isCalled(o, clazz); | ||
} | ||
|
||
public static boolean beforeDeref(Object called) { | ||
if (called == null && ExceptionStack.isStoppable(NullPointerException.class)) | ||
return true; | ||
return getStrat().beforeDeref(called); | ||
} | ||
|
||
public static <T> T init(Class clazz) { | ||
return getStrat().init(clazz); | ||
} | ||
|
||
public static <T> T returned(Class clazz) { | ||
return getStrat().returned(clazz); | ||
} | ||
|
||
public static <T> T varAssign(Object table) { | ||
if(! stack.isEmpty() && ! stack.peek().contains(table)) | ||
stack.peek().add(table); | ||
return (T) table; | ||
} | ||
|
||
public static <T> T varInit(Object table) { | ||
if(! stack.isEmpty()) | ||
stack.peek().add(table); | ||
return (T) table; | ||
} | ||
|
||
public static void methodStart() { | ||
stack.push(new ArrayList<Object>()); | ||
} | ||
|
||
public static void methodEnd() { | ||
stack.pop(); | ||
} | ||
|
||
public static List<Object> getCurrentVars(){ | ||
return stack.peek(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package bcornu.resi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import bcornu.resi.context.TryContext; | ||
|
||
public class ExceptionStack { | ||
|
||
private static List<TryContext> tryContexts = new ArrayList<>(); | ||
|
||
public static void register(TryContext tc) { | ||
tryContexts.add(tc); | ||
} | ||
|
||
public static void unregister(TryContext tc){ | ||
if(tryContexts.isEmpty()) | ||
return; | ||
if(tryContexts.get(tryContexts.size()-1).equals(tc)){ | ||
tryContexts.remove(tryContexts.size()-1); | ||
}else{ | ||
System.err.println("oops?"); | ||
} | ||
} | ||
|
||
public static boolean isStoppable(Class<? extends Exception> c){ | ||
for (TryContext tryContext : tryContexts) { | ||
for (Class clazz : tryContext.getTypes()) { | ||
if(clazz.isAssignableFrom(c)){ | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package bcornu.resi; | ||
|
||
|
||
public class ForceReturn extends RuntimeException { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package bcornu.resi; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public abstract class Strategy { | ||
|
||
public abstract <T> T isCalled(T o, Class clazz); | ||
|
||
public abstract <T> T returned(Class clazz); | ||
|
||
public abstract boolean beforeDeref(Object called); | ||
|
||
protected <T> T obtain(Class clazz) { | ||
if(clazz==null) | ||
return null; | ||
List<Object> vars = CallChecker.getCurrentVars(); | ||
for (Object object : vars) { | ||
if(object!=null && object.getClass()!=null && object.getClass().isAssignableFrom(clazz)){ | ||
System.out.println("var found!"); | ||
return (T) object; | ||
} | ||
} | ||
throw new AbnormalExecutionError("cannot found var: "+clazz); | ||
} | ||
|
||
public <T> T init(Class clazz) { | ||
if(clazz==null) | ||
return null; | ||
if(clazz.isPrimitive()){ | ||
return initPrimitive(clazz); | ||
} | ||
return null; | ||
} | ||
|
||
protected <T> T initPrimitive(Class clazz){ | ||
if(clazz == int.class){ | ||
return (T) new Integer(0); | ||
} | ||
if(clazz == char.class){ | ||
return (T) new Character(' '); | ||
} | ||
if(clazz == boolean.class){ | ||
return (T) new Boolean(false); | ||
} | ||
if(clazz == float.class){ | ||
return (T) new Float(0); | ||
} | ||
if(clazz == double.class){ | ||
return (T) new Double(0); | ||
} | ||
if(clazz == long.class){ | ||
return (T) new Long(0); | ||
} | ||
throw new AbnormalExecutionError("missing primitive:"+clazz); | ||
} | ||
|
||
protected <T> T initNotNull(Class clazz){ | ||
if(clazz==null) | ||
return null; | ||
if(clazz.isPrimitive()){ | ||
return initPrimitive(clazz); | ||
} | ||
if(clazz.isInterface()){ | ||
if(clazz.isAssignableFrom(Set.class)){ | ||
return (T) new HashSet(); | ||
} | ||
if(clazz.isAssignableFrom(Comparator.class)){ | ||
return (T) new Comparator() { | ||
public int compare(Object o1, Object o2) { | ||
return 0; | ||
} | ||
}; | ||
} | ||
else throw new AbnormalExecutionError("missing interface"+clazz); | ||
} | ||
Object res = null; | ||
try { | ||
res = (T) clazz.newInstance(); | ||
} catch (InstantiationException | IllegalAccessException e) { | ||
System.err.println("cannot new instance "+clazz); | ||
try{ | ||
for (Constructor constructor : clazz.getConstructors()) { | ||
try{ | ||
Class[] types = constructor.getParameterTypes(); | ||
Object[] params = new Object[types.length]; | ||
for (int i = 0; i < types.length; i++) { | ||
try{ | ||
if(types[i]==clazz) | ||
params[i]=null; | ||
else | ||
params[i] = init(types[i]); | ||
}catch (Throwable t){ | ||
t.printStackTrace(); | ||
} | ||
} | ||
res = (T) constructor.newInstance(params); | ||
return (T) res; | ||
}catch (Throwable t){ | ||
t.printStackTrace(); | ||
} | ||
} | ||
}catch (Throwable t){ | ||
t.printStackTrace(); | ||
} | ||
} | ||
return (T) res; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bcornu.resi.context; | ||
|
||
import bcornu.resi.CallChecker; | ||
|
||
public class MethodeContext { | ||
|
||
public MethodeContext() { | ||
CallChecker.methodStart(); | ||
} | ||
|
||
public <T> T methodSkip() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
public void methodEnd() { | ||
CallChecker.methodEnd(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package bcornu.resi.context; | ||
|
||
import bcornu.resi.ExceptionStack; | ||
|
||
public class TryContext { | ||
|
||
private int id = -1; | ||
private Class[] types; | ||
|
||
public TryContext(int id, String... types) { | ||
this.id=id; | ||
this.types = new Class[types.length]; | ||
int i=0; | ||
for (String str : types) { | ||
try { | ||
this.types[i++]=Class.forName(str); | ||
} catch (ClassNotFoundException e) { | ||
//throw new RuntimeException(e); | ||
} | ||
} | ||
ExceptionStack.register(this); | ||
} | ||
|
||
public void catchStart(int i) { | ||
ExceptionStack.unregister(this); | ||
} | ||
|
||
public void finallyStart(int i) { | ||
ExceptionStack.unregister(this); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if(!(o instanceof TryContext))return false; | ||
return this.id == ((TryContext)o).id; | ||
} | ||
|
||
public Class[] getTypes() { | ||
return types; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bcornu.resi.strategies; | ||
|
||
import bcornu.resi.AbnormalExecutionError; | ||
import bcornu.resi.Strategy; | ||
|
||
public class NoStrat extends Strategy{ | ||
|
||
public <T> T isCalled(T o, Class clazz) { | ||
return (T) o; | ||
} | ||
|
||
public boolean beforeDeref(Object called) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public <T> T returned(Class clazz) { | ||
throw new AbnormalExecutionError("should not call return"); | ||
} | ||
} |
Oops, something went wrong.