Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » failure on XVariableDeclaration resolution in XBaseInterpreter
failure on XVariableDeclaration resolution in XBaseInterpreter [message #858788] Fri, 27 April 2012 09:48 Go to next message
John Blue is currently offline John BlueFriend
Messages: 7
Registered: April 2012
Location: San Francisco
Junior Member

On a simple language which extends from XBase.

Module:
  {Module}
  'module' canonicalName=QualifiedName
  (elements += XExpressionInsideBlock|elements+=Import)*
;


I wrote the following test which fails in the evaluation of s3:
IllegalStateException: Could not access field:test.s1


    def void testParsingAndLinkingWithVars() {
    	val dsl = "
		    module test
            val s1 = 'foo'
            val s2 = 'bar'
            val s3 = s1 + s2
        " 
        parser.parse(dsl).assertNoErrors
        
        val module = parser.parse(dsl)
        val s1 = module.elements.get(0) as XVariableDeclaration
        val s2 = module.elements.get(1) as XVariableDeclaration
        val s3 = module.elements.get(2) as XVariableDeclaration
        
        val evaluationContext = contextProvider.get()
        evaluationContext.newValue(XbaseScopeProvider::THIS, module)
        
        interpreter.evaluate(s1, evaluationContext, CancelIndicator::NullImpl)
        interpreter.evaluate(s2, evaluationContext, CancelIndicator::NullImpl)

        val s1val = evaluationContext.getValue(QualifiedName::create(s1.name))
        val s2val = evaluationContext.getValue(QualifiedName::create(s2.name))

        Assert::assertEquals(s1val, "foo")
        Assert::assertEquals(s2val, "bar")

=>here=>interpreter.evaluate(s3, evaluationContext, CancelIndicator::NullImpl)
        val s3val = evaluationContext.getValue(QualifiedName::create(s3.name))
        Assert::assertEquals(s3val, "foobar")
    }


I have an Inferer for Module:

   	acceptor.accept(module.toClass(module.fullyQualifiedName) [
   	for (element : module.elements) {
   	switch element {
   		XVariableDeclaration: {
		members +=element.toField(element.name, element.getExpressionType)
   		}
   	}}])


As well as a simpleName provider:

	def dispatch getSimpleName(JvmType element) {
	    return "this";
	}

	def dispatch getSimpleName(JvmIdentifiableElement element) {
	    return super.getSimpleName(element);
	}


Still when it is trying to resolve s1, it wants to find it under name test.s1 not this.s1 or simply s1...
Perhaps it is to do with me test setup.. What am I missing?

[Updated on: Fri, 27 April 2012 09:57]

Report message to a moderator

Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #859314 is a reply to message #858788] Fri, 27 April 2012 15:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

shouldnt you customize org.eclipse.xtext.xbase.scoping.XbaseScopeProvider.createLocalVarScope(IScope, LocalVariableScopeContext)

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #859322 is a reply to message #859314] Fri, 27 April 2012 15:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Alternatively you could change the grammar to

Module returns xbase::XBlockExpression:
  {Module}
  'module' canonicalName=QualifiedName
  (expressions += XExpressionInsideBlock)*
;


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #860829 is a reply to message #859322] Sat, 28 April 2012 08:17 Go to previous messageGo to next message
John Blue is currently offline John BlueFriend
Messages: 7
Registered: April 2012
Location: San Francisco
Junior Member

Christian, extending module from XBlockExpression i think is step in the right direction but it did not solve the problem.

It is basically failing here on the first line since it is looking for a RawType under the name "test" which I have not generated:

JavaReflectAccess:getFieldJvmField field) {
Class class1 = getRawType(field.getDeclaringType());
...
}

A declared JVmType called "test" is defined in the inferrer but it is not getting looked up.

This is forcing me to generate Java code to get JavaReflectAccess working!
Alternatively in the createLocalVarScope, I can walk through all module children and add the variables with an alias..?
What do you think?

[Updated on: Sat, 28 April 2012 08:18]

Report message to a moderator

Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #860865 is a reply to message #860829] Sat, 28 April 2012 08:40 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

i meant having a look what the scope provider does for blocks

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Woes migrating to 2.2.1 from 2.0.1 - need help
Next Topic:Adding comments using the JvmModelInferrer
Goto Forum:
  


Current Time: Fri Jul 10 20:37:06 GMT 2020

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

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

Back to the top