data, ui: comment handling

* CodeView displays comments as atomic regions. They are either displayed as a whole or not at all. Do nothing halfway!
* added CommentHandler that handles comments detected by clang.
* stored CommentLocations in database.
This commit is contained in:
malte_langkabel
2015-11-06 14:03:20 +01:00
parent e186eefdff
commit 50bc970c30
17 changed files with 282 additions and 31 deletions
+2
View File
@@ -145,6 +145,8 @@ public:
const ParseLocation& location, const NameHierarchy& macroNameHierarchy, const ParseLocation& scopeLocation) = 0;
virtual Id onMacroExpandParsed(
const ParseLocation& location, const NameHierarchy& macroNameHierarchy) = 0;
virtual Id onCommentParsed(const ParseLocation& location) = 0;
};
#endif // PARSER_CLIENT_H
+3 -1
View File
@@ -2,11 +2,13 @@
#include "clang/Lex/Preprocessor.h"
#include "data/parser/cxx/CommentHandler.h"
#include "data/parser/cxx/PreprocessorCallbacks.h"
ASTAction::ASTAction(ParserClient* client, FileRegister* fileRegister)
: m_client(client)
, m_fileRegister(fileRegister)
, m_commentHandler(client)
{
}
@@ -24,7 +26,7 @@ bool ASTAction::BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::S
clang::Preprocessor& preprocessor = compiler.getPreprocessor();
preprocessor.addPPCallbacks(
llvm::make_unique<PreprocessorCallbacks>(compiler.getSourceManager(), m_client, m_fileRegister));
preprocessor.addCommentHandler(&m_commentHandler);
return true;
}
+3
View File
@@ -5,6 +5,7 @@
#include "clang/Frontend/FrontendAction.h"
#include "data/parser/cxx/ASTConsumer.h"
#include "data/parser/cxx/CommentHandler.h"
#include "utility/file/FileRegister.h"
class ASTAction : public clang::ASTFrontendAction
@@ -22,6 +23,8 @@ protected:
private:
ParserClient* m_client;
FileRegister* m_fileRegister;
CommentHandler m_commentHandler;
};
#endif // AST_ACTION_H
@@ -0,0 +1,28 @@
#include "data/parser/cxx/CommentHandler.h"
#include "data/parser/ParserClient.h"
CommentHandler::CommentHandler(ParserClient* client)
: m_client(client)
{
}
CommentHandler::~CommentHandler()
{
}
bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::SourceRange sourceRange)
{
clang::SourceManager& sourceManager = preprocessor.getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
m_client->onCommentParsed(ParseLocation(
presumedBegin.getFilename(),
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
presumedEnd.getColumn()
));
return false;
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef COMMENT_HANDLER_H
#define COMMENT_HANDLER_H
#include "clang/Lex/Preprocessor.h"
class ParserClient;
class CommentHandler
: public clang::CommentHandler
{
public:
CommentHandler(ParserClient* client);
virtual ~CommentHandler();
virtual bool HandleComment(clang::Preprocessor& preprocessor, clang::SourceRange sourceRange);
private:
ParserClient* m_client;
};
#endif // COMMENT_HANDLER_H