#include <trigraphs.hh>
Inheritance diagram for lestes::lang::cplus::lex::trigraphs:

Public Member Functions | |
| ptr< ucn_token > | read (void) |
| Reads next token. | |
Static Public Member Functions | |
| static ptr< trigraphs > | create (void) |
| Returns new instance. | |
Protected Member Functions | |
| trigraphs (void) | |
| Creates new instance. | |
| virtual void | gc_mark (void) |
| Marks the object. | |
Private Types | |
| enum | state_type { START = 0, QUE = 1, QUEQUE = 2, ONE = 3, TWO = 4 } |
| States of the trigraph processor. More... | |
Private Member Functions | |
| trigraphs (const trigraphs ©) | |
| Hides copy constructor. | |
| trigraphs & | operator= (const trigraphs &rhs) |
| Hides assignment operator. | |
Private Attributes | |
| state_type | state |
| Current state of the processor. | |
| srp< ucn_token > | first |
| First buffered token. | |
| srp< ucn_token > | second |
| Second buffered token. | |
Static Private Attributes | |
| static const ulint | translation_length = 128 |
| Length of map of trigraph translations. | |
| static const ucn | translation_map [translation_length] |
| Map of trigraph translations, also serves as flags. | |
Maps trigraph sequences to their translations.
Definition at line 51 of file trigraphs.hh.
enum lestes::lang::cplus::lex::trigraphs::state_type [private] |
States of the trigraph processor.
| START | No tokens in buffer. |
| QUE | One question mark in buffer. |
| QUEQUE | Two question marks in buffer. |
| ONE | One ordinary token in buffer. |
| TWO | Two ordinary tokens in buffer. |
Definition at line 68 of file trigraphs.hh.
00068 { 00069 //! No tokens in buffer. 00070 START = 0, 00071 //! One question mark in buffer. 00072 QUE = 1, 00073 //! Two question marks in buffer. 00074 QUEQUE = 2, 00075 //! One ordinary token in buffer. 00076 ONE = 3, 00077 //! Two ordinary tokens in buffer. 00078 TWO = 4 00079 } state_type;
| lestes::lang::cplus::lex::trigraphs::trigraphs | ( | void | ) | [protected] |
Creates new instance.
Creates new instance.
Definition at line 53 of file trigraphs.cc.
Referenced by create().
00053 : 00054 ucn_filter(), 00055 state(START) 00056 { 00057 }
| lestes::lang::cplus::lex::trigraphs::trigraphs | ( | const trigraphs & | copy | ) | [private] |
Hides copy constructor.
| ptr< ucn_token > lestes::lang::cplus::lex::trigraphs::read | ( | void | ) | [virtual] |
Reads next token.
Reads next token after translation of trigraph sequences.
Implements lestes::lang::cplus::lex::ucn_filter.
Definition at line 63 of file trigraphs.cc.
References lestes::msg::eolog, first, lestes::lang::cplus::lex::ucn_filter::input_read(), lassert2, ONE, QUE, QUEQUE, second, START, state, lestes::lang::cplus::lex::ucn_token::TOK_BASIC, translation_map, TWO, and u.
00064 { 00065 trigraphs_logger << "trigraphs::read()\n" << msg::eolog; 00066 trigraphs_logger << "state == " << state["sqQ12"] << '\n' << msg::eolog; 00067 00068 ptr<ucn_token> t; 00069 00070 switch (state) { 00071 case ONE: 00072 // flush one token 00073 t = first; 00074 // release reference 00075 first = NULL; 00076 state = START; 00077 trigraphs_logger << "return only saved\ntrigraphs::read() end\n" << msg::eolog; 00078 return t; 00079 case TWO: 00080 // flush one of two tokens 00081 t = first; 00082 first = second; 00083 // release reference 00084 second = NULL; 00085 state = ONE; 00086 trigraphs_logger << "return first saved\ntrigraphs::read() end\n" << msg::eolog; 00087 return t; 00088 default: 00089 break; 00090 } 00091 00092 while (true) { 00093 t = input_read(); 00094 ucn_token_type utt = t->type_get(); 00095 // can return out of order, location is already recorded 00096 // if (utt == ucn_token::TOK_ERROR) 00097 // return t; 00098 00099 switch (state) { 00100 case START: 00101 if (utt == ucn_token::TOK_BASIC && t->value_get() == character::ascii_qmark) { 00102 // first '?' 00103 state = QUE; 00104 first = t; 00105 } else { 00106 trigraphs_logger << "trigraphs::read() end\n" << msg::eolog; 00107 return t; 00108 } 00109 break; 00110 case QUE: 00111 if (utt == ucn_token::TOK_BASIC && t->value_get() == character::ascii_qmark) { 00112 // second '?' 00113 state = QUEQUE; 00114 second = t; 00115 } else { 00116 ptr<ucn_token> tmp; 00117 // flush first 00118 tmp = first; 00119 // prepare to flush the second 00120 first = t; 00121 state = ONE; 00122 trigraphs_logger << "trigraphs::read() end\n" << msg::eolog; 00123 return tmp; 00124 } 00125 break; 00126 case QUEQUE: 00127 // found trigraph sequence 00128 if (utt == ucn_token::TOK_BASIC) { 00129 ucn u = t->value_get(); 00130 ucn v = translation_map[character::extract_value(u)]; 00131 if (v != 0) { 00132 t = first; 00133 // release the reference 00134 first = NULL; 00135 t = t->clone_value(v); 00136 state = START; 00137 trigraphs_logger << "trigraphs::read() end\n" << msg::eolog; 00138 return t; 00139 } 00140 00141 // check the third token, with '?' so there will be "??" again 00142 state = u == character::ascii_qmark ? QUEQUE : TWO; 00143 } else { 00144 // there will be ordinary "?X" sequence in the buffer 00145 state = TWO; 00146 } 00147 00148 00149 { 00150 // shift the buffer 00151 ptr<ucn_token> tmp = first; 00152 first = second; 00153 second = t; 00154 trigraphs_logger << "trigraphs::read() end\n" << msg::eolog; 00155 return tmp; 00156 } 00157 default: 00158 lassert2(false,"You should never get here"); 00159 } 00160 trigraphs_logger << "state == " << state["sqQ12"] << '\n' << msg::eolog; 00161 } 00162 }
| ptr< trigraphs > lestes::lang::cplus::lex::trigraphs::create | ( | void | ) | [static] |
Returns new instance.
Returns new instance.
Definition at line 178 of file trigraphs.cc.
References trigraphs().
00179 { 00180 return new trigraphs(); 00181 }
| void lestes::lang::cplus::lex::trigraphs::gc_mark | ( | void | ) | [protected, virtual] |
Marks the object.
Marks the object.
Reimplemented from lestes::lang::cplus::lex::ucn_filter.
Definition at line 167 of file trigraphs.cc.
References first, lestes::lang::cplus::lex::ucn_filter::gc_mark(), and second.
00168 { 00169 first.gc_mark(); 00170 second.gc_mark(); 00171 ucn_filter::gc_mark(); 00172 }
Hides assignment operator.
const ulint lestes::lang::cplus::lex::trigraphs::translation_length = 128 [static, private] |
const ucn lestes::lang::cplus::lex::trigraphs::translation_map [static, private] |
Initial value:
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
character::ascii_vbar,
0, 0, 0, 0, 0,
character::ascii_hat,
character::ascii_left_bracket,
character::ascii_right_bracket,
0, 0, 0,
character::ascii_tilde,
0,
character::ascii_backslash,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
character::ascii_left_brace,
character::ascii_hash,
character::ascii_right_brace,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
}
Trigraph translation map. Defines mapping between ASCII characters. Zero values have no defined translation.
Definition at line 83 of file trigraphs.hh.
Referenced by read().
srp<ucn_token> lestes::lang::cplus::lex::trigraphs::first [private] |
srp<ucn_token> lestes::lang::cplus::lex::trigraphs::second [private] |
1.5.1-20070107