Skip to content

annotate private class members as needed#50

Merged
andrurogerz merged 13 commits intocompnerd:mainfrom
andrurogerz:private-methods
May 5, 2025
Merged

annotate private class members as needed#50
andrurogerz merged 13 commits intocompnerd:mainfrom
andrurogerz:private-methods

Conversation

@andrurogerz
Copy link
Collaborator

Purpose

Updates IDS to add the export annotation to private class members that require export. Previously, only public and protected member were exported.

Overview

This patch makes the following changes:

  1. Implements VisitCallExpr to visit method calls identified in the AST. Common code for exporting method declarations was refactored from VisitFunctionDecl into private method export_function_if_needed, which is now also called by VisitCallExpr for private methods
  2. Implements VisitDeclRefExpr to visit static fields references identified in the AST. Common code for exporting variable declarations was refactored from VisitVarDecl into export_variable_if_needed, which is now also called by VisitDeclRefExpr for private static fields.
  3. Tracks every method, variable, and record declaration that needs an export annotation added in a simple DeclSet class. An instance of this class replaces previous in_exported_record_ member bool that was used to track if the "current" record was being exported. This change simplifies things and ensures that we don't mistakenly export the same symbol twice now that there are multiple codepaths.
  4. Implements a new is_in_system_header method to ensure we skip processing any declarations in system headers (this was missing from VisitVarDecl).
  5. Adds a bunch of new test cases that fail without the other changes.

Background

Private methods in a class must be exported when they are referenced by inline function definitions. For example:

class Example {
public:
  inline int publicMethod() {
    return privateMethod();
  }

private:
  int privateMethod();
};

Similarly, private static fields must in a class must also be exported when referenced by inline function definitions. For example:

class Example {
public:
  inline int publicMethod() {
    return privateStaticFiedl;
  }

private:
  static int privateStaticField;
};

Validation

  1. Ran existing and new tests on Linux and Windows.
  2. Ran on LLVM Support library headers and compared results with previous results & manual fixups. Results matched what I had done manually before (+ a few annotations I missed).

@andrurogerz andrurogerz requested a review from compnerd April 30, 2025 15:50
@andrurogerz andrurogerz requested a review from compnerd April 30, 2025 21:01
@andrurogerz
Copy link
Collaborator Author

@compnerd any additional feedback on this one? I have been using it locally to code-mod in annotations, and it is working great.

Copy link
Owner

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor tweaks, but this looks good now! Thanks for persisting through this.

@andrurogerz andrurogerz merged commit c48649d into compnerd:main May 5, 2025
2 checks passed
@andrurogerz andrurogerz deleted the private-methods branch May 5, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants