home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / Jikes / Source / src / code.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-24  |  2.5 KB  |  107 lines

  1. #ifndef code_INCLUDED
  2. #define code_INCLUDED
  3.  
  4. #include "platform.h"
  5.  
  6. /*
  7. //FIXME: need to readdress this include stuff
  8. #include <ctype.h>
  9. #include <assert.h>
  10. */
  11.  
  12. #ifdef    HAVE_JIKES_NAMESPACE
  13. namespace Jikes {    // Open namespace Jikes block
  14. #endif
  15.  
  16. class Code
  17. {
  18.     //
  19.     // To facilitate the scanning, the character set is partitioned into
  20.     // 8 classes using the array CODE. The classes are described below
  21.     // together with some self-explanatory functions defined on CODE.
  22.     //
  23.     enum {
  24.              LOG_BASE_SIZE       = 9,
  25.              LOG_COMPLEMENT_SIZE = 7,
  26.              BASE_SIZE           = 512,
  27.              SLOT_SIZE           = 128,
  28.              SLOT_MASK           = 127,
  29.  
  30.              NEWLINE_CODE        = 1,
  31.              SPACE_CODE          = 2,
  32.              BAD_CODE            = 3,
  33.              DIGIT_CODE          = 4,
  34.              OTHER_DIGIT_CODE    = 5,
  35.              LOWER_CODE          = 6,
  36.              UPPER_CODE          = 7,
  37.              OTHER_LETTER_CODE   = 8
  38.          };
  39.  
  40.     static char code[39424];
  41.     static char *base[512];
  42.  
  43.  
  44. public:
  45.  
  46.     static inline void SetBadCode(wchar_t c)
  47.     {
  48.         base[c >> LOG_COMPLEMENT_SIZE][c] = BAD_CODE;
  49.     }
  50.  
  51.     static inline void CodeCheck(wchar_t c)
  52.     {
  53.          assert(c >> LOG_COMPLEMENT_SIZE < BASE_SIZE);
  54.          assert(base[c >> LOG_COMPLEMENT_SIZE] + c >= (&code[0]));
  55.          assert(base[c >> LOG_COMPLEMENT_SIZE] + c < (&code[39424]));
  56.     }
  57.  
  58.     static inline bool IsNewline(wchar_t c) // \r characters are replaced by \x0a in Stream::ProcessInput().
  59.     {
  60.         return c == '\x0a';
  61.     }
  62.  
  63.     static inline bool IsSpaceButNotNewline(wchar_t c)
  64.     {
  65.         return base[c >> LOG_COMPLEMENT_SIZE][c] == SPACE_CODE;
  66.     }
  67.  
  68.     static inline bool IsSpace(wchar_t c)
  69.     {
  70.         return base[c >> LOG_COMPLEMENT_SIZE][c] <= SPACE_CODE;
  71.     }
  72.  
  73.     static inline bool IsDigit(wchar_t c)
  74.     {
  75.         return base[c >> LOG_COMPLEMENT_SIZE][c] == DIGIT_CODE;
  76.     }
  77.  
  78.     static inline bool IsUpper(wchar_t c)
  79.     {
  80.         return base[c >> LOG_COMPLEMENT_SIZE][c] == UPPER_CODE;
  81.     }
  82.  
  83.     static inline bool IsLower(wchar_t c)
  84.     {
  85.         return base[c >> LOG_COMPLEMENT_SIZE][c] == LOWER_CODE;
  86.     }
  87.  
  88.     static inline bool IsAlpha(wchar_t c)
  89.     {
  90.         return base[c >> LOG_COMPLEMENT_SIZE][c] >= LOWER_CODE;
  91.     }
  92.  
  93.     static inline bool IsAlnum(wchar_t c)
  94.     {
  95.         return base[c >> LOG_COMPLEMENT_SIZE][c] >= DIGIT_CODE;
  96.     }
  97.  
  98.  
  99. };
  100.  
  101. #ifdef    HAVE_JIKES_NAMESPACE
  102. }            // Close namespace Jikes block
  103. #endif
  104.  
  105. #endif
  106.  
  107.