Package aterm

Examples of aterm.ATerm


      throws GenerationException {
    String result;
    ATermAppl appl = (ATermAppl) pattern;
    int arity = appl.getArity();
    if (arity > 0) {
      ATerm last = appl.getArgument(arity - 1);
      if (last.getType() == ATerm.PLACEHOLDER) {
        ATerm ph = ((ATermPlaceholder) last).getPlaceholder();
        if (ph.getType() == ATerm.LIST) {
          throw new RuntimeException(
              "list placeholder not supported in"
                  + " argument list of function application");
        }
      }
    }
    result = "(ATerm)ATmakeAppl"
        + (arity <= 6 ? String.valueOf(arity) : "") + "(";
    result += prefix + afunRegister.lookup(appl.getAFun());
    for (int i = 0; i < arity; i++) {
      ATerm arg = appl.getArgument(i);
      result += ", " + genConstructorImpl(arg);
    }
    result += ")";
    return result;
  }
View Full Code Here


    ATermList list = (ATermList) pattern;
    int length = list.getLength();
    if (length == 0) {
      result = "ATempty";
    } else {
      ATerm last = list.elementAt(length - 1);
      if (last.getType() == ATerm.PLACEHOLDER) {
        ATerm ph = ((ATermPlaceholder) last).getPlaceholder();
        if (ph.getType() == ATerm.LIST) {
          ATermAppl field = (ATermAppl) (((ATermList) ph).getFirst());
          result = "(ATermList)"
              + StringConversions.makeIdentifier(field.getName());
        }
      }
      if (result == null || result.length() == 0) {
        result = "ATmakeList1(" + genConstructorImpl(last) + ")";
      }
      for (int i = length - 2; i >= 0; i--) {
        ATerm elem = list.elementAt(i);
        result = "ATinsert(" + result + ", " + genConstructorImpl(elem)
            + ")";
      }
    }
    result = "(ATerm)" + result;
View Full Code Here

    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

    String name = afunRegister.lookup(afun);
    ATerm[] args = new ATerm[afun.getArity()];
    for (int j = 0; j < afun.getArity(); j++) {
      args[j] = factory.parse("x");
    }
    ATerm term = factory.makeAppl(afun, args);
    return factory.make("[" + prefix + name + ",<term>]", term);
  }
View Full Code Here

    pureFactory = new PureFactory();
  }
 
  public void testWriting() throws Exception{
    // A term
    ATerm input = pureFactory.parse("line(box(rect(2), square(4, 3)), circle(6))");
    byte[] expectedResult = new byte[]{1, 2, 4, 108, 105, 110, 101, 1, 2, 3, 98, 111, 120, 1, 1, 4, 114, 101, 99, 116, 2, 2, 1, 2, 6, 115, 113, 117, 97, 114, 101, 2, 4, 2, 3, 1, 1, 6, 99, 105, 114, 99, 108, 101, 2, 6};
    write(input, expectedResult);
   
    // A shared term
    input = pureFactory.parse("line(line(), line())");
View Full Code Here

  }
 
  public void testReading(){
    // A term
    byte[] input = new byte[]{1, 2, 4, 108, 105, 110, 101, 1, 2, 3, 98, 111, 120, 1, 1, 4, 114, 101, 99, 116, 2, 2, 1, 2, 6, 115, 113, 117, 97, 114, 101, 2, 4, 2, 3, 1, 1, 6, 99, 105, 114, 99, 108, 101, 2, 6};
    ATerm expectedResult = pureFactory.parse("line(box(rect(2), square(4, 3)), circle(6))");
    read(input, expectedResult);
   
    // A shared term
    input = new byte[]{1, 2, 4, 108, 105, 110, 101, 1, 0, 4, 108, 105, 110, 101, -128, 1};
    expectedResult = pureFactory.parse("line(line(), line())");
View Full Code Here

    buffer.put(input);
    buffer.flip();
   
    BinaryReader binaryReader = new BinaryReader(pureFactory);
    binaryReader.deserialize(buffer);
    ATerm result = binaryReader.getRoot();
   
    if(result != expectedResult){
      log("The result didn't match the expected result.");
      /*log("Was: "+result+", expected: "+expectedResult);*/
      return;
 
View Full Code Here

   
    log("Reading OK for: "+expectedResult);
  }
 
  public void testChunkification() throws VisitFailure{
    ATerm in = makeBigDummyTerm(2500);
    ByteBuffer buffer = ByteBuffer.allocate(1000);
    BinaryWriter bw = new BinaryWriter(in);
    BinaryReader binaryReader = new BinaryReader(pureFactory);
   
    while(!binaryReader.isDone()){
      buffer.clear();
      bw.serialize(buffer);
      binaryReader.deserialize(buffer);
    }
   
    ATerm result = binaryReader.getRoot();
   
    if(result == in) log("Chunkification OK");
    else log("Chunkification FAILED");
  }
View Full Code Here

        while (iter.hasNext()) {
            Entry entry = iter.next();

            if (entry.isConstructor()) {
                String altId = ((ATermAppl) entry.getAlternative()).getAFun().getName();
                ATerm pattern = entry.getTermPattern();

                Alternative alt = new Alternative(altId, pattern);

                addAlternative(typeId, type, altId, alt);
            } else {
View Full Code Here

      for (i = elems.length - 1; i >= 0; i--) {
        list = list.insert(elems[i]);
      }
      return list;
    case ATerm.PLACEHOLDER:
      ATerm ph = ((ATermPlaceholder) t).getPlaceholder();
      if (ph.getType() == ATerm.LIST) {
        return pattern.getFactory().parse("<list>");
      }
      ATerm type = ((ATermAppl) ph).getArgument(0);
      String typeName = type.toString();

      if (typeName.equals("chars")) {
        return pattern.getFactory().parse("[<list>]");
      } else if (typeName.equals("char")) {
        return pattern.getFactory().parse("<int>");
View Full Code Here

TOP

Related Classes of aterm.ATerm

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.