lestes::lang::cplus::lex::macro_arguments Class Reference

Macro argument list. More...

#include <macro_arguments.hh>

Inheritance diagram for lestes::lang::cplus::lex::macro_arguments:

lestes::std::object lestes::std::mem::keystone List of all members.

Public Member Functions

bool parse (const ptr< token_input > &input)
 Parses argument list.
ulint length (void) const
 Returns length of the list.
ptr< macro_argumentargument_get (ulint index) const
 Returns argument at specified index.
bool check (ulint pars_length) const
 Checks if the arguments match parameter list length.

Static Public Member Functions

static ptr< macro_argumentscreate (void)
 Returns empty list.

Protected Member Functions

 macro_arguments (void)
 Creates empty list.
virtual void gc_mark (void)
 Marks the object.

Private Types

enum  state_type { BEGIN, PARSED, PARSED_EMPTY, DEAD }
 Type of internal state. More...
typedef vector< srp< macro_argument > > arguments_type
 Type of list of macro arguments.

Private Attributes

state_type state
 Internal state of the object.
srp< arguments_typearguments
 List of macro arguments.

Detailed Description

Macro argument list.

Represents list of macro arguments. Arguments can be empty, which introduces certain ambiguity when dealing with single empty argument, which is the same as no argument at all. Such argument list has state == PARSED_EMPTY, length() == 1 and one empty argument.

Definition at line 56 of file macro_arguments.hh.


Member Typedef Documentation

typedef vector< srp<macro_argument> > lestes::lang::cplus::lex::macro_arguments::arguments_type [private]

Type of list of macro arguments.

Definition at line 79 of file macro_arguments.hh.


Member Enumeration Documentation

enum lestes::lang::cplus::lex::macro_arguments::state_type [private]

Type of internal state.

Enumerator:
BEGIN 
PARSED 
PARSED_EMPTY 
DEAD 

Definition at line 75 of file macro_arguments.hh.


Constructor & Destructor Documentation

lestes::lang::cplus::lex::macro_arguments::macro_arguments ( void   )  [protected]

Creates empty list.

Creates empty list.

Postcondition:
state == BEGIN

length() == 0

Definition at line 50 of file macro_arguments.cc.

Referenced by create().

00050                                     :
00051         state(BEGIN),
00052         arguments(arguments_type::create())
00053 {
00054 }


Member Function Documentation

bool lestes::lang::cplus::lex::macro_arguments::parse ( const ptr< token_input > &  input  ) 

Parses argument list.

Parses macro argument list in parentheses.

Precondition:
state == BEGIN
Parameters:
input The source for arguments, starting with '(' token.
Returns:
false In case of parse error.

Definition at line 62 of file macro_arguments.cc.

References arguments, BEGIN, lestes::lang::cplus::lex::macro_argument::CONTINUE, lestes::lang::cplus::lex::macro_argument::create(), DEAD, lestes::lang::cplus::lex::macro_argument::EMPTY, lassert, lestes::lang::cplus::lex::macro_argument::LAST, PARSED, PARSED_EMPTY, state, and lestes::lang::cplus::lex::pp_token::TOK_LEFT_PAR.

00063 {
00064         lassert(state == BEGIN);
00065 
00066         ptr<pp_token> t;
00067         t = input->read_front();
00068         
00069         lassert(t->type_get() == pp_token::TOK_LEFT_PAR);
00070         
00071         bool first = true;
00072         macro_argument::result_type result;
00073 
00074         do {
00075                 ptr<macro_argument> ma = macro_argument::create();
00076                 result = ma->parse(input,first);
00077                 first = false;
00078                 
00079                 arguments->push_back(ma);
00080 
00081                 if (result == macro_argument::EMPTY) {
00082                         state = PARSED_EMPTY;
00083                         return true;
00084                 }
00085         
00086         } while (result == macro_argument::CONTINUE);
00087 
00088         if (result == macro_argument::LAST) {
00089                 state = PARSED;
00090                 return true;
00091         }
00092 
00093         // else result == macro_argument::ERROR
00094         state = DEAD;
00095         return false;
00096 }

ulint lestes::lang::cplus::lex::macro_arguments::length ( void   )  const

Returns length of the list.

Returns length of the argument list.

Precondition:
state == PARSED || state == PARSED_EMPTY
Returns:
Length of the argument list.

Definition at line 103 of file macro_arguments.cc.

References arguments, lassert, PARSED, PARSED_EMPTY, and state.

Referenced by argument_get(), and check().

00104 {
00105         lassert(state == PARSED || state == PARSED_EMPTY);
00106         return arguments->size();
00107 }

ptr< macro_argument > lestes::lang::cplus::lex::macro_arguments::argument_get ( ulint  index  )  const

Returns argument at specified index.

Returns argument at specified position.

Precondition:
state == PARSED || state == PARSED_EMPTY

index < length()

Parameters:
index The index of the desired argument.
Returns:
The argument at specified index.

Definition at line 129 of file macro_arguments.cc.

References arguments, lassert, length(), PARSED, PARSED_EMPTY, and state.

00130 {
00131         lassert(state == PARSED || state == PARSED_EMPTY);
00132         lassert(index < length());
00133         return arguments->at(index);
00134 }

bool lestes::lang::cplus::lex::macro_arguments::check ( ulint  pars_length  )  const

Checks if the arguments match parameter list length.

Checks whether the arguments match the length of a parameter list. Either the lengths are the same, or there is no parameters and the argument list is empty.

Precondition:
state == PARSED || state == PARSED_EMPTY
pars_length The length of the checked parameter list.
Returns:
true If the length matches or state == PARSED_EMPTY and pars_length == 0.

Definition at line 116 of file macro_arguments.cc.

References lassert, length(), PARSED, PARSED_EMPTY, and state.

00117 {
00118         lassert(state == PARSED || state == PARSED_EMPTY);
00119         return length() == pars_length || (pars_length == 0 && state == PARSED_EMPTY);
00120 }

ptr< macro_arguments > lestes::lang::cplus::lex::macro_arguments::create ( void   )  [static]

Returns empty list.

Returns new empty argument list.

Postcondition:
state == BEGIN

length() == 0

Definition at line 150 of file macro_arguments.cc.

References macro_arguments().

Referenced by lestes::lang::cplus::lex::macro::expand().

00151 {
00152         return new macro_arguments();
00153 }

void lestes::lang::cplus::lex::macro_arguments::gc_mark ( void   )  [protected, virtual]

Marks the object.

Marks the object.

Reimplemented from lestes::std::mem::keystone.

Definition at line 139 of file macro_arguments.cc.

References arguments, and lestes::std::mem::keystone::gc_mark().

00140 {
00141         arguments.gc_mark();
00142 	::lestes::std::object::gc_mark();
00143 }


Member Data Documentation

state_type lestes::lang::cplus::lex::macro_arguments::state [private]

Internal state of the object.

Definition at line 77 of file macro_arguments.hh.

Referenced by argument_get(), check(), length(), and parse().

srp<arguments_type> lestes::lang::cplus::lex::macro_arguments::arguments [private]

List of macro arguments.

Definition at line 81 of file macro_arguments.hh.

Referenced by argument_get(), gc_mark(), length(), and parse().


The documentation for this class was generated from the following files:
Generated on Mon Feb 12 18:24:17 2007 for lestes by doxygen 1.5.1-20070107