Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
LabComm
Commits
bdceaa13
Commit
bdceaa13
authored
May 28, 2015
by
Anders Blomdell
Browse files
Changed notion of sample identity for C# to enable renaming
parent
e6e5f5e8
Changes
10
Hide whitespace changes
Inline
Side-by-side
compiler/2014/CS_CodeGen.jrag
View file @
bdceaa13
...
...
@@ -13,7 +13,6 @@ aspect CS_CodeGenEnv {
private int indent;
private int depth;
private CS_printer printer;
private HashMap unique = new HashMap();
final private static class CS_printer {
...
...
@@ -159,15 +158,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;
}
}
}
...
...
@@ -377,6 +367,7 @@ aspect CS_Class {
CS_emitSignature(env);
env.println("}");
env.unindent();
}
public void Decl.CS_emitSignature(CS_env env) {
...
...
@@ -422,12 +413,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
getSample
Class
() {");
env.println("public
SampleDispatcher
getSample
Identity
() {");
env.indent();
env.println("return
typeof(" + getName() + ")
;");
env.println("return
dispatcher
;");
env.unindent();
env.println("}");
env.println();
...
...
@@ -459,21 +450,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+";");
...
...
@@ -499,7 +475,6 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println("");
} //TODO, fix above method
public void TypeDecl.CS_emitEncoder(CS_env env) {
...
...
@@ -526,9 +501,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();
...
...
@@ -736,7 +711,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;
}
}
...
...
@@ -866,7 +841,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;
}
}
...
...
lib/csharp/Makefile
View file @
bdceaa13
MODULES
=
Constant
\
MODULES
=
AbstractDecoder
\
Constant
\
Decoder
\
DecoderChannel
\
DecoderRegistry
\
...
...
@@ -8,7 +9,7 @@ MODULES=Constant\
Sample
\
SampleDispatcher
\
SampleHandler
\
SampleType
SampleType
.PHONY
:
all
all
:
labcomm2014.dll
...
...
lib/csharp/se/lth/control/labcomm2014/AbstractDecoder.cs
0 → 100644
View file @
bdceaa13
using
System
;
namespace
se.lth.control.labcomm2014
{
public
interface
AbstractDecoder
{
void
runOne
();
void
run
();
void
register
(
SampleDispatcher
dispatcher
,
SampleHandler
handler
);
void
registerSampleRef
(
SampleDispatcher
dispatcher
);
}
}
lib/csharp/se/lth/control/labcomm2014/Decoder.cs
View file @
bdceaa13
...
...
@@ -2,11 +2,7 @@ using System;
namespace
se.lth.control.labcomm2014
{
public
interface
Decoder
{
void
register
(
SampleDispatcher
dispatcher
,
SampleHandler
handler
);
void
registerSampleRef
(
SampleDispatcher
dispatcher
);
public
interface
Decoder
:
AbstractDecoder
{
bool
decodeBoolean
();
byte
decodeByte
();
...
...
@@ -17,7 +13,7 @@ namespace se.lth.control.labcomm2014 {
double
decodeDouble
();
String
decodeString
();
int
decodePacked32
();
Type
decodeSampleRef
();
SampleDispatcher
decodeSampleRef
();
}
...
...
lib/csharp/se/lth/control/labcomm2014/DecoderChannel.cs
View file @
bdceaa13
...
...
@@ -166,11 +166,11 @@ namespace se.lth.control.labcomm2014 {
return
(
int
)
(
res
&
0xffffffff
);
}
public
Type
decodeSampleRef
()
{
public
SampleDispatcher
decodeSampleRef
()
{
int
index
=
(
int
)
ReadInt
(
4
);
try
{
DecoderRegistry
.
Entry
e
=
ref_registry
.
get
(
index
);
return
e
.
getSampleDispatcher
().
getSample
Class
();
return
e
.
getSampleDispatcher
().
getSample
Identity
();
}
catch
(
NullReferenceException
)
{
return
null
;
}
...
...
lib/csharp/se/lth/control/labcomm2014/DecoderRegistry.cs
View file @
bdceaa13
...
...
@@ -90,11 +90,11 @@ namespace se.lth.control.labcomm2014 {
}
}
private
Dictionary
<
Type
,
Entry
>
by
Class
;
private
Dictionary
<
SampleDispatcher
,
Entry
>
by
Identity
;
private
Dictionary
<
int
,
Entry
>
byIndex
;
public
DecoderRegistry
()
{
by
Class
=
new
Dictionary
<
Type
,
Entry
>();
by
Identity
=
new
Dictionary
<
SampleDispatcher
,
Entry
>();
byIndex
=
new
Dictionary
<
int
,
Entry
>();
}
...
...
@@ -102,7 +102,7 @@ namespace se.lth.control.labcomm2014 {
SampleHandler
handler
)
{
lock
(
this
)
{
Entry
e
;
by
Class
.
TryGetValue
(
dispatcher
.
getSample
Class
(),
out
e
);
by
Identity
.
TryGetValue
(
dispatcher
.
getSample
Identity
(),
out
e
);
if
(
e
!=
null
)
{
e
.
check
(
dispatcher
.
getName
(),
dispatcher
.
getSignature
());
e
.
setHandler
(
handler
);
...
...
@@ -117,7 +117,7 @@ namespace se.lth.control.labcomm2014 {
}
if
(
e
==
null
)
{
e
=
new
Entry
(
dispatcher
,
handler
);
by
Class
.
Add
(
dispatcher
.
getSample
Class
(),
e
);
by
Identity
.
Add
(
dispatcher
.
getSample
Identity
(),
e
);
}
}
}
...
...
@@ -132,7 +132,7 @@ namespace se.lth.control.labcomm2014 {
if
(
e
!=
null
)
{
e
.
check
(
name
,
signature
);
}
else
{
foreach
(
Entry
e2
in
by
Class
.
Values
)
{
foreach
(
Entry
e2
in
by
Identity
.
Values
)
{
if
(
e2
.
match
(
name
,
signature
))
{
e2
.
setIndex
(
index
);
e
=
e2
;
...
...
lib/csharp/se/lth/control/labcomm2014/Encoder.cs
View file @
bdceaa13
...
...
@@ -6,8 +6,8 @@ namespace se.lth.control.labcomm2014 {
void
register
(
SampleDispatcher
dispatcher
);
void
registerSampleRef
(
SampleDispatcher
dispatcher
);
void
begin
(
Type
c
);
void
end
(
Type
c
);
void
begin
(
SampleDispatcher
dispatcher
);
void
end
(
SampleDispatcher
dispatcher
);
void
encodeBoolean
(
bool
value
);
void
encodeByte
(
byte
value
);
...
...
@@ -18,7 +18,7 @@ namespace se.lth.control.labcomm2014 {
void
encodeDouble
(
double
value
);
void
encodeString
(
String
value
);
void
encodePacked32
(
Int64
value
);
void
encodeSampleRef
(
Type
value
);
void
encodeSampleRef
(
SampleDispatcher
value
);
}
...
...
lib/csharp/se/lth/control/labcomm2014/EncoderChannel.cs
View file @
bdceaa13
...
...
@@ -53,11 +53,11 @@ namespace se.lth.control.labcomm2014 {
bytes
.
SetLength
(
0
);
}
public
void
begin
(
Type
c
)
{
begin
(
def_registry
.
getTag
(
c
));
public
void
begin
(
SampleDispatcher
identity
)
{
begin
(
def_registry
.
getTag
(
identity
));
}
public
void
end
(
Type
c
)
{
public
void
end
(
SampleDispatcher
identity
)
{
WritePacked32
(
writer
,
current_tag
);
WritePacked32
(
writer
,
bytes
.
Length
);
bytes
.
WriteTo
(
writer
);
...
...
@@ -132,7 +132,7 @@ namespace se.lth.control.labcomm2014 {
WritePacked32
(
bytes
,
value
);
}
public
void
encodeSampleRef
(
Type
value
)
{
public
void
encodeSampleRef
(
SampleDispatcher
value
)
{
int
index
=
0
;
try
{
index
=
ref_registry
.
getTag
(
value
);
...
...
lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs
View file @
bdceaa13
...
...
@@ -26,29 +26,29 @@ namespace se.lth.control.labcomm2014 {
}
private
int
userIndex
=
Constant
.
FIRST_USER_INDEX
;
private
Dictionary
<
Type
,
Entry
>
by
Class
;
private
Dictionary
<
SampleDispatcher
,
Entry
>
by
Identity
;
public
EncoderRegistry
()
{
by
Class
=
new
Dictionary
<
Type
,
Entry
>();
by
Identity
=
new
Dictionary
<
SampleDispatcher
,
Entry
>();
}
public
int
add
(
SampleDispatcher
dispatcher
)
{
lock
(
this
)
{
Entry
e
;
by
Class
.
TryGetValue
(
dispatcher
.
getSample
Class
(),
out
e
);
by
Identity
.
TryGetValue
(
dispatcher
.
getSample
Identity
(),
out
e
);
if
(
e
==
null
)
{
e
=
new
Entry
(
dispatcher
,
userIndex
);
by
Class
.
Add
(
dispatcher
.
getSample
Class
(),
e
);
by
Identity
.
Add
(
dispatcher
.
getSample
Identity
(),
e
);
userIndex
++;
}
return
e
.
getIndex
();
}
}
public
int
getTag
(
Type
sample
)
{
public
int
getTag
(
SampleDispatcher
sample
)
{
lock
(
this
)
{
Entry
e
;
by
Class
.
TryGetValue
(
sample
,
out
e
);
by
Identity
.
TryGetValue
(
sample
,
out
e
);
if
(
e
==
null
)
{
throw
new
Exception
(
"'"
+
sample
.
ToString
()
+
...
...
lib/csharp/se/lth/control/labcomm2014/SampleDispatcher.cs
View file @
bdceaa13
...
...
@@ -4,12 +4,12 @@ namespace se.lth.control.labcomm2014 {
public
interface
SampleDispatcher
{
Type
getSample
Class
();
SampleDispatcher
getSample
Identity
();
String
getName
();
byte
[]
getSignature
();
void
decodeAndHandle
(
Decoder
decoder
,
SampleHandler
handler
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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