Skip to content
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

Ulyanov Daniil Lab1 Var4 #16

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/nn-cmplr-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install clang-format
run: |
sudo apt-get install -y clang-format
- name: Run clang-format
run: |
git-clang-format --diff `git merge-base ${GITHUB_SHA} ${GITHUB_BASE_REF}`
git-clang-format --diff `git merge-base ${GITHUB_SHA} origin/${GITHUB_BASE_REF}` ${GITHUB_SHA} 2>&1 | tee log.txt
exit `grep -c diff log.txt`
clang-tidy:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ add_subdirectory(runtime)

option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
add_subdirectory(examples)
add_subdirectory(labs)

if(APPLE)
# this line is needed as a cleanup to ensure that any CMakeCaches with the old
Expand Down
9 changes: 9 additions & 0 deletions clang/labs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FILE(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
FOREACH(child ${children})
IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child})
add_subdirectory(${child})
ENDIF()
ENDFOREACH()

set(CLANG_TEST_DEPS ${CLANG_TEST_DEPS} PARENT_SCOPE)
message("CLANG_TEST_DEPS ${CLANG_TEST_DEPS}")
10 changes: 10 additions & 0 deletions clang/labs/lab1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(CLANG_PLUGIN_SUPPORT)
FILE(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
FOREACH(child ${children})
IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child})
add_subdirectory(${child})
ENDIF()
ENDFOREACH()

set(CLANG_TEST_DEPS ${CLANG_TEST_DEPS} PARENT_SCOPE)
endif()
14 changes: 14 additions & 0 deletions clang/labs/lab1/bodrov_daniil/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_llvm_library(ClassFieldPrinter MODULE ClassPrinter.cpp PLUGIN_TOOL clang)

if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS
Support
)
clang_target_link_libraries(ClassFieldPrinter PRIVATE
clangAST
clangBasic
clangFrontend
)
endif()

set(CLANG_TEST_DEPS "ClassFieldPrinter" ${CLANG_TEST_DEPS} PARENT_SCOPE)
104 changes: 104 additions & 0 deletions clang/labs/lab1/bodrov_daniil/ClassPrinter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "llvm/Support/raw_ostream.h"

namespace {

class MemberInfoPrinter {
public:
void print(const clang::ValueDecl *Member, const std::string &MemberType) {
llvm::outs() << "|_ " << Member->getNameAsString() << ' ';
llvm::outs() << '(' << Member->getType().getAsString() << '|';
llvm::outs() << getAccessSpecifierAsString(Member)
<< (MemberType == "field" ? ")" : ("|" + MemberType + ")"))
<< "\n";
}

private:
std::string getAccessSpecifierAsString(const clang::ValueDecl *Member) {
switch (Member->getAccess()) {
case clang::AS_public:
return "public";
case clang::AS_protected:
return "protected";
case clang::AS_private:
return "private";
default:
return "unknown";
}
}
};

class UserTypePrinter {
public:
void print(clang::CXXRecordDecl *UserType) {
llvm::outs() << UserType->getNameAsString() << ' ';
llvm::outs() << (UserType->isStruct() ? "(struct" : "(class");
llvm::outs() << (UserType->isTemplated() ? "|template)" : ")") << '\n';
}
};

class ClassMembersPrinter final
: public clang::RecursiveASTVisitor<ClassMembersPrinter> {
public:
explicit ClassMembersPrinter(clang::ASTContext *Context)
: ClassContext(Context) {}

bool VisitCXXRecordDecl(clang::CXXRecordDecl *Declaration) {
if (Declaration->isStruct() || Declaration->isClass()) {
UserPrinter.print(Declaration);

for (const auto &Decl : Declaration->decls()) {
if (auto Field = llvm::dyn_cast<clang::FieldDecl>(Decl)) {
MemberPrinter.print(Field, "field");
} else if (auto Var = llvm::dyn_cast<clang::VarDecl>(Decl)) {
if (Var->isStaticDataMember()) {
MemberPrinter.print(Var, "static");
}
} else if (auto Method = llvm::dyn_cast<clang::CXXMethodDecl>(Decl)) {
MemberPrinter.print(Method, "method");
}
}
llvm::outs() << '\n';
}
return true;
}

private:
clang::ASTContext *ClassContext;
MemberInfoPrinter MemberPrinter;
UserTypePrinter UserPrinter;
};

class ClassMembersConsumer final : public clang::ASTConsumer {
public:
explicit ClassMembersConsumer(clang::ASTContext *Context)
: Visitor(Context) {}

void HandleTranslationUnit(clang::ASTContext &Context) override {
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
}

private:
ClassMembersPrinter Visitor;
};

class ClassFieldPrinterAction final : public clang::PluginASTAction {
public:
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &Ci, llvm::StringRef) override {
return std::make_unique<ClassMembersConsumer>(&Ci.getASTContext());
}

bool ParseArgs(const clang::CompilerInstance &Ci,
const std::vector<std::string> &Args) override {
return true;
}
};

} // namespace

static clang::FrontendPluginRegistry::Add<ClassFieldPrinterAction>
X("class-field-printer", "Prints all members of the class");
14 changes: 14 additions & 0 deletions clang/labs/lab1/ivanov_nikita/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_llvm_library(clangDepMatcher MODULE deprecatedMatcher.cpp PLUGIN_TOOL clang)

if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS
Support
)
clang_target_link_libraries(clangDepMatcher PRIVATE
clangAST
clangBasic
clangFrontend
)
endif()

set(CLANG_TEST_DEPS "clangDepMatcher" ${CLANG_TEST_DEPS} PARENT_SCOPE)
59 changes: 59 additions & 0 deletions clang/labs/lab1/ivanov_nikita/deprecatedMatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendPluginRegistry.h"

using namespace clang;

class DepConsumer : public ASTConsumer {
CompilerInstance &Instance;

public:
explicit DepConsumer(CompilerInstance &CI) : Instance(CI) {}

void HandleTranslationUnit(ASTContext &Context) override {
struct Visitor : public RecursiveASTVisitor<Visitor> {
ASTContext *Context;

Visitor(ASTContext *Context) : Context(Context) {}

bool VisitFunctionDecl(FunctionDecl *Func) {
if (Func->getNameInfo().getAsString().find("deprecated") !=
std::string::npos) {
DiagnosticsEngine &Diags = Context->getDiagnostics();
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Warning, "Deprecated in function name");
Diags.Report(Func->getLocation(), DiagID)
<< Func->getNameInfo().getAsString();
}
return true;
}
} v(&Instance.getASTContext());

v.TraverseDecl(Context.getTranslationUnitDecl());
}
};

class DeprecatedPlugin : public PluginASTAction {
protected:
std::unique_ptr<ASTConsumer>
CreateASTConsumer(CompilerInstance &Compiler,
llvm::StringRef InFile) override {
return std::make_unique<DepConsumer>(Compiler);
}

bool ParseArgs(const CompilerInstance &Compiler,
const std::vector<std::string> &args) override {
if (!args.empty() && args[0] == "help")
PrintHelp(llvm::errs());

return true;
}

void PrintHelp(llvm::raw_ostream &ros) {
ros << "Deprecated Plugin version 1.0\n";
}
};

static FrontendPluginRegistry::Add<DeprecatedPlugin> X("deprecated-match",
"deprecated match");
14 changes: 14 additions & 0 deletions clang/labs/lab1/korablev_nikita/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_llvm_library(RenamedIdPlugin MODULE RenameIdentificator.cpp PLUGIN_TOOL clang)

if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS
Support
)
clang_target_link_libraries(RenamedIdPlugin PRIVATE
clangAST
clangBasic
clangFrontend
)
endif()

set(CLANG_TEST_DEPS "RenamedIdPlugin" ${CLANG_TEST_DEPS} PARENT_SCOPE)
Loading