minor optimization

This commit is contained in:
Roy Qu 2022-12-27 14:29:49 +08:00
parent 022f32a95f
commit a1af733a53
4 changed files with 77 additions and 116 deletions

View File

@ -821,10 +821,8 @@ void CppPreprocessor::removeCurrentBranch()
mBranchResults.pop_back();
}
QStringList CppPreprocessor::result() const
const QStringList& CppPreprocessor::result() const
{
return mResult;
}
PFileIncludes CppPreprocessor::getFileIncludesEntry(const QString &fileName)
{

View File

@ -77,7 +77,9 @@ public:
void clearProjectIncludePaths();
void removeScannedFile(const QString& filename);
QStringList result() const;
const QStringList& result() const{
return mResult;
};
QHash<QString, PFileIncludes> &includesList();

View File

@ -93,16 +93,6 @@ void CppTokenizer::dumpTokens(const QString &fileName)
}
}
const CppTokenizer::PToken &CppTokenizer::operator[](int i) const
{
return mTokenList[i];
}
int CppTokenizer::tokenCount() const
{
return mTokenList.count();
}
void CppTokenizer::addToken(const QString &sText, int iLine, TokenType tokenType)
{
PToken token = std::make_shared<Token>();
@ -799,26 +789,6 @@ void CppTokenizer::skipToNextToken()
mCurrent++;
}
bool CppTokenizer::isIdentChar(const QChar &ch)
{
return ch=='_' || ch.isLetter() ;
}
int CppTokenizer::lambdasCount() const
{
return mLambdas.count();
}
int CppTokenizer::indexOfFirstLambda() const
{
return mLambdas.front();
}
void CppTokenizer::removeFirstLambda()
{
mLambdas.pop_front();
}
void CppTokenizer::advance()
{
switch(mCurrent->unicode()) {
@ -844,71 +814,3 @@ void CppTokenizer::advance()
mCurrent++;
}
}
bool CppTokenizer::isLetterChar(const QChar &ch)
{
// return (ch>= 'A' && ch<='Z')
// || (ch>='a' && ch<='z')
return isIdentChar(ch)
|| ch == '_'
|| ch == '*'
|| ch == '&'
|| ch == '~';
}
bool CppTokenizer::isHexChar(const QChar &ch)
{
return (ch >= 'A' && ch<='F')
|| (ch>='a' && ch<='f')
|| ch == 'x'
|| ch == 'L';
}
bool CppTokenizer::isDigitChar(const QChar &ch)
{
return (ch>='0' && ch<='9');
}
bool CppTokenizer::isSpaceChar(const QChar &ch)
{
return (ch == ' ' || ch == '\t');
}
bool CppTokenizer::isLineChar(const QChar &ch)
{
return (ch=='\n' || ch=='\r');
}
bool CppTokenizer::isBlankChar(const QChar &ch)
{
return (ch<=32) && (ch>0);
}
bool CppTokenizer::isOperatorChar(const QChar &ch)
{
switch (ch.unicode()) {
case '+':
case '-':
case '/':
case '*':
case '[':
case ']':
case '=':
case '%':
case '!':
case '&':
case '|':
case '>':
case '<':
case '^':
return true;
default:
return false;
}
}
bool CppTokenizer::currentWordEquals(QChar *wordStart, QChar *wordEnd, const QString& text)
{
QString currentWord(wordStart, wordEnd-wordStart);
return currentWord == text;
}

View File

@ -47,12 +47,25 @@ public:
void clear();
void tokenize(const QStringList& buffer);
void dumpTokens(const QString& fileName);
const PToken& operator[](int i) const;
int tokenCount() const;
static bool isIdentChar(const QChar& ch);
int lambdasCount() const;
int indexOfFirstLambda() const;
void removeFirstLambda();
const PToken& operator[](int i) const {
return mTokenList[i];
}
int tokenCount() const {
return mTokenList.count();
}
static bool isIdentChar(const QChar& ch) {
return ch=='_' || ch.isLetter() ;
}
int lambdasCount() const {
return mLambdas.count();
}
int indexOfFirstLambda() const {
return mLambdas.front();
}
void removeFirstLambda() {
mLambdas.pop_front();
}
private:
void addToken(const QString& sText, int iLine, TokenType tokenType);
@ -86,15 +99,61 @@ private:
void skipToEOL();
void skipToNextToken();
bool openFile(const QString& fileName);
static bool isLetterChar(const QChar& ch);
static bool isHexChar(const QChar& ch);
static bool isDigitChar(const QChar& ch);
static bool isSpaceChar(const QChar& ch);
static bool isLineChar(const QChar& ch);
static bool isBlankChar(const QChar& ch);
static bool isOperatorChar(const QChar& ch);
static bool isLetterChar(const QChar& ch) {
return isIdentChar(ch)
|| ch == '_'
|| ch == '*'
|| ch == '&'
|| ch == '~';
}
static bool isHexChar(const QChar& ch) {
return (ch >= 'A' && ch<='F')
|| (ch>='a' && ch<='f')
|| ch == 'x'
|| ch == 'L';
}
static bool isDigitChar(const QChar& ch) {
return (ch>='0' && ch<='9');
}
static bool currentWordEquals(QChar* wordStart, QChar *wordEnd, const QString& text);
static bool isSpaceChar(const QChar& ch) {
return (ch == ' ' || ch == '\t');
}
static bool isLineChar(const QChar& ch) {
return (ch=='\n' || ch=='\r');
}
static bool isBlankChar(const QChar& ch) {
return (ch<=32) && (ch>0);
}
static bool isOperatorChar(const QChar& ch) {
switch (ch.unicode()) {
case '+':
case '-':
case '/':
case '*':
case '[':
case ']':
case '=':
case '%':
case '!':
case '&':
case '|':
case '>':
case '<':
case '^':
return true;
default:
return false;
}
}
static bool currentWordEquals(QChar* wordStart, QChar *wordEnd, const QString& text) {
QString currentWord(wordStart, wordEnd-wordStart);
return currentWord == text;
}
private:
QStringList mBuffer;