Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tlc4b
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
tlc4b
Commits
0cafd422
Verified
Commit
0cafd422
authored
5 months ago
by
Miles Vella
Browse files
Options
Downloads
Patches
Plain Diff
Remove strict scope check vor assign substitutions: it broke double function assignments
see test
parent
6cf8f0c7
No related branches found
No related tags found
No related merge requests found
Pipeline
#152328
passed
5 months ago
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/de/tlc4b/analysis/MachineContext.java
+7
-33
7 additions, 33 deletions
src/main/java/de/tlc4b/analysis/MachineContext.java
src/test/java/de/tlc4b/analysis/ScopeTest.java
+13
-1
13 additions, 1 deletion
src/test/java/de/tlc4b/analysis/ScopeTest.java
with
20 additions
and
34 deletions
src/main/java/de/tlc4b/analysis/MachineContext.java
+
7
−
33
View file @
0cafd422
...
...
@@ -48,7 +48,7 @@ public class MachineContext extends DepthFirstAdapter {
private
AOperationsMachineClause
operationMachineClause
;
private
AAssertionsMachineClause
assertionsMachineClause
;
private
ArrayList
<
LinkedHash
Map
<
String
,
Node
>>
contextTable
;
private
List
<
Map
<
String
,
Node
>>
contextTable
;
protected
final
Hashtable
<
Node
,
Node
>
referencesTable
;
...
...
@@ -311,7 +311,7 @@ public class MachineContext extends DepthFirstAdapter {
pExpression
.
apply
(
this
);
}
for
(
int
i
=
contextTable
.
size
()
-
1
;
i
>=
0
;
i
--)
{
LinkedHash
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
i
);
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
i
);
if
(
currentScope
.
containsKey
(
name
))
{
this
.
referencesTable
.
put
(
node
,
currentScope
.
get
(
name
));
return
;
...
...
@@ -397,7 +397,7 @@ public class MachineContext extends DepthFirstAdapter {
private
void
putLocalVariableIntoCurrentScope
(
AIdentifierExpression
node
)
throws
ScopeException
{
String
name
=
Utils
.
getTIdentifierListAsString
(
node
.
getIdentifier
());
LinkedHash
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
contextTable
.
size
()
-
1
);
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
contextTable
.
size
()
-
1
);
if
(
currentScope
.
containsKey
(
name
))
{
throw
new
ScopeException
(
"Duplicate Identifier: "
+
name
);
}
else
{
...
...
@@ -409,7 +409,7 @@ public class MachineContext extends DepthFirstAdapter {
public
void
caseAIdentifierExpression
(
AIdentifierExpression
node
)
{
String
name
=
Utils
.
getTIdentifierListAsString
(
node
.
getIdentifier
());
for
(
int
i
=
contextTable
.
size
()
-
1
;
i
>=
0
;
i
--)
{
LinkedHash
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
i
);
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
i
);
if
(
currentScope
.
containsKey
(
name
))
{
this
.
referencesTable
.
put
(
node
,
currentScope
.
get
(
name
));
return
;
...
...
@@ -422,7 +422,7 @@ public class MachineContext extends DepthFirstAdapter {
public
void
caseAPrimedIdentifierExpression
(
APrimedIdentifierExpression
node
)
{
String
name
=
Utils
.
getTIdentifierListAsString
(
node
.
getIdentifier
());
for
(
int
i
=
contextTable
.
size
()
-
1
;
i
>=
0
;
i
--)
{
LinkedHash
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
i
);
Map
<
String
,
Node
>
currentScope
=
contextTable
.
get
(
i
);
if
(
currentScope
.
containsKey
(
name
))
{
this
.
referencesTable
.
put
(
node
,
currentScope
.
get
(
name
));
return
;
...
...
@@ -596,34 +596,8 @@ public class MachineContext extends DepthFirstAdapter {
@Override
public
void
caseAAssignSubstitution
(
AAssignSubstitution
node
)
{
ArrayList
<
LinkedHashMap
<
String
,
Node
>>
temp
=
contextTable
;
{
List
<
PExpression
>
copy
=
new
ArrayList
<>(
node
.
getLhsExpression
());
ArrayList
<
LinkedHashMap
<
String
,
Node
>>
varTable
=
new
ArrayList
<>();
varTable
.
add
(
variables
);
for
(
PExpression
e
:
copy
)
{
if
(
e
instanceof
AFunctionExpression
)
{
contextTable
=
varTable
;
((
AFunctionExpression
)
e
).
getIdentifier
().
apply
(
this
);
// full context table
contextTable
=
temp
;
for
(
Node
n
:
((
AFunctionExpression
)
e
).
getParameters
())
{
n
.
apply
(
this
);
}
}
else
{
contextTable
=
temp
;
// TODO outputparameter + variables
e
.
apply
(
this
);
}
}
}
{
contextTable
=
temp
;
List
<
PExpression
>
copy
=
new
ArrayList
<>(
node
.
getRhsExpressions
());
for
(
PExpression
e
:
copy
)
{
e
.
apply
(
this
);
}
}
super
.
caseAAssignSubstitution
(
node
);
// TODO: check if only writable variables are written to?
}
@Override
...
...
This diff is collapsed.
Click to expand it.
src/test/java/de/tlc4b/analysis/ScopeTest.java
+
13
−
1
View file @
0cafd422
...
...
@@ -4,6 +4,8 @@ import org.junit.Ignore;
import
org.junit.Test
;
import
static
de
.
tlc4b
.
util
.
TestUtil
.
checkMachine
;
import
static
de
.
tlc4b
.
util
.
TestUtil
.
translate
;
import
de.tlc4b.exceptions.ScopeException
;
public
class
ScopeTest
{
...
...
@@ -152,4 +154,14 @@ public class ScopeTest {
checkMachine
(
machine
);
}
@Test
public
void
testDoubleFunctionAssign
()
throws
Exception
{
String
machine
=
"MACHINE test\n"
+
"VARIABLES f\n"
+
"INVARIANT f : 1..3 +-> (1..3 +-> BOOL)\n"
+
"INITIALISATION f := {}\n"
+
"OPERATIONS put(x, y, value) = SELECT x : 1..3 & y : 1..3 & value : BOOL THEN f(x)(y) := value END\n"
+
"END"
;
translate
(
machine
);
}
}
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