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" 17 #include "clang/Basic/SourceLocation.h" 18 19 namespace clang { 20 class SourceManager; 21 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 30 /// Turn a SourceLocation into a [line, column] pair. 31 Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc); 32 33 } // namespace clangd 34 } // namespace clang 35 #endif 36