Perfect the patch for astyle

This commit is contained in:
Roy Qu 2024-03-27 19:24:34 +08:00
parent 0cc4f09c53
commit bd52bd9831
4 changed files with 79 additions and 67 deletions

View File

@ -99,6 +99,7 @@ Red Panda C++ Version 2.27
- enhancement: Open ".def" (Module definition file) file in editor when double click it in the project view.
- enhancement: When a dll project has .def file, use it when generating the dll file.
- fix: "project name".exe.manifest is auto removed when build the project.
- fix: "0x3.12p+1" is treadted as a plus expression when reformatting code ( by 绣球135@qq
Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.

View File

@ -3590,77 +3590,72 @@ bool ASFormatter::isInSwitchStatement() const
*
* @return whether the current '+' or '-' is in an exponent.
*/
bool ASFormatter::isInExponent() const {
assert (currentChar == '+' || currentChar == '-');
bool ASFormatter::isInExponent() const
{
assert (currentChar == '+' || currentChar == '-');
if (charNum >= 2) {
char prevPrevFormattedChar = currentLine[charNum - 2];
char prevFormattedChar = currentLine[charNum - 1];
//XQ135 modify// return ((prevFormattedChar == 'e' || prevFormattedChar == 'E')
//XQ135 modify// && (prevPrevFormattedChar == '.' || isDigit(prevPrevFormattedChar)));
char qian1 = prevFormattedChar; //XQ135 modify// Start
char qian2 = prevPrevFormattedChar; //XQ135 modify//
if (charNum < 2)
return false;
bool isexp = false;
int i = 2;
if (qian1 == 'e' || qian1 == 'E') {
while ((charNum - i) >= 0) {
qian2 = currentLine[charNum - i];
if (qian2 == '.' || isDigit (qian2)) {
isexp = true;
} else {
if (! (qian2 == ' ' || qian2 == '&' || qian2 == '|' || qian2 == '='
|| qian2 == 7 || qian2 == 10 || qian2 == 13 || qian2 == '~'
|| qian2 == '+' || qian2 == '-' || qian2 == '*' || qian2 == '/'
|| qian2 == '(' || qian2 == ')' || qian2 == '[' || qian2 == ']'
|| qian2 == '{' || qian2 == '}' || qian2 == ',' || qian2 == ':'
|| qian2 == ';' || qian2 == '.' || qian2 == '#' || qian2 == '<'
|| qian2 == '>' || qian2 == '^' || qian2 == '%' || qian2 == '!' )) {
isexp = false;
}
break;
}
i++;
}
}
if (isexp) {return true;}
int i = charNum - 1;
char prevChar = currentLine[i];
if (! (qian1 == 'p' || qian1 == 'P')) {return false;}
i = 2;
while ((charNum - i) >= 0) {
qian2 = currentLine[charNum - i];
if (qian2 == '.' || isDigit (qian2) || qian2 == 'x' || qian2 == 'X'
|| (qian2 >= 'a' && qian2 <= 'f') || (qian2 >= 'A' && qian2 <= 'F')) {
if (qian2 == 'x' || qian2 == 'X') {
if ((charNum - i - 1) >= 0) {
if (currentLine[charNum - i - 1] == '0') {
if ((charNum - i - 2) >= 0) {
qian2 = currentLine[charNum - i - 2];
if (qian2 == ' ' || qian2 == '&' || qian2 == '|' || qian2 == '='
|| qian2 == 7 || qian2 == 10 || qian2 == 13 || qian2 == '~'
|| qian2 == '+' || qian2 == '-' || qian2 == '*' || qian2 == '/'
|| qian2 == '(' || qian2 == ')' || qian2 == '[' || qian2 == ']'
|| qian2 == '{' || qian2 == '}' || qian2 == ',' || qian2 == ':'
|| qian2 == ';' || qian2 == '.' || qian2 == '#' || qian2 == '<'
|| qian2 == '>' || qian2 == '^' || qian2 == '%' || qian2 == '!') {
return true;
} else {
return false;
}
}
return true;
if (prevChar == 'e' || prevChar == 'E') {
i--;
bool hasPoint = false;
int numCount = 0;
while (i >= 0) {
prevChar = currentLine[i];
if (prevChar == '.') {
if (hasPoint)
return false;
hasPoint = true;
} else if (isDigit(prevChar)) {
numCount++;
} else {
if (isLetterOrUnderLine(prevChar) || prevChar == '$')
return false;
break;
}
return false;
}
return false;
i--;
}
} else {
break;
}
i++; //XQ135 modify// Floating-point number supporting hexadecimal representation
} //XQ135 modify// End 2024.3.24
}
return false;
return numCount > 0;
}
if (prevChar == 'p' || prevChar == 'P') {
i--;
bool hasPoint = false;
bool hasX = false;
int numCount = 0;
while (i >= 0) {
prevChar = currentLine[i];
if (isHexDigit(prevChar)) {
if (hasX)
return false;
numCount++ ;
} else if (prevChar == '.') {
if (hasPoint || hasX)
return false;
hasPoint = true;
} else if ( prevChar == 'x' || prevChar =='X') {
if (hasX)
return false;
i--;
if (i<0)
return false;
if (currentLine[i]!='0')
return false;
hasX = true;
} else {
if (isLetterOrUnderLine(prevChar) || prevChar == '$')
return false;
break;
}
i--; //XQ135 modify// Floating-point number supporting hexadecimal representation
}
return hasX && numCount > 0;
}
return false;
}
/**

View File

@ -761,7 +761,21 @@ bool ASBase::isCharPotentialOperator(char ch) const
// NOTE: Visual C isdigit() gives assert error if char > 256
bool ASBase::isDigit(char ch) const
{
return (ch >= '0' && ch <= '9');
return (ch >= '0' && ch <= '9');
}
bool ASBase::isHexDigit(char ch) const
{
return (ch >= '0' && ch <= '9')
|| (ch >= 'a' && ch <= 'f')
|| (ch >= 'A' && ch <= 'F');
}
bool ASBase::isLetterOrUnderLine(char ch) const
{ return (ch >= 'a' && ch <= 'z')
|| (ch >= 'A' && ch <= 'Z')
|| (ch == '_');
}
// check if a specific character is a digit separator

View File

@ -318,6 +318,8 @@ protected: // functions definitions are at the end of ASResource.cpp
const vector<const string*>* possibleOperators) const;
string getCurrentWord(const string& line, size_t index) const;
bool isDigit(char ch) const;
bool isHexDigit(char ch) const;
bool isLetterOrUnderLine(char ch) const;
bool isLegalNameChar(char ch) const;
bool isCharPotentialHeader(const string& line, size_t i) const;
bool isCharPotentialOperator(char ch) const;