Skip to content

Дудченко Олеся. Лабораторная работа 1. Clang AST. Вариант 1. #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: course-spring-2025
Choose a base branch
from

Conversation

Uzzika
Copy link

@Uzzika Uzzika commented Mar 19, 2025

Это плагин для Clang, который анализирует C++ код и выводит информацию о классах и структурах. Вот что он делает:
TypeInfoVisitor
Задача:
Ищет все классы и структуры в коде. Для каждого класса или структуры:
Выводит имя.
Если есть родительские классы, выводит их имена.
Выводит все поля (переменные) с их типами и доступом (public, protected, private).
Выводит все методы (функции) с их возвращаемыми типами, доступом и дополнительной информацией (например, virtual, override, pure).
Игнорирует автоматически созданные методы (например, конструкторы по умолчанию).

TypeInfoConsumer
Управляет обходом кода.
Использует TypeInfoVisitor для анализа всех классов и структур в файле.

TypeInfoAction
Точка входа для плагина.
Создает TypeInfoConsumer и передает ему данные для анализа.

@Uzzika Uzzika requested review from aobolensk and m-ly4 as code owners March 19, 2025 17:12
Comment on lines +68 to +70
if (isPureVirtual) {
llvm::outs() << "|pure";
}

Choose a reason for hiding this comment

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

I guess, if the method is not virtual it cannot be pure & virtual at the same time either

void sleep() override { /* something */ }
void eat() override { /* something */ }
void work() { /* something */ }
};

Choose a reason for hiding this comment

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

Please, consider adding your own test cases as well

return true;
}

llvm::outs() << record->getName();
Copy link
Collaborator

Choose a reason for hiding this comment

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

More duplication code
Use auto &os = llvm::outs()

} // namespace

static clang::FrontendPluginRegistry::Add<TypeInfoAction>
X("type_info_plugin", "Prints information about user-defined types");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
X("type_info_plugin", "Prints information about user-defined types");
X("type_info_plugin", "Prints information about user-defined types");

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add test please

struct A {};

struct B {
  struct A {};
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants