clang  9.0.0
SourceCode.cpp
Go to the documentation of this file.
1 //===--- SourceCode.cpp - Source code manipulation routines -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides functions that simplify extraction of source code.
10 //
11 //===----------------------------------------------------------------------===//
13 #include "clang/Lex/Lexer.h"
14 
15 using namespace clang;
16 
18  const ASTContext &Context) {
19  return Lexer::getSourceText(Range, Context.getSourceManager(),
20  Context.getLangOpts());
21 }
22 
24  tok::TokenKind Next,
25  ASTContext &Context) {
27  Range.getEnd(), Context.getSourceManager(), Context.getLangOpts());
28  if (!Tok || !Tok->is(Next))
29  return Range;
30  return CharSourceRange::getTokenRange(Range.getBegin(), Tok->getLocation());
31 }
static CharSourceRange getTokenRange(SourceRange R)
StringRef getText(CharSourceRange Range, const ASTContext &Context)
Returns the source-code text in the specified range.
Definition: SourceCode.cpp:17
SourceLocation getBegin() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
const FormatToken & Tok
A source range independent of the SourceManager.
Definition: Replacement.h:44
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
Definition: Lexer.cpp:930
Represents a character-granular source range.
CharSourceRange maybeExtendRange(CharSourceRange Range, tok::TokenKind Next, ASTContext &Context)
Extends Range to include the token Next, if it immediately follows the end of the range...
Definition: SourceCode.cpp:23
static Optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Finds the token that comes right after the given location.
Definition: Lexer.cpp:1228
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
Dataflow Directional Tag Classes.
SourceLocation getEnd() const
SourceManager & getSourceManager()
Definition: ASTContext.h:665
const LangOptions & getLangOpts() const
Definition: ASTContext.h:710