Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a56ea3f517d25548f35d9d6c64205924cc6e99e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2004, 2018 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tools.internal;

import java.lang.reflect.*;

public class SizeofGenerator extends JNIGenerator {


@Override
public void generate(JNIClass clazz) {
	String className = clazz.getSimpleName();
	output("\tprintf(\"");
	output(className);
	output("=%d\\n\", sizeof(");
	output(className);
	outputln("));");
//	Field[] fields = clazz.getDeclaredFields();
//	generate(fields);	
}
	
@Override
public void generate() {
	outputln("int main() {");
	super.generate();
	outputln("}");
}

public void generate(JNIField[] fields) {
	sort(fields);	
	for (JNIField field : fields) {
		if ((field.getModifiers() & Modifier.FINAL) == 0) continue;
		generate(field);
	}
}

public void generate(JNIField field) {
	output("\tprintf(\"");
	output(field.getName());
	output("=%d\\n\", sizeof(");
	output(field.getName());
	outputln("));");
}

public static void main(String[] args) {
	if (args.length < 1) {
		System.out.println("Usage: java SizeofGenerator <className1> <className2>");
		return;
	}
	try {
		SizeofGenerator gen = new SizeofGenerator();
		for (String clazzName : args) {
			Class<?> clazz = Class.forName(clazzName);
			gen.generate(new ReflectClass(clazz));
		}
	} catch (Exception e) {
		System.out.println("Problem");
		e.printStackTrace(System.out);
	}
}

}

Back to the top