Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
39ac3dc3
提交
39ac3dc3
authored
3月 20, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A Java parser / Java to C converter.
上级
04db103b
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
140 行增加
和
43 行删除
+140
-43
Expr.java
h2/src/tools/org/h2/java/Expr.java
+2
-2
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+38
-24
TestApp.java
h2/src/tools/org/h2/java/TestApp.java
+1
-2
Math.java
h2/src/tools/org/h2/java/lang/Math.java
+25
-0
String.java
h2/src/tools/org/h2/java/lang/String.java
+29
-13
StringBuilder.java
h2/src/tools/org/h2/java/lang/StringBuilder.java
+43
-0
System.java
h2/src/tools/org/h2/java/lang/System.java
+2
-2
没有找到文件。
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
39ac3dc3
...
...
@@ -47,7 +47,7 @@ class CallExpr implements Expr {
MethodObj
m
=
classObj
.
getMethod
(
name
,
args
);
String
methodName
;
if
(
m
.
isVirtual
)
{
methodName
=
"
*
virtual_"
+
m
.
name
+
"[CLASS_ID("
+
expr
.
toString
()+
")]"
;
methodName
=
"virtual_"
+
m
.
name
+
"[CLASS_ID("
+
expr
.
toString
()+
")]"
;
}
else
{
methodName
=
JavaParser
.
toC
(
classObj
.
toString
()
+
"."
+
m
.
name
);
}
...
...
@@ -224,7 +224,7 @@ class NewExpr implements Expr {
buff
.
append
(
")"
);
}
}
else
{
buff
.
append
(
"NEW_OBJ("
+
type
.
id
+
", "
+
type
+
")"
);
buff
.
append
(
"NEW_OBJ("
+
type
.
id
+
", "
+
JavaParser
.
toC
(
type
.
toString
())
+
")"
);
}
return
buff
.
toString
();
}
...
...
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
39ac3dc3
...
...
@@ -28,10 +28,10 @@ public class JavaParser {
private
static
final
int
TOKEN_OTHER
=
5
;
private
static
final
HashSet
<
String
>
RESERVED
=
new
HashSet
<
String
>();
private
static
final
HashMap
<
String
,
ClassObj
>
BUILT_IN_TYPES
=
new
HashMap
<
String
,
ClassObj
>();
private
static
final
HashMap
<
String
,
String
>
JAVA_IMPORT_MAP
=
new
HashMap
<
String
,
String
>();
private
static
int
firstClassId
;
private
final
ArrayList
<
ClassObj
>
allClasses
=
new
ArrayList
<
ClassObj
>();
private
final
HashMap
<
String
,
ClassObj
>
builtInTypes
=
new
HashMap
<
String
,
ClassObj
>();
private
String
source
;
...
...
@@ -39,7 +39,7 @@ public class JavaParser {
private
String
packageName
;
private
ClassObj
classObj
;
private
int
classId
=
firs
tClassId
;
private
int
nex
tClassId
;
private
MethodObj
method
;
private
FieldObj
thisPointer
;
private
HashMap
<
String
,
String
>
importMap
=
new
HashMap
<
String
,
String
>();
...
...
@@ -49,7 +49,11 @@ public class JavaParser {
private
ArrayList
<
Statement
>
nativeHeaders
=
new
ArrayList
<
Statement
>();
static
{
public
JavaParser
()
{
addBuiltInTypes
();
}
private
void
addBuiltInTypes
()
{
String
[]
list
=
{
"abstract"
,
"continue"
,
"for"
,
"new"
,
"switch"
,
"assert"
,
"default"
,
"if"
,
"package"
,
"synchronized"
,
"boolean"
,
"do"
,
"goto"
,
"private"
,
"this"
,
"break"
,
"double"
,
"implements"
,
"protected"
,
"throw"
,
"byte"
,
"else"
,
"import"
,
"public"
,
"throws"
,
"case"
,
"enum"
,
"instanceof"
,
...
...
@@ -76,16 +80,25 @@ public class JavaParser {
JAVA_IMPORT_MAP
.
put
(
s
,
"java.lang."
+
s
);
addBuiltInType
(
id
++,
false
,
0
,
"java.lang."
+
s
);
}
firs
tClassId
=
id
;
nex
tClassId
=
id
;
}
private
static
void
addBuiltInType
(
int
id
,
boolean
primitive
,
int
primitiveType
,
String
type
)
{
ClassObj
typeObj
=
new
ClassObj
();
typeObj
.
id
=
id
;
typeObj
.
name
=
type
;
typeObj
.
isPrimitive
=
primitive
;
typeObj
.
primitiveType
=
primitiveType
;
BUILT_IN_TYPES
.
put
(
type
,
typeObj
);
private
void
addBuiltInType
(
int
id
,
boolean
primitive
,
int
primitiveType
,
String
type
)
{
ClassObj
c
=
new
ClassObj
();
c
.
id
=
id
;
c
.
name
=
type
;
c
.
isPrimitive
=
primitive
;
c
.
primitiveType
=
primitiveType
;
builtInTypes
.
put
(
type
,
c
);
addClass
(
c
);
}
private
void
addClass
(
ClassObj
c
)
{
int
id
=
c
.
id
;
while
(
id
>=
allClasses
.
size
())
{
allClasses
.
add
(
null
);
}
allClasses
.
set
(
id
,
c
);
}
/**
...
...
@@ -151,16 +164,17 @@ public class JavaParser {
isInterface
=
true
;
}
String
name
=
readIdentifier
();
classObj
=
BUILT_IN_TYPES
.
get
(
packageName
+
"."
+
name
);
classObj
=
builtInTypes
.
get
(
packageName
+
"."
+
name
);
if
(
classObj
==
null
)
{
classObj
=
new
ClassObj
();
classObj
.
id
=
c
lassId
++;
classObj
.
id
=
nextC
lassId
++;
}
classObj
.
isPublic
=
isPublic
;
classObj
.
isInterface
=
isInterface
;
classObj
.
name
=
packageName
==
null
?
""
:
(
packageName
+
"."
)
+
name
;
// import this class
importMap
.
put
(
name
,
classObj
.
name
);
addClass
(
classObj
);
classes
.
put
(
classObj
.
name
,
classObj
);
if
(
readIf
(
"extends"
))
{
classObj
.
superClassName
=
readQualifiedIdentifier
();
...
...
@@ -181,7 +195,7 @@ public class JavaParser {
}
private
boolean
isTypeOrIdentifier
()
{
if
(
BUILT_IN_TYPES
.
containsKey
(
current
.
token
))
{
if
(
builtInTypes
.
containsKey
(
current
.
token
))
{
return
true
;
}
return
current
.
type
==
TOKEN_IDENTIFIER
;
...
...
@@ -196,7 +210,7 @@ public class JavaParser {
}
private
ClassObj
getClassIf
(
String
type
)
{
ClassObj
c
=
BUILT_IN_TYPES
.
get
(
type
);
ClassObj
c
=
builtInTypes
.
get
(
type
);
if
(
c
!=
null
)
{
return
c
;
}
...
...
@@ -213,7 +227,7 @@ public class JavaParser {
}
c
=
classes
.
get
(
mappedType
);
if
(
c
==
null
)
{
c
=
BUILT_IN_TYPES
.
get
(
mappedType
);
c
=
builtInTypes
.
get
(
mappedType
);
if
(
c
==
null
)
{
throw
new
RuntimeException
(
"Unknown class: "
+
mappedType
);
}
...
...
@@ -409,7 +423,7 @@ public class JavaParser {
private
String
readTypeOrIdentifier
()
{
if
(
current
.
type
==
TOKEN_RESERVED
)
{
if
(
BUILT_IN_TYPES
.
containsKey
(
current
.
token
))
{
if
(
builtInTypes
.
containsKey
(
current
.
token
))
{
return
read
();
}
}
...
...
@@ -745,7 +759,7 @@ public class JavaParser {
expr
=
e2
;
if
(
n
.
equals
(
"length"
)
&&
t
.
arrayLevel
>
0
)
{
e2
.
field
=
new
FieldObj
();
e2
.
field
.
type
=
BUILT_IN_TYPES
.
get
(
"int"
).
baseType
;
e2
.
field
.
type
=
builtInTypes
.
get
(
"int"
).
baseType
;
e2
.
field
.
name
=
"length"
;
}
else
{
if
(
t
==
null
||
t
.
classObj
==
null
)
{
...
...
@@ -1380,11 +1394,11 @@ public class JavaParser {
i
++;
}
out
.
println
(
") = {"
);
for
(
ClassObj
c
:
classes
.
values
()
)
{
if
(
c
.
methods
.
containsKey
(
m
.
name
))
{
out
.
println
(
" "
+
toC
(
c
.
name
)
+
"_"
+
m
.
name
+
", "
);
for
(
ClassObj
c
:
allClasses
)
{
if
(
c
!=
null
&&
c
.
methods
.
containsKey
(
m
.
name
))
{
out
.
println
(
toC
(
c
.
name
)
+
"_"
+
m
.
name
+
", "
);
}
else
{
out
.
print
ln
(
"
0, "
);
out
.
print
(
"
0, "
);
}
}
out
.
println
(
"};"
);
...
...
@@ -1494,7 +1508,7 @@ public class JavaParser {
* @return the class
*/
ClassObj
getClassObj
(
String
className
)
{
ClassObj
c
=
BUILT_IN_TYPES
.
get
(
className
);
ClassObj
c
=
builtInTypes
.
get
(
className
);
if
(
c
==
null
)
{
c
=
classes
.
get
(
className
);
}
...
...
h2/src/tools/org/h2/java/TestApp.java
浏览文件 @
39ac3dc3
...
...
@@ -25,8 +25,7 @@ int main(int argc, char** argv) {
* @param args the command line arguments
*/
public
static
void
main
(
String
...
args
)
{
System
.
out
.
println
(
"Hello World"
);
System
.
out
.
println
(
"Hello!"
);
System
.
out
.
println
(
"Hello "
+
"World"
+
1
);
}
public
int
hashCode
()
{
...
...
h2/src/tools/org/h2/java/lang/Math.java
0 → 100644
浏览文件 @
39ac3dc3
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
java
.
lang
;
/**
* A java.lang.String implementation.
*/
public
class
Math
{
/**
* Get the larger of both values.
*
* @param a the first value
* @param b the second value
* @return the larger
*/
public
static
int
max
(
int
a
,
int
b
)
{
return
a
>
b
?
a
:
b
;
}
}
h2/src/tools/org/h2/java/lang/String.java
浏览文件 @
39ac3dc3
...
...
@@ -28,9 +28,10 @@ package org.h2.java.lang;
#define false 0
#define null 0
#define LENGTH(a) (*(((jint*)(a))-2))
#define LENGTH(a) (*(((jint*)(a))-3))
#define CLASS_ID(a) (*(((jint*)(a))-2))
#define NEW_ARRAY(size, length) new_array(0, size, length)
#define NEW_OBJ_ARRAY(length) new_array(
1
, sizeof(void*), 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))
...
...
@@ -42,6 +43,13 @@ void* string(char* s);
*/
/*
* Object layout:
* m-3: arrays: length; otherwise not allocated
* m-2: arrays: 0; otherwise type
* m-1: number of references
*/
/**
* A java.lang.String implementation.
*/
...
...
@@ -50,32 +58,36 @@ public class String {
/* c:
void* new_array(jint object, jint size, jint length) {
int count = sizeof(jint) *
2
+ size * length;
int count = sizeof(jint) *
3
+ size * length;
int* m = (jint*) calloc(1, count);
*m =
(object << 31) +
length;
*(m
+1
) = 1;
return m +
2
;
*m = length;
*(m
+ 2
) = 1;
return m +
3
;
}
void* new_object(jint type, jint size) {
int count = sizeof(jint) * 2 + size;
int* m = (jint*) calloc(1, count);
*m = type;
*(m
+
1) = 1;
*(m
+
1) = 1;
return m + 2;
}
void* set_object(void** target, void* o) {
int* m = (jint*) target;
if (*(m - 2) == 1) {
free(m - 1);
if (*(m - 1) == 1) {
if (*(m - 2) == 0) {
free(m - 3);
} else {
free(m - 2);
}
} else {
(*(m -
2
))--;
(*(m -
1
))--;
}
*target = o;
m = (jint*) target;
if (o != 0) {
(*(m -
2
))++;
(*(m -
1
))++;
}
return m;
}
...
...
@@ -91,12 +103,16 @@ void* string(char* s) {
*/
private
char
[]
chars
;
/**
* The character array.
*/
char
[]
chars
;
private
int
hashCode
;
public
String
(
char
[]
chars
)
{
this
.
chars
=
new
char
[
chars
.
length
];
System
.
arraycopy
Chars
(
chars
,
0
,
this
.
chars
,
0
,
chars
.
length
);
System
.
arraycopy
(
chars
,
0
,
this
.
chars
,
0
,
chars
.
length
);
}
public
int
hashCode
()
{
...
...
h2/src/tools/org/h2/java/lang/StringBuilder.java
0 → 100644
浏览文件 @
39ac3dc3
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
java
.
lang
;
/**
* A java.lang.String implementation.
*/
public
class
StringBuilder
{
private
int
length
;
private
char
[]
buffer
;
public
StringBuilder
()
{
buffer
=
new
char
[
10
];
}
/**
* Append the given string.
*
* @param s the string
* @return this
*/
public
StringBuilder
append
(
String
s
)
{
int
l
=
s
.
length
();
ensureCapacity
(
l
);
System
.
arraycopy
(
s
.
chars
,
0
,
buffer
,
length
,
l
);
length
+=
l
;
return
this
;
}
private
void
ensureCapacity
(
int
plus
)
{
if
(
buffer
.
length
<
length
+
plus
)
{
char
[]
b
=
new
char
[
Math
.
max
(
length
+
plus
,
buffer
.
length
*
2
)];
System
.
arraycopy
(
buffer
,
0
,
b
,
0
,
length
);
buffer
=
b
;
}
}
}
h2/src/tools/org/h2/java/lang/System.java
浏览文件 @
39ac3dc3
...
...
@@ -28,7 +28,7 @@ public class System {
* @param destPos the first element in the destination
* @param length the number of element to copy
*/
public
static
void
arraycopy
Chars
(
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:
memmove(((jchar*)dest) + destPos,
((jchar*)src) + srcPos, sizeof(jchar) * length);
...
...
@@ -45,7 +45,7 @@ public class System {
* @param destPos the first element in the destination
* @param length the number of element to copy
*/
public
static
void
arraycopy
Byte
(
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:
memmove(((jbyte*)dest) + destPos,
((jbyte*)src) + srcPos, sizeof(jbyte) * length);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论