10#include "clang/Basic/LangOptions.h"
11#include "llvm/ADT/StringExtras.h"
12#include "llvm/Support/Format.h"
13#include "llvm/Support/FormatVariadic.h"
19 OS << llvm::formatv(
"{0} {1}:{2} ", clang::tok::getTokenName(T.Kind), T.Line,
22 llvm::printEscapedString(T.text(),
OS);
25 OS << llvm::format(
" flags=%x", T.Flags);
30 OS <<
"Index Kind Line Text\n";
31 for (
const auto &T : TS.
tokens()) {
32 OS << llvm::format(
"%5d: %16s %4d:%-2d ", TS.
index(T),
33 clang::tok::getTokenName(T.Kind), T.Line, T.Indent);
35 llvm::printEscapedString(T.text(),
OS);
38 OS << llvm::format(
" flags=%x", T.Flags);
45 OS << llvm::formatv(
"[{0},{1})", R.
Begin, R.
End);
51 Storage.emplace_back();
52 Storage.back().Kind = clang::tok::eof;
57 unsigned LastLine = Storage.back().Line;
58 Storage.emplace_back();
59 Storage.back().Kind = tok::eof;
63 Tokens = Tokens.drop_front().drop_back();
67 assert(!Storage.empty() && Storage.front().Kind == tok::eof);
68 if (Storage.size() == 1)
70 return Storage.back().Kind == tok::eof;
74 bool FirstToken =
true;
77 for (
const auto &T :
tokens()) {
78 StringRef
Text = T.text();
82 if (LastText.data() + LastText.size() !=
Text.data())
97 clang::LangStandard::Kind
Standard) {
98 clang::LangOptions Opts;
99 std::vector<std::string> UnusedIncludes;
100 LangOptions::setLangDefaults(Opts,
Lang, llvm::Triple(), UnusedIncludes,
105 Opts.CXXOperatorNames =
true;
106 if (Opts.CPlusPlus20)
107 Opts.Coroutines =
true;
111 Opts.MicrosoftExt =
true;
112 Opts.DeclSpecKeyword =
true;
120 for (
const Token &T : Input.tokens()) {
121 if (T.Kind == tok::comment)
CompiledFragmentImpl & Out
A complete sequence of Tokens representing a source file.
ArrayRef< Token > tokens() const
Token::Index index(const Token &T) const
Returns the index of T within the stream.
void print(llvm::raw_ostream &) const
Print the tokens in this stream to the output stream.
void finalize()
Finalize the token stream, allowing tokens to be accessed.
TokenStream(std::shared_ptr< void > Payload=nullptr)
Create an empty stream.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
TokenStream stripComments(const TokenStream &Input)
Drops comment tokens.
clang::LangOptions genericLangOpts(clang::Language Lang, clang::LangStandard::Kind Standard)
A generic lang options suitable for lexing/parsing a langage.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
A half-open range of tokens within a stream.
A single C++ or preprocessor token.