Merge branch 'master' of ssh://gohorb.ba-horb.de/bahome/staff/stan/git/FJTypeinference
This commit is contained in:
commit
0467bec4b3
50
README.md
Normal file
50
README.md
Normal file
@ -0,0 +1,50 @@
|
||||
## Typeinference for Featherweight Java
|
||||
|
||||
[Try it here](https://janulrich.github.io/FeatherweightTypeInference/)
|
||||
|
||||
### Input Examples
|
||||
|
||||
```
|
||||
class Identity extends Object{
|
||||
id(a){
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
class Overloading extends Object{
|
||||
m(a, b){return a;}
|
||||
m(a,b){return b;}
|
||||
}
|
||||
|
||||
class TestOverloading extends Object{
|
||||
test(a){
|
||||
return new Test().m(this,a);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
class List<A extends Object> extends Object{
|
||||
A head;
|
||||
List<A> tail;
|
||||
add( a){
|
||||
return new List(a, this);
|
||||
}
|
||||
get(){
|
||||
return this.head;
|
||||
}
|
||||
}
|
||||
|
||||
class PrincipleType extends Object {
|
||||
function(a){
|
||||
return a.add(this).get();
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
@ -34,6 +34,32 @@ object FJTypeinference {
|
||||
).toSet)
|
||||
private def cToUnifyType(c: Class): UnifyRefType = UnifyRefType(c.name, c.genericParams.map(it => convertType(it._1)))
|
||||
|
||||
private def removeOverloadedSubtypeMethods(in: Class, finiteClosure: FiniteClosure) = {
|
||||
def methodIsSupertype(m : Method, superMethod: Method) = {
|
||||
def getBound(t: Type) = t match {
|
||||
case GenericType(x) =>
|
||||
(in.genericParams ++ m.genericParams.map(c => (c.asInstanceOf[LessDot].l, c.asInstanceOf[LessDot].r)))
|
||||
.find(p => p._1.equals(GenericType(x))).map(_._2).get
|
||||
case x => x
|
||||
}
|
||||
//finiteClosure.superTypes(getBound(m.retType))
|
||||
false
|
||||
}
|
||||
|
||||
val methodNames = in.methods.map(_.name)
|
||||
val newMethods = methodNames.flatMap(mName => {
|
||||
val overloadedMethods = in.methods.filter(_.name.equals(mName))
|
||||
overloadedMethods.foldLeft(Set[Method]())((ms, m)=>{
|
||||
if(ms.find(methodIsSupertype(_, m)).isDefined) { //If there is a method which is more general
|
||||
ms //do not add this method
|
||||
}else { //otherwise check if this method shadows another method
|
||||
ms.filter(methodIsSupertype(m, _))
|
||||
}
|
||||
})
|
||||
})
|
||||
Class(in.name, in.genericParams, in.superType, in.fields, newMethods)
|
||||
}
|
||||
|
||||
def typeinference(str: String): Either[String, (Set[Set[UnifyConstraint]], List[Class])] = {
|
||||
val ast = Parser.parse(str).map(ASTBuilder.fromParseTree(_))
|
||||
var typedClasses: List[Class] = List()
|
||||
@ -51,6 +77,11 @@ object FJTypeinference {
|
||||
})
|
||||
unifyResults
|
||||
})
|
||||
val fc = generateFC(typedClasses)
|
||||
//typedClasses =
|
||||
typedClasses.map(cl => {
|
||||
removeOverloadedSubtypeMethods(cl, fc)
|
||||
})
|
||||
typeResult.map(it => (it.flatten, typedClasses))
|
||||
}
|
||||
}
|
||||
|
40501
target/scala-2.13/fj-typeinference-fastopt/main.js
Normal file
40501
target/scala-2.13/fj-typeinference-fastopt/main.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user