Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:58

0001 //===--- TokenConcatenation.h - Token Concatenation Avoidance ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the TokenConcatenation class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_LEX_TOKENCONCATENATION_H
0014 #define LLVM_CLANG_LEX_TOKENCONCATENATION_H
0015 
0016 #include "clang/Basic/TokenKinds.h"
0017 
0018 namespace clang {
0019   class Preprocessor;
0020   class Token;
0021 
0022   /// TokenConcatenation class, which answers the question of
0023   ///   "Is it safe to emit two tokens without a whitespace between them, or
0024   ///    would that cause implicit concatenation of the tokens?"
0025   ///
0026   /// For example, it emitting two identifiers "foo" and "bar" next to each
0027   /// other would cause the lexer to produce one "foobar" token.  Emitting "1"
0028   /// and ")" next to each other is safe.
0029   ///
0030   class TokenConcatenation {
0031     const Preprocessor &PP;
0032 
0033     enum AvoidConcatInfo {
0034       /// By default, a token never needs to avoid concatenation.  Most tokens
0035       /// (e.g. ',', ')', etc) don't cause a problem when concatenated.
0036       aci_never_avoid_concat = 0,
0037 
0038       /// aci_custom_firstchar - AvoidConcat contains custom code to handle this
0039       /// token's requirements, and it needs to know the first character of the
0040       /// token.
0041       aci_custom_firstchar = 1,
0042 
0043       /// aci_custom - AvoidConcat contains custom code to handle this token's
0044       /// requirements, but it doesn't need to know the first character of the
0045       /// token.
0046       aci_custom = 2,
0047 
0048       /// aci_avoid_equal - Many tokens cannot be safely followed by an '='
0049       /// character.  For example, "<<" turns into "<<=" when followed by an =.
0050       aci_avoid_equal = 4
0051     };
0052 
0053     /// TokenInfo - This array contains information for each token on what
0054     /// action to take when avoiding concatenation of tokens in the AvoidConcat
0055     /// method.
0056     char TokenInfo[tok::NUM_TOKENS];
0057   public:
0058     TokenConcatenation(const Preprocessor &PP);
0059 
0060     bool AvoidConcat(const Token &PrevPrevTok,
0061                      const Token &PrevTok,
0062                      const Token &Tok) const;
0063 
0064   private:
0065     /// IsIdentifierStringPrefix - Return true if the spelling of the token
0066     /// is literally 'L', 'u', 'U', or 'u8'.
0067     bool IsIdentifierStringPrefix(const Token &Tok) const;
0068   };
0069   } // end clang namespace
0070 
0071 #endif