I continue on: http://www.eclipse.org/forums/index.php/t/513601/
The goal
Create a matrix literal (matlab style)
Examples:
val x = a.[*,1:2]
val c = 1
val y = a.[c;1:2]
This should be converted to
final Matrix x = new MatrixBuilder().columnRange(1,2).build();
final int c = 1;
final Matrix y = new MatrixBuilder().rowSelect(c).columnRange(1,2).build()
I made a custom xbase compiler that does that correctly for me. The problem however is in my type converter.
The Problem
When I ONLY have the following in my typecomputer:
def void _computeTypes(OMatrixRangeLiteral object, ITypeComputationState state) {
val LightweightTypeReference type = getTypeForName(
typeof(OMatrix),
state
);
state.acceptActualType(type)
}
Then everything works fine (except that I cannot reference to other variables of course ie.: a.[c,*] won't work)
When I change my typecomputer as follows (as said in the documentation of ITypeComputer 2.4)
def void _computeTypes(OMatrixRangeLiteral object, ITypeComputationState state) {
val LightweightTypeReference type = getTypeForName(
typeof(OMatrix),
state
);
state.acceptActualType(type)
if (object.columns.lower != null) {
state.computeTypes(object.columns.lower)
}
}
Then it will correctly resolve that membercall to 'c' but the actual type is NOT correct anymore.
ie:
final Object x = new MatrixBuilder().columnRange(1,2).build();
final int c = 1;
final Object y = new MatrixBuilder().rowSelect(c).columnRange(1,2).build()
My relevant grammar
XLiteral returns XExpression:
XCollectionLiteral |
XClosure |
XBooleanLiteral |
XNumberLiteral |
XNullLiteral |
XStringLiteral |
XTypeLiteral |
OMatrixRangeLiteral;
MatrixRangeLiteral returns XExpression:
{MatrixRangeLiteral}
id=(ValidID) '.' '[' rows=RangeNotation ';' columns=RangeNotation ']';
RangeNotation returns RangeNotation:
{RangeNotation}
(lower=XExpression (isrange?=':' upper=XExpression)?) |
=>(isselection?='(' selections+=XExpression (',' selections+=XExpression)* ')') |
all?='*';
My ITypeComputer
class OlimathTypeComputer extends XbaseWithAnnotationsTypeComputer {
override def computeTypes(XExpression expression, ITypeComputationState state) {
if (expression instanceof OMatrixRangeLiteral) {
_computeTypes(expression as OMatrixRangeLiteral, state)
} else {
super.computeTypes(expression, state)
}
}
def void _computeTypes(OMatrixRangeLiteral object, ITypeComputationState state) {
val LightweightTypeReference type = getTypeForName(
typeof(OMatrix),
state
);
state.acceptActualType(type)
// columns
/// lower
if (object.columns.lower != null) {
state.computeTypes(object.columns.lower)
}
[Updated on: Wed, 28 August 2013 12:56]
Report message to a moderator