- 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: crash when refactor symbol and cursor is at the end of the identifier
- fix: refactor symbol doesn't work for 1-length identifiers - 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) - 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 Red Panda C++ Version 0.13.1
- enhancement: suppoort localization info in project templates - 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 ( } else if (
(tokenType != SynHighlighterTokenType::Symbol) && (tokenType != SynHighlighterTokenType::Symbol) &&
(tokenType != SynHighlighterTokenType::Space) && (tokenType != SynHighlighterTokenType::Space) &&
(tokenType != SynHighlighterTokenType::Keyword) &&
(tokenType != SynHighlighterTokenType::Identifier) (tokenType != SynHighlighterTokenType::Identifier)
) { ) {
return; 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 // SpacePos := LastPos(' ', Copy(S, BracePos, MaxInt)) // start search at brace
// end else begin // end else begin
// } // }
int spacePos = s.lastIndexOf(' '); // Cut up at last space //skip []
if (spacePos >= 0) { int varEndPos = s.length()-1;
args = ""; int bracketLevel = 0;
int bracketPos = s.indexOf('['); while (varEndPos>=0) {
if (bracketPos >= 0) { switch(s[varEndPos].unicode()) {
args = s.mid(bracketPos); case ']':
s.truncate(bracketPos); 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( addStatement(
functionStatement, functionStatement,
mCurrentFile, mCurrentFile,
"", // do not override hint "", // do not override hint
s.mid(0,spacePos), // 'int*' s.mid(0,varStartPos), // 'int*'
s.mid(spacePos+1), // a s.mid(varStartPos,varEndPos-varStartPos+1), // a
args, args,
"", "",
functionStatement->definitionLine, functionStatement->definitionLine,
@ -4352,6 +4372,14 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, const QStrin
true, true,
false); 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 , paramStart = i + 1; // step over ,
} }
i++; i++;

View File

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

View File

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