Fix mod_scanner usage information to consider aliases

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • Programmability 2025-06-23
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Cursors in cindex/clang that refer to the usage of some declaration provide information such as USRs, semantic parent, and type.

      When the usage (e.g. a CALL_EXPR or DECL_REF_EXPR) refers to a declaration using an alias for its outer scope (AKA some part of the qualified name of the usage uses an alias), the cindex Cursor does not hold any immediate information about the alias. Instead, the USR, type, and semantic parent provide information about the underlying type.

       

      Example:

      some.cpp

      func() {
          A::b();
      }

      some.h

      namespace detail {
          class impl {
          public:
              static void b() { }
          }
      }
      
      using A = typename detail::impl;

       

      The cursor that refers to the call to `A::b();` does not have any immediate information about "A" (in the tree below, this cursor would be "DECL_REF_EXPR: b"). I suspect this is because all syntactic "sugar" is removed.

      NAMESPACE: detail
      ├── CLASS_DECL: impl
      │   ├── CXX_ACCESS_SPEC_DECL: <anonymous>
      │   ├── CXX_METHOD: b
      │   │   ├── COMPOUND_STMT: <anonymous>
      TYPE_ALIAS_DECL: A
      ├── NAMESPACE_REF: detail
      ├── TYPE_REF: class detail::impl
      FUNCTION_DECL: func
      ├── COMPOUND_STMT: <anonymous>
      │   ├── CALL_EXPR: b
      │   │   ├── UNEXPOSED_EXPR: b
      │   │   │   ├── DECL_REF_EXPR: b
      │   │   │   │   ├── TYPE_REF: A 

      "DECL_REF_EXPR: b" would be a typical cursor location where we create our usage information. If we print information about the Declaration created from the cursor for "DECL_REF_EXPR: b", we see that it does not refer to "A" in any way:

      Decl(display_name='::detail::impl::b()', usr='c:@N@detail@S@impl@F@b#S', raw_usr='c:@N@detail@S@impl@F@b#S', kind='CXX_METHOD', spelling='b', sem_par='c:@N@detail@S@impl', lex_par='c:@N@detail@S@impl', used_from={})

      Furthermore, none of the various clang functions give us the "desugared" information with "A".

      In this particular case, we can rely on the information that "TYPE_REF: A" is a child of our "DECL_REF_EXPR: b" cursor, but this issue can appear in various other scenarios.

       

      Our goal is to create usage information for the declaration of "A::b" with the type alias "A", but this doesn't exist (and "A::b" has no USR in clang). One possible solution is to modify mod_scanner.py in a "clang"-friendly way, where we traverse through the Index's tree to find references to the alias. In our "DecoratedCursor.parent" calculation, we can substitute the alias declaration (TYPE_ALIAS_DECL: A) as the parent.

            Assignee:
            Alex Li
            Reporter:
            Alex Li
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: