Skip to content

Kozyreva Ekaterina lab1 option 1 #8

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
84e732d
kulikov lab1 (#1)
AveZorgen Mar 4, 2024
5a86d17
Иванов Никита ФИ3. Лабораторная работа № 1. (#2)
Atikin-NT Mar 10, 2024
d6f98a1
Zakharov Artem. Lab 1. Option 4. (#4)
un1i Mar 14, 2024
dc4b1b7
Sharapov Georgiy. First Lab. (#3)
nol0n Mar 15, 2024
84d74da
Kuznetsov Artyom (Laboratory work №1 option №1) (#5)
Kuznetsov-Artyom Mar 15, 2024
d54cd5d
Soloninko Andrey. Lab №1, var 1 (#7)
Manymoera Mar 15, 2024
847c794
Fix clang-format check (#11)
aobolensk Mar 15, 2024
a2de4ee
Volodin Evgeniy. Lab №1. Option №1. (#9)
evldn Mar 15, 2024
8ac9ea3
Sadikov Damir. Lab №1. Var 3 (#12)
Damlrca Mar 17, 2024
9631799
Fix for Volodin Evgeniy. Lab №1. Option №1. (#14)
evldn Mar 17, 2024
74dd97f
Fix clang-format error code (#23)
aobolensk Mar 17, 2024
e47fbee
Turn back clang-format's output in check log (#25)
m-ly4 Mar 18, 2024
8f9a2ad
Korablev Nikita. Lab №1. Option №4. (#8)
NikitaKorablev Mar 18, 2024
579a90c
Bodrov Daniil. Lab 1. Task 1 (#21)
overinvest Mar 18, 2024
c4295cb
Kulagin Aleksandr / lab1 / var 2 (#24)
mahbhlddnhakkh Mar 18, 2024
a9aa535
Kostin Artem. Lab #1. Var 3. (#15)
aartyomm Mar 18, 2024
e894020
Fixed CMakeFiles for Korablev Nikita's plugin (#30)
NikitaKorablev Mar 18, 2024
618a1e9
Первая лабораторная, вариант 1, Бендюжко Татьяна (#16)
Tatiana567 Mar 18, 2024
a8f384e
Polozov Vladislav Lab1 Var3 (#10)
Mortus19 Mar 18, 2024
b1d0b2d
Durandin Vladimir. Lab №1. Option №2 (#20)
Sturmannn Mar 18, 2024
28c5e02
Petrov Maksim. Lab 1. Var 3. (#19)
soileks Mar 18, 2024
765beff
Ivan_Vasilev_lab_1_var_3 (#22)
AdAndRoll Mar 19, 2024
d1fe1c0
Kulagin Aleksandr / lab1 / var 2 IMPROVEMENT (#33)
mahbhlddnhakkh Mar 19, 2024
ca90c8b
Shishkina Valeriya. Lab #1. Var #1. (#18)
ShLera04 Mar 19, 2024
eb203b6
Kulaev Evgeny. Laboratory work №1. Option №2 (#6)
zcotti Mar 19, 2024
3bc0b3b
Alexseev Danila. 1 lab option №3 (#17)
lxvdnl Mar 19, 2024
a85dba4
commit
Mar 19, 2024
065c6c5
commit
Mar 20, 2024
ab689f9
commit
Mar 20, 2024
adb3b8c
Update CMakeLists.txt
kth-vyu Mar 28, 2024
7735204
change request solved
kth-vyu Mar 30, 2024
9be251c
change solved
kth-vyu Mar 30, 2024
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/alexseev_danila/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_llvm_library(depWarningPluginAlexseev MODULE deprecatedWarning.cpp PLUGIN_TOOL clang)

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

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

using namespace clang;

class DepFuncVisitor : public RecursiveASTVisitor<DepFuncVisitor> {
private:
ASTContext *Context;
std::string ExcludeFunc;

public:
explicit DepFuncVisitor(ASTContext *Context, std::string ExcludeFunc)
: Context(Context), ExcludeFunc(ExcludeFunc) {}

bool VisitFunctionDecl(FunctionDecl *Func) {
if (Func->getNameInfo().getAsString().find("deprecated") !=
std::string::npos &&
Func->getNameInfo().getAsString() != ExcludeFunc) {
DiagnosticsEngine &Diags = Context->getDiagnostics();
size_t CustomDiagID =
Diags.getCustomDiagID(DiagnosticsEngine::Warning,
"Function contains 'deprecated' in its name");
Diags.Report(Func->getLocation(), CustomDiagID)
<< Func->getNameInfo().getAsString();
}
return true;
}
};

class DepFuncConsumer : public ASTConsumer {
std::string ExcludeFunc;

public:
explicit DepFuncConsumer(std::string ExcludeFunc)
: ExcludeFunc(ExcludeFunc) {}

void HandleTranslationUnit(ASTContext &Context) override {
DepFuncVisitor Visitor(&Context, ExcludeFunc);
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
}
};

class DepFuncPlugin : public PluginASTAction {
protected:
std::string ExcludeFunc = "";

std::unique_ptr<ASTConsumer>
CreateASTConsumer(CompilerInstance &Compiler,
llvm::StringRef InFile) override {
return std::make_unique<DepFuncConsumer>(ExcludeFunc);
}
bool ParseArgs(const CompilerInstance &Compiler,
const std::vector<std::string> &Args) override {
for (unsigned i = 0, e = Args.size(); i != e; ++i) {
if (Args[i].substr(0, 9) == "-exclude=") {
ExcludeFunc = Args[i].substr(9);
}
}
return true;
}
};

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

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

set(CLANG_TEST_DEPS "Myfirstplugin" ${CLANG_TEST_DEPS} PARENT_SCOPE)
66 changes: 66 additions & 0 deletions clang/labs/lab1/bend_tatiana/PrintFunctionNames.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Decl.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/LLVM.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Sema/Sema.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
#include <string>
#include <vector>
using namespace clang;

namespace {

class MyASTConsumer : public ASTConsumer {

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

bool VisitCXXRecordDecl(CXXRecordDecl *CxxRDecl) {
if (CxxRDecl->isClass() || CxxRDecl->isStruct()) {
llvm::outs() << CxxRDecl->getNameAsString() << "\n";

for (auto It = CxxRDecl->decls_begin(); It != CxxRDecl->decls_end();
++It)
if (FieldDecl *NDecl = dyn_cast<FieldDecl>(*It))
llvm::outs() << "|_ " << NDecl->getNameAsString() << "\n";
else if (VarDecl *NDecl = dyn_cast<VarDecl>(*It))
llvm::outs() << "|_ " << NDecl->getNameAsString() << "\n";

llvm::outs() << "\n";
}
return true;
}
} V;
V.TraverseDecl(Context.getTranslationUnitDecl());
}
};

class PrintFunctionNamesAction : public PluginASTAction {
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef) override {
return std::make_unique<MyASTConsumer>();
}

bool ParseArgs(const CompilerInstance &CI,
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 << "Plugin prints names of classes and their fields\n";
}
};

} // namespace

static FrontendPluginRegistry::Add<PrintFunctionNamesAction>
X("classprinter", "prints names of classes and their fields");
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");
Loading