Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
LabComm
Commits
3fbc9aee
Commit
3fbc9aee
authored
10 years ago
by
Sven Gestegård Robertz
Browse files
Options
Downloads
Patches
Plain Diff
ASTbuilder: add checks to only append typedefs from the same source
parent
71869dc0
Branches
typedefs
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/java/se/lth/control/labcomm/ASTbuilder.java
+7
-3
7 additions, 3 deletions
lib/java/se/lth/control/labcomm/ASTbuilder.java
lib/java/se/lth/control/labcomm/TypeDefParser.java
+51
-8
51 additions, 8 deletions
lib/java/se/lth/control/labcomm/TypeDefParser.java
with
58 additions
and
11 deletions
lib/java/se/lth/control/labcomm/ASTbuilder.java
+
7
−
3
View file @
3fbc9aee
...
...
@@ -158,13 +158,17 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
/** Create a labcomm AST for the ParsedTypeDef d, including
* all declarations from p.
*
* This copies the declarations in p, and creates a new AST.
*
* If d is a sampleDecl, include the typedefs it depends on.
* If p is not null, and the source of d matches the
* TypeDefParser this ASTbuilder was created for,
* creates a new AST containing the declarations in p
* and d and (if d is a sampleDecl) its dependencies.
*
* Otherwise, makeProgram(d)
*/
public
Program
makeProgram
(
TypeDefParser
.
ParsedTypeDef
d
,
Program
p
)
{
if
(
p
!=
null
)
{
if
(
p
!=
null
&&
d
.
checkSource
(
tdp
)
)
{
return
makeProgram
(
d
,
p
.
getDecls
().
fullCopy
());
}
else
{
return
makeProgram
(
d
);
...
...
This diff is collapsed.
Click to expand it.
lib/java/se/lth/control/labcomm/TypeDefParser.java
+
51
−
8
View file @
3fbc9aee
...
...
@@ -2,8 +2,9 @@ package se.lth.control.labcomm;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.Iterator
;
import
java.util.NoSuchElementException
;
import
java.io.ByteArrayInputStream
;
import
java.io.DataInputStream
;
...
...
@@ -17,6 +18,10 @@ import se.lth.control.labcomm.TypeBinding;
public
class
TypeDefParser
implements
TypeDef
.
Handler
,
TypeBinding
.
Handler
{
public
interface
TypeDefListener
{
void
onTypeDef
(
ParsedTypeDef
d
);
}
static
class
SelfBinding
extends
TypeDef
{
private
int
sampleIndex
;
...
...
@@ -48,10 +53,25 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
}
}
public
interface
TypeDefListener
{
void
onTypeDef
(
ParsedTypeDef
d
);
static
class
EmptyIterator
<
T
>
implements
java
.
util
.
Iterator
{
@Override
public
boolean
hasNext
()
{
return
false
;
}
@Override
public
T
next
()
{
throw
new
NoSuchElementException
();
}
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
}
static
EmptyIterator
<
ParsedTypeDef
>
emptyIterator
=
new
EmptyIterator
<>();
private
HashMap
<
Integer
,
TypeDef
>
typeDefs
;
private
HashMap
<
Integer
,
Integer
>
typeBindings
;
private
HashSet
<
TypeDefListener
>
listeners
;
...
...
@@ -403,10 +423,22 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
private
int
idx
;
private
String
name
;
private
ParsedType
type
;
private
final
TypeDefParser
source
;
ParsedTypeDef
(
TypeDefParser
source
,
int
idx
,
String
name
){
this
.
source
=
source
;
this
.
idx
=
idx
;
this
.
name
=
name
;
}
ParsedTypeDef
(
TypeDefParser
source
,
int
idx
,
String
name
,
ParsedType
type
)
{
this
(
source
,
idx
,
name
);
this
.
type
=
type
;
}
ParsedTypeDef
(
int
idx
,
String
name
){
this
.
idx
=
idx
;
this
.
name
=
name
;
this
(
null
,
idx
,
name
);
}
ParsedTypeDef
(
int
idx
,
String
name
,
ParsedType
type
)
{
...
...
@@ -414,6 +446,16 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
this
.
type
=
type
;
}
/** @return true if source is same as
*/
public
boolean
checkSource
(
TypeDefParser
o
)
{
boolean
result
=
source
==
o
;
System
.
err
.
println
(
"ParsedTypeDef.checkSource: source = "
+
source
);
System
.
err
.
println
(
"ParsedTypeDef.checkSource: o "
+
o
);
System
.
err
.
println
(
"ParsedTypeDef.checkSource: "
+
result
);
return
result
;
}
/** To be overridden in ParsedSampleDef
*/
public
boolean
isSampleDef
()
{
...
...
@@ -421,7 +463,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
}
Iterator
<
ParsedTypeDef
>
getDepIterator
()
{
throw
new
Error
(
"ParseTypeDef has no dependencies"
);
return
emptyIterator
;
}
void
setType
(
ParsedType
type
)
{
...
...
@@ -465,8 +507,9 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
public
class
ParsedSampleDef
extends
ParsedTypeDef
{
private
HashSet
<
ParsedTypeDef
>
deps
;
ParsedSampleDef
(
ParsedTypeDef
td
)
{
super
(
td
.
getIndex
(),
td
.
getName
(),
td
.
getType
());
super
(
td
.
source
,
td
.
getIndex
(),
td
.
getName
(),
td
.
getType
());
this
.
deps
=
new
HashSet
<
ParsedTypeDef
>();
}
...
...
@@ -496,7 +539,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
private
LinkedList
<
TypeDef
>
typeStack
;
ParsedTypeDef
newTypeDef
()
{
currentParsed
=
new
ParsedTypeDef
(
getCurrentIndex
(),
getCurrentName
());
currentParsed
=
new
ParsedTypeDef
(
TypeDefParser
.
this
,
getCurrentIndex
(),
getCurrentName
());
return
currentParsed
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment