[stringtemplate-interest] What compiles to : Bytecode.INSTR_LOAD_ATTR ?

Udo Borkowski ub at abego-software.de
Sun Sep 4 02:53:25 PDT 2011


Hi Colin,

instead of 

>         group.defineTemplate("main", "string", "{<string.q>}");

just write 

>         group.defineTemplate("main", "{<string.q>}");


and it will generate an INSTR_LOAD_LOCAL

Udo


On 03.09.2011, at 14:30, Collin Fagan wrote:

> Hi Everyone,
> 
> In my (probably misguided) quest to inject attributes into the scope of a template I've overridden the getAttribute method on Interpreter. This method call gets invoked when the Interpreter runs into Bytecode.INSTR_LOAD_ATTR. My problem is that my simple test never generates this bytecode. It only generates Bytecode.INSTR_LOAD_LOCAL. 
> 
> Does anyone know what I have to do to generate Bytecode.INSTR_LOAD_ATTR?
> 
> 
> Thanks,
> 
> Collin
> 
> 
> Here is my experimental code:
> 
> /**
>  *
>  * @author collin
>  */
> public class Exp {
> 
>     private class ExtInterpreter extends Interpreter {
> 
>         public ExtInterpreter(STGroup group, Locale locale,
>                 ErrorManager errMgr, boolean debug) {
>             super(group, locale, errMgr, debug);
>             // TODO Auto-generated constructor stub
>         }
>         
>         @Override
>         public Object getAttribute(ST self, String name) {
>             System.out.println(name);
>             return super.getAttribute(self, name);
>         }
>     }
>     
>     @Test
>     public void testStaticMethodAddForString() {
>         STGroup group = new STGroup();
>         group.defineTemplate("main", "string", "{<string.q>}");
>         ST mainTemplate = group.getInstanceOf("main");
> //        mainTemplate.add("string", "this is my test string");
> 
>         Interpreter interp = new ExtInterpreter(group,Locale.getDefault(),group.errMgr,false);
>         StringWriter stringWriter = new StringWriter();
>         STWriter wr = new AutoIndentWriter(stringWriter);
>         wr.setLineWidth(STWriter.NO_WRAP);
>         interp.exec(wr, mainTemplate);
>         System.out.print(stringWriter.toString());
>     }
> }
> 
> 
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110904/ceb05f3a/attachment.html 


More information about the stringtemplate-interest mailing list