Java源码示例:com.apple.internal.jobjc.generator.model.Framework
示例1
protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Framework fw : fws){
for(final Width width : Width.values()){
System.out.println("SOR -- Getting Struct offsets @" + width + " for " + fw.name);
String nativeSrc = generateFileForFramework(fw, width);
String executable = compileObjC(nativeSrc, width);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, width);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
}
示例2
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例3
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例4
@Override public void writeBeginning(final PrintStream out) {
out.print(new JLField("private static", JOBJC_CLASSNAME, "instance"));
out.print(new JLField("private final", JObjCRuntime.class.getName(), "runtime"));
JLMethod getInstR = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance", "final JObjCRuntime runtime");
getInstR.body.add("if(runtime == null) throw new NullPointerException(\"runtime\");");
getInstR.body.add("if(instance == null) instance = new JObjC(runtime);");
getInstR.body.add("return instance;");
out.print(getInstR);
JLMethod getInst = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance");
getInst.body.add("return getInstance(JObjCRuntime.getInstance());");
out.print(getInst);
JLCtor ctor = new JLCtor("private", JOBJC_CLASSNAME, "final JObjCRuntime runtime");
ctor.body.add("this.runtime = runtime;");
for (final Framework f : frameworks)
ctor.body.add("runtime.registerPackage(\"" + f.pkg + "\");");
out.print(ctor);
}
示例5
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例6
protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Framework fw : fws){
for(final Width width : Width.values()){
System.out.println("SOR -- Getting Struct offsets @" + width + " for " + fw.name);
String nativeSrc = generateFileForFramework(fw, width);
String executable = compileObjC(nativeSrc, width);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, width);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
}
示例7
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例8
protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Framework fw : fws){
for(final Width width : Width.values()){
System.out.println("SOR -- Getting Struct offsets @" + width + " for " + fw.name);
String nativeSrc = generateFileForFramework(fw, width);
String executable = compileObjC(nativeSrc, width);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, width);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
}
示例9
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例10
protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Framework fw : fws){
for(final Width width : Width.values()){
System.out.println("SOR -- Getting Struct offsets @" + width + " for " + fw.name);
String nativeSrc = generateFileForFramework(fw, width);
String executable = compileObjC(nativeSrc, width);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, width);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
}
示例11
protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Framework fw : fws){
for(final Width width : Width.values()){
System.out.println("SOR -- Getting Struct offsets @" + width + " for " + fw.name);
String nativeSrc = generateFileForFramework(fw, width);
String executable = compileObjC(nativeSrc, width);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, width);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
}
示例12
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例13
@Override protected void _resolve(final Collection<Framework> fws) throws Exception{
for(final Width arch : Width.values()){
System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
String nativeSrc = generateFileForFrameworks(fws, arch);
String executable = compileObjC(nativeSrc, arch);
execute(executable, new Map1<String,Object>(){
public Object apply(String ln) {
try {
processLine(ln, fws, arch);
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}
示例14
public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
generatedClassFiles.add(new RootJObjCClass(frameworks));
for (final Framework f : frameworks) {
f.generateClasses(generatedClassFiles);
}
return generatedClassFiles;
}
示例15
protected Framework findFrameworkByName(Collection<Framework> fws, String name){
if(cachedFw != null && cachedFw.name.equals(name))
return cachedFw;
cachedFw = null;
for(Framework fw : fws)
if(fw.name.equals(name)){
cachedFw = fw;
break;
}
return cachedFw;
}
示例16
protected void processLine(String ln, Collection<Framework> fws, Width arch) throws Exception{
System.out.println("\tSOR '" + ln + "'");
if(ln.trim().length() == 0) return;
Pattern stinfo = Pattern.compile("^(.*) (.*):(\\d+).*$");
Matcher m = stinfo.matcher(ln);
if(!m.matches()) throw new RuntimeException("Failed to parse line from exec: " + ln);
String fwname = m.group(1);
String stname = m.group(2);
int stsize = Integer.parseInt(m.group(3));
Framework fw = findFrameworkByName(fws, fwname);
Struct st = fw.getStructByName(stname);
NStruct nst = wget(arch, st.type.type32, st.type.type64);
nst.sizeof.put(arch, stsize);
// System.out.println(st.name + " : " + stsize);
Pattern finfo = Pattern.compile(" (-?\\d+)");
Matcher fm = finfo.matcher(ln);
int fi = 0;
while(fm.find()){
NField sf = nst.fields.get(fi++);
sf.offset.put(arch, Integer.parseInt(fm.group(1)));
// System.out.println("\t" + sf.name + " : " + off);
}
TypeCache.inst().pingType(st.type);
}
示例17
public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
generatedClassFiles.add(new RootJObjCClass(frameworks));
for (final Framework f : frameworks) {
f.generateClasses(generatedClassFiles);
}
return generatedClassFiles;
}
示例18
static void printStructInfos(Framework fw, Width arch, PrintWriter out){
for(Struct st : fw.structs){
NStruct nst = wget(arch, st.type.type32, st.type.type64);
out.println("std::cout << \"" + fw.name + " " + st.name + "\" << ':' << sizeof("+st.name+")");
for(NField sf : nst.fields){
out.print("\t<< ' ' << ");
out.println(sf.type instanceof NType.NBitfield
? "-1"
: "offsetof("+st.name+","+sf.name+")");
}
out.println("\t<< std::endl;");
}
}
示例19
public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
generatedClassFiles.add(new RootJObjCClass(frameworks));
for (final Framework f : frameworks) {
f.generateClasses(generatedClassFiles);
}
return generatedClassFiles;
}
示例20
/**
* Generates Objective-C file and returns absolute path name.
*/
private String generateFileForFramework(Framework fw, Width arch) throws Exception{
File tempfile = File.createTempFile("JObjC-SOR-" + fw.name + "-" + arch + "-", ".mm");
PrintWriter out = new PrintWriter(new FileWriter(tempfile));
out.println("#include<iostream>");
printHeaderLines(fw, arch, out);
out.println("");
out.println("int main(int argc, char** argv){");
printStructInfos(fw, arch, out);
out.println("\treturn 0;");
out.println("}");
out.close();
return tempfile.getAbsolutePath();
}
示例21
protected Framework findFrameworkByName(Collection<Framework> fws, String name){
if(cachedFw != null && cachedFw.name.equals(name))
return cachedFw;
cachedFw = null;
for(Framework fw : fws)
if(fw.name.equals(name)){
cachedFw = fw;
break;
}
return cachedFw;
}
示例22
protected void processLine(String ln, Collection<Framework> fws, Width arch) throws Exception{
System.out.println("\tSOR '" + ln + "'");
if(ln.trim().length() == 0) return;
Pattern stinfo = Pattern.compile("^(.*) (.*):(\\d+).*$");
Matcher m = stinfo.matcher(ln);
if(!m.matches()) throw new RuntimeException("Failed to parse line from exec: " + ln);
String fwname = m.group(1);
String stname = m.group(2);
int stsize = Integer.parseInt(m.group(3));
Framework fw = findFrameworkByName(fws, fwname);
Struct st = fw.getStructByName(stname);
NStruct nst = wget(arch, st.type.type32, st.type.type64);
nst.sizeof.put(arch, stsize);
// System.out.println(st.name + " : " + stsize);
Pattern finfo = Pattern.compile(" (-?\\d+)");
Matcher fm = finfo.matcher(ln);
int fi = 0;
while(fm.find()){
NField sf = nst.fields.get(fi++);
sf.offset.put(arch, Integer.parseInt(fm.group(1)));
// System.out.println("\t" + sf.name + " : " + off);
}
TypeCache.inst().pingType(st.type);
}
示例23
/**
* Generates Objective-C file and returns absolute path name.
*/
private String generateFileForFramework(Framework fw, Width arch) throws Exception{
File tempfile = File.createTempFile("JObjC-SOR-" + fw.name + "-" + arch + "-", ".mm");
PrintWriter out = new PrintWriter(new FileWriter(tempfile));
out.println("#include<iostream>");
printHeaderLines(fw, arch, out);
out.println("");
out.println("int main(int argc, char** argv){");
printStructInfos(fw, arch, out);
out.println("\treturn 0;");
out.println("}");
out.close();
return tempfile.getAbsolutePath();
}
示例24
static void printStructInfos(Framework fw, Width arch, PrintWriter out){
for(Struct st : fw.structs){
NStruct nst = wget(arch, st.type.type32, st.type.type64);
out.println("std::cout << \"" + fw.name + " " + st.name + "\" << ':' << sizeof("+st.name+")");
for(NField sf : nst.fields){
out.print("\t<< ' ' << ");
out.println(sf.type instanceof NType.NBitfield
? "-1"
: "offsetof("+st.name+","+sf.name+")");
}
out.println("\t<< std::endl;");
}
}
示例25
public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
generatedClassFiles.add(new RootJObjCClass(frameworks));
for (final Framework f : frameworks) {
f.generateClasses(generatedClassFiles);
}
return generatedClassFiles;
}
示例26
protected Framework findFrameworkByName(Collection<Framework> fws, String name){
if(cachedFw != null && cachedFw.name.equals(name))
return cachedFw;
cachedFw = null;
for(Framework fw : fws)
if(fw.name.equals(name)){
cachedFw = fw;
break;
}
return cachedFw;
}
示例27
public void resolve(Collection<Framework> fws){
try {
_resolve(fws);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例28
public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
generatedClassFiles.add(new RootJObjCClass(frameworks));
for (final Framework f : frameworks) {
f.generateClasses(generatedClassFiles);
}
return generatedClassFiles;
}
示例29
protected void processLine(String ln, Collection<Framework> fws, Width arch) throws Exception{
System.out.println("\tSOR '" + ln + "'");
if(ln.trim().length() == 0) return;
Pattern stinfo = Pattern.compile("^(.*) (.*):(\\d+).*$");
Matcher m = stinfo.matcher(ln);
if(!m.matches()) throw new RuntimeException("Failed to parse line from exec: " + ln);
String fwname = m.group(1);
String stname = m.group(2);
int stsize = Integer.parseInt(m.group(3));
Framework fw = findFrameworkByName(fws, fwname);
Struct st = fw.getStructByName(stname);
NStruct nst = wget(arch, st.type.type32, st.type.type64);
nst.sizeof.put(arch, stsize);
// System.out.println(st.name + " : " + stsize);
Pattern finfo = Pattern.compile(" (-?\\d+)");
Matcher fm = finfo.matcher(ln);
int fi = 0;
while(fm.find()){
NField sf = nst.fields.get(fi++);
sf.offset.put(arch, Integer.parseInt(fm.group(1)));
// System.out.println("\t" + sf.name + " : " + off);
}
TypeCache.inst().pingType(st.type);
}
示例30
public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
generatedClassFiles.add(new RootJObjCClass(frameworks));
for (final Framework f : frameworks) {
f.generateClasses(generatedClassFiles);
}
return generatedClassFiles;
}