-
Notifications
You must be signed in to change notification settings - Fork 55
Аникин Максим. Лабораторная работа 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
base: course-spring-2025
Are you sure you want to change the base?
Conversation
@@ -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 | |||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
#include <algorithm> | ||
#include <string> |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
[](const clang::ParmVarDecl *param) { | ||
llvm::outs() << param->getType().getAsString(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[](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> { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y("data_type", "Analyzes AST and prints information about data types"); | |
Y("data_type", "Analyzes AST and prints information about data types"); | |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
|
||
out << "|" << getAccessSpecifierString(var->getAccess()); | ||
|
||
out << ")\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out << "|" << getAccessSpecifierString(var->getAccess()); | |
out << ")\n"; | |
out << "|" << getAccessSpecifierString(var->getAccess()) << ")\n"; |
Данный плагин для clang производит анализ пользовательских типов данных.
Плагин проверяет тип данных на поля, методы и наследование.
Выводит о них информацию: тип данных, доступ, характеристики.