#include "Tokens.h" #include using namespace std; clang::Tokens::Tokens(CXTranslationUnit &cx_tu, SourceRange &range): cx_tu(cx_tu) { clang_tokenize(cx_tu, range.cx_range, &cx_tokens, &num_tokens); cx_cursors.clear(); cx_cursors.reserve(num_tokens); clang_annotateTokens(cx_tu, cx_tokens, num_tokens, cx_cursors.data()); for (int i = 0; i < num_tokens; i++) { emplace_back(cx_tu, cx_tokens[i], cx_cursors[i]); } } clang::Tokens::~Tokens() { clang_disposeTokens(cx_tu, cx_tokens, size()); } /*CXCursor clang::Tokens::find_referenced() { cursors.clear(); cursors.reserve(size()); clang_annotateTokens(tu, tokens.data(), size(), cursors.data()); auto kind=clang_getCursorKind(cursors[0]); cout << " " << kind << endl; cout << " Decl: " << clang_isDeclaration(kind) << endl; cout << " Attr: " << clang_isAttribute(kind) << endl; cout << " Ref: " << clang_isReference(kind) << endl; cout << " Expr: " << clang_isExpression(kind) << endl; auto referenced=clang_getCursorReferenced(cursors[0]); kind=clang_getCursorKind(referenced); cout << " " << kind << endl; cout << " Decl: " << clang_isDeclaration(kind) << endl; cout << " Attr: " << clang_isAttribute(kind) << endl; cout << " Ref: " << clang_isReference(kind) << endl; cout << " Expr: " << clang_isExpression(kind) << endl; //TODO: To find similar function declarations, these must be equal (if cursor is declaration): //TODO: How do we know it is a function? clang_getCursorKind(cursor)==CXCursor_CXXMethod? cout << " " << clang_getCString(clang_getTypeSpelling(clang_getCursorType(referenced))) << endl; cout << " " << clang_getCString(clang_getTypeSpelling(clang_getCursorType(clang_getCursorSemanticParent(referenced)))) << endl; cout << " " << clang_getCString(clang_getCursorSpelling(referenced)) << endl; return referenced; }*/ void clang::Tokens::rename(CXCursor &referenced) { for(size_t c=0;c