[Uml-devel] KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser
Jean Vittor
jean.vittor at free.fr
Wed Apr 9 12:13:08 UTC 2008
SVN commit 795179 by jvittor:
add a grammar for macro definitions
M +28 -27 driver.h
M +45 -19 preprocesslexer.cpp
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/driver.h #795178:795179
@@ -93,44 +93,45 @@
class Macro
{
public:
- typedef QString Argument;
+ typedef QString Argument;
typedef std::list<Argument> ArgumentList;
Macro() {}
+ Macro( const QString &n) : m_name( n) {}
Macro( const QString &n, const QString &b ) : m_name( n ), m_body( b ) {}
- Macro( const Macro& source )
- : m_name( source.m_name),
- m_fileName( source.m_fileName ),
- m_body( source.m_body ),
+ Macro( const Macro& source )
+ : m_name( source.m_name),
+ m_fileName( source.m_fileName ),
+ m_body( source.m_body ),
m_arguments( source.m_arguments) {}
- Macro& operator = ( const Macro& source )
- {
- m_name = source.m_name;
- m_body = source.m_body;
- m_fileName = source.m_fileName;
+ Macro& operator = ( const Macro& source )
+ {
+ m_name = source.m_name;
+ m_body = source.m_body;
+ m_fileName = source.m_fileName;
m_arguments = source.m_arguments;
- return *this;
- }
+ return *this;
+ }
- bool operator == ( const Macro& source ) const
- {
- return
- m_name == source.m_name &&
- m_fileName == source.m_fileName &&
- m_body == source.m_body &&
+ bool operator == ( const Macro& source ) const
+ {
+ return
+ m_name == source.m_name &&
+ m_fileName == source.m_fileName &&
+ m_body == source.m_body &&
m_arguments == source.m_arguments;
- }
+ }
QString const& name() const {return m_name;}
- void setName( const QString& name ) { m_name = name; }
+ void setName( const QString& name ) { m_name = name; }
- QString fileName() const { return m_fileName; }
- void setFileName( const QString& fileName ) { m_fileName = fileName; }
+ QString fileName() const { return m_fileName; }
+ void setFileName( const QString& fileName ) { m_fileName = fileName; }
- QString body() const { return m_body; }
- void setBody( const QString& body ) { m_body = body; }
+ QString body() const { return m_body; }
+ void setBody( const QString& body ) { m_body = body; }
bool hasArguments() const { return !m_arguments.empty();}
ArgumentList const& arguments() const {return m_arguments;}
@@ -139,9 +140,9 @@
void push_back( Argument const& argument)
{m_arguments.push_back( argument);}
private:
- QString m_name;
- QString m_fileName;
- QString m_body;
+ QString m_name;
+ QString m_fileName;
+ QString m_body;
ArgumentList m_arguments;
};
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp #795178:795179
@@ -478,10 +478,7 @@
QString tokText = tok.text();
QString str = (tok == Token_identifier && m_data->hasBind(tokText)) ? m_data->apply( tokText ) : tokText;
if( str == ide ){
- //Problem p( i18n("unsafe use of macro '%1'").arg(ide), m_currentLine, m_currentColumn );
- //m_driver->addProblem( m_driver->currentFileName(), p );
m_driver->removeMacro( ide );
- // str = QString();
}
if( stringify ) {
@@ -679,26 +676,55 @@
return m_driver->hasMacro( word );
}
+struct push_back_c_impl {
+ template <typename Container, typename Item>
+ struct result {typedef void type;};
+ template <typename Container, typename Item>
+ void operator()(Container& c, Item const& item) const
+ {c.push_back( item);}
+};
+
+function<push_back_c_impl> const push_back_c = push_back_c_impl();
+
+struct macroDefinition :
+ grammar<macroDefinition, result_closure<Macro>::context_t>
+{
+ template < typename ScannerT >
+ struct definition {
+ typedef rule<ScannerT> rule_t;
+ rule_t main;
+ rule_t macroName;
+ rule<ScannerT, result_closure<QString>::context_t> ellipsis, argument;
+
+ rule_t const& start() const {return main;}
+
+ definition( macroDefinition const& self) {
+ main =
+ *gr_whiteSpace
+ >> macroName
+ >> !(ch_p('(') >> *gr_whiteSpace
+ >> list_p( *gr_whiteSpace
+ >> argument[ push_back_c( self.result_, arg1)]
+ >> *gr_whiteSpace
+ ,
+ ','
+ )
+ >> ')');
+ macroName = identifier_pg[ self.result_ = construct_<Macro>( arg1)];
+ argument =
+ ellipsis [assign_a(argument.result_)]
+ | identifier_pg [assign_a(argument.result_)];
+ ellipsis =
+ str_p("...")[ellipsis.result_ = constructQString( arg1, arg2)];
+ }
+ };
+} macroDefinition_pg;
+
void PreprocessLexer::processDefine()
{
Macro m;
m.setFileName( m_driver->currentFileName() );
- m_source.parse( *gr_whiteSpace
- >>
- identifier_pg[boost::bind( &Macro::setName, (Macro*)&m, _1)]);
- m_source.parse( ch_p('(') >> *gr_whiteSpace
- >>
- list_p( *gr_whiteSpace
- >>
- (str_p("...")[ push_back_a( m, "...")]
- | identifier_pg[ push_back_a( m)]
- )
- >> *gr_whiteSpace
- ,
- ','
- )
- >> ')'
- );
+ m_source.parse( macroDefinition_pg[var(m) = arg1]);
m_preprocessorEnabled = true;
More information about the umbrello-devel
mailing list