]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/clang/include/clang/Lex/TokenConcatenation.h
Move all sources from the llvm project into contrib/llvm-project.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / clang / include / clang / Lex / TokenConcatenation.h
1 //===--- TokenConcatenation.h - Token Concatenation Avoidance ---*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the TokenConcatenation class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_LEX_TOKENCONCATENATION_H
14 #define LLVM_CLANG_LEX_TOKENCONCATENATION_H
15
16 #include "clang/Basic/TokenKinds.h"
17
18 namespace clang {
19   class Preprocessor;
20   class Token;
21
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?"
25   ///
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.
29   ///
30   class TokenConcatenation {
31     const Preprocessor &PP;
32
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,
37
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
40       /// token.
41       aci_custom_firstchar = 1,
42
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
45       /// token.
46       aci_custom = 2,
47
48       /// aci_avoid_equal - Many tokens cannot be safely followed by an '='
49       /// character.  For example, "<<" turns into "<<=" when followed by an =.
50       aci_avoid_equal = 4
51     };
52
53     /// TokenInfo - This array contains information for each token on what
54     /// action to take when avoiding concatenation of tokens in the AvoidConcat
55     /// method.
56     char TokenInfo[tok::NUM_TOKENS];
57   public:
58     TokenConcatenation(const Preprocessor &PP);
59
60     bool AvoidConcat(const Token &PrevPrevTok,
61                      const Token &PrevTok,
62                      const Token &Tok) const;
63
64   private:
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;
68   };
69   } // end clang namespace
70
71 #endif