Skip to content

Аникин Максим. Лабораторная работа 1. Clang Ast. Вариант 1. #47

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 3 commits into
base: course-spring-2025
Choose a base branch
from

Conversation

decl1
Copy link

@decl1 decl1 commented Mar 19, 2025

Данный плагин для clang производит анализ пользовательских типов данных.
Плагин проверяет тип данных на поля, методы и наследование.
Выводит о них информацию: тип данных, доступ, характеристики.

@@ -0,0 +1,42 @@
// RUN: %clang_cc1 -load %llvmshlibdir/DataType_Anikin_Maksim_FIIT2_ClangAST%pluginext -plugin data_type -fsyntax-only %s 2>&1 | FileCheck %s

Choose a reason for hiding this comment

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

Consider adding tests for union covered in your pass

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@decl1 decl1 requested a review from aobolensk March 20, 2025 13:27
Comment on lines +6 to +7
#include <algorithm>
#include <string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need these header files?

#include <algorithm>
#include <string>

namespace anikin_m_ast {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the context of a plugin, then it is better to use an anonymous namespace

Comment on lines +69 to +71
[](const clang::ParmVarDecl *param) {
llvm::outs() << param->getType().getAsString();
}
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
[](const clang::ParmVarDecl *param) {
llvm::outs() << param->getType().getAsString();
}
[&out](const clang::ParmVarDecl *param) {
out << param->getType().getAsString();
}

}
}

class ASTWalker final : public clang::RecursiveASTVisitor<ASTWalker> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is better to follow the generally accepted naming when writing your classes (Visitor, Consumer, Action)

} // namespace anikin_m_ast

static clang::FrontendPluginRegistry::Add<anikin_m_ast::ASTPluginAction>
Y("data_type", "Analyzes AST and prints information about data 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
Y("data_type", "Analyzes AST and prints information about data types");
Y("data_type", "Analyzes AST and prints information about data 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 {};
};

namespace anikin_m_ast {

std::string getAccessSpecifierString(clang::AccessSpecifier access) {
if (access == clang::AS_public)
Copy link

Choose a reason for hiding this comment

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

switch..case is a bit more effective here.

Comment on lines +43 to +46

out << "|" << getAccessSpecifierString(var->getAccess());

out << ")\n";
Copy link

Choose a reason for hiding this comment

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

Suggested change
out << "|" << getAccessSpecifierString(var->getAccess());
out << ")\n";
out << "|" << getAccessSpecifierString(var->getAccess()) << ")\n";

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.

4 participants