Skip to main content



      Home
Home » Modeling » TMF (Xtext) » failure on XVariableDeclaration resolution in XBaseInterpreter
failure on XVariableDeclaration resolution in XBaseInterpreter [message #858788] Fri, 27 April 2012 05:48 Go to next message
Eclipse UserFriend
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 05:57] by Moderator

Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #859314 is a reply to message #858788] Fri, 27 April 2012 11:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian
Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #859322 is a reply to message #859314] Fri, 27 April 2012 11:20 Go to previous messageGo to next message
Eclipse UserFriend
Alternatively you could change the grammar to

Module returns xbase::XBlockExpression:
  {Module}
  'module' canonicalName=QualifiedName
  (expressions += XExpressionInsideBlock)*
;
Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #860829 is a reply to message #859322] Sat, 28 April 2012 04:17 Go to previous messageGo to next message
Eclipse UserFriend
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 04:18] by Moderator

Re: failure on XVariableDeclaration resolution in XBaseInterpreter [message #860865 is a reply to message #860829] Sat, 28 April 2012 04:40 Go to previous message
Eclipse UserFriend
Hi,

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

~Christian
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: Wed Jul 23 11:01:33 EDT 2025

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

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

Back to the top