001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.ir.operand;
014    
015    import org.jikesrvm.classloader.TypeReference;
016    
017    /**
018     * This operand represents the null constant.
019     *
020     * @see Operand
021     */
022    public final class NullConstantOperand extends ConstantOperand {
023    
024      /**
025       * Return a new operand that is semantically equivalent to <code>this</code>.
026       *
027       * @return a copy of <code>this</code>
028       */
029      public Operand copy() {
030        return new NullConstantOperand();
031      }
032    
033      /**
034       * Return the {@link TypeReference} of the value represented by the operand.
035       *
036       * @return TypeReference.NULL_TYPE
037       */
038      public TypeReference getType() {
039        return TypeReference.NULL_TYPE;
040      }
041    
042      /**
043       * Does the operand represent a value of the reference data type?
044       *
045       * @return <code>true</code>
046       */
047      public boolean isRef() {
048        return true;
049      }
050    
051      /**
052       * Does the operand definitely represent <code>null</code>?
053       *
054       * @return <code>true</code>
055       */
056      public boolean isDefinitelyNull() {
057        return true;
058      }
059    
060      /**
061       * Are two operands semantically equivalent?
062       *
063       * @param op other operand
064       * @return   <code>true</code> if <code>this</code> and <code>op</code>
065       *           are semantically equivalent or <code>false</code>
066       *           if they are not.
067       */
068      public boolean similar(Operand op) {
069        return op instanceof NullConstantOperand;
070      }
071    
072      /**
073       * Returns the string representation of this operand.
074       *
075       * @return a string representation of this operand.
076       */
077      public String toString() {
078        return "<null>";
079      }
080    }