1 //===--- TokenConcatenation.h - Token Concatenation Avoidance ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the TokenConcatenation class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LEX_TOKENCONCATENATION_H
14 #define LLVM_CLANG_LEX_TOKENCONCATENATION_H
16 #include "clang/Basic/TokenKinds.h"
22 /// TokenConcatenation class, which answers the question of
23 /// "Is it safe to emit two tokens without a whitespace between them, or
24 /// would that cause implicit concatenation of the tokens?"
26 /// For example, it emitting two identifiers "foo" and "bar" next to each
27 /// other would cause the lexer to produce one "foobar" token. Emitting "1"
28 /// and ")" next to each other is safe.
30 class TokenConcatenation {
31 const Preprocessor &PP;
33 enum AvoidConcatInfo {
34 /// By default, a token never needs to avoid concatenation. Most tokens
35 /// (e.g. ',', ')', etc) don't cause a problem when concatenated.
36 aci_never_avoid_concat = 0,
38 /// aci_custom_firstchar - AvoidConcat contains custom code to handle this
39 /// token's requirements, and it needs to know the first character of the
41 aci_custom_firstchar = 1,
43 /// aci_custom - AvoidConcat contains custom code to handle this token's
44 /// requirements, but it doesn't need to know the first character of the
48 /// aci_avoid_equal - Many tokens cannot be safely followed by an '='
49 /// character. For example, "<<" turns into "<<=" when followed by an =.
53 /// TokenInfo - This array contains information for each token on what
54 /// action to take when avoiding concatenation of tokens in the AvoidConcat
56 char TokenInfo[tok::NUM_TOKENS];
58 TokenConcatenation(const Preprocessor &PP);
60 bool AvoidConcat(const Token &PrevPrevTok,
62 const Token &Tok) const;
65 /// IsIdentifierStringPrefix - Return true if the spelling of the token
66 /// is literally 'L', 'u', 'U', or 'u8'.
67 bool IsIdentifierStringPrefix(const Token &Tok) const;
69 } // end clang namespace