Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Klarén
LabComm
Commits
3978f22a
Commit
3978f22a
authored
10 years ago
by
Sven Gestegård Robertz
Browse files
Options
Downloads
Patches
Plain Diff
cherry-pick fde3673cc
parent
db394539
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
compiler/DeclNames.jrag
+7
-0
7 additions, 0 deletions
compiler/DeclNames.jrag
compiler/Java_CodeGen.jrag
+112
-17
112 additions, 17 deletions
compiler/Java_CodeGen.jrag
examples/simple/simple.lc
+9
-0
9 additions, 0 deletions
examples/simple/simple.lc
lib/java/Makefile
+1
-0
1 addition, 0 deletions
lib/java/Makefile
with
129 additions
and
17 deletions
compiler/DeclNames.jrag
+
7
−
0
View file @
3978f22a
...
@@ -4,4 +4,11 @@ aspect DeclNames {
...
@@ -4,4 +4,11 @@ aspect DeclNames {
inh String Field.declName();
inh String Field.declName();
eq StructType.getField(int i).declName() = declName();
eq StructType.getField(int i).declName() = declName();
//TODO: aspect should be renamed to parent-something
inh Decl Type.parentDecl();
inh Decl Field.parentDecl();
eq Decl.getType().parentDecl() = this;
eq StructType.getField(int i).parentDecl() = parentDecl();
}
}
This diff is collapsed.
Click to expand it.
compiler/Java_CodeGen.jrag
+
112
−
17
View file @
3978f22a
...
@@ -206,6 +206,21 @@ aspect Java_CodeGen {
...
@@ -206,6 +206,21 @@ aspect Java_CodeGen {
public void Program.J_gen(PrintStream ps, String pack, int version) throws IOException {
public void Program.J_gen(PrintStream ps, String pack, int version) throws IOException {
Java_env env;
Java_env env;
/*
// Registration class
env = new Java_env(version, ps);
if (pack != null && pack.length() > 0) {
env.println("package " + pack + ";");
}
env.println("public class LabCommRegister {");
env.println();
env.indent();
Java_emitTypeRegister(env);
env.unindent();
env.println();
env.println("}");
// env.close();
*/
env = new Java_env(version, ps);
env = new Java_env(version, ps);
for (int i = 0; i < getNumDecl(); i++) {
for (int i = 0; i < getNumDecl(); i++) {
Decl d = getDecl(i);
Decl d = getDecl(i);
...
@@ -221,6 +236,21 @@ aspect Java_CodeGen {
...
@@ -221,6 +236,21 @@ aspect Java_CodeGen {
public void Program.J_gen(String dir, String pack, int version) throws IOException {
public void Program.J_gen(String dir, String pack, int version) throws IOException {
Java_env env;
Java_env env;
/*
// Registration class
env = new Java_env(version, new File(dir, "LabCommRegister.java"));
if (pack != null && pack.length() > 0) {
env.println("package " + pack + ";");
}
env.println("public class LabCommRegister {");
env.println();
env.indent();
Java_emitTypeRegister(env);
env.unindent();
env.println();
env.println("}");
env.close();
*/
for (int i = 0; i < getNumDecl(); i++) {
for (int i = 0; i < getNumDecl(); i++) {
Decl d = getDecl(i);
Decl d = getDecl(i);
try {
try {
...
@@ -256,6 +286,57 @@ aspect Java_CodeGen {
...
@@ -256,6 +286,57 @@ aspect Java_CodeGen {
}
}
}
}
}
}
}
aspect Java_Register {
public void Program.Java_emitTypeRegister(Java_env env) {
env.println("static void register(Encoder e) {");
env.indent();
for (int i = 0; i < getNumDecl(); i++) {
getDecl(i).Java_emitTypeRegister(env);
}
env.unindent();
env.println("}");
}
public void Decl.Java_emitTypeRegister(Java_env env) {
throw new Error(this.getClass().getName() +
".Java_emitTypeRegister(Java_env env)" +
" not declared");
}
public void SampleDecl.Java_emitTypeRegister(Java_env env) {
env.println(getName() + ".register(e);");
}
public void TypeDecl.Java_emitTypeRegister(Java_env env) {
// TODO
env.println("//TODO " + getName() + ".register(e);");
}
}
aspect User_Types {
syn String Type.getTypeName();
eq Type.getTypeName() = getClass().getName();
eq PrimType.getTypeName() = getName();
eq UserType.getTypeName() = getName();
syn boolean Type.isUserType();
eq Type.isUserType() = false;
eq UserType.isUserType() = true;
coll Set<Decl> Decl.references() [new HashSet<Decl>()] with add;
Field contributes ((UserType)getType()).decl()
when parentDecl() != null && getType().isUserType()
to Decl.references()
for parentDecl();
}
}
aspect Java_Class {
aspect Java_Class {
...
@@ -267,46 +348,46 @@ aspect Java_Class {
...
@@ -267,46 +348,46 @@ aspect Java_Class {
}
}
public void TypeDecl.Java_emitClass(Java_env env, String pack) {
public void TypeDecl.Java_emitClass(Java_env env, String pack) {
if (getType().Java_needInstance()) {
// Hackish prettyprint preamble
// Hackish prettyprint preamble
env.println("/* ");
env.println("/* ");
pp(env.getPrintStream());
pp(env.getPrintStream());
if( !references().isEmpty() ) {
Iterator<Decl> it = references().iterator();
while(it.hasNext()) {
Decl t = it.next();
env.println(" //Depends on "+t.getName() + " (" + t +") " );
}
} else {
env.println(" //no more deps ");
}
env.println("*/");
env.println("*/");
if (pack != null && pack.length() > 0) {
if (pack != null && pack.length() > 0) {
env.println("package " + pack + ";");
env.println("package " + pack + ";");
}
}
env.println("import java.io.IOException;");
env.println("import se.lth.control.labcomm"+env.verStr+".SampleType;");
env.println("import se.lth.control.labcomm"+env.verStr+".SampleType;");
if (getType().Java_needInstance()) {
env.println("import java.io.IOException;");
env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;");
env.println();
env.println();
}
//For types not needing an instance, currently just an empty class is generated
env.println("public class " + getName() + " implements SampleType {");
env.println("public class " + getName() + " implements SampleType {");
env.println();
env.println();
if (getType().Java_needInstance()) {
env.indent();
env.indent();
getType().Java_emitInstance(env);
getType().Java_emitInstance(env);
Java_emitEncoder(env);
Java_emitEncoder(env);
Java_emitDecoder(env);
Java_emitDecoder(env);
}
env.unindent();
env.unindent();
env.println("}");
env.println("}");
}
}
}
// TODO: ?
// Code snippet for making samples of user types extend their type
// currently commented out. Is this a good idea?
//
// syn String Type.getTypeName();
// eq Type.getTypeName() = getClass().getName();
// eq PrimType.getTypeName() = getName();
// eq UserType.getTypeName() = getName();
// syn boolean Type.isUserType();
// eq Type.isUserType() = false;
// eq UserType.isUserType() = true;
//
// plus use some lines down
public void SampleDecl.Java_emitClass(Java_env env, String pack) {
public void SampleDecl.Java_emitClass(Java_env env, String pack) {
env.println("/* ");
env.println("/* ");
...
@@ -325,6 +406,10 @@ aspect Java_Class {
...
@@ -325,6 +406,10 @@ aspect Java_Class {
env.println("import se.lth.control.labcomm"+env.verStr+".Sample;");
env.println("import se.lth.control.labcomm"+env.verStr+".Sample;");
env.println();
env.println();
env.print("public class " + getName());
env.print("public class " + getName());
// TODO: ?
// Code for making samples of user types extend their type
// currently commented out. Is this a good idea or not?
//
// if(getType().isUserType()) {
// if(getType().isUserType()) {
// env.print(" extends "+getType().getTypeName());
// env.print(" extends "+getType().getTypeName());
// }
// }
...
@@ -350,6 +435,16 @@ aspect Java_Class {
...
@@ -350,6 +435,16 @@ aspect Java_Class {
env.println("public static void register(Encoder e) throws IOException {");
env.println("public static void register(Encoder e) throws IOException {");
env.indent();
env.indent();
if( !references().isEmpty() ) {
Iterator<Decl> it = references().iterator();
while(it.hasNext()) {
Decl t = it.next();
env.println(" //Depends on "+t.getName() + " (" + t +") " );
}
} else {
env.println(" //no more deps ");
}
env.println("e.register(new Dispatcher());");
env.println("e.register(new Dispatcher());");
env.unindent();
env.unindent();
env.println("}");
env.println("}");
...
...
This diff is collapsed.
Click to expand it.
examples/simple/simple.lc
+
9
−
0
View file @
3978f22a
...
@@ -6,6 +6,15 @@ typedef struct {
...
@@ -6,6 +6,15 @@ typedef struct {
sample TwoInts theTwoInts;
sample TwoInts theTwoInts;
sample TwoInts anotherTwoInts;
sample TwoInts anotherTwoInts;
typedef int AnInt;
sample AnInt theInt;
sample struct {
TwoInts ti1;
TwoInts ti2;
} twoTwoInts;
sample struct {
sample struct {
int x;
int x;
string s;
string s;
...
...
This diff is collapsed.
Click to expand it.
lib/java/Makefile
+
1
−
0
View file @
3978f22a
...
@@ -9,6 +9,7 @@ MODULES=Constant \
...
@@ -9,6 +9,7 @@ MODULES=Constant \
Sample
\
Sample
\
SampleDispatcher
\
SampleDispatcher
\
SampleHandler
\
SampleHandler
\
Type
\
SampleType
\
SampleType
\
Writer
\
Writer
\
WriterWrapper
WriterWrapper
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment