clang API Documentation

TokenConcatenation.h
Go to the documentation of this file.
00001 //===--- TokenConcatenation.h - Token Concatenation Avoidance ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the TokenConcatenation class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_LEX_TOKENCONCATENATION_H
00015 #define LLVM_CLANG_LEX_TOKENCONCATENATION_H
00016 
00017 #include "clang/Basic/TokenKinds.h"
00018 
00019 namespace clang {
00020   class Preprocessor;
00021   class Token;
00022 
00023   /// TokenConcatenation class, which answers the question of
00024   ///   "Is it safe to emit two tokens without a whitespace between them, or
00025   ///    would that cause implicit concatenation of the tokens?"
00026   ///
00027   /// For example, it emitting two identifiers "foo" and "bar" next to each
00028   /// other would cause the lexer to produce one "foobar" token.  Emitting "1"
00029   /// and ")" next to each other is safe.
00030   ///
00031   class TokenConcatenation {
00032     Preprocessor &PP;
00033 
00034     enum AvoidConcatInfo {
00035       /// By default, a token never needs to avoid concatenation.  Most tokens
00036       /// (e.g. ',', ')', etc) don't cause a problem when concatenated.
00037       aci_never_avoid_concat = 0,
00038 
00039       /// aci_custom_firstchar - AvoidConcat contains custom code to handle this
00040       /// token's requirements, and it needs to know the first character of the
00041       /// token.
00042       aci_custom_firstchar = 1,
00043 
00044       /// aci_custom - AvoidConcat contains custom code to handle this token's
00045       /// requirements, but it doesn't need to know the first character of the
00046       /// token.
00047       aci_custom = 2,
00048 
00049       /// aci_avoid_equal - Many tokens cannot be safely followed by an '='
00050       /// character.  For example, "<<" turns into "<<=" when followed by an =.
00051       aci_avoid_equal = 4
00052     };
00053 
00054     /// TokenInfo - This array contains information for each token on what
00055     /// action to take when avoiding concatenation of tokens in the AvoidConcat
00056     /// method.
00057     char TokenInfo[tok::NUM_TOKENS];
00058   public:
00059     TokenConcatenation(Preprocessor &PP);
00060 
00061     bool AvoidConcat(const Token &PrevPrevTok, 
00062                      const Token &PrevTok, 
00063                      const Token &Tok) const;
00064 
00065   private:
00066     /// IsIdentifierStringPrefix - Return true if the spelling of the token
00067     /// is literally 'L', 'u', 'U', or 'u8'.
00068     bool IsIdentifierStringPrefix(const Token &Tok) const;
00069   };
00070   } // end clang namespace
00071 
00072 #endif