home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / jikes-1.02 / src / code.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-26  |  2.9 KB  |  111 lines

  1. // $Id: code.h,v 1.7 1999/08/26 15:34:06 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1999, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef code_INCLUDED
  11. #define code_INCLUDED
  12.  
  13. #include "config.h"
  14. #include <ctype.h>
  15. #include <assert.h>
  16.  
  17. class Code
  18. {
  19.     //
  20.     // To facilitate the scanning, the character set is partitioned into
  21.     // 8 classes using the array CODE. The classes are described below
  22.     // together with some self-explanatory functions defined on CODE.
  23.     //
  24.     enum {
  25.              LOG_BASE_SIZE       = 9,
  26.              LOG_COMPLEMENT_SIZE = 7,
  27.              BASE_SIZE           = 512,
  28.              SLOT_SIZE           = 128,
  29.              SLOT_MASK           = 127,
  30.  
  31.              NEWLINE_CODE        = 1,
  32.              SPACE_CODE          = 2,
  33.              BAD_CODE            = 3,
  34.              DIGIT_CODE          = 4,
  35.              OTHER_DIGIT_CODE    = 5,
  36.              LOWER_CODE          = 6,
  37.              UPPER_CODE          = 7,
  38.              OTHER_LETTER_CODE   = 8
  39.          };
  40.  
  41.     static char code[39424];
  42.     static char *base[512];
  43.  
  44. #ifdef EBCDIC
  45.     static char to_ascii[256];
  46.     static char to_ebcdic[256];
  47. #endif
  48.  
  49. public:
  50.  
  51.     static inline void SetBadCode(wchar_t c)
  52.     {
  53.         base[c >> LOG_COMPLEMENT_SIZE][c] = BAD_CODE;
  54.     }
  55.  
  56.     static inline void CodeCheck(wchar_t c)
  57.     {
  58.          assert(c >> LOG_COMPLEMENT_SIZE < BASE_SIZE);
  59.          assert(base[c >> LOG_COMPLEMENT_SIZE] + c >= (&code[0]));
  60.          assert(base[c >> LOG_COMPLEMENT_SIZE] + c < (&code[39424]));
  61.     }
  62.  
  63.     static inline bool IsNewline(wchar_t c) // \r characters are replaced by \x0a in read_input.
  64.     {
  65.         return c == '\x0a';
  66.     }
  67.  
  68.     static inline bool IsSpaceButNotNewline(wchar_t c)
  69.     {
  70.         return base[c >> LOG_COMPLEMENT_SIZE][c] == SPACE_CODE;
  71.     }
  72.  
  73.     static inline bool IsSpace(wchar_t c)
  74.     {
  75.         return base[c >> LOG_COMPLEMENT_SIZE][c] <= SPACE_CODE;
  76.     }
  77.  
  78.     static inline bool IsDigit(wchar_t c)
  79.     {
  80.         return base[c >> LOG_COMPLEMENT_SIZE][c] == DIGIT_CODE;
  81.     }
  82.  
  83.     static inline bool IsUpper(wchar_t c)
  84.     {
  85.         return base[c >> LOG_COMPLEMENT_SIZE][c] == UPPER_CODE;
  86.     }
  87.  
  88.     static inline bool IsLower(wchar_t c)
  89.     {
  90.         return base[c >> LOG_COMPLEMENT_SIZE][c] == LOWER_CODE;
  91.     }
  92.  
  93.     static inline bool IsAlpha(wchar_t c)
  94.     {
  95.         return base[c >> LOG_COMPLEMENT_SIZE][c] >= LOWER_CODE;
  96.     }
  97.  
  98.     static inline bool IsAlnum(wchar_t c)
  99.     {
  100.         return base[c >> LOG_COMPLEMENT_SIZE][c] >= DIGIT_CODE;
  101.     }
  102.  
  103. #ifdef EBCDIC
  104.     static inline char ToASCII(char c)         { return to_ascii[c]; }
  105.     static inline char ToEBCDIC(char c)        { return to_ebcdic[c]; }
  106. #endif
  107.  
  108. };
  109.  
  110. #endif
  111.