zcov: / include/expr/Lexer.h


Files: 1 Branches Taken: 0.0% 0 / 0
Generated: 2009-05-17 22:47 Branches Executed: 0.0% 0 / 0
Line Coverage: 100.0% 1 / 1


Programs: 3 Runs 1022


       1                 : //===- Lexer.h - --*- C++ -*-===//
       2                 : //
       3                 : // Klee
       4                 : //
       5                 : //===---------------------------===//
       6                 : 
       7                 : #ifndef KLEE_EXPR_LEXER_H
       8                 : #define KLEE_EXPR_LEXER_H
       9                 : 
      10                 : #include <string>
      11                 : 
      12                 : namespace llvm {
      13                 :   class MemoryBuffer;
      14                 : }
      15                 : 
      16                 : namespace klee {
      17                 : namespace expr {
      18                 :   struct Token {
      19                 :     enum Kind {
      20                 :       At,                       /// '@'
      21                 :       Arrow,                    /// '->'
      22                 :       Colon,                    /// ':'
      23                 :       Comma,                    /// ','
      24                 :       Comment,                  /// #[^\n]+
      25                 :       EndOfFile,                /// <end of file>
      26                 :       Equals,                   /// ' = '
      27                 :       Identifier,               /// [a-zA-Z_][a-zA-Z0-9._]*
      28                 :       KWFalse,                  /// 'false'
      29                 :       KWQuery,                  /// 'query'
      30                 :       KWReserved,               /// fp[0-9]+([.].*)?, i[0-9]+
      31                 :       KWTrue,                   /// 'true'
      32                 :       KWWidth,                  /// w[0-9]+
      33                 :       LBrace,                   /// '{'
      34                 :       LParen,                   /// '('
      35                 :       LSquare,                  /// '['
      36                 :       Number,                   /// [+-]?[0-9][a-zA-Z0-9_]+
      37                 :       RBrace,                   /// '}'
      38                 :       RParen,                   /// ')'
      39                 :       RSquare,                  /// ']'
      40                 :       Semicolon,                /// ';'
      41                 :       Unknown                   /// <other>
      42                 :     };
      43                 : 
      44                 :     Kind        kind;           /// The token kind.
      45                 :     const char *start;          /// The beginning of the token string. 
      46                 :     unsigned    length;         /// The length of the token.
      47                 :     unsigned    line;           /// The line number of the start of this token.
      48                 :     unsigned    column;         /// The column number at the start of
      49                 :                                 /// this token.
      50                 : 
      51                 :     /// getKindName - The name of this token's kind.
      52                 :     const char *getKindName() const;
      53                 : 
      54                 :     /// getString - The string spanned by this token. This is not
      55                 :     /// particularly efficient, use start and length when reasonable.
      56                 :     std::string getString() const { return std::string(start, length); }
      57                 : 
      58                 :     /// isKeyword - True if this token is a keyword.
      59                 :     bool isKeyword() const { 
      60               18:       return kind >= KWFalse && kind <= KWTrue; 
      61                 :     }
      62                 : 
      63                 :     // dump - Dump the token to stderr.
      64                 :     void dump();
      65                 :   };
      66                 : 
      67                 :   /// Lexer - Interface for lexing tokens from a .pc language file.
      68                 :   class Lexer {
      69                 :     const char *BufferPos;      /// The current lexer position.
      70                 :     const char *BufferEnd;      /// The buffer end position.
      71                 :     unsigned    LineNumber;     /// The current line.
      72                 :     unsigned    ColumnNumber;   /// The current column.
      73                 : 
      74                 :     /// GetNextChar - Eat a character or -1 from the stream.
      75                 :     int GetNextChar();
      76                 : 
      77                 :     /// PeekNextChar - Return the next character without consuming it
      78                 :     /// from the stream. This does not perform newline
      79                 :     /// canonicalization.
      80                 :     int PeekNextChar();
      81                 : 
      82                 :     /// SetTokenKind - Set the token kind and length (using the
      83                 :     /// token's start pointer, which must have been initialized).
      84                 :     Token &SetTokenKind(Token &Result, Token::Kind k);
      85                 : 
      86                 :     /// SetTokenKind - Set an identifiers token kind. This has the
      87                 :     /// same requirements as SetTokenKind and additionally takes care
      88                 :     /// of keyword recognition.
      89                 :     Token &SetIdentifierTokenKind(Token &Result);
      90                 :   
      91                 :     void SkipToEndOfLine();
      92                 : 
      93                 :     /// LexNumber - Lex a number which does not have a base specifier.
      94                 :     Token &LexNumber(Token &Result);
      95                 : 
      96                 :     /// LexIdentifier - Lex an identifier.
      97                 :     Token &LexIdentifier(Token &Result);
      98                 : 
      99                 :   public:
     100                 :     explicit Lexer(const llvm::MemoryBuffer *_buf);
     101                 :     ~Lexer();
     102                 : 
     103                 :     /// Lex - Return the next token from the file or EOF continually
     104                 :     /// when the end of the file is reached. The input argument is
     105                 :     /// used as the result, for convenience.
     106                 :     Token &Lex(Token &Result);
     107                 :   };
     108                 : }
     109                 : }
     110                 : 
     111                 : #endif

Generated: 2009-05-17 22:47 by zcov