Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 1 | //===--- SourceCode.h - Manipulating source code as strings -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Various code that examines C++ source code without using heavy AST machinery |
| 11 | // (and often not even the lexer). To be used sparingly! |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H |
| 15 | #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H |
| 16 | #include "Protocol.h" |
Marc-Andre Laperle | 63a1098 | 2018-02-21 02:39:08 +0000 | [diff] [blame] | 17 | #include "clang/Basic/SourceLocation.h" |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 18 | |
| 19 | namespace clang { |
Marc-Andre Laperle | 63a1098 | 2018-02-21 02:39:08 +0000 | [diff] [blame] | 20 | class SourceManager; |
| 21 | |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 22 | namespace clangd { |
| 23 | |
| 24 | /// Turn a [line, column] pair into an offset in Code. |
| 25 | size_t positionToOffset(llvm::StringRef Code, Position P); |
| 26 | |
| 27 | /// Turn an offset in Code into a [line, column] pair. |
| 28 | Position offsetToPosition(llvm::StringRef Code, size_t Offset); |
| 29 | |
Marc-Andre Laperle | 63a1098 | 2018-02-21 02:39:08 +0000 | [diff] [blame] | 30 | /// Turn a SourceLocation into a [line, column] pair. |
| 31 | Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc); |
| 32 | |
Ilya Biryukov | 71028b8 | 2018-03-12 15:28:22 +0000 | [diff] [blame^] | 33 | // Converts a half-open clang source range to an LSP range. |
| 34 | // Note that clang also uses closed source ranges, which this can't handle! |
| 35 | Range halfOpenToRange(const SourceManager &SM, CharSourceRange R); |
| 36 | |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 37 | } // namespace clangd |
| 38 | } // namespace clang |
| 39 | #endif |