From ffafcd44162fe8c7b2404ba11387e6dc7a122585 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 10 Apr 2024 21:10:26 +0800 Subject: [PATCH] code clean --- libs/qsynedit/qsynedit/miscprocs.cpp | 6 - libs/qsynedit/qsynedit/miscprocs.h | 1 - libs/qsynedit/qsynedit/syntaxer/cpp.cpp | 102 +-------------- libs/qsynedit/qsynedit/syntaxer/cpp.h | 41 +++--- libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp | 129 +------------------ libs/qsynedit/qsynedit/syntaxer/syntaxer.h | 42 +++--- libs/qsynedit/qsynedit/syntaxer/textfile.cpp | 8 -- libs/qsynedit/qsynedit/syntaxer/textfile.h | 1 - 8 files changed, 51 insertions(+), 279 deletions(-) diff --git a/libs/qsynedit/qsynedit/miscprocs.cpp b/libs/qsynedit/qsynedit/miscprocs.cpp index 6a49f0d2..59613934 100644 --- a/libs/qsynedit/qsynedit/miscprocs.cpp +++ b/libs/qsynedit/qsynedit/miscprocs.cpp @@ -81,12 +81,6 @@ bool enumTokenAttributes(PSyntaxer syntaxer, bool skipDuplicates, tokenAttriProc, params, syntaxerList); } -int mulDiv(int a, int b, int c) -{ - //todo: handle overflow? - return a*b/c; -} - FontStyles getFontStyles(const QFont &font) { FontStyles styles; diff --git a/libs/qsynedit/qsynedit/miscprocs.h b/libs/qsynedit/qsynedit/miscprocs.h index 98071b73..a86d1c56 100644 --- a/libs/qsynedit/qsynedit/miscprocs.h +++ b/libs/qsynedit/qsynedit/miscprocs.h @@ -37,7 +37,6 @@ class QColor; namespace QSynedit { int minMax(int x, int mi, int ma); -int mulDiv(int a, int b, int c); BufferCoord maxBufferCoord(const BufferCoord& P1, const BufferCoord& P2); BufferCoord minBufferCoord(const BufferCoord& P1, const BufferCoord& P2); diff --git a/libs/qsynedit/qsynedit/syntaxer/cpp.cpp b/libs/qsynedit/qsynedit/syntaxer/cpp.cpp index 13e04e03..bfc12999 100644 --- a/libs/qsynedit/qsynedit/syntaxer/cpp.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/cpp.cpp @@ -220,110 +220,10 @@ CppSyntaxer::CppSyntaxer(): Syntaxer() resetState(); } -const PTokenAttribute &CppSyntaxer::preprocessorAttribute() const -{ - return mPreprocessorAttribute; -} - -const PTokenAttribute &CppSyntaxer::invalidAttribute() const -{ - return mInvalidAttribute; -} - -const PTokenAttribute &CppSyntaxer::numberAttribute() const -{ - return mNumberAttribute; -} - -const PTokenAttribute &CppSyntaxer::floatAttribute() const -{ - return mFloatAttribute; -} - -const PTokenAttribute &CppSyntaxer::hexAttribute() const -{ - return mHexAttribute; -} - -const PTokenAttribute &CppSyntaxer::octAttribute() const -{ - return mOctAttribute; -} - -const PTokenAttribute &CppSyntaxer::stringEscapeSequenceAttribute() const -{ - return mStringEscapeSequenceAttribute; -} - -const PTokenAttribute &CppSyntaxer::charAttribute() const -{ - return mCharAttribute; -} - -const PTokenAttribute &CppSyntaxer::variableAttribute() const -{ - return mVariableAttribute; -} - -const PTokenAttribute &CppSyntaxer::functionAttribute() const -{ - return mFunctionAttribute; -} - -const PTokenAttribute &CppSyntaxer::classAttribute() const -{ - return mClassAttribute; -} - -const PTokenAttribute &CppSyntaxer::globalVarAttribute() const -{ - return mGlobalVarAttribute; -} - -const PTokenAttribute &CppSyntaxer::localVarAttribute() const -{ - return mLocalVarAttribute; -} - -bool CppSyntaxer::isStringToNextLine(int state) -{ - return state == RangeState::rsStringNextLine; -} - -bool CppSyntaxer::isRawStringStart(int state) -{ - return state == RangeState::rsRawString; -} - -bool CppSyntaxer::isRawStringNoEscape(int state) -{ - return state == RangeState::rsRawStringNotEscaping; -} - -bool CppSyntaxer::isRawStringEnd(int state) -{ - return state == RangeState::rsRawStringEnd; -} - -bool CppSyntaxer::isCharNotFinished(int state) -{ - return state == RangeState::rsChar || state == RangeState::rsCharEscaping; -} - -bool CppSyntaxer::isCharEscaping(int state) -{ - return state == RangeState::rsCharEscaping; -} - bool CppSyntaxer::isInAttribute(const SyntaxState &state) { return state.extraData.contains(DATA_KEY_IN_ATTRIBUTE) - && state.extraData[DATA_KEY_IN_ATTRIBUTE].toBool(); -} - -CppSyntaxer::TokenId CppSyntaxer::getTokenId() -{ - return mTokenId; + && state.extraData[DATA_KEY_IN_ATTRIBUTE].toBool(); } void CppSyntaxer::procAndSymbol() diff --git a/libs/qsynedit/qsynedit/syntaxer/cpp.h b/libs/qsynedit/qsynedit/syntaxer/cpp.h index 2235fafa..d84e55f7 100644 --- a/libs/qsynedit/qsynedit/syntaxer/cpp.h +++ b/libs/qsynedit/qsynedit/syntaxer/cpp.h @@ -60,31 +60,31 @@ public: CppSyntaxer(const CppSyntaxer&)=delete; CppSyntaxer operator=(const CppSyntaxer&)=delete; - const PTokenAttribute &preprocessorAttribute() const; + const PTokenAttribute &preprocessorAttribute() const { return mPreprocessorAttribute; } - const PTokenAttribute &invalidAttribute() const; + const PTokenAttribute &invalidAttribute() const { return mInvalidAttribute; } - const PTokenAttribute &numberAttribute() const; + const PTokenAttribute &numberAttribute() const { return mNumberAttribute; } - const PTokenAttribute &floatAttribute() const; + const PTokenAttribute &floatAttribute() const { return mFloatAttribute; } - const PTokenAttribute &hexAttribute() const; + const PTokenAttribute &hexAttribute() const { return mHexAttribute; } - const PTokenAttribute &octAttribute() const; + const PTokenAttribute &octAttribute() const { return mOctAttribute; } - const PTokenAttribute &stringEscapeSequenceAttribute() const; + const PTokenAttribute &stringEscapeSequenceAttribute() const { return mStringEscapeSequenceAttribute; } - const PTokenAttribute &charAttribute() const; + const PTokenAttribute &charAttribute() const { return mCharAttribute; } - const PTokenAttribute &variableAttribute() const; + const PTokenAttribute &variableAttribute() const { return mVariableAttribute; } - const PTokenAttribute &functionAttribute() const; + const PTokenAttribute &functionAttribute() const { return mFunctionAttribute; } - const PTokenAttribute &classAttribute() const; + const PTokenAttribute &classAttribute() const { return mClassAttribute; } - const PTokenAttribute &globalVarAttribute() const; + const PTokenAttribute &globalVarAttribute() const { return mGlobalVarAttribute; } - const PTokenAttribute &localVarAttribute() const; + const PTokenAttribute &localVarAttribute() const { return mLocalVarAttribute; } static const QSet Keywords; @@ -92,15 +92,15 @@ public: static const QSet StandardAttributes; - bool isStringToNextLine(int state); - bool isRawStringStart(int state); - bool isRawStringNoEscape(int state); - bool isRawStringEnd(int state); - bool isCharNotFinished(int state); - bool isCharEscaping(int state); + bool isStringToNextLine(int state) { return state == RangeState::rsStringNextLine; } + bool isRawStringStart(int state) { return state == RangeState::rsRawString; } + bool isRawStringNoEscape(int state) { return state == RangeState::rsRawStringNotEscaping; } + bool isRawStringEnd(int state) { return state == RangeState::rsRawStringEnd; } + bool isCharNotFinished(int state) { return state == RangeState::rsChar || state == RangeState::rsCharEscaping; } + bool isCharEscaping(int state) { return state == RangeState::rsCharEscaping; } bool isInAttribute(const SyntaxState &state); - TokenId getTokenId(); + TokenId getTokenId() { return mTokenId; } private: void procAndSymbol(); void procCppStyleComment(); @@ -159,7 +159,6 @@ private: private: SyntaxState mRange; -// SynRangeState mSpaceRange; QString mLine; int mLineSize; int mRun; diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp index cb516e2a..58a6e877 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp @@ -41,46 +41,6 @@ Syntaxer::Syntaxer() : addAttribute(mSymbolAttribute); } -QMap Syntaxer::attributes() const -{ - return mAttributes; -} - -const QSet& Syntaxer::wordBreakChars() const -{ - return mWordBreakChars; -} - -const PTokenAttribute& Syntaxer::identifierAttribute() const -{ - return mIdentifierAttribute; -} - -const PTokenAttribute &Syntaxer::keywordAttribute() const -{ - return mKeywordAttribute; -} - -const PTokenAttribute &Syntaxer::commentAttribute() const -{ - return mCommentAttribute; -} - -const PTokenAttribute& Syntaxer::stringAttribute() const -{ - return mStringAttribute; -} - -const PTokenAttribute& Syntaxer::whitespaceAttribute() const -{ - return mWhitespaceAttribute; -} - -const PTokenAttribute& Syntaxer::symbolAttribute() const -{ - return mSymbolAttribute; -} - bool Syntaxer::isKeyword(const QString &) { return false; @@ -153,48 +113,17 @@ bool Syntaxer::isWordBreakChar(const QChar &ch) bool Syntaxer::isIdentChar(const QChar &ch) const { - if (ch == '_') { - return true; - } - if ((ch>='0') && (ch <= '9')) { - return true; - } - if ((ch>='a') && (ch <= 'z')) { - return true; - } - if ((ch>='A') && (ch <= 'Z')) { - return true; - } - return false; + return (ch == '_') + || ((ch>='0') && (ch <= '9')) + || ((ch>='a') && (ch <= 'z')) + || ((ch>='A') && (ch <= 'Z')); } bool Syntaxer::isIdentStartChar(const QChar &ch) const { - if (ch == '_') { - return true; - } - if ((ch>='a') && (ch <= 'z')) { - return true; - } - if ((ch>='A') && (ch <= 'Z')) { - return true; - } - return false; -} - -void Syntaxer::addAttribute(PTokenAttribute attribute) -{ - mAttributes[attribute->name()]=attribute; -} - -void Syntaxer::clearAttributes() -{ - mAttributes.clear(); -} - -int Syntaxer::attributesCount() const -{ - return mAttributes.size(); + return (ch == '_') + || ((ch>='a') && (ch <= 'z')) + || ((ch>='A') && (ch <= 'Z')); } PTokenAttribute Syntaxer::getAttribute(const QString& name) const @@ -217,48 +146,6 @@ QString Syntaxer::blockCommentEndSymbol() return QString(); } -FontStyles TokenAttribute::styles() const -{ - return mStyles; -} - -void TokenAttribute::setStyles(const FontStyles &styles) -{ - if (mStyles!=styles) { - mStyles = styles; - } -} - -const QColor& TokenAttribute::foreground() const -{ - return mForeground; -} - -void TokenAttribute::setForeground(const QColor &color) -{ - mForeground = color; -} - -const QColor &TokenAttribute::background() const -{ - return mBackground; -} - -void TokenAttribute::setBackground(const QColor &background) -{ - mBackground = background; -} - -TokenType TokenAttribute::tokenType() const -{ - return mTokenType; -} - -QString TokenAttribute::name() const -{ - return mName; -} - TokenAttribute::TokenAttribute(const QString &name, TokenType tokenType): mForeground(QColor()), mBackground(QColor()), @@ -280,11 +167,9 @@ bool SyntaxState::operator==(const SyntaxState &s2) && (braceLevel == s2.braceLevel) // current braces embedding level (needed by rainbow color) && (bracketLevel == s2.bracketLevel) // current brackets embedding level (needed by rainbow color) && (parenthesisLevel == s2.parenthesisLevel) // current parenthesis embedding level (needed by rainbow color) - && (indents == s2.indents) && (lastUnindent == s2.lastUnindent) ; - } IndentInfo SyntaxState::getLastIndent() diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h index 3ce0ed7f..70b25caa 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h @@ -93,18 +93,22 @@ public: TokenAttribute(const TokenAttribute&)=delete; TokenAttribute& operator=(const TokenAttribute&)=delete; - QString name() const; + QString name() const { return mName; } - FontStyles styles() const; - void setStyles(const FontStyles &styles); + FontStyles styles() const { return mStyles; } + void setStyles(const FontStyles &styles) { + if (mStyles!=styles) { + mStyles = styles; + } + } - const QColor &foreground() const; - void setForeground(const QColor &color); + const QColor &foreground() const { return mForeground; } + void setForeground(const QColor &color) { mForeground = color; } - const QColor &background() const; - void setBackground(const QColor &background); + const QColor &background() const { return mBackground; } + void setBackground(const QColor &background) { mBackground = background; } - TokenType tokenType() const; + TokenType tokenType() const { return mTokenType; } private: QColor mForeground; @@ -122,21 +126,21 @@ public: Syntaxer(const Syntaxer&)=delete; Syntaxer& operator=(const Syntaxer&)=delete; - virtual QMap attributes() const; + QMap attributes() const { return mAttributes; } - const QSet& wordBreakChars() const; + const QSet& wordBreakChars() const { return mWordBreakChars; } - const PTokenAttribute& identifierAttribute() const; + const PTokenAttribute& identifierAttribute() const { return mIdentifierAttribute; } - const PTokenAttribute& keywordAttribute() const; + const PTokenAttribute& keywordAttribute() const { return mKeywordAttribute; } - const PTokenAttribute& commentAttribute() const; + const PTokenAttribute& commentAttribute() const { return mCommentAttribute; } - const PTokenAttribute& stringAttribute() const; + const PTokenAttribute& stringAttribute() const { return mStringAttribute; } - const PTokenAttribute& whitespaceAttribute() const; + const PTokenAttribute& whitespaceAttribute() const { return mWhitespaceAttribute; } - const PTokenAttribute& symbolAttribute() const; + const PTokenAttribute& symbolAttribute() const { return mSymbolAttribute; } virtual bool isIdentChar(const QChar& ch) const; virtual bool isIdentStartChar(const QChar& ch) const; @@ -183,9 +187,9 @@ protected: PTokenAttribute mWhitespaceAttribute; PTokenAttribute mSymbolAttribute; - void addAttribute(PTokenAttribute attribute); - void clearAttributes(); - virtual int attributesCount() const; + void addAttribute(PTokenAttribute attribute) { mAttributes[attribute->name()]=attribute; } + void clearAttributes() { mAttributes.clear(); } + virtual int attributesCount() const { return mAttributes.size(); } private: QMap mAttributes; diff --git a/libs/qsynedit/qsynedit/syntaxer/textfile.cpp b/libs/qsynedit/qsynedit/syntaxer/textfile.cpp index c082feba..0d3ed5db 100644 --- a/libs/qsynedit/qsynedit/syntaxer/textfile.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/textfile.cpp @@ -48,14 +48,6 @@ void TextSyntaxer::procNull() mState = RangeState::Unknown; } -QMap TextSyntaxer::attributes() const -{ - QMap result; - result.insert(SYNS_AttrText, mTextAttribute); - result.insert(SYNS_AttrSpace, whitespaceAttribute()); - return result; -} - bool TextSyntaxer::eol() const { return mTokenID == TokenId::Null; diff --git a/libs/qsynedit/qsynedit/syntaxer/textfile.h b/libs/qsynedit/qsynedit/syntaxer/textfile.h index 9c03f83a..8328522f 100644 --- a/libs/qsynedit/qsynedit/syntaxer/textfile.h +++ b/libs/qsynedit/qsynedit/syntaxer/textfile.h @@ -61,7 +61,6 @@ private: void procNull(); public: - QMap attributes() const override; bool eol() const override; QString languageName() override;