Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
42c4f92d
提交
42c4f92d
authored
12 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Documentation / cleanup
上级
e4842f9d
master
noel-pr1
plus33-master
pr/267
stumc-Issue#576
version-1.4.198
version-1.4.197
version-1.4.196
version-1.4.195
version-1.4.194
version-1.4.193
version-1.4.192
version-1.4.191
version-1.4.190
version-1.4.188
version-1.4.187
version-1.4.186
version-1.4.185
version-1.4.184
version-1.4.183
version-1.4.182
version-1.4.181
version-1.4.178
version-1.4.177
version-1.3
无相关合并请求
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
529 行增加
和
149 行删除
+529
-149
ClassObj.java
h2/src/tools/org/h2/java/ClassObj.java
+31
-1
Expr.java
h2/src/tools/org/h2/java/Expr.java
+168
-78
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+47
-25
Statement.java
h2/src/tools/org/h2/java/Statement.java
+206
-31
Test.java
h2/src/tools/org/h2/java/Test.java
+3
-2
TestApp.java
h2/src/tools/org/h2/java/TestApp.java
+27
-2
PrintStream.java
h2/src/tools/org/h2/java/io/PrintStream.java
+1
-1
Integer.java
h2/src/tools/org/h2/java/lang/Integer.java
+7
-1
Long.java
h2/src/tools/org/h2/java/lang/Long.java
+7
-1
String.java
h2/src/tools/org/h2/java/lang/String.java
+28
-3
System.java
h2/src/tools/org/h2/java/lang/System.java
+4
-4
没有找到文件。
h2/src/tools/org/h2/java/ClassObj.java
浏览文件 @
42c4f92d
...
...
@@ -372,6 +372,11 @@ class Type {
return
asString
();
}
/**
* Get the C++ code.
*
* @return the C++ code
*/
public
String
asString
()
{
StringBuilder
buff
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
arrayLevel
;
i
++)
{
...
...
@@ -392,10 +397,14 @@ class Type {
}
}
for
(
int
i
=
0
;
i
<
arrayLevel
;
i
++)
{
buff
.
append
(
" >"
);
if
(
refCount
)
{
buff
.
append
(
" >"
);
}
else
{
if
(!
classObj
.
isPrimitive
)
{
buff
.
append
(
"*"
);
}
}
buff
.
append
(
" >"
);
}
if
(!
refCount
)
{
if
(
isObject
())
{
...
...
@@ -417,5 +426,26 @@ class Type {
return
false
;
}
/**
* Get the default value, for primitive types (0 usually).
*
* @param context the context
* @return the expression
*/
public
Expr
getDefaultValue
(
JavaParser
context
)
{
if
(
classObj
.
isPrimitive
)
{
LiteralExpr
literal
=
new
LiteralExpr
(
context
,
classObj
.
className
);
literal
.
literal
=
"0"
;
CastExpr
cast
=
new
CastExpr
();
cast
.
type
=
this
;
cast
.
expr
=
literal
;
cast
.
type
=
this
;
return
cast
;
}
LiteralExpr
literal
=
new
LiteralExpr
(
context
,
classObj
.
className
);
literal
.
literal
=
"null"
;
return
literal
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
42c4f92d
差异被折叠。
点击展开。
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
42c4f92d
...
...
@@ -22,7 +22,15 @@ import org.h2.util.New;
*/
public
class
JavaParser
{
public
static
final
boolean
REF_COUNT
=
true
;
/**
* Whether ref-counting is used.
*/
public
static
final
boolean
REF_COUNT
=
false
;
/**
* Whether ref-counting is used for constants.
*/
public
static
final
boolean
REF_COUNT_STATIC
=
false
;
private
static
final
HashMap
<
String
,
ClassObj
>
BUILT_IN_CLASSES
=
New
.
hashMap
();
...
...
@@ -245,6 +253,12 @@ public class JavaParser {
return
c
;
}
/**
* Get the class for a built-in type.
*
* @param type the type
* @return the class or null if not found
*/
static
ClassObj
getBuiltInClass
(
String
type
)
{
return
BUILT_IN_CLASSES
.
get
(
type
);
}
...
...
@@ -386,6 +400,8 @@ public class JavaParser {
}
else
{
field
.
value
=
readExpr
();
}
}
else
{
field
.
value
=
field
.
type
.
getDefaultValue
(
this
);
}
read
(
";"
);
if
(
isStatic
)
{
...
...
@@ -495,8 +511,8 @@ public class JavaParser {
while
(
source
.
charAt
(
current
.
index
)
!=
'\n'
)
{
current
.
index
++;
}
St
atementNative
stat
=
new
StatementNative
();
stat
.
code
=
source
.
substring
(
start
,
current
.
index
).
trim
(
);
St
ring
s
=
source
.
substring
(
start
,
current
.
index
).
trim
();
StatementNative
stat
=
new
StatementNative
(
s
);
read
();
return
isC
?
stat
:
null
;
}
else
if
(
readIf
(
"/*"
))
{
...
...
@@ -505,8 +521,8 @@ public class JavaParser {
while
(
source
.
charAt
(
current
.
index
)
!=
'*'
||
source
.
charAt
(
current
.
index
+
1
)
!=
'/'
)
{
current
.
index
++;
}
St
atementNative
stat
=
new
StatementNative
();
stat
.
code
=
source
.
substring
(
start
,
current
.
index
).
trim
(
);
St
ring
s
=
source
.
substring
(
start
,
current
.
index
).
trim
();
StatementNative
stat
=
new
StatementNative
(
s
);
current
.
index
+=
2
;
read
();
return
isC
?
stat
:
null
;
...
...
@@ -554,16 +570,16 @@ public class JavaParser {
read
(
";"
);
return
new
ContinueStatement
();
}
else
if
(
readIf
(
"switch"
))
{
SwitchStatement
switchStat
=
new
SwitchStatement
();
read
(
"("
);
switchStat
.
expr
=
readExpr
(
);
SwitchStatement
switchStat
=
new
SwitchStatement
(
readExpr
()
);
read
(
")"
);
read
(
"{"
);
while
(
true
)
{
if
(
readIf
(
"default"
))
{
read
(
":"
);
StatementBlock
block
=
new
StatementBlock
();
switchStat
.
defaultBlock
=
block
;
switchStat
.
setDefaultBlock
(
block
)
;
while
(
true
)
{
block
.
instructions
.
add
(
readStatement
());
if
(
current
.
token
.
equals
(
"case"
)
||
current
.
token
.
equals
(
"default"
)
||
current
.
token
.
equals
(
"}"
))
{
...
...
@@ -571,7 +587,7 @@ public class JavaParser {
}
}
}
else
if
(
readIf
(
"case"
))
{
switchStat
.
cases
.
add
(
readExpr
()
);
Expr
expr
=
readExpr
(
);
read
(
":"
);
StatementBlock
block
=
new
StatementBlock
();
while
(
true
)
{
...
...
@@ -580,7 +596,7 @@ public class JavaParser {
break
;
}
}
switchStat
.
blocks
.
add
(
block
);
switchStat
.
addCase
(
expr
,
block
);
}
else
if
(
readIf
(
"}"
))
{
break
;
}
...
...
@@ -654,8 +670,7 @@ public class JavaParser {
f
.
type
=
dec
.
type
;
f
.
name
=
varName
;
localVars
.
put
(
varName
,
f
);
dec
.
variables
.
add
(
varName
);
dec
.
values
.
add
(
value
);
dec
.
addVariable
(
varName
,
value
);
if
(
readIf
(
";"
))
{
break
;
}
...
...
@@ -666,8 +681,7 @@ public class JavaParser {
current
=
start
;
// ExprStatement
}
ExprStatement
stat
=
new
ExprStatement
();
stat
.
expr
=
readExpr
();
ExprStatement
stat
=
new
ExprStatement
(
readExpr
());
read
(
";"
);
return
stat
;
}
...
...
@@ -992,7 +1006,7 @@ public class JavaParser {
if
(
ch
>=
'a'
&&
ch
<=
'z'
)
{
// don't use Character.toUpperCase
// to avoid locale problems
// (the uppercase of
i isn't always I
)
// (the uppercase of
'i' is not always 'I'
)
buff
.
append
((
char
)
(
ch
+
'A'
-
'a'
));
}
else
if
(
ch
>=
'A'
&&
ch
<=
'Z'
)
{
buff
.
append
(
ch
);
...
...
@@ -1026,7 +1040,7 @@ public class JavaParser {
private
Expr
readExpr5
()
{
if
(
readIf
(
"new"
))
{
NewExpr
expr
=
new
NewExpr
(
this
);
NewExpr
expr
=
new
NewExpr
();
String
typeName
=
readTypeOrIdentifier
();
expr
.
classObj
=
getClass
(
typeName
);
if
(
readIf
(
"("
))
{
...
...
@@ -1550,7 +1564,12 @@ public class JavaParser {
*/
void
writeHeader
(
PrintWriter
out
)
{
for
(
Statement
s
:
nativeHeaders
)
{
out
.
println
(
s
);
out
.
println
(
s
.
asString
());
}
if
(
JavaParser
.
REF_COUNT_STATIC
)
{
out
.
println
(
"#define STRING(s) STRING_REF(s)"
);
}
else
{
out
.
println
(
"#define STRING(s) STRING_PTR(s)"
);
}
out
.
println
();
for
(
ClassObj
c
:
classes
.
values
())
{
...
...
@@ -1603,9 +1622,6 @@ public class JavaParser {
for
(
FieldObj
f
:
c
.
instanceFields
.
values
())
{
out
.
print
(
" "
);
out
.
print
(
f
.
type
.
asString
()
+
" "
+
f
.
name
);
if
(
f
.
value
!=
null
)
{
out
.
print
(
" = "
+
f
.
value
);
}
out
.
println
(
";"
);
}
out
.
println
(
"public:"
);
...
...
@@ -1640,7 +1656,7 @@ public class JavaParser {
Collections
.
sort
(
constantNames
);
for
(
String
c
:
constantNames
)
{
String
s
=
stringConstantToStringMap
.
get
(
c
);
if
(
JavaParser
.
REF_COUNT
)
{
if
(
JavaParser
.
REF_COUNT
_STATIC
)
{
out
.
println
(
"ptr<java_lang_String> "
+
c
+
" = STRING(L\""
+
s
+
"\");"
);
}
else
{
out
.
println
(
"java_lang_String* "
+
c
+
" = STRING(L\""
+
s
+
"\");"
);
...
...
@@ -1655,9 +1671,9 @@ public class JavaParser {
*/
void
writeSource
(
PrintWriter
out
)
{
for
(
ClassObj
c
:
classes
.
values
())
{
out
.
println
(
"/* "
+
c
.
className
+
"
.cpp
*/"
);
out
.
println
(
"/* "
+
c
.
className
+
" */"
);
for
(
Statement
s
:
c
.
nativeCode
)
{
out
.
println
(
s
);
out
.
println
(
s
.
asString
()
);
}
for
(
FieldObj
f
:
c
.
staticFields
.
values
())
{
StringBuilder
buff
=
new
StringBuilder
();
...
...
@@ -1694,10 +1710,16 @@ public class JavaParser {
}
out
.
println
(
") {"
);
if
(
m
.
isConstructor
)
{
// TODO
for
(
FieldObj
f
:
c
.
instanceFields
.
values
())
{
out
.
print
(
" "
);
out
.
print
(
"this->"
+
f
.
name
);
out
.
print
(
" = "
+
f
.
value
.
asString
());
out
.
println
(
";"
);
}
}
if
(
m
.
block
!=
null
)
{
out
.
print
(
m
.
block
.
toString
());
m
.
block
.
setMethod
(
m
);
out
.
print
(
m
.
block
.
asString
());
}
out
.
println
(
"}"
);
out
.
println
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/Statement.java
浏览文件 @
42c4f92d
差异被折叠。
点击展开。
h2/src/tools/org/h2/java/Test.java
浏览文件 @
42c4f92d
...
...
@@ -30,11 +30,12 @@ public class Test extends TestBase {
// chmod +x test
// ./test
// TODO initialize fields
// include files:
// /usr/include/c++/4.2.1/tr1/stdio.h
// /usr/include/stdio.h
// TODO initialize fields
// inttypes.h
// not supported yet:
// exceptions
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/TestApp.java
浏览文件 @
42c4f92d
...
...
@@ -26,8 +26,33 @@ int main(int argc, char** argv) {
* @param args the command line arguments
*/
public
static
void
main
(
String
...
args
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
out
.
println
(
"Hello "
+
i
);
String
[]
list
=
new
String
[
1000
];
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
list
[
i
]
=
"Hello "
+
i
;
}
// time:29244000 mac g++ -O3 without array bound checks
// time:30673000 mac java
// time:32449000 mac g++ -O3
// time:69692000 mac g++ -O3 ref counted
// time:1200000000 raspberry g++ -O3
// time:1720000000 raspberry g++ -O3 ref counted
// time:1980469000 raspberry java IcedTea6 1.8.13 Cacao VM
// time:12962645810 raspberry java IcedTea6 1.8.13 Zero VM
// java -XXaltjvm=cacao
for
(
int
k
=
0
;
k
<
4
;
k
++)
{
long
t
=
System
.
nanoTime
();
long
h
=
0
;
for
(
int
j
=
0
;
j
<
10000
;
j
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
String
s
=
list
[
i
];
h
=
(
h
*
7
)
^
s
.
hashCode
();
}
}
System
.
out
.
println
(
"hash: "
+
h
);
t
=
System
.
nanoTime
()
-
t
;
System
.
out
.
println
(
"time:"
+
t
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/io/PrintStream.java
浏览文件 @
42c4f92d
...
...
@@ -18,7 +18,7 @@ public class PrintStream {
*/
public
void
println
(
String
s
)
{
// c: int x = s->chars->length();
// c: printf("%.*S\n", x, s->chars->get
Data
());
// c: printf("%.*S\n", x, s->chars->get
Pointer
());
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/Integer.java
浏览文件 @
42c4f92d
...
...
@@ -11,8 +11,14 @@ package org.h2.java.lang;
*/
public
class
Integer
{
/**
* The smallest possible value.
*/
public
static
final
int
MIN_VALUE
=
1
<<
31
;
/**
* The largest possible value.
*/
public
static
final
int
MAX_VALUE
=
(
int
)
((
1L
<<
31
)
-
1
);
/**
...
...
@@ -23,7 +29,7 @@ public class Integer {
*/
public
static
String
toString
(
int
x
)
{
// c: wchar_t ch[20];
// c: swprintf(ch, 20, L"%
d"
, x);
// c: swprintf(ch, 20, L"%
" PRId32
, x);
// c: return STRING(ch);
// c: return;
if
(
x
==
MIN_VALUE
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/Long.java
浏览文件 @
42c4f92d
...
...
@@ -12,8 +12,14 @@ package org.h2.java.lang;
*/
public
class
Long
{
/**
* The smallest possible value.
*/
public
static
final
long
MIN_VALUE
=
1L
<<
63
;
/**
* The largest possible value.
*/
public
static
final
long
MAX_VALUE
=
(
1L
<<
63
)
-
1
;
/**
...
...
@@ -24,7 +30,7 @@ public class Long {
*/
public
static
String
toString
(
long
x
)
{
// c: wchar_t ch[30];
// c: swprintf(ch, 30, L"%
ld"
, x);
// c: swprintf(ch, 30, L"%
" PRId64
, x);
// c: return STRING(ch);
// c: return;
if
(
x
==
MIN_VALUE
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/String.java
浏览文件 @
42c4f92d
...
...
@@ -14,8 +14,11 @@ import org.h2.java.Local;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <stdint.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#define jvoid void
#define jboolean int8_t
...
...
@@ -31,9 +34,12 @@ import org.h2.java.Local;
#define false 0
#define null 0
#define STRING(s) ptr<java_lang_String>(new java_lang_String(ptr< array<jchar> >(new array<jchar>(s, (jint) wcslen(s)))));
#define STRING_REF(s) ptr<java_lang_String> \
(new java_lang_String(ptr< array<jchar> > \
(new array<jchar>(s, (jint) wcslen(s)))));
// #define STRING(s) new java_lang_String(new array<jchar>(s, (jint) wcslen(s)));
#define STRING_PTR(s) new java_lang_String \
(new array<jchar>(s, (jint) wcslen(s)));
class RefBase {
protected:
...
...
@@ -86,6 +92,9 @@ public:
T& operator*() {
return *pointer;
}
T* getPointer() {
return pointer;
}
T* operator->() {
return pointer;
}
...
...
@@ -112,7 +121,7 @@ public:
~array() {
delete[] data;
}
T* get
Data
() {
T* get
Pointer
() {
return data;
}
jint length() {
...
...
@@ -180,15 +189,31 @@ public class String {
return
chars
.
length
;
}
/**
* The toString method.
*
* @return the string
*/
public
String
toStringMethod
()
{
return
this
;
}
/**
* Get the java.lang.String.
*
* @return the string
*/
@Ignore
public
java
.
lang
.
String
asString
()
{
return
new
java
.
lang
.
String
(
chars
);
}
/**
* Wrap a java.lang.String.
*
* @param x the string
* @return the object
*/
@Ignore
public
static
String
wrap
(
java
.
lang
.
String
x
)
{
return
new
String
(
x
.
toCharArray
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/java/lang/System.java
浏览文件 @
42c4f92d
...
...
@@ -30,8 +30,8 @@ public class System {
*/
public
static
void
arraycopy
(
char
[]
src
,
int
srcPos
,
char
[]
dest
,
int
destPos
,
int
length
)
{
/* c:
memmove(((jchar*)dest->get
Data
()) + destPos,
((jchar*)src->get
Data
()) + srcPos, sizeof(jchar) * length);
memmove(((jchar*)dest->get
Pointer
()) + destPos,
((jchar*)src->get
Pointer
()) + srcPos, sizeof(jchar) * length);
*/
// c: return;
java
.
lang
.
System
.
arraycopy
(
src
,
srcPos
,
dest
,
destPos
,
length
);
...
...
@@ -49,8 +49,8 @@ public class System {
*/
public
static
void
arraycopy
(
byte
[]
src
,
int
srcPos
,
byte
[]
dest
,
int
destPos
,
int
length
)
{
/* c:
memmove(((jbyte*)dest->get
Data
()) + destPos,
((jbyte*)src->get
Data
()) + srcPos, sizeof(jbyte) * length);
memmove(((jbyte*)dest->get
Pointer
()) + destPos,
((jbyte*)src->get
Pointer
()) + srcPos, sizeof(jbyte) * length);
*/
// c: return;
java
.
lang
.
System
.
arraycopy
(
src
,
srcPos
,
dest
,
destPos
,
length
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论