Package dk.brics.xmlgraph

Examples of dk.brics.xmlgraph.XMLGraph


    g.sharpen();
    return g;
  }

  public XMLGraph transferConst(ConstStm s) {
    final XMLGraph g = global_xg.clone();
    g.useFragment(stm_nodes.getTemplateConstantXMLFragment(s.getConst()));
    // open gaps
    g.processReachableNodes(new NodeProcessor<Object>() {
      @Override
      public Object process(ChoiceNode n) {
        if (n.isGap() && !n.isOpen()) {
          n.setContentAndStatus(true, false, n.getContents(), g);
        }
        return this;
      }
    });
    g.sharpen();
    return g;
  }
View Full Code Here


  private boolean unknown(XMLGraph g) {
    return g != null && g.isUnknown();
  }
 
  public XMLGraph transferCopy(final CopyStm s, final XMLGraph base, XMLGraph firstattr, XMLGraph firstchild, XMLGraph nextnode) {
    XMLGraph g = base.clone();
    if (base.isUnknown() || unknown(firstattr) || unknown(firstchild) || unknown(nextnode)) {
      g.setUnknown();
      return g;
    }
    restoreEdges(stm_nodes.getCopyLeftChoice(s, g), g);
    switch (s.getKind()) {
    case ELEMENT:
      stm_nodes.getCopyElementNode(s, g).setName(getFirstElementNames(base), g);
      restoreEdges(stm_nodes.getCopyElementNode(s, g).getContent(), g);
      if (firstattr != null) {
        g.merge(firstattr);
        stm_nodes.getCopyFirstAttribute(s, g).setContent(firstattr.getRoots(), g);
      }
      if (firstchild != null) {
        g.merge(firstchild);
        stm_nodes.getCopyFirstChild(s, g).setContent(firstchild.getRoots(), g);
      }
      if (nextnode != null) {
        g.merge(nextnode);
        stm_nodes.getCopyNextNode(s, g).setContent(nextnode.getRoots(), g);
      }
      g.getRoots().clear();
      g.getRoots().add(stm_nodes.getCopyTopNode(s, g).getIndex());
      break;
    case COMMENT:
    case PROCESSINGINSTRUCTION:
      g = nextnode.clone();
      break;
    case ATTRIBUTE:
    case ATTRNODE:
    case ATTRIBUTEGAP:
    case TEMPLATEGAP:
    case TEMPNODE:
    case TEXT:
      ChoiceNode left = stm_nodes.getCopyLeftChoice(s, g);
      final LinkedHashSet<Integer> leftContent = new LinkedHashSet<Integer>();
      if (nextnode != null) {
        g.merge(nextnode);
        g.getRoots().clear();
        g.getRoots().add(stm_nodes.getCopyTopNode(s, g).getIndex());
        stm_nodes.getCopyNextNode(s, g).setContent(nextnode.getRoots(), g);
      }
      apply(base, new CachedNodeProcessor<EPresence>() {
        @Override
        public EPresence cycle() {
          return EPresence.UNKNOWN;
        }
        @Override
        public EPresence process(AttributeNode n) {
          leftContent.add(n.getIndex());
          //addChild(left, n.getIndex(), g);
          //left.getContents().add(n.getIndex());
          return EPresence.NONEMPTY;
        }
        @Override
        public EPresence process(ElementNode n) {
          return EPresence.BOTTOM;
        }
        @Override
        public EPresence process(OneOrMoreNode n) {
          return base.getNode(n.getContent()).process(this);
        }
        @Override
        public EPresence process(TextNode n) {
          if (s.getKind() == CopyStm.Kind.TEXT) {
            if (n.getText().isEmpty())
              return EPresence.BOTTOM;
            leftContent.add(n.getIndex());
            //addChild(left, child, g)
            //left.getContents().add(n.getIndex());
            if (n.getText().isEmptyString())
              return EPresence.EMPTY;
            else if (n.getText().run(""))
              return EPresence.UNKNOWN;
            else
              return EPresence.NONEMPTY;
          }
          return EPresence.BOTTOM;
        }
        @Override
        public EPresence process(ChoiceNode n) {
          EPresence p = EPresence.BOTTOM;
          if (n.isGap() && n.isOpen()) {
            if (base.getOpenAttributeGaps().contains(n.getName()) || base.getOpenTemplateGaps().contains(n.getName())) {
              //left.getContents().add(n.getIndex());
              leftContent.add(n.getIndex());
              p = EPresence.UNKNOWN;
            }
          }
          for (int child : n.getContents()) {
            p = p.leastUpperBound(base.getNode(child).process(this));
          }
          return p;
        }
        @Override
        public EPresence process(SequenceNode n) {
          EPresence p = EPresence.EMPTY;
          for (int child : n.getContents()) {
            p = p.concat(base.getNode(child).process(this));
            if (p.definitelyNonEmpty())
              break;
          }
          return p;
        }
        @Override
        public EPresence process(InterleaveNode n) {
          EPresence p = EPresence.BOTTOM;
          for (int child : n.getContents()) {
            p = p.leastUpperBound(base.getNode(child).process(this));
          }
          return p;
        }
      });
      left.setContent(leftContent, g);
      //left.getContents().addAll(base.getRoots());
      break;
    default:
      throw new RuntimeException("unexpected copy type " + s.getKind());
    }
    g.sharpen();
    return g;
  }
View Full Code Here

    g.sharpen();
    return g;
  }
 
  public XMLGraph transferEmpty(EmptyStm s) {
    XMLGraph g = global_xg.clone();
    return g;
  }
View Full Code Here

    XMLGraph g = global_xg.clone();
    return g;
  }

  public XMLGraph transferGapify(final GapifyStm s, final XMLGraph base) {
    final XMLGraph g = base.clone();
    if (g.isUnknown()) {
      return g;
    }
    final ChoiceNode gap_node = stm_nodes.getGapifyChoiceNode(s,g);
    StatusMap smt;
    //try {
      //smt = evaluator.evaluate(base, s.getXPath(), dummy_root, dummy_root_content);
    smt = evaluateXPathOrRoot(s.getXPath(), base);
    //} catch (XPathException e) {
    //  throw new XMLXPathException(e);
    //}
    final StatusMap sm = smt;
    checkXPathEmpty(s, base, sm);
    g.processRoots(new ReachableNodesProcessor(g) { 
      @Override
      public Object process(ChoiceNode n) { // all concrete nodes have a choice node parent
        Collection<Integer> cs = new LinkedHashSet<Integer>();
        boolean modified = false;
        boolean add_gap = false;
        for (int i : n.getContents()) {
          boolean keep = true;
          boolean hit = false;
          Node c = g.getNode(i);
          if (c instanceof ConcreteNode) {
            switch (sm.get(i)) {
            case ALL:
            case DEFINITE:
              hit = true;
              keep = false;
              break;
            case SOME:
            case DONTKNOW:
              hit = true;
              break;
            case NEVER:
            case NONE:
              break;
            }
          }
          if (keep)
            cs.add(i);
          else
            modified = true;
          if (hit) {
            add_gap = true;
            boolean tgap = false;
            boolean agap = false;
            if (c instanceof ElementNode)
              tgap = true;
            else if (c instanceof AttributeNode)
              agap = true;
            else if (c instanceof TextNode) { // TODO: determine whether this is TextNode a tgap or an agap (or both)
              tgap = true;
              agap = true;
            }
            String gapname = s.getGapName();
            if (tgap)
              g.addOpenTemplateGap(gapname);
            if (agap)
              g.addOpenAttributeGap(gapname);
            if (s.getSchema() != null) {
              if (g.getGapTypeMap().get(gapname) != null &&
                  !g.getGapTypeMap().get(gapname).equals(s.getSchema().getType()))
                throw new XMLAnalysisException("Different types of gap '" + gapname + "'", s.getOrigin());
              g.getGapTypeMap().put(gapname, s.getSchema().getType());
            }
          }
        }
        if (add_gap) {
          cs.add(gap_node.getIndex());
          modified = true;
        }
        if (modified) {
          n.setContent(cs, g);
          gap_node.setContentAndStatus(true, gap_node.isRemoved(), gap_node.getContents(), g);
        }
        return null;
      }
    });
    g.sharpen();
    return g;
  }
View Full Code Here

        for (Plugging plugging : pluggings) {
            final AssignStmt statement = plugging.getStmt();
            AnalyzeStm analyzeStm = result.getHotspots().get(
                    stmt2box.get(statement));
            if (analyzeStm != null) {
                XMLGraph xg = xmlGraphs.getIn(analyzeStm, analyzeStm.getBase());
                final GapFinderByName gapFinder = new GapFinderByName(
                        plugging.getNames());
                log.debug("looking for gaps with the name: "
                        + plugging.getNames().getFiniteStrings());
                log.debug("the xml graph is known to have the following gaps:");

                if (getGapNames(xg).isEmpty()) {
                    System.out.println("empty gaps for: "
                            + SourceUtil.getLocation(plugging.getContainer()
                                    .getMethod(), plugging.getContainer()
                                    .getStatement()));
                    new XMLGraph2Dot(new PrintWriter(System.out)).print(xg);
                }
                xg.processNodes(gapFinder);
                for (ChoiceNode gap : gapFinder.getGaps()) {
                    if (!gap2plug.containsKey(gap))
                        gap2plug.put(gap, new HashSet<Plugging>());
                    gap2plug.get(gap).add(plugging);
                }
View Full Code Here

                        + " @ "
                        + SourceUtil.getLocation(container.getMethod(),
                                container.getStatement())
                        + " --> null analyzestmt");
            } else {
                XMLGraph xg = xmlGraphs.getIn(analyzeStm, analyzeStm.getBase());
                new XMLGraph2Dot(new PrintWriter(System.out)).print(xg);
                ret2xg.put(returnStmt, xg);
            }
        }
        return ret2xg;
View Full Code Here

TOP

Related Classes of dk.brics.xmlgraph.XMLGraph

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.