failure on XVariableDeclaration resolution in XBaseInterpreter [message #858788] |
Fri, 27 April 2012 09:48 |
|
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 #860829 is a reply to message #859322] |
Sat, 28 April 2012 08:17 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04133 seconds