Skip to content
GitLab
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
cc8f66ad
Commit
cc8f66ad
authored
Feb 11, 2015
by
Sven Gestegård Robertz
Browse files
rename and cleanup
parent
64a8c45d
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/user_types/TDDecoder.java
View file @
cc8f66ad
...
...
@@ -6,7 +6,7 @@ import java.io.IOException;
import
se.lth.control.labcomm.DecoderChannel
;
import
se.lth.control.labcomm.TypeDef
;
import
se.lth.control.labcomm.TypeDefParser
;
import
se.lth.control.labcomm.
TypeDefVisito
r
;
import
se.lth.control.labcomm.
ASTbuilde
r
;
//import se.lth.control.labcomm.TypeBinding;
import
se.lth.control.labcomm2014.compiler.Program
;
...
...
@@ -78,27 +78,18 @@ public class TDDecoder
public
void
onTypeDef
(
TypeDefParser
.
ParsedTypeDef
d
)
{
if
(
d
.
isSampleDef
()){
System
.
out
.
println
(
"onTypeDef (sample): "
);
TypeDefVisitor
v
=
new
TypeDefVisito
r
();
ASTbuilder
v
=
new
ASTbuilde
r
();
Program
p
=
v
.
makeProgram
((
TypeDefParser
.
ParsedSampleDef
)
d
);
LinkedList
errors
=
new
LinkedList
();
p
.
errorCheck
(
errors
);
if
(
errors
.
isEmpty
())
{
try
{
try
{
//FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt");
//PrintStream out = new PrintStream(f);
p
.
pp
(
System
.
out
);
//p.C_genC(System.out, new Vector(), "lcname", "prefix", 2014);
//p.J_gen(out, "testpackage", 2014);
//out.close();
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
System
.
err
.
println
(
"Exception: "
+
e
);
e
.
printStackTrace
();
}
}
else
{
for
(
Iterator
iter
=
errors
.
iterator
();
iter
.
hasNext
();
)
{
String
s
=
(
String
)
iter
.
next
();
System
.
out
.
println
(
s
);
}
}
}
//System.out.println(" "+d.getName()+";");
...
...
lib/java/Makefile
View file @
cc8f66ad
...
...
@@ -13,7 +13,7 @@ MODULES=Constant \
BuiltinType
\
TypeDef
\
TypeBinding
\
TypeDefVisito
r
\
ASTbuilde
r
\
TypeDefParser
\
Writer
\
WriterWrapper
...
...
lib/java/se/lth/control/labcomm/ASTbuilder.java
View file @
cc8f66ad
...
...
@@ -40,7 +40,7 @@ import se.lth.control.labcomm2014.compiler.VariableSize;
/** A class for building a JastAdd AST from the parsed types
* created by a TypeDefParser. This class depends on the LabComm compiler.
*/
public
class
TypeDefVisito
r
implements
TypeDefParser
.
ParsedSymbolVisitor
{
public
class
ASTbuilde
r
implements
TypeDefParser
.
ParsedSymbolVisitor
{
///// tree building
//
...
...
@@ -48,11 +48,20 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
private
LinkedList
<
Type
>
typeStack
;
private
LinkedList
<
Field
>
fieldStack
;
public
TypeDefVisito
r
()
{
public
ASTbuilde
r
()
{
this
.
typeStack
=
new
LinkedList
<
Type
>();
this
.
fieldStack
=
new
LinkedList
<
Field
>();
}
private
void
assertStacksEmpty
()
throws
RuntimeException
{
if
(!
typeStack
.
isEmpty
())
{
throw
new
RuntimeException
(
"Error: type stack not empty"
);
}
if
(!
fieldStack
.
isEmpty
())
{
throw
new
RuntimeException
(
"Error: field stack not empty"
);
}
}
public
void
visit
(
TypeDefParser
.
TypeSymbol
s
){
throw
new
Error
(
"not implemented? needed?"
);
...
...
@@ -119,12 +128,31 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
Decl
result
=
new
TypeDecl
(
typeStack
.
pop
(),
d
.
getName
());
return
result
;
}
private
Program
createAndCheckProgram
(
List
<
Decl
>
ds
)
{
Program
p
=
new
Program
(
ds
);
LinkedList
errors
=
new
LinkedList
();
p
.
errorCheck
(
errors
);
if
(
errors
.
isEmpty
())
{
return
p
;
}
else
{
//XXX temporary debug printout
for
(
Iterator
iter
=
errors
.
iterator
();
iter
.
hasNext
();
)
{
String
s
=
(
String
)
iter
.
next
();
System
.
err
.
println
(
s
);
}
// This should not happen
throw
new
RuntimeException
(
"Internal error: parsed labcomm declaration has errors"
);
}
}
public
Program
makeProgram
(
TypeDefParser
.
ParsedTypeDef
d
)
{
assertStacksEmpty
();
List
<
Decl
>
ds
=
new
List
<
Decl
>();
ds
.
add
(
makeDecl
(
d
));
return
new
Program
(
ds
);
assertStacksEmpty
();
return
createAndCheckProgram
(
ds
);
}
public
Decl
makeDecl
(
TypeDefParser
.
ParsedSampleDef
d
)
{
...
...
@@ -133,6 +161,7 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
return
result
;
}
public
Program
makeProgram
(
TypeDefParser
.
ParsedSampleDef
d
)
{
assertStacksEmpty
();
List
<
Decl
>
ds
=
new
List
<
Decl
>();
Iterator
<
TypeDefParser
.
ParsedTypeDef
>
it
=
d
.
getDepIterator
();
...
...
@@ -142,7 +171,8 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
ds
.
add
(
makeDecl
(
d
));
return
new
Program
(
ds
);
assertStacksEmpty
();
return
createAndCheckProgram
(
ds
);
}
}
lib/java/se/lth/control/labcomm2006/ASTbuilder.java
View file @
cc8f66ad
package
se.lth.control.labcomm2006
;
public
class
TypeDefVisito
r
{
public
class
ASTbuilde
r
{
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment