Skip to content

Commit

Permalink
Adding some changes to the api of the methods and some tests for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tesonep committed Jun 8, 2016
1 parent ed1e6c2 commit 490db65
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.uqbar.project.wollok.codeGenerator.model

import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.codeGenerator.model.types.Type
import org.uqbar.project.wollok.codeGenerator.model.types.context.TypeContext

interface Context extends Expression {
Expand Down Expand Up @@ -31,6 +32,7 @@ abstract class AbstractContext implements Context{

interface MethodContext extends Context {
def Variable getReturnVariable()
def Type returnTypeFor(TypeContext tc)
}

@Accessors
Expand All @@ -39,6 +41,10 @@ abstract class AbstractCompositeContext extends AbstractContext implements Metho
val returnVariable = new Variable(this, "_return");

override typeFor(TypeContext tc) {
throw new UnsupportedOperationException("TODO: auto-generated method stub")
}

override returnTypeFor(TypeContext tc){
returnVariable.typeFor(tc)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DefaultStrategy implements MessageSendStrategy {
override type(MessageSend send, MessageSentTypeContext tc) {
val method = tc.receiver.classDefinition.getMethodNamed(send.selector)
tc.method = method
method.typeFor(tc)
method.returnTypeFor(tc)
}

override canApply(MessageSend send, MessageSentTypeContext tc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NativeMethod extends Method {
this.numberOfParamters = numberOfParameters
}

override typeFor(TypeContext tc) {
override returnTypeFor(TypeContext tc) {
val javaClassName = DefaultNativeObjectFactory.wollokToJavaFQN(parent.name)
val c = Class.forName(javaClassName)
val m = c.methods.findFirst [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,57 @@ class ClassTest extends AbstractWollokCodeGeneratorTypeInfererTest {
assertNativeTypeEquals(NativeTypesEnum.INT, pgm.returnVariable)
}

@Test
def void classWithSubclasses() {
'''
class SuperClass {
method yy(){
return 32
}
}
class MiClase inherits SuperClass{
method xx(){
return self.yy()
}
}
program p {
var x = new MiClase()
return x.xx()
}
'''.parseAndPerformAnalysis

assertClassType(pgm.resolveWollokClass("MiClase".classNameWithSyntheticPackage), pgm.variables.get("x"))
assertNativeTypeEquals(NativeTypesEnum.INT, pgm.returnVariable)
}

@Test
def void methodInSuperclass() {
'''
class SuperClass {
method yy(){
return 32
}
method zz(){
return "asdad"
}
}
class MiClase inherits SuperClass{
method xx(){
return self.yy()
}
}
program p {
var x = new MiClase()
return x.zz()
}
'''.parseAndPerformAnalysis

assertClassType(pgm.resolveWollokClass("MiClase".classNameWithSyntheticPackage), pgm.variables.get("x"))
assertNativeTypeEquals(NativeTypesEnum.STRING, pgm.returnVariable)
}

}

0 comments on commit 490db65

Please sign in to comment.