Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.IListWriter


    if(!v.getType().isTuple())
      throw RuntimeExceptionFactory.illegalArgument(v, null, null, "argument of type tuple is required");
    ITuple tp = (ITuple) v;
    Type tt = tp.getType();
    int a = tt.getArity();
    IListWriter w = values.listWriter();
    for(int i = 0; i < a; i++){
      String fname = tt.getFieldName(i);
      if(fname == null)
        fname = "";
      w.append(values.string(fname));
    }
    return w.done();
  }
View Full Code Here


    INumber zero = diff.subtract(diff); // zero in the type that we're dealing with.

    // Use declared types here
    Type resultType = second.getType().lub(from.getType().lub(to.getType()));
   
    IListWriter w = vf.listWriter();
    if (iFrom.lessEqual(iTo).getValue() && diff.greater(zero).getValue()) {
       while (iFrom.less(iTo).getValue()) {
        w.append(iFrom);
        iFrom = iFrom.add(diff);
        if (ctx.isInterrupted()) throw new InterruptException(ctx.getStackTrace(), ctx.getCurrentAST().getLocation());
      };
    }
    else if (iFrom.greaterEqual(iTo).getValue() && diff.less(zero).getValue()) {
       while (iFrom.greater(iTo).getValue()) {
        w.append(iFrom);
        iFrom = iFrom.add(diff);
      };
    }
    return makeResult(tf.listType(resultType), w.done(), ctx)
  }
View Full Code Here

      }

      @Override
      public IValue visitList(Type type) {
        if(type.isListRelation()) {
          IListWriter w = vf.listWriter();

          if (type.hasFieldNames()) {
            for (int i = 0; i < type.getArity(); i++) {
              w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
            }
          }
          else {
            if (type.getFieldTypes().isBottom()) {
              return vf.constructor(Factory.Symbol_List, vf.constructor(Factory.Symbol_Void));
            }
         
            for (Type f : type.getFieldTypes()) {
              w.append(f.accept(this));
            }
          }
       
          return vf.constructor(Factory.Symbol_ListRel, w.done());
        }
        return vf.constructor(Factory.Symbol_List, type.getElementType().accept(this));
      }

      @Override
      public IValue visitMap(Type type) {
        if (type.hasFieldNames()) {
          return vf.constructor(Factory.Symbol_Map, vf.constructor(Factory.Symbol_Label, vf.string(type.getKeyLabel()), type.getKeyType().accept(this)), vf.constructor(Factory.Symbol_Label, vf.string(type.getValueLabel()), type.getValueType().accept(this)));
        }
        else {
          return vf.constructor(Factory.Symbol_Map, type.getKeyType().accept(this), type.getValueType().accept(this));
        }
      }

      @Override
      public IValue visitNumber(Type type) {
        return vf.constructor(Factory.Symbol_Num);
      }

      @Override
      public IValue visitAlias(Type type) {
        IListWriter w = vf.listWriter();
        Type params = type.getTypeParameters();
       
        if (params.getArity() > 0) {
          for (Type t : params) {
            w.append(t.accept(this));
          }
        }
       
        return vf.constructor(Factory.Symbol_Alias, vf.string(type.getName()), w.done(), type.getAliased().accept(this));
      }

      @Override
      public IValue visitSet(Type type) {
        if(type.isRelation()) {
          IListWriter w = vf.listWriter();

          if (type.hasFieldNames()) {
            for (int i = 0; i < type.getArity(); i++) {
              w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
            }
          }
          else {
            if (type.getFieldTypes().isBottom()) {
              return vf.constructor(Factory.Symbol_Set, vf.constructor(Factory.Symbol_Void));
            }
            for (Type f : type.getFieldTypes()) {
              w.append(f.accept(this));
            }
          }
       
          return vf.constructor(Factory.Symbol_Rel, w.done());
        }
        return vf.constructor(Factory.Symbol_Set, type.getElementType().accept(this));
      }

      @Override
      public IValue visitSourceLocation(Type type) {
        return vf.constructor(Factory.Symbol_Loc);
      }

      @Override
      public IValue visitString(Type type) {
        return vf.constructor(Factory.Symbol_Str);
      }

      @Override
      public IValue visitNode(Type type) {
        return vf.constructor(Factory.Symbol_Node);
      }

      @Override
      public IValue visitConstructor(Type type) {
        IValue adt = cache.get(type.getAbstractDataType());
       
        if (adt == null) {
          visitAbstractData(type.getAbstractDataType());
        }
       
        IValue result = cache.get(type);
       
        if (result == null) {
          IListWriter w = vf.listWriter();

          if (type.hasFieldNames()) {
            for (int i = 0; i < type.getArity(); i++) {
              w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
            }
          }
          else {
            for (Type field : type.getFieldTypes()) {
              w.append(field.accept(this));
            }
          }
         
         
         
          result = vf.constructor(Factory.Symbol_Cons, vf.constructor(Factory.Symbol_Label, vf.string(type.getName()), adt), w.done());

          cache.put(type, result);
          addConstructorDefinition((IConstructor) result, type);
        }
       
        return result;
      }

      private void addConstructorDefinition(IConstructor result, Type type) {
        IConstructor adt = (IConstructor) type.getAbstractDataType().accept(this);
       
        IConstructor choice = definitions.get(adt);
        ISetWriter alts = vf.setWriter();
       
        if (choice != null) {
          alts.insertAll((ISet) choice.get("alternatives"));
        }
       
        IListWriter w = vf.listWriter();
        if (type.hasFieldNames()) {
          for(int i = 0; i < type.getArity(); i++) {
            w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
          }
        }
        else {
          for (Type field : type.getFieldTypes()) {
            w.append(field.accept(this));
          }
        }
       
        IListWriter kwTypes = vf.listWriter();
        IMapWriter kwDefaults = vf.mapWriter();
       
        for (String key : type.getKeywordParameters()) {
          kwTypes.insert(vf.constructor(Factory.Symbol_Label, vf.string(key), type.getKeywordParameterType(key).accept(this)));
        }
       
        alts.insert(vf.constructor(Factory.Production_Cons, vf.constructor(Factory.Symbol_Label,  vf.string(type.getName()), adt), w.done(), kwTypes.done(), kwDefaults.done(), vf.set()));
        choice = vf.constructor(Factory.Production_Choice, adt, alts.done());
        definitions.put(adt, choice);
      }
     
     

      @Override
      public IValue visitAbstractData(Type type) {
        IValue sym = cache.get(type);
       
        if (sym == null) {
          IListWriter w = vf.listWriter();
          Type params = type.getTypeParameters();
          if (params.getArity() > 0) {
            for (Type param : params) {
              w.append(param.accept(this));
            }
          }
         
          sym = vf.constructor(Factory.Symbol_Adt, vf.string(type.getName()), w.done());
          cache.put(type, sym);
       

          // make sure to find the type by the uninstantiated adt
          Type adt = store.lookupAbstractDataType(type.getName());
          for (Type cons : store.lookupAlternatives(adt)) {
            cons.accept(this);
          }
        }
       
        return sym;
      }

      @Override
      public IValue visitTuple(Type type) {
        IListWriter w = vf.listWriter();
       
        if (type.hasFieldNames()) {
          for (int i = 0; i < type.getArity(); i++) {
            w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
          }
        }
        else {
          for (Type f : type) {
            w.append(f.accept(this));
          }
        }

        return vf.constructor(Factory.Symbol_Tuple, w.done());
      }

      @Override
      public IValue visitValue(Type type) {
        return vf.constructor(Factory.Symbol_Value);
      }

      @Override
      public IValue visitVoid(Type type) {
        return vf.constructor(Factory.Symbol_Void);
      }

      @Override
      public IValue visitBool(Type boolType) {
        return vf.constructor(Factory.Symbol_Bool);
      }

      @Override
      public IValue visitParameter(Type parameterType) {
        return vf.constructor(Factory.Symbol_BoundParameter, vf.string(parameterType.getName()), parameterType.getBound().accept(this));
      }

      @Override
      public IValue visitExternal(Type externalType) {
        if (externalType instanceof NonTerminalType) {
          return visitNonTerminalType((NonTerminalType) externalType);
        }
        else if (externalType instanceof ReifiedType) {
          return visitReifiedType((ReifiedType) externalType);
        }
        else if (externalType instanceof FunctionType) {
          return visitFunctionType((FunctionType) externalType);
        }
       
        throw new ImplementationError("unable to reify " + externalType);
      }

      private IValue visitFunctionType(FunctionType externalType) {
        IListWriter w = vf.listWriter();
        for (Type arg : externalType.getArgumentTypes()) {
          w.append(arg.accept(this));
        }
       
        return vf.constructor(Factory.Symbol_Func, externalType.getReturnType().accept(this), w.done());
      }

      private IValue visitReifiedType(ReifiedType externalType) {
        return vf.constructor(Factory.Symbol_ReifiedType, externalType.getTypeParameters().getFieldType(0).accept(this));
      }
View Full Code Here

  public IConstructor createCharNode(int charNumber){
    return VF.constructor(Factory.Tree_Char, VF.integer(charNumber));
  }

  public IConstructor createLiteralNode(int[] characters, Object production){
    IListWriter listWriter = VF.listWriter(Factory.Tree);
    for(int i = characters.length - 1; i >= 0; --i){
      listWriter.insert(VF.constructor(Factory.Tree_Char, VF.integer(characters[i])));
    }
   
    return VF.constructor(Factory.Tree_Appl, (IConstructor) production, listWriter.done());
  }
View Full Code Here

   
    return VF.constructor(Factory.Tree_Appl, (IConstructor) production, listWriter.done());
  }
 
  private static IConstructor buildAppl(ArrayList<IConstructor> children, Object production){
    IListWriter childrenListWriter = VF.listWriter(Factory.Tree);
    for(int i = children.size() - 1; i >= 0; --i){
      childrenListWriter.insert(children.get(i));
    }
   
    return VF.constructor(Factory.Tree_Appl, (IConstructor) production, childrenListWriter.done());
  }
View Full Code Here

  public IConstructor createSubListCycleNode(Object production){
    return buildCycle(1, production);
  }

  public IConstructor createRecoveryNode(int[] characters){
    IListWriter listWriter = VF.listWriter(Factory.Tree);
    for(int i = characters.length - 1; i >= 0; --i){
      listWriter.insert(VF.constructor(Factory.Tree_Char, VF.integer(characters[i])));
    }
   
    return VF.constructor(Factory.Tree_Appl, VF.constructor(Factory.Production_Skipped), listWriter.done());
  }
View Full Code Here

    return null;
  }

  private IList getASTArgs(IConstructor tree) {
    IList children = TreeAdapter.getArgs(tree);
    IListWriter writer = ValueFactoryFactory.getValueFactory().listWriter(Factory.Args.getElementType());
 
    for (int i = 0; i < children.length(); i++) {
      IConstructor kid = (IConstructor) children.get(i);
      if (!TreeAdapter.isLiteral(kid) && !TreeAdapter.isCILiteral(kid) && !TreeAdapter.isEmpty(kid)) {
        writer.append(kid)
      }
      // skip layout
      i++;
    }
   
    return writer.done();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.IListWriter

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.