Package abstrasy.pcfx

Source Code of abstrasy.pcfx.PCFx_store_static

package abstrasy.pcfx;


import abstrasy.Hash;
import abstrasy.Node;
import abstrasy.PCoder;
import abstrasy.Tools;

/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
*   http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/

public class PCFx_store_static extends PCFx {

    /**
     * respecte la protection de la finalité des listes
     */
    public PCFx_store_static() {
    }

    /**
     * eval
     *
     * @param startAt Node
     * @return Node
     * @throws Exception
     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        /**
     *  forme générale : (store! valeur in liste/string/hash/deleg at position/clé)
     *                    0      1      2  3                       4  5
     */

        /**
     * vérification élémentaire de la syntaxe
     */
        startAt.requirePCode(2, PCoder.PC_IN);
        startAt.requirePCode(4, PCoder.PC_AT);
        startAt.isGoodArgsCnt(6);

        /**
     * début du traitement
     */
        startAt.requireNodeType(3, Node.VTYPE_INDIRECTION);
        Node xnode = startAt.getSubNode(3, Node.TYPE_HASH | Node.TYPE_CLIST | Node.TYPE_STRING | Node.VTYPE_DELEGABLE);


        /*
         * Cas où (store! valeur in objet at clé)... Il s'agit d'une surcharge...
         */
        if (xnode.isDelegable())
            return Node.VDelegable.evalMethod(xnode, PCoder.getMethod(PCoder.PC_STORE_STATIC),
                    Node.createCList().append(startAt.getSubNode(5, Node.VTYPE_VALUABLE)).append(startAt.getSubNode(1, Node.VTYPE_VALUABLE)));

        /*
         * autres...
         */

        long qt = xnode.getQType();

        if (qt == Node.TYPE_CLIST) {


            xnode.requireAccessType(Node.ACCESSTYPE_WRITELOCK);
            /*
             *    (store! x in [...] at index)
             */
            int index = (int) startAt.getSubNode(5, Node.TYPE_NUMBER).getNumber();


            index = Tools.computeAbsoluteIndex(xnode.size(), index, 1);


            xnode.setElementAt(startAt.getSubNode(1, Node.VTYPE_VALUABLE).secure(), index);


        }
        else if (qt == Node.TYPE_HASH) {


            xnode.requireAccessType(Node.ACCESSTYPE_WRITELOCK);
            /*
             *    (store! x in hash at index)
             */
            Node k = startAt.getSubNode(5, Hash.KEY_TYPES);

            xnode.getHash().store(k, startAt.getSubNode(1, Node.VTYPE_VALUABLE).secure());


        }
        else if (qt == Node.TYPE_STRING) {


            xnode.requireAccessType(Node.ACCESSVTYPE_MUTABLE_WRITELOCK);
            /*
             * (store! "x" in "..." at index)
             */
            int index = (int) startAt.getSubNode(5, Node.TYPE_NUMBER).getNumber();
            String vs = startAt.getSubNode(1, Node.TYPE_STRING).getString();


            index = Tools.computeAbsoluteIndex(xnode.getString().length(), index, vs.length());


            StringBuffer stmp = new StringBuffer(xnode.getString());
            stmp.replace(index, index + vs.length(), vs);
            xnode.setString(stmp.toString());


        }


        return null;

    }

}
TOP

Related Classes of abstrasy.pcfx.PCFx_store_static

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.