- fix: parser can't correctly handle variable definitions that don't have spaces like 'int*x';

- fix: parser can't correctly handle function parameters like 'int *x'
This commit is contained in:
Roy Qu 2022-01-12 20:59:28 +08:00
parent 454df24e08
commit eefb65bcb4
7 changed files with 525 additions and 473 deletions

View File

@ -12,6 +12,8 @@ Red Panda C++ Version 0.13.2
- fix: crash when refactor symbol and cursor is at the end of the identifier
- fix: refactor symbol doesn't work for 1-length identifiers
- enhancement: redirect stdio to a file while debugging ( must use gdb server mode to debug)
- fix: parser can't correctly handle variable definitions that don't have spaces like 'int*x';
- fix: parser can't correctly handle function parameters like 'int *x'
Red Panda C++ Version 0.13.1
- enhancement: suppoort localization info in project templates

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -2609,6 +2609,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete)
} else if (
(tokenType != SynHighlighterTokenType::Symbol) &&
(tokenType != SynHighlighterTokenType::Space) &&
(tokenType != SynHighlighterTokenType::Keyword) &&
(tokenType != SynHighlighterTokenType::Identifier)
) {
return;

View File

@ -4329,20 +4329,40 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, const QStrin
// SpacePos := LastPos(' ', Copy(S, BracePos, MaxInt)) // start search at brace
// end else begin
// }
int spacePos = s.lastIndexOf(' '); // Cut up at last space
if (spacePos >= 0) {
args = "";
int bracketPos = s.indexOf('[');
if (bracketPos >= 0) {
args = s.mid(bracketPos);
s.truncate(bracketPos);
//skip []
int varEndPos = s.length()-1;
int bracketLevel = 0;
while (varEndPos>=0) {
switch(s[varEndPos].unicode()) {
case ']':
bracketLevel++;
break;
case '[':
bracketLevel--;
varEndPos--;
break;
}
if (bracketLevel==0)
break;
varEndPos--;
}
int varStartPos = varEndPos;
if (varEndPos>=0) {
while (varStartPos-1>=0) {
if (!mTokenizer.isIdentChar(s[varStartPos-1]))
break;
varStartPos--;
}
}
if (varStartPos>=0) {
if (varEndPos+1<s.length())
args=s.mid(varEndPos+1);
addStatement(
functionStatement,
mCurrentFile,
"", // do not override hint
s.mid(0,spacePos), // 'int*'
s.mid(spacePos+1), // a
s.mid(0,varStartPos), // 'int*'
s.mid(varStartPos,varEndPos-varStartPos+1), // a
args,
"",
functionStatement->definitionLine,
@ -4352,6 +4372,14 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, const QStrin
true,
false);
}
if (varStartPos<s.length()) {
args = "";
int bracketPos = s.indexOf('[');
if (bracketPos >= 0) {
args = s.mid(bracketPos);
s.truncate(bracketPos);
}
}
paramStart = i + 1; // step over ,
}
i++;

View File

@ -268,8 +268,9 @@ QString CppTokenizer::getWord(bool bSkipParenthesis, bool bSkipArray, bool bSkip
// Get next word...
QChar* offset = mCurrent;
mCurrent++;
// Copy the word ahead of us
while (isLetterChar(*mCurrent) || isDigitChar(*mCurrent))
while (isIdentChar(*mCurrent) || isDigitChar(*mCurrent))
mCurrent++;
QString currentWord;
@ -582,6 +583,11 @@ void CppTokenizer::skipToNextToken()
advance();
}
bool CppTokenizer::isIdentChar(const QChar &ch)
{
return ch.isLetter();
}
void CppTokenizer::advance()
{
switch(mCurrent->unicode()) {
@ -634,7 +640,7 @@ bool CppTokenizer::isLetterChar(const QChar &ch)
{
// return (ch>= 'A' && ch<='Z')
// || (ch>='a' && ch<='z')
return ch.isLetter()
return isIdentChar(ch)
|| ch == '_'
|| ch == '*'
|| ch == '&'

View File

@ -37,6 +37,7 @@ public:
const TokenList& tokens();
PToken operator[](int i);
int tokenCount();
bool isIdentChar(const QChar& ch);
private:
void addToken(const QString& sText, int iLine);
void advance();