Package gov.nasa.jpf.conformanceChecker.checkers

Source Code of gov.nasa.jpf.conformanceChecker.checkers.NativePeerChecker

//
// Copyright (C) 2012 United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration
// (NASA).  All Rights Reserved.
//
// This software is distributed under the NASA Open Source Agreement
// (NOSA), version 1.3.  The NOSA has been approved by the Open Source
// Initiative.  See the file NOSA-1.3-JPF at the top of the distribution
// directory tree for the complete NOSA document.
//
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
//
package gov.nasa.jpf.conformanceChecker.checkers;

import gov.nasa.jpf.conformanceChecker.comparators.MethodInfoComparator;
import gov.nasa.jpf.conformanceChecker.reporters.Reporter;
import gov.nasa.jpf.jvm.ClassInfo;
import gov.nasa.jpf.jvm.MethodInfo;

import java.util.Arrays;
import java.util.List;

/**
* This abstract class provides common methods for checkers that deal with
* native peers.
*
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public abstract class NativePeerChecker extends Checker {

  public NativePeerChecker(List<Reporter> reporters, MemberLevel level) {
    super(reporters, level);
  }

  public NativePeerChecker(List<Reporter> reporters) {
    super(reporters);
  }
 
  public NativePeerChecker() {
    super();
  }

  /**
   * Gets an array of {@link MethodInfo} objects representing the
   * peer methods of the given native peer class.
   *
   * @see NativePeerChecker#getPeerMethods(ClassInfo)
   */
  protected MethodInfo[] getSortedPeerMethods(ClassInfo peer) {
    MethodInfoComparator comparator = new MethodInfoComparator();
    MethodInfo[] peerMethods = getPeerMethods(peer);
    Arrays.sort(peerMethods, comparator);
    return peerMethods;
  }
 
  /**
   * Gets the peer methods of the given native peer class. Peer methods
   * are the ones that intercept native calls
   */
  protected MethodInfo[] getPeerMethods(ClassInfo peer) {
    // The model class has no peer. Returning a zero size array
    // enables us to detect orphan native peers anyway
    if (peer == null) {
      return new MethodInfo[0];
    }
    MethodInfo[] allPeerMethods = peer.getDeclaredMethodInfos();
    MethodInfo[] peerMethods = new MethodInfo[allPeerMethods.length];
    int j = 0;
    for (int i = 0; i<allPeerMethods.length ; i++) {
      if(isNativePeerMethod(allPeerMethods[i])) {
        peerMethods[j] = allPeerMethods[i];
        j++;
      }
    }
    peerMethods = Arrays.copyOf(peerMethods, j);
    return peerMethods;
  }
 
  /**
   * Returns true if the given method looks like a native peer method,
   * i.e. like a method executed in place of a native one.
   */
  protected static boolean isNativePeerMethod(MethodInfo mth) {
    return mth.getName().indexOf('_') >= 0;
  }
 
}
TOP

Related Classes of gov.nasa.jpf.conformanceChecker.checkers.NativePeerChecker

TOP
Copyright © 2018 www.massapi.com. 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.