Package aterm

Examples of aterm.AFun


        }
      }
    }

    public void voidVisitAppl(ATermAppl appl) throws VisitFailure {
      AFun fun = appl.getAFun();
      int nameLength;
      try{
        nameLength = fun.serialize(stream);
      }catch(IOException ioex){
        throw new VisitFailure(ioex.getMessage());
      }
      position += nameLength;
      if (fun.getArity() > 0 || nameLength == 0) {
        stream.write('(');
        position++;
        for (int i = 0; i < fun.getArity(); i++) {
          if (i != 0) {
            stream.write(',');
            position++;
          }
          voidVisitChild(appl.getArgument(i));
View Full Code Here


  public boolean match(ATerm pattern, List<Object> list) {
    if (pattern.getType() == ATerm.PLACEHOLDER) {
      ATerm t = ((ATermPlaceholder) pattern).getPlaceholder();
      if (t.getType() == ATerm.APPL) {
        ATermAppl appl = (ATermAppl) t;
        AFun afun = appl.getAFun();
        if (afun.getName().equals("placeholder") && afun.getArity() == 0 && !afun.isQuoted()) {
          list.add(t);
          return true;
        }
      }
    }
View Full Code Here

    return super.match(pattern, list);
  }

  public ATerm make(List<Object> args) {
    ATermAppl appl;
    AFun fun;
    String name;

    appl = (ATermAppl) type;
    fun = appl.getAFun();
    name = fun.getName();
    if (!fun.isQuoted()) {
      if (fun.getArity() == 0) {
        if (name.equals("term")) {
          ATerm t = (ATerm) args.get(0);
          args.remove(0);

          return t;
        } else if (name.equals("list")) {
          ATermList l = (ATermList) args.get(0);
          args.remove(0);

          return l;
        } else if (name.equals("bool")) {
          Boolean b = (Boolean) args.get(0);
          args.remove(0);

          return factory.makeAppl(factory.makeAFun(b.toString(), 0,
                false));
        } else if (name.equals("int")) {
          Integer i = (Integer) args.get(0);
          args.remove(0);

          return factory.makeInt(i.intValue());
        } else if (name.equals("real")) {
          Double d = (Double) args.get(0);
          args.remove(0);

          return factory.makeReal(d.doubleValue());
        } else if (name.equals("blob")) {
            byte[] data = (byte[]) args.get(0);
            args.remove(0);

            return factory.makeBlob(data);
        } else if (name.equals("placeholder")) {
          ATerm t = (ATerm) args.get(0);
          args.remove(0);
          return factory.makePlaceholder(t);
        } else if (name.equals("str")) {
          String str = (String) args.get(0);
          args.remove(0);
          return factory.makeAppl(factory.makeAFun(str, 0, true));
        } else if (name.equals("id")) {
          String str = (String) args.get(0);
          args.remove(0);
          return factory.makeAppl(factory.makeAFun(str, 0, false));
        } else if (name.equals("fun")) {
          String str = (String) args.get(0);
          args.remove(0);
          return factory.makeAppl(factory.makeAFun(str, 0, false));
        }
      }
      if (name.equals("appl")) {
        ATermList oldargs = appl.getArguments();
        String newname = (String) args.get(0);
        args.remove(0);
        ATermList newargs = (ATermList) oldargs.make(args);
        AFun newfun = factory.makeAFun(newname, newargs.getLength(),
            false);
        return factory.makeApplList(newfun, newargs);
      }
    }
    throw new RuntimeException("illegal pattern: " + this);
View Full Code Here

  boolean match(ATerm pattern, List<Object> list){
    if(pattern.getType() == PLACEHOLDER){
      ATerm type = ((ATermPlaceholder) pattern).getPlaceholder();
      if(type.getType() == ATerm.APPL){
        ATermAppl appl = (ATermAppl) type;
        AFun afun = appl.getAFun();
        if(afun.getName().equals("term") && afun.getArity() == 0 && !afun.isQuoted()){
          list.add(this);
          return true;
        }
      }
    }
View Full Code Here

    if (pattern.getType() == ATerm.PLACEHOLDER) {
      ATerm type = ((ATermPlaceholder) pattern).getPlaceholder();
      if (type.getType() == ATerm.APPL) {
        ATermAppl appl = (ATermAppl) type;
        AFun afun = appl.getAFun();
        if (afun.getName().equals("blob")
            && afun.getArity() == 0
            && !afun.isQuoted()) {
          list.add(data);
          return true;
            }
      }
    }
View Full Code Here

    return this;
  }

  public boolean equivalent(SharedObject obj){
    if(obj instanceof AFun){
      AFun peer = (AFun) obj;
        return peer.getName().equals(name) && peer.getArity() == arity && peer.isQuoted() == isQuoted;
    }
    return false;
  }
View Full Code Here

    if (pattern.getType() == ATerm.PLACEHOLDER) {
      ATerm type = ((ATermPlaceholder) pattern).getPlaceholder();
      if (type.getType() == ATerm.APPL) {
        ATermAppl appl = (ATermAppl) type;
        AFun afun = appl.getAFun();
        if (afun.getName().equals("real") && afun.getArity() == 0 && !afun.isQuoted()) {
          list.add(new Double(value));
          return true;
        }
      }
    }
View Full Code Here

  private ATermList makeAFunList() {
    ATermList afun_list = factory.makeList();
    Iterator<AFun> afuns = afunRegister.aFunIterator();

    while (afuns.hasNext()) {
      AFun afun = afuns.next();
      ATerm entry = makeDictEntry(afun);
      afun_list = afun_list.insert(entry);
    }
    return afun_list;
  }
View Full Code Here

  protected ATerm buildMatchPattern(ATerm t) {
    switch (t.getType()) {
    case ATerm.APPL:
      ATermAppl appl = (ATermAppl) t;
      AFun fun = appl.getAFun();
      ATerm[] newargs = new ATerm[fun.getArity()];
      for (int i = 0; i < fun.getArity(); i++) {
        newargs[i] = buildMatchPattern(appl.getArgument(i));
      }
      return pattern.getFactory().makeAppl(fun, newargs);
    case ATerm.LIST:
      ATermList list = (ATermList) t;
View Full Code Here

        extractFields(alt.getPattern(), new Location(alt.getId()));
    }

    private void extractFields(ATerm t, Location loc) {
        AFun fun;
        ATermAppl appl;
        ATermList list;

        switch (t.getType()) {
            case ATerm.APPL :
                //{{{ Call 'extractFields' for every argument

                appl = (ATermAppl) t;
                fun = appl.getAFun();
                for (int i = 0; i < fun.getArity(); i++) {
                    Location newloc = (Location) loc.clone();
                    newloc.addStep(new Step(Step.ARG, i));
                    extractFields(appl.getArgument(i), newloc);
                }
View Full Code Here

TOP

Related Classes of aterm.AFun

Copyright © 2018 www.massapicom. 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.