Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3f377668
提交
3f377668
authored
3月 13, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A Java parser / Java to C converter.
上级
cf69bd38
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
142 行增加
和
91 行删除
+142
-91
ClassObj.java
h2/src/tools/org/h2/java/ClassObj.java
+10
-5
Expr.java
h2/src/tools/org/h2/java/Expr.java
+4
-3
JavaParser.java
h2/src/tools/org/h2/java/JavaParser.java
+77
-61
Statement.java
h2/src/tools/org/h2/java/Statement.java
+2
-2
Test.java
h2/src/tools/org/h2/java/Test.java
+3
-0
TestApp.java
h2/src/tools/org/h2/java/TestApp.java
+7
-2
String.java
h2/src/tools/org/h2/java/lang/String.java
+39
-16
System.java
h2/src/tools/org/h2/java/lang/System.java
+0
-2
没有找到文件。
h2/src/tools/org/h2/java/ClassObj.java
浏览文件 @
3f377668
...
...
@@ -56,7 +56,7 @@ public class ClassObj {
ArrayList
<
Statement
>
nativeCode
=
new
ArrayList
<
Statement
>();
String
id
;
int
id
;
/**
* Add a method.
...
...
@@ -87,9 +87,9 @@ public class ClassObj {
public
String
toString
()
{
if
(
isPrimitive
)
{
return
name
;
return
"j"
+
name
;
}
return
"struct "
+
name
;
return
name
;
}
}
...
...
@@ -127,7 +127,7 @@ class MethodObj {
/**
* The parameter list.
*/
ArrayList
<
FieldObj
>
parameters
=
new
ArrayList
<
FieldObj
>();
LinkedHashMap
<
String
,
FieldObj
>
parameters
=
new
LinkedHashMap
<
String
,
FieldObj
>();
/**
* Whether this method is final.
...
...
@@ -143,6 +143,11 @@ class MethodObj {
* Whether this method is native.
*/
boolean
isNative
;
/**
* Whether this is a constructor.
*/
boolean
isConstructor
;
}
/**
...
...
@@ -209,7 +214,7 @@ class Type {
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
JavaParser
.
toC
(
type
.
name
));
buff
.
append
(
JavaParser
.
toC
(
type
.
toString
()
));
if
(!
type
.
isPrimitive
)
{
buff
.
append
(
"*"
);
}
...
...
h2/src/tools/org/h2/java/Expr.java
浏览文件 @
3f377668
...
...
@@ -41,7 +41,7 @@ class CallExpr implements Expr {
if
(
className
!=
null
)
{
buff
.
append
(
JavaParser
.
toC
(
className
+
"."
+
name
)).
append
(
"("
);
}
else
{
buff
.
append
(
JavaParser
.
toC
(
expr
.
getType
().
type
.
name
+
"."
+
name
)).
append
(
"("
);
buff
.
append
(
JavaParser
.
toC
(
expr
.
getType
().
type
+
"."
+
name
)).
append
(
"("
);
}
int
i
=
0
;
if
(
expr
!=
null
)
{
...
...
@@ -198,7 +198,7 @@ class StringExpr implements Expr {
String
text
;
public
String
toString
()
{
return
"
\""
+
javaEncode
(
text
)
+
"\"
"
;
return
"
STRING(\""
+
javaEncode
(
text
)
+
"\")
"
;
}
public
Type
getType
()
{
...
...
@@ -282,7 +282,8 @@ class VariableExpr implements Expr {
}
if
(
field
!=
null
)
{
if
(
field
.
isStatic
)
{
buff
.
append
(
JavaParser
.
toC
(
field
.
type
.
type
.
name
+
"."
+
field
.
name
));
// buff.append(JavaParser.toC(field.type.type.name + "." + field.name));
buff
.
append
(
JavaParser
.
toC
(
name
));
}
else
{
buff
.
append
(
field
.
name
);
}
...
...
h2/src/tools/org/h2/java/JavaParser.java
浏览文件 @
3f377668
差异被折叠。
点击展开。
h2/src/tools/org/h2/java/Statement.java
浏览文件 @
3f377668
...
...
@@ -77,7 +77,7 @@ class SwitchStatement implements Statement {
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"switch ("
).
append
(
expr
).
append
(
") {\n"
);
for
(
int
i
=
0
;
i
<
cases
.
size
();
i
++)
{
buff
.
append
(
"case
:
"
+
cases
.
get
(
i
)
+
":\n"
);
buff
.
append
(
"case "
+
cases
.
get
(
i
)
+
":\n"
);
buff
.
append
(
blocks
.
get
(
i
).
toString
());
}
if
(
defaultBlock
!=
null
)
{
...
...
@@ -148,7 +148,7 @@ class ForStatement implements Statement {
Type
it
=
iterable
.
getType
();
if
(
it
!=
null
&&
it
.
arrayLevel
>
0
)
{
String
idx
=
"i_"
+
iterableVariable
;
buff
.
append
(
"int "
+
idx
+
" = 0; "
+
idx
+
" < LEN("
+
iterable
+
"); "
+
idx
+
"++"
);
buff
.
append
(
"int "
+
idx
+
" = 0; "
+
idx
+
" < LEN
GTH
("
+
iterable
+
"); "
+
idx
+
"++"
);
buff
.
append
(
") {\n"
);
buff
.
append
(
JavaParser
.
indent
(
iterableType
+
" "
+
iterableVariable
+
" = "
+
iterable
+
"["
+
idx
+
"];\n"
));
buff
.
append
(
block
.
toString
()).
append
(
"}"
);
...
...
h2/src/tools/org/h2/java/Test.java
浏览文件 @
3f377668
...
...
@@ -26,6 +26,9 @@ public class Test extends TestBase {
}
public
void
test
()
throws
IOException
{
// gcc --std=c99 test.c
// (for "mixed declarations and code")
// not supported yet:
// HexadecimalFloatingPointLiteral
// int x()[] { return null; }
...
...
h2/src/tools/org/h2/java/TestApp.java
浏览文件 @
3f377668
...
...
@@ -9,10 +9,15 @@ package org.h2.java;
/**
* A test application.
*/
/// #include <stdio.h>
public
class
TestApp
{
// private static final int FINAL_VALUE = 10;
/* c:
int main(char** args) {
org_h2_java_TestApp_main(null);
}
*/
/**
* Run this application.
...
...
h2/src/tools/org/h2/java/lang/String.java
浏览文件 @
3f377668
...
...
@@ -2,17 +2,33 @@ package org.h2.java.lang;
/* c:
#define boolean int
#define LENGTH(a) (*(((int*)(a))-1))
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define jvoid void
#define jboolean int8_t
#define jbyte int8_t
#define jchar int16_t
#define jint int32_t
#define jlong int64_t
#define jfloat float
#define jdouble double
#define true 1
#define false 0
#define null 0
#define LENGTH(a) (*(((jint*)(a))-1))
#define NEW_ARRAY(size, length) new_array(0, size, length)
#define NEW_OBJ_ARRAY(length) new_array(1, sizeof(void*), length)
#define NEW_OBJ(type
, size) new_object(type, sizeof(struct typ
e))
#define NEW_OBJ(type
Id, typeName) new_object(typeId, sizeof(struct typeNam
e))
#define SET(variable, p) set_object(variable, p)
#define STRING(s) ((java_lang_String*) string(s))
void* new_array(
int object, int size,
int length);
void* new_object(
int type,
int size);
void* new_array(
jint object, jint size, j
int length);
void* new_object(
jint type, j
int size);
void* set_object(void** target, void* o);
void* string(char* s);
*/
...
...
@@ -23,38 +39,45 @@ public class String {
/* c:
#include <stdlib.h>
void* new_array(int object, int size, int length) {
int count = sizeof(int) * 2 + size * length;
int* m = (int*) calloc(1, count);
void* new_array(jint object, jint size, jint length) {
int count = sizeof(jint) * 2 + size * length;
int* m = (jint*) calloc(1, count);
*m = object << 31 + length;
*(m+1) = 1;
return m + 2;
}
void* new_object(
int type,
int size) {
int count = sizeof(int) * 2 + size;
int* m = (int*) calloc(1, count);
void* new_object(
jint type, j
int size) {
int count = sizeof(
j
int) * 2 + size;
int* m = (
j
int*) calloc(1, count);
*m = type;
*(m+1) = 1;
return m + 2;
}
void* set_object(void** target, void* o) {
int* m = (int*) target;
int* m = (
j
int*) target;
if (*(m - 2) == 1) {
free(m - 1);
} else {
(*(m - 2))--;
}
*target = o;
m = (int*) target;
m = (
j
int*) target;
if (o != 0) {
(*(m - 2))++;
}
}
void* string(char* s) {
int len = strlen(s);
jchar* chars = NEW_ARRAY(sizeof(char), 1 * LENGTH(chars));
for (int i = 0; i < len; i++) {
chars[i] = s[i];
}
return java_lang_String_init_obj(chars);
}
*/
private
char
[]
chars
;
...
...
h2/src/tools/org/h2/java/lang/System.java
浏览文件 @
3f377668
...
...
@@ -7,8 +7,6 @@ import java.io.PrintStream;
*/
public
class
System
{
// c: #include <stdio>
/**
* The stdout stream.
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论