equal
deleted
inserted
replaced
45 #include <qdebug.h> |
45 #include <qdebug.h> |
46 #include <qfile.h> |
46 #include <qfile.h> |
47 #include <qhash.h> |
47 #include <qhash.h> |
48 #include <qregexp.h> |
48 #include <qregexp.h> |
49 #include <qstring.h> |
49 #include <qstring.h> |
|
50 #include <qtextcodec.h> |
50 |
51 |
51 #include <ctype.h> |
52 #include <ctype.h> |
52 #include <string.h> |
53 #include <string.h> |
53 |
54 |
54 QT_BEGIN_NAMESPACE |
55 QT_BEGIN_NAMESPACE |
95 static QRegExp *definedX = 0; |
96 static QRegExp *definedX = 0; |
96 |
97 |
97 static QRegExp *defines = 0; |
98 static QRegExp *defines = 0; |
98 static QRegExp *falsehoods = 0; |
99 static QRegExp *falsehoods = 0; |
99 |
100 |
|
101 static QTextCodec *sourceCodec = 0; |
|
102 |
100 /* |
103 /* |
101 This function is a perfect hash function for the 37 keywords of C99 |
104 This function is a perfect hash function for the 37 keywords of C99 |
102 (with a hash table size of 512). It should perform well on our |
105 (with a hash table size of 512). It should perform well on our |
103 Qt-enhanced C++ subset. |
106 Qt-enhanced C++ subset. |
104 */ |
107 */ |
116 k = 0; |
119 k = 0; |
117 } |
120 } |
118 kwordHashTable[k] = number; |
121 kwordHashTable[k] = number; |
119 } |
122 } |
120 |
123 |
121 Tokenizer::Tokenizer(const Location& loc, FILE *in) |
124 Tokenizer::Tokenizer(const Location& loc, QFile &in) |
122 { |
125 { |
123 init(); |
126 init(); |
124 QFile file; |
127 yyIn = in.readAll(); |
125 file.open(in, QIODevice::ReadOnly); |
|
126 yyIn = file.readAll(); |
|
127 file.close(); |
|
128 yyPos = 0; |
128 yyPos = 0; |
129 start(loc); |
129 start(loc); |
130 } |
130 } |
131 |
131 |
132 Tokenizer::Tokenizer(const Location& loc, const QByteArray &in) |
132 Tokenizer::Tokenizer(const Location& loc, const QByteArray &in) |
480 } |
480 } |
481 |
481 |
482 void Tokenizer::initialize(const Config &config) |
482 void Tokenizer::initialize(const Config &config) |
483 { |
483 { |
484 QString versionSym = config.getString(CONFIG_VERSIONSYM); |
484 QString versionSym = config.getString(CONFIG_VERSIONSYM); |
|
485 |
|
486 QString sourceEncoding = config.getString(CONFIG_SOURCEENCODING); |
|
487 if (sourceEncoding.isEmpty()) |
|
488 sourceEncoding = QLatin1String("ISO-8859-1"); |
|
489 sourceCodec = QTextCodec::codecForName(sourceEncoding.toLocal8Bit()); |
485 |
490 |
486 comment = new QRegExp("/(?:\\*.*\\*/|/.*\n|/[^\n]*$)"); |
491 comment = new QRegExp("/(?:\\*.*\\*/|/.*\n|/[^\n]*$)"); |
487 comment->setMinimal(true); |
492 comment->setMinimal(true); |
488 versionX = new QRegExp("$cannot possibly match^"); |
493 versionX = new QRegExp("$cannot possibly match^"); |
489 if (!versionSym.isEmpty()) |
494 if (!versionSym.isEmpty()) |
748 return defines->exactMatch(definedX->cap(1)); |
753 return defines->exactMatch(definedX->cap(1)); |
749 else |
754 else |
750 return !falsehoods->exactMatch(t); |
755 return !falsehoods->exactMatch(t); |
751 } |
756 } |
752 |
757 |
|
758 QString Tokenizer::lexeme() const |
|
759 { |
|
760 return sourceCodec->toUnicode(yyLex); |
|
761 } |
|
762 |
|
763 QString Tokenizer::previousLexeme() const |
|
764 { |
|
765 return sourceCodec->toUnicode(yyPrevLex); |
|
766 } |
|
767 |
753 QT_END_NAMESPACE |
768 QT_END_NAMESPACE |