Regenerate FunctionN and ExtensionFunctionN classes
GenerateFunctions now also generates Java classes in runtime/src/jet/ directory, and they have the matching declarations to those in compiler/src/jet/ Delete ExtensionFunctionN's protected constructor, as it wasn't needed Delete toString(), a more useful version will be implemented soon
This commit is contained in:
@@ -16,8 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.generators.runtime;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
import org.jetbrains.jet.utils.Printer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class GenerateFunctions {
|
||||
@@ -38,7 +43,7 @@ public class GenerateFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateFunctions(PrintStream out, int count, FunctionKind kind) {
|
||||
private static void generateBuiltInFunctions(PrintStream out, int count, FunctionKind kind) {
|
||||
generated(out);
|
||||
for (int i = 0; i <= count; i++) {
|
||||
out.print("public abstract class " + kind.classNamePrefix + i);
|
||||
@@ -64,6 +69,51 @@ public class GenerateFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateRuntimeFunction(PrintStream out, int i, FunctionKind kind) {
|
||||
generateRuntimeClassHeader(out);
|
||||
|
||||
out.print("public abstract class " + kind.classNamePrefix + i);
|
||||
out.print("<");
|
||||
if (kind.hasReceiverParameter) {
|
||||
out.print("T, ");
|
||||
}
|
||||
for (int j = 1; j <= i; j++) {
|
||||
out.print("P" + j + ", ");
|
||||
}
|
||||
out.print("R> extends DefaultJetObject {");
|
||||
out.println();
|
||||
out.print(" public abstract R invoke(");
|
||||
if (kind.hasReceiverParameter) {
|
||||
out.print("T receiver");
|
||||
if (i > 0) {
|
||||
out.print(", ");
|
||||
}
|
||||
}
|
||||
for (int j = 1; j <= i; j++) {
|
||||
out.print("P" + j + " p" + j);
|
||||
if (j < i) {
|
||||
out.print(", ");
|
||||
}
|
||||
}
|
||||
out.print(");");
|
||||
out.println();
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
private static void generateRuntimeClassHeader(PrintStream out) {
|
||||
try {
|
||||
out.println(FileUtil.loadFile(new File("injector-generator/copyright.txt")));
|
||||
}
|
||||
catch (IOException e) {
|
||||
ExceptionUtils.rethrow(e);
|
||||
}
|
||||
out.println("package jet;");
|
||||
out.println();
|
||||
out.println("import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;");
|
||||
out.println();
|
||||
out.println("@AssertInvisibleInResolver");
|
||||
}
|
||||
|
||||
private static void generated(PrintStream out) {
|
||||
out.println("// Generated by " + GenerateFunctions.class.getName());
|
||||
out.println();
|
||||
@@ -71,17 +121,35 @@ public class GenerateFunctions {
|
||||
out.println();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
private static void generateBuiltInClasses() throws FileNotFoundException {
|
||||
File baseDir = new File("compiler/frontend/src/jet/");
|
||||
assert baseDir.exists() : "Base dir does not exist: " + baseDir.getAbsolutePath();
|
||||
|
||||
for (FunctionKind kind : FunctionKind.values()) {
|
||||
PrintStream functions = new PrintStream(new File(baseDir, kind.fileName));
|
||||
generateFunctions(functions, MAX_PARAM_COUNT, kind);
|
||||
generateBuiltInFunctions(functions, MAX_PARAM_COUNT, kind);
|
||||
functions.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateRuntimeClasses() throws FileNotFoundException {
|
||||
File baseDir = new File("runtime/src/jet/");
|
||||
assert baseDir.exists() : "Base dir does not exist: " + baseDir.getAbsolutePath();
|
||||
|
||||
for (FunctionKind kind : FunctionKind.values()) {
|
||||
for (int i = 0; i <= MAX_PARAM_COUNT; i++) {
|
||||
PrintStream function = new PrintStream(new File(baseDir, kind.classNamePrefix + i + ".java"));
|
||||
generateRuntimeFunction(function, i, kind);
|
||||
function.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
generateBuiltInClasses();
|
||||
generateRuntimeClasses();
|
||||
}
|
||||
|
||||
private GenerateFunctions() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user