MCPcopy Create free account
hub / github.com/KDAB/codebrowser / syntaxHighlight

Method syntaxHighlight

generator/annotator.cpp:987–1143  ·  view source on GitHub ↗

This function is inspired From clang::html::SyntaxHighlight() from HTMLRewrite.cpp * from the clang 3.1 from The LLVM Compiler Infrastructure * distributed under the University of Illinois Open Source * Adapted to the codebrowser generator. Also used to parse the comments. * The tags names have been changed, and we make a difference between different kinds of * keywords */

Source from the content-addressed store, hash-verified

985 * keywords
986 */
987void Annotator::syntaxHighlight(Generator &generator, clang::FileID FID, clang::Sema &Sema) {
988 using namespace clang;
989
990 const clang::Preprocessor &PP = Sema.getPreprocessor();
991 const clang::SourceManager &SM = getSourceMgr();
992 const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
993 Lexer L(FID, FromFile, SM, getLangOpts());
994 const char *BufferStart = FromFile->getBufferStart();
995 const char *BufferEnd = FromFile->getBufferEnd();
996
997 // Inform the preprocessor that we want to retain comments as tokens, so we
998 // can highlight them.
999 L.SetCommentRetentionState(true);
1000
1001 // Lex all the tokens in raw mode, to avoid entering #includes or expanding
1002 // macros.
1003 Token Tok;
1004 L.LexFromRawLexer(Tok);
1005
1006 while (Tok.isNot(tok::eof)) {
1007 // Since we are lexing unexpanded tokens, all tokens are from the main
1008 // FileID.
1009 unsigned TokOffs = SM.getFileOffset(Tok.getLocation());
1010 unsigned TokLen = Tok.getLength();
1011 switch (Tok.getKind()) {
1012 default: break;
1013 case tok::identifier:
1014 llvm_unreachable("tok::identifier in raw lexing mode!");
1015 case tok::raw_identifier: {
1016 // Fill in Result.IdentifierInfo and update the token kind,
1017 // looking up the identifier in the identifier table.
1018 PP.LookUpIdentifierInfo(Tok);
1019 // If this is a pp-identifier, for a keyword, highlight it as such.
1020 switch (Tok.getKind()) {
1021 case tok::identifier:
1022 break;
1023
1024 case tok::kw_auto:
1025 case tok::kw_char:
1026 case tok::kw_const:
1027 case tok::kw_double:
1028 case tok::kw_float:
1029 case tok::kw_int:
1030 case tok::kw_long:
1031 case tok::kw_register:
1032// case tok::kw_restrict: // ??? (type or not)
1033 case tok::kw_short:
1034 case tok::kw_signed:
1035 case tok::kw_static:
1036 case tok::kw_unsigned:
1037 case tok::kw_void:
1038 case tok::kw_volatile:
1039 case tok::kw_bool:
1040 case tok::kw_mutable:
1041 case tok::kw_wchar_t:
1042 case tok::kw_char16_t:
1043 case tok::kw_char32_t:
1044 generator.addTag("em", {}, TokOffs, TokLen);

Callers

nothing calls this directly

Calls 2

addTagMethod · 0.80
handleCommentMethod · 0.80

Tested by

no test coverage detected