< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/InstructionFinder.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.bcel.internal.util;
  22 


  45  * package to search for regular expressions.
  46  *
  47  * A typical application would look like this:
  48  *
  49  * <pre>
  50  *
  51  *
  52  *   InstructionFinder f   = new InstructionFinder(il);
  53  *   String            pat = &quot;IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)&quot;;
  54  *
  55  *   for (Iterator i = f.search(pat, constraint); i.hasNext(); ) {
  56  *   InstructionHandle[] match = (InstructionHandle[])i.next();
  57  *   ...
  58  *   il.delete(match[1], match[5]);
  59  *   ...
  60  *   }
  61  *
  62  *
  63  * </pre>
  64  *
  65  * @version $Id$
  66  * @see com.sun.org.apache.bcel.internal.generic.Instruction
  67  * @see InstructionList
  68  * @LastModified: Jun 2019
  69  */
  70 public class InstructionFinder {
  71 
  72     private static final int OFFSET = 32767; // char + OFFSET is outside of LATIN-1
  73     private static final int NO_OPCODES = 256; // Potential number, some are not used
  74     private static final Map<String, String> map = new HashMap<>();
  75     private final InstructionList il;
  76     private String il_string; // instruction list as string
  77     private InstructionHandle[] handles; // map instruction
  78 
  79 
  80     // list to array
  81     /**
  82      * @param il
  83      *          instruction list to search for given patterns
  84      */
  85     public InstructionFinder(final InstructionList il) {
  86         this.il = il;
  87         reread();
  88     }


   1 /*
   2  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.bcel.internal.util;
  22 


  45  * package to search for regular expressions.
  46  *
  47  * A typical application would look like this:
  48  *
  49  * <pre>
  50  *
  51  *
  52  *   InstructionFinder f   = new InstructionFinder(il);
  53  *   String            pat = &quot;IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)&quot;;
  54  *
  55  *   for (Iterator i = f.search(pat, constraint); i.hasNext(); ) {
  56  *   InstructionHandle[] match = (InstructionHandle[])i.next();
  57  *   ...
  58  *   il.delete(match[1], match[5]);
  59  *   ...
  60  *   }
  61  *
  62  *
  63  * </pre>
  64  *

  65  * @see com.sun.org.apache.bcel.internal.generic.Instruction
  66  * @see InstructionList
  67  * @LastModified: Jan 2020
  68  */
  69 public class InstructionFinder {
  70 
  71     private static final int OFFSET = 32767; // char + OFFSET is outside of LATIN-1
  72     private static final int NO_OPCODES = 256; // Potential number, some are not used
  73     private static final Map<String, String> map = new HashMap<>();
  74     private final InstructionList il;
  75     private String il_string; // instruction list as string
  76     private InstructionHandle[] handles; // map instruction
  77 
  78 
  79     // list to array
  80     /**
  81      * @param il
  82      *          instruction list to search for given patterns
  83      */
  84     public InstructionFinder(final InstructionList il) {
  85         this.il = il;
  86         reread();
  87     }


< prev index next >