@@ -79,8 +79,9 @@ static const char *strip_quotes(CBMArena *a, const char *text) {
7979
8080// Callee suffixes for IRIS Python interop string-dispatch. Kept at file scope
8181// (not inside the function) to satisfy cppcheck variableScope.
82- static const char * s_py_dispatch_suffixes [] = {".classMethodValue" , ".classMethodVoid" ,
83- ".classMethodBoolean" , ".classMethodObject" , NULL };
82+ static const char * s_py_dispatch_suffixes [] = {".classMethodValue" , ".classMethodVoid" ,
83+ ".classMethodBoolean" , ".classMethodObject" ,
84+ ".invokeClassMethod" , NULL };
8485
8586// Per-language callee-suffix dispatch table — returns a NULL-terminated list of
8687// method-name suffixes whose calls should be resolved by extracting class+method
@@ -2039,6 +2040,49 @@ static const char *extract_nth_string_arg(CBMExtractCtx *ctx, TSNode args, uint3
20392040 return NULL ;
20402041}
20412042
2043+ // IRIS embedded Python names the target class in the receiver:
2044+ // iris.cls("Pkg.Class").Method(...) calls ClassMethod Pkg.Class.Method.
2045+ // Returns "Pkg.Class.Method", or NULL unless the receiver is iris.cls() with
2046+ // a string-literal first argument. A non-literal class names nothing, so it
2047+ // gets no class-qualified callee rather than a guessed one.
2048+ static const char * python_iris_cls_callee (CBMExtractCtx * ctx , TSNode call_node ) {
2049+ TSNode fn = ts_node_child_by_field_name (call_node , TS_FIELD ("function" ));
2050+ if (ts_node_is_null (fn ) || strcmp (ts_node_type (fn ), "attribute" ) != 0 ) {
2051+ return NULL ;
2052+ }
2053+ TSNode recv = ts_node_child_by_field_name (fn , TS_FIELD ("object" ));
2054+ TSNode meth = ts_node_child_by_field_name (fn , TS_FIELD ("attribute" ));
2055+ if (ts_node_is_null (recv ) || ts_node_is_null (meth ) || strcmp (ts_node_type (recv ), "call" ) != 0 ) {
2056+ return NULL ;
2057+ }
2058+ TSNode recv_fn = ts_node_child_by_field_name (recv , TS_FIELD ("function" ));
2059+ TSNode recv_args = ts_node_child_by_field_name (recv , TS_FIELD ("arguments" ));
2060+ if (ts_node_is_null (recv_fn ) || ts_node_is_null (recv_args ) ||
2061+ ts_node_named_child_count (recv_args ) == 0 ) {
2062+ return NULL ;
2063+ }
2064+ const char * recv_text = cbm_node_text (ctx -> arena , recv_fn , ctx -> source );
2065+ if (!recv_text || strcmp (recv_text , "iris.cls" ) != 0 ) {
2066+ return NULL ;
2067+ }
2068+ TSNode cls_arg = ts_node_named_child (recv_args , 0 );
2069+ if (!is_string_like (ts_node_type (cls_arg ))) {
2070+ return NULL ;
2071+ }
2072+ // Plain quoted literals only: an f-string or other prefixed string is a
2073+ // "string" node too, but its text is not a class name.
2074+ char * cls_text = cbm_node_text (ctx -> arena , cls_arg , ctx -> source );
2075+ if (!cls_text || (cls_text [0 ] != '"' && cls_text [0 ] != '\'' )) {
2076+ return NULL ;
2077+ }
2078+ const char * cls = strip_and_validate_string_arg (ctx -> arena , cls_text );
2079+ const char * mth = cbm_node_text (ctx -> arena , meth , ctx -> source );
2080+ if (!cls || !cls [0 ] || !mth || !mth [0 ]) {
2081+ return NULL ;
2082+ }
2083+ return cbm_arena_sprintf (ctx -> arena , "%s.%s" , cls , mth );
2084+ }
2085+
20422086// --- Unified handler: called once per node by the cursor walk ---
20432087
20442088// Process a keyword argument (keyword_argument or pair node).
@@ -3887,6 +3931,16 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
38873931 }
38883932 }
38893933
3934+ // #1260: iris.cls("Pkg.X").M() names its class, so the qualified
3935+ // callee replaces the bare one. Keeping both would let the bare
3936+ // name weak-match an unrelated same-named method.
3937+ if (ctx -> language == CBM_LANG_PYTHON ) {
3938+ const char * iris_callee = python_iris_cls_callee (ctx , node );
3939+ if (iris_callee ) {
3940+ call .callee_name = iris_callee ;
3941+ call .is_method = false;
3942+ }
3943+ }
38903944 cbm_calls_push (& ctx -> result -> calls , ctx -> arena , call );
38913945 invocation = describe_emitted_primary_call (node , & callee );
38923946
0 commit comments