提交 4ac71488 authored 作者: Thomas Mueller's avatar Thomas Mueller

Java to C++ converter

上级 637b845a
...@@ -101,7 +101,8 @@ public class ClassObj { ...@@ -101,7 +101,8 @@ public class ClassObj {
list = new ArrayList<MethodObj>(); list = new ArrayList<MethodObj>();
methods.put(method.name, list); methods.put(method.name, list);
} else { } else {
method.name = method.name + "_" + (list.size() + 1); // for overloaded methods
// method.name = method.name + "_" + (list.size() + 1);
} }
list.add(method); list.add(method);
} }
...@@ -248,6 +249,11 @@ class MethodObj { ...@@ -248,6 +249,11 @@ class MethodObj {
* Whether this is a constructor. * Whether this is a constructor.
*/ */
boolean isConstructor; boolean isConstructor;
public String toString() {
return name;
}
} }
/** /**
...@@ -305,6 +311,10 @@ class FieldObj { ...@@ -305,6 +311,10 @@ class FieldObj {
*/ */
ClassObj declaredClass; ClassObj declaredClass;
public String toString() {
return name;
}
} }
/** /**
...@@ -338,12 +348,12 @@ class Type { ...@@ -338,12 +348,12 @@ class Type {
public String toString() { public String toString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append(JavaParser.toC(classObj.toString())); for (int i = 0; i < arrayLevel; i++) {
if (!classObj.isPrimitive) { buff.append("ptr<array< ");
buff.append("*");
} }
buff.append(classObj.toString());
for (int i = 0; i < arrayLevel; i++) { for (int i = 0; i < arrayLevel; i++) {
buff.append("*"); buff.append(" > >");
} }
return buff.toString(); return buff.toString();
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.java; package org.h2.java;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
/** /**
* An expression. * An expression.
...@@ -14,6 +15,7 @@ import java.util.ArrayList; ...@@ -14,6 +15,7 @@ import java.util.ArrayList;
public interface Expr { public interface Expr {
// toString // toString
Type getType(); Type getType();
Expr cast(Type type);
} }
/** /**
...@@ -52,7 +54,6 @@ class CallExpr implements Expr { ...@@ -52,7 +54,6 @@ class CallExpr implements Expr {
public String toString() { public String toString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
String methodName;
initMethod(); initMethod();
if (method.isIgnore) { if (method.isIgnore) {
if (args.size() == 0) { if (args.size() == 0) {
...@@ -64,23 +65,23 @@ class CallExpr implements Expr { ...@@ -64,23 +65,23 @@ class CallExpr implements Expr {
"Cannot ignore method with multiple arguments: " + method); "Cannot ignore method with multiple arguments: " + method);
} }
} else { } else {
if (method.isVirtual) { if (expr == null) {
methodName = "virtual_" + method.name + "[CLASS_ID("+expr.toString()+")]"; // static method
buff.append(JavaParser.toC(classObj.toString() + "." + method.name));
} else { } else {
methodName = JavaParser.toC(classObj.toString() + "." + method.name); buff.append(expr.toString()).append("->");
buff.append(method.name);
} }
buff.append(methodName).append("("); buff.append("(");
int i = 0; int i = 0;
if (expr != null) { Iterator<FieldObj> paramIt = method.parameters.values().iterator();
buff.append(expr.toString());
i++;
}
for (Expr a : args) { for (Expr a : args) {
if (i > 0) { if (i > 0) {
buff.append(", "); buff.append(", ");
} }
FieldObj f = paramIt.next();
i++; i++;
buff.append(a); buff.append(a.cast(f.type));
} }
buff.append(")"); buff.append(")");
} }
...@@ -92,6 +93,10 @@ class CallExpr implements Expr { ...@@ -92,6 +93,10 @@ class CallExpr implements Expr {
return method.returnType; return method.returnType;
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -104,19 +109,17 @@ class AssignExpr implements Expr { ...@@ -104,19 +109,17 @@ class AssignExpr implements Expr {
Expr right; Expr right;
public String toString() { public String toString() {
if (left.getType().isSimplePrimitive()) { return left + " " + op + " " + right.cast(left.getType());
return left + " " + op + " " + right;
}
if (right.toString().equals("null")) {
return "release(" + left + ")";
}
return left + " = set(" + left + ", " + right + ")";
} }
public Type getType() { public Type getType() {
return left.getType(); return left.getType();
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -135,6 +138,14 @@ class ConditionalExpr implements Expr { ...@@ -135,6 +138,14 @@ class ConditionalExpr implements Expr {
return ifTrue.getType(); return ifTrue.getType();
} }
public Expr cast(Type type) {
ConditionalExpr e2 = new ConditionalExpr();
e2.condition = condition;
e2.ifTrue = ifTrue.cast(type);
e2.ifFalse = ifFalse.cast(type);
return e2;
}
} }
/** /**
...@@ -153,6 +164,9 @@ class LiteralExpr implements Expr { ...@@ -153,6 +164,9 @@ class LiteralExpr implements Expr {
} }
public String toString() { public String toString() {
if ("null".equals(literal)) {
return JavaParser.toCType(type) + "()";
}
return literal; return literal;
} }
...@@ -164,6 +178,14 @@ class LiteralExpr implements Expr { ...@@ -164,6 +178,14 @@ class LiteralExpr implements Expr {
return type; return type;
} }
public Expr cast(Type type) {
if ("null".equals(literal)) {
// TODO should be immutable
this.type = type;
}
return this;
}
} }
/** /**
...@@ -193,13 +215,11 @@ class OpExpr implements Expr { ...@@ -193,13 +215,11 @@ class OpExpr implements Expr {
if (left.getType().isObject() || right.getType().isObject()) { if (left.getType().isObject() || right.getType().isObject()) {
// TODO convert primitive to to String, call toString // TODO convert primitive to to String, call toString
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append("java_lang_StringBuilder_toString("); buff.append("ptr<java_lang_StringBuilder>(new java_lang_StringBuilder(");
buff.append("java_lang_StringBuilder_append(");
buff.append("java_lang_StringBuilder_init_obj(");
buff.append(convertToString(left)); buff.append(convertToString(left));
buff.append("), "); buff.append("))->append(");
buff.append(convertToString(right)); buff.append(convertToString(right));
buff.append("))"); buff.append(")->toString()");
return buff.toString(); return buff.toString();
} }
} }
...@@ -209,7 +229,7 @@ class OpExpr implements Expr { ...@@ -209,7 +229,7 @@ class OpExpr implements Expr {
private String convertToString(Expr e) { private String convertToString(Expr e) {
Type t = e.getType(); Type t = e.getType();
if (t.arrayLevel > 0) { if (t.arrayLevel > 0) {
return e.toString() + ".toString()"; return e.toString() + "->toString()";
} }
if (t.classObj.isPrimitive) { if (t.classObj.isPrimitive) {
ClassObj wrapper = context.getWrapper(t.classObj); ClassObj wrapper = context.getWrapper(t.classObj);
...@@ -217,7 +237,12 @@ class OpExpr implements Expr { ...@@ -217,7 +237,12 @@ class OpExpr implements Expr {
} else if (e.getType().toString().equals("java_lang_String*")) { } else if (e.getType().toString().equals("java_lang_String*")) {
return e.toString(); return e.toString();
} }
return e.toString() + ".toString()"; return e.toString() + "->toString()";
}
private static boolean isComparison(String op) {
return op.equals("==") || op.equals(">") || op.equals("<") ||
op.equals(">=") || op.equals("<=") || op.equals("!=");
} }
public Type getType() { public Type getType() {
...@@ -227,6 +252,11 @@ class OpExpr implements Expr { ...@@ -227,6 +252,11 @@ class OpExpr implements Expr {
if (right == null) { if (right == null) {
return left.getType(); return left.getType();
} }
if (isComparison(op)) {
Type t = new Type();
t.classObj = JavaParser.getBuiltInClass("boolean");
return t;
}
if (op.equals("+")) { if (op.equals("+")) {
if (left.getType().isObject() || right.getType().isObject()) { if (left.getType().isObject() || right.getType().isObject()) {
Type t = new Type(); Type t = new Type();
...@@ -242,6 +272,10 @@ class OpExpr implements Expr { ...@@ -242,6 +272,10 @@ class OpExpr implements Expr {
return lt; return lt;
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -261,23 +295,14 @@ class NewExpr implements Expr { ...@@ -261,23 +295,14 @@ class NewExpr implements Expr {
public String toString() { public String toString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
if (arrayInitExpr.size() > 0) { if (arrayInitExpr.size() > 0) {
if (classObj.isPrimitive) { buff.append("ptr<array<" + classObj + "> >(new array<" + classObj + ">(1 ");
buff.append("NEW_ARRAY(sizeof(" + classObj + ")");
buff.append(", 1 ");
for (Expr e : arrayInitExpr) { for (Expr e : arrayInitExpr) {
buff.append("* ").append(e); buff.append("* ").append(e);
} }
buff.append(")"); buff.append("))");
} else {
buff.append("NEW_OBJ_ARRAY(1 ");
for (Expr e : arrayInitExpr) {
buff.append("* ").append(e);
}
buff.append(")");
}
} else { } else {
MethodObj m = classObj.getMethod("init_obj", args); buff.append("new " + JavaParser.toC(classObj.toString()));
buff.append(JavaParser.toC(classObj.toString() + "." + m.name)).append("("); buff.append("(");
int i = 0; int i = 0;
for (Expr a : args) { for (Expr a : args) {
if (i++ > 0) { if (i++ > 0) {
...@@ -297,6 +322,10 @@ class NewExpr implements Expr { ...@@ -297,6 +322,10 @@ class NewExpr implements Expr {
return t; return t;
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -386,6 +415,11 @@ class StringExpr implements Expr { ...@@ -386,6 +415,11 @@ class StringExpr implements Expr {
} }
return buff.toString(); return buff.toString();
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -405,24 +439,20 @@ class VariableExpr implements Expr { ...@@ -405,24 +439,20 @@ class VariableExpr implements Expr {
public String toString() { public String toString() {
init(); init();
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
if ("length".equals(name) && base.getType().arrayLevel > 0) {
buff.append("LENGTH(");
buff.append(base.toString());
buff.append(")");
} else {
if (base != null) { if (base != null) {
buff.append(base.toString()).append("->"); buff.append(base.toString()).append("->");
} }
if (field != null) { if (field != null) {
if (field.isStatic) { if (field.isStatic) {
buff.append(JavaParser.toC(field.declaredClass + "." + field.name)); buff.append(JavaParser.toC(field.declaredClass + "." + field.name));
} else { } else if (field.name != null) {
buff.append(field.name); buff.append(field.name);
} else if ("length".equals(name) && base.getType().arrayLevel > 0) {
buff.append("length()");
} }
} else { } else {
buff.append(JavaParser.toC(name)); buff.append(JavaParser.toC(name));
} }
}
return buff.toString(); return buff.toString();
} }
...@@ -450,6 +480,10 @@ class VariableExpr implements Expr { ...@@ -450,6 +480,10 @@ class VariableExpr implements Expr {
return field.type; return field.type;
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -473,6 +507,10 @@ class ArrayExpr implements Expr { ...@@ -473,6 +507,10 @@ class ArrayExpr implements Expr {
return expr.getType(); return expr.getType();
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -500,6 +538,10 @@ class ArrayInitExpr implements Expr { ...@@ -500,6 +538,10 @@ class ArrayInitExpr implements Expr {
return buff.toString(); return buff.toString();
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -518,6 +560,10 @@ class CastExpr implements Expr { ...@@ -518,6 +560,10 @@ class CastExpr implements Expr {
return "(" + type + ") " + expr; return "(" + type + ") " + expr;
} }
public Expr cast(Type type) {
return this;
}
} }
/** /**
...@@ -536,7 +582,11 @@ class ArrayAccessExpr implements Expr { ...@@ -536,7 +582,11 @@ class ArrayAccessExpr implements Expr {
} }
public String toString() { public String toString() {
return base + "[" + index + "]"; return base + "->at(" + index + ")";
}
public Expr cast(Type type) {
return this;
} }
} }
...@@ -38,7 +38,13 @@ class ReturnStatement extends StatementBase { ...@@ -38,7 +38,13 @@ class ReturnStatement extends StatementBase {
Expr expr; Expr expr;
public String toString() { public String toString() {
return "return " + (expr == null ? "" : expr) + ";"; if (expr == null) {
return "return;";
}
if (expr.getType().isSimplePrimitive()) {
return "return " + expr + ";";
}
return "return " + JavaParser.toCType(expr.getType()) + "(" + expr + ");";
} }
} }
...@@ -187,9 +193,9 @@ class ForStatement extends StatementBase { ...@@ -187,9 +193,9 @@ class ForStatement extends StatementBase {
Type it = iterable.getType(); Type it = iterable.getType();
if (it != null && it.arrayLevel > 0) { if (it != null && it.arrayLevel > 0) {
String idx = "i_" + iterableVariable; String idx = "i_" + iterableVariable;
buff.append("int " + idx + " = 0; " + idx + " < LENGTH(" + iterable + "); " + idx + "++"); buff.append("int " + idx + " = 0; " + idx + " < " + iterable + "->length(); " + idx + "++");
buff.append(") {\n"); buff.append(") {\n");
buff.append(JavaParser.indent(iterableType + " " + iterableVariable + " = " + iterable + "["+ idx +"];\n")); buff.append(JavaParser.indent(iterableType + " " + iterableVariable + " = " + iterable + "->at("+ idx +");\n"));
buff.append(block.toString()).append("}"); buff.append(block.toString()).append("}");
} else { } else {
// TODO iterate over a collection // TODO iterate over a collection
...@@ -247,7 +253,7 @@ class VarDecStatement extends StatementBase { ...@@ -247,7 +253,7 @@ class VarDecStatement extends StatementBase {
public String toString() { public String toString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append(type).append(' '); buff.append(JavaParser.toCType(type)).append(' ');
StringBuilder assign = new StringBuilder(); StringBuilder assign = new StringBuilder();
for (int i = 0; i < variables.size(); i++) { for (int i = 0; i < variables.size(); i++) {
if (i > 0) { if (i > 0) {
...@@ -260,7 +266,7 @@ class VarDecStatement extends StatementBase { ...@@ -260,7 +266,7 @@ class VarDecStatement extends StatementBase {
if (value.getType().isSimplePrimitive()) { if (value.getType().isSimplePrimitive()) {
buff.append(" = ").append(value); buff.append(" = ").append(value);
} else { } else {
assign.append(varName).append(" = reference(").append(value).append(");\n"); assign.append(varName).append(" = ").append(value).append(";\n");
} }
} }
} }
......
...@@ -26,7 +26,7 @@ public class Test extends TestBase { ...@@ -26,7 +26,7 @@ public class Test extends TestBase {
} }
public void test() throws IOException { public void test() throws IOException {
// gcc --std=c99 -o test test.cpp // g++ -o test test.cpp
// chmod +x test // chmod +x test
// ./test // ./test
...@@ -76,7 +76,7 @@ public class Test extends TestBase { ...@@ -76,7 +76,7 @@ public class Test extends TestBase {
parser.writeHeader(w); parser.writeHeader(w);
parser.writeSource(w); parser.writeSource(w);
w.flush(); w.flush();
w = new PrintWriter(new FileWriter("bin/test.c")); w = new PrintWriter(new FileWriter("bin/test.cpp"));
parser.writeHeader(w); parser.writeHeader(w);
parser.writeSource(w); parser.writeSource(w);
w.close(); w.close();
......
...@@ -14,7 +14,7 @@ public class TestApp { ...@@ -14,7 +14,7 @@ public class TestApp {
/* c: /* c:
int main(int argc, char** argv) { int main(int argc, char** argv) {
org_h2_java_TestApp_main(null); org_h2_java_TestApp_main(ptr<array<ptr<java_lang_String> > >());
} }
*/ */
...@@ -26,9 +26,7 @@ int main(int argc, char** argv) { ...@@ -26,9 +26,7 @@ int main(int argc, char** argv) {
*/ */
public static void main(String... args) { public static void main(String... args) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
String s = "Hello " + i; System.out.println("Hello " + i);
System.out.println(s);
s = null;
} }
} }
......
...@@ -17,8 +17,8 @@ public class PrintStream { ...@@ -17,8 +17,8 @@ public class PrintStream {
* @param s the string * @param s the string
*/ */
public void println(String s) { public void println(String s) {
// c: int x = LENGTH(s->chars); // c: int x = s->chars->length();
// c: printf("%.*S\n", x, s->chars); // c: printf("%.*S\n", x, s->chars->getData());
} }
} }
...@@ -22,9 +22,9 @@ public class Integer { ...@@ -22,9 +22,9 @@ public class Integer {
* @return the String * @return the String
*/ */
public static String toString(int x) { public static String toString(int x) {
// c: char ch[20]; // c: wchar_t ch[20];
// c: snprintf(ch, 20, "%d", x); // c: swprintf(ch, 20, L"%d", x);
// c: return string(ch); // c: return STRING(ch);
// c: return; // c: return;
if (x == MIN_VALUE) { if (x == MIN_VALUE) {
return String.wrap("-2147483648"); return String.wrap("-2147483648");
......
...@@ -11,14 +11,16 @@ package org.h2.java.lang; ...@@ -11,14 +11,16 @@ package org.h2.java.lang;
*/ */
public class Object { public class Object {
private static final int[] K = { 1 };
public int hashCode() { public int hashCode() {
return K[0]; return 0;
} }
public boolean equals(Object other) { public boolean equals(Object other) {
return this == other; return other == this;
}
public java.lang.String toString() {
return "?";
} }
} }
...@@ -30,126 +30,116 @@ import org.h2.java.Ignore; ...@@ -30,126 +30,116 @@ import org.h2.java.Ignore;
#define false 0 #define false 0
#define null 0 #define null 0
#define LENGTH(a) (*(((jint*)(a))-3)) #define STRING(s) ptr<java_lang_String>(new java_lang_String(ptr< array<jchar> >(new array<jchar>(s, (jint) wcslen(s)))));
#define CLASS_ID(a) (*(((jint*)(a))-2))
#define NEW_ARRAY(size, length) new_array(0, size, length)
#define NEW_OBJ_ARRAY(length) new_array(0, sizeof(void*), length)
#define NEW_OBJ(typeId, typeName) new_object(typeId, sizeof(struct typeName))
#define SET(variable, p) set_object(variable, p)
#define STRING(s) ((java_lang_String*) string(s))
void* new_array(jint object, jint size, jint length);
void* new_object(jint type, jint size);
void* reference(void* o);
void release(void* o);
void* set(void* o, void* n);
void* string(char* s);
*/ class RefBase {
protected:
/* jint refCount;
* Object layout: public:
* m-2: data type RefBase() {
* m-1: number of references refCount = 1;
* m: object data
*
* Array layout:
* m-3: length (number of elements)
* m-2: 0 (array marker)
* m-1: number of references
* m: first element
*/
/**
* A java.lang.String implementation.
*/
public class String {
/* c:
void* new_array_with_count(jint object, jint size, jint length, jint refCount) {
jint count = sizeof(jint) * 3 + size * length;
jint* m = (jint*) calloc(1, count);
*m = length;
*(m + 2) = refCount;
return m + 3;
}
void* new_array(jint object, jint size, jint length) {
return new_array_with_count(object, size, length, 1);
}
void* new_static_array(jint object, jint size, jint length) {
return new_array_with_count(object, size, length, 0);
}
void* new_object_with_count(jint type, jint size, jint refCount) {
jint count = sizeof(jint) * 2 + size;
jint* m = (jint*) calloc(1, count);
*m = type;
*(m + 1) = refCount;
return m + 2;
}
void* new_object(jint type, jint size) {
return new_object_with_count(type, size, 1);
}
void* new_static_object(jint type, jint size) {
return new_object_with_count(type, size, 0);
}
void* reference(void* o) {
if (o != 0) {
jint* m = (jint*) o;
if (*(m - 1) > 0) {
(*(m - 1))++;
} }
void reference() {
refCount++;
} }
return o; void release() {
} if (--refCount == 0) {
delete this;
void release(void* o) {
if (o == 0) {
return;
} }
jint* m = (jint*) o;
if (*(m - 1) <= 1) {
if (*(m - 1) == 0) {
return;
} }
if (*(m - 2) == 0) { };
free(m - 3); template <class T> class ptr {
} else { T* pointer;
free(m - 2); public:
explicit ptr(T* p=0) : pointer(p) {
if (p != 0) {
((RefBase*)p)->reference();
} }
} else {
(*(m - 1))--;
} }
} ptr(const ptr<T>& p) : pointer(p.pointer) {
if (p.pointer != 0) {
void* set(void* o, void* n) { ((RefBase*)p.pointer)->reference();
release(o);
return reference(n);
}
void* string(char* s) {
jint len = strlen(s);
jchar* chars = NEW_ARRAY(sizeof(jchar), len);
for (int i = 0; i < len; i++) {
chars[i] = s[i];
} }
return java_lang_String_init_obj(chars); }
} ~ptr() {
if (pointer != 0) {
((RefBase*)pointer)->release();
}
}
ptr<T>& operator= (const ptr<T>& p) {
if (this != &p && pointer != p.pointer) {
if (pointer != 0) {
((RefBase*)pointer)->release();
}
pointer = p.pointer;
if (pointer != 0) {
((RefBase*)pointer)->reference();
}
}
return *this;
}
T& operator*() {
return *pointer;
}
T* operator->() {
return pointer;
}
jboolean operator==(const ptr<T>& p) {
return pointer == p->pointer;
}
jboolean operator==(const RefBase* t) {
return pointer == t;
}
};
template <class T> class array : RefBase {
jint len;
T* data;
public:
array(const T* d, jint len) {
this->len = len;
data = new T[len];
memcpy(data, d, sizeof(T) * len);
}
array(jint len) {
this->len = len;
data = new T[len];
}
~array() {
delete[] data;
}
T* getData() {
return data;
}
jint length() {
return len;
}
T& operator[](jint index) {
if (index < 0 || index >= len) {
throw "index set";
}
return data[index];
}
T& at(jint index) {
if (index < 0 || index >= len) {
throw "index set";
}
return data[index];
}
};
*/ */
/**
* A java.lang.String implementation.
*/
public class String {
/** /**
* The character array. * The character array.
*/ */
char[] chars; char[] chars;
private int hashCode; private int hash;
public String(char[] chars) { public String(char[] chars) {
this.chars = new char[chars.length]; this.chars = new char[chars.length];
...@@ -162,7 +152,7 @@ void* string(char* s) { ...@@ -162,7 +152,7 @@ void* string(char* s) {
} }
public int hashCode() { public int hashCode() {
if (hashCode == 0) { if (hash == 0) {
if (chars.length == 0) { if (chars.length == 0) {
return 0; return 0;
} }
...@@ -170,10 +160,10 @@ void* string(char* s) { ...@@ -170,10 +160,10 @@ void* string(char* s) {
for (char c : chars) { for (char c : chars) {
h = h * 31 + c; h = h * 31 + c;
} }
hashCode = h; hash = h;
return h; return h;
} }
return hashCode; return hash;
} }
/** /**
...@@ -185,6 +175,10 @@ void* string(char* s) { ...@@ -185,6 +175,10 @@ void* string(char* s) {
return chars.length; return chars.length;
} }
public String toStringMethod() {
return this;
}
@Ignore @Ignore
public java.lang.String asString() { public java.lang.String asString() {
return new java.lang.String(chars); return new java.lang.String(chars);
......
...@@ -30,8 +30,8 @@ public class System { ...@@ -30,8 +30,8 @@ public class System {
*/ */
public static void arraycopy(char[] src, int srcPos, char[] dest, int destPos, int length) { public static void arraycopy(char[] src, int srcPos, char[] dest, int destPos, int length) {
/* c: /* c:
memmove(((jchar*)dest) + destPos, memmove(((jchar*)dest->getData()) + destPos,
((jchar*)src) + srcPos, sizeof(jchar) * length); ((jchar*)src->getData()) + srcPos, sizeof(jchar) * length);
*/ */
// c: return; // c: return;
java.lang.System.arraycopy(src, srcPos, dest, destPos, length); java.lang.System.arraycopy(src, srcPos, dest, destPos, length);
...@@ -49,8 +49,8 @@ public class System { ...@@ -49,8 +49,8 @@ public class System {
*/ */
public static void arraycopy(byte[] src, int srcPos, byte[] dest, int destPos, int length) { public static void arraycopy(byte[] src, int srcPos, byte[] dest, int destPos, int length) {
/* c: /* c:
memmove(((jbyte*)dest) + destPos, memmove(((jbyte*)dest->getData()) + destPos,
((jbyte*)src) + srcPos, sizeof(jbyte) * length); ((jbyte*)src->getData()) + srcPos, sizeof(jbyte) * length);
*/ */
// c: return; // c: return;
java.lang.System.arraycopy(src, srcPos, dest, destPos, length); java.lang.System.arraycopy(src, srcPos, dest, destPos, length);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论