package runEnv; import runEnv.basicValue.*; public class PtrValue extends RunValue { /* Represents the address of a value */ private Multiple base; private int offset; public PtrValue( Multiple base, int offset ) { this.base = base; this.offset = offset; } public PtrValue( Multiple base ) { this( base, 0 ); } public PtrValue( String value ) { this( new Multiple( value ) ); } public RunValue getValue() { return base.getValue( offset ); } public void setValue( RunValue value ) { base.setValue( offset, value ); } public PtrValue elementAt( int index ) { return new PtrValue( base, offset + index ); } public PtrValue addressValue() { return this; } public String toString() { return base.name() + "(" + Integer.toHexString( base.size() ) + ")+" + Integer.toHexString( offset ); } public String stringValue() { String result = ""; for ( int i = 0; ; i++ ) { char c = base.getValue( offset + i ).charValue(); if ( c == 0 ) return result; result += c; } } public PtrValue setStringValue( String s ) { for ( int i = 0; i < s.length(); i++ ) { char c = s.charAt( i ); base.setValue( offset + i, new CharValue( c ) ); } base.setValue( offset + s.length(), new CharValue( '\0' ) ); return elementAt( s.length() ); } public boolean equals( RunValue otherValue ) { if ( ! ( otherValue instanceof PtrValue ) ) return false; PtrValue otherAddress = ( PtrValue ) otherValue; return base == otherAddress.base && offset == otherAddress.offset; } }