Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0d2befdf
提交
0d2befdf
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A Java parser / Java to C converter.
上级
67b5f248
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
318 行增加
和
28 行删除
+318
-28
ClassObj.java
h2/src/tools/org/h2/java/ClassObj.java
+14
-0
Expr.java
h2/src/tools/org/h2/java/Expr.java
+72
-3
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+79
-18
Test.java
h2/src/tools/org/h2/java/Test.java
+1
-0
PrintStream.java
h2/src/tools/org/h2/java/io/PrintStream.java
+6
-0
package.html
h2/src/tools/org/h2/java/io/package.html
+15
-0
Object.java
h2/src/tools/org/h2/java/lang/Object.java
+9
-1
String.java
h2/src/tools/org/h2/java/lang/String.java
+10
-1
System.java
h2/src/tools/org/h2/java/lang/System.java
+17
-5
package.html
h2/src/tools/org/h2/java/lang/package.html
+15
-0
package.html
h2/src/tools/org/h2/java/package.html
+15
-0
Arrays.java
h2/src/tools/org/h2/java/util/Arrays.java
+50
-0
package.html
h2/src/tools/org/h2/java/util/package.html
+15
-0
没有找到文件。
h2/src/tools/org/h2/java/ClassObj.java
浏览文件 @
0d2befdf
...
...
@@ -54,8 +54,14 @@ public class ClassObj {
*/
LinkedHashMap
<
String
,
MethodObj
>
methods
=
new
LinkedHashMap
<
String
,
MethodObj
>();
/**
* The list of native statements.
*/
ArrayList
<
Statement
>
nativeCode
=
new
ArrayList
<
Statement
>();
/**
* The class number.
*/
int
id
;
/**
...
...
@@ -64,6 +70,9 @@ public class ClassObj {
* @param method the method
*/
void
addMethod
(
MethodObj
method
)
{
if
(
methods
.
containsKey
(
method
.
name
))
{
throw
new
RuntimeException
(
"Method overloading is not supported: "
+
method
.
name
);
}
methods
.
put
(
method
.
name
,
method
);
}
...
...
@@ -195,6 +204,11 @@ class FieldObj {
*/
Expr
value
;
/**
* The class where this field is declared.
*/
ClassObj
declaredClass
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
0d2befdf
...
...
@@ -137,7 +137,11 @@ class OpExpr implements Expr {
}
else
if
(
right
==
null
)
{
return
left
+
op
;
}
return
left
+
" "
+
op
+
" "
+
right
;
if
(
op
.
equals
(
">>>"
))
{
// ujint / ujlong
return
"(((u"
+
left
.
getType
()
+
") "
+
left
+
") >> "
+
right
+
")"
;
}
return
"("
+
left
+
" "
+
op
+
" "
+
right
+
")"
;
}
public
Type
getType
()
{
...
...
@@ -282,8 +286,7 @@ class VariableExpr implements Expr {
}
if
(
field
!=
null
)
{
if
(
field
.
isStatic
)
{
// buff.append(JavaParser.toC(field.type.type.name + "." + field.name));
buff
.
append
(
JavaParser
.
toC
(
name
));
buff
.
append
(
JavaParser
.
toC
(
field
.
declaredClass
+
"."
+
field
.
name
));
}
else
{
buff
.
append
(
field
.
name
);
}
...
...
@@ -325,3 +328,69 @@ class ArrayExpr implements Expr {
}
}
/**
* An array initializer expression.
*/
class
ArrayInitExpr
implements
Expr
{
Type
type
;
ArrayList
<
Expr
>
list
=
new
ArrayList
<
Expr
>();
public
Type
getType
()
{
return
type
;
}
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
(
"{ "
);
int
i
=
0
;
for
(
Expr
e
:
list
)
{
if
(
i
++
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
e
.
toString
());
}
buff
.
append
(
" }"
);
return
buff
.
toString
();
}
}
/**
* A type cast expression.
*/
class
CastExpr
implements
Expr
{
Type
type
;
Expr
expr
;
public
Type
getType
()
{
return
type
;
}
public
String
toString
()
{
return
"("
+
type
+
") "
+
expr
;
}
}
/**
* An array access expression (get or set).
*/
class
ArrayAccessExpr
implements
Expr
{
Expr
base
;
Expr
index
;
public
Type
getType
()
{
Type
t
=
new
Type
();
t
.
type
=
base
.
getType
().
type
;
t
.
arrayLevel
=
base
.
getType
().
arrayLevel
-
1
;
return
t
;
}
public
String
toString
()
{
return
base
+
"["
+
index
+
"]"
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
0d2befdf
...
...
@@ -49,7 +49,7 @@ public class JavaParser {
private
ArrayList
<
Statement
>
nativeHeaders
=
new
ArrayList
<
Statement
>();
static
{
String
[]
list
=
new
String
[]
{
"abstract"
,
"continue"
,
"for"
,
"new"
,
"switch"
,
"assert"
,
"default"
,
"if"
,
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"
,
"return"
,
"transient"
,
"catch"
,
"extends"
,
"int"
,
"short"
,
"try"
,
"char"
,
"final"
,
"interface"
,
...
...
@@ -68,7 +68,7 @@ public class JavaParser {
addBuiltInType
(
id
++,
true
,
"float"
);
addBuiltInType
(
id
++,
true
,
"boolean"
);
addBuiltInType
(
id
++,
true
,
"short"
);
String
[]
java
=
new
String
[]
{
"Boolean"
,
"Byte"
,
"Character"
,
"Class"
,
"ClassLoader"
,
"Double"
,
"Float"
,
String
[]
java
=
{
"Boolean"
,
"Byte"
,
"Character"
,
"Class"
,
"ClassLoader"
,
"Double"
,
"Float"
,
"Integer"
,
"Long"
,
"Math"
,
"Number"
,
"Object"
,
"Runtime"
,
"Short"
,
"String"
,
"StringBuffer"
,
"StringBuilder"
,
"System"
,
"Thread"
,
"ThreadGroup"
,
"ThreadLocal"
,
"Throwable"
,
"Void"
};
for
(
String
s
:
java
)
{
...
...
@@ -290,14 +290,19 @@ public class JavaParser {
field
.
isFinal
=
isFinal
;
field
.
isPublic
=
isPublic
;
field
.
isPrivate
=
isPrivate
;
field
.
declaredClass
=
classObj
;
if
(
isStatic
)
{
classObj
.
addStaticField
(
field
);
}
else
{
classObj
.
addInstanceField
(
field
);
}
if
(
readIf
(
"="
))
{
if
(
field
.
type
.
arrayLevel
>
0
&&
readIf
(
"{"
))
{
field
.
value
=
readArrayInit
(
field
.
type
);
}
else
{
field
.
value
=
readExpr
();
}
}
read
(
";"
);
}
}
...
...
@@ -305,6 +310,24 @@ public class JavaParser {
}
}
private
Expr
readArrayInit
(
Type
type
)
{
ArrayInitExpr
expr
=
new
ArrayInitExpr
();
expr
.
type
=
new
Type
();
expr
.
type
.
type
=
type
.
type
;
expr
.
type
.
arrayLevel
=
type
.
arrayLevel
-
1
;
while
(
true
)
{
expr
.
list
.
add
(
readExpr
());
if
(
readIf
(
"}"
))
{
break
;
}
read
(
","
);
if
(
readIf
(
"}"
))
{
break
;
}
}
return
expr
;
}
private
void
initThisPointer
()
{
thisPointer
=
new
FieldObj
();
thisPointer
.
isLocal
=
true
;
...
...
@@ -507,8 +530,12 @@ public class JavaParser {
String
varName
=
readIdentifier
();
Expr
value
=
null
;
if
(
readIf
(
"="
))
{
if
(
dec
.
type
.
arrayLevel
>
0
&&
readIf
(
"{"
))
{
value
=
readArrayInit
(
dec
.
type
);
}
else
{
value
=
readExpr
();
}
}
FieldObj
f
=
new
FieldObj
();
f
.
isLocal
=
true
;
f
.
type
=
dec
.
type
;
...
...
@@ -590,6 +617,20 @@ public class JavaParser {
private
Expr
readExpr3
()
{
if
(
readIf
(
"("
))
{
if
(
isTypeOrIdentifier
())
{
ParseState
start
=
copyParseState
();
String
name
=
readTypeOrIdentifier
();
ClassObj
c
=
getClassIf
(
name
);
if
(
c
!=
null
)
{
read
(
")"
);
CastExpr
expr
=
new
CastExpr
();
expr
.
type
=
new
Type
();
expr
.
type
.
type
=
c
;
expr
.
expr
=
readExpr
();
return
expr
;
}
current
=
start
;
}
Expr
expr
=
readExpr
();
read
(
")"
);
return
expr
;
...
...
@@ -675,10 +716,11 @@ public class JavaParser {
if
(
t
.
arrayLevel
==
0
)
{
throw
getSyntaxException
(
"Not an array: "
+
expr
);
}
Expr
arrayIndex
=
readExpr
();
ArrayAccessExpr
arrayExpr
=
new
ArrayAccessExpr
();
arrayExpr
.
base
=
expr
;
arrayExpr
.
index
=
readExpr
();
read
(
"]"
);
// TODO arrayGet or arraySet
return
arrayIndex
;
return
arrayExpr
;
}
else
{
break
;
}
...
...
@@ -1199,12 +1241,21 @@ public class JavaParser {
for
(
ClassObj
c
:
classes
.
values
())
{
out
.
println
(
"/* "
+
c
.
name
+
".h */"
);
for
(
FieldObj
f
:
c
.
staticFields
.
values
())
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"extern "
);
if
(
f
.
isFinal
)
{
out
.
println
(
"#define "
+
toC
(
c
.
name
+
"."
+
f
.
name
)
+
" ("
+
f
.
value
+
")"
);
}
else
{
out
.
print
(
"extern "
+
toC
(
f
.
type
.
toString
())
+
" "
+
toC
(
c
.
name
+
"."
+
f
.
name
));
out
.
println
(
";"
);
buff
.
append
(
"const "
);
}
buff
.
append
(
toC
(
f
.
type
.
type
.
toString
()));
if
(!
f
.
type
.
type
.
isPrimitive
)
{
buff
.
append
(
"*"
);
}
buff
.
append
(
" "
).
append
(
toC
(
c
.
name
+
"."
+
f
.
name
));
for
(
int
i
=
0
;
i
<
f
.
type
.
arrayLevel
;
i
++)
{
buff
.
append
(
"[]"
);
}
buff
.
append
(
";"
);
out
.
println
(
buff
.
toString
());
}
out
.
println
(
"struct "
+
toC
(
c
.
name
)
+
" {"
);
for
(
FieldObj
f
:
c
.
instanceFields
.
values
())
{
...
...
@@ -1251,13 +1302,23 @@ public class JavaParser {
out
.
println
(
s
);
}
for
(
FieldObj
f
:
c
.
staticFields
.
values
())
{
if
(!
f
.
isFinal
)
{
out
.
print
(
toC
(
f
.
type
.
toString
())
+
" "
+
toC
(
c
.
name
+
"."
+
f
.
name
));
if
(
f
.
value
!=
null
)
{
out
.
print
(
" = "
+
f
.
value
);
StringBuilder
buff
=
new
StringBuilder
();
if
(
f
.
isFinal
)
{
buff
.
append
(
"const "
);
}
out
.
println
(
";"
);
buff
.
append
(
toC
(
f
.
type
.
type
.
toString
()));
if
(!
f
.
type
.
type
.
isPrimitive
)
{
buff
.
append
(
"*"
);
}
buff
.
append
(
" "
).
append
(
toC
(
c
.
name
+
"."
+
f
.
name
));
for
(
int
i
=
0
;
i
<
f
.
type
.
arrayLevel
;
i
++)
{
buff
.
append
(
"[]"
);
}
if
(
f
.
value
!=
null
)
{
buff
.
append
(
" = "
+
f
.
value
);
}
buff
.
append
(
";"
);
out
.
println
(
buff
.
toString
());
}
for
(
MethodObj
m
:
c
.
methods
.
values
())
{
out
.
print
(
m
.
returnType
+
" "
+
toC
(
c
.
name
)
+
"_"
+
m
.
name
+
"("
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/Test.java
浏览文件 @
0d2befdf
...
...
@@ -62,6 +62,7 @@ public class Test extends TestBase {
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.String"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.io.PrintStream"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.System"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.util.Arrays"
);
parser
.
parse
(
"src/tools"
,
"org.h2.java.TestApp"
);
PrintWriter
w
=
new
PrintWriter
(
System
.
out
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/io/PrintStream.java
浏览文件 @
0d2befdf
/*
* 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
.
io
;
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/io/package.html
0 → 100644
浏览文件 @
0d2befdf
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
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
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
A simple implementation of the java.lang.* package for the Java parser.
</body></html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/Object.java
浏览文件 @
0d2befdf
/*
* 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
;
/**
...
...
@@ -5,8 +11,10 @@ package org.h2.java.lang;
*/
public
class
Object
{
private
static
final
int
[]
K
=
{
1
};
public
int
hashCode
()
{
return
0
;
return
K
[
0
]
;
}
public
boolean
equals
(
Object
other
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/String.java
浏览文件 @
0d2befdf
/*
* 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
;
/* c:
...
...
@@ -6,6 +12,7 @@ package org.h2.java.lang;
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <stdint.h>
#define jvoid void
#define jboolean int8_t
...
...
@@ -15,6 +22,8 @@ package org.h2.java.lang;
#define jlong int64_t
#define jfloat float
#define jdouble double
#define ujint uint32_t
#define ujlong uint64_t
#define true 1
#define false 0
#define null 0
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/System.java
浏览文件 @
0d2befdf
/*
* 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
;
import
java.io.PrintStream
;
...
...
@@ -22,9 +28,11 @@ public class System {
* @param destPos the first element in the destination
* @param length the number of element to copy
*/
public
static
void
arraycopy
(
java
.
lang
.
Object
src
,
int
srcPos
,
java
.
lang
.
Object
dest
,
int
destPos
,
int
length
)
{
// TODO
// c: memmove(dest + destPos, src + srcPos, length);
public
static
void
arraycopyChars
(
char
[]
src
,
int
srcPos
,
char
[]
dest
,
int
destPos
,
int
length
)
{
/* c:
memmove(((jchar*)dest) + destPos,
((jchar*)src) + srcPos, sizeof(jchar) * length);
*/
}
/**
...
...
@@ -37,8 +45,12 @@ public class System {
* @param destPos the first element in the destination
* @param length the number of element to copy
*/
public
static
void
arraycopyChars
(
char
[]
src
,
int
srcPos
,
char
[]
dest
,
int
destPos
,
int
length
)
{
// c: memmove(((jchar*)dest) + destPos, ((jchar*)src) + srcPos, sizeof(jchar) * length);
public
static
void
arraycopyByte
(
byte
[]
src
,
int
srcPos
,
byte
[]
dest
,
int
destPos
,
int
length
)
{
/* c:
memmove(((jbyte*)dest) + destPos,
((jbyte*)src) + srcPos, sizeof(jbyte) * length);
*/
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/package.html
0 → 100644
浏览文件 @
0d2befdf
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
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
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
A simple implementation of the java.lang.* package for the Java parser.
</body></html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/package.html
0 → 100644
浏览文件 @
0d2befdf
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
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
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
A Java parser implementation.
</body></html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/util/Arrays.java
0 → 100644
浏览文件 @
0d2befdf
/*
* 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
.
util
;
/**
* An simple implementation of java.util.Arrays
*/
public
class
Arrays
{
/**
* Fill an array with the given value.
*
* @param array the array
* @param x the value
*/
public
static
void
fill
(
char
[]
array
,
char
x
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
array
[
i
]
=
x
;
}
}
/**
* Fill an array with the given value.
*
* @param array the array
* @param x the value
*/
public
static
void
fillByte
(
byte
[]
array
,
byte
x
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
array
[
i
]
=
x
;
}
}
/**
* Fill an array with the given value.
*
* @param array the array
* @param x the value
*/
public
static
void
fillInt
(
int
[]
array
,
int
x
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
array
[
i
]
=
x
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/util/package.html
0 → 100644
浏览文件 @
0d2befdf
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
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
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
A simple implementation of the java.lang.* package for the Java parser.
</body></html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论