diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 7457d482..7dc7f4c7 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -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) { diff --git a/RedPandaIDE/parser/cpppreprocessor.h b/RedPandaIDE/parser/cpppreprocessor.h index c6c18062..48efb9a3 100644 --- a/RedPandaIDE/parser/cpppreprocessor.h +++ b/RedPandaIDE/parser/cpppreprocessor.h @@ -77,7 +77,9 @@ public: void clearProjectIncludePaths(); void removeScannedFile(const QString& filename); - QStringList result() const; + const QStringList& result() const{ + return mResult; + }; QHash &includesList(); diff --git a/RedPandaIDE/parser/cpptokenizer.cpp b/RedPandaIDE/parser/cpptokenizer.cpp index 33fc1ae4..0c0ab5e7 100644 --- a/RedPandaIDE/parser/cpptokenizer.cpp +++ b/RedPandaIDE/parser/cpptokenizer.cpp @@ -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(); @@ -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; -} diff --git a/RedPandaIDE/parser/cpptokenizer.h b/RedPandaIDE/parser/cpptokenizer.h index 4af7f9f0..0188e5f1 100644 --- a/RedPandaIDE/parser/cpptokenizer.h +++ b/RedPandaIDE/parser/cpptokenizer.h @@ -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;