Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with XbaseCompiler
icon5.gif  Problem with XbaseCompiler [message #1148330] Mon, 21 October 2013 12:28 Go to next message
Matthias Spiller is currently offline Matthias SpillerFriend
Messages: 13
Registered: September 2013
Junior Member
Hi,

I have a DSL where I want to be able to call into Java-Classes.
My garmmar:
Model:
	body = XBlockExpression
;

XPrimaryExpression returns XExpression:
	Call |
	XLiteral
;

Call returns XExpression:
    {Call}
    name = ValidID
    "calls"
    feature = [JvmType|QualifiedName]
    
    "("
    (parameters+=XAssignment ("," parameters+=XAssignment)*)?
    ")"
;


A file like:
{
    abc calls MyClass(a=1)
}


with MyClass being:
public class MyClass {	
	public int a;	
	public void execute() {
		System.out.println(a);
	}
}


shall be compiled to:
@SuppressWarnings("all")
public class example {
  public void run() {
    abc.a = 1;
    abc.execute();
    
  }  
  private Wrapper_MyClass abc = new Wrapper_MyClass();
}


So far this works. However, when I write
MyClass(a=1+1)
instead of
MyClass(a=1)
, I get an NullPointerException from the compiler:

java.lang.NullPointerException
	at org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:90)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:374)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:370)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:366)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.declareFreshLocalVariable(AbstractXbaseCompiler.java:478)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:253)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:123)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:482)
	at org.xtext.example.mydsl1.jvmmodel.MyDslCompiler.doInternalToJavaStatement(MyDslCompiler.java:22)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:329)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.prepareExpression(FeatureCallCompiler.java:384)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:232)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:123)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:482)
	at org.xtext.example.mydsl1.jvmmodel.MyDslCompiler.doInternalToJavaStatement(MyDslCompiler.java:22)


It seems that the type of "1 + 1" is unknown during compilation, while validation does not give any errors.

The relevant part of my TypeComputer is:
    def _doComputeTypes(Call expr, ITypeComputationState state) {
        val c = expr.feature as JvmGenericType
        for(f : c.declaredFields) {
            state.addLocalToCurrentScope(f)
        }
        
        for(p: expr.parameters) {
            super.computeTypes(p, state)
        }
        
        state.acceptActualType(getPrimitiveVoid(state))
    }


Any ideas?

Many thanks,
Matthias
Re: Problem with XbaseCompiler [message #1149563 is a reply to message #1148330] Tue, 22 October 2013 06:45 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 10/21/13 3:13 PM, schrieb Matthias Spiller:
> The relevant part of my TypeComputer is:
> def _doComputeTypes(Call expr, ITypeComputationState state) {
> val c = expr.feature as JvmGenericType
> for(f : c.declaredFields) {
> state.addLocalToCurrentScope(f)
> }
> for(p: expr.parameters) {
> super.computeTypes(p, state)
> }
> state.acceptActualType(getPrimitiveVoid(state))
> }
>
> Any ideas?

first you need to clone the computation state, like this:

val expressionState = state.withoutExpectation

then when computing the types on the assignments you don'T call super,
but you call

state.computeTypes(p)

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Problem with XbaseCompiler [message #1149577 is a reply to message #1149563] Tue, 22 October 2013 07:00 Go to previous messageGo to next message
Matthias Spiller is currently offline Matthias SpillerFriend
Messages: 13
Registered: September 2013
Junior Member
Thanks Sven,

unfortunately this does not help.
The type of the right-hand-side assignment ist still null when the compiler calls _toJavaStatement.

This is how the TypeComputer now looks like:
    
    def _doComputeTypes(Call expr, ITypeComputationState state) {
        val c = expr.feature as JvmGenericType
        for(f : c.declaredFields) {
            state.addLocalToCurrentScope(f)
        }
        
        val expressionState = state.withoutExpectation
        
        for(p: expr.parameters) {
            expressionState.computeTypes(p)
        }
        
        state.acceptActualType(getPrimitiveVoid(state))
    }



Matthias

[Updated on: Tue, 22 October 2013 07:03]

Report message to a moderator

Re: Problem with XbaseCompiler [message #1149943 is a reply to message #1149577] Tue, 22 October 2013 12:16 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Is your method really called, e.g. did you override #doComputeTypes to dispatch to your implementation?
Re: Problem with XbaseCompiler [message #1151258 is a reply to message #1149943] Wed, 23 October 2013 08:16 Go to previous messageGo to next message
Matthias Spiller is currently offline Matthias SpillerFriend
Messages: 13
Registered: September 2013
Junior Member
Yes it is:

    override computeTypes(XExpression expression, ITypeComputationState state) {
        if(expression instanceof Call) {
            _doComputeTypes(expression as Call, state)
        }
        else {
            super.computeTypes(expression, state)            
        }
    }
Re: Problem with XbaseCompiler [message #1158995 is a reply to message #1151258] Mon, 28 October 2013 08:23 Go to previous message
Matthias Spiller is currently offline Matthias SpillerFriend
Messages: 13
Registered: September 2013
Junior Member
I see that my bound ITypeComputer is called, at least during validation.
When compiling it seems the the bound ITypeProvider is called. This one seems to be lacking the type information.
Any idea?

What is also important is that I provide my own types for XStringLiteral and XNumberLiteral in the TypeComputer
Previous Topic:Iterating through Xtext model and making decisions for Code Gen
Next Topic:Custom validation rules marker
Goto Forum:
  


Current Time: Fri Aug 14 08:19:45 GMT 2020

Powered by FUDForum. Page generated in 0.01757 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top