39
39
import com .oracle .graal .python .builtins .objects .str .PString ;
40
40
import com .oracle .graal .python .nodes .ErrorMessages ;
41
41
import com .oracle .graal .python .nodes .PRaiseNode ;
42
- import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
43
- import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
44
42
import com .oracle .graal .python .nodes .attributes .SetAttributeNode ;
45
43
import com .oracle .graal .python .nodes .control .GetNextNode ;
46
44
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
@@ -69,7 +67,6 @@ public class ImportStarNode extends AbstractImportNode {
69
67
@ Child private GetItemNode getItemNode ;
70
68
@ Child private PythonObjectLibrary pythonLibrary ;
71
69
@ Child private CastToJavaStringNode castToStringNode ;
72
- @ Child private GetAnyAttributeNode readNode ;
73
70
@ Child private GetNextNode nextNode ;
74
71
@ Child private PRaiseNode raiseNode ;
75
72
@@ -97,14 +94,6 @@ private void writeAttribute(VirtualFrame frame, PythonObject globals, String nam
97
94
}
98
95
}
99
96
100
- private Object readAttribute (VirtualFrame frame , Object object , String name ) {
101
- if (readNode == null ) {
102
- CompilerDirectives .transferToInterpreterAndInvalidate ();
103
- readNode = insert (GetAttributeNode .GetAnyAttributeNode .create ());
104
- }
105
- return readNode .executeObject (frame , object , name );
106
- }
107
-
108
97
public ImportStarNode (String moduleName , int level ) {
109
98
this .moduleName = moduleName ;
110
99
this .level = level ;
@@ -131,22 +120,22 @@ public void executeVoid(VirtualFrame frame) {
131
120
throw new IllegalStateException (e );
132
121
}
133
122
} else {
123
+ PythonObjectLibrary pol = ensurePythonLibrary ();
134
124
try {
135
- Object attrAll = readAttribute ( frame , importedModule , __ALL__ );
125
+ Object attrAll = pol . lookupAttributeStrict ( importedModule , frame , __ALL__ );
136
126
int n = ensurePythonLibrary ().lengthWithState (attrAll , PArguments .getThreadState (frame ));
137
127
for (int i = 0 ; i < n ; i ++) {
138
128
Object attrName = ensureGetItemNode ().executeWith (frame , attrAll , i );
139
- writeAttributeToLocals (frame , (PythonModule ) importedModule , locals , attrName , true );
129
+ writeAttributeToLocals (frame , pol , (PythonModule ) importedModule , locals , attrName , true );
140
130
}
141
131
} catch (PException e ) {
142
132
e .expectAttributeError (ensureIsAttributeErrorProfile ());
143
133
assert importedModule instanceof PythonModule ;
144
- PythonObjectLibrary pol = ensurePythonLibrary ();
145
134
Object keysIterator = pol .getIterator (pol .getDict (importedModule ));
146
135
while (true ) {
147
136
try {
148
137
Object key = ensureGetNextNode ().execute (frame , keysIterator );
149
- writeAttributeToLocals (frame , (PythonModule ) importedModule , locals , key , false );
138
+ writeAttributeToLocals (frame , pol , (PythonModule ) importedModule , locals , key , false );
150
139
} catch (PException iterException ) {
151
140
iterException .expectStopIteration (ensureIsStopIterationErrorProfile ());
152
141
break ;
@@ -156,17 +145,17 @@ public void executeVoid(VirtualFrame frame) {
156
145
}
157
146
}
158
147
159
- private void writeAttributeToLocals (VirtualFrame frame , PythonModule importedModule , PythonObject locals , Object attrName , boolean fromAll ) {
148
+ private void writeAttributeToLocals (VirtualFrame frame , PythonObjectLibrary pol , PythonModule importedModule , PythonObject locals , Object attrName , boolean fromAll ) {
160
149
try {
161
150
String name = ensureCastToStringNode ().execute (attrName );
162
151
// skip attributes with leading '__' if there was no '__all__' attribute (see
163
152
// 'ceval.c: import_all_from')
164
153
if (fromAll || !PString .startsWith (name , "__" )) {
165
- Object moduleAttr = readAttribute ( frame , importedModule , name );
154
+ Object moduleAttr = pol . lookupAttribute ( importedModule , frame , name );
166
155
writeAttribute (frame , locals , name , moduleAttr );
167
156
}
168
157
} catch (CannotCastException cce ) {
169
- throw raise ( PythonBuiltinClassType . TypeError , fromAll ? ErrorMessages .ITEM_IN_S_MUST_BE_STRING : ErrorMessages .KEY_IN_S_MUST_BE_STRING ,
158
+ throw raiseTypeError ( fromAll ? ErrorMessages .ITEM_IN_S_MUST_BE_STRING : ErrorMessages .KEY_IN_S_MUST_BE_STRING ,
170
159
moduleName , fromAll ? __ALL__ : __DICT__ , attrName );
171
160
}
172
161
}
@@ -211,12 +200,12 @@ private IsBuiltinClassProfile ensureIsStopIterationErrorProfile() {
211
200
return isStopIterationProfile ;
212
201
}
213
202
214
- private PException raise ( PythonBuiltinClassType errType , String format , Object ... args ) {
203
+ private PException raiseTypeError ( String format , Object ... args ) {
215
204
if (raiseNode == null ) {
216
205
CompilerDirectives .transferToInterpreterAndInvalidate ();
217
206
raiseNode = insert (PRaiseNode .create ());
218
207
}
219
- throw raiseNode .raise (errType , format , args );
208
+ throw raiseNode .raise (PythonBuiltinClassType . TypeError , format , args );
220
209
}
221
210
222
211
private GetNextNode ensureGetNextNode () {
0 commit comments