Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
167230d2
提交
167230d2
authored
6月 26, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Java to C++ converter
上级
142c2e4b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
334 行增加
和
59 行删除
+334
-59
ClassObj.java
h2/src/tools/org/h2/java/ClassObj.java
+7
-2
Expr.java
h2/src/tools/org/h2/java/Expr.java
+11
-13
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+205
-29
Local.java
h2/src/tools/org/h2/java/Local.java
+15
-0
Statement.java
h2/src/tools/org/h2/java/Statement.java
+2
-2
Test.java
h2/src/tools/org/h2/java/Test.java
+6
-2
Long.java
h2/src/tools/org/h2/java/lang/Long.java
+57
-0
String.java
h2/src/tools/org/h2/java/lang/String.java
+14
-11
System.java
h2/src/tools/org/h2/java/lang/System.java
+17
-0
没有找到文件。
h2/src/tools/org/h2/java/ClassObj.java
浏览文件 @
167230d2
...
...
@@ -267,9 +267,14 @@ class FieldObj {
Type
type
;
/**
* Whether this is a
local field
.
* Whether this is a
variable or parameter
.
*/
boolean
isLocal
;
boolean
isVariable
;
/**
* Whether this is a local field (not separately garbage collected).
*/
boolean
isLocalField
;
/**
* The field name.
...
...
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
167230d2
...
...
@@ -23,21 +23,19 @@ public interface Expr {
*/
class
CallExpr
implements
Expr
{
final
JavaParser
context
;
final
Expr
expr
;
final
ArrayList
<
Expr
>
args
=
new
ArrayList
<
Expr
>();
final
boolean
isStatic
;
final
String
className
;
final
String
name
;
private
final
JavaParser
context
;
private
final
String
className
;
private
final
String
name
;
private
Expr
expr
;
private
ClassObj
classObj
;
private
MethodObj
method
;
CallExpr
(
JavaParser
context
,
Expr
expr
,
String
className
,
String
name
,
boolean
isStatic
)
{
CallExpr
(
JavaParser
context
,
Expr
expr
,
String
className
,
String
name
)
{
this
.
context
=
context
;
this
.
expr
=
expr
;
this
.
className
=
className
;
this
.
name
=
name
;
this
.
isStatic
=
isStatic
;
}
private
void
initMethod
()
{
...
...
@@ -50,6 +48,9 @@ class CallExpr implements Expr {
classObj
=
expr
.
getType
().
classObj
;
}
method
=
classObj
.
getMethod
(
name
,
args
);
if
(
method
.
isStatic
)
{
expr
=
null
;
}
}
public
String
toString
()
{
...
...
@@ -165,7 +166,7 @@ class LiteralExpr implements Expr {
public
String
toString
()
{
if
(
"null"
.
equals
(
literal
))
{
return
JavaParser
.
toCType
(
type
)
+
"()"
;
return
JavaParser
.
toCType
(
type
,
true
)
+
"()"
;
}
return
literal
;
}
...
...
@@ -301,7 +302,7 @@ class NewExpr implements Expr {
}
buff
.
append
(
"))"
);
}
else
{
buff
.
append
(
"new "
+
JavaParser
.
toC
(
classObj
.
toString
()));
buff
.
append
(
"
ptr<"
+
JavaParser
.
toC
(
classObj
.
toString
())
+
">(
new "
+
JavaParser
.
toC
(
classObj
.
toString
()));
buff
.
append
(
"("
);
int
i
=
0
;
for
(
Expr
a
:
args
)
{
...
...
@@ -310,7 +311,7 @@ class NewExpr implements Expr {
}
buff
.
append
(
a
);
}
buff
.
append
(
")"
);
buff
.
append
(
")
)
"
);
}
return
buff
.
toString
();
}
...
...
@@ -458,9 +459,6 @@ class VariableExpr implements Expr {
private
void
init
()
{
if
(
field
==
null
)
{
if
(
base
==
null
)
{
System
.
out
.
println
(
"??"
);
}
Type
t
=
base
.
getType
();
if
(
t
.
arrayLevel
>
0
)
{
if
(
"length"
.
equals
(
name
))
{
...
...
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
167230d2
差异被折叠。
点击展开。
h2/src/tools/org/h2/java/Local.java
0 → 100644
浏览文件 @
167230d2
/*
* Copyright 2004-2011 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
;
/**
* This annotation marks fields that are not shared and therefore don't need to
* be garbage collected separately.
*/
public
@interface
Local
{
// empty
}
h2/src/tools/org/h2/java/Statement.java
浏览文件 @
167230d2
...
...
@@ -44,7 +44,7 @@ class ReturnStatement extends StatementBase {
if
(
expr
.
getType
().
isSimplePrimitive
())
{
return
"return "
+
expr
+
";"
;
}
return
"return "
+
JavaParser
.
toCType
(
expr
.
getType
())
+
"("
+
expr
+
");"
;
return
"return "
+
JavaParser
.
toCType
(
expr
.
getType
()
,
true
)
+
"("
+
expr
+
");"
;
}
}
...
...
@@ -253,7 +253,7 @@ class VarDecStatement extends StatementBase {
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
JavaParser
.
toCType
(
type
)).
append
(
' '
);
buff
.
append
(
JavaParser
.
toCType
(
type
,
true
)).
append
(
' '
);
StringBuilder
assign
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
variables
.
size
();
i
++)
{
if
(
i
>
0
)
{
...
...
h2/src/tools/org/h2/java/Test.java
浏览文件 @
167230d2
...
...
@@ -30,13 +30,16 @@ public class Test extends TestBase {
// chmod +x test
// ./test
// (for "mixed declarations and code")
// include files:
// /usr/include/c++/4.2.1/tr1/stdio.h
// /usr/include/stdio.h
// TODO initialize fields
// not supported yet:
// exceptions
// HexadecimalFloatingPointLiteral
// int x()[] { return null; }
// annotations
// import static
// import *
// initializer blocks
...
...
@@ -66,6 +69,7 @@ public class Test extends TestBase {
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.String"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.Math"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.Integer"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.Long"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.StringBuilder"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.io.PrintStream"
);
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.System"
);
...
...
h2/src/tools/org/h2/java/lang/Long.java
0 → 100644
浏览文件 @
167230d2
/*
/*
* Copyright 2004-2011 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.Long implementation.
*/
public
class
Long
{
public
static
final
long
MIN_VALUE
=
1L
<<
63
;
public
static
final
long
MAX_VALUE
=
(
1L
<<
63
)
-
1
;
/**
* Convert a value to a String.
*
* @param x the value
* @return the String
*/
public
static
String
toString
(
long
x
)
{
// c: wchar_t ch[30];
// c: swprintf(ch, 30, L"%ld", x);
// c: return STRING(ch);
// c: return;
if
(
x
==
MIN_VALUE
)
{
return
String
.
wrap
(
"-9223372036854775808"
);
}
char
[]
ch
=
new
char
[
30
];
int
i
=
30
-
1
,
count
=
0
;
boolean
negative
;
if
(
x
<
0
)
{
negative
=
true
;
x
=
-
x
;
}
else
{
negative
=
false
;
}
for
(;
i
>=
0
;
i
--)
{
ch
[
i
]
=
(
char
)
(
'0'
+
(
x
%
10
));
x
/=
10
;
count
++;
if
(
x
==
0
)
{
break
;
}
}
if
(
negative
)
{
ch
[--
i
]
=
'-'
;
count
++;
}
return
new
String
(
ch
,
i
,
count
);
}
}
h2/src/tools/org/h2/java/lang/String.java
浏览文件 @
167230d2
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
java
.
lang
;
import
org.h2.java.Ignore
;
import
org.h2.java.Local
;
/* c:
...
...
@@ -37,7 +38,7 @@ protected:
jint refCount;
public:
RefBase() {
refCount =
1
;
refCount =
0
;
}
void reference() {
refCount++;
...
...
@@ -47,6 +48,8 @@ public:
delete this;
}
}
virtual ~RefBase() {
}
};
template <class T> class ptr {
T* pointer;
...
...
@@ -137,6 +140,7 @@ public class String {
/**
* The character array.
*/
@Local
char
[]
chars
;
private
int
hash
;
...
...
@@ -152,18 +156,17 @@ public class String {
}
public
int
hashCode
()
{
if
(
hash
==
0
)
{
if
(
chars
.
length
==
0
)
{
return
0
;
}
int
h
=
0
;
for
(
char
c
:
chars
)
{
h
=
h
*
31
+
c
;
int
h
=
hash
;
if
(
h
==
0
)
{
int
size
=
chars
.
length
;
if
(
size
!=
0
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
h
=
h
*
31
+
chars
[
i
];
}
hash
=
h
;
}
hash
=
h
;
return
h
;
}
return
h
ash
;
return
h
;
}
/**
...
...
h2/src/tools/org/h2/java/lang/System.java
浏览文件 @
167230d2
...
...
@@ -56,4 +56,21 @@ public class System {
java
.
lang
.
System
.
arraycopy
(
src
,
srcPos
,
dest
,
destPos
,
length
);
}
/**
* Get the current time in milliseconds since 1970-01-01.
*
* @return the milliseconds
*/
public
static
long
nanoTime
()
{
/* c:
#if CLOCKS_PER_SEC == 1000000
return (jlong) clock() * 1000;
#else
return (jlong) clock() * 1000000 / CLOCKS_PER_SEC;
#endif
*/
// c: return;
return
java
.
lang
.
System
.
nanoTime
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论