// Copyright 2016 The Bazel Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.testing.coverage; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; import org.jacoco.core.internal.flow.IFrame; import org.jacoco.core.internal.flow.Instruction; import org.jacoco.core.internal.flow.LabelInfo; import org.jacoco.core.internal.flow.MethodProbesVisitor; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; /** * The mapper is a probes visitor that will cache control flow information as well as keeping track * of the probes as the main driver generates the probe ids. Upon finishing the method it uses the * information collected to generate the mapping information between probes and the instructions. */ public class MethodProbesMapper extends MethodProbesVisitor { /* * The implementation roughly follows the same pattern of the Analyzer class of Jacoco. * * The mapper has a few states: * * - lineMappings: a mapping between line number and labels * * - a sequence of "instructions", where each instruction has one or more predecessors. The * predecessor field has a sole purpose of propagating probe id. The 'merge' nodes in the CFG has * no predecessors, since the branch stops at theses points. * * - The instructions each has states that keep track of the probes that are associated with the * instruction. * * Initially the probe ids are assigned to the instructions that immediately precede the probe. At * the end of visiting the methods, the probe ids are propagated through the predecessor chains. */ // States // // These are state variables that needs to be updated in the visitor methods. // The values usually changes as we traverse the byte code. private Instruction lastInstruction = null; private int currentLine = -1; private List