Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
031d8eff
Commit
031d8eff
authored
May 14, 2013
by
Anders Blomdell
Browse files
Corrected C# code generation to correctly handle arrays of arrays.
parent
4cc58e6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
compiler/CS_CodeGen.jrag
View file @
031d8eff
...
...
@@ -429,11 +429,11 @@ aspect CS_Class {
}
public void ArrayType.CS_emitEncoder(CS_env env, String name) {
env.print_block_begin();
int baseDepth = env.getDepth();
for (int i = 0 ; i < getNumExp() ; i++) {
String limit = getExp(i).CS_emitEncoder(env,
name + ".GetLength(" + i + ")");
env.print_block_begin();
env.println("int i_" + (baseDepth + i) + "_max = " + limit + ";");
}
String index = null;
...
...
@@ -448,8 +448,8 @@ aspect CS_Class {
getType().CS_emitEncoder(env, name + "[" + index + "]");
for (int i = 0 ; i < getNumExp() ; i++) {
env.print_for_end();
env.print_block_end();
}
env.print_block_end();
}
public String Exp.CS_emitEncoder(CS_env env, String name) {
...
...
@@ -539,7 +539,7 @@ aspect CS_Class {
}
env.print("i_" + (baseDepth + i) + "_max");
}
env.print
ln
("]");
env.print("]");
getType().CS_emitTypeSuffix(env);
env.println(";");
...
...
@@ -592,22 +592,6 @@ aspect CS_Class {
}
}
public void Type.CS_emitNew(CS_env env, String size) {
throw new Error(this.getClass().getName() +
".CS_emitNew(CS_env env, String size)" +
" not declared");
}
public void ArrayType.CS_emitNew(CS_env env, String size, int depth) {
env.print("new ");
getType().CS_emitTypePrefix(env);
env.print("[" + size + "]");
getType().CS_emitTypeSuffix(env);
for (int i = 1 ; i < depth ; i++) {
env.print("[]");
}
}
public void Type.CS_emitTypePrefix(CS_env env) {
throw new Error(this.getClass().getName() +
".CS_emitTypePrefix(CS_env env)" +
...
...
@@ -647,12 +631,12 @@ aspect CS_Class {
}
public void ArrayType.CS_emitTypeSuffix(CS_env env){
getType().CS_emitTypeSuffix(env);
env.print("[");
for (int i = 1 ; i < getNumExp() ; i++) {
env.print(",");
}
env.print("]");
getType().CS_emitTypeSuffix(env);
}
public boolean Type.CS_needInstance() {
...
...
@@ -703,7 +687,7 @@ aspect CS_Class {
public void StructType.CS_emitInstance(CS_env env) {
if (CS_Depth() > 0) {
env.println("public
static
class " + CS_structName() + " {");
env.println("public class " + CS_structName() + " {");
env.indent();
}
for (int i = 0 ; i < getNumField() ; i++) {
...
...
@@ -751,12 +735,13 @@ aspect CS_Class {
}
public void ArrayType.CS_emitType(CS_env env){
getType().CS_emitType(env);
getType().CS_emitType
Prefix
(env);
env.print("[");
for (int i = 1 ; i < getNumExp() ; i++) {
env.print(",");
}
env.print("]");
getType().CS_emitTypeSuffix(env);
}
public void StructType.CS_emitType(CS_env env){
...
...
test/Makefile
View file @
031d8eff
TESTS
=
basic simple
TESTS
=
basic simple
nested
LABCOMM_JAR
=
../compiler/labComm.jar
LABCOMM
=
java
-jar
$(LABCOMM_JAR)
...
...
test/nested.lc
View file @
031d8eff
typedef int int_array_ss[1][_, 3, _][5];
sample struct { int aa; boolean bb; int_array_ss ias; } struct_array_ss[1][_][_];
sample int s_array_array_array[1][1, 1][1, 1, 1];
sample struct {
int b[1][1, 1];
int c[1][_, 1, _][_,_];
} struct_array_ss[1];
typedef int int_t;
typedef int int_array_t[1][2][3,4];
typedef struct { int a; } struct_t;
...
...
@@ -18,3 +20,4 @@ sample int_array_t int_array_t_s;
sample struct_t struct_t_s;
sample struct_array_t struct_array_t_s;
sample struct_struct_t struct_struct_t_s;
test/test_encoder_decoder.py
View file @
031d8eff
...
...
@@ -142,7 +142,7 @@ def get_signatures(path):
with
fp
as
fp
:
m
=
imp
.
load_module
(
'signatures'
,
fp
,
pathname
,
description
)
pass
return
m
.
s
ignatures
return
m
.
s
ample
class
Test
:
...
...
@@ -250,46 +250,4 @@ if __name__ == "__main__":
for
lc
in
args
.
lc
:
run
(
lc
,
args
)
pass
exit
(
0
)
print
os
.
getcwd
(),
sys
.
argv
if
not
os
.
path
.
exists
(
"gen"
):
os
.
makedirs
(
"gen"
)
if
len
(
sys
.
argv
)
>
1
:
files
=
[
s
[
0
:
-
3
]
for
s
in
sys
.
argv
[
1
:]
if
s
.
endswith
(
'.lc'
)]
else
:
files
=
[
s
[
0
:
-
3
]
for
s
in
os
.
listdir
(
"."
)
if
s
.
endswith
(
'.lc'
)]
for
f
in
files
:
cscode
.
test_program
(
"gen/csharp/test_%s.cs"
%
f
,
"gen/%s.typeinfo"
%
f
)
sys
.
path
.
insert
(
0
,
"../lib/python"
)
import
labcomm
;
sys
.
path
.
insert
(
0
,
"gen/python"
)
for
f
in
files
:
print
f
h
=
hexwriter
(
"gen/%s.vec"
%
f
)
encoder
=
labcomm
.
Encoder
(
h
)
signatures
=
[]
i
=
__import__
(
f
)
for
k
in
dir
(
i
):
v
=
getattr
(
i
,
k
)
try
:
s
=
v
.
signature
except
:
s
=
None
if
s
:
signatures
.
append
(
s
)
encoder
.
add_decl
(
s
)
for
s
in
signatures
:
for
e
in
generate
(
s
):
encoder
.
encode
(
e
[
1
],
s
)
h
.
flush
()
ccode
.
gen
(
f
,
signatures
)
pass
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment