Commit f2be82a5 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

Merge branch 'master' into intentions_rebased

Conflicts:
	lib/c/2014/test/test_labcomm_renaming_encoder.c
	lib/csharp/se/lth/control/labcomm2014/DecoderChannel.cs
	lib/csharp/se/lth/control/labcomm2014/EncoderChannel.cs
parents b3ccaa4f bdceaa13
......@@ -9,7 +9,6 @@ aspect CS_CodeGenEnv {
public class CS_env extends PrintEnv {
private CS_printer printer;
private HashMap unique = new HashMap();
final private static class CS_printer extends PrintEnv.FilePrinter {
public CS_printer(File f) {
......@@ -57,15 +56,6 @@ aspect CS_CodeGenEnv {
println("}");
}
public String getUnique(Object o) {
String result = (String)unique.get(o);
if (result == null) {
result = "_" + (unique.size() + 1) + "_";
}
unique.put(o, result);
return result;
}
}
}
......@@ -275,6 +265,7 @@ aspect CS_Class {
CS_emitSignature(env);
env.println("}");
env.unindent();
}
public void Decl.CS_emitSignature(CS_env env) {
......@@ -320,12 +311,12 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println();
env.println("private class Dispatcher : SampleDispatcher{");
env.println("private class Dispatcher : SampleDispatcher {");
env.indent();
env.println();
env.println("public Type getSampleClass() {");
env.println("public SampleDispatcher getSampleIdentity() {");
env.indent();
env.println("return typeof(" + getName() + ");");
env.println("return dispatcher;");
env.unindent();
env.println("}");
env.println();
......@@ -357,21 +348,6 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println();
// env.println("public void encodeSignature(Encoder e) throws IOException{");
// env.indent();
// env.println("emitSignature(e);");
// env.unindent();
// env.println("}");
// env.println();
// env.println("public void encodeSignatureMetadata(Encoder e, int index){");
// env.indent();
// env.println("e.encodePacked32(Constant.TYPE_DEF);");
// env.println("e.encodePacked32(index);");
// env.println("e.encodeString(getName());");
// env.println("emitSignature(e);");
// env.unindent();
// env.println("}");
// env.println();
env.println("public bool canDecodeAndHandle() {");
env.indent();
env.println("return "+isSample+";");
......@@ -397,7 +373,6 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println("");
} //TODO, fix above method
public void TypeDecl.CS_emitEncoder(CS_env env) {
......@@ -424,9 +399,9 @@ aspect CS_Class {
}
env.println(") {");
env.indent();
env.println("e.begin(typeof(" + getName() + "));");
env.println("e.begin(dispatcher);");
getDataType().CS_emitEncoder(env, "value");
env.println("e.end(typeof(" + getName() + "));");
env.println("e.end(dispatcher);");
env.unindent();
env.println("}");
env.println();
......@@ -634,7 +609,7 @@ aspect CS_Class {
public void PrimType.CS_emitTypePrefix(CS_env env) {
switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } break;
case LABCOMM_SAMPLE: { env.print("Type"); } break;
case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
default: { env.print(getName()); } break;
}
}
......@@ -764,7 +739,7 @@ aspect CS_Class {
switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } break;
case LABCOMM_BOOLEAN: { env.print("bool"); } break;
case LABCOMM_SAMPLE: { env.print("Type"); } break;
case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
default: { env.print(getName()); } break;
}
}
......
......@@ -24,6 +24,7 @@ OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o \
labcomm$(VERSION)_renaming.o \
labcomm$(VERSION)_renaming_registry.o \
labcomm$(VERSION)_renaming_encoder.o \
labcomm$(VERSION)_renaming_decoder.o
......@@ -50,6 +51,7 @@ TESTS=test_labcomm_basic_type_encoding \
test_labcomm \
test_labcomm_pthread_scheduler \
test_labcomm_copy \
test_labcomm_renaming_registry \
test_labcomm_renaming_encoder \
test_labcomm_renaming_decoder
#FIXME: test_labcomm_errors
......@@ -175,6 +177,9 @@ $(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/gen/more_types.o
$(TEST_DIR)/gen/test_labcomm_renaming_registry: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm_renaming_encoder: \
$(TEST_DIR)/gen/generated_encoding.o
......
......@@ -31,4 +31,12 @@ char *labcomm2014_renaming_prefix(struct labcomm2014_memory *m,
char *labcomm2014_renaming_suffix(struct labcomm2014_memory *m,
char *name, void *context);
struct labcomm2014_renaming_registry *labcomm2014_renaming_registry_new(
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler);
void labcomm2014_renaming_registry_free(
struct labcomm2014_renaming_registry *r);
#endif
......@@ -23,92 +23,63 @@
#include "labcomm2014_renaming_decoder.h"
#include "labcomm2014.h"
#include "labcomm2014_private.h"
#include "labcomm2014_renaming_private.h"
struct decoder {
struct labcomm2014_decoder decoder;
struct labcomm2014_decoder *next;
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context);
struct labcomm2014_renaming_registry *registry;
char *(*rename_func)(struct labcomm2014_memory *m, char *name, void *context);
void *context;
LABCOMM_SIGNATURE_ARRAY_DEF(renamed, struct labcomm2014_signature *);
LABCOMM_SIGNATURE_ARRAY_DEF(renamed,
struct labcomm2014_renaming_rename *);
};
static struct labcomm2014_signature *get_renamed(
static struct labcomm2014_renaming_rename *get_renamed(
struct labcomm2014_decoder *d,
const struct labcomm2014_signature *signature)
{
struct labcomm2014_signature *result;
struct labcomm2014_renaming_rename *result;
struct decoder *id = d->context;
int index;
index = labcomm2014_get_local_index(signature);
labcomm2014_scheduler_data_lock(d->scheduler);
result = LABCOMM_SIGNATURE_ARRAY_GET(id->renamed,
struct labcomm2014_signature *,
struct labcomm2014_renaming_rename *,
index, NULL);
labcomm2014_scheduler_data_unlock(d->scheduler);
return result;
}
static struct labcomm2014_signature *set_renamed(
static struct labcomm2014_renaming_rename *set_renamed(
struct labcomm2014_decoder *d,
const struct labcomm2014_signature *signature)
{
struct labcomm2014_signature *result;
struct labcomm2014_renaming_rename *result = NULL;
result = get_renamed(d, signature);
if (result == NULL) {
/* create a renamed sample */
struct decoder *id = d->context;
struct labcomm2014_renaming_rename **renamed;
struct labcomm2014_renaming_rename *entry = NULL;
int index;
struct labcomm2014_signature **renamed;
index = labcomm2014_get_local_index(signature);
if (index <= 0) { goto out; /*result already NULL */}
entry = labcomm2014_renaming_rename_new(id->registry, signature,
id->rename_func, id->context);
if (entry == NULL) { goto out; }
labcomm2014_scheduler_data_lock(d->scheduler);
renamed = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, id->renamed,
struct labcomm2014_signature *,
struct labcomm2014_renaming_rename *,
index);
if (renamed == NULL) {
labcomm2014_error_warning(d->error,
LABCOMM2014_ERROR_MEMORY,
"Could not allocate rename slot: %s\n",
signature->name);
goto unlock;
}
if (*renamed != NULL) {
/* Somebody beat as to allocation, this should never happen */
goto unlock;
}
result = labcomm2014_memory_alloc(d->memory, 0, sizeof(*result));
if (result == NULL) {
labcomm2014_error_warning(d->error,
LABCOMM2014_ERROR_MEMORY,
"Could not allocate rename signature: %s\n",
signature->name);
goto unlock;
}
result->name = id->rename(d->memory, signature->name, id->context);
if (result->name == NULL) {
labcomm2014_error_warning(d->error,
LABCOMM2014_ERROR_MEMORY,
"Could not allocate rename name: %s\n",
signature->name);
goto unlock_free_result;
}
result->encoded_size = signature->encoded_size;
result->size = signature->size;
result->signature = signature->signature;
result->index = 0;
#ifndef LABCOMM_NO_TYPEDECL
result->tdsize = signature->tdsize;
result->treedata = signature->treedata;
#endif
labcomm2014_set_local_index(result);
*renamed = result;
if (renamed == NULL) { goto free_unlock; }
if (*renamed != NULL) { result = *renamed; goto free_unlock; }
*renamed = entry;
result = entry;
goto unlock;
unlock_free_result:
labcomm2014_memory_free(d->memory, 0, result);
result = NULL;
free_unlock:
labcomm2014_renaming_rename_free(id->registry, entry);
unlock:
labcomm2014_scheduler_data_unlock(d->scheduler);
out:
......@@ -118,33 +89,42 @@ static struct labcomm2014_signature *set_renamed(
}
static int do_sample_register(struct labcomm2014_decoder *d,
const struct labcomm2014_signature *s,
const struct labcomm2014_signature *signature,
labcomm2014_decoder_function decoder,
labcomm2014_handler_function handler,
void *context)
{
const struct labcomm2014_renaming_rename *renamed;
struct decoder *id = d->context;
return id->next->sample_register(id->next, set_renamed(d, s), decoder,
handler, context);
renamed = set_renamed(d, signature);
return id->next->sample_register(
id->next, labcomm2014_renaming_rename_signature(renamed),
decoder, handler, context);
}
static int do_ref_register(struct labcomm2014_decoder *d,
const struct labcomm2014_signature *signature)
{
const struct labcomm2014_renaming_rename *renamed;
struct decoder *id = d->context;
return id->next->ref_register(id->next, set_renamed(d, signature));
renamed = set_renamed(d, signature);
return id->next->ref_register(
id->next, labcomm2014_renaming_rename_signature(renamed));
}
static int do_ioctl(struct labcomm2014_decoder *d,
const struct labcomm2014_signature *signature,
uint32_t ioctl_action, va_list args)
{
const struct labcomm2014_renaming_rename *renamed;
struct decoder *id = d->context;
return id->next->ioctl(id->next, get_renamed(d, signature),
ioctl_action, args);
renamed = get_renamed(d, signature);
return id->next->ioctl(
id->next, labcomm2014_renaming_rename_signature(renamed),
ioctl_action, args);
}
static int do_decode_one(struct labcomm2014_decoder *d)
......@@ -166,14 +146,15 @@ static const struct labcomm2014_sample_ref *do_ref_get(
struct labcomm2014_decoder *d,
const struct labcomm2014_signature *signature)
{
const struct labcomm2014_signature *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct decoder *id = d->context;
renamed = get_renamed(d, signature);
if (renamed == NULL) {
return id->next->ref_get(id->next, signature);
} else {
return id->next->ref_get(id->next, renamed);
return id->next->ref_get(id->next,
labcomm2014_renaming_rename_signature(renamed));
}
}
......@@ -182,23 +163,25 @@ static void do_free(struct labcomm2014_decoder *d)
struct decoder *id = d->context;
int i;
LABCOMM_SIGNATURE_ARRAY_FOREACH(id->renamed, struct labcomm2014_signature *,
LABCOMM_SIGNATURE_ARRAY_FOREACH(id->renamed,
struct labcomm2014_renaming_rename *,
i) {
struct labcomm2014_signature *s;
s = LABCOMM_SIGNATURE_ARRAY_GET(id->renamed,
struct labcomm2014_signature *, i, NULL);
if (s) {
labcomm2014_memory_free(d->memory, 0, s->name);
labcomm2014_memory_free(d->memory, 0, s);
struct labcomm2014_renaming_rename *r;
r = LABCOMM_SIGNATURE_ARRAY_GET(id->renamed,
struct labcomm2014_renaming_rename *,
i, NULL);
if (r) {
labcomm2014_renaming_rename_free(id->registry, r);
}
}
LABCOMM_SIGNATURE_ARRAY_FREE(d->memory, id->renamed,
struct labcomm2014_signature *);
struct labcomm2014_renaming_rename *);
labcomm2014_memory_free(d->memory, 0, id);
}
struct labcomm2014_decoder *labcomm2014_renaming_decoder_new(
struct labcomm2014_decoder *d,
struct labcomm2014_renaming_registry *registry,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context)
{
......@@ -220,10 +203,11 @@ struct labcomm2014_decoder *labcomm2014_renaming_decoder_new(
result->decoder.index_to_sample_ref = do_index_to_sample_ref;
result->decoder.ref_get = do_ref_get;
result->next = d;
result->rename = rename;
result->registry = registry;
result->rename_func = rename;
result->context = context;
LABCOMM_SIGNATURE_ARRAY_INIT(result->renamed,
struct labcomm2014_signature *);
struct labcomm2014_renaming_rename *);
return &(result->decoder);
}
}
......@@ -23,9 +23,11 @@
#define __LABCOMM2014_RENAMING_DECODER_H__
#include "labcomm2014.h"
#include "labcomm2014_renaming.h"
struct labcomm2014_decoder *labcomm2014_renaming_decoder_new(
struct labcomm2014_decoder *d,
struct labcomm2014_renaming_registry *r,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context);
......
......@@ -23,104 +23,63 @@
#include "labcomm2014_renaming_encoder.h"
#include "labcomm2014.h"
#include "labcomm2014_private.h"
struct renamed {
struct labcomm2014_signature signature;
struct labcomm2014_signature_data s_treedata[2];
};
#include "labcomm2014_renaming_private.h"
struct encoder {
struct labcomm2014_encoder encoder;
struct labcomm2014_encoder *next;
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context);
struct labcomm2014_renaming_registry *registry;
char *(*rename_func)(struct labcomm2014_memory *m, char *name, void *context);
void *context;
LABCOMM_SIGNATURE_ARRAY_DEF(renamed, struct renamed *);
LABCOMM_SIGNATURE_ARRAY_DEF(renamed,
struct labcomm2014_renaming_rename *);
};
static struct renamed *get_renamed(
static struct labcomm2014_renaming_rename *get_renamed(
struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
struct renamed *result;
struct labcomm2014_renaming_rename *result;
struct encoder *ie = e->context;
int index;
index = labcomm2014_get_local_index(signature);
labcomm2014_scheduler_writer_lock(e->scheduler);
result = LABCOMM_SIGNATURE_ARRAY_GET(ie->renamed,
struct renamed *,
struct labcomm2014_renaming_rename *,
index, NULL);
labcomm2014_scheduler_writer_unlock(e->scheduler);
return result;
}
static struct renamed *set_renamed(
static struct labcomm2014_renaming_rename *set_renamed(
struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
struct renamed *result;
struct labcomm2014_renaming_rename *result = NULL;
result = get_renamed(e, signature);
if (result == NULL) {
/* create a renamed sample */
struct encoder *ie = e->context;
struct labcomm2014_renaming_rename **renamed;
struct labcomm2014_renaming_rename *entry = NULL;
int index;
struct renamed **renamed;
index = labcomm2014_get_local_index(signature);
if (index <= 0) { goto out; /*result already NULL */}
entry = labcomm2014_renaming_rename_new(ie->registry, signature,
ie->rename_func, ie->context);
if (entry == NULL) { goto out; }
labcomm2014_scheduler_writer_lock(e->scheduler);
renamed = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, ie->renamed,
struct renamed *,
struct labcomm2014_renaming_rename *,
index);
if (renamed == NULL) {
labcomm2014_error_warning(e->error,
LABCOMM2014_ERROR_MEMORY,
"Could not allocate rename slot: %s\n",
signature->name);
goto unlock;
}
if (*renamed != NULL) {
/* Somebody beat as to allocation, this should never happen */
goto unlock;
}
result = labcomm2014_memory_alloc(e->memory, 0, sizeof(*result));
if (result == NULL) {
labcomm2014_error_warning(e->error,
LABCOMM2014_ERROR_MEMORY,
"Could not allocate rename signature: %s\n",
signature->name);
goto unlock;
}
result->signature.name = ie->rename(
e->memory, signature->name, ie->context);
if (result->signature.name == NULL) {
labcomm2014_error_warning(e->error,
LABCOMM2014_ERROR_MEMORY,
"Could not allocate rename name: %s\n",
signature->name);
goto unlock_free_result;
}
result->signature.encoded_size = signature->encoded_size;
result->signature.size = signature->size;
result->signature.signature = signature->signature;
result->signature.index = 0;
#ifndef LABCOMM_NO_TYPEDECL
struct labcomm2014_signature_data s_treedata[2] = {
LABCOMM_SIGDEF_SIGNATURE(*signature),
LABCOMM_SIGDEF_END
};
result->s_treedata[0] = s_treedata[0];
result->s_treedata[1] = s_treedata[1];
result->signature.tdsize = sizeof(result->s_treedata);
result->signature.treedata = result->s_treedata;
#endif
labcomm2014_set_local_index(&result->signature);
*renamed = result;
if (renamed == NULL) { goto free_unlock; }
if (*renamed != NULL) { result = *renamed; goto free_unlock; }
*renamed = entry;
result = entry;
goto unlock;
unlock_free_result:
labcomm2014_memory_free(e->memory, 0, result);
result = NULL;
free_unlock:
labcomm2014_renaming_rename_free(ie->registry, entry);
unlock:
labcomm2014_scheduler_writer_unlock(e->scheduler);
out:
......@@ -132,14 +91,15 @@ static struct renamed *set_renamed(
static int do_type_register(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
const struct renamed *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed) {
/* Register base type and renamed type */
ie->next->type_register(ie->next, signature);
return ie->next->type_register(ie->next, &renamed->signature);
return ie->next->type_register(
ie->next, labcomm2014_renaming_rename_signature(renamed));
} else {
return ie->next->type_register(ie->next, signature);
}
......@@ -149,12 +109,13 @@ static int do_type_bind(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
char has_deps)
{
const struct renamed *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed) {
return ie->next->type_bind(ie->next, &renamed->signature, 1);
return ie->next->type_bind(
ie->next, labcomm2014_renaming_rename_signature(renamed), 1);
} else {
return ie->next->type_bind(ie->next, signature, has_deps);
}
......@@ -164,21 +125,23 @@ static int do_sample_register(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
labcomm2014_encoder_function encode)
{
const struct renamed *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = set_renamed(e, signature);
return ie->next->sample_register(ie->next, &renamed->signature, encode);
return ie->next->sample_register(
ie->next, labcomm2014_renaming_rename_signature(renamed), encode);
}
static int do_ref_register(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
const struct renamed *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = set_renamed(e, signature);
return ie->next->ref_register(ie->next, &renamed->signature);
return ie->next->ref_register(ie->next,
labcomm2014_renaming_rename_signature(renamed));
}
static int do_encode(struct labcomm2014_encoder *e,
......@@ -186,14 +149,16 @@ static int do_encode(struct labcomm2014_encoder *e,
labcomm2014_encoder_function encode,
void *value)
{
const struct renamed *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed == NULL) {
return -EINVAL;
} else {
return ie->next->encode(ie->next, &renamed->signature, encode, value);
return ie->next->encode(ie->next,
labcomm2014_renaming_rename_signature(renamed),
encode, value);
}
}
......@@ -201,12 +166,12 @@ static int do_ioctl(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
uint32_t ioctl_action, va_list args)
{
const struct renamed *renamed;
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed != NULL) {
signature = &renamed->signature;
signature = labcomm2014_renaming_rename_signature(renamed);
}
return ie->next->ioctl(ie->next, signature, ioctl_action, args);