Xbase: TypeComputer for own generated Java Classes [message #1775061] |
Tue, 24 October 2017 05:18  |
Eclipse User |
|
|
|
Hello, it's me again! :-)
After understanding how to type simple types correctly with the xbase type computer, I tried implementing a version for Classes as Types.
The Grammer is, simplified, the following:
Program:
{Program}
body = XBlockExpression
types += Type
;
Variable returns XVariableDeclaration:
{Variable} writeable?='variable' simpleName=ID ':' (typing=DataType);
Type:
(Enumeration | Composition);
DataType:
(SimpleDataType | ComplexDataType | ListType);
ListType:
=> ('list' '<' type=DataType) '>';
ComplexDataType:
{ComplexDataType} typeName=[Type];
Composition:
{Composition} "type" name=ID ":" "structure" "{" (attributes+=Attribute)* "}";
Attribute:
{Attribute}
"attribute" name=ID ":" typing=DataType ";";
Enumeration:
{Enumeration} "type" name=ID ":" "enumeration" "{" values+=EnumTypeValue ("," values+=EnumTypeValue)* "}";
EnumTypeValue:
name=ID;
SimpleDataType:
{SimpleDataType} typeName=('integer' | 'string' | 'rational' | 'boolean');
@Override
XPrimaryExpression returns XExpression:
/* Default XPrimaryExpressions */ |
Variable;
I try to get the type for ComplexDataType which is a reference to a created type.
The user should be able to program software like this:
{
variable a : TestStruc
a.a = 3
}
type TestStruc : structure {
attribute a : integer;
}
The parsing seems to work. But the type of a is CompositionImpl a instead of TestStruc. The second line (a.a = 3) doesn't work either, but I think it depends on the type of the first one.
The TypeComputer for the Compositions looks like the following currently:
/* THE PROBLEM IS PROBABLY HERE BECAUSE THE TYPE DOESN'T GET CALCULATED CORRECTLY */
var cdt = vr.typing as ComplexDataType
if (cdt.typeName instanceof Enumeration) {
state.assignType(vr, getRawTypeForName((cdt.typeName as Enumeration).class, state)) // is this the right way?
} else if (cdt.typeName instanceof Composition) { /* Composition */
var comp = cdt.typeName as Composition
state.assignType(vr, getRawTypeForName((comp as Composition).class, state))
// TODO Here is the mistake I guess
}
I suppose the error is in the "state.assignType.." line, but I haven't found a way to set the type, in the example "TestStruc" correctly. What do I have to change here?
A working sample can be found here: https://github.com/rehne93/dsl-complex-type-mapping
The grammar extension is .mydsl. The relevant parts are in the compiler and the typing package.
The compiler seems to work, the variable gets generated as "TestStruc a = new TestStruc()"; but the feature call uses the type of "CompositionImpl" which doesn't work obviously.
If there are any more relevant questions, feel free to ask.
As always, thanks a lot in advance!
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03786 seconds