31
31
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICT__ ;
32
32
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__FUNC__ ;
33
33
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__KWDEFAULTS__ ;
34
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__NAME__ ;
35
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__QUALNAME__ ;
34
36
import static com .oracle .graal .python .nodes .SpecialMethodNames .__GETATTRIBUTE__ ;
35
37
import static com .oracle .graal .python .nodes .SpecialMethodNames .__GET__ ;
36
38
import static com .oracle .graal .python .nodes .SpecialMethodNames .__REDUCE__ ;
46
48
import com .oracle .graal .python .builtins .objects .PNone ;
47
49
import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
48
50
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
51
+ import com .oracle .graal .python .builtins .objects .module .PythonModule ;
49
52
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins ;
50
53
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
54
+ import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
51
55
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
52
56
import com .oracle .graal .python .nodes .ErrorMessages ;
53
57
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
60
64
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryBuiltinNode ;
61
65
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
62
66
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
67
+ import com .oracle .graal .python .nodes .util .CannotCastException ;
68
+ import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
63
69
import com .oracle .graal .python .runtime .exception .PException ;
64
70
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
65
71
import com .oracle .truffle .api .dsl .Cached ;
@@ -133,7 +139,7 @@ public abstract static class ReprNode extends PythonUnaryBuiltinNode {
133
139
@ Specialization (limit = "3" )
134
140
Object reprMethod (VirtualFrame frame , PMethod self ,
135
141
@ CachedLibrary ("self.getSelf()" ) PythonObjectLibrary lib ,
136
- @ Cached ("createGetAttributeNode( )" ) GetAttributeNode getNameAttrNode ,
142
+ @ Cached ("create(__QUALNAME__ )" ) GetAttributeNode getNameAttrNode ,
137
143
@ Cached GetNameNode getTypeNameNode ) {
138
144
String typeName = getTypeNameNode .execute (lib .getLazyPythonClass (self .getSelf ()));
139
145
return strFormat ("<bound method %s of %s object at 0x%x>" , getNameAttrNode .executeObject (frame , self .getFunction ()), typeName , PythonAbstractObject .systemHashCode (self .getSelf ()));
@@ -143,10 +149,6 @@ Object reprMethod(VirtualFrame frame, PMethod self,
143
149
private static String strFormat (String fmt , Object ... objects ) {
144
150
return String .format (fmt , objects );
145
151
}
146
-
147
- protected static GetAttributeNode createGetAttributeNode () {
148
- return GetAttributeNode .create (SpecialAttributeNames .__QUALNAME__ , null );
149
- }
150
152
}
151
153
152
154
@ Builtin (name = __DEFAULTS__ , minNumOfPositionalArgs = 1 , isGetter = true )
@@ -194,4 +196,47 @@ PMethod doGeneric(@SuppressWarnings("unused") PMethod self, Object obj, @Suppres
194
196
return factory ().createMethod (obj , self .getFunction ());
195
197
}
196
198
}
199
+
200
+ @ Builtin (name = __NAME__ , minNumOfPositionalArgs = 1 , isGetter = true )
201
+ @ GenerateNodeFactory
202
+ public abstract static class MethodName extends PythonUnaryBuiltinNode {
203
+ @ Specialization
204
+ Object getName (VirtualFrame frame , PMethod method ,
205
+ @ Cached ("create(__NAME__)" ) GetAttributeNode getNameAttrNode ) {
206
+ return getNameAttrNode .executeObject (frame , method .getFunction ());
207
+ }
208
+ }
209
+
210
+ @ Builtin (name = __QUALNAME__ , minNumOfPositionalArgs = 1 , isGetter = true )
211
+ @ GenerateNodeFactory
212
+ public abstract static class MethodQualName extends PythonUnaryBuiltinNode {
213
+ @ Specialization
214
+ Object getQualName (VirtualFrame frame , PMethod method ,
215
+ @ Cached ("create(__QUALNAME__)" ) GetAttributeNode getQualNameAttrNode ,
216
+ @ Cached ("create(__NAME__)" ) GetAttributeNode getNameAttrNode ,
217
+ @ Cached TypeNodes .IsTypeNode isTypeNode ,
218
+ @ Cached CastToJavaStringNode castToJavaStringNode ,
219
+ @ CachedLibrary ("method.getSelf()" ) PythonObjectLibrary pol ) {
220
+ Object self = method .getSelf ();
221
+ String selfName = castToJavaStringNode .execute (getNameAttrNode .executeObject (frame , self ));
222
+ if (self instanceof PythonModule ) {
223
+ return selfName ;
224
+ }
225
+
226
+ Object type = isTypeNode .execute (self ) ? self : pol .getLazyPythonClass (self );
227
+ String typeQualName ;
228
+ try {
229
+ typeQualName = castToJavaStringNode .execute (getQualNameAttrNode .executeObject (frame , type ));
230
+ } catch (CannotCastException e ) {
231
+ throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .IS_NOT_A , __QUALNAME__ , "unicode object" );
232
+ }
233
+
234
+ return getQualNameGeneric (typeQualName , selfName );
235
+ }
236
+
237
+ @ TruffleBoundary
238
+ private static Object getQualNameGeneric (String typeQualName , String name ) {
239
+ return String .format ("%s.%s" , typeQualName , name );
240
+ }
241
+ }
197
242
}
0 commit comments