[Uml-devel] KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser
Ralf Habacker
ralf.habacker at gmail.com
Sat Jul 7 15:43:18 UTC 2012
SVN commit 1304518 by habacker:
Refactored typedef Position, PositionFileName and CharIterator to full
classes for easier access to the file member.
M +1 -2 driver.cpp
M +0 -1 lexer.h
M +87 -12 position.h
M +0 -1 preprocesslexer.h
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/driver.cpp #1304517:1304518
@@ -234,8 +234,7 @@
lexer = &lex;
setupLexer( &lex );
- if (!lex.setSource( sourceProvider()->contents(fileName),
- QString2PositionFilename( fileName)))
+ if (!lex.setSource( sourceProvider()->contents(fileName), fileName))
return false;
if( !onlyPreProcess ){
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/lexer.h #1304517:1304518
@@ -49,7 +49,6 @@
using boost::spirit::classic::scanner;
using boost::spirit::classic::ext::skip_rule_parser;
-typedef boost::spirit::classic::position_iterator<QChar const*> CharIterator;
typedef rule<scanner<CharIterator> > SkipRule;
typedef skip_rule_parser<SkipRule, CharIterator> CharParser;
typedef scanner<CharIterator> CharScanner;
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/position.h #1304517:1304518
@@ -43,33 +43,108 @@
#include <QChar>
#include <QDebug>
-typedef boost::spirit::classic::file_position_base<std::basic_string<QChar> > Position;
-typedef std::basic_string<QChar> PositionFilename;
+typedef std::basic_string<QChar> PositionFilenameType;
-inline PositionFilename QString2PositionFilename( QString const& p)
+class PositionFilename : public PositionFilenameType
{
- return p.data();
+public:
+ PositionFilename()
+ {
}
+ PositionFilename(const QString &p) : PositionFilenameType(p.data())
+ {
+ }
+
+ QString toString() const
+ {
+ QString result;
+ for(unsigned int i = 0; i < size(); i++)
+ result.append(at(i));
+ return result;
+ }
+};
+
+inline QDebug operator<<(QDebug out, const PositionFilename &p)
+{
+ out << p.toString();
+ return out;
+}
+
+typedef boost::spirit::classic::file_position_base<PositionFilename> PositionType;
+
+class Position : public PositionType
+{
+public:
+ Position()
+ {
+ }
+
+ Position(const PositionFilename &p) : PositionType(p)
+ {
+ }
+
+ Position(const Position &p) : PositionType(p)
+ {
+ }
+
+ Position(const PositionType &p) : PositionType(p)
+ {
+ }
+
+ bool operator<(Position const& p) const
+ {
+ assert( file == p.file);
+ return( (line < p.line) || ( (line == p.line) && (column < p.column)));
+ }
+
+ bool operator>=(Position const& p) const
+ {
+ return !(*this < p);
+ }
+};
+
inline QDebug operator<<(QDebug out, Position const &p)
{
out << "Position("
- //<< "file" << p.file
- << "line:" << p.line
- << "column:" << p.column
+ << "file" << p.file
+ << "line" << p.line
+ << "column" << p.column
<< ")";
return out;
}
-inline bool operator<( Position const& p1, Position const& p2)
+typedef boost::spirit::classic::position_iterator<QChar const*, PositionType> CharIteratorType;
+
+class CharIterator : public CharIteratorType
{
- assert( p1.file == p2.file);
- return( (p1.line < p2.line) || ( (p1.line == p2.line) && (p1.column < p2.column)));
+public:
+ CharIterator()
+ {
}
-inline bool operator>=( Position const& p1, Position const& p2)
+ CharIterator(const QChar *a, const QChar *b, Position p) : CharIteratorType(a,b,p)
{
- return !(p1 < p2);
}
+ CharIterator(const PositionType &p) : CharIteratorType(0, 0, p)
+ {
+ }
+/*
+ CharIterator(PositionType p) : CharIteratorType(0, 0, p)
+ {
+ }
+*/
+ const Position &get_position() const
+ {
+ return static_cast<const Position&>(CharIteratorType::get_position());
+ }
+
+ void set_position(Position const& p)
+ {
+ CharIteratorType::set_position(p);
+ }
+};
+
+
#endif
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.h #1304517:1304518
@@ -43,7 +43,6 @@
using boost::spirit::classic::scanner;
using boost::spirit::classic::ext::skip_rule_parser;
-typedef boost::spirit::classic::position_iterator<QChar const*> CharIterator;
typedef rule<scanner<CharIterator> > SkipRule;
typedef skip_rule_parser<SkipRule, CharIterator> CharParser;
typedef scanner<CharIterator> CharScanner;
More information about the umbrello-devel
mailing list