Package dk.brics.automaton

Examples of dk.brics.automaton.Automaton


      Automaton result = Automaton.concatenate(autos);
      return result;
    }
    @Override
    public Automaton process(OneOrMoreNode n) {
      Automaton result = graph.getNode(n.getContent()).process(this).repeat(1);
      return result;
    }
View Full Code Here


     * @param t the Soot type.
     * @return an automaton whose language contains all possible values
     *         of the result of converting this type into a string.
     */
    public final Automaton getTypeAutomaton(Type t) {
        Automaton ta = jt.getTypeAutomaton(t);
        if (ta != null) {
            return ta;
        }
        if (t instanceof RefType) {
            SootClass c = ((RefType) t).getSootClass();
View Full Code Here

    /**
     * Returns new character set with all characters in strings in the given language.
     */
    public CharSet(Automaton a) {
        Automaton b = a.singleChars();
        for (Transition t : b.getInitialState().getTransitions()) {
            intervals.add(new Interval(t.getMin(), t.getMax()));
        }
    }
View Full Code Here

    /**
     * Constructs automaton accepting strings with zero or more characters from this set.
     */
    public Automaton toAutomaton() {
        Automaton a = new Automaton();
        State s = a.getInitialState();
        s.setAccept(true);
        for (Interval v : intervals) {
            s.addTransition(new Transition(v.getMin(), v.getMax(), s));
        }
        return a;
View Full Code Here

      return null;
   
    // make return value
    Variable result;
    if (resolution.getReturnedAutomaton() != null) {
      Automaton auto = resolution.getReturnedAutomaton();
     
      Variable temp = factory.createVariable(VariableType.STRING);
      factory.addStatement(new StringInit(temp, auto));
     
      switch (resultType) {
View Full Code Here

            return type_automaton.get(t);
        } else if (t instanceof NullType) {
            return Automaton.makeString("null");
        } else if (t instanceof RefType) {
          for (Resolver resolver : resolvers) {
            Automaton at = resolver.resolveToString(((RefType)t).getSootClass());
            if (at != null)
              return at;
          }
          return null;
        } else {
View Full Code Here

      return class_hierarchy.isClassSubclassOf(a, b);
    }
   
    public Automaton resolveToStringMethod(SootClass a) {
      for (Resolver resolver : resolvers) {
        Automaton result = resolver.resolveToString(a);
        if (result != null)
          return result;
      }
      return null;
    }
View Full Code Here

        return extract(p.getFirstState(), p.getSecondState(), new HashSet<MLFAStatePair>());
    }

    private Automaton extract(MLFAState s, MLFAState f, final Set<MLFAStatePair> stack) {
        MLFAStatePair p = new MLFAStatePair(s, f);
        Automaton a = memo.get(p);
        if (a != null) {
            return a;
        }
        if (stack.contains(p)) {
            throw new RuntimeException("MLFA is non-rankable");
        }
        stack.add(p);
        Set<MLFAState> reachable = findReachable(s, f);

        // handle special case with just one automaton/epsilon/identity transition from s to f
        if (((s != f && reachable.size() == 2) || (s == f && reachable.size() == 1))
                && s.getEdges().size() == 1 && f.getEdges().size() == 0) {
            MLFATransition t = s.getEdges().iterator().next().getTransition();
            a = t.visitBy(new TransitionVisitor<Automaton>() {

                public Automaton visitAutomatonTransition(AutomatonTransition t) {
                    return t.getAutomaton();
                }

                public Automaton visitEpsilonTransition(EpsilonTransition t) {
                    return Automaton.makeEmptyString();
                }

                public Automaton visitIdentityTransition(IdentityTransition t) {
                    return extract(t.getStartState(), t.getFinalState(), stack);
                }

                public Automaton visitUnaryTransition(UnaryTransition t) {
                    return null;
                }

                public Automaton visitBinaryTransition(BinaryTransition t) {
                    return null;
                }
            });
        }
        if (a == null) {
            a = new Automaton();

            // construct automaton states
            Map<MLFAState, State> statemap = new HashMap<MLFAState, State>();
            for (MLFAState q : reachable) {
                State ss = new State();
                statemap.put(q, ss);
                if (q == s) {
                    a.setInitialState(ss);
                }
                if (q == f) {
                    ss.setAccept(true);
                }
            }

            // add transitions
            final Set<StatePair> epsilons = new HashSet<StatePair>();
            for (MLFAState q : reachable) {
                for (MLFAEdge e : q.getEdges()) {
                    if (reachable.contains(e.getDestination())) {
                        final State qq = statemap.get(q);
                        final State pp = statemap.get(e.getDestination());
                        Automaton b = e.getTransition().visitBy(new TransitionVisitor<Automaton>() {

                            public Automaton visitAutomatonTransition(AutomatonTransition t) {
                                return t.getAutomaton().clone();
                            }

                            public Automaton visitEpsilonTransition(EpsilonTransition t) {
                                epsilons.add(new StatePair(qq, pp));
                                return null;
                            }

                            public Automaton visitIdentityTransition(IdentityTransition t) {
                                return extract(t.getStartState(), t.getFinalState(), stack).clone();
                            }

                            public Automaton visitUnaryTransition(UnaryTransition t) {
                                return t.getOperation().op(extract(t.getStartState(), t.getFinalState(), stack));
                            }

                            public Automaton visitBinaryTransition(BinaryTransition t) {
                                return t.getOperation().op(
                                        extract(t.getStartState1(), t.getFinalState1(), stack),
                                        extract(t.getStartState2(), t.getFinalState2(), stack));
                            }
                        });
                        if (b != null) {
                            epsilons.add(new StatePair(qq, b.getInitialState()));
                            for (State rr : b.getAcceptStates()) {
                                rr.setAccept(false);
                                epsilons.add(new StatePair(rr, pp));
                            }
                        }
                    }
View Full Code Here

    //
    //  WRAPPERS
    //
    else if (isWrapperClass(declaringClass)) {
      if (methodName.equals("toString") && numArgs == 0) {
        Automaton typeAuto = Automatons.fromType(declaringClass.getName());
        if (typeAuto == null)
          throw new RuntimeException("Unknown wrapper class " + declaringClass.getName());
       
        Variable result = factory.createVariable(VariableType.STRING);
        factory.addStatement(new StringInit(result, typeAuto));
View Full Code Here

            factory.addStatement(new StringInit(result, Basic.makeAnyString()));
          }
          break;
         
        case OBJECT:
          Automaton auto = Basic.makeAnyString();
          if (val.getType() instanceof RefType) {
            Automaton resolved = factory.resolveToStringMethod(((RefType)val.getType()).getSootClass());
            if (resolved != null)
              auto = resolved;
          }
          factory.addStatement(new StringInit(result, auto));
          break;
View Full Code Here

TOP

Related Classes of dk.brics.automaton.Automaton

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.