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

Public Member Functions | |
| ptr< source_location > | location_get (void) const |
| Returns definition location. | |
| ptr< token_value > | name_get (void) const |
| Returns macro name. | |
| bool | funlike_get (void) const |
| Returns function-like flag. | |
| bool | predefined_get (void) const |
| Returns predefined flag. | |
| ptr< token_sequence > | expand (const ptr< pp_token > &name, const ptr< token_input > &input, const ptr< macro_storage > ¯os) |
| Expands macro. | |
| bool | parse (const ptr< token_input > &ts) |
| Parses the macro definition. | |
| bool | equals (const ptr< macro > &other) const |
| Tests equality. | |
Static Public Member Functions | |
| static ptr< macro > | create (void) |
| Creates empty object. | |
| static ptr< macro > | create_predefined (void) |
| Creates predefined macro. | |
Protected Member Functions | |
| macro (void) | |
| Constructs empty object. | |
| virtual void | gc_mark (void) |
| Marks the object. | |
Private Types | |
| enum | state_type { BEGIN, PARSED, DEAD } |
| Type of internal state. More... | |
Private Member Functions | |
| bool | parse_name (const ptr< token_input > &input) |
| Parses name. | |
| bool | parse_head (const ptr< token_input > &input) |
| Parses parameter list. | |
| bool | parse_body (const ptr< token_input > &input) |
| Parses expansion list. | |
Private Attributes | |
| state_type | state |
| Internal state of the object. | |
| srp< source_location > | location |
| Location of definition. | |
| srp< token_value > | name |
| Name of the macro. | |
| bool | funlike |
| Flag designating function-like macro. | |
| bool | predefined |
| Flag designating predefined macro. | |
| srp< macro_head > | head |
| Parameter list of the macro. | |
| srp< macro_body > | body |
| Expansion list of the macro. | |
Represents stored preprocessor macro.
Definition at line 66 of file macro.hh.
enum lestes::lang::cplus::lex::macro::state_type [private] |
| lestes::lang::cplus::lex::macro::macro | ( | void | ) | [protected] |
Constructs empty object.
Creates new empty macro object.
Definition at line 61 of file macro.cc.
Referenced by create().
00061 : 00062 state(BEGIN), 00063 location(), 00064 name(), 00065 funlike(false), 00066 predefined(false), 00067 head(macro_head::create()), 00068 body(macro_body::create()) 00069 { 00070 }
| ptr< source_location > lestes::lang::cplus::lex::macro::location_get | ( | void | ) | const |
| ptr< token_value > lestes::lang::cplus::lex::macro::name_get | ( | void | ) | const |
| bool lestes::lang::cplus::lex::macro::funlike_get | ( | void | ) | const |
| bool lestes::lang::cplus::lex::macro::predefined_get | ( | void | ) | const |
| ptr< token_sequence > lestes::lang::cplus::lex::macro::expand | ( | const ptr< pp_token > & | a_name, | |
| const ptr< token_input > & | input, | |||
| const ptr< macro_storage > & | macros | |||
| ) |
Expands macro.
Expands this macro, if the call matches the definition, taking possible arguments from input.
| input | The source of possible arguments, starting at macro name. | |
| loc | The location of the macro expansion. |
The expanded, but not rescanned sequence if the call matched the definition.
NULL in case of nested error.
Definition at line 223 of file macro.cc.
References body, lestes::lang::cplus::lex::macro_arguments::create(), funlike_get(), head, lestes::lang::cplus::lex::invalid_argument_count, lassert, name, lestes::report, lestes::lang::cplus::lex::pp_token::TOK_LEFT_PAR, and lestes::lang::cplus::lex::unterminated_argument_list.
00225 { 00226 ptr<source_location> loc = a_name->location_get(); 00227 00228 if (funlike_get()) { 00229 ptr<pp_token> tok = input->peek_front(); 00230 lassert(tok->type_get() == pp_token::TOK_LEFT_PAR); 00231 00232 ptr<macro_arguments> mas = macro_arguments::create(); 00233 if (!mas->parse(input)) { 00234 // missing terminating `)' 00235 report << unterminated_argument_list << name->content_get() << loc; 00236 return NULL; 00237 } 00238 00239 if (!mas->check(head->length())) { 00240 // argument count is different from parameter count 00241 report << invalid_argument_count << name->content_get() << mas->length() << loc; 00242 return NULL; 00243 } 00244 00245 // expand function-like 00246 return body->expand(loc,mas,macros); 00247 } 00248 // expand object-like 00249 return body->expand(loc); 00250 }
| bool lestes::lang::cplus::lex::macro::parse | ( | const ptr< token_input > & | input | ) |
Parses the macro definition.
Parses macro definition and stores data into self.
| input | The source for tokens, starting before macro name. |
Definition at line 152 of file macro.cc.
References BEGIN, DEAD, lassert, parse_body(), parse_head(), parse_name(), PARSED, and state.
00153 { 00154 lassert(state == BEGIN); 00155 00156 if (!parse_name(input)) { 00157 state = DEAD; 00158 return false; 00159 } 00160 if (!parse_head(input)) { 00161 state = DEAD; 00162 return false; 00163 } 00164 if (!parse_body(input)) { 00165 state = DEAD; 00166 return false; 00167 } 00168 state = PARSED; 00169 return true; 00170 }
| bool lestes::lang::cplus::lex::macro::equals | ( | const ptr< macro > & | other | ) | const |
Tests equality.
Returns whether macro definitions are equal.
| other | The macro to compare with. |
Definition at line 257 of file macro.cc.
References body, head, and lestes::is_equal().
00258 { 00259 if (!other) return false; 00260 00261 if (!is_equal(head,other->head)) return false; 00262 00263 if (!is_equal(body,other->body)) return false; 00264 return true; 00265 }
| ptr< macro > lestes::lang::cplus::lex::macro::create | ( | void | ) | [static] |
| static ptr<macro> lestes::lang::cplus::lex::macro::create_predefined | ( | void | ) | [static] |
Creates predefined macro.
| void lestes::lang::cplus::lex::macro::gc_mark | ( | void | ) | [protected, virtual] |
Marks the object.
Marks the object.
Reimplemented from lestes::std::mem::keystone.
Definition at line 270 of file macro.cc.
References body, lestes::std::mem::keystone::gc_mark(), head, location, and name.
00271 { 00272 location.gc_mark(); 00273 name.gc_mark(); 00274 head.gc_mark(); 00275 body.gc_mark(); 00276 ::lestes::std::object::gc_mark(); 00277 }
| bool lestes::lang::cplus::lex::macro::parse_name | ( | const ptr< token_input > & | input | ) | [private] |
Parses name.
Parses macro name and stores into self.
| input | The source for tokens, starting before macro name. |
Definition at line 110 of file macro.cc.
References lestes::lang::cplus::lex::token_value::create(), lestes::lang::cplus::lex::defined_invalid_macro_name, lestes::lang::cplus::lex::definition_expects_macro_name, lestes::is_equal(), location, lestes::lang::cplus::lex::macro_name_alt_operator, lestes::lang::cplus::lex::macro_name_identifier, name, lestes::report, and lestes::lang::cplus::lex::pp_token::TOK_LINE_END.
Referenced by parse().
00111 { 00112 ptr<pp_token> t = input->read_front_skip_ws(); 00113 00114 // the location of the macro will be the name in the definition 00115 location = t->location_get(); 00116 00117 if (t->type_get() == pp_token::TOK_LINE_END) { 00118 // no macro name at all 00119 report << definition_expects_macro_name << location; 00120 return false; 00121 } 00122 00123 if (t->is_alternative()) { 00124 // C++ operator alternative spelling are not identifiers 00125 report << macro_name_alt_operator << t->spelling_get() << location; 00126 return false; 00127 } 00128 00129 if (!t->is_name()) { 00130 // macro name must be an identifier 00131 report << macro_name_identifier << location; 00132 return false; 00133 } 00134 00135 name = t->value_get(); 00136 00137 if (is_equal(name,token_value::create("defined"))) { 00138 // defined is reserved as macro name 00139 report << defined_invalid_macro_name << location; 00140 return false; 00141 } 00142 00143 return true; 00144 }
| bool lestes::lang::cplus::lex::macro::parse_head | ( | const ptr< token_input > & | input | ) | [private] |
Parses parameter list.
Parses macro parameter list, sets funlike and stores parameters into self.
| input | The source for tokens, starting after macro name. |
Definition at line 77 of file macro.cc.
References funlike, head, and lestes::lang::cplus::lex::pp_token::TOK_LEFT_PAR.
Referenced by parse().
00078 { 00079 ptr<pp_token> t = input->peek_front(); 00080 00081 if (t->type_get() != pp_token::TOK_LEFT_PAR) { 00082 funlike = false; 00083 // no parameters 00084 return true; 00085 } 00086 00087 // discard the left par 00088 input->read_front(); 00089 00090 funlike = true; 00091 00092 return head->parse(input); 00093 }
| bool lestes::lang::cplus::lex::macro::parse_body | ( | const ptr< token_input > & | input | ) | [private] |
Parses expansion list.
Parses macro replacement list and stores values into self.
| input | The source for tokens, starting at the beginning of the replacement list. |
Definition at line 100 of file macro.cc.
References body, funlike, and head.
Referenced by parse().
Internal state of the object.
Definition at line 105 of file macro.hh.
Referenced by funlike_get(), name_get(), parse(), and predefined_get().
srp<source_location> lestes::lang::cplus::lex::macro::location [private] |
Location of definition.
Definition at line 107 of file macro.hh.
Referenced by gc_mark(), location_get(), and parse_name().
srp<token_value> lestes::lang::cplus::lex::macro::name [private] |
Name of the macro.
Definition at line 109 of file macro.hh.
Referenced by expand(), gc_mark(), name_get(), and parse_name().
bool lestes::lang::cplus::lex::macro::funlike [private] |
Flag designating function-like macro.
Definition at line 111 of file macro.hh.
Referenced by funlike_get(), parse_body(), and parse_head().
bool lestes::lang::cplus::lex::macro::predefined [private] |
Flag designating predefined macro.
Definition at line 113 of file macro.hh.
Referenced by predefined_get().
srp<macro_head> lestes::lang::cplus::lex::macro::head [private] |
Parameter list of the macro.
Definition at line 115 of file macro.hh.
Referenced by equals(), expand(), gc_mark(), parse_body(), and parse_head().
srp<macro_body> lestes::lang::cplus::lex::macro::body [private] |
1.5.1-20070107