logic: implemented highlighting both opening and closing bracket in Code view while hovering either one (issue #12)
This commit is contained in:
@@ -59,7 +59,6 @@ CxxAstVisitor::CxxAstVisitor(
|
||||
return NameHierarchy(L"global", NAME_DELIMITER_UNKNOWN);
|
||||
}
|
||||
);
|
||||
|
||||
m_contextComponent = std::make_shared<CxxAstVisitorComponentContext>(this);
|
||||
m_components.push_back(m_contextComponent);
|
||||
m_typeRefKindComponent = std::make_shared<CxxAstVisitorComponentTypeRefKind>(this);
|
||||
@@ -499,9 +498,9 @@ bool CxxAstVisitor::TraverseBinComma(clang::BinaryOperator* s)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CxxAstVisitor::TraverseDeclarationNameInfo(clang::DeclarationNameInfo NameInfo)
|
||||
bool CxxAstVisitor::TraverseDeclarationNameInfo(clang::DeclarationNameInfo NameInfo)
|
||||
{
|
||||
// we don't visit any children here
|
||||
// we don't visit any children here
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -609,6 +608,7 @@ DEF_VISIT_CUSTOM_TYPE_PTR(UnaryAddrOf, UnaryOperator)
|
||||
DEF_VISIT_CUSTOM_TYPE_PTR(UnaryDeref, UnaryOperator)
|
||||
DEF_VISIT_TYPE_PTR(DeclStmt)
|
||||
DEF_VISIT_TYPE_PTR(ReturnStmt)
|
||||
DEF_VISIT_TYPE_PTR(CompoundStmt)
|
||||
DEF_VISIT_TYPE_PTR(InitListExpr)
|
||||
DEF_VISIT_TYPE_PTR(TagDecl)
|
||||
DEF_VISIT_TYPE_PTR(ClassTemplateSpecializationDecl)
|
||||
@@ -633,6 +633,7 @@ DEF_VISIT_TYPE_PTR(MemberExpr)
|
||||
DEF_VISIT_TYPE_PTR(CXXDependentScopeMemberExpr)
|
||||
DEF_VISIT_TYPE_PTR(CXXConstructExpr)
|
||||
DEF_VISIT_TYPE_PTR(LambdaExpr)
|
||||
DEF_VISIT_TYPE_PTR(MSAsmStmt)
|
||||
DEF_VISIT_CUSTOM_TYPE_PTR(ConstructorInitializer, CXXCtorInitializer)
|
||||
|
||||
#undef DEF_VISIT_CUSTOM_TYPE_PTR
|
||||
@@ -736,7 +737,7 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceRange& sourceRa
|
||||
if (sourceRange.isValid())
|
||||
{
|
||||
const clang::SourceManager& sourceManager = m_astContext->getSourceManager();
|
||||
|
||||
|
||||
clang::SourceRange range = sourceRange;
|
||||
clang::SourceLocation endLoc = m_preprocessor->getLocForEndOfToken(range.getEnd());
|
||||
|
||||
@@ -789,7 +790,7 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceRange& sourceRa
|
||||
return parseLocation;
|
||||
}
|
||||
|
||||
bool CxxAstVisitor::isLocatedInProjectFile(clang::SourceLocation loc)
|
||||
bool CxxAstVisitor::isLocatedInProjectFile(clang::SourceLocation loc) const
|
||||
{
|
||||
const clang::SourceManager& sourceManager = m_astContext->getSourceManager();
|
||||
|
||||
@@ -815,7 +816,7 @@ bool CxxAstVisitor::isLocatedInProjectFile(clang::SourceLocation loc)
|
||||
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
|
||||
if (fileEntry != nullptr && fileEntry->isValid())
|
||||
{
|
||||
FilePath filePath = getCanonicalFilePathCache()->getCanonicalFilePath(fileEntry);
|
||||
FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
|
||||
const bool ret = m_fileRegister->hasFilePath(filePath);
|
||||
m_inProjectFileMap[fileId] = ret;
|
||||
return ret;
|
||||
|
||||
@@ -110,6 +110,7 @@ public:
|
||||
virtual bool VisitUnaryDeref(clang::UnaryOperator* s);
|
||||
virtual bool VisitDeclStmt(clang::DeclStmt* s);
|
||||
virtual bool VisitReturnStmt(clang::ReturnStmt* s);
|
||||
virtual bool VisitCompoundStmt(clang::CompoundStmt* s);
|
||||
virtual bool VisitInitListExpr(clang::InitListExpr* s);
|
||||
|
||||
|
||||
@@ -139,14 +140,14 @@ public:
|
||||
virtual bool VisitCXXDependentScopeMemberExpr(clang::CXXDependentScopeMemberExpr* s);
|
||||
virtual bool VisitCXXConstructExpr(clang::CXXConstructExpr* s);
|
||||
virtual bool VisitLambdaExpr(clang::LambdaExpr* s);
|
||||
virtual bool VisitMSAsmStmt(clang::MSAsmStmt* s);
|
||||
virtual bool VisitConstructorInitializer(clang::CXXCtorInitializer* init);
|
||||
|
||||
ParseLocation getParseLocationOfTagDeclBody(clang::TagDecl* decl) const;
|
||||
ParseLocation getParseLocationOfFunctionBody(const clang::FunctionDecl* decl) const;
|
||||
ParseLocation getParseLocation(const clang::SourceLocation& loc) const;
|
||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
||||
bool isLocatedInUnparsedProjectFile(clang::SourceLocation loc);
|
||||
bool isLocatedInProjectFile(clang::SourceLocation loc);
|
||||
bool isLocatedInProjectFile(clang::SourceLocation loc) const;
|
||||
|
||||
private:
|
||||
typedef clang::RecursiveASTVisitor<CxxAstVisitor> Base;
|
||||
@@ -177,8 +178,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inUnparsedProjectFileMap;
|
||||
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inProjectFileMap;
|
||||
mutable std::unordered_map<const clang::FileID, bool, FileIdHash> m_inProjectFileMap;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -113,12 +113,14 @@ DEF_TRAVERSE_TYPE_PTR(CXXTemporaryObjectExpr)
|
||||
virtual void visitUnaryDeref(clang::UnaryOperator* s) {}
|
||||
virtual void visitDeclStmt(clang::DeclStmt* s) {}
|
||||
virtual void visitReturnStmt(clang::ReturnStmt* s) {}
|
||||
virtual void visitCompoundStmt(clang::CompoundStmt* s) {};
|
||||
virtual void visitInitListExpr(clang::InitListExpr* s) {}
|
||||
virtual void visitDeclRefExpr(clang::DeclRefExpr* s) {}
|
||||
virtual void visitMemberExpr(clang::MemberExpr* s) {}
|
||||
virtual void visitCXXDependentScopeMemberExpr(clang::CXXDependentScopeMemberExpr* s) {}
|
||||
virtual void visitCXXConstructExpr(clang::CXXConstructExpr* s) {}
|
||||
virtual void visitLambdaExpr(clang::LambdaExpr* s) {}
|
||||
virtual void visitMSAsmStmt(clang::MSAsmStmt* s) {}
|
||||
|
||||
virtual void visitConstructorInitializer(clang::CXXCtorInitializer* init) {}
|
||||
|
||||
|
||||
@@ -14,6 +14,74 @@
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
clang::SourceLocation getFirstLBraceLocation(clang::SourceLocation searchStartLoc, const clang::SourceManager& sm, const clang::LangOptions& opts)
|
||||
{
|
||||
{
|
||||
clang::Token token;
|
||||
if (clang::Lexer::getRawToken(searchStartLoc, token, sm, opts))
|
||||
{
|
||||
if (token.getKind() == clang::tok::l_brace)
|
||||
{
|
||||
return token.getLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
llvm::Optional<clang::Token> token = clang::Lexer::findNextToken(searchStartLoc, sm, opts);
|
||||
if (token.hasValue())
|
||||
{
|
||||
if (token.getValue().getKind() == clang::tok::l_brace)
|
||||
{
|
||||
return token.getValue().getLocation();
|
||||
}
|
||||
searchStartLoc = token.getValue().getLocation();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return clang::SourceLocation();
|
||||
}
|
||||
|
||||
clang::SourceLocation getLastRBraceLocation(clang::SourceLocation searchStartLoc, clang::SourceLocation searchEndLoc, const clang::SourceManager& sm, const clang::LangOptions& opts)
|
||||
{
|
||||
{
|
||||
searchEndLoc = searchEndLoc.getLocWithOffset(-1);
|
||||
llvm::Optional<clang::Token> token = clang::Lexer::findNextToken(searchEndLoc, sm, opts);
|
||||
if (token.hasValue())
|
||||
{
|
||||
if (token.getValue().getKind() == clang::tok::r_brace)
|
||||
{
|
||||
return token.getValue().getLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
clang::Token token;
|
||||
if (clang::Lexer::getRawToken(searchEndLoc, token, sm, opts))
|
||||
{
|
||||
if (token.getKind() == clang::tok::r_brace)
|
||||
{
|
||||
return token.getLocation();
|
||||
}
|
||||
}
|
||||
if (searchEndLoc < searchStartLoc)
|
||||
{
|
||||
break;
|
||||
}
|
||||
searchEndLoc = searchEndLoc.getLocWithOffset(-1);
|
||||
}
|
||||
return clang::SourceLocation();
|
||||
}
|
||||
}
|
||||
|
||||
CxxAstVisitorComponentIndexer::CxxAstVisitorComponentIndexer(
|
||||
CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister
|
||||
)
|
||||
@@ -24,10 +92,6 @@ CxxAstVisitorComponentIndexer::CxxAstVisitorComponentIndexer(
|
||||
{
|
||||
}
|
||||
|
||||
CxxAstVisitorComponentIndexer::~CxxAstVisitorComponentIndexer()
|
||||
{
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::beginTraverseNestedNameSpecifierLoc(const clang::NestedNameSpecifierLoc& loc)
|
||||
{
|
||||
if (!shouldVisitReference(loc.getBeginLoc(), getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl()))
|
||||
@@ -194,6 +258,15 @@ void CxxAstVisitorComponentIndexer::visitTagDecl(clang::TagDecl* d)
|
||||
symbolKind
|
||||
);
|
||||
}
|
||||
|
||||
if (d->isThisDeclarationADefinition() &&
|
||||
(
|
||||
!clang::isa<clang::CXXRecordDecl>(d) ||
|
||||
clang::dyn_cast<clang::CXXRecordDecl>(d)->getTemplateSpecializationKind() != clang::TSK_ImplicitInstantiation
|
||||
))
|
||||
{
|
||||
recordBraces(getParseLocation(d->getBraceRange().getBegin()), getParseLocation(d->getBraceRange().getEnd()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +481,11 @@ void CxxAstVisitorComponentIndexer::visitNamespaceDecl(clang::NamespaceDecl* d)
|
||||
utility::convertAccessSpecifier(d->getAccess()),
|
||||
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
|
||||
);
|
||||
|
||||
recordBraces(
|
||||
getParseLocation(getFirstLBraceLocation(d->getLocStart(), m_astContext->getSourceManager(), m_astContext->getLangOpts())),
|
||||
getParseLocation(getLastRBraceLocation(d->getLocStart(), d->getLocEnd(), m_astContext->getSourceManager(), m_astContext->getLangOpts()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,6 +644,33 @@ void CxxAstVisitorComponentIndexer::visitTypeLoc(clang::TypeLoc tl)
|
||||
}
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::visitCompoundStmt(clang::CompoundStmt* s)
|
||||
{
|
||||
if (shouldVisitStmt(s))
|
||||
{
|
||||
const clang::NamedDecl* contextDecl = getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
|
||||
if (!contextDecl || !utility::isImplicit(contextDecl))
|
||||
{
|
||||
recordBraces(getParseLocation(s->getLBracLoc()), getParseLocation(s->getRBracLoc()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::visitInitListExpr(clang::InitListExpr* s)
|
||||
{
|
||||
if (shouldVisitStmt(s))
|
||||
{
|
||||
if (s->isSyntacticForm())
|
||||
{
|
||||
const clang::NamedDecl* contextDecl = getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
|
||||
if (!contextDecl || !utility::isImplicit(contextDecl))
|
||||
{
|
||||
recordBraces(getParseLocation(s->getLBraceLoc()), getParseLocation(s->getRBraceLoc()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::visitDeclRefExpr(clang::DeclRefExpr* s)
|
||||
{
|
||||
clang::ValueDecl* decl = s->getDecl();
|
||||
@@ -717,6 +822,25 @@ void CxxAstVisitorComponentIndexer::visitLambdaExpr(clang::LambdaExpr* s)
|
||||
}
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::visitMSAsmStmt(clang::MSAsmStmt* s)
|
||||
{
|
||||
if (shouldVisitStmt(s))
|
||||
{
|
||||
if (s->hasBraces())
|
||||
{
|
||||
const clang::NamedDecl* contextDecl = getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
|
||||
if (!contextDecl || !utility::isImplicit(contextDecl))
|
||||
{
|
||||
ParseLocation asdasd = getParseLocation(s->getLocEnd());
|
||||
recordBraces(
|
||||
getParseLocation(s->getLBraceLoc()),
|
||||
getParseLocation(getLastRBraceLocation(s->getLocStart(), s->getLocEnd(), m_astContext->getSourceManager(), m_astContext->getLangOpts()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::visitConstructorInitializer(clang::CXXCtorInitializer* init)
|
||||
{
|
||||
if (shouldVisitReference(init->getMemberLocation(), getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl()))
|
||||
@@ -753,6 +877,33 @@ void CxxAstVisitorComponentIndexer::recordTemplateMemberSpecialization(
|
||||
}
|
||||
}
|
||||
|
||||
void CxxAstVisitorComponentIndexer::recordBraces(const ParseLocation& lbraceLoc, const ParseLocation& rbraceLoc)
|
||||
{
|
||||
std::wstring name =
|
||||
lbraceLoc.filePath.fileName() + L"<" +
|
||||
std::to_wstring(lbraceLoc.startLineNumber) + L":" +
|
||||
std::to_wstring(lbraceLoc.startColumnNumber) + L">";
|
||||
|
||||
if (lbraceLoc.startColumnNumber != rbraceLoc.startColumnNumber ||
|
||||
lbraceLoc.endColumnNumber != rbraceLoc.endColumnNumber ||
|
||||
lbraceLoc.startLineNumber != rbraceLoc.startLineNumber ||
|
||||
lbraceLoc.endLineNumber != rbraceLoc.endLineNumber)
|
||||
{
|
||||
if (lbraceLoc.startColumnNumber == lbraceLoc.endColumnNumber &&
|
||||
lbraceLoc.startLineNumber == lbraceLoc.endLineNumber)
|
||||
{
|
||||
m_client->recordLocalSymbol(name, lbraceLoc);
|
||||
//m_client->recordLocalSymbol(L"BRACE_START", lbraceLoc);
|
||||
}
|
||||
if (rbraceLoc.startColumnNumber == rbraceLoc.endColumnNumber &&
|
||||
rbraceLoc.startLineNumber == rbraceLoc.endLineNumber)
|
||||
{
|
||||
m_client->recordLocalSymbol(name, rbraceLoc);
|
||||
//m_client->recordLocalSymbol(L"BRACE_END", rbraceLoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ParseLocation CxxAstVisitorComponentIndexer::getParseLocationOfTagDeclBody(clang::TagDecl* decl) const
|
||||
{
|
||||
return getAstVisitor()->getParseLocationOfTagDeclBody(decl);
|
||||
@@ -790,7 +941,26 @@ ReferenceKind CxxAstVisitorComponentIndexer::consumeDeclRefContextKind()
|
||||
return refKind;
|
||||
}
|
||||
|
||||
bool CxxAstVisitorComponentIndexer::shouldVisitDecl(const clang::Decl* decl)
|
||||
bool CxxAstVisitorComponentIndexer::shouldVisitStmt(const clang::Stmt* s) const
|
||||
{
|
||||
if (s)
|
||||
{
|
||||
clang::SourceLocation loc = m_astContext->getSourceManager().getExpansionLoc(s->getLocStart());
|
||||
|
||||
if (loc.isInvalid())
|
||||
{
|
||||
loc = s->getLocStart();
|
||||
}
|
||||
|
||||
if (getAstVisitor()->isLocatedInProjectFile(loc))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CxxAstVisitorComponentIndexer::shouldVisitDecl(const clang::Decl* decl) const
|
||||
{
|
||||
if (decl)
|
||||
{
|
||||
@@ -809,7 +979,7 @@ bool CxxAstVisitorComponentIndexer::shouldVisitDecl(const clang::Decl* decl)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CxxAstVisitorComponentIndexer::shouldVisitReference(const clang::SourceLocation& referenceLocation, const clang::Decl* contextDecl)
|
||||
bool CxxAstVisitorComponentIndexer::shouldVisitReference(const clang::SourceLocation& referenceLocation, const clang::Decl* contextDecl) const
|
||||
{
|
||||
clang::SourceLocation loc = m_astContext->getSourceManager().getExpansionLoc(referenceLocation);
|
||||
if (loc.isInvalid())
|
||||
@@ -817,7 +987,7 @@ bool CxxAstVisitorComponentIndexer::shouldVisitReference(const clang::SourceLoca
|
||||
loc = referenceLocation;
|
||||
}
|
||||
|
||||
if (getAstVisitor()->isLocatedInProjectFile(loc))
|
||||
if (getAstVisitor()->isLocatedInProjectFile(loc))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,47 +13,51 @@ class CxxAstVisitorComponentIndexer: public CxxAstVisitorComponent
|
||||
{
|
||||
public:
|
||||
CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~CxxAstVisitorComponentIndexer();
|
||||
|
||||
virtual void beginTraverseNestedNameSpecifierLoc(const clang::NestedNameSpecifierLoc& loc) override;
|
||||
virtual void beginTraverseTemplateArgumentLoc(const clang::TemplateArgumentLoc& loc) override;
|
||||
virtual void beginTraverseLambdaCapture(clang::LambdaExpr *lambdaExpr, const clang::LambdaCapture *capture) override;
|
||||
void beginTraverseNestedNameSpecifierLoc(const clang::NestedNameSpecifierLoc& loc) override;
|
||||
void beginTraverseTemplateArgumentLoc(const clang::TemplateArgumentLoc& loc) override;
|
||||
void beginTraverseLambdaCapture(clang::LambdaExpr *lambdaExpr, const clang::LambdaCapture *capture) override;
|
||||
|
||||
virtual void visitTagDecl(clang::TagDecl* d) override;
|
||||
virtual void visitClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl* d) override;
|
||||
virtual void visitVarDecl(clang::VarDecl* d) override;
|
||||
virtual void visitVarTemplateSpecializationDecl(clang::VarTemplateSpecializationDecl* d) override;
|
||||
virtual void visitFieldDecl(clang::FieldDecl* d) override;
|
||||
virtual void visitFunctionDecl(clang::FunctionDecl* d) override;
|
||||
virtual void visitCXXMethodDecl(clang::CXXMethodDecl* d) override;
|
||||
virtual void visitEnumConstantDecl(clang::EnumConstantDecl* d) override;
|
||||
virtual void visitNamespaceDecl(clang::NamespaceDecl* d) override;
|
||||
virtual void visitNamespaceAliasDecl(clang::NamespaceAliasDecl* d) override;
|
||||
virtual void visitTypedefDecl(clang::TypedefDecl* d) override;
|
||||
virtual void visitTypeAliasDecl(clang::TypeAliasDecl* d) override;
|
||||
virtual void visitUsingDirectiveDecl(clang::UsingDirectiveDecl* d) override;
|
||||
virtual void visitUsingDecl(clang::UsingDecl* d) override;
|
||||
virtual void visitNonTypeTemplateParmDecl(clang::NonTypeTemplateParmDecl* d) override;
|
||||
virtual void visitTemplateTypeParmDecl(clang::TemplateTypeParmDecl* d) override;
|
||||
virtual void visitTemplateTemplateParmDecl(clang::TemplateTemplateParmDecl* d) override;
|
||||
void visitTagDecl(clang::TagDecl* d) override;
|
||||
void visitClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl* d) override;
|
||||
void visitVarDecl(clang::VarDecl* d) override;
|
||||
void visitVarTemplateSpecializationDecl(clang::VarTemplateSpecializationDecl* d) override;
|
||||
void visitFieldDecl(clang::FieldDecl* d) override;
|
||||
void visitFunctionDecl(clang::FunctionDecl* d) override;
|
||||
void visitCXXMethodDecl(clang::CXXMethodDecl* d) override;
|
||||
void visitEnumConstantDecl(clang::EnumConstantDecl* d) override;
|
||||
void visitNamespaceDecl(clang::NamespaceDecl* d) override;
|
||||
void visitNamespaceAliasDecl(clang::NamespaceAliasDecl* d) override;
|
||||
void visitTypedefDecl(clang::TypedefDecl* d) override;
|
||||
void visitTypeAliasDecl(clang::TypeAliasDecl* d) override;
|
||||
void visitUsingDirectiveDecl(clang::UsingDirectiveDecl* d) override;
|
||||
void visitUsingDecl(clang::UsingDecl* d) override;
|
||||
void visitNonTypeTemplateParmDecl(clang::NonTypeTemplateParmDecl* d) override;
|
||||
void visitTemplateTypeParmDecl(clang::TemplateTypeParmDecl* d) override;
|
||||
void visitTemplateTemplateParmDecl(clang::TemplateTemplateParmDecl* d) override;
|
||||
|
||||
virtual void visitTypeLoc(clang::TypeLoc tl) override;
|
||||
void visitTypeLoc(clang::TypeLoc tl) override;
|
||||
|
||||
virtual void visitDeclRefExpr(clang::DeclRefExpr* s) override;
|
||||
virtual void visitMemberExpr(clang::MemberExpr* s) override;
|
||||
virtual void visitCXXConstructExpr(clang::CXXConstructExpr* s) override;
|
||||
virtual void visitLambdaExpr(clang::LambdaExpr* s) override;
|
||||
void visitCompoundStmt(clang::CompoundStmt* s) override;
|
||||
void visitInitListExpr(clang::InitListExpr* s) override;
|
||||
void visitDeclRefExpr(clang::DeclRefExpr* s) override;
|
||||
void visitMemberExpr(clang::MemberExpr* s) override;
|
||||
void visitCXXConstructExpr(clang::CXXConstructExpr* s) override;
|
||||
void visitLambdaExpr(clang::LambdaExpr* s) override;
|
||||
void visitMSAsmStmt(clang::MSAsmStmt* s) override;
|
||||
|
||||
virtual void visitConstructorInitializer(clang::CXXCtorInitializer* init) override;
|
||||
void visitConstructorInitializer(clang::CXXCtorInitializer* init) override;
|
||||
|
||||
private:
|
||||
void recordTemplateMemberSpecialization(
|
||||
const clang::MemberSpecializationInfo* memberSpecializationInfo,
|
||||
const NameHierarchy& context,
|
||||
const ParseLocation& location,
|
||||
const clang::MemberSpecializationInfo* memberSpecializationInfo,
|
||||
const NameHierarchy& context,
|
||||
const ParseLocation& location,
|
||||
SymbolKind symbolKind
|
||||
);
|
||||
|
||||
void recordBraces(const ParseLocation& lbraceLoc, const ParseLocation& rbraceLoc);
|
||||
|
||||
ParseLocation getParseLocationOfTagDeclBody(clang::TagDecl* decl) const;
|
||||
ParseLocation getParseLocationOfFunctionBody(const clang::FunctionDecl* decl) const;
|
||||
ParseLocation getParseLocation(const clang::SourceLocation& loc) const;
|
||||
@@ -61,8 +65,9 @@ private:
|
||||
|
||||
ReferenceKind consumeDeclRefContextKind();
|
||||
|
||||
bool shouldVisitDecl(const clang::Decl* decl);
|
||||
bool shouldVisitReference(const clang::SourceLocation& referenceLocation, const clang::Decl* contextDecl);
|
||||
bool shouldVisitStmt(const clang::Stmt* s) const;
|
||||
bool shouldVisitDecl(const clang::Decl* decl) const;
|
||||
bool shouldVisitReference(const clang::SourceLocation& referenceLocation, const clang::Decl* contextDecl) const;
|
||||
|
||||
clang::ASTContext* m_astContext;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
|
||||
@@ -76,7 +76,7 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
|
||||
compileCommand.Filename = utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr());
|
||||
compileCommand.Directory = utility::encodeToUtf8(indexerCommand->getWorkingDirectory().wstr());
|
||||
compileCommand.CommandLine = utility::concat(
|
||||
utility::convert<std::wstring, std::string>(indexerCommand->getCompilerFlags(), [](const std::wstring & flag) { return utility::encodeToUtf8(flag); }),
|
||||
utility::convert<std::wstring, std::string>(indexerCommand->getCompilerFlags(), [](const std::wstring & flag) { return utility::encodeToUtf8(flag); }),
|
||||
getCommandlineArgumentsEssential(
|
||||
std::vector<std::wstring>(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths()
|
||||
)
|
||||
@@ -98,7 +98,7 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxEmpty> indexerComman
|
||||
compileCommand.Filename = utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr());
|
||||
compileCommand.Directory = utility::encodeToUtf8(indexerCommand->getWorkingDirectory().wstr());
|
||||
compileCommand.CommandLine = prependSyntaxOnlyToolArgs(appendFilePath(
|
||||
getCommandlineArguments(indexerCommand),
|
||||
getCommandlineArguments(indexerCommand),
|
||||
utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr())
|
||||
));
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ CxxVerboseAstVisitor::~CxxVerboseAstVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl *d)
|
||||
bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl* d)
|
||||
{
|
||||
if (d)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl *d)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CxxVerboseAstVisitor::TraverseStmt(clang::Stmt *stmt)
|
||||
bool CxxVerboseAstVisitor::TraverseStmt(clang::Stmt* stmt)
|
||||
{
|
||||
if (stmt)
|
||||
{
|
||||
@@ -70,7 +70,6 @@ bool CxxVerboseAstVisitor::TraverseStmt(clang::Stmt *stmt)
|
||||
<< " <" << loc.startLineNumber << ":" << loc.startColumnNumber
|
||||
<< ", " << loc.endLineNumber << ":" << loc.endColumnNumber << ">"
|
||||
);
|
||||
|
||||
{
|
||||
ScopedSwitcher<unsigned int> switcher(m_indentation, m_indentation + 1);
|
||||
return base::TraverseStmt(stmt);
|
||||
|
||||
@@ -25,8 +25,8 @@ public:
|
||||
private:
|
||||
typedef CxxAstVisitor base;
|
||||
|
||||
virtual bool TraverseDecl(clang::Decl *d);
|
||||
virtual bool TraverseStmt(clang::Stmt *stmt);
|
||||
virtual bool TraverseDecl(clang::Decl* d);
|
||||
virtual bool TraverseStmt(clang::Stmt* stmt);
|
||||
virtual bool TraverseTypeLoc(clang::TypeLoc tl);
|
||||
|
||||
std::string getIndentString() const;
|
||||
|
||||
@@ -34,13 +34,13 @@ bool utility::isImplicit(const clang::Decl* d)
|
||||
else if (const clang::FunctionDecl* fd = clang::dyn_cast_or_null<clang::FunctionDecl>(d))
|
||||
{
|
||||
if (
|
||||
fd->isTemplateInstantiation() &&
|
||||
fd->isTemplateInstantiation() &&
|
||||
fd->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization) // or undefined??
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (
|
||||
fd->getMemberSpecializationInfo() &&
|
||||
fd->getMemberSpecializationInfo() &&
|
||||
fd->getMemberSpecializationInfo()->getTemplateSpecializationKind() == clang::TSK_ExplicitSpecialization)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -98,19 +98,18 @@ private:
|
||||
|
||||
void processSourceFiles(const std::wstring& projectName, const std::vector<FilePath>& sourceFilePaths)
|
||||
{
|
||||
TimeStamp startTime = TimeStamp::now();
|
||||
m_duration = 0;
|
||||
for (const FilePath& filePath : sourceFilePaths)
|
||||
{
|
||||
processSourceFile(projectName, filePath);
|
||||
}
|
||||
size_t duration = TimeStamp::now().deltaMS(startTime);
|
||||
if (s_trackTime)
|
||||
{
|
||||
const FilePath projectDataRoot = FilePath(L"data/CxxIndexSampleProjectsTestSuite/" + projectName).makeAbsolute();
|
||||
|
||||
std::ofstream outfile;
|
||||
outfile.open((projectDataRoot.wstr() + L"/" + projectName + L".timing").c_str(), std::ios_base::app);
|
||||
outfile << startTime.toString() << " - " << duration << " ms\n";
|
||||
outfile << TimeStamp::now().toString() << " - " << m_duration << " ms\n";
|
||||
outfile.close();
|
||||
}
|
||||
}
|
||||
@@ -174,8 +173,12 @@ private:
|
||||
"c++1z"
|
||||
);
|
||||
|
||||
TimeStamp startTime = TimeStamp::now();
|
||||
parser.buildIndex(command);
|
||||
m_duration += TimeStamp::now().deltaMS(startTime);
|
||||
|
||||
return TextAccess::createFromString(utility::encodeToUtf8(parserClient->m_lines));
|
||||
}
|
||||
|
||||
size_t m_duration;
|
||||
};
|
||||
@@ -1546,7 +1546,7 @@ public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// test qualifier locations
|
||||
|
||||
|
||||
void test_cxx_parser_finds_qualifier_of_access_to_global_variable_defined_in_namespace()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
@@ -4048,6 +4048,145 @@ public:
|
||||
TS_ASSERT_EQUALS(client->includes.size(), 1);
|
||||
}
|
||||
|
||||
|
||||
void test_cxx_parser_finds_braces_of_class_decl()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"class App\n"
|
||||
"{\n"
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:1> <2:1 2:1>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:1> <3:1 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_braces_of_namespace_decl()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"namespace n\n"
|
||||
"{\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:1> <2:1 2:1>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:1> <3:1 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_braces_of_function_decl()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:1> <2:1 2:1>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:1> <3:1 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_braces_of_method_decl()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"class App\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" App(int i) {}\n"
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<4:13> <4:13 4:13>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<4:13> <4:14 4:14>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_braces_of_init_list()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"int a = 0;\n"
|
||||
"int b[] = {a};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:11> <2:11 2:11>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<2:11> <2:13 2:13>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_braces_of_lambda()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"void lambdaCaller()\n"
|
||||
"{\n"
|
||||
" [](){}();\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<3:6> <3:6 3:6>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<3:6> <3:7 3:7>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_braces_of_asm_stmt()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" __asm\n"
|
||||
" {\n"
|
||||
" mov eax, eax\n"
|
||||
" }\n"
|
||||
"}\n",
|
||||
{ L"--target=i686-pc-windows-msvc" }
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<4:2> <4:2 4:2>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::wstring>(
|
||||
client->localSymbols, L"input.cc<4:2> <6:2 6:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_no_duplicate_braces_of_template_class_and_method_decl()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"template <typename T>\n"
|
||||
"class App\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" App(int i) {}\n"
|
||||
"};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" App<int> a;\n"
|
||||
" return 0;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 9);
|
||||
}
|
||||
|
||||
void test_cxx_parser_catches_error()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
@@ -4081,7 +4220,7 @@ public:
|
||||
client->errors, L"'this_path_does_not_exist.txt' file not found <2:10 2:10>"
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
void test_cxx_parser_finds_location_of_line_comment()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
referencedNameString = FilePath(referencedNameString).fileName();
|
||||
}
|
||||
}
|
||||
catch (const boost::filesystem::filesystem_error& e)
|
||||
catch (const boost::filesystem::filesystem_error&)
|
||||
{
|
||||
// do nothing and use the old contectNameString
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
contextNameString = FilePath(contextNameString).fileName();
|
||||
}
|
||||
}
|
||||
catch (const boost::filesystem::filesystem_error& e)
|
||||
catch (const boost::filesystem::filesystem_error&)
|
||||
{
|
||||
// do nothing and use the old contectNameString
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ private:
|
||||
const ParseLocation& location,
|
||||
const std::wstring& message,
|
||||
bool fatal,
|
||||
bool indexed,
|
||||
bool indexed,
|
||||
const FilePath& translationUnit) override
|
||||
{
|
||||
if (location.isValid())
|
||||
|
||||
Reference in New Issue
Block a user