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
80e60b92
Commit
80e60b92
authored
Apr 26, 2024
by
Jan Gruteser
Browse files
Options
Downloads
Patches
Plain Diff
support arithmetic operators for both reals and integers
should be simplified but fixes tests for now
parent
59852b07
No related branches found
No related tags found
No related merge requests found
Pipeline
#134688
passed
Apr 26, 2024
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/tla2b/analysis/TypeChecker.java
+30
-11
30 additions, 11 deletions
src/main/java/de/tla2b/analysis/TypeChecker.java
with
30 additions
and
11 deletions
src/main/java/de/tla2b/analysis/TypeChecker.java
+
30
−
11
View file @
80e60b92
...
@@ -1193,25 +1193,44 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
...
@@ -1193,25 +1193,44 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
case
B_OPCODE_div:
// /
case
B_OPCODE_div:
// /
case
B_OPCODE_mod:
// % modulo
case
B_OPCODE_mod:
// % modulo
case
B_OPCODE_exp:
{
// x hoch y, x^y
case
B_OPCODE_exp:
{
// x hoch y, x^y
TLAType
type
;
// TODO: Simplify
if
(
expected
instanceof
RealType
)
{
try
{
try
{
RealType
.
getInstance
().
unify
(
expected
);
RealType
.
getInstance
().
unify
(
expected
);
for
(
int
i
=
0
;
i
<
n
.
getArgs
().
length
;
i
++)
{
type
=
RealType
.
getInstance
();
visitExprOrOpArgNode
(
n
.
getArgs
()[
i
],
RealType
.
getInstance
());
}
return
RealType
.
getInstance
();
}
catch
(
UnificationException
e
)
{
}
catch
(
UnificationException
e
)
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found REAL at '%s',%n%s"
,
expected
,
n
.
getOperator
().
getName
(),
n
.
getLocation
()));
}
}
else
if
(
expected
instanceof
IntType
)
{
try
{
try
{
IntType
.
getInstance
().
unify
(
expected
);
IntType
.
getInstance
().
unify
(
expected
);
type
=
IntType
.
getInstance
();
}
catch
(
UnificationException
ue
)
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found INTEGER at '%s',%n%s"
,
expected
,
n
.
getOperator
().
getName
(),
n
.
getLocation
()));
}
}
else
if
(
expected
instanceof
UntypedType
)
{
IntType
.
getInstance
().
unify
(
expected
);
type
=
IntType
.
getInstance
();
try
{
for
(
int
i
=
0
;
i
<
n
.
getArgs
().
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
n
.
getArgs
().
length
;
i
++)
{
visitExprOrOpArgNode
(
n
.
getArgs
()[
i
],
IntType
.
getInstance
()
);
visitExprOrOpArgNode
(
n
.
getArgs
()[
i
],
type
);
}
}
return
IntType
.
getInstance
();
}
catch
(
TypeErrorException
e
)
{
}
catch
(
UnificationException
e2
)
{
RealType
.
getInstance
().
unify
(
expected
);
type
=
RealType
.
getInstance
();
}
}
else
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found INTEGER at '%s',%n%s"
,
expected
,
throw
new
TypeErrorException
(
String
.
format
(
"Expected %s, found INTEGER at '%s',%n%s"
,
expected
,
n
.
getOperator
().
getName
(),
n
.
getLocation
()));
n
.
getOperator
().
getName
(),
n
.
getLocation
()));
}
}
for
(
int
i
=
0
;
i
<
n
.
getArgs
().
length
;
i
++)
{
visitExprOrOpArgNode
(
n
.
getArgs
()[
i
],
type
);
}
}
return
type
;
}
}
case
B_OPCODE_dotdot:
// ..
case
B_OPCODE_dotdot:
// ..
...
...
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