Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tla2bAST
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
tla2bAST
Commits
a1f570aa
Commit
a1f570aa
authored
1 year ago
by
Jan Gruteser
Browse files
Options
Downloads
Patches
Plain Diff
support unary minus for reals
also needs to be simplified
parent
ad0a223a
No related branches found
No related tags found
No related merge requests found
Pipeline
#134724
passed
1 year ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/de/tla2b/analysis/TypeChecker.java
+30
-5
30 additions, 5 deletions
src/main/java/de/tla2b/analysis/TypeChecker.java
src/test/java/de/tla2b/typechecking/standardmodules/TestModuleReals.java
+11
-5
11 additions, 5 deletions
...e/tla2b/typechecking/standardmodules/TestModuleReals.java
with
41 additions
and
10 deletions
src/main/java/de/tla2b/analysis/TypeChecker.java
+
30
−
5
View file @
a1f570aa
...
...
@@ -1285,14 +1285,39 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
case
B_OPCODE_uminus:
// -x
{
// TODO: simplify
TLAType
type
;
if
(
expected
instanceof
RealType
)
{
try
{
RealType
.
getInstance
().
unify
(
expected
);
type
=
RealType
.
getInstance
();
}
catch
(
UnificationException
e
)
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found REAL at '-',%n%s"
,
expected
,
n
.
getLocation
()));
}
}
else
if
(
expected
instanceof
IntType
)
{
try
{
IntType
.
getInstance
().
unify
(
expected
);
type
=
IntType
.
getInstance
();
}
catch
(
UnificationException
e
)
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found INTEGER at '-',%n%s"
,
expected
,
n
.
getLocation
()));
}
visitExprOrOpArgNode
(
n
.
getArgs
()[
0
],
IntType
.
getInstance
());
return
IntType
.
getInstance
();
}
else
if
(
expected
instanceof
UntypedType
)
{
IntType
.
getInstance
().
unify
(
expected
);
type
=
IntType
.
getInstance
();
try
{
visitExprOrOpArgNode
(
n
.
getArgs
()[
0
],
type
);
}
catch
(
TypeErrorException
e
)
{
RealType
.
getInstance
().
unify
(
expected
);
type
=
RealType
.
getInstance
();
}
}
else
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found INTEGER at '-',%n%s"
,
expected
,
n
.
getLocation
()));
}
visitExprOrOpArgNode
(
n
.
getArgs
()[
0
],
type
);
return
type
;
}
/*
...
...
This diff is collapsed.
Click to expand it.
src/test/java/de/tla2b/typechecking/standardmodules/TestModuleReals.java
+
11
−
5
View file @
a1f570aa
...
...
@@ -35,8 +35,6 @@ public class TestModuleReals {
TestUtil
.
typeCheckString
(
module
);
}
// FIXME: support:
@Ignore
/*
* unary minus: -x
*/
...
...
@@ -44,12 +42,20 @@ public class TestModuleReals {
public
void
unifyUnaryMinusReal
()
throws
TLA2BException
{
final
String
module
=
"-------------- MODULE Testing ----------------\n"
+
"EXTENDS Reals \n"
+
"CONSTANTS k
, k2
\n"
+
"ASSUME k = -
k2
\n"
+
"================================="
;
+
"CONSTANTS k \n"
+
"ASSUME k = -
1.0
\n"
+
"================================="
;
TestTypeChecker
t
=
TestUtil
.
typeCheckString
(
module
);
assertEquals
(
"REAL"
,
t
.
getConstantType
(
"k"
));
assertEquals
(
"REAL"
,
t
.
getConstantType
(
"k2"
));
}
@Test
(
expected
=
TypeErrorException
.
class
)
public
void
unifyUnaryMinusRealError
()
throws
TLA2BException
{
final
String
module
=
"-------------- MODULE Testing ----------------\n"
+
"EXTENDS Reals \n"
+
"ASSUME -1 = -1.0 \n"
+
"================================="
;
TestTypeChecker
t
=
TestUtil
.
typeCheckString
(
module
);
}
@Test
(
expected
=
TypeErrorException
.
class
)
...
...
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