1 //===--- CommentLexer.cpp -------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/AST/CommentLexer.h"
11 #include "clang/AST/CommentCommandTraits.h"
12 #include "clang/AST/CommentDiagnostic.h"
13 #include "clang/Basic/CharInfo.h"
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/Support/ConvertUTF.h"
17 #include "llvm/Support/ErrorHandling.h"
22 void Token::dump(const Lexer &L, const SourceManager &SM) const {
23 llvm::errs() << "comments::Token Kind=" << Kind << " ";
25 llvm::errs() << " " << Length << " \"" << L.getSpelling(*this, SM) << "\"\n";
28 static inline bool isHTMLNamedCharacterReferenceCharacter(char C) {
32 static inline bool isHTMLDecimalCharacterReferenceCharacter(char C) {
36 static inline bool isHTMLHexCharacterReferenceCharacter(char C) {
40 static inline StringRef convertCodePointToUTF8(
41 llvm::BumpPtrAllocator &Allocator,
43 char *Resolved = Allocator.Allocate<char>(UNI_MAX_UTF8_BYTES_PER_CODE_POINT);
44 char *ResolvedPtr = Resolved;
45 if (llvm::ConvertCodePointToUTF8(CodePoint, ResolvedPtr))
46 return StringRef(Resolved, ResolvedPtr - Resolved);
53 #include "clang/AST/CommentHTMLTags.inc"
54 #include "clang/AST/CommentHTMLNamedCharacterReferences.inc"
56 } // end anonymous namespace
58 StringRef Lexer::resolveHTMLNamedCharacterReference(StringRef Name) const {
59 // Fast path, first check a few most widely used named character references.
60 return llvm::StringSwitch<StringRef>(Name)
67 .Default(translateHTMLNamedCharacterReferenceToUTF8(Name));
70 StringRef Lexer::resolveHTMLDecimalCharacterReference(StringRef Name) const {
71 unsigned CodePoint = 0;
72 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
73 assert(isHTMLDecimalCharacterReferenceCharacter(Name[i]));
75 CodePoint += Name[i] - '0';
77 return convertCodePointToUTF8(Allocator, CodePoint);
80 StringRef Lexer::resolveHTMLHexCharacterReference(StringRef Name) const {
81 unsigned CodePoint = 0;
82 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
84 const char C = Name[i];
85 assert(isHTMLHexCharacterReferenceCharacter(C));
86 CodePoint += llvm::hexDigitValue(C);
88 return convertCodePointToUTF8(Allocator, CodePoint);
91 void Lexer::skipLineStartingDecorations() {
92 // This function should be called only for C comments
93 assert(CommentState == LCS_InsideCComment);
95 if (BufferPtr == CommentEnd)
103 const char *NewBufferPtr = BufferPtr;
105 if (NewBufferPtr == CommentEnd)
108 char C = *NewBufferPtr;
109 while (isHorizontalWhitespace(C)) {
111 if (NewBufferPtr == CommentEnd)
116 BufferPtr = NewBufferPtr + 1;
126 /// Returns pointer to the first newline character in the string.
127 const char *findNewline(const char *BufferPtr, const char *BufferEnd) {
128 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
129 if (isVerticalWhitespace(*BufferPtr))
135 const char *skipNewline(const char *BufferPtr, const char *BufferEnd) {
136 if (BufferPtr == BufferEnd)
139 if (*BufferPtr == '\n')
142 assert(*BufferPtr == '\r');
144 if (BufferPtr != BufferEnd && *BufferPtr == '\n')
150 const char *skipNamedCharacterReference(const char *BufferPtr,
151 const char *BufferEnd) {
152 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
153 if (!isHTMLNamedCharacterReferenceCharacter(*BufferPtr))
159 const char *skipDecimalCharacterReference(const char *BufferPtr,
160 const char *BufferEnd) {
161 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
162 if (!isHTMLDecimalCharacterReferenceCharacter(*BufferPtr))
168 const char *skipHexCharacterReference(const char *BufferPtr,
169 const char *BufferEnd) {
170 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
171 if (!isHTMLHexCharacterReferenceCharacter(*BufferPtr))
177 bool isHTMLIdentifierStartingCharacter(char C) {
181 bool isHTMLIdentifierCharacter(char C) {
182 return isAlphanumeric(C);
185 const char *skipHTMLIdentifier(const char *BufferPtr, const char *BufferEnd) {
186 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
187 if (!isHTMLIdentifierCharacter(*BufferPtr))
193 /// Skip HTML string quoted in single or double quotes. Escaping quotes inside
196 /// Returns pointer to closing quote.
197 const char *skipHTMLQuotedString(const char *BufferPtr, const char *BufferEnd)
199 const char Quote = *BufferPtr;
200 assert(Quote == '\"' || Quote == '\'');
203 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
204 const char C = *BufferPtr;
205 if (C == Quote && BufferPtr[-1] != '\\')
211 const char *skipWhitespace(const char *BufferPtr, const char *BufferEnd) {
212 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
213 if (!isWhitespace(*BufferPtr))
219 bool isWhitespace(const char *BufferPtr, const char *BufferEnd) {
220 return skipWhitespace(BufferPtr, BufferEnd) == BufferEnd;
223 bool isCommandNameStartCharacter(char C) {
227 bool isCommandNameCharacter(char C) {
228 return isAlphanumeric(C);
231 const char *skipCommandName(const char *BufferPtr, const char *BufferEnd) {
232 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
233 if (!isCommandNameCharacter(*BufferPtr))
239 /// Return the one past end pointer for BCPL comments.
240 /// Handles newlines escaped with backslash or trigraph for backslahs.
241 const char *findBCPLCommentEnd(const char *BufferPtr, const char *BufferEnd) {
242 const char *CurPtr = BufferPtr;
243 while (CurPtr != BufferEnd) {
244 while (!isVerticalWhitespace(*CurPtr)) {
246 if (CurPtr == BufferEnd)
249 // We found a newline, check if it is escaped.
250 const char *EscapePtr = CurPtr - 1;
251 while(isHorizontalWhitespace(*EscapePtr))
254 if (*EscapePtr == '\\' ||
255 (EscapePtr - 2 >= BufferPtr && EscapePtr[0] == '/' &&
256 EscapePtr[-1] == '?' && EscapePtr[-2] == '?')) {
257 // We found an escaped newline.
258 CurPtr = skipNewline(CurPtr, BufferEnd);
260 return CurPtr; // Not an escaped newline.
265 /// Return the one past end pointer for C comments.
266 /// Very dumb, does not handle escaped newlines or trigraphs.
267 const char *findCCommentEnd(const char *BufferPtr, const char *BufferEnd) {
268 for ( ; BufferPtr != BufferEnd; ++BufferPtr) {
269 if (*BufferPtr == '*') {
270 assert(BufferPtr + 1 != BufferEnd);
271 if (*(BufferPtr + 1) == '/')
275 llvm_unreachable("buffer end hit before '*/' was seen");
278 } // end anonymous namespace
280 void Lexer::formTokenWithChars(Token &Result, const char *TokEnd,
281 tok::TokenKind Kind) {
282 const unsigned TokLen = TokEnd - BufferPtr;
283 Result.setLocation(getSourceLocation(BufferPtr));
284 Result.setKind(Kind);
285 Result.setLength(TokLen);
287 Result.TextPtr = "<UNSET>";
293 void Lexer::lexCommentText(Token &T) {
294 assert(CommentState == LCS_InsideBCPLComment ||
295 CommentState == LCS_InsideCComment);
300 case LS_VerbatimBlockFirstLine:
301 lexVerbatimBlockFirstLine(T);
303 case LS_VerbatimBlockBody:
304 lexVerbatimBlockBody(T);
306 case LS_VerbatimLineText:
307 lexVerbatimLineText(T);
309 case LS_HTMLStartTag:
317 assert(State == LS_Normal);
319 const char *TokenPtr = BufferPtr;
320 assert(TokenPtr < CommentEnd);
321 while (TokenPtr != CommentEnd) {
325 // Commands that start with a backslash and commands that start with
326 // 'at' have equivalent semantics. But we keep information about the
327 // exact syntax in AST for comments.
328 tok::TokenKind CommandKind =
329 (*TokenPtr == '@') ? tok::at_command : tok::backslash_command;
331 if (TokenPtr == CommentEnd) {
332 formTextToken(T, TokenPtr);
340 case '\\': case '@': case '&': case '$':
341 case '#': case '<': case '>': case '%':
342 case '\"': case '.': case ':':
343 // This is one of \\ \@ \& \$ etc escape sequences.
345 if (C == ':' && TokenPtr != CommentEnd && *TokenPtr == ':') {
346 // This is the \:: escape sequence.
349 StringRef UnescapedText(BufferPtr + 1, TokenPtr - (BufferPtr + 1));
350 formTokenWithChars(T, TokenPtr, tok::text);
351 T.setText(UnescapedText);
355 // Don't make zero-length commands.
356 if (!isCommandNameStartCharacter(*TokenPtr)) {
357 formTextToken(T, TokenPtr);
361 TokenPtr = skipCommandName(TokenPtr, CommentEnd);
362 unsigned Length = TokenPtr - (BufferPtr + 1);
364 // Hardcoded support for lexing LaTeX formula commands
365 // \f$ \f[ \f] \f{ \f} as a single command.
366 if (Length == 1 && TokenPtr[-1] == 'f' && TokenPtr != CommentEnd) {
368 if (C == '$' || C == '[' || C == ']' || C == '{' || C == '}') {
374 StringRef CommandName(BufferPtr + 1, Length);
376 const CommandInfo *Info = Traits.getCommandInfoOrNULL(CommandName);
378 if ((Info = Traits.getTypoCorrectCommandInfo(CommandName))) {
379 StringRef CorrectedName = Info->Name;
380 SourceLocation Loc = getSourceLocation(BufferPtr);
381 SourceRange CommandRange(Loc.getLocWithOffset(1),
382 getSourceLocation(TokenPtr));
383 Diag(Loc, diag::warn_correct_comment_command_name)
384 << CommandName << CorrectedName
385 << FixItHint::CreateReplacement(CommandRange, CorrectedName);
387 formTokenWithChars(T, TokenPtr, tok::unknown_command);
388 T.setUnknownCommandName(CommandName);
389 Diag(T.getLocation(), diag::warn_unknown_comment_command_name);
393 if (Info->IsVerbatimBlockCommand) {
394 setupAndLexVerbatimBlock(T, TokenPtr, *BufferPtr, Info);
397 if (Info->IsVerbatimLineCommand) {
398 setupAndLexVerbatimLine(T, TokenPtr, Info);
401 formTokenWithChars(T, TokenPtr, CommandKind);
402 T.setCommandID(Info->getID());
407 lexHTMLCharacterReference(T);
412 if (TokenPtr == CommentEnd) {
413 formTextToken(T, TokenPtr);
416 const char C = *TokenPtr;
417 if (isHTMLIdentifierStartingCharacter(C))
418 setupAndLexHTMLStartTag(T);
420 setupAndLexHTMLEndTag(T);
422 formTextToken(T, TokenPtr);
428 TokenPtr = skipNewline(TokenPtr, CommentEnd);
429 formTokenWithChars(T, TokenPtr, tok::newline);
431 if (CommentState == LCS_InsideCComment)
432 skipLineStartingDecorations();
436 size_t End = StringRef(TokenPtr, CommentEnd - TokenPtr).
437 find_first_of("\n\r\\@&<");
438 if (End != StringRef::npos)
441 TokenPtr = CommentEnd;
442 formTextToken(T, TokenPtr);
449 void Lexer::setupAndLexVerbatimBlock(Token &T,
450 const char *TextBegin,
451 char Marker, const CommandInfo *Info) {
452 assert(Info->IsVerbatimBlockCommand);
454 VerbatimBlockEndCommandName.clear();
455 VerbatimBlockEndCommandName.append(Marker == '\\' ? "\\" : "@");
456 VerbatimBlockEndCommandName.append(Info->EndCommandName);
458 formTokenWithChars(T, TextBegin, tok::verbatim_block_begin);
459 T.setVerbatimBlockID(Info->getID());
461 // If there is a newline following the verbatim opening command, skip the
462 // newline so that we don't create an tok::verbatim_block_line with empty
464 if (BufferPtr != CommentEnd &&
465 isVerticalWhitespace(*BufferPtr)) {
466 BufferPtr = skipNewline(BufferPtr, CommentEnd);
467 State = LS_VerbatimBlockBody;
471 State = LS_VerbatimBlockFirstLine;
474 void Lexer::lexVerbatimBlockFirstLine(Token &T) {
476 assert(BufferPtr < CommentEnd);
478 // FIXME: It would be better to scan the text once, finding either the block
479 // end command or newline.
481 // Extract current line.
482 const char *Newline = findNewline(BufferPtr, CommentEnd);
483 StringRef Line(BufferPtr, Newline - BufferPtr);
485 // Look for end command in current line.
486 size_t Pos = Line.find(VerbatimBlockEndCommandName);
488 const char *NextLine;
489 if (Pos == StringRef::npos) {
490 // Current line is completely verbatim.
492 NextLine = skipNewline(Newline, CommentEnd);
493 } else if (Pos == 0) {
494 // Current line contains just an end command.
495 const char *End = BufferPtr + VerbatimBlockEndCommandName.size();
496 StringRef Name(BufferPtr + 1, End - (BufferPtr + 1));
497 formTokenWithChars(T, End, tok::verbatim_block_end);
498 T.setVerbatimBlockID(Traits.getCommandInfo(Name)->getID());
502 // There is some text, followed by end command. Extract text first.
503 TextEnd = BufferPtr + Pos;
505 // If there is only whitespace before end command, skip whitespace.
506 if (isWhitespace(BufferPtr, TextEnd)) {
512 StringRef Text(BufferPtr, TextEnd - BufferPtr);
513 formTokenWithChars(T, NextLine, tok::verbatim_block_line);
514 T.setVerbatimBlockText(Text);
516 State = LS_VerbatimBlockBody;
519 void Lexer::lexVerbatimBlockBody(Token &T) {
520 assert(State == LS_VerbatimBlockBody);
522 if (CommentState == LCS_InsideCComment)
523 skipLineStartingDecorations();
525 if (BufferPtr == CommentEnd) {
526 formTokenWithChars(T, BufferPtr, tok::verbatim_block_line);
527 T.setVerbatimBlockText("");
531 lexVerbatimBlockFirstLine(T);
534 void Lexer::setupAndLexVerbatimLine(Token &T, const char *TextBegin,
535 const CommandInfo *Info) {
536 assert(Info->IsVerbatimLineCommand);
537 formTokenWithChars(T, TextBegin, tok::verbatim_line_name);
538 T.setVerbatimLineID(Info->getID());
540 State = LS_VerbatimLineText;
543 void Lexer::lexVerbatimLineText(Token &T) {
544 assert(State == LS_VerbatimLineText);
546 // Extract current line.
547 const char *Newline = findNewline(BufferPtr, CommentEnd);
548 StringRef Text(BufferPtr, Newline - BufferPtr);
549 formTokenWithChars(T, Newline, tok::verbatim_line_text);
550 T.setVerbatimLineText(Text);
555 void Lexer::lexHTMLCharacterReference(Token &T) {
556 const char *TokenPtr = BufferPtr;
557 assert(*TokenPtr == '&');
559 if (TokenPtr == CommentEnd) {
560 formTextToken(T, TokenPtr);
564 bool isNamed = false;
565 bool isDecimal = false;
567 if (isHTMLNamedCharacterReferenceCharacter(C)) {
569 TokenPtr = skipNamedCharacterReference(TokenPtr, CommentEnd);
571 } else if (C == '#') {
573 if (TokenPtr == CommentEnd) {
574 formTextToken(T, TokenPtr);
578 if (isHTMLDecimalCharacterReferenceCharacter(C)) {
580 TokenPtr = skipDecimalCharacterReference(TokenPtr, CommentEnd);
582 } else if (C == 'x' || C == 'X') {
585 TokenPtr = skipHexCharacterReference(TokenPtr, CommentEnd);
587 formTextToken(T, TokenPtr);
591 formTextToken(T, TokenPtr);
594 if (NamePtr == TokenPtr || TokenPtr == CommentEnd ||
596 formTextToken(T, TokenPtr);
599 StringRef Name(NamePtr, TokenPtr - NamePtr);
600 TokenPtr++; // Skip semicolon.
603 Resolved = resolveHTMLNamedCharacterReference(Name);
605 Resolved = resolveHTMLDecimalCharacterReference(Name);
607 Resolved = resolveHTMLHexCharacterReference(Name);
609 if (Resolved.empty()) {
610 formTextToken(T, TokenPtr);
613 formTokenWithChars(T, TokenPtr, tok::text);
617 void Lexer::setupAndLexHTMLStartTag(Token &T) {
618 assert(BufferPtr[0] == '<' &&
619 isHTMLIdentifierStartingCharacter(BufferPtr[1]));
620 const char *TagNameEnd = skipHTMLIdentifier(BufferPtr + 2, CommentEnd);
621 StringRef Name(BufferPtr + 1, TagNameEnd - (BufferPtr + 1));
622 if (!isHTMLTagName(Name)) {
623 formTextToken(T, TagNameEnd);
627 formTokenWithChars(T, TagNameEnd, tok::html_start_tag);
628 T.setHTMLTagStartName(Name);
630 BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
632 const char C = *BufferPtr;
633 if (BufferPtr != CommentEnd &&
634 (C == '>' || C == '/' || isHTMLIdentifierStartingCharacter(C)))
635 State = LS_HTMLStartTag;
638 void Lexer::lexHTMLStartTag(Token &T) {
639 assert(State == LS_HTMLStartTag);
641 const char *TokenPtr = BufferPtr;
643 if (isHTMLIdentifierCharacter(C)) {
644 TokenPtr = skipHTMLIdentifier(TokenPtr, CommentEnd);
645 StringRef Ident(BufferPtr, TokenPtr - BufferPtr);
646 formTokenWithChars(T, TokenPtr, tok::html_ident);
647 T.setHTMLIdent(Ident);
652 formTokenWithChars(T, TokenPtr, tok::html_equals);
656 const char *OpenQuote = TokenPtr;
657 TokenPtr = skipHTMLQuotedString(TokenPtr, CommentEnd);
658 const char *ClosingQuote = TokenPtr;
659 if (TokenPtr != CommentEnd) // Skip closing quote.
661 formTokenWithChars(T, TokenPtr, tok::html_quoted_string);
662 T.setHTMLQuotedString(StringRef(OpenQuote + 1,
663 ClosingQuote - (OpenQuote + 1)));
668 formTokenWithChars(T, TokenPtr, tok::html_greater);
673 if (TokenPtr != CommentEnd && *TokenPtr == '>') {
675 formTokenWithChars(T, TokenPtr, tok::html_slash_greater);
677 formTextToken(T, TokenPtr);
684 // Now look ahead and return to normal state if we don't see any HTML tokens
686 BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
687 if (BufferPtr == CommentEnd) {
693 if (!isHTMLIdentifierStartingCharacter(C) &&
694 C != '=' && C != '\"' && C != '\'' && C != '>') {
700 void Lexer::setupAndLexHTMLEndTag(Token &T) {
701 assert(BufferPtr[0] == '<' && BufferPtr[1] == '/');
703 const char *TagNameBegin = skipWhitespace(BufferPtr + 2, CommentEnd);
704 const char *TagNameEnd = skipHTMLIdentifier(TagNameBegin, CommentEnd);
705 StringRef Name(TagNameBegin, TagNameEnd - TagNameBegin);
706 if (!isHTMLTagName(Name)) {
707 formTextToken(T, TagNameEnd);
711 const char *End = skipWhitespace(TagNameEnd, CommentEnd);
713 formTokenWithChars(T, End, tok::html_end_tag);
714 T.setHTMLTagEndName(Name);
716 if (BufferPtr != CommentEnd && *BufferPtr == '>')
717 State = LS_HTMLEndTag;
720 void Lexer::lexHTMLEndTag(Token &T) {
721 assert(BufferPtr != CommentEnd && *BufferPtr == '>');
723 formTokenWithChars(T, BufferPtr + 1, tok::html_greater);
727 Lexer::Lexer(llvm::BumpPtrAllocator &Allocator, DiagnosticsEngine &Diags,
728 const CommandTraits &Traits,
729 SourceLocation FileLoc,
730 const char *BufferStart, const char *BufferEnd):
731 Allocator(Allocator), Diags(Diags), Traits(Traits),
732 BufferStart(BufferStart), BufferEnd(BufferEnd),
733 FileLoc(FileLoc), BufferPtr(BufferStart),
734 CommentState(LCS_BeforeComment), State(LS_Normal) {
737 void Lexer::lex(Token &T) {
739 switch (CommentState) {
740 case LCS_BeforeComment:
741 if (BufferPtr == BufferEnd) {
742 formTokenWithChars(T, BufferPtr, tok::eof);
746 assert(*BufferPtr == '/');
747 BufferPtr++; // Skip first slash.
749 case '/': { // BCPL comment.
750 BufferPtr++; // Skip second slash.
752 if (BufferPtr != BufferEnd) {
753 // Skip Doxygen magic marker, if it is present.
754 // It might be missing because of a typo //< or /*<, or because we
755 // merged this non-Doxygen comment into a bunch of Doxygen comments
756 // around it: /** ... */ /* ... */ /** ... */
757 const char C = *BufferPtr;
758 if (C == '/' || C == '!')
762 // Skip less-than symbol that marks trailing comments.
763 // Skip it even if the comment is not a Doxygen one, because //< and /*<
764 // are frequent typos.
765 if (BufferPtr != BufferEnd && *BufferPtr == '<')
768 CommentState = LCS_InsideBCPLComment;
769 if (State != LS_VerbatimBlockBody && State != LS_VerbatimBlockFirstLine)
771 CommentEnd = findBCPLCommentEnd(BufferPtr, BufferEnd);
774 case '*': { // C comment.
775 BufferPtr++; // Skip star.
777 // Skip Doxygen magic marker.
778 const char C = *BufferPtr;
779 if ((C == '*' && *(BufferPtr + 1) != '/') || C == '!')
782 // Skip less-than symbol that marks trailing comments.
783 if (BufferPtr != BufferEnd && *BufferPtr == '<')
786 CommentState = LCS_InsideCComment;
788 CommentEnd = findCCommentEnd(BufferPtr, BufferEnd);
792 llvm_unreachable("second character of comment should be '/' or '*'");
795 case LCS_BetweenComments: {
796 // Consecutive comments are extracted only if there is only whitespace
797 // between them. So we can search for the start of the next comment.
798 const char *EndWhitespace = BufferPtr;
799 while(EndWhitespace != BufferEnd && *EndWhitespace != '/')
802 // Turn any whitespace between comments (and there is only whitespace
803 // between them -- guaranteed by comment extraction) into a newline. We
804 // have two newlines between C comments in total (first one was synthesized
806 formTokenWithChars(T, EndWhitespace, tok::newline);
808 CommentState = LCS_BeforeComment;
812 case LCS_InsideBCPLComment:
813 case LCS_InsideCComment:
814 if (BufferPtr != CommentEnd) {
818 // Skip C comment closing sequence.
819 if (CommentState == LCS_InsideCComment) {
820 assert(BufferPtr[0] == '*' && BufferPtr[1] == '/');
822 assert(BufferPtr <= BufferEnd);
824 // Synthenize newline just after the C comment, regardless if there is
825 // actually a newline.
826 formTokenWithChars(T, BufferPtr, tok::newline);
828 CommentState = LCS_BetweenComments;
831 // Don't synthesized a newline after BCPL comment.
832 CommentState = LCS_BetweenComments;
839 StringRef Lexer::getSpelling(const Token &Tok,
840 const SourceManager &SourceMgr,
841 bool *Invalid) const {
842 SourceLocation Loc = Tok.getLocation();
843 std::pair<FileID, unsigned> LocInfo = SourceMgr.getDecomposedLoc(Loc);
845 bool InvalidTemp = false;
846 StringRef File = SourceMgr.getBufferData(LocInfo.first, &InvalidTemp);
852 const char *Begin = File.data() + LocInfo.second;
853 return StringRef(Begin, Tok.getLength());
856 } // end namespace comments
857 } // end namespace clang