261105.1 · e4063257f8a3da0ff5ca8ce18e4c933918ab611c
updated astyle to version 3.6.22
reading declarations
@@ -9,9 +9,9 @@ == highlight 4.22 -02.11.2026+05.11.2026 - - updated astyle lib to version 3.6.21+ - updated astyle lib to version 3.6.22 - added support for UTF-16 and UTF-32 input files with byte order mark (https://gitlab.com/saalen/highlight/-/work_items/266) - added m4 language definition - added rainbow_brackets.lua plug-in (colours brackets by nesting depth)
src/core/astyle/ASBeautifier.cpp
@@ -236,6 +236,7 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other) prevLineBeginsWithComma = other.prevLineBeginsWithComma; lineIsCommentOnly = other.lineIsCommentOnly; lineIsLineCommentOnly = other.lineIsLineCommentOnly;+ lineEndsInLineComment = other.lineEndsInLineComment; shouldIndentBracedLine = other.shouldIndentBracedLine; isInSwitch = other.isInSwitch; foundPreCommandHeader = other.foundPreCommandHeader;@@ -433,6 +434,7 @@ void ASBeautifier::init(ASSourceIterator* iter) prevLineBeginsWithComma = false; lineIsCommentOnly = false; lineIsLineCommentOnly = false;+ lineEndsInLineComment = false; shouldIndentBracedLine = true; isInSwitch = false; foundPreCommandHeader = false;@@ -666,7 +668,15 @@ std::string ASBeautifier::beautify(const std::string& originalLine) return preLineWS(preprocBlockIndent, 0) + line; } - if (!isInComment+ // bug #611: after an #else the lines are parsed by an active worker beautifier,+ // a comment opened there is not known to this instance+ bool isInActiveComment = isInComment+ || (!isInDefine+ && activeBeautifierStack != nullptr+ && !activeBeautifierStack->empty()+ && activeBeautifierStack->back()->isInComment);++ if (!isInActiveComment && !isInQuoteContinuation && !line.empty() && ((line[0] == '#' && !isIndentedPreprocessor(line, 0))@@ -881,11 +891,13 @@ std::string ASBeautifier::beautify(const std::string& originalLine) // a string literal ending the line may be continued by a literal on the next line (bug #172): // align it with the first literal of a statement's first line or with a continued literal,- // any other continuation line keeps the regular continuation indent (bug #587)+ // any other continuation line keeps the regular continuation indent (bug #587),+ // a quote ending a line comment is no string literal (bug #613) quoteContinuationIndent = 0; if (isCStyle() && !isInDefine && !isInComment+ && !lineEndsInLineComment && !isInQuote && !isInMultiLineString && parenDepth == 0@@ -1803,6 +1815,7 @@ bool ASBeautifier::statementEndsWithComma(std::string_view line, int index) cons size_t lineLength = line.length(); size_t i = 0; char quoteChar_ = ' ';+ char lastCodeCh = ' '; // last char outside of comments (SF #612) for (i = index + 1; i < lineLength; ++i) {@@ -1820,12 +1833,14 @@ bool ASBeautifier::statementEndsWithComma(std::string_view line, int index) cons if (ch == '\\') {+ lastCodeCh = ch; ++i; continue; } if (isInQuote_) {+ lastCodeCh = quoteChar_; if (ch == quoteChar_) isInQuote_ = false; continue;@@ -1834,6 +1849,7 @@ bool ASBeautifier::statementEndsWithComma(std::string_view line, int index) cons if (ch == '"' || (ch == '\'' && !isDigitSeparator(line, i))) {+ lastCodeCh = ch; isInQuote_ = true; quoteChar_ = ch; continue;@@ -1852,6 +1868,9 @@ bool ASBeautifier::statementEndsWithComma(std::string_view line, int index) cons continue; } + if (!std::isblank(static_cast<unsigned char>(ch)))+ lastCodeCh = ch;+ if (ch == '(') parenCount++; if (ch == ')')@@ -1862,12 +1881,7 @@ bool ASBeautifier::statementEndsWithComma(std::string_view line, int index) cons || parenCount > 0) return false; - size_t lastChar = line.find_last_not_of(" \t", i - 1);-- if (lastChar == std::string::npos || line[lastChar] != ',')- return false;-- return true;+ return lastCodeCh == ','; } /**@@ -1896,6 +1910,66 @@ bool ASBeautifier::isDesignatedInitializer(std::string_view line, size_t index) return nextChar == index; } +/**+ * Determine if the line text before the assignment operator at index+ * is only an assignment target like 'a.b()->c[i]' (SF #612).+ * Parenthesized and bracketed contents are bypassed.+ *+ * @return true if no other operator precedes the assignment, otherwise false.+ */+bool ASBeautifier::isAssignmentTargetOnly(std::string_view line, size_t index) const+{+ int depth = 0;+ char quoteChar_ = ' ';+ bool haveTarget = false;++ for (size_t i = 0; i < index; ++i)+ {+ char ch = line[i];++ if (quoteChar_ != ' ')+ {+ if (ch == '\\')+ ++i;+ else if (ch == quoteChar_)+ quoteChar_ = ' ';+ continue;+ }+ if (ch == '"' || (ch == '\'' && !isDigitSeparator(line, i)))+ {+ quoteChar_ = ch;+ continue;+ }+ if (ch == '(' || ch == '[')+ {+ ++depth;+ continue;+ }+ if (ch == ')' || ch == ']')+ {+ if (--depth < 0)+ return false;+ continue;+ }+ if (depth > 0 || std::isblank(static_cast<unsigned char>(ch)))+ continue;+ if (isLegalNameChar(ch))+ {+ haveTarget = true;+ continue;+ }+ if (i + 1 < index+ && ((ch == '-' && line[i + 1] == '>')+ || (ch == ':' && line[i + 1] == ':')))+ {+ ++i;+ continue;+ }+ return false;+ }+ return haveTarget && depth == 0 && quoteChar_ == ' ';+}+ /** * check if current comment is a line-end comment *@@ -1906,7 +1980,7 @@ bool ASBeautifier::isLineEndComment(std::string_view line, int startPos) const assert(line.compare(startPos, ASResource::AS_OPEN_COMMENT.length(), ASResource::AS_OPEN_COMMENT) == 0 || line.compare(startPos, ASResource::AS_GSC_OPEN_COMMENT.length(), ASResource::AS_GSC_OPEN_COMMENT) == 0 ); - bool isCppComment = line.compare(startPos, ASResource::AS_OPEN_COMMENT.length(), ASResource::AS_OPEN_COMMENT);+ bool isCppComment = line.compare(startPos, ASResource::AS_OPEN_COMMENT.length(), ASResource::AS_OPEN_COMMENT) == 0; // comment must be closed on this line with nothing after it size_t endNum = line.find(isCppComment ? ASResource::AS_CLOSE_COMMENT : ASResource::AS_GSC_CLOSE_COMMENT, startPos + 2);@@ -4085,7 +4159,7 @@ void ASBeautifier::handlePotentialHeaderSection(std::string_view line, size_t* i } -void ASBeautifier::handlePotentialOperatorSection(std::string_view line, size_t* i, bool tabIncrementIn, bool* haveAssignmentThisLine, bool isInOperator)+void ASBeautifier::handlePotentialOperatorSection(std::string_view line, size_t* i, bool tabIncrementIn, bool* haveAssignmentThisLine, bool isInOperator, bool prevLineEndsWithAssign) { // Check if an operator has been reached. const std::string* foundAssignmentOp = findOperator(line, *i, assignmentOperators.get());@@ -4184,9 +4258,10 @@ void ASBeautifier::handlePotentialOperatorSection(std::string_view line, size_t* && prevNonSpaceCh != ']' // an array && statementEndsWithComma(line, *i)) {- // only one assignment indent per line + GH #10+ // only one assignment indent per line + GH #10 (a scoped name before the assignment) // a designated initializer ending with a comma needs no indent- if (!*haveAssignmentThisLine && !isDesignatedInit && line.find(ASResource::AS_SCOPE_RESOLUTION) == std::string::npos)+ if (!*haveAssignmentThisLine && !isDesignatedInit+ && line.substr(0, *i).find(ASResource::AS_SCOPE_RESOLUTION) == std::string::npos) { // register indent at previous word *haveAssignmentThisLine = true;@@ -4206,8 +4281,11 @@ void ASBeautifier::handlePotentialOperatorSection(std::string_view line, size_t* if (*i == 0 && spaceIndentCount == 0) spaceIndentCount += indentLength; - // #SF 97- if (prevNonLegalCh == '=' && currentNonLegalCh == '=')+ // #SF 97, SF #612: chained assignments continuing a line ending with '='+ // are aligned with the first line, also for targets like 'a.b() ='+ if ((prevNonLegalCh == '=' && currentNonLegalCh == '=')+ || (prevLineEndsWithAssign+ && isAssignmentTargetOnly(line, *i + 1 - foundAssignmentOp->length()))) spaceIndentCount = 0; registerContinuationIndent(line, *i, spaceIndentCount, tabIncrementIn, 0, false);@@ -4233,6 +4311,8 @@ void ASBeautifier::parseCurrentLine(std::string_view line) bool haveAssignmentThisLine = false; bool closingBraceReached = false; bool previousLineProbation = (probationHeader != nullptr);+ // SF #612: the previous line ended with an assignment operator+ const bool prevLineEndsWithAssign = currentNonSpaceCh == '='; char ch = ' '; int tabIncrementIn = 0; @@ -4754,9 +4834,11 @@ void ASBeautifier::parseCurrentLine(std::string_view line) if (isPotentialOperator) {- handlePotentialOperatorSection(line, &i, tabIncrementIn, &haveAssignmentThisLine, isInOperator);+ handlePotentialOperatorSection(line, &i, tabIncrementIn, &haveAssignmentThisLine, isInOperator, prevLineEndsWithAssign); } } // end of for loop * end of for loop * end of for loop * end of for loop * end of for loop *++ lineEndsInLineComment = isInLineComment; }
@@ -29,7 +29,7 @@ #include <cstring> // need both string and cstring for GCC #endif -#define ASTYLE_VERSION "3.6.21"+#define ASTYLE_VERSION "3.6.22" namespace astyle {@@ -507,6 +507,7 @@ private: // functions [[nodiscard]] bool isUsingBeforeFirstCase(std::string_view line) const; [[nodiscard]] bool statementEndsWithComma(std::string_view line, int index) const; [[nodiscard]] bool isDesignatedInitializer(std::string_view line, size_t index) const;+ [[nodiscard]] bool isAssignmentTargetOnly(std::string_view line, size_t index) const; [[nodiscard]] std::string getIndentedSpaceEquivalent(std::string_view line_) const; void popLambda();@@ -521,7 +522,7 @@ private: // functions void handleParens(std::string_view line, size_t i, bool tabIncrementIn, bool* isInOperator, char ch); void handleClosingParen(std::string_view line, size_t i, bool tabIncrementIn); void handlePotentialHeaderSection(std::string_view line, size_t* i, bool tabIncrementIn, bool* isInOperator);- void handlePotentialOperatorSection(std::string_view line, size_t* i, bool tabIncrementIn, bool* haveAssignmentThisLine, bool isInOperator);+ void handlePotentialOperatorSection(std::string_view line, size_t* i, bool tabIncrementIn, bool* haveAssignmentThisLine, bool isInOperator, bool prevLineEndsWithAssign); private: // variables int beautifierFileType;@@ -644,6 +645,7 @@ private: // variables bool prevLineBeginsWithComma; bool lineIsCommentOnly; bool lineIsLineCommentOnly;+ bool lineEndsInLineComment; // set by parseCurrentLine() (bug #613) bool shouldIndentBracedLine; bool isInSwitch; bool foundPreCommandHeader;