Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
24ed565b
提交
24ed565b
authored
3月 26, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Java to C converter.
上级
92a8cfac
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
224 行增加
和
114 行删除
+224
-114
ClassObj.java
h2/src/tools/org/h2/java/ClassObj.java
+15
-8
Expr.java
h2/src/tools/org/h2/java/Expr.java
+83
-18
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+63
-45
Test.java
h2/src/tools/org/h2/java/Test.java
+3
-0
TestApp.java
h2/src/tools/org/h2/java/TestApp.java
+0
-38
Integer.java
h2/src/tools/org/h2/java/lang/Integer.java
+27
-0
String.java
h2/src/tools/org/h2/java/lang/String.java
+5
-0
StringBuilder.java
h2/src/tools/org/h2/java/lang/StringBuilder.java
+28
-5
没有找到文件。
h2/src/tools/org/h2/java/ClassObj.java
浏览文件 @
24ed565b
...
...
@@ -28,7 +28,7 @@ public class ClassObj {
/**
* The fully qualified class name.
*/
String
n
ame
;
String
classN
ame
;
/**
* Whether this is an interface.
...
...
@@ -126,9 +126,9 @@ public class ClassObj {
public
String
toString
()
{
if
(
isPrimitive
)
{
return
"j"
+
n
ame
;
return
"j"
+
classN
ame
;
}
return
n
ame
;
return
classN
ame
;
}
/**
...
...
@@ -141,7 +141,7 @@ public class ClassObj {
MethodObj
getMethod
(
String
find
,
ArrayList
<
Expr
>
args
)
{
ArrayList
<
MethodObj
>
list
=
methods
.
get
(
find
);
if
(
list
==
null
)
{
throw
new
RuntimeException
(
"Method not found: "
+
name
);
throw
new
RuntimeException
(
"Method not found: "
+
className
+
" "
+
find
);
}
if
(
list
.
size
()
==
1
)
{
return
list
.
get
(
0
);
...
...
@@ -155,9 +155,6 @@ public class ClassObj {
for
(
FieldObj
f
:
m
.
parameters
.
values
())
{
Expr
a
=
args
.
get
(
i
++);
Type
t
=
a
.
getType
();
if
(
t
==
null
)
{
System
.
out
.
println
(
a
.
getType
());
}
if
(!
t
.
equals
(
f
.
type
))
{
match
=
false
;
break
;
...
...
@@ -167,7 +164,17 @@ public class ClassObj {
return
m
;
}
}
throw
new
RuntimeException
(
"Method not found: "
+
name
);
throw
new
RuntimeException
(
"Method not found: "
+
className
);
}
/**
* Get the field with the given name.
*
* @param name the field name
* @return the field
*/
FieldObj
getField
(
String
name
)
{
return
instanceFields
.
get
(
name
);
}
}
...
...
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
24ed565b
...
...
@@ -27,7 +27,8 @@ class CallExpr implements Expr {
final
boolean
isStatic
;
final
String
className
;
final
String
name
;
ClassObj
classObj
;
private
ClassObj
classObj
;
private
MethodObj
method
;
CallExpr
(
JavaParser
context
,
Expr
expr
,
String
className
,
String
name
,
boolean
isStatic
)
{
this
.
context
=
context
;
...
...
@@ -37,19 +38,26 @@ class CallExpr implements Expr {
this
.
isStatic
=
isStatic
;
}
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
private
void
initMethod
()
{
if
(
method
!=
null
)
{
return
;
}
if
(
className
!=
null
)
{
classObj
=
context
.
getClassObj
(
className
);
}
else
{
classObj
=
expr
.
getType
().
classObj
;
}
MethodObj
m
=
classObj
.
getMethod
(
name
,
args
);
method
=
classObj
.
getMethod
(
name
,
args
);
}
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
String
methodName
;
if
(
m
.
isVirtual
)
{
methodName
=
"virtual_"
+
m
.
name
+
"[CLASS_ID("
+
expr
.
toString
()+
")]"
;
initMethod
();
if
(
method
.
isVirtual
)
{
methodName
=
"virtual_"
+
method
.
name
+
"[CLASS_ID("
+
expr
.
toString
()+
")]"
;
}
else
{
methodName
=
JavaParser
.
toC
(
classObj
.
toString
()
+
"."
+
m
.
name
);
methodName
=
JavaParser
.
toC
(
classObj
.
toString
()
+
"."
+
m
ethod
.
name
);
}
buff
.
append
(
methodName
).
append
(
"("
);
int
i
=
0
;
...
...
@@ -68,8 +76,8 @@ class CallExpr implements Expr {
}
public
Type
getType
()
{
// TODO
return
null
;
initMethod
();
return
method
.
returnType
;
}
}
...
...
@@ -168,12 +176,34 @@ class OpExpr implements Expr {
}
else
if
(
op
.
equals
(
"+"
))
{
if
(
left
.
getType
().
isObject
()
||
right
.
getType
().
isObject
())
{
// TODO convert primitive to to String, call toString
return
"STRING_CONCAT("
+
left
+
", "
+
right
+
")"
;
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"java_lang_StringBuilder_toString("
);
buff
.
append
(
"java_lang_StringBuilder_append("
);
buff
.
append
(
"java_lang_StringBuilder_init_obj("
);
buff
.
append
(
convertToString
(
left
));
buff
.
append
(
"), "
);
buff
.
append
(
convertToString
(
right
));
buff
.
append
(
"))"
);
return
buff
.
toString
();
}
}
return
"("
+
left
+
" "
+
op
+
" "
+
right
+
")"
;
}
private
String
convertToString
(
Expr
e
)
{
Type
t
=
e
.
getType
();
if
(
t
.
arrayLevel
>
0
)
{
return
e
.
toString
()
+
".toString()"
;
}
if
(
t
.
classObj
.
isPrimitive
)
{
ClassObj
wrapper
=
context
.
getWrapper
(
t
.
classObj
);
return
JavaParser
.
toC
(
wrapper
+
".toString"
)
+
"("
+
e
.
toString
()
+
")"
;
}
else
if
(
e
.
getType
().
toString
().
equals
(
"java_lang_String*"
))
{
return
e
.
toString
();
}
return
e
.
toString
()
+
".toString()"
;
}
public
Type
getType
()
{
if
(
left
==
null
)
{
return
right
.
getType
();
...
...
@@ -203,14 +233,20 @@ class OpExpr implements Expr {
*/
class
NewExpr
implements
Expr
{
ClassObj
type
;
ClassObj
classObj
;
ArrayList
<
Expr
>
arrayInitExpr
=
new
ArrayList
<
Expr
>();
ArrayList
<
Expr
>
args
=
new
ArrayList
<
Expr
>();
final
JavaParser
context
;
NewExpr
(
JavaParser
context
)
{
this
.
context
=
context
;
}
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
if
(
arrayInitExpr
.
size
()
>
0
)
{
if
(
type
.
isPrimitive
)
{
buff
.
append
(
"NEW_ARRAY(sizeof("
+
type
+
")"
);
if
(
classObj
.
isPrimitive
)
{
buff
.
append
(
"NEW_ARRAY(sizeof("
+
classObj
+
")"
);
buff
.
append
(
", 1 "
);
for
(
Expr
e
:
arrayInitExpr
)
{
buff
.
append
(
"* "
).
append
(
e
);
...
...
@@ -224,14 +260,23 @@ class NewExpr implements Expr {
buff
.
append
(
")"
);
}
}
else
{
buff
.
append
(
"NEW_OBJ("
+
type
.
id
+
", "
+
JavaParser
.
toC
(
type
.
toString
())
+
")"
);
MethodObj
m
=
classObj
.
getMethod
(
"init_obj"
,
args
);
buff
.
append
(
JavaParser
.
toC
(
classObj
.
toString
()
+
"."
+
m
.
name
)).
append
(
"("
);
int
i
=
0
;
for
(
Expr
a
:
args
)
{
if
(
i
++
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
a
);
}
buff
.
append
(
")"
);
}
return
buff
.
toString
();
}
public
Type
getType
()
{
Type
t
=
new
Type
();
t
.
classObj
=
type
;
t
.
classObj
=
classObj
;
t
.
arrayLevel
=
arrayInitExpr
.
size
();
return
t
;
}
...
...
@@ -330,10 +375,16 @@ class VariableExpr implements Expr {
Expr
base
;
FieldObj
field
;
String
name
;
private
final
JavaParser
context
;
VariableExpr
(
JavaParser
context
)
{
this
.
context
=
context
;
}
public
String
toString
()
{
init
();
StringBuilder
buff
=
new
StringBuilder
();
if
(
field
!=
null
&&
"length"
.
equals
(
field
.
name
)
&&
base
!=
null
&&
base
.
getType
()
!=
null
&&
base
.
getType
().
arrayLevel
>
0
)
{
if
(
"length"
.
equals
(
name
)
&&
base
.
getType
().
arrayLevel
>
0
)
{
buff
.
append
(
"LENGTH("
);
buff
.
append
(
base
.
toString
());
buff
.
append
(
")"
);
...
...
@@ -354,10 +405,24 @@ class VariableExpr implements Expr {
return
buff
.
toString
();
}
p
ublic
Type
getType
()
{
p
rivate
void
init
()
{
if
(
field
==
null
)
{
return
null
;
Type
t
=
base
.
getType
();
if
(
t
.
arrayLevel
>
0
)
{
if
(
"length"
.
equals
(
name
))
{
field
=
new
FieldObj
();
field
.
type
=
context
.
getClassObj
(
"int"
).
baseType
;
}
else
{
throw
new
RuntimeException
(
"Unknown array method: "
+
name
);
}
}
else
{
field
=
t
.
classObj
.
getField
(
name
);
}
}
}
public
Type
getType
()
{
init
();
return
field
.
type
;
}
...
...
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
24ed565b
差异被折叠。
点击展开。
h2/src/tools/org/h2/java/Test.java
浏览文件 @
24ed565b
...
...
@@ -60,6 +60,9 @@ public class Test extends TestBase {
JavaParser
parser
=
new
JavaParser
();
parser
.
parse
(
"src/tools/org/h2"
,
"java.lang.Object"
);
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.StringBuilder"
);
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"
);
...
...
h2/src/tools/org/h2/java/TestApp.java
浏览文件 @
24ed565b
...
...
@@ -28,42 +28,4 @@ int main(int argc, char** argv) {
System
.
out
.
println
(
"Hello "
+
"World"
+
1
);
}
public
int
hashCode
()
{
return
1
;
}
/**
* A test method.
*
* @param name ignored
* @param x ignored
* @return ignored
*/
public
int
getName
(
int
name
,
int
x
)
{
System
.
out
.
println
(
"Hello"
);
int
m
=
x
;
// m = FINAL_VALUE;
switch
(
x
)
{
case
1
:
m
=
3
;
m
=
4
;
break
;
default
:
m
=
4
;
m
=
5
;
}
for
(
int
i
=
0
;
i
<
10
;
i
++,
i
--)
{
getName
(
0
,
0
);
}
if
(
m
>
0
)
{
getName
(
2
,
3
);
}
else
{
getName
(
1
,
12
);
}
do
{
getName
(
0
,
0
);
return
name
;
}
while
(
true
);
}
}
h2/src/tools/org/h2/java/lang/Integer.java
0 → 100644
浏览文件 @
24ed565b
/*
* 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.Integer implementation.
*/
public
class
Integer
{
/**
* Convert a value to a String.
*
* @param x the value
* @return the String
*/
public
static
String
toString
(
int
x
)
{
// c: char ch[20];
// c: snprintf(ch, 20, "%d", x);
// c: return string(ch);
return
null
;
}
}
h2/src/tools/org/h2/java/lang/String.java
浏览文件 @
24ed565b
...
...
@@ -115,6 +115,11 @@ void* string(char* s) {
System
.
arraycopy
(
chars
,
0
,
this
.
chars
,
0
,
chars
.
length
);
}
public
String
(
char
[]
chars
,
int
offset
,
int
count
)
{
this
.
chars
=
new
char
[
count
];
System
.
arraycopy
(
chars
,
offset
,
this
.
chars
,
0
,
count
);
}
public
int
hashCode
()
{
if
(
hashCode
==
0
)
{
if
(
chars
.
length
==
0
)
{
...
...
h2/src/tools/org/h2/java/lang/StringBuilder.java
浏览文件 @
24ed565b
...
...
@@ -14,24 +14,47 @@ public class StringBuilder {
private
int
length
;
private
char
[]
buffer
;
public
StringBuilder
(
String
s
)
{
char
[]
chars
=
s
.
chars
;
int
len
=
chars
.
length
;
buffer
=
new
char
[
len
];
System
.
arraycopy
(
chars
,
0
,
buffer
,
0
,
len
);
this
.
length
=
len
;
}
public
StringBuilder
()
{
buffer
=
new
char
[
10
];
}
/**
* Append the given
string
.
* Append the given
value
.
*
* @param
s the string
* @param
x the value
* @return this
*/
public
StringBuilder
append
(
String
s
)
{
int
l
=
s
.
length
();
public
StringBuilder
append
(
String
x
)
{
int
l
=
x
.
length
();
ensureCapacity
(
l
);
System
.
arraycopy
(
s
.
chars
,
0
,
buffer
,
length
,
l
);
System
.
arraycopy
(
x
.
chars
,
0
,
buffer
,
length
,
l
);
length
+=
l
;
return
this
;
}
/**
* Append the given value.
*
* @param x the value
* @return this
*/
public
StringBuilder
append
(
int
x
)
{
append
(
Integer
.
toString
(
x
));
return
this
;
}
public
java
.
lang
.
String
toString
()
{
return
new
java
.
lang
.
String
(
buffer
,
0
,
length
);
}
private
void
ensureCapacity
(
int
plus
)
{
if
(
buffer
.
length
<
length
+
plus
)
{
char
[]
b
=
new
char
[
Math
.
max
(
length
+
plus
,
buffer
.
length
*
2
)];
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论