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


  49  *
  50  * <pre>
  51  *
  52  *
  53  *   InstructionFinder f   = new InstructionFinder(il);
  54  *   String            pat = &quot;IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)&quot;;
  55  *
  56  *   for (Iterator i = f.search(pat, constraint); i.hasNext(); ) {
  57  *   InstructionHandle[] match = (InstructionHandle[])i.next();
  58  *   ...
  59  *   il.delete(match[1], match[5]);
  60  *   ...
  61  *   }
  62  *
  63  *
  64  * </pre>
  65  *
  66  * @version $Id: InstructionFinder.java 1749603 2016-06-21 20:50:19Z ggregory $
  67  * @see com.sun.org.apache.bcel.internal.generic.Instruction
  68  * @see InstructionList

  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, 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 


  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: InstructionFinder.java 1749603 2016-06-21 20:50:19Z ggregory $
  66  * @see com.sun.org.apache.bcel.internal.generic.Instruction
  67  * @see InstructionList
  68  * @LastModified: Oct 2017
  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     }


< prev index next >