Package aterm

Examples of aterm.ATermList


      if(term.getChildCount() > current.subTermIndex + 1){
        if(term.getType() != ATerm.LIST){
          next = (ATerm) term.getChildAt(++current.subTermIndex);
        }else{
          ATermList nextList = current.nextPartOfList;
          next = nextList.getFirst();
          current.nextPartOfList = nextList.getNext();
         
          current.subTermIndex++;
        }
       
        ATermMapping child = new ATermMapping();
View Full Code Here


    return str.toString();
  }

  private ATermList parseATerms(ATermReader reader) throws IOException {
    ATerm[] terms = parseATermsArray(reader);
    ATermList result = empty;
    for (int i = terms.length - 1; i >= 0; i--) {
      result = makeList(terms[i], result);
    }

    return result;
View Full Code Here

          throw new ParseError("illegal character: '" + (char) reader.getLastChar() + "'");
        }
    }

    if (reader.getLastChar() == '{') {
      ATermList annos;
      if (reader.readSkippingWS() == '}') {
        reader.readSkippingWS();
        annos = empty;
      } else {
        annos = parseATerms(reader);
View Full Code Here

        }
       
        result = makeAppl(fun, newArguments);
        break;
      case ATerm.LIST:
        ATermList list = (ATermList) term;
        if(list.isEmpty()){
          result = empty;
          break;
        }
        ATerm first = importTerm(list.getFirst());
        ATermList next = (ATermList) importTerm(list.getNext());
       
        result = makeList(first, next);
        break;
      case ATerm.INT:
        ATermInt integer = (ATermInt) term;
       
        result = makeInt(integer.getInt());
        break;
      case ATerm.LONG:
        ATermLong elongatedType = (ATermLong) term;
       
        result = makeLong(elongatedType.getLong());
        break;
      case ATerm.REAL:
        ATermReal real = (ATermReal) term;
       
        result = makeReal(real.getReal());
        break;
      case ATerm.PLACEHOLDER:
        ATermPlaceholder placeHolder = (ATermPlaceholder) term;
       
        result = makePlaceholder(importTerm(placeHolder.getPlaceholder()));
        break;
      case ATerm.AFUN:
        AFun afun = (AFun) term;
       
        return makeAFun(afun.getName(), afun.getArity(), afun.isQuoted());
      default:
        throw new RuntimeException("Unknown term type id: "+term.getType());
    }
   
    if(term.hasAnnotations()){
      ATermList annotations = term.getAnnotations();
      result = result.setAnnotations(annotations);
    }
   
    return result;
  }
View Full Code Here

      if (child.getType() == ATerm.LIST) {
        stream.write(']');
        position++;
      }

      ATermList annos = child.getAnnotations();
      if (!annos.isEmpty()) {
        stream.write('{');
        position++;
        visit(annos);
        stream.write('}');
        position++;
View Full Code Here

          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

  public boolean hasAnnotations(){
    return (annotations != null && !annotations.isEmpty());
  }

  public ATerm setAnnotation(ATerm label, ATerm anno){
    ATermList new_annos = annotations.dictPut(label, anno);
    ATerm result = setAnnotations(new_annos);

    return result;
  }
View Full Code Here

  }

  private String buildListConstructorImpl(ATerm pattern)
      throws GenerationException {
    String result = null;
    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

      for (int j = 0; j < appl.getArity(); j++) {
        result.append(genNestedComparison(appl.getArgument(j),
            termName, j, true));
      }
    } else if (pattern.getType() == ATerm.LIST) {
      ATermList list = (ATermList) pattern;

      if (list.isEmpty()) {
        result.append(genIndentation() + "if (ATisEmpty((ATermList)"
            + termName + ")) " + genCompareFunctOpenBracket());
      } else {
        result.append(genIndentation() + "if (ATgetType((ATerm)"
            + termName + ") == AT_LIST && ATisEmpty((ATermList)"
            + termName + ") == ATfalse) "
            + genCompareFunctOpenBracket());

        StringBuffer headName = new StringBuffer(termName + "_head");
        StringBuffer tailName = new StringBuffer(termName + "_list");
        StringBuffer headDecl = new StringBuffer(genIndentation()
            + "ATerm " + headName + ";" + newLine);
        StringBuffer headDef = new StringBuffer(headName
            + " = ATgetFirst(" + tailName + ");" + newLine);
        StringBuffer tailDecl = new StringBuffer(genIndentation()
            + "ATermList " + tailName + " = (ATermList)" + termName /* JURGEN */
            + ";" + newLine);
        StringBuffer tailDef = new StringBuffer(tailName
            + " = ATgetNext(" + tailName + ");" + newLine);
        StringBuffer tempResult = new StringBuffer();
        StringBuffer checkHeadCode = new StringBuffer();
        boolean headDeclared = false;

        for (int j = 0; !list.isEmpty(); j++) {
          String getHeadCode = genIndentation() + headDef;
          String getTailCode = genIndentation() + tailDef;
          checkHeadCode = genNestedComparison(list.getFirst(),
              headName, j, false);

          /*
           * If the head contains a predefined type, it can be
           * checked.
           */
          if (checkHeadCode.length() > 0) {
            if (!headDeclared) {
              result.append(headDecl);
              headDeclared = true;
            }

            tempResult.append(getHeadCode);
            tempResult.append(getTailCode);
            tempResult.append(checkHeadCode);
            list = list.getNext();

            /*
             * If the last element of the list is a list placeholder
             * then don't do any additional checking.
             */
            if (!list.isEmpty()
                && list.getFirst().getType() == ATerm.PLACEHOLDER
                && (((ATermPlaceholder) list.getFirst())
                    .getPlaceholder()).getType() == ATerm.LIST
                && (list.getNext()).isEmpty()) {
              break;
            } else if (!list.isEmpty()) {
              tempResult.append(genIndentation()
                  + "if (ATgetType((ATerm)" + tailName
                  + ") == AT_LIST && ATisEmpty((ATermList)"
                  + tailName + ") == ATfalse) "
                  + genCompareFunctOpenBracket());
            } else { /* the list must be empty */
              tempResult.append(genIndentation()
                  + "if (ATgetType((ATerm)" + tailName
                  + ") == AT_LIST && ATisEmpty((ATermList)"
                  + tailName + ") == ATtrue) "
                  + genCompareFunctOpenBracket());
            }
          } else {
            list = list.getNext();
            /*
             * If the last element of the list is a list placeholder
             * then don't do any additional checking.
             */
            if (!list.isEmpty()
                && list.getFirst().getType() == ATerm.PLACEHOLDER
                && (((ATermPlaceholder) list.getFirst())
                    .getPlaceholder()).getType() == ATerm.LIST
                && (list.getNext()).isEmpty()) {
              break;
            } else if (!list.isEmpty()) {
              tempResult.append(getTailCode);

              tempResult.append(genIndentation()
                  + "if (ATgetType((ATerm)" + tailName
                  + ") == AT_LIST && ATisEmpty((ATermList)"
View Full Code Here

            + genCompareFunctOpenBracket());
      }
    }

    if (type.getType() == ATerm.LIST) {
      ATermList list = (ATermList) type;
      result.append(genPlaceholderComparison(list.getFirst(), argName, 0,
          true));
    }

    return result;
  }
View Full Code Here

TOP

Related Classes of aterm.ATermList

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.