]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/clang/lib/Tooling/Refactoring/SourceCode.cpp
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / clang / lib / Tooling / Refactoring / SourceCode.cpp
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 //===----------------------------------------------------------------------===//
12 #include "clang/Tooling/Refactoring/SourceCode.h"
13 #include "clang/Lex/Lexer.h"
14
15 using namespace clang;
16
17 StringRef clang::tooling::getText(CharSourceRange Range,
18                                   const ASTContext &Context) {
19   return Lexer::getSourceText(Range, Context.getSourceManager(),
20                               Context.getLangOpts());
21 }
22
23 CharSourceRange clang::tooling::maybeExtendRange(CharSourceRange Range,
24                                                  tok::TokenKind Next,
25                                                  ASTContext &Context) {
26   Optional<Token> Tok = Lexer::findNextToken(
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 }