Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
dcbd0115
提交
dcbd0115
authored
3月 16, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A Java parser / Java to C converter.
上级
49953a3d
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
269 行增加
和
96 行删除
+269
-96
ClassObj.java
h2/src/tools/org/h2/java/ClassObj.java
+75
-7
Expr.java
h2/src/tools/org/h2/java/Expr.java
+61
-10
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+107
-79
TestApp.java
h2/src/tools/org/h2/java/TestApp.java
+1
-0
Arrays.java
h2/src/tools/org/h2/java/util/Arrays.java
+25
-0
没有找到文件。
h2/src/tools/org/h2/java/ClassObj.java
浏览文件 @
dcbd0115
...
...
@@ -34,6 +34,11 @@ public class ClassObj {
*/
boolean
isPrimitive
;
/**
* The primitive type (higher types are more complex)
*/
int
primitiveType
;
/**
* The imported classes.
*/
...
...
@@ -52,7 +57,7 @@ public class ClassObj {
/**
* The methods.
*/
LinkedHashMap
<
String
,
MethodObj
>
methods
=
new
LinkedHashMap
<
String
,
MethodObj
>();
LinkedHashMap
<
String
,
ArrayList
<
MethodObj
>>
methods
=
new
LinkedHashMap
<
String
,
ArrayList
<
MethodObj
>
>();
/**
* The list of native statements.
...
...
@@ -64,16 +69,27 @@ public class ClassObj {
*/
int
id
;
Type
baseType
;
ClassObj
()
{
baseType
=
new
Type
();
baseType
.
classObj
=
this
;
}
/**
* Add a method.
*
* @param method the method
*/
void
addMethod
(
MethodObj
method
)
{
if
(
methods
.
containsKey
(
method
.
name
))
{
throw
new
RuntimeException
(
"Method overloading is not supported: "
+
method
.
name
);
ArrayList
<
MethodObj
>
list
=
methods
.
get
(
method
.
name
);
if
(
list
==
null
)
{
list
=
new
ArrayList
<
MethodObj
>();
methods
.
put
(
method
.
name
,
list
);
}
else
{
method
.
name
=
method
.
name
+
"_"
+
(
list
.
size
()
+
1
);
}
methods
.
put
(
method
.
name
,
method
);
list
.
add
(
method
);
}
/**
...
...
@@ -101,6 +117,38 @@ public class ClassObj {
return
name
;
}
String
getMethodName
(
String
find
,
ArrayList
<
Expr
>
args
)
{
ArrayList
<
MethodObj
>
list
=
methods
.
get
(
find
);
if
(
list
==
null
)
{
return
name
;
}
if
(
list
.
size
()
==
1
)
{
return
list
.
get
(
0
).
name
;
}
for
(
MethodObj
m
:
list
)
{
if
(!
m
.
isVarArgs
&&
m
.
parameters
.
size
()
!=
args
.
size
())
{
continue
;
}
boolean
match
=
true
;
int
i
=
0
;
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
;
}
}
if
(
match
)
{
return
m
.
name
;
}
}
return
name
;
}
}
/**
...
...
@@ -108,6 +156,8 @@ public class ClassObj {
*/
class
MethodObj
{
boolean
isVarArgs
;
/**
* Whether this method is static.
*/
...
...
@@ -219,17 +269,19 @@ class Type {
/**
* The class.
*/
ClassObj
type
;
ClassObj
classObj
;
/**
* The array nesting level. 0 if not an array.
*/
int
arrayLevel
;
boolean
isVarArgs
;
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
JavaParser
.
toC
(
type
.
toString
()));
if
(!
type
.
isPrimitive
)
{
buff
.
append
(
JavaParser
.
toC
(
classObj
.
toString
()));
if
(!
classObj
.
isPrimitive
)
{
buff
.
append
(
"*"
);
}
for
(
int
i
=
0
;
i
<
arrayLevel
;
i
++)
{
...
...
@@ -237,5 +289,21 @@ class Type {
}
return
buff
.
toString
();
}
boolean
isObject
()
{
return
arrayLevel
>
0
||
!
classObj
.
isPrimitive
;
}
public
int
hashCode
()
{
return
toString
().
hashCode
();
}
public
boolean
equals
(
Object
other
)
{
if
(
other
instanceof
Type
)
{
return
this
.
toString
().
equals
(
other
.
toString
());
}
return
false
;
}
}
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
dcbd0115
...
...
@@ -27,6 +27,7 @@ class CallExpr implements Expr {
final
boolean
isStatic
;
final
String
className
;
final
String
name
;
ClassObj
classObj
;
CallExpr
(
JavaParser
context
,
Expr
expr
,
String
className
,
String
name
,
boolean
isStatic
)
{
this
.
context
=
context
;
...
...
@@ -39,10 +40,12 @@ class CallExpr implements Expr {
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
if
(
className
!=
null
)
{
buff
.
append
(
JavaParser
.
toC
(
className
+
"."
+
name
)).
append
(
"("
);
classObj
=
context
.
getClassObj
(
className
);
}
else
{
buff
.
append
(
JavaParser
.
toC
(
expr
.
getType
().
type
+
"."
+
name
)).
append
(
"("
)
;
classObj
=
expr
.
getType
().
classObj
;
}
String
methodName
=
classObj
.
getMethodName
(
name
,
args
);
buff
.
append
(
JavaParser
.
toC
(
classObj
.
toString
()
+
"."
+
methodName
)).
append
(
"("
);
int
i
=
0
;
if
(
expr
!=
null
)
{
buff
.
append
(
expr
.
toString
());
...
...
@@ -110,14 +113,25 @@ class ConditionalExpr implements Expr {
class
LiteralExpr
implements
Expr
{
String
literal
;
private
final
JavaParser
context
;
private
final
String
className
;
private
Type
type
;
public
LiteralExpr
(
JavaParser
context
,
String
className
)
{
this
.
context
=
context
;
this
.
className
=
className
;
}
public
String
toString
()
{
return
literal
;
}
public
Type
getType
()
{
// TODO
return
null
;
if
(
type
==
null
)
{
type
=
new
Type
();
type
.
classObj
=
context
.
getClassObj
(
className
);
}
return
type
;
}
}
...
...
@@ -130,6 +144,11 @@ class OpExpr implements Expr {
Expr
left
;
String
op
;
Expr
right
;
private
final
JavaParser
context
;
OpExpr
(
JavaParser
context
)
{
this
.
context
=
context
;
}
public
String
toString
()
{
if
(
left
==
null
)
{
...
...
@@ -140,13 +159,35 @@ class OpExpr implements Expr {
if
(
op
.
equals
(
">>>"
))
{
// ujint / ujlong
return
"(((u"
+
left
.
getType
()
+
") "
+
left
+
") >> "
+
right
+
")"
;
}
else
if
(
op
.
equals
(
"+"
))
{
if
(
left
.
getType
().
isObject
()
||
right
.
getType
().
isObject
())
{
// TODO convert primitive to to String, call toString
return
"STRING_CONCAT("
+
left
+
", "
+
right
+
")"
;
}
}
return
"("
+
left
+
" "
+
op
+
" "
+
right
+
")"
;
}
public
Type
getType
()
{
// TODO
return
null
;
if
(
left
==
null
)
{
return
right
.
getType
();
}
if
(
right
==
null
)
{
return
left
.
getType
();
}
if
(
op
.
equals
(
"+"
))
{
if
(
left
.
getType
().
isObject
()
||
right
.
getType
().
isObject
())
{
Type
t
=
new
Type
();
t
.
classObj
=
context
.
getClassObj
(
"java.lang.String"
);
return
t
;
}
}
Type
lt
=
left
.
getType
();
Type
rt
=
right
.
getType
();
if
(
lt
.
classObj
.
primitiveType
<
rt
.
classObj
.
primitiveType
)
{
return
rt
;
}
return
lt
;
}
}
...
...
@@ -184,7 +225,7 @@ class NewExpr implements Expr {
public
Type
getType
()
{
Type
t
=
new
Type
();
t
.
type
=
type
;
t
.
classObj
=
type
;
t
.
arrayLevel
=
arrayInitExpr
.
size
();
return
t
;
}
...
...
@@ -201,13 +242,23 @@ class StringExpr implements Expr {
*/
String
text
;
private
final
JavaParser
context
;
private
Type
type
;
StringExpr
(
JavaParser
context
)
{
this
.
context
=
context
;
}
public
String
toString
()
{
return
"STRING(\""
+
javaEncode
(
text
)
+
"\")"
;
}
public
Type
getType
()
{
// TODO
return
null
;
if
(
type
==
null
)
{
type
=
new
Type
();
type
.
classObj
=
context
.
getClassObj
(
"java.lang.String"
);
}
return
type
;
}
/**
...
...
@@ -384,7 +435,7 @@ class ArrayAccessExpr implements Expr {
public
Type
getType
()
{
Type
t
=
new
Type
();
t
.
type
=
base
.
getType
().
type
;
t
.
classObj
=
base
.
getType
().
classObj
;
t
.
arrayLevel
=
base
.
getType
().
arrayLevel
-
1
;
return
t
;
}
...
...
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
dcbd0115
差异被折叠。
点击展开。
h2/src/tools/org/h2/java/TestApp.java
浏览文件 @
dcbd0115
...
...
@@ -6,6 +6,7 @@
*/
package
org
.
h2
.
java
;
/**
* A test application.
*/
...
...
h2/src/tools/org/h2/java/util/Arrays.java
浏览文件 @
dcbd0115
...
...
@@ -23,6 +23,31 @@ public class Arrays {
}
}
/**
* Fill an array with the given value.
*
* @param array the array
* @param x the value
*/
public
static
void
fill
(
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
fill
(
int
[]
array
,
int
x
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
array
[
i
]
=
x
;
}
}
/**
* Fill an array with the given value.
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论