Package dk.brics.automaton

Examples of dk.brics.automaton.Automaton


    // Otherwise just handle it as a normal call with only one possible target
    result = makeVariable(getType(v.getMethod().getReturnType()));
    handleInvocationTarget(result, v, method, callee, arguments);
   
        // if the called method was annotated, use the static type instead
        Automaton staticType = factory.getMethodReturnType(v.getMethod());
        if (staticType != null)
            return makeAutomatonVariable(staticType);
        else
            return result;
  }
View Full Code Here


    }
   
    factory.endBranch();
   
    // if the called method was annotated, use the static type instead
        Automaton staticType = factory.getMethodReturnType(v.getMethod());
    if (staticType != null)
        return makeAutomatonVariable(staticType);
    else
        return result;
  }
View Full Code Here

    return makeVariable(VariableType.NULL);
  }
 
  @Override
  public Variable caseParameterRef(ParameterRef v, ValueBox box) {
      Automaton staticType = factory.getParameterType(v);
      if (staticType != null) {
          return makeAutomatonVariable(staticType);
      }
    return factory.getParameter(v);
  }
View Full Code Here

  @Override
  public Variable caseStaticInvokeExpr(StaticInvokeExpr v, ValueBox box) {
      Variable result = null;
     
      // find the static string return type, if it has one
      Automaton staticReturn = factory.getMethodReturnType(v.getMethod());
      if (staticReturn != null) {
          result = makeAutomatonVariable(staticReturn);
      }
     
    // evaluate all arguments
View Full Code Here

        if (type == VariableType.NONE)
            return getNothing();
       
        // if the field is @Type annotated, create a variable with its static type
        if (factory.fromSootType(v.getType()) == VariableType.STRING) {
            Automaton staticType = factory.getFieldType(v.getField());
            if (staticType != null) {
                return makeAutomatonVariable(staticType);
            }
        }
       
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        for (State s : b.getStates()) {
            Set<Transition> transitions = s.getTransitions();
            for (Transition t : new ArrayList<Transition>(transitions)) {
                char min = t.getMin();
                char max = t.getMax();
                State dest = t.getDest();
                if (min != Character.MIN_VALUE || max != Character.MAX_VALUE) {
                    transitions.remove(t);
                    for (int c = min; c <= max; c++) {
                      String up = String.valueOf((char)c).toUpperCase();
                      if (up.length() == 1) {
                        transitions.add(new Transition(Character.toUpperCase((char) c), dest));
                      } else {
                        // YES some characters translate to more than one character when turned upper case
                        // for example the German character "�" becomes "SS"
                        State lastState = s;
                        for (int i=0; i<up.length()-1; i++) {
                          char ch = up.charAt(i);
                          State state = new State();
                          lastState.addTransition(new Transition(ch, state));
                          lastState = state;
                        }
                        lastState.addTransition(new Transition(up.charAt(up.length()-1), dest));
                      }
                    }
                }
            }
        }
        b.setDeterministic(false);
        b.reduce();
        b.minimize();
        return b;
    }
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        State accept = new State();
        accept.setAccept(true);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            epsilons.add(new StatePair(s, accept));
        }
        b.addEpsilons(epsilons);
        b.minimize();
        return b;
    }
View Full Code Here

    StringAnalysis.addResolver(new Resolver() {
      public MethodResolution resolveMethod(InvokeExpr e, SootMethod m) {
        String sig = m.getSignature();
        if (sig.equals("<dk.brics.xact.XML: java.lang.String getString(java.lang.String)>") ||
            sig.equals("<dk.brics.xact.XML: java.lang.String getString()>")) {
          Automaton a = Datatypes.get("string"); // TODO: should use the XML graph (run twice!?)
          return new MethodResolution(e.getArgCount(), a);
        }
        // TODO methods taking an Iterable or array should not corrupt the argument
        if (sig.equals("<dk.brics.xact.XML: dk.brics.xact.XML concat(java.lang.Object[])>")) {
          MethodResolution r = new MethodResolution(1, Automaton.makeAnyString());
View Full Code Here

                        Stmt stmt = (Stmt) unit;
                        if (stmt.containsInvokeExpr()) {
                            InvokeExpr expr = stmt.getInvokeExpr();
                            if (expr.getMethod().getSignature().equals("<dk.brics.string.runtime.Strings: java.lang.String analyze(java.lang.String,java.lang.String)>")) {
                                ValueBox spot = expr.getArgBox(0);
                                Automaton expected = getRegExp(expr).toAutomaton(bindings);
                                hotspots.add(new RuntimeHotspot(spot, expected, HotspotKind.ANALYZE));
                            } else
                            if (expr.getMethod().getSignature().equals("<dk.brics.string.runtime.Strings: java.lang.String analyze(java.lang.String,java.net.URL)>")) {
                                ValueBox spot = expr.getArgBox(0);
                                Automaton expected = bindings.getFromURL(bindings.getConstantURL(expr.getArg(1)));
                                hotspots.add(new RuntimeHotspot(spot, expected, HotspotKind.ANALYZE));
                            } else
                            if (expr.getMethod().getSignature().equals("<dk.brics.string.runtime.Strings: java.lang.String check(java.lang.String,java.lang.String)>")) {
                                ValueBox spot = expr.getArgBox(0);
                                Automaton expected = getRegExp(expr).toAutomaton(bindings);
                                hotspots.add(new RuntimeHotspot(spot, expected, HotspotKind.CHECK));
                            } else
                            if (expr.getMethod().getSignature().equals("<dk.brics.string.runtime.Strings: java.lang.String check(java.lang.String,java.net.URL)>")) {
                                ValueBox spot = expr.getArgBox(0);
                                Automaton expected = bindings.getFromURL(bindings.getConstantURL(expr.getArg(1)));
                                hotspots.add(new RuntimeHotspot(spot, expected, HotspotKind.CHECK));
                            }
                        }
                    }
                }
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        for (State s : b.getStates()) {
            Set<Transition> transitions = s.getTransitions();
            for (Transition t : new ArrayList<Transition>(transitions)) {
                char min = t.getMin();
                char max = t.getMax();
                State dest = t.getDest();
                if (min <= c && c <= max) {
                    transitions.add(new Transition(Character.MIN_VALUE, Character.MAX_VALUE, dest));
                }
            }
        }
        b.setDeterministic(false);
        b.reduce();
        b.minimize();
        return b;
    }
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.