1 11 package org.eclipse.swt.tools.internal; 12 13 import java.lang.reflect.*; 14 15 public class SizeofGenerator extends JNIGenerator { 16 17 18 public void generate(Class clazz) { 19 String className = getClassName(clazz); 20 output("\tprintf(\""); 21 output(className); 22 output("=%d\\n\", sizeof("); 23 output(className); 24 outputln("));"); 25 } 28 29 public void generate() { 30 outputln("int main() {"); 31 super.generate(); 32 outputln("}"); 33 } 34 35 public void generate(Field[] fields) { 36 sort(fields); 37 for (int i = 0; i < fields.length; i++) { 38 Field field = fields[i]; 39 if ((field.getModifiers() & Modifier.FINAL) == 0) continue; 40 generate(field); 41 } 42 } 43 44 public void generate(Field field) { 45 output("\tprintf(\""); 46 output(field.getName()); 47 output("=%d\\n\", sizeof("); 48 output(field.getName()); 49 outputln("));"); 50 } 51 52 public static void main(String [] args) { 53 if (args.length < 1) { 54 System.out.println("Usage: java SizeofGenerator <className1> <className2>"); 55 return; 56 } 57 try { 58 SizeofGenerator gen = new SizeofGenerator(); 59 for (int i = 0; i < args.length; i++) { 60 String clazzName = args[i]; 61 Class clazz = Class.forName(clazzName); 62 gen.generate(clazz); 63 } 64 } catch (Exception e) { 65 System.out.println("Problem"); 66 e.printStackTrace(System.out); 67 } 68 } 69 70 } 71 | Popular Tags |