//===--- TokenConcatenation.cpp - Token Concatenation Avoidance -----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the TokenConcatenation class. // //===----------------------------------------------------------------------===// #include "clang/Lex/TokenConcatenation.h" #include "clang/Basic/CharInfo.h" #include "clang/Lex/Preprocessor.h" #include "llvm/Support/ErrorHandling.h" usingnamespaceclang; /// IsStringPrefix - Return true if Str is a string prefix. /// 'L', 'u', 'U', or 'u8'. Including raw versions. static bool IsStringPrefix(StringRef Str, bool CPlusPlus11) { … } /// IsIdentifierStringPrefix - Return true if the spelling of the token /// is literally 'L', 'u', 'U', or 'u8'. Including raw versions. bool TokenConcatenation::IsIdentifierStringPrefix(const Token &Tok) const { … } TokenConcatenation::TokenConcatenation(const Preprocessor &pp) : … { … } /// GetFirstChar - Get the first character of the token \arg Tok, /// avoiding calls to getSpelling where possible. static char GetFirstChar(const Preprocessor &PP, const Token &Tok) { … } /// AvoidConcat - If printing PrevTok immediately followed by Tok would cause /// the two individual tokens to be lexed as a single token, return true /// (which causes a space to be printed between them). This allows the output /// of -E mode to be lexed to the same token stream as lexing the input /// directly would. /// /// This code must conservatively return true if it doesn't want to be 100% /// accurate. This will cause the output to include extra space characters, /// but the resulting output won't have incorrect concatenations going on. /// Examples include "..", which we print with a space between, because we /// don't want to track enough to tell "x.." from "...". bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, const Token &Tok) const { … }