forked from runtimeverification/k
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKLabelConstant.java
More file actions
78 lines (63 loc) · 2.03 KB
/
KLabelConstant.java
File metadata and controls
78 lines (63 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2013-2016 K Team. All Rights Reserved.
package org.kframework.kil;
import java.util.concurrent.ConcurrentHashMap;
/**
* AST representation of a KLabel constant.
*/
public class KLabelConstant extends KLabel {
/**
* HashMap caches the constants to ensure uniqueness.
*/
private static final ConcurrentHashMap<String, KLabelConstant> cache = new ConcurrentHashMap<>();
/**
* Static function for creating AST term representation of KLabel constants. The function caches the KLabelConstant objects; subsequent calls with the same label return
* the same object. As opposed to "of", does not inspect for list of productions. Should be used for builtins only.
*
* @param label
* string representation of the KLabel; must not be '`' escaped;
* @return AST term representation the KLabel;
*/
public static KLabelConstant of(String label) {
assert label != null;
return cache.computeIfAbsent(label, x -> new KLabelConstant(x));
}
/**
* Checks whether this label corresponds to a predicate
* @return true if the label denotes a predicate or false otherwise
*/
public boolean isPredicate() {
return label.startsWith("is");
}
public String getLabel() {
return label;
}
/* un-escaped label */
private final String label;
public KLabelConstant(String label) {
this.label = label;
}
@Override
public ASTNode shallowCopy() {
/* this object is immutable */
return this;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof KLabelConstant)) {
return false;
}
KLabelConstant kLabelConstant = (KLabelConstant) object;
return label.equals(kLabelConstant.label);
}
@Override
public int hashCode() {
return label.hashCode();
}
@Override
public String toString() {
return getLabel();
}
}