-
Notifications
You must be signed in to change notification settings - Fork 16
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
Showing
6 changed files
with
119 additions
and
20 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
28 changes: 28 additions & 0 deletions
28
...wollok.tests/src/org/uqbar/project/wollok/tests/typesystem/xpect/parentConstructor.wlk.xt
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,28 @@ | ||
/* XPECT_SETUP org.uqbar.project.wollok.tests.typesystem.xpect.TypeSystemXpectTestCase END_SETUP */ | ||
|
||
object pepita inherits Golondrina(1) { } | ||
object pepona inherits Ave(nombre = "Pepona") { } | ||
object pepe inherits Ave { } | ||
|
||
class Golondrina inherits Ave { | ||
// XPECT type at energia --> Number | ||
const energia | ||
|
||
constructor(_energia) { | ||
energia = _energia | ||
} | ||
|
||
// XPECT methodType at hermana --> () => { } | ||
method hermana() = object inherits Golondrina(2) { } | ||
|
||
// XPECT methodType at amiga --> () => { } | ||
method amiga() = object inherits Ave(nombre = "Ami") { } | ||
} | ||
|
||
class Ave { | ||
// XPECT type at nombre --> String | ||
var nombre | ||
|
||
method nombreAve() = nombre | ||
} | ||
|
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
39 changes: 33 additions & 6 deletions
39
...src/org/uqbar/project/wollok/typesystem/constraints/ConstructorConstraintsGenerator.xtend
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 |
---|---|---|
@@ -1,31 +1,58 @@ | ||
package org.uqbar.project.wollok.typesystem.constraints | ||
|
||
import org.eclipse.emf.common.util.EList | ||
import org.eclipse.emf.ecore.EObject | ||
import org.uqbar.project.wollok.typesystem.constraints.variables.TypeVariablesRegistry | ||
import org.uqbar.project.wollok.wollokDsl.WClass | ||
import org.uqbar.project.wollok.wollokDsl.WConstructorCall | ||
import org.uqbar.project.wollok.wollokDsl.WExpression | ||
import org.uqbar.project.wollok.wollokDsl.WMethodContainer | ||
|
||
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.resolveConstructor | ||
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.* | ||
import static extension org.uqbar.project.wollok.model.WollokModelExtensions.* | ||
import static extension org.uqbar.project.wollok.utils.XtendExtensions.* | ||
|
||
/** | ||
* @author npasserini | ||
*/ | ||
class ConstructorConstraintsGenerator extends CrossReferenceConstraintsGenerator<WConstructorCall> { | ||
abstract class ConstructorConstraintsGenerator<T extends EObject> extends CrossReferenceConstraintsGenerator<T> { | ||
|
||
new(TypeVariablesRegistry registry) { | ||
super(registry) | ||
} | ||
|
||
override generate(WConstructorCall it) { | ||
val constructor = classRef.resolveConstructor(values) | ||
def generate(EObject it, WClass clazz, EList<WExpression> values) { | ||
val constructor = clazz.resolveConstructor(values) | ||
|
||
// Constructor might be null when neither the referred class nor any of it superclasses define a constructor, | ||
// And wouldn't be an error if the constructor call has no parameters. | ||
// TODO Handle and inform error conditions. | ||
// TODO 2: We should consider also argumentList.initializers | ||
constructor?.parameters?.biForEach(values) [ param, arg | | ||
param.tvarOrParam.instanceFor(it.tvar).beSupertypeOf(arg.tvar) | ||
] | ||
] | ||
} | ||
} | ||
|
||
class ConstructorCallConstraintsGenerator extends ConstructorConstraintsGenerator<WConstructorCall> { | ||
|
||
new(TypeVariablesRegistry registry) { | ||
super(registry) | ||
} | ||
|
||
override generate(WConstructorCall it) { | ||
generate(classRef, values) | ||
} | ||
} | ||
|
||
class ObjectParentConstraintsGenerator extends ConstructorConstraintsGenerator<WMethodContainer> { | ||
|
||
new(TypeVariablesRegistry registry) { | ||
super(registry) | ||
} | ||
|
||
override generate(WMethodContainer it) { | ||
generate(parent, parentParameters) | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...src/org/uqbar/project/wollok/typesystem/constraints/InitializerConstraintsGenerator.xtend
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,22 @@ | ||
package org.uqbar.project.wollok.typesystem.constraints | ||
|
||
import org.uqbar.project.wollok.typesystem.constraints.variables.TypeVariablesRegistry | ||
import org.uqbar.project.wollok.wollokDsl.WInitializer | ||
|
||
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.* | ||
|
||
class InitializerConstraintsGenerator extends CrossReferenceConstraintsGenerator<WInitializer> { | ||
|
||
new(TypeVariablesRegistry registry) { | ||
super(registry) | ||
} | ||
|
||
override generate(WInitializer it) { | ||
// Initializer could be in a ConstructorCall or an object parent declaration | ||
val instantiatedClass = declaringConstructorCall?.classRef ?: declaringContext.parent | ||
val initializedVariable = instantiatedClass.getVariableDeclaration(initializer.name) | ||
|
||
initializedVariable.variable.tvar.beSupertypeOf(initialValue.tvar) | ||
} | ||
|
||
} |
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