Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Bodrov Daniil. Lab 1. Task 1 #21

Merged
merged 18 commits into from
Mar 18, 2024

Conversation

overinvest
Copy link

@overinvest overinvest commented Mar 17, 2024

This code represents a plugin for Clang that allows outputting information about class members in C++. The program relies on using the Clang tooling and its Abstract Syntax Tree (AST) to analyze and output information about structures and classes in the source code.

The program consists of several components:

  • MemberInfoPrinter: This class is responsible for printing information about class members, such as fields, methods, and static members. It accesses the Clang AST to retrieve information about each member and prints its name, type, and access specifier.

  • UserTypePrinter: This class is responsible for printing information about user-defined types, such as structures and classes. It determines the type of each user-defined type and prints the corresponding information.

  • ClassMembersPrinter: This class is a subclass of clang::RecursiveASTVisitor and traverses the AST to find and print information about class members. It uses MemberInfoPrinter and UserTypePrinter to print information about members and types.

  • ClassMembersConsumer: This class is an ASTConsumer that processes the AST and runs ClassMembersPrinter for each detected class or structure.

  • ClassFieldPrinterAction: This class represents the action of the Clang plugin. It creates an instance of ClassMembersConsumer to process the AST and output information about class members.

The program allows analyzing C++ source code and outputting information about class members, their types, and access specifiers.

Example:

// CHECK: TestClass (class)
class TestClass {
public:
  int publicInt; // CHECK-NEXT: |_ publicInt (int|public)
  static int publicStaticInt; // CHECK-NEXT: |_ publicStaticInt (int|public|static)
  void publicFunc() {} // CHECK-NEXT: |_ publicFunc (void (void)|public|method)

private:
  int privateInt; // CHECK-NEXT: |_ privateInt (int|private)
  static int privateStaticInt; // CHECK-NEXT: |_ privateStaticInt (int|private|static)
  void privateFunc() {} // CHECK-NEXT: |_ privateFunc (void (void)|private|method)
};

In the provided example, a class TestClass is shown with various members, including public, private, static variables, and methods. The CHECK comments represent the expected output of the program in the format defined in the main code.

@overinvest
Copy link
Author

Could I get some feedback on what I need to fix in the code? I'm not quite understanding why clang-format is throwing an error

@m-ly4
Copy link

m-ly4 commented Mar 18, 2024

Could I get some feedback on what I need to fix in the code? I'm not quite understanding why clang-format is throwing an error

I'm glad that you fixed format errors on your own. For the future, you can just execute clang-format tool on diff of your patch and automatically apply all it's suggestions.

@m-ly4 m-ly4 merged commit 579a90c into NN-complr-tech:course-spring-2024 Mar 18, 2024
@overinvest overinvest deleted the dev-lab1 branch March 18, 2024 18:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants