/*
 * Created on 13. jan.. 2012
 *
 * Copyright (c) 2012, Karl Trygve Kalleberg <karltk near strategoxt dot org>
 *
 * Licensed under the GNU Lesser General Public License, v2.1
 */
package org.spoofax.interpreter.library.spx;

import java.util.LinkedList;

import org.spoofax.interpreter.core.IContext;
import org.spoofax.interpreter.core.InterpreterException;
import org.spoofax.interpreter.library.AbstractPrimitive;
import org.spoofax.interpreter.stratego.SDefT;
import org.spoofax.interpreter.stratego.Strategy;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.spoofax.interpreter.terms.ITermFactory;

public class SPX_interpreter_introspect_strategies extends AbstractPrimitive {

    public SPX_interpreter_introspect_strategies() {
        super("SPX_interpreter_introspect_strategies", 0, 0);
    }

    @Override
    public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
            throws InterpreterException {
        ITermFactory f = env.getFactory();
        LinkedList<IStrategoAppl> as = new LinkedList<IStrategoAppl>();
        for(SDefT sdef : env.getVarScope().getSVars()) {
            as.addFirst(sdef.toExternalDef(f));
        }
        env.setCurrent(f.makeList(as));
        return true;
    }

}

@@ -355,16 +355,62 @@
 eption;%0A
+import org.spoofax.interpreter.core.VarScope;%0A
 import o
@@ -1057,16 +1057,22 @@
         
+final 
 ITermFac
@@ -1106,16 +1106,22 @@
         
+final 
 LinkedLi
@@ -1176,24 +1176,25 @@
 ppl%3E();%0A
+%0A
         
 for(SDef
@@ -1189,56 +1189,254 @@
     
-for(SDefT sdef : env.getVarScope().getSVars()) %7B
+// see also Context.getStrategyNames()%0A        VarScope v = env.getVarScope();%0A        while(v.getParent() != null)%0A            v = v.getParent();%0A%0A        for(SDefT sdef : v.getSVars()) %7B%0A            // FIXME: this throws NotImplementedException
 %0A   
@@ -1476,24 +1476,24 @@
 nalDef(f));%0A
-
         %7D%0A  
@@ -1490,16 +1490,17 @@
       %7D%0A
+%0A
         

Fix SPX_interpreter_introspect_strategies