zcov: / include/clang/Lex/LiteralSupport.h


Files: 1 Branches Taken: 72.4% 21 / 29
Generated: 2010-02-10 01:31 Branches Executed: 79.3% 23 / 29
Line Coverage: 87.5% 28 / 32


Programs: 12 Runs 18108


       1                 : //===--- LiteralSupport.h ---------------------------------------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : // This file defines the NumericLiteralParser, CharLiteralParser, and
      11                 : // StringLiteralParser interfaces.
      12                 : //
      13                 : //===----------------------------------------------------------------------===//
      14                 : 
      15                 : #ifndef CLANG_LITERALSUPPORT_H
      16                 : #define CLANG_LITERALSUPPORT_H
      17                 : 
      18                 : #include <string>
      19                 : #include "llvm/ADT/APFloat.h"
      20                 : #include "llvm/ADT/SmallString.h"
      21                 : #include "llvm/System/DataTypes.h"
      22                 : 
      23                 : namespace clang {
      24                 : 
      25                 : class Diagnostic;
      26                 : class Preprocessor;
      27                 : class Token;
      28                 : class SourceLocation;
      29                 : class TargetInfo;
      30                 : 
      31                 : /// NumericLiteralParser - This performs strict semantic analysis of the content
      32                 : /// of a ppnumber, classifying it as either integer, floating, or erroneous,
      33                 : /// determines the radix of the value and can convert it to a useful value.
      34                 : class NumericLiteralParser {
      35                 :   Preprocessor &PP; // needed for diagnostics
      36                 : 
      37                 :   const char *const ThisTokBegin;
      38                 :   const char *const ThisTokEnd;
      39                 :   const char *DigitsBegin, *SuffixBegin; // markers
      40                 :   const char *s; // cursor
      41                 : 
      42                 :   unsigned radix;
      43                 : 
      44                 :   bool saw_exponent, saw_period;
      45                 : 
      46                 : public:
      47                 :   NumericLiteralParser(const char *begin, const char *end,
      48                 :                        SourceLocation Loc, Preprocessor &PP);
      49                 :   bool hadError;
      50                 :   bool isUnsigned;
      51                 :   bool isLong;        // This is *not* set for long long.
      52                 :   bool isLongLong;
      53                 :   bool isFloat;       // 1.0f
      54                 :   bool isImaginary;   // 1.0i
      55                 :   bool isMicrosoftInteger;  // Microsoft suffix extension i8, i16, i32, or i64.
      56                 : 
      57             8673:   bool isIntegerLiteral() const {
                     8673: branch 0 taken
                        0: branch 1 not taken
                     8673: branch 2 taken
                        0: branch 3 not taken
      58             8673:     return !saw_period && !saw_exponent;
      59                 :   }
      60            18891:   bool isFloatingLiteral() const {
                    17361: branch 0 taken
                     1530: branch 1 taken
                       12: branch 2 taken
                    17349: branch 3 taken
      61            18891:     return saw_period || saw_exponent;
      62                 :   }
      63                 :   bool hasSuffix() const {
      64                 :     return SuffixBegin != ThisTokEnd;
      65                 :   }
      66                 : 
      67             3453:   unsigned getRadix() const { return radix; }
      68                 : 
      69                 :   /// GetIntegerValue - Convert this numeric literal value to an APInt that
      70                 :   /// matches Val's input width.  If there is an overflow (i.e., if the unsigned
      71                 :   /// value read is larger than the APInt's bits will hold), set Val to the low
      72                 :   /// bits of the result and return true.  Otherwise, return false.
      73                 :   bool GetIntegerValue(llvm::APInt &Val);
      74                 : 
      75                 :   /// GetFloatValue - Convert this numeric literal to a floating value, using
      76                 :   /// the specified APFloat fltSemantics (specifying float, double, etc).
      77                 :   /// The optional bool isExact (passed-by-reference) has its value
      78                 :   /// set to true if the returned APFloat can represent the number in the
      79                 :   /// literal exactly, and false otherwise.
      80                 :   llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result);
      81                 : 
      82                 : private:
      83                 : 
      84                 :   void ParseNumberStartingWithZero(SourceLocation TokLoc);
      85                 : 
      86                 :   /// SkipHexDigits - Read and skip over any hex digits, up to End.
      87                 :   /// Return a pointer to the first non-hex digit or End.
      88              987:   const char *SkipHexDigits(const char *ptr) {
                      912: branch 1 taken
                     4913: branch 3 taken
                       75: branch 4 taken
      89             6887:     while (ptr != ThisTokEnd && isxdigit(*ptr))
      90             4913:       ptr++;
      91              987:     return ptr;
      92                 :   }
      93                 : 
      94                 :   /// SkipOctalDigits - Read and skip over any octal digits, up to End.
      95                 :   /// Return a pointer to the first non-hex digit or End.
      96              544:   const char *SkipOctalDigits(const char *ptr) {
                      165: branch 0 taken
                      395: branch 1 taken
                       52: branch 2 taken
                      113: branch 3 taken
                       16: branch 4 taken
                       36: branch 5 taken
      97             1104:     while (ptr != ThisTokEnd && ((*ptr >= '0') && (*ptr <= '7')))
      98               16:       ptr++;
      99              544:     return ptr;
     100                 :   }
     101                 : 
     102                 :   /// SkipDigits - Read and skip over any digits, up to End.
     103                 :   /// Return a pointer to the first non-hex digit or End.
     104             8717:   const char *SkipDigits(const char *ptr) {
                    18055: branch 0 taken
                     7364: branch 1 taken
                    16702: branch 2 taken
                     1353: branch 3 taken
     105            34136:     while (ptr != ThisTokEnd && isdigit(*ptr))
     106            16702:       ptr++;
     107             8717:     return ptr;
     108                 :   }
     109                 : 
     110                 :   /// SkipBinaryDigits - Read and skip over any binary digits, up to End.
     111                 :   /// Return a pointer to the first non-binary digit or End.
     112                0:   const char *SkipBinaryDigits(const char *ptr) {
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
                        0: branch 4 not taken
                        0: branch 5 not taken
     113                0:     while (ptr != ThisTokEnd && (*ptr == '0' || *ptr == '1'))
     114                0:       ptr++;
     115                0:     return ptr;
     116                 :   }
     117                 : 
     118                 : };
     119                 : 
     120                 : /// CharLiteralParser - Perform interpretation and semantic analysis of a
     121                 : /// character literal.
     122                 : class CharLiteralParser {
     123                 :   uint64_t Value;
     124                 :   bool IsWide;
     125                 :   bool IsMultiChar;
     126                 :   bool HadError;
     127                 : public:
     128                 :   CharLiteralParser(const char *begin, const char *end,
     129                 :                     SourceLocation Loc, Preprocessor &PP);
     130                 : 
     131              192:   bool hadError() const { return HadError; }
     132              215:   bool isWide() const { return IsWide; }
     133               22:   bool isMultiChar() const { return IsMultiChar; }
     134              192:   uint64_t getValue() const { return Value; }
     135                 : };
     136                 : 
     137                 : /// StringLiteralParser - This decodes string escape characters and performs
     138                 : /// wide string analysis and Translation Phase #6 (concatenation of string
     139                 : /// literals) (C99 5.1.1.2p1).
     140             9530: class StringLiteralParser {
     141                 :   Preprocessor &PP;
     142                 : 
     143                 :   unsigned MaxTokenLength;
     144                 :   unsigned SizeBound;
     145                 :   unsigned wchar_tByteWidth;
     146                 :   llvm::SmallString<512> ResultBuf;
     147                 :   char *ResultPtr; // cursor
     148                 : public:
     149                 :   StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
     150                 :                       Preprocessor &PP);
     151                 :   bool hadError;
     152                 :   bool AnyWide;
     153                 :   bool Pascal;
     154                 : 
     155             9426:   const char *GetString() { return &ResultBuf[0]; }
     156            11309:   unsigned GetStringLength() const { return ResultPtr-&ResultBuf[0]; }
     157                 : 
     158             1781:   unsigned GetNumStringChars() const {
                       30: branch 0 taken
                     1751: branch 1 taken
     159             1781:     if (AnyWide)
     160               30:       return GetStringLength() / wchar_tByteWidth;
     161             1751:     return GetStringLength();
     162                 :   }
     163                 :   /// getOffsetOfStringByte - This function returns the offset of the
     164                 :   /// specified byte of the string data represented by Token.  This handles
     165                 :   /// advancing over escape sequences in the string.
     166                 :   static unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo,
     167                 :                                         Preprocessor &PP);
     168                 : };
     169                 : 
     170                 : }  // end namespace clang
     171                 : 
     172                 : #endif

Generated: 2010-02-10 01:31 by zcov