Package org.eclipse.imp.pdb.facts

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


  }

  private IValue traverseNodeOnce(IValue subject, CaseBlockList casesOrRules,
      DIRECTION direction, PROGRESS progress, FIXEDPOINT fixedpoint, TraverseResult tr) {
    IValue result;
    INode node = (INode)subject;
    if (node.arity() == 0 && !(node.mayHaveKeywordParameters() && node.asWithKeywordParameters().hasParameters()) ){
      result = subject;
    }
    else {
      IValue args[] = new IValue[node.arity()];
      Map<String, IValue> kwParams = null;
      if (node.mayHaveKeywordParameters() && node.asWithKeywordParameters().hasParameters()) {
        kwParams = new HashMap<>();
      }
      boolean hasChanged = false;
      boolean hasMatched = false;
     
      for (int i = 0; i < node.arity(); i++){
        IValue child = node.get(i);
        tr.changed = false;
        tr.matched = false;
        args[i] = traverseOnce(child, casesOrRules, direction, progress, fixedpoint, tr);
        hasChanged |= tr.changed;
        hasMatched |= tr.matched;
      }
      if (kwParams != null) {
        IWithKeywordParameters<? extends INode> nodeKw = node.asWithKeywordParameters();
        for (String kwName : nodeKw.getParameterNames()) {
          IValue val = nodeKw.getParameter(kwName);
          tr.changed = false;
          tr.matched = false;
          IValue newVal = traverseOnce(val, casesOrRules, direction, progress, fixedpoint, tr);
          kwParams.put(kwName, newVal);
          hasChanged |= tr.changed;
          hasMatched |= tr.matched;
        }
      }
     
      tr.changed = hasChanged;
      tr.matched = hasMatched;
     
      INode n = null;
      if (kwParams != null) {
        n = eval.getValueFactory().node(node.getName(), args, kwParams);
      }
      else {
        n = eval.getValueFactory().node(node.getName(), args);
     
        if (!node.mayHaveKeywordParameters() && node.asAnnotatable().hasAnnotations()) {
          n = n.asAnnotatable().setAnnotations(node.asAnnotatable().getAnnotations());
        }
      }
     
      result = n;
    }
View Full Code Here


        return values.tuple(implodeArgs(store, type, args, ctx));
      }
     
      // if in node space, make untyped nodes
      if (isUntypedNodeType(type)) {
        INode ast = values.node(constructorName, implodeArgs(store, type, args, ctx));
        return ast.asAnnotatable().setAnnotation("location", TreeAdapter.getLocation(tree)).asAnnotatable().setAnnotation("comments", comments);
      }
     
      // make a typed constructor
      if (!type.isAbstractData()) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Constructor (" + constructorName + ") should match with abstract data type and not with " + type));
      }

      Set<Type> conses = findConstructors(type, constructorName, length, store);
      Iterator<Type> iter = conses.iterator();
      while (iter.hasNext()) {
        try {
          Type cons = iter.next();
          ISourceLocation loc = TreeAdapter.getLocation(tree);
          IValue[] implodedArgs = implodeArgs(store, cons, args, ctx);
          IConstructor ast = makeConstructor(type, constructorName, ctx, implodedArgs);
          return ast.asAnnotatable().setAnnotation("location", loc).asAnnotatable().setAnnotation("comments", comments);
        }
        catch (Backtrack b) {
          continue;
        }
      }
View Full Code Here

TOP

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

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.