lestes::lang::cplus::lex::taboo_macros Class Reference

Set of taboo macros. More...

#include <taboo_macros.hh>

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

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

Public Member Functions

ucn_string names_get (void) const
bool contains (const ptr< macro > &a_macro) const
 Tests macro membership.
ptr< taboo_macrosextend (const ptr< macro > &a_macro) const
 Returns new set with added macro.

Static Public Member Functions

static ptr< taboo_macroscreate (void)
 Returns empty set.

Protected Member Functions

 taboo_macros (void)
 Creates empty set.
virtual void gc_mark (void)
 Marks the object.

Private Types

typedef ::lestes::std::set<
srp< macro > > 
taboo_type
 Type of set of macros.
typedef ::lestes::std::map<
srp< macro >, srp< taboo_macros > > 
shared_type
 Type of auxiliary map for sharing newly created instances.

Private Member Functions

 taboo_macros (const ptr< taboo_macros > &copy, const ptr< macro > &a_macro)
 Creates a copy of the object with added macro.

Private Attributes

srp< taboo_typetaboo
 Set of taboo macros.
srp< shared_typeshared
 Internal map to remember objects created by extend.

Static Private Attributes

static ptr< taboo_macrosempty_instance
 Internal shared empty instance.

Detailed Description

Set of taboo macros.

Represents a set of macros, which shall not be expanded. The set is constant and extending it creates a new set.

Definition at line 56 of file taboo_macros.hh.


Member Typedef Documentation

typedef ::lestes::std::set< srp<macro> > lestes::lang::cplus::lex::taboo_macros::taboo_type [private]

Type of set of macros.

Definition at line 75 of file taboo_macros.hh.

typedef ::lestes::std::map< srp<macro>, srp<taboo_macros> > lestes::lang::cplus::lex::taboo_macros::shared_type [private]

Type of auxiliary map for sharing newly created instances.

Definition at line 77 of file taboo_macros.hh.


Constructor & Destructor Documentation

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

Creates empty set.

Creates new empty set.

Postcondition:
taboo->length() == 0

shared->length() == 0

Definition at line 53 of file taboo_macros.cc.

Referenced by create().

00053                               :
00054         taboo(taboo_type::create()),
00055         shared(shared_type::create())
00056 {
00057 }

lestes::lang::cplus::lex::taboo_macros::taboo_macros ( const ptr< taboo_macros > &  source,
const ptr< macro > &  a_macro 
) [private]

Creates a copy of the object with added macro.

Creates copy of set, adding a new macro.

Precondition:
source != NULL
Postcondition:
taboo->length() == source->taboo->length() + (source->contains(a_macro) ? 0 : 1)

shared->length() == 0

Parameters:
source The source object to copy.
a_macro The macro to insert into new object's set.

Definition at line 67 of file taboo_macros.cc.

References lassert, and taboo.

00067                                                                                     :
00068         taboo(taboo_type::create()),
00069         shared(shared_type::create())
00070 {
00071         lassert(source);
00072         lassert(a_macro);
00073         
00074         // copy the content
00075         // TODO pt make more elegant
00076         // ??? bad bad coder copy(source->taboo->begin(),source->taboo->end(),inserter(*taboo));
00077         
00078         for (taboo_type::iterator it = source->taboo->begin(),
00079                         end = source->taboo->end(); it != end; ++it) {
00080                 taboo->insert(*it);
00081         }
00082 
00083         // add the new macro
00084         taboo->insert(a_macro);
00085         /* TODO pt ::std::cerr << "inserted taboo " << a_macro->name_get()->content_get() << " :";
00086         
00087         for (taboo_type::iterator it = taboo->begin(),
00088                         end = taboo->end(); it != end; ++it) {
00089                 ::std::cerr << ' ' << (*it)->name_get()->content_get();
00090         }
00091 
00092         ::std::cerr << (taboo->find(a_macro) != taboo->end() ? "found" : "BOOM") << '\n';
00093         */
00094 }


Member Function Documentation

ucn_string lestes::lang::cplus::lex::taboo_macros::names_get ( void   )  const

Definition at line 158 of file taboo_macros.cc.

References taboo, and u.

00159 {
00160         ucn_string u;
00161         
00162         u += character::create_from_host('{');
00163 
00164         for (taboo_type::iterator it = taboo->begin(),
00165                         end = taboo->end(); it != end; ++it) {
00166                 u += character::create_from_host(' ');
00167                 u += (*it)->name_get()->content_get();
00168         }
00169         
00170         u += character::create_from_host('}');
00171         return u;
00172 }

bool lestes::lang::cplus::lex::taboo_macros::contains ( const ptr< macro > &  a_macro  )  const

Tests macro membership.

Tests whether the taboo set contains a macro.

Parameters:
a_macro The macro to test.
Returns:
true If the macro is contained in the set.

Definition at line 115 of file taboo_macros.cc.

References taboo.

Referenced by extend().

00116 {
00117         return taboo->find(a_macro) != taboo->end();
00118 }

ptr< taboo_macros > lestes::lang::cplus::lex::taboo_macros::extend ( const ptr< macro > &  a_macro  )  const

Returns new set with added macro.

Returns new taboo set with added macro.

Precondition:
a_macro != NULL
Parameters:
a_macro The macro to be added to the new taboo.
Returns:
New object with set extended by a_macro.

Definition at line 126 of file taboo_macros.cc.

References contains(), lassert, and shared.

00127 {
00128         lassert(a_macro);
00129         
00130         // macro is already in this instance
00131         if (contains(a_macro)) return ptr<taboo_macros>(const_cast<taboo_macros *>(this));
00132         
00133         // lookup the cache of extensions
00134         shared_type::iterator it = shared->find(a_macro);
00135         // return shared instance
00136         if (it != shared->end()) return (*it).second;
00137         
00138         // call special "copy and extend" constructor
00139         ptr<taboo_macros> nju = ptr<taboo_macros>(
00140                         new taboo_macros(ptr<taboo_macros>(const_cast<taboo_macros *>(this)),a_macro));
00141         
00142         // record into cache
00143         shared->insert(make_pair(a_macro,nju));
00144                         
00145         return nju;
00146 }

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

Returns empty set.

Returns empty taboo set.

Postcondition:
taboo->length() == 0
Returns:
Instance containing no macros.

Definition at line 101 of file taboo_macros.cc.

References empty_instance, and taboo_macros().

Referenced by lestes::lang::cplus::lex::pp_token::create(), and lestes::lang::cplus::lex::pp_token::create_alternative().

00102 {
00103         if (!empty_instance) {
00104                 empty_instance = new taboo_macros();
00105         }
00106         return empty_instance;
00107 }

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

Marks the object.

Marks the object.

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

Definition at line 151 of file taboo_macros.cc.

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

00152 {
00153         taboo.gc_mark();
00154         shared.gc_mark();
00155 	::lestes::std::object::gc_mark();
00156 }


Member Data Documentation

srp<taboo_type> lestes::lang::cplus::lex::taboo_macros::taboo [private]

Set of taboo macros.

Definition at line 79 of file taboo_macros.hh.

Referenced by contains(), gc_mark(), names_get(), and taboo_macros().

srp<shared_type> lestes::lang::cplus::lex::taboo_macros::shared [mutable, private]

Internal map to remember objects created by extend.

Definition at line 81 of file taboo_macros.hh.

Referenced by extend(), and gc_mark().

ptr< taboo_macros > lestes::lang::cplus::lex::taboo_macros::empty_instance [static, private]

Internal shared empty instance.

The shared empty instance of taboo macros. Used for fast initialization of tokens.

Definition at line 83 of file taboo_macros.hh.

Referenced by create().


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