idl_re.cpp
来自「Boost provides free peer-reviewed portab」· C++ 代码 · 共 2,462 行 · 第 1/5 页
CPP
2,462 行
/* Generated by re2c 0.13.2 on Thu Oct 09 21:18:08 2008 */#line 1 "idl.re"/*============================================================================= Boost.Wave: A Standard compliant C++ preprocessor library Sample: IDL lexer http://www.boost.org/ Copyright (c) 2001-2008 Hartmut Kaiser. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)=============================================================================*/#include <ctime>#include <cstdlib>#include <cstdio>#include <cstring>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <boost/config.hpp>#if defined(BOOST_HAS_UNISTD_H)#include <unistd.h>#else#include <io.h>#endif #include <boost/assert.hpp>#include <boost/detail/workaround.hpp>// reuse the token ids and re2c helper functions from the default C++ lexer#include <boost/wave/token_ids.hpp>#include <boost/wave/cpplexer/re2clex/aq.hpp>#include <boost/wave/cpplexer/re2clex/scanner.hpp>#include <boost/wave/cpplexer/cpplexer_exceptions.hpp>#include "idl_re.hpp"#if defined(_MSC_VER) && !defined(__COMO__)#pragma warning (disable: 4101) // 'foo' : unreferenced local variable#pragma warning (disable: 4102) // 'foo' : unreferenced label#endif#define BOOST_WAVE_BSIZE 196608#define YYCTYPE uchar#define YYCURSOR cursor#define YYLIMIT s->lim#define YYMARKER s->ptr#define YYFILL(n) {cursor = fill(s, cursor);}//#define BOOST_WAVE_RET(i) {s->cur = cursor; return (i);}#define BOOST_WAVE_RET(i) \ { \ s->line += count_backslash_newlines(s, cursor); \ s->cur = cursor; \ return (i); \ } \ /**////////////////////////////////////////////////////////////////////////////////namespace boost {namespace wave {namespace idllexer {namespace re2clex {#define RE2C_ASSERT BOOST_ASSERTint get_one_char(boost::wave::cpplexer::re2clex::Scanner *s){ using namespace boost::wave::cpplexer::re2clex; if (0 != s->act) { RE2C_ASSERT(s->first != 0 && s->last != 0); RE2C_ASSERT(s->first <= s->act && s->act <= s->last); if (s->act < s->last) return *(s->act)++; } return -1;}std::ptrdiff_t rewind_stream (boost::wave::cpplexer::re2clex::Scanner *s, int cnt){ if (0 != s->act) { RE2C_ASSERT(s->first != 0 && s->last != 0); s->act += cnt; RE2C_ASSERT(s->first <= s->act && s->act <= s->last); return s->act - s->first; } return 0;}std::size_t get_first_eol_offset(boost::wave::cpplexer::re2clex::Scanner* s){ if (!AQ_EMPTY(s->eol_offsets)) { return s->eol_offsets->queue[s->eol_offsets->head]; } else { return (unsigned int)-1; }}void adjust_eol_offsets(boost::wave::cpplexer::re2clex::Scanner* s, std::size_t adjustment){ boost::wave::cpplexer::re2clex::aq_queue q; std::size_t i; if (!s->eol_offsets) s->eol_offsets = boost::wave::cpplexer::re2clex::aq_create(); q = s->eol_offsets; if (AQ_EMPTY(q)) return; i = q->head; while (i != q->tail) { if (adjustment > q->queue[i]) q->queue[i] = 0; else q->queue[i] -= adjustment; ++i; if (i == q->max_size) i = 0; } if (adjustment > q->queue[i]) q->queue[i] = 0; else q->queue[i] -= adjustment;}int count_backslash_newlines(boost::wave::cpplexer::re2clex::Scanner *s, boost::wave::cpplexer::re2clex::uchar *cursor){ using namespace boost::wave::cpplexer::re2clex; std::size_t diff, offset; int skipped = 0; /* figure out how many backslash-newlines skipped over unknowingly. */ diff = cursor - s->bot; offset = get_first_eol_offset(s); while (offset <= diff && offset != (unsigned int)-1) { skipped++; boost::wave::cpplexer::re2clex::aq_pop(s->eol_offsets); offset = get_first_eol_offset(s); } return skipped;}bool is_backslash( boost::wave::cpplexer::re2clex::uchar *p, boost::wave::cpplexer::re2clex::uchar *end, int &len){ if (*p == '\\') { len = 1; return true; } else if (*p == '?' && *(p+1) == '?' && (p+2 < end && *(p+2) == '/')) { len = 3; return true; } return false;}boost::wave::cpplexer::re2clex::uchar *fill(boost::wave::cpplexer::re2clex::Scanner *s, boost::wave::cpplexer::re2clex::uchar *cursor){ using namespace std; // some systems have memcpy etc. in namespace std using namespace boost::wave::cpplexer::re2clex; if(!s->eof) { uchar* p; std::ptrdiff_t cnt = s->tok - s->bot; if(cnt) { memcpy(s->bot, s->tok, s->lim - s->tok); s->tok = s->bot; s->ptr -= cnt; cursor -= cnt; s->lim -= cnt; adjust_eol_offsets(s, cnt); } if((s->top - s->lim) < BOOST_WAVE_BSIZE) { uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BOOST_WAVE_BSIZE)*sizeof(uchar)); if (buf == 0) { using namespace std; // some systems have printf in std if (0 != s->error_proc) { (*s->error_proc)(s, cpplexer::lexing_exception::unexpected_error, "Out of memory!"); } else printf("Out of memory!\n"); /* get the scanner to stop */ *cursor = 0; return cursor; } memcpy(buf, s->tok, s->lim - s->tok); s->tok = buf; s->ptr = &buf[s->ptr - s->bot]; cursor = &buf[cursor - s->bot]; s->lim = &buf[s->lim - s->bot]; s->top = &s->lim[BOOST_WAVE_BSIZE]; free(s->bot); s->bot = buf; } if (s->act != 0) { cnt = s->last - s->act; if (cnt > BOOST_WAVE_BSIZE) cnt = BOOST_WAVE_BSIZE; memcpy(s->lim, s->act, cnt); s->act += cnt; if (cnt != BOOST_WAVE_BSIZE) { s->eof = &s->lim[cnt]; *(s->eof)++ = '\0'; } } /* backslash-newline erasing time */ /* first scan for backslash-newline and erase them */ for (p = s->lim; p < s->lim + cnt - 2; ++p) { int len = 0; if (is_backslash(p, s->lim + cnt, len)) { if (*(p+len) == '\n') { int offset = len + 1; memmove(p, p + offset, s->lim + cnt - p - offset); cnt -= offset; --p; aq_enqueue(s->eol_offsets, p - s->bot + 1); } else if (*(p+len) == '\r') { if (*(p+len+1) == '\n') { int offset = len + 2; memmove(p, p + offset, s->lim + cnt - p - offset); cnt -= offset; --p; } else { int offset = len + 1; memmove(p, p + offset, s->lim + cnt - p - offset); cnt -= offset; --p; } aq_enqueue(s->eol_offsets, p - s->bot + 1); } } } /* FIXME: the following code should be fixed to recognize correctly the trigraph backslash token */ /* check to see if what we just read ends in a backslash */ if (cnt >= 2) { uchar last = s->lim[cnt-1]; uchar last2 = s->lim[cnt-2]; /* check \ EOB */ if (last == '\\') { int next = get_one_char(s); /* check for \ \n or \ \r or \ \r \n straddling the border */ if (next == '\n') { --cnt; /* chop the final \, we've already read the \n. */ boost::wave::cpplexer::re2clex::aq_enqueue(s->eol_offsets, cnt + (s->lim - s->bot)); } else if (next == '\r') { int next2 = get_one_char(s); if (next2 == '\n') { --cnt; /* skip the backslash */ } else { /* rewind one, and skip one char */ rewind_stream(s, -1); --cnt; } boost::wave::cpplexer::re2clex::aq_enqueue(s->eol_offsets, cnt + (s->lim - s->bot)); } else if (next != -1) /* -1 means end of file */ { /* next was something else, so rewind the stream */ rewind_stream(s, -1); } } /* check \ \r EOB */ else if (last == '\r' && last2 == '\\') { int next = get_one_char(s); if (next == '\n') { cnt -= 2; /* skip the \ \r */ } else { /* rewind one, and skip two chars */ rewind_stream(s, -1); cnt -= 2; } boost::wave::cpplexer::re2clex::aq_enqueue(s->eol_offsets, cnt + (s->lim - s->bot)); } /* check \ \n EOB */ else if (last == '\n' && last2 == '\\') { cnt -= 2; boost::wave::cpplexer::re2clex::aq_enqueue(s->eol_offsets, cnt + (s->lim - s->bot)); } } s->lim += cnt; if (s->eof) /* eof needs adjusting if we erased backslash-newlines */ { s->eof = s->lim; *(s->eof)++ = '\0'; } } return cursor;}boost::wave::token_id scan(boost::wave::cpplexer::re2clex::Scanner *s){ using namespace boost::wave::cpplexer::re2clex; uchar *cursor = s->tok = s->cur;#line 378 "idl.re"#line 366 "idl_re.cpp"{ YYCTYPE yych; unsigned int yyaccept = 0; static const unsigned char yybm[] = { /* table 1 .. 8: 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 32, 56, 56, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 56, 40, 56, 56, 56, 56, 56, 56, 56, 152, 56, 56, 56, 56, 56, 59, 59, 59, 59, 59, 59, 59, 59, 58, 58, 56, 56, 56, 56, 48, 56, 56, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 56, 56, 56, 56, 58, 56, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, /* table 9 .. 15: 256 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 0, 70, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 68, 64, 68, 68, 68, 68, 4, 68, 68, 68, 68, 68, 68, 68, 68, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 68, 68, 68, 68, 68, 16, 68, 76, 76, 76, 76, 76, 76, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 32, 68, 68, 68, 68, 76, 76, 76, 76, 76, 76, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, }; if ((YYLIMIT - YYCURSOR) < 12) YYFILL(12); yych = *YYCURSOR; switch (yych) { case 0x00: goto yy69; case 0x09: case 0x0B: case 0x0C: case ' ': goto yy64; case 0x0A: goto yy66; case 0x0D: goto yy68; case '!': goto yy45; case '"': goto yy63; case '#': goto yy15; case '%': goto yy35; case '&': goto yy39; case '\'': goto yy62; case '(': goto yy17; case ')': goto yy19; case '*': goto yy33; case '+': goto yy29; case ',': goto yy53; case '-': goto yy31; case '.': goto yy27; case '/': goto yy2; case '0': goto yy59; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': goto yy61; case ':': goto yy23; case ';': goto yy21; case '<': goto yy49; case '=': goto yy47; case '>': goto yy51; case '?': goto yy25; case 'A': case 'B': case 'C': case 'D': case 'E': case 'G': case 'H': case 'I': case 'J': case 'K': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?