Package dk.brics.automaton

Examples of dk.brics.automaton.Automaton


    if (re.endsWith("$") && !re.endsWith("\\$")) {
      re = re.substring(0, re.length() - 1);
    }

    Automaton automaton = new RegExp(re).toAutomaton();
    prefixBegin = automaton.getCommonPrefix();
    prefixLen = prefixBegin.length();

    if (0 < prefixLen) {
      char max = (char) (prefixBegin.charAt(prefixLen - 1) + 1);
      prefixEnd = prefixBegin.substring(0, prefixLen - 1) + max;
View Full Code Here


    private RunAutomaton runauto = null;
   
    public CompiledAutomaton( String rhsPattern ) {
        RegExp regexpr = new dk.brics.automaton.RegExp(rhsPattern, RegExp.NONE);
        Automaton auto = regexpr.toAutomaton();
        this.runauto = new RunAutomaton(auto, true);
    }
View Full Code Here

    public static void main(String[] args) {
        boolean isLength = args[0].equals("length");
        RegExp r = new RegExp(args[1]);
        String prefix = args[2];
        int length=0;
        Automaton a = r.toAutomaton();
//        System.out.println(a.toDot());
        if (!isLength) {
            length = Integer.parseInt(args[3])-1;
            if (length==-1) {
                if (a.getInitialState().isAccept()) {
                    System.out.println("TRUE");
                } else {
                    System.out.println("FALSE");
                }
            } else {
                System.out.println(toCVC3FormulaString(a,prefix,length));
            }
        } else {
            boolean accept = args[3].equals("true");
            String example = a.getShortestExample(accept);
            if (example != null)
                System.out.println("(" + prefix + " >= " + example.length() + ")");
            else
                System.out.println("(" + prefix + " >= " + 0 + ")");
        }
View Full Code Here

            } else {
                log.fatal("unrecognized runtime method!");
                System.exit(1);
            }
            log.info("Checking " + kind + " at line " + line + " in " + sf + "...");
            Automaton a = sa.getAutomaton(e);
            Automaton expected_neg = rh.expected.complement();
            if (rh.kind == HotspotKind.ANALYZE) {
                Automaton diff = a.intersection(expected_neg);
                if (diff.isEmpty()) {
                    if (a.equals(rh.expected)) {
                        log.info("Exact match!");
                    } else {
                        log.info("Always satisfied!");
                    }
                } else {
                    log.info("Dissatisfied by:");
                    log.info("\"" + Misc.escape(diff.getShortestExample(true)) + "\"");
                }
            } else if (rh.kind == HotspotKind.CHECK) {
                if (a.intersection(expected_neg).isEmpty()) {
                    log.info("Always satisfied!");
                } else if (a.intersection(rh.expected).isEmpty()) {
                    log.info("Never satisfied!");
                }
            }
        }
       
        // report results for annotation hotspots
        for (ValueBox box : annotationHotspots) {
            String sf = sa.getSourceFile(box);
            int line = sa.getLineNumber(box);
            Automaton auto = sa.getAutomaton(box);
            Automaton expected = aa.getAutomaton(box);
            System.out.print(sf + ":" + line + " ");
            if (!auto.subsetOf(expected)) {
                Automaton violating = auto.minus(expected);
                String example = Misc.escape(violating.getShortestExample(true));
                String type = aa.getDescription(expected);
                if (type.length() > 25) // 25 is completely arbitrary
                    type = type.substring(0, 21) + "...";
                log.info("ERROR: The type \"" + type + "\" is violated by:");
                log.info("    \"" + example + "\"");
View Full Code Here

        try {
            URI uri = new URI(url.toString());
            if (uri_cache.containsKey(uri)) {
                return uri_cache.get(uri);
            }
            Automaton a = Automaton.load(url);
            uri_cache.put(uri, a);
            return a;
        } catch (Exception e) {
            throw new InvalidRuntimeUseException("Invalid automaton URL: " + url);
        }
View Full Code Here

 
  private void handleAnnotationHotspots() {
    for (ValueBox box : analyzer.getHotspots()) {
      //Stmt stmt = analyzer.getStmt(box);
      Stmt stmt = tagger.getStmt(box);
      Automaton a = analyzer.getAutomaton(box);
      Automaton b = sa.getAutomaton(box);
      Automaton diff = a.complement().intersection(b);
      if (!diff.isEmpty()) {
        String from;
        if (b.isTotal()) {
          from = "anystring";
        }
        else {
          from = quoteString(diff.getShortestExample(true));
        }
        if (stmt.containsInvokeExpr()) {
          InvokeExpr invoke = stmt.getInvokeExpr();
          for (int i=0; i<invoke.getArgCount(); i++) {
            if (box == invoke.getArgBox(i)) {
View Full Code Here

      else {
        System.err.println("unrecognized runtime method!");
        System.exit(1);
      }
      System.err.println("Checking "+kind+" at line "+line+" in "+sf+"...");
      Automaton a = sa.getAutomaton(e);
      Automaton expected_neg = rh.expected.complement();
      if (rh.kind==HotspotKind.ANALYZE) {
        Automaton diff = a.intersection(expected_neg);
        if (diff.isEmpty())
          if (a.equals(rh.expected))
            System.err.println("Exact match!");
          else
            System.err.println("Always satified!");
        else {
          System.err.println("Dissatisfied by:");
          System.err.println(quoteString(diff.getShortestExample(true)));
          tagger.tag(e, "Dissatisfied by: " + quoteString(diff.getShortestExample(true)));
        }
      } else if (rh.kind==HotspotKind.CHECK) {
        if (a.intersection(expected_neg).isEmpty())
          System.err.println("Always satified!");
        else if (a.intersection(rh.expected).isEmpty()) {
View Full Code Here

      //Find fields containing the @Type annotation and add to map
      Collection<SootField> fields = sootClass.getFields();
      for (SootField field : fields) {
        if (field.hasTag("VisibilityAnnotationTag")) {
          VisibilityAnnotationTag vat = (VisibilityAnnotationTag)field.getTag("VisibilityAnnotationTag");
          Automaton automaton = getAutomatonFromTag(vat);
          if (automaton != null) {
            fieldAutomatonMap.put(field, automaton);
          }
        }
        //Remove all tags from field. JSA tags will be added later
        field.removeAllTags();
      }
     
      //Find methods containing @Type or @LoadType annotation and add to map
      Collection<SootMethod> methods = sootClass.getMethods();
      for (SootMethod m : methods) {
        //Find return annotation
        if (isStringType(m.getReturnType())) {
          VisibilityAnnotationTag vat = (VisibilityAnnotationTag)m.getTag("VisibilityAnnotationTag");
          if (vat != null) {
            Automaton automaton = getAutomatonFromTag(vat);
            if (automaton != null) {
                returnAutomatonMap.put(m, automaton);
            }
          }
        }
       
        //Find parameter annotations
        int count = m.getParameterCount();
        for (int i = 0; i<count; i++) {
          if (isStringType(m.getParameterType(i))) {
            VisibilityParameterAnnotationTag vpat = (VisibilityParameterAnnotationTag)m.getTag("VisibilityParameterAnnotationTag");
            if (vpat != null) {
              VisibilityAnnotationTag vat = vpat.getVisibilityAnnotations().get(i);
              Automaton automaton = getAutomatonFromTag(vat);
              if (automaton != null) {
                Map<Integer,Automaton> pMap;
                if (parameterAutomatonMap.containsKey(m)) {
                  pMap = parameterAutomatonMap.get(m);
                }
                else {
                  pMap = new HashMap<Integer,Automaton>();
                  parameterAutomatonMap.put(m, pMap);
                }
                pMap.put(i, automaton);
              }
            }
          }
        }
        //Remove all tags from method. JSA tags will be added later
        m.removeAllTags();
      }
    }
   
    // apply inheritance relations to construct the 'full' maps
    for (SootClass sootClass : classes) {
        for (SootMethod m1 : sootClass.getMethods()) {
            Automaton m1Returns = returnAutomatonMap.get(m1);
            Map<Integer, Automaton> m1Parameters = parameterAutomatonMap.get(m1);
            //if (m1Returns == null && m1Parameters == null)
            //    continue;
            if (m1Parameters == null)
              m1Parameters = Collections.emptyMap();
            for (SootMethod m2 : (List<SootMethod>)h.resolveAbstractDispatch(sootClass, m1)) {
                // HANDLE RETURN TYPES
                if (m1Returns != null) {
                    inheritReturnType(m1, m1Returns, m2);
                }
               
                // HANDLE PARAMETER TYPES
                //if (m1Parameters != null) {
                      if (!parameterAutomatonMapFull.containsKey(m2)) {
                          parameterAutomatonMapFull.put(m2, new HashMap<Integer,Automaton>());
                      }
                    for (int i=0; i<m1.getParameterCount(); i++) {
                        Automaton m1Parameter = m1Parameters.get(i);
                        if (m1Parameter == null) {
                          // ensure that the child's parameter has no annotation
                          Map<Integer,Automaton> m2Parameters = parameterAutomatonMap.get(m2);
                          if (m2Parameters != null && m2Parameters.containsKey(i)) {
                            errorSuperParameterNotAnnotated(m2, m1, i);
View Full Code Here

    }
  }

    private void inheritParameterType(SootMethod m1, SootMethod m2, int paramIndex, Automaton m1Parameter) {
        Map<Integer,Automaton> m2Parameters = parameterAutomatonMap.get(m2);
        Automaton m2Parameter = (m2Parameters == null) ? null : m2Parameters.get(paramIndex);
       
        if (m2Parameter == null) {
            Automaton m2ParameterFull = parameterAutomatonMapFull.get(m2).get(paramIndex);
            if (m2ParameterFull == null) {
                // if super method's parameter is not annotated, then any string must be accepted
                // by the child method
                parameterAutomatonMapFull.get(m2).put(paramIndex, Automaton.makeAnyString());
            } else {
View Full Code Here

public class TextProcessor {
  XMLGraph graph;
 
  final public Automaton apply(XMLGraph g, Node node) {
    graph = g;
    Automaton result = node.process(proc);
    return result;
  }
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.