Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Show changes
Commits on Source (576)
Showing
with 4330 additions and 366 deletions
AST
AST/*
LabComm.class
labComm.jar
lib/java/se/lth/control/labcomm/LabComm.class
lib/java/se/lth/control/labcomm/LabCommDecoderChannel.class
lib/java/se/lth/control/labcomm/LabCommDecoder.class
lib/java/se/lth/control/labcomm/LabCommDecoderRegistry.class
lib/java/se/lth/control/labcomm/LabCommDecoderRegistry$Entry.class
lib/java/se/lth/control/labcomm/LabCommDispatcher.class
lib/java/se/lth/control/labcomm/LabCommEncoderChannel.class
lib/java/se/lth/control/labcomm/LabCommEncoder.class
lib/java/se/lth/control/labcomm/LabCommEncoderRegistry.class
lib/java/se/lth/control/labcomm/LabCommEncoderRegistry$Entry.class
lib/java/se/lth/control/labcomm/LabCommHandler.class
lib/java/se/lth/control/labcomm/LabCommReader.class
lib/java/se/lth/control/labcomm/LabCommSample.class
lib/java/se/lth/control/labcomm/LabCommType.class
lib/java/se/lth/control/labcomm/LabCommWriter.class
gen
*~
*.class
*.o
*.pyc
examples/dynamic/gen
Rationale for the licensing choosen for LabComm
===============================================
Primary goal: the owners of systems with LabComm communication in it,
should have the liberty to replace the LabComm parts with
any software they see fit.
Secondary goal: it should be possible to release propreitary software
with LabComm.
Wanted software architecture
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+------------------------------------------------------------+
| Propreitary software (any license) |
+------------------------------------------------------------+
| Labcomm glue (LGPL) |
+--------------+-----+--------------+ |
| Generated | | Generated | |
| encoder/ | | encoder/ | |
| decoder | * * | decoder | |
| ( GPLv3 + | | ( GPLv3 + | +---------------+
| permission) | | permission) | | Non-system |
+--------------+-----+--------------+--+ | library |
| LabComm library (GPLv3 + permission) | | (any license) |
+--------------------------------------+-----+----------+----+
| System library (any license) | |
+-------------------------------------------------------+ |
| OS (any license) |
+------------------------------------------------------------+
License considerations
^^^^^^^^^^^^^^^^^^^^^^
We need to allow linking to the LabComm library from the LGPL glue
(see http://www.gnu.org/licenses/gpl-faq.html#GPLIncompatibleLibs).
We can not set a license on generated code
(http://www.gnu.org/licenses/gpl-faq.html#GPLOutput),
but when used with the LabComm library we can force it
to be licensed under GPLv3.
Suggested license for all library files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permission under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by directly linking
any functionality of it, with the the exception of calls denoting the
boundary of encoded samples and calls encoding primitive datatypes,
with any software licensed under the GNU Lesser General Public License,
the licensors of this Program grant you additional permission to convey
the resulting work.
SUBDIRS=compiler lib test examples packaging
export LABCOMM_JAR=$(shell pwd)/compiler/labcomm2014_compiler.jar
export LABCOMM=java -jar $(LABCOMM_JAR)
export VALGRIND=valgrind --leak-check=full --error-exitcode=1
UNAME_S=$(shell uname -s)
.PHONY: all
all: $(SUBDIRS:%=all-%)
.PHONY: all-%
all-%:
ifeq ($(UNAME_S),Darwin)
DYLD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $*
else
LD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $*
endif
.PHONY: test
test: $(SUBDIRS:%=test-%)
.PHONY: test-%
test-%:
ifeq ($(UNAME_S),Darwin)
DYLD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $* test
else
LD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $* test
endif
.PHONY: clean
clean: $(SUBDIRS:%=clean-%)
.PHONY: clean-%
clean-%:
$(MAKE) -C $* clean
.PHONY: distclean
distclean: clean $(SUBDIRS:%=distclean-%)
.PHONY: distclean-%
distclean-%:
$(MAKE) -C $* distclean
.PHONY: srpm
srpm:
make -C packaging $@
Embryo of documentation. More details on http://wiki.cs.lth.se/moin/LabComm
*** The LabComm data description language: ***
Primitive types
sample boolean a_boolean;
sample byte a_byte;
sample short a_short;
sample int an_int;
sample long a_long;
sample float a_float;
sample double a_double;
sample string a_string;
Arrays
sample int fixed_array[3];
sample int variable_array[_]; // Note 1
sample int fixed_array_of_array[3][4]; // Note 2
sample int fixed_rectangular_array[3, 4]; // Note 2
sample int variable_array_of_array[_][_]; // Notes 1 & 2
sample int variable_rectangular_array[_, _]; // Notes 1 & 2
1 In contrast to C, LabComm supports both fixed and variable (denoted by '_') sized arrays.
2 In contrast to Java, LabComm supports multidimensional arrays and not only arrays of arrays.
Structures
sample struct {
int an_int_field;
double a_double_field;
} a_struct;
User defined types
typedef struct {
int field_1;
byte field_2;
} user_type[_];
sample user_type a_user_type_instance;
sample user_type another_user_type_instance;
Example sample declaration (e.g. example.lc)
sample struct {
int sequence;
struct {
boolean last;
string data;
} line[_];
} log_message;
From an .lc file, the labcomm compiler can generate marshalling and demarshalling code
for C, Java, Python, and C#.
gen
labcomm2006_compiler.jar
labcomm2014_compiler.jar
labcomm2014_compiler.jar
aspect Annotations {
syn boolean TypeInstance.hasAnnotations() = getAnnotations().getNumAnnotation()>0;
syn boolean TypeInstance.hasIntentions() = ! intentionSet().isEmpty();
syn String Annotations.getName() = new String(lookup(""));
syn byte[] Annotations.lookup(String key) {
for(Annotation a: getAnnotations()) {
byte[] res = a.lookup(key);
if(res != null) return res;
}
return null;
}
syn byte[] Annotation.lookup(String key) = (getKey().equals(key) ? getValue() : null);
syn boolean Annotation.isIntention() = false;
eq Intention.isIntention() = true;
inh TypeInstance Annotation.parentInstance();
eq TypeInstance.getAnnotations().parentInstance() = this;
coll Set<Intention> TypeInstance.intentionSet() [new HashSet<Intention>()] with add;
Intention contributes this
to TypeInstance.intentionSet()
for parentInstance();
}
aspect SigAnnotations {
inh Decl TypeInstance.parentDecl();
coll Set Decl.allAnnotations() [new HashSet()] with add;
TypeInstance contributes getAnnotationString()
to Decl.allAnnotations()
for parentDecl();
// Helper attribute to get the "outermost" intentions for Decls
syn byte[] TypeInstance.intentionBytes() = getIntentionBytes(sortedIntentions());
syn byte[] Decl.getIntentionBytes() = getTypeInstance().intentionBytes();
static Comparator TypeInstance.intentionComp =
new Comparator<Intention>() {
public int compare(Intention i1, Intention i2) {
return i1.getKey().compareTo(i2.getKey());
}
};
syn int Decl.getNumIntentions() = getTypeInstance().sortedIntentions().getNumChild();
syn List<Intention> TypeInstance.sortedIntentions() {
List<Intention> res = new List<Intention>();
//TODO: refactor out creation of sorted list of intentions
java.util.ArrayList<Intention> sorted = new ArrayList(intentionSet());
java.util.Collections.sort(sorted, intentionComp);
for(Intention i : sorted) {
res.add(i);
}
return res;
}
public DocString.DocString(byte[] bs) {
super("DOCSTRING", bs);
}
public DocString.DocString(String s) {
super("DOCSTRING", s.getBytes());
}
public String Intention.toString() {
return "("+getKey() + ":"+new String(getValue())+")";
}
public String DocString.toString() {
return "\""+new String(getValue())+"\"";
}
/// TESTING
syn String Decl.getAnnotationString() {
StringBuilder sb = new StringBuilder();
Iterator<String> iti = allAnnotations().iterator();
while(iti.hasNext()) {
//Annotation i = iti.next();
//sb.append("("+i.getKey()+" : "+i.getValue()+") ");
String i = iti.next();
sb.append(i);
}
return sb.toString();
}
syn int TypeInstance.fooHash() {
List<Annotation> ints = getAnnotations().getAnnotationList();
int result=0;
for(Annotation i : ints) {
if(i.isIntention()) {
result += i.toString().hashCode();
}
}
return result;
}
syn String TypeInstance.getAnnotationString() {
StringBuilder sb = new StringBuilder();
List<Annotation> ints = getAnnotations().getAnnotationList();
for(Annotation i : ints) {
sb.append(i.toString());
}
return sb.toString();
}
public void Decl.debugAnnotations() {
getTypeInstance().debugAnnotations(getName());
}
public void TypeInstance.debugAnnotations(String context) {
if(hasAnnotations()){
System.out.println(context+".annotations: " + fooHash() + " : " + getAnnotationString());
} else {
//System.out.println(context + " : " + fooHash() + " : " + ": NO ANNOTATIONS ");
}
}
// TESTING END
}
......@@ -13,29 +13,29 @@ aspect ArrayRewrite {
when (! getDim(0).isVariable())
to FixedArrayType {
if (getNumDim() == 1) {
return new FixedArrayType(getType(),
getDim(0).getExpList());
return new FixedArrayType(getDataType(),
getDim(0));
} else {
List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i));
}
return new FixedArrayType(new ParseArrayType(getType(), l),
getDim(0).getExpList());
return new FixedArrayType(new ParseArrayType(getDataType(), l),
getDim(0));
}
}
when (getDim(0).isVariable())
to VariableArrayType {
if (getNumDim() == 1) {
return new VariableArrayType(getType(),
getDim(0).getExpList());
return new VariableArrayType(getDataType(),
getDim(0));
} else {
List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i));
}
return new VariableArrayType(new ParseArrayType(getType(), l),
getDim(0).getExpList());
return new VariableArrayType(new ParseArrayType(getDataType(), l),
getDim(0));
}
}
}
......
aspect DeclNames {
inh String DataType.declName();
eq Decl.getTypeInstance().declName() = getName();
inh String Field.declName();
eq StructType.getField(int i).declName() = declName();
//TODO: aspect should be renamed to parent-something
inh Decl DataType.parentDecl();
inh Decl Field.parentDecl();
eq Decl.getTypeInstance().parentDecl() = this;
eq StructType.getField(int i).parentDecl() = parentDecl();
}
import java.util.Collection;
aspect ErrorCheck {
syn int ASTNode.lineNumber() = getLine(getStart());
protected String ASTNode.errors = null;
protected void ASTNode.error(String s) {
s = "Error at " + lineNumber() + ": " + s;
if(errors == null) {
errors = s;
} else {
errors = errors + "\n" + s;
}
}
protected boolean ASTNode.hasErrors() {
return errors != null;
}
public void ASTNode.errorCheck(Collection collection) {
nameCheck();
typeCheck();
if(hasErrors())
collection.add(errors);
for(int i = 0; i < getNumChild(); i++) {
getChild(i).errorCheck(collection);
}
}
}
import java.util.*;
aspect Signature {
public class SignatureLine {
private int indent;
private byte[] data;
private String comment;
public SignatureLine(int indent, byte[] data, String comment) {
this.indent = indent;
this.data = data;
this.comment = comment;
}
public int getIndent() {
return indent;
}
public byte[] getData() {
return data;
}
public String getComment() {
return comment;
}
}
public class SignatureList {
aspect NoIntentionForTypeOrSampledefs {
inh boolean TypeInstance.addIntentions();
eq Decl.getTypeInstance().addIntentions() = false;
eq StructType.getField(int i).addIntentions() = true;
}
private int indent;
private ArrayList list = new ArrayList();
public void add(byte[] data, String comment) {
list.add(new SignatureLine(indent, data, comment));
}
public void addInt(int value, String comment) {
byte[] data = new byte[4];
for (int i = 0 ; i < 4 ; i++) {
data[3 - i] = (byte)((value >> (8 * i)) & 0xff);
}
add(data, comment);
}
public void addString(String value, String comment) {
addInt(value.length(), comment);
byte[] data = new byte[value.length()];
for (int i = 0 ; i < value.length() ; i++) {
data[i] = (byte)(value.charAt(i) & 0xff);
}
add(data, null);
}
public int size() {
return list.size();
}
aspect FlatSignature {
public String getIndent(int i) {
StringBuffer result = new StringBuffer();
int indent = ((SignatureLine)list.get(i)).getIndent();
for (i = 0 ; i < indent ; i++) {
result.append(" ");
}
return result.toString();
}
public byte[] getData(int i) {
return ((SignatureLine)list.get(i)).getData();
}
public String getComment(int i) {
return ((SignatureLine)list.get(i)).getComment();
}
public void indent() {
indent++;
}
public void unindent() {
indent--;
}
}
public SignatureList Decl.signature() {
SignatureList result = new SignatureList();
flatSignature(result);
public SignatureList Decl.flatSignature(int version) {
SignatureList result = getSignature().getFlatSignatureList();
return result;
}
public void ASTNode.flatSignature(SignatureList list) {
throw new Error(this.getClass().getName() +
".flatSignature(SignatureList list)" +
throw new Error(this.getClass().getName() +
".flatSignature(SignatureList list)" +
" not declared");
}
public void TypeDecl.flatSignature(SignatureList list) {
getType().flatSignature(list);
getTypeInstance().flatSignature(list);
}
public void SampleDecl.flatSignature(SignatureList list) {
getType().flatSignature(list);
getTypeInstance().flatSignature(list);
}
// public void SampleRefType.flatSignature(SignatureList list) {
// list.addInt(LABCOMM_SAMPLE_REF, "sample");
// }
public void TypeInstance.flatSignature(SignatureList list) {
if(addIntentions()) {
debugAnnotations(this.getName()+".TypeInstance.flatSignature");
list.addIntentions(intentions(), "intentions: "+getIntentionString());
}
getDataType().flatSignature(list);
}
public void VoidType.flatSignature(SignatureList list) {
......@@ -125,7 +59,7 @@ aspect Signature {
for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).flatSignature(list);
}
getType().flatSignature(list);
getDataType().flatSignature(list);
list.unindent();
list.add(null, "}");
}
......@@ -142,8 +76,10 @@ aspect Signature {
}
public void Field.flatSignature(SignatureList list) {
list.addString(getName(), signatureComment());
getType().flatSignature(list);
debugAnnotations(this.getName()+".Field.flatSignature");
list.addIntentions(intentions(), "Field: "+getIntentionString());
// list.addString(getName(), signatureComment());
getDataType().flatSignature(list);
}
public void IntegerLiteral.flatSignature(SignatureList list) {
......@@ -158,7 +94,7 @@ aspect Signature {
StringBuffer result = new StringBuffer("array [");
for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) {
result.append(", ");
result.append(", ");
}
result.append(getExp(i).signatureComment());
}
......@@ -167,15 +103,19 @@ aspect Signature {
}
public String ASTNode.signatureComment() {
throw new Error(this.getClass().getName() +
".signatureComment()" +
throw new Error(this.getClass().getName() +
".signatureComment()" +
" not declared");
}
public String Field.signatureComment() {
return getType().signatureComment() + " '" + getName() +"'";
return getDataType().signatureComment() + " '" + getName() +"'";
}
// public String SampleRefType.signatureComment() {
// return "sample";
// }
public String PrimType.signatureComment() {
return getName();
}
......@@ -196,4 +136,4 @@ aspect Signature {
return "_";
}
}
\ No newline at end of file
}
aspect TypeDefGen {
public void Specification.generateTypedefs(PrintStream out, int ver) {
for(Decl d : getDecls()) {
d.generateTypedefs(out);
}
}
public void Decl.generateTypedefs(PrintStream out) {
}
public void Decl.generateDepTypedefs(PrintStream out){
Iterator<Decl> it = type_dependencies().iterator();
while(it.hasNext()) {
Decl d = it.next();
d.generateDepTypedefs(out);
}
pp(out);
}
public void SampleDecl.generateTypedefs(PrintStream out){
if(hasDependencies()) {
out.println("sample "+getName()+"_def {");
out.println(" sample sample;");
out.println(" string typedef = <<EOL");
for(Decl d : type_dependencies()) {
d.generateDepTypedefs(out);
}
pp(out);
out.println("EOL;");
}
}
}
Specification ::= Decl*;
abstract Decl ::= TypeInstance /Signature/;
TypeInstance ::= DataType Annotations;
Annotations ::= Annotation*;
Annotation ::= <Key:String> <Value:byte[]>;
Intention : Annotation;
DocString : Annotation;
TypeDecl : Decl;
SampleDecl : Decl;
//Signatures are in the abstract grammar, so that
//they can be extended and refined by aspects.
Signature ::= SignatureList FlatSignatureList:SignatureList;
SignatureList ::= SignatureLine*;
abstract SignatureLine ::= <Indent:int> <Comment:String>;
abstract DataSignatureLine : SignatureLine;
ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>;
IntSignatureLine : DataSignatureLine ::= <Data:int>;
StringSignatureLine : DataSignatureLine ::= <Data:String>;
IntentionSignatureLine : DataSignatureLine ::= Intention* ;
TypeRefSignatureLine : SignatureLine ::= Decl;
Field : TypeInstance;
abstract DataType;
VoidType : DataType;
//SampleRefType : DataType;
PrimType : DataType ::= <Name:String> <Token:int>;
UserType : DataType ::= <Name:String>;
StructType : DataType ::= Field*;
ParseArrayType : DataType ::= DataType Dim*;
abstract ArrayType : DataType ::= DataType Dim;
VariableArrayType : ArrayType;
FixedArrayType : ArrayType;
Dim ::= Exp*;
abstract Exp;
IntegerLiteral : Exp ::= <Value:String>;
VariableSize : Exp;
This diff is collapsed.
aspect LabCommTokens {
public static final int ASTNode.LABCOMM_VERSION = 0x01;
public static final int ASTNode.LABCOMM_SAMPLE_DEF = 0x02; // The flat signature
public static final int ASTNode.LABCOMM_SAMPLE_REF = 0x03;
public static final int ASTNode.LABCOMM_TYPE_DEF = 0x03; // and type declarations, hierarchically
public static final int ASTNode.LABCOMM_TYPE_BINDING=0x05;
public static final int ASTNode.LABCOMM_ARRAY = 0x10;
public static final int ASTNode.LABCOMM_STRUCT = 0x11;
public static final int ASTNode.LABCOMM_BOOLEAN = 0x20;
public static final int ASTNode.LABCOMM_BYTE = 0x21;
public static final int ASTNode.LABCOMM_SHORT = 0x22;
public static final int ASTNode.LABCOMM_INT = 0x23;
public static final int ASTNode.LABCOMM_LONG = 0x24;
public static final int ASTNode.LABCOMM_FLOAT = 0x25;
public static final int ASTNode.LABCOMM_DOUBLE = 0x26;
public static final int ASTNode.LABCOMM_STRING = 0x27;
public static final int ASTNode.LABCOMM_SAMPLE = 0x28;
}