Comments (6)
+1
from sourcetrail.
+1 via HN
from sourcetrail.
+1 via mail
from sourcetrail.
Searching around in the code, I guess it's not tooooooo hard.
It should be possible to either extend the CxxAstVisitor or create a similar component. The question in that would be how to handle Obj-C++, as that is a mixture of Obj-C and C++.
Edit:// Looking further it would require the CxxAstVisitor to inherit from LexicallyOrderedRecursiveASTVisitor instead of RecursiveASTVisitor as described here: https://clang.llvm.org/doxygen/classclang_1_1LexicallyOrderedRecursiveASTVisitor.html#details
from sourcetrail.
I would recommend to create an entirely new AST visitor class for Objective-C support that derives from the LexicallyOrderedRecursiveASTVisitor. Mainly because the existing CxxAstVisitor is quite complex due to templates in C++. If parts of code are getting used in both visitors, we could still extract those parts into helper functions.
from sourcetrail.
I looked a little bit deeper, and if I understand this correctly, it needs to be part of the CxxAstVisitor. This is due to the existance of Obj-C++. Furthermore for some reason the LexicallyOrderedRecursiveASTVisitor, crashes on Obj-C++ files (Obj-C works fine).
A minimal example without c++
class ExampleVisitor : public RecursiveASTVisitor<ExampleVisitor> {
private:
ASTContext *astContext;
public:
explicit ExampleVisitor(CompilerInstance *CI)
: astContext(&(CI->getASTContext()))
{
}
bool shouldVisitDecl(const Decl* decl) {
const SourceManager& sourceManager = astContext->getSourceManager();
SourceLocation loc = sourceManager.getExpansionLoc(decl->getLocation());
return sourceManager.isInMainFile(loc);
}
bool shouldVisitExpr(const Expr* expr) {
const SourceManager& sourceManager = astContext->getSourceManager();
SourceLocation loc = sourceManager.getExpansionLoc(expr->getExprLoc());
return sourceManager.isInMainFile(loc);
}
string getFilename(const Decl* decl) {
const SourceManager& sourceManager = astContext->getSourceManager();
return string(sourceManager.getFilename(decl->getLocation()));
}
bool VisitObjCContainerDecl(ObjCContainerDecl *decl) {
if(!shouldVisitDecl(decl)) {
return true;
}
recorder->endRecording();
recorder->beginRecording();
return true;
}
bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *decl) {
if (!shouldVisitDecl(decl)) {
return true;
}
errs() << "- Found ObjC Interface Declaration: " << decl->getQualifiedNameAsString() << "\n";
return true;
}
bool VisitObjCImplementationDecl(ObjCImplementationDecl *decl) {
if(!shouldVisitDecl(decl)) {
return true;
}
errs() << "- Found ObjC Implementation: " << decl->getQualifiedNameAsString() << "\n";
return true;
}
bool VisitObjCCategoryDecl(ObjCCategoryDecl *decl) {
if (!shouldVisitDecl(decl)) {
return true;
}
errs() << "- Found ObjC Category Declaration: " << decl->getClassInterface()->getQualifiedNameAsString() << " " << decl->getQualifiedNameAsString() << "\n";
return true;
}
bool VisitObjCMethodDecl(ObjCMethodDecl *decl) {
if (!shouldVisitDecl(decl)) {
return true;
}
errs() << "| - Found ObjC Method Declaration: " << decl->getQualifiedNameAsString() << "\n";
if (auto body = decl->getBody()) {
body->getStmtClassName();
}
return true;
}
bool VisitObjCPropertyDecl(ObjCPropertyDecl *decl) {
if (!shouldVisitDecl(decl)) {
return true;
}
errs() << "| - Found ObjC Property Declaration: " << decl->getQualifiedNameAsString() << "\n";
return true;
}
bool VisitFunctionDecl(FunctionDecl *decl) {
if (!shouldVisitDecl(decl)) {
return true;
}
errs() << "| - Found Function Declaration: " << decl->getQualifiedNameAsString() << "\n";
return true;
}
bool VisitCallExpr(CallExpr *expr) {
if (!shouldVisitExpr(expr)) {
return true;
}
errs() << "| - - Found FunctionCall\n";
return true;
}
bool VisitObjCMessageExpr(ObjCMessageExpr *expr) {
if (!shouldVisitExpr(expr)) {
return true;
}
errs() << "| - - Found MethodCall: ["<< expr->getReceiverInterface()->getQualifiedNameAsString() << " " << expr->getSelector().getAsString() << "]\n";
errs() << "| - - - file: " << getFilename(expr->getReceiverInterface()) << "\n";
return true;
}
};
from sourcetrail.
Related Issues (20)
- preprocessor conditionals 'inactive' visual style
- strlen() {non-indexed} being shown as returning `long long` rather than `size_t`
- Unable to use SourceTrail with VSCode and WSL HOT 1
- Start failure on W10 20H2 AMD x64 HOT 2
- Passed a file-system folder or subtree to custom indexer (rather than individual files) HOT 1
- Unknown argument "-mlongcalls"; did you mean "-mlong-calls" when indexing ESP32 project
- When multiple custom indexers are used, increment updates pass the wrong files HOT 1
- Custom trail with multi symbol HOT 1
- Continuing Sourcetrail / Sourcetrail End Of Life (EOL) HOT 5
- Support Java 17 (LTS) Language Standard
- Is there any thing i can do to make sourcetrail not only show direct relations of active symbols? HOT 1
- An unknown exception was thrown during indexing. HOT 1
- Move the Project to KDE Umbrella to avoid discontinuing? HOT 1
- Feature request - Headless support HOT 1
- The program crash and exit when click menu Edit-> Preferences... HOT 2
- Add hints for inherithed and overridden methods HOT 1
- Build sourcetrail with Github CICD. HOT 2
- Create Github organization alternate to `SourceTrail` HOT 10
- Few function calls are not being mapped.
- Return code '255' when indexing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sourcetrail.