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
69b2c47a
Commit
69b2c47a
authored
5 months ago
by
Jan Gruteser
Browse files
Options
Downloads
Patches
Plain Diff
add utility methods in TypeChecker
for unification and set/getType
parent
d42053e9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/tla2b/analysis/TypeChecker.java
+58
-15
58 additions, 15 deletions
src/main/java/de/tla2b/analysis/TypeChecker.java
with
58 additions
and
15 deletions
src/main/java/de/tla2b/analysis/TypeChecker.java
+
58
−
15
View file @
69b2c47a
...
@@ -266,21 +266,6 @@ public class TypeChecker extends BuiltInOPs implements BBuildIns, TranslationGlo
...
@@ -266,21 +266,6 @@ public class TypeChecker extends BuiltInOPs implements BBuildIns, TranslationGlo
throw
new
NotImplementedException
(
exprNode
.
toString
(
2
));
throw
new
NotImplementedException
(
exprNode
.
toString
(
2
));
}
}
private
static
void
setType
(
SemanticNode
node
,
TLAType
type
,
int
paramId
)
{
node
.
setToolObject
(
paramId
,
type
);
if
(
type
instanceof
AbstractHasFollowers
)
{
((
AbstractHasFollowers
)
type
).
addFollower
(
node
);
}
}
public
static
void
setType
(
SemanticNode
node
,
TLAType
type
)
{
setType
(
node
,
type
,
TYPE_ID
);
}
public
static
TLAType
getType
(
SemanticNode
n
)
{
return
(
TLAType
)
n
.
getToolObject
(
TYPE_ID
);
}
private
TLAType
visitOpApplNode
(
OpApplNode
n
,
TLAType
expected
)
throws
TLA2BException
{
private
TLAType
visitOpApplNode
(
OpApplNode
n
,
TLAType
expected
)
throws
TLA2BException
{
switch
(
n
.
getOperator
().
getKind
())
{
switch
(
n
.
getOperator
().
getKind
())
{
...
@@ -1520,4 +1505,62 @@ public class TypeChecker extends BuiltInOPs implements BBuildIns, TranslationGlo
...
@@ -1520,4 +1505,62 @@ public class TypeChecker extends BuiltInOPs implements BBuildIns, TranslationGlo
}
}
}
}
}
}
/*
* Utility methods
*/
private
static
void
setTypeAndFollowers
(
SemanticNode
node
,
TLAType
type
,
int
paramId
)
{
setType
(
node
,
type
,
paramId
);
if
(
type
instanceof
AbstractHasFollowers
)
{
((
AbstractHasFollowers
)
type
).
addFollower
(
node
);
}
}
private
static
void
setTypeAndFollowers
(
SemanticNode
node
,
TLAType
type
)
{
setTypeAndFollowers
(
node
,
type
,
TYPE_ID
);
}
private
static
void
setType
(
SemanticNode
node
,
TLAType
type
,
int
paramId
)
{
node
.
setToolObject
(
paramId
,
type
);
}
public
static
void
setType
(
SemanticNode
node
,
TLAType
type
)
{
setType
(
node
,
type
,
TYPE_ID
);
}
private
static
TLAType
getType
(
SemanticNode
n
,
int
paramId
)
{
return
(
TLAType
)
n
.
getToolObject
(
paramId
);
}
public
static
TLAType
getType
(
SemanticNode
n
)
{
return
getType
(
n
,
TYPE_ID
);
}
private
TLAType
unify
(
TLAType
toUnify
,
TLAType
expected
,
String
opMsg
,
SemanticNode
n
)
throws
TypeErrorException
{
TLAType
found
=
toUnify
;
DebugUtils
.
printDebugMsg
(
"Unify "
+
found
+
" and "
+
expected
+
" at '"
+
opMsg
+
"' ("
+
n
.
getLocation
()
+
")"
);
try
{
found
=
found
.
unify
(
expected
);
}
catch
(
UnificationException
e
)
{
throw
new
TypeErrorException
(
String
.
format
(
"Expected '%s', found '%s' at %s,%n%s"
,
expected
,
found
,
"'"
+
opMsg
+
"'"
,
n
.
getLocation
()));
}
return
found
;
}
private
TLAType
unify
(
TLAType
toUnify
,
TLAType
expected
,
OpApplNode
n
)
throws
TypeErrorException
{
return
unify
(
toUnify
,
expected
,
n
.
getOperator
().
getName
().
toString
(),
n
);
}
private
TLAType
unifyAndSetTypeWithFollowers
(
TLAType
toUnify
,
TLAType
expected
,
String
opMsg
,
SemanticNode
n
)
throws
TypeErrorException
{
TLAType
found
=
unify
(
toUnify
,
expected
,
opMsg
,
n
);
setTypeAndFollowers
(
n
,
found
);
return
found
;
}
private
TLAType
unifyAndSetType
(
TLAType
toUnify
,
TLAType
expected
,
String
opMsg
,
SemanticNode
n
)
throws
TypeErrorException
{
TLAType
found
=
unify
(
toUnify
,
expected
,
opMsg
,
n
);
setType
(
n
,
found
);
return
found
;
}
}
}
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