This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
forked from NN-complr-tech/llvm
-
Notifications
You must be signed in to change notification settings - Fork 59
Kurdina Julia. Lab 1. Var 3 #65
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ebb2ffd
first_commit
JKurdina a7e6168
second_commit
JKurdina 9583fcc
format_changes
JKurdina 7c8f16c
changes
JKurdina f082baa
fix format
JKurdina 37742dc
fix format
JKurdina 9ec71e2
fix format
JKurdina 826a57c
new changes
JKurdina e3805ed
fix format
JKurdina f43f548
edits
JKurdina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/AST/RecursiveASTVisitor.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
#include "clang/Frontend/FrontendPluginRegistry.h" | ||
|
||
using namespace clang; | ||
|
||
class AddWarningConsumer : public ASTConsumer { | ||
CompilerInstance &Instance; | ||
bool withoutClass; | ||
|
||
public: | ||
AddWarningConsumer(CompilerInstance &Instance, bool withoutClass) | ||
: Instance(Instance), withoutClass(withoutClass) {} | ||
|
||
void HandleTranslationUnit(ASTContext &context) override { | ||
|
||
struct Visitor : public RecursiveASTVisitor<Visitor> { | ||
ASTContext *context; | ||
bool withoutClass; | ||
Visitor(ASTContext *context, bool withoutClass) | ||
: context(context), withoutClass(withoutClass) {} | ||
|
||
bool VisitFunctionDecl(FunctionDecl *FD) { | ||
if (!withoutClass || withoutClass && !FD->isCXXClassMember()) { | ||
std::string name = FD->getNameInfo().getAsString(); | ||
if (name.find("deprecated") != std::string::npos) { | ||
DiagnosticsEngine &diag = context->getDiagnostics(); | ||
unsigned diagID = diag.getCustomDiagID( | ||
DiagnosticsEngine::Warning, "Function or method is deprecated"); | ||
SourceLocation location = FD->getLocation(); | ||
diag.Report(location, diagID); | ||
} | ||
} | ||
return true; | ||
} | ||
} v(&Instance.getASTContext(), withoutClass); | ||
|
||
v.TraverseDecl(context.getTranslationUnitDecl()); | ||
} | ||
}; | ||
|
||
class AddWarningAction : public PluginASTAction { | ||
protected: | ||
bool withoutClass = false; | ||
std::unique_ptr<ASTConsumer> | ||
CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override { | ||
return std::make_unique<AddWarningConsumer>(CI, withoutClass); | ||
} | ||
|
||
bool ParseArgs(const CompilerInstance &CI, | ||
const std::vector<std::string> &args) override { | ||
for (const auto &arg : args) { | ||
if (arg == "-notCheckClass") { | ||
withoutClass = true; | ||
} | ||
} | ||
return true; | ||
m-ly4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
static FrontendPluginRegistry::Add<AddWarningAction> X("warn_dep", "warn_dep"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_llvm_library(addWarning MODULE AddWarning.cpp PLUGIN_TOOL clang) | ||
|
||
if(WIN32 OR CYGWIN) | ||
set(LLVM_LINK_COMPONENTS | ||
Support | ||
) | ||
clang_target_link_libraries(addWarning PRIVATE | ||
clangAST | ||
clangBasic | ||
clangFrontend | ||
) | ||
endif() | ||
|
||
set(CLANG_TEST_DEPS "addWarning" ${CLANG_TEST_DEPS} PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: split-file %s %t | ||
// RUN: %clang_cc1 -load %llvmshlibdir/addWarning%pluginext -plugin warn_dep %t/with_notCheckClass.cpp -plugin-arg-warn_dep -notCheckClass 2>&1 | FileCheck %t/with_notCheckClass.cpp | ||
// RUN: %clang_cc1 -load %llvmshlibdir/addWarning%pluginext -plugin warn_dep %t/without_notCheckClass.cpp 2>&1 | FileCheck %t/without_notCheckClass.cpp | ||
|
||
//--- with_notCheckClass.cpp | ||
|
||
// CHECK: warning: Function or method is deprecated | ||
void deprecated(); | ||
|
||
// CHECK: warning: Function or method is deprecated | ||
void function_name_is_deprecated(); | ||
|
||
// CHECK-NOT: warning: Function or method is deprecated | ||
void function(); | ||
|
||
// CHECK-NOT: warning: Function or method is deprecated | ||
void function_depr(); | ||
|
||
class CheckClass { | ||
// CHECK-NOT: warning: Function or method is deprecated | ||
void deprecated(); | ||
// CHECK-NOT: warning: Function or method is deprecated | ||
void function(); | ||
}; | ||
|
||
//--- without_notCheckClass.cpp | ||
|
||
// CHECK: warning: Function or method is deprecated | ||
void deprecated(); | ||
|
||
// CHECK: warning: Function or method is deprecated | ||
void function_name_is_deprecated(); | ||
|
||
// CHECK-NOT: warning: Function or method is deprecated | ||
void function(); | ||
|
||
// CHECK-NOT: warning: Function or method is deprecated | ||
void function_depr(); | ||
|
||
class CheckClass { | ||
// CHECK: warning: Function or method is deprecated | ||
void deprecated(); | ||
// CHECK-NOT: warning: Function or method is deprecated | ||
void function(); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
||
already means that withoutClass == true