ByteRenderer.java revision 00fc68adf2e39aeb9fed35293f2576bbe729ec4b
19bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com/*
29bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * [The "BSD licence"]
300fc68adf2e39aeb9fed35293f2576bbe729ec4bJesusFreke@JesusFreke.com * Copyright (c) 2010 Ben Gruver (JesusFreke)
49bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * All rights reserved.
59bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com *
69bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * Redistribution and use in source and binary forms, with or without
79bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * modification, are permitted provided that the following conditions
89bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * are met:
99bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 1. Redistributions of source code must retain the above copyright
109bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com *    notice, this list of conditions and the following disclaimer.
119bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 2. Redistributions in binary form must reproduce the above copyright
129bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com *    notice, this list of conditions and the following disclaimer in the
139bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com *    documentation and/or other materials provided with the distribution.
149bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 3. The name of the author may not be used to endorse or promote products
159bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com *    derived from this software without specific prior written permission.
169bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com *
179bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
189bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
209bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
219bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
229bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
269bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com */
289bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com
296ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.compackage org.jf.baksmali.Renderers;
309bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com
316ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.comimport org.antlr.stringtemplate.AttributeRenderer;
329bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com
336ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.compublic class ByteRenderer implements AttributeRenderer {
346ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com    public String toString(Object o) {
356ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        Byte b = (Byte)o;
366ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        if (b < 0) {
376ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com            return "-0x" + Integer.toHexString(-1 * b) + "t";
386ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        }
396ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        return "0x" + Integer.toHexString(b) + "t";
409bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com    }
419bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com
426ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com    public String toString(Object o, String s) {
436ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        if (s.equals("unsigned")) {
446ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com            Byte b = (Byte)o;
455867263eb588f4671400895d1e6b01c01535061bJesusFreke@JesusFreke.com            return "0x" + Integer.toHexString(b & 0xFF) + "t";
466ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        }
476ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.com        return toString(o);
489bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com    }
499bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com}
50