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
Veselov Ilya lab 1 var 1 #36
Merged
m-ly4
merged 13 commits into
NN-complr-tech:course-spring-2024
from
spells39:veselov_ilya
Mar 21, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7e8cc07
Veselov Ilya var 1
spells39 fa0c746
fix
spells39 3994942
fix
spells39 73bd8bd
fix
spells39 a9ec444
fix
spells39 931fd36
fix clang-format
spells39 d9319be
added static member printing test, test with instantiation of templat…
spells39 7fdc865
some fix
spells39 56572ba
some fix
spells39 6d8724f
fix
spells39 d70a188
another fix
spells39 3989acd
Update clang/test/lab1/veselov_ilya/test.cpp
spells39 91f2147
Merge branch 'course-spring-2024' into veselov_ilya
spells39 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,14 @@ | ||
add_llvm_library(PrintClassDescPlugin MODULE printClass.cpp PLUGIN_TOOL clang) | ||
|
||
if(WIN32 OR CYGWIN) | ||
set(LLVM_LINK_COMPONENTS | ||
Support | ||
) | ||
clang_target_link_libraries(PrintClassDescPlugin PRIVATE | ||
clangAST | ||
clangBasic | ||
clangFrontend | ||
) | ||
endif() | ||
|
||
set(CLANG_TEST_DEPS "PrintClassDescPlugin" ${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,56 @@ | ||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/AST/RecursiveASTVisitor.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
#include "clang/Frontend/FrontendPluginRegistry.h" | ||
|
||
class PrintClassVisitor : public clang::RecursiveASTVisitor<PrintClassVisitor> { | ||
public: | ||
explicit PrintClassVisitor(clang::ASTContext *Context) : Context(Context) {} | ||
|
||
bool VisitCXXRecordDecl(clang::CXXRecordDecl *decl) { | ||
llvm::outs() << decl->getNameAsString() << "\n"; | ||
for (clang::Decl *d : decl->decls()) { | ||
if (auto *member = clang::dyn_cast<clang::FieldDecl>(d)) { | ||
llvm::outs() << "|_" << member->getNameAsString() << "\n"; | ||
} else if (auto *staticMember = clang::dyn_cast<clang::VarDecl>(d)) { | ||
if (staticMember->isStaticDataMember()) { | ||
llvm::outs() << "|_" << staticMember->getNameAsString() << "\n"; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private: | ||
clang::ASTContext *Context; | ||
}; | ||
|
||
class PrintClassConsumer : public clang::ASTConsumer { | ||
public: | ||
explicit PrintClassConsumer(clang::ASTContext *Context) : Visitor(Context) {} | ||
|
||
void HandleTranslationUnit(clang::ASTContext &Context) override { | ||
Visitor.TraverseDecl(Context.getTranslationUnitDecl()); | ||
} | ||
|
||
private: | ||
PrintClassVisitor Visitor; | ||
}; | ||
|
||
class PrintClassPlugin : public clang::PluginASTAction { | ||
public: | ||
std::unique_ptr<clang::ASTConsumer> | ||
CreateASTConsumer(clang::CompilerInstance &Compiler, | ||
llvm::StringRef InFile) override { | ||
return std::make_unique<PrintClassConsumer>(&Compiler.getASTContext()); | ||
} | ||
|
||
protected: | ||
bool ParseArgs(const clang::CompilerInstance &Compiler, | ||
const std::vector<std::string> &args) override { | ||
return true; | ||
} | ||
}; | ||
|
||
static clang::FrontendPluginRegistry::Add<PrintClassPlugin> | ||
X("print-class", "Prints description of class."); |
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,46 @@ | ||
// RUN: %clang_cc1 -load %llvmshlibdir/PrintClassDescPlugin%pluginext -plugin print-class %s 2>&1 | FileCheck %s | ||
|
||
|
||
// CHECK: Empty | ||
class Empty {}; | ||
|
||
// CHECK: MyStruct | ||
struct MyStruct{ | ||
// CHECK-NEXT: |_a | ||
int a; | ||
// CHECK-NEXT: |_b | ||
int b; | ||
}; | ||
|
||
// CHECK: MyClass | ||
class MyClass { | ||
// CHECK-NEXT: |_a_c | ||
int a_c; | ||
// CHECK-NEXT: |_b_c | ||
float b_c; | ||
// CHECK-NEXT: |_c_c | ||
double c_c; | ||
}; | ||
|
||
// CHECK: outerClass | ||
class outerClass { | ||
// CHECK: innerClass | ||
class innerClass { | ||
//CHECK-NEXT: |_var | ||
float var; | ||
}; | ||
}; | ||
|
||
// CHECK: TemplateClass | ||
template<typename T> class TemplateClass { | ||
//CHECK-NEXT: Tvariable | ||
T Tvariable; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// CHECK: StaticClass | ||
class StaticClass { | ||
// CHECK-NEXT: |_staticField | ||
static int staticField; | ||
// CHECK-NEXT: |_instantiationInt | ||
TemplateClass<int> instantiationInt; | ||
}; |
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.
Could you please also add test with instantiation of this class for a concrete type?