1 //===--- TokenConcatenation.h - Token Concatenation Avoidance ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the TokenConcatenation class.
12 //===----------------------------------------------------------------------===//
14 #ifndef CLANG_LEX_TOKEN_CONCATENATION_H
15 #define CLANG_LEX_TOKEN_CONCATENATION_H
17 #include "clang/Basic/TokenKinds.h"
23 /// TokenConcatenation class, which answers the question of
24 /// "Is it safe to emit two tokens without a whitespace between them, or
25 /// would that cause implicit concatenation of the tokens?"
27 /// For example, it emitting two identifiers "foo" and "bar" next to each
28 /// other would cause the lexer to produce one "foobar" token. Emitting "1"
29 /// and ")" next to each other is safe.
31 class TokenConcatenation {
34 enum AvoidConcatInfo {
35 /// By default, a token never needs to avoid concatenation. Most tokens
36 /// (e.g. ',', ')', etc) don't cause a problem when concatenated.
37 aci_never_avoid_concat = 0,
39 /// aci_custom_firstchar - AvoidConcat contains custom code to handle this
40 /// token's requirements, and it needs to know the first character of the
42 aci_custom_firstchar = 1,
44 /// aci_custom - AvoidConcat contains custom code to handle this token's
45 /// requirements, but it doesn't need to know the first character of the
49 /// aci_avoid_equal - Many tokens cannot be safely followed by an '='
50 /// character. For example, "<<" turns into "<<=" when followed by an =.
54 /// TokenInfo - This array contains information for each token on what
55 /// action to take when avoiding concatenation of tokens in the AvoidConcat
57 char TokenInfo[tok::NUM_TOKENS];
59 TokenConcatenation(Preprocessor &PP);
61 bool AvoidConcat(const Token &PrevPrevTok,
63 const Token &Tok) const;
66 /// IsIdentifierStringPrefix - Return true if the spelling of the token
67 /// is literally 'L', 'u', 'U', or 'u8'.
68 bool IsIdentifierStringPrefix(const Token &Tok) const;
70 } // end clang namespace