Skip to content
Snippets Groups Projects
Commit 2519db57 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

WiP: adding annotations to signature

parent 00d6182c
No related branches found
No related tags found
No related merge requests found
......@@ -495,12 +495,19 @@ aspect Java_Class {
env.println();
}
public void TypeInstance.Java_emitAnnotationComment(Java_env env) {
if(hasAnnotations()) {
env.println("// "+getAnnotationString());
}
}
//XXX TODO: refactor: split into a static class ("TypeDefSingleton"?)and a (smaller) dispatcher
public void Decl.Java_emitDispatcher(Java_env env, boolean isSample) {
// String genericStr = ""; //env.versionHasMetaData()?"<"+getName()+">":"";
String genericStr = "<"+getName()+">";
env.println("private static Dispatcher dispatcher = new Dispatcher();");
env.println();
getTypeInstance().Java_emitAnnotationComment(env);
env.println("public SampleDispatcher getDispatcher() {");
env.indent();
env.println("return dispatcher;");
......
import java.util.*;
aspect Annotations {
aspect SigAnnotations {
inh Decl TypeInstance.parentDecl();
......@@ -20,6 +20,9 @@ aspect Annotations {
public String DocString.toString() {
return "\""+getValue()+"\"";
}
syn boolean ASTNode.isTypeInstance() = false;
eq TypeInstance.isTypeInstance() = true;
}
aspect Signature {
......@@ -59,14 +62,21 @@ aspect Signature {
}
public void Decl.debugAnnotations() {
System.out.println("Decl.annotations: " + getAnnotationString());
getTypeInstance().debugAnnotations(getName());
}
public void TypeInstance.debugAnnotations(String context) {
if(hasAnnotations()){
System.out.println(context+".annotations: " + getAnnotationString());
} else {
System.out.println(context+": NO ANNOTATIONS ");
}
}
// TESTING END
syn nta Signature Decl.getSignature() {
debugAnnotations();
SignatureList sl = new SignatureList();
genSigLineForDecl(sl, true);
genSigLineForDecl(sl, true, this);
SignatureList fsl = new SignatureList();
flatSignature(fsl);
Signature sig = new Signature();
......@@ -200,79 +210,88 @@ aspect Signature {
}
public void ASTNode.genSigLineForDecl(SignatureList list, boolean decl) {
public void ASTNode.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
throw new Error(this.getClass().getName() +
".genSigLineForDecl(SignatureList list)" +
" not declared");
}
public void TypeDecl.genSigLineForDecl(SignatureList list, boolean decl) {
public void TypeInstance.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
debugAnnotations(this.getName());
getDataType().genSigLineForDecl(list, decl, this);
}
public void TypeDecl.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
//TODO intent
if(decl){
getDataType().genSigLineForDecl(list, decl);
getTypeInstance().genSigLineForDecl(list, decl, this);
}else{
list.addTypeRef(this, "//TODO (from list.addTypeRef)");
}
}
public void SampleDecl.genSigLineForDecl(SignatureList list, boolean decl) {
getDataType().genSigLineForDecl(list, decl);
public void SampleDecl.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
//TODO intent
getTypeInstance().genSigLineForDecl(list, decl, this);
}
public void VoidType.genSigLineForDecl(SignatureList list, boolean decl) {
public void VoidType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(LABCOMM_STRUCT, "void");
list.addInt(0, null);
}
// public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) {
// public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
// list.addInt(LABCOMM_SAMPLE_REF, "sample");
// }
public void PrimType.genSigLineForDecl(SignatureList list, boolean decl) {
public void PrimType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(getToken(), null);
}
/* For UserType, the decl parameter is ignored, as a UserType
* will always be a TypeRef
*/
public void UserType.genSigLineForDecl(SignatureList list, boolean decl) {
public void UserType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
TypeDecl thet = lookupType(getName());
list.addTypeRef(thet, null);
}
public void ArrayType.genSigLineForDecl(SignatureList list, boolean decl) {
public void ArrayType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(LABCOMM_ARRAY, signatureComment());
list.indent();
list.addInt(getNumExp(), null);
for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).genSigLineForDecl(list, false);
getExp(i).genSigLineForDecl(list, false, null);
}
getDataType().genSigLineForDecl(list, false);
getDataType().genSigLineForDecl(list, false, null);
list.unindent();
list.add(null, "}");
}
public void StructType.genSigLineForDecl(SignatureList list, boolean decl) {
public void StructType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(LABCOMM_STRUCT, "struct { " + getNumField() + " fields");
list.indent();
list.addInt(getNumField(), null);
for (int i = 0 ; i < getNumField() ; i++) {
getField(i).genSigLineForDecl(list, false);
getField(i).genSigLineForDecl(list, false, inst);
}
list.unindent();
list.add(null, "}");
}
public void Field.genSigLineForDecl(SignatureList list, boolean decl) {
public void Field.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addString(getName(), signatureComment());
getDataType().genSigLineForDecl(list, decl);
super.genSigLineForDecl(list, decl, inst);
//TODOintent
//getDataType().genSigLineForDecl(list, decl, inst);
}
public void IntegerLiteral.genSigLineForDecl(SignatureList list, boolean decl) {
public void IntegerLiteral.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(Integer.parseInt(getValue()), null);
}
public void VariableSize.genSigLineForDecl(SignatureList list, boolean decl) {
public void VariableSize.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(0, null);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment