Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Wrong context variable taken by gsl #145

Open
MaxSagebaum opened this issue Jun 9, 2017 · 2 comments
Open

Wrong context variable taken by gsl #145

MaxSagebaum opened this issue Jun 9, 2017 · 2 comments

Comments

@MaxSagebaum
Copy link

If have the setup that I create an additional attribute 'primalCall' on my nodes in the statup of the script:

for context.function as curFunction

  curFunction.primalCall2 = "$(curFunction.name)"
  curFunction.primalCall = "$(curFunction.name)"
endfor

In the function that I call to generate the code, I have the same value as an local variable:

function generateExpression(curFunction)
  primalCall = "this.getValue()"
> return $(my.curFunction.primalCall2)($(primalCall));
> return $(my.curFunction.primalCall)($(primalCall));
endfunction

The output of gsl is now:

 return doSomething(this.getValue());
 return this.getValue()(this.getValue());

So the xml attribute 'primalCall' is not taken. Instead gls takes the value of the lokal variable 'primalCall'.

It is probably just an return error because if 'curFunction' does not have the attribute 'primalCall' then an error is generated, that such attribute does not exist.

I have attached the xml and gls file. The generation is done with:

gsl -script:contextError.gsl -a def.xml error.hpp

I could not upload the files so here they are in plain text:

contextError.gsl

.ignorecase = 0 
.template 0

for context.function as curFunction

  curFunction.primalCall2 = "$(curFunction.name)"
  curFunction.primalCall = "$(curFunction.name)"
endfor

function generateExpression(curFunction)
  primalCall = "this.getValue()"
> return $(my.curFunction.primalCall2)($(primalCall));
> return $(my.curFunction.primalCall)($(primalCall));
endfunction

.endtemplate
.output "$(switches.arg1)"
.for context.function as curFunction
.  generateExpression(curFunction)
.endfor

def.xml

<context>
  <function name="doSomething" rType="Vector">
    <arg type="Vector" name="v1"/>
    <arg type="Vector" name="v2"/>
  </function>
</context>

@jschultz
Copy link
Contributor

I'm not quite clear what the error is here, that is, the behaviour is exactly what I would expect - when no scope is specified, GSL retrieves attributes from the innermost scope that defines an attribute with the specified name. Defining primalCall without an explicit scope in the function generateExpression causes the attribute to be defined in the function's scope, from where it is then retrieved in the following lines.

However:

It is probably just an return error because if 'curFunction' does not
have the attribute 'primalCall' then an error is generated, that such
attribute does not exist.

I took the definition of primalCall out of curFunction and did not receive any error. Instead I got the output I would expect:

return doSomething(doSomething);
return doSomething(doSomething);

Could give a more precise explanation of what you expect, what you receive, and where the two differ?

@MaxSagebaum
Copy link
Author

That is wired. I just checked if I have the newest version, which is the case.

I did the following:

[msagebaum]bugreport> git clone https://github.com/imatix/gsl.git
Cloning into 'gsl'...
remote: Counting objects: 1596, done.
remote: Total 1596 (delta 0), reused 0 (delta 0), pack-reused 1596
Receiving objects: 100% (1596/1596), 1.97 MiB | 230.00 KiB/s, done.
Resolving deltas: 100% (850/850), done.
Checking connectivity... done.
[msagebaum]bugreport> cd gsl/src 
[msagebaum]src> make -j5  
... (Only 2 warnings here)
./c -q -r libgsl.a ggobjt.o ggcomm.o ggscop.o ggcode.o ggcodem.o ggpars.o ggparsm.o ggconv.o ggdiag.o ggenvt.o ggfile.o gggsl.o ggmath.o ggpcre.o ggproc.o ggscrp.o ggsock.o ggstrn.o ggsymb.o ggthrd.o ggtime.o ggxml.o sflbits.o sflcvds.o sflcvts.o sflfile.o sfllbuf.o sflnode.o sflsock.o sfltron.o smtlog.o smtmsg.o smtsimu.o smttst2.o sflcomp.o sflcvns.o sfldate.o sflfind.o sfllist.o sflprint.o sflsort.o sfluid.o smtoper.o smtslot.o smttst3.o sflcons.o sflcvsb.o sfldes.o sflfort.o sflmail.o sflproc.o sflstr.o sflxml.o smtpipe.o smtsmtp.o smtxlog.o sflconv.o sflcvsd.o sfldescr.o sflheap.o sflmath.o sflscrit.o sflsymb.o sflxmll.o smtpop.o smtsock.o sflcryp.o sflcvsn.o sfldir.o sflhttp.o sflmem.o sflsearch.o sflsyst.o sflxmls.o smtrdns.o smttime.o sflcvbs.o sflcvst.o sflenv.o sflini.o sflmesg.o sflsha.o sfltok.o smtecho.o smtrdnsl.o smttran.o sflcvdp.o sflcvtp.o sflexdr.o sfllang.o sflmime.o sflslot.o sfltree.o smtlib.o smtserv.o smttst1.o
./c -q    -L gsl
./gsl -v
GSL/4.1.3
Built from http://github.com/imatix/gsl.git master
Copyright (c) 1996-2016 iMatix Corporation
Compiler: gcc -c -O2 -D_REENTRANT -D_GNU_SOURCE -Wall -Wno-unused -fno-strict-aliasing -DBASE_THREADSAFE -I. gsl.c
[msagebaum]src> cd ../..
[msagebaum]bugreport> ./gsl/src/gsl -script:contextError.gsl -a def.xml error.hpp
GSL/4.1.3 Copyright (c) 1996-2016 iMatix Corporation
gsl/4 I: Processing def.xml...

The result in error.hpp is:

 return doSomething(this.getValue());
 return this.getValue()(this.getValue());

So the second line is wrong. I would expect it to be the same as the first line. GSL seems to insert for $(my.curFunction.primalCall) the value of the local variable $(primalCall).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants