58
58
* A container class used to store per-node attributes used by the instrumentation framework.
59
59
*
60
60
*/
61
- public class InteropMap implements TruffleObject {
61
+ public final class InteropMap implements TruffleObject {
62
+ private final Map <String , Object > data ;
62
63
63
- private final Map <String , Object > data = new HashMap <>();
64
+ public InteropMap (Map <String , Object > data ) {
65
+ this .data = data ;
66
+ }
64
67
65
68
@ Override
66
69
public ForeignAccess getForeignAccess () {
67
70
return InteropMapMRForeign .ACCESS ;
68
71
}
69
72
70
73
@ TruffleBoundary
71
- public void addProperty (String name , Object value ) {
72
- data .put (name , value );
73
- }
74
-
75
- @ TruffleBoundary
76
- public int size () {
74
+ private int size () {
77
75
return data .size ();
78
76
}
79
77
80
78
@ TruffleBoundary
81
- public Object getProperty (String name ) {
82
- assert hasProperty (name );
79
+ private Object getKey (String name ) {
80
+ assert hasKey (name );
83
81
return data .get (name );
84
82
}
85
83
86
84
@ TruffleBoundary
87
- public boolean hasProperty (String name ) {
85
+ private boolean hasKey (String name ) {
88
86
return data .containsKey (name );
89
87
}
90
88
91
89
@ TruffleBoundary
92
- public TruffleObject getPropertyNames () {
90
+ private TruffleObject getKeys () {
93
91
return new InteropArray (data .keySet ().toArray ());
94
92
}
95
93
96
94
@ TruffleBoundary
97
95
public static InteropMap fromPDict (PDict dict ) {
98
- InteropMap map = new InteropMap ();
96
+ Map < String , Object > map = new HashMap <> ();
99
97
for (DictEntry s : dict .getDictStorage ().entries ()) {
100
- map .addProperty (s .getKey ().toString (), s .getValue ());
98
+ map .put (s .getKey ().toString (), s .getValue ());
101
99
}
102
- return map ;
100
+ return new InteropMap ( map ) ;
103
101
}
104
102
105
103
@ TruffleBoundary
106
104
public static InteropMap fromPythonObject (PythonObject globals ) {
107
- InteropMap map = new InteropMap ();
105
+ Map < String , Object > map = new HashMap <> ();
108
106
for (String name : globals .getAttributeNames ()) {
109
- map .addProperty (name , globals .getAttribute (name ));
107
+ map .put (name , globals .getAttribute (name ));
110
108
}
111
- return map ;
109
+ return new InteropMap ( map ) ;
112
110
}
113
111
114
112
static boolean isInstance (TruffleObject object ) {
@@ -120,30 +118,29 @@ static class InteropMapMR {
120
118
121
119
@ Resolve (message = "READ" )
122
120
abstract static class Read extends Node {
123
- public Object access (InteropMap target , String key ) {
124
- return target .getProperty (key );
121
+ Object access (InteropMap target , String key ) {
122
+ return target .getKey (key );
125
123
}
126
124
}
127
125
128
126
@ Resolve (message = "HAS_KEYS" )
129
127
abstract static class HasKeys extends Node {
130
-
131
- public Object access (@ SuppressWarnings ("unused" ) Object target ) {
128
+ boolean access (@ SuppressWarnings ("unused" ) Object target ) {
132
129
return true ;
133
130
}
134
131
}
135
132
136
133
@ Resolve (message = "KEYS" )
137
134
abstract static class Keys extends Node {
138
- public Object access (InteropMap target ) {
139
- return target .getPropertyNames ();
135
+ Object access (InteropMap target ) {
136
+ return target .getKeys ();
140
137
}
141
138
}
142
139
143
140
@ Resolve (message = "KEY_INFO" )
144
141
abstract static class KeyInfoMR extends Node {
145
- public Object access (InteropMap target , Object key ) {
146
- if (key instanceof String && target .hasProperty ((String ) key )) {
142
+ int access (InteropMap target , Object key ) {
143
+ if (key instanceof String && target .hasKey ((String ) key )) {
147
144
return KeyInfo .READABLE ;
148
145
} else {
149
146
return 0 ;
0 commit comments