From f04c7c02219b473af514c86d52b318bdeff1a627 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 12 Mar 2023 12:42:44 +0800 Subject: [PATCH] refactor test for operator --- RedPandaIDE/parser/cppparser.cpp | 6 +++--- RedPandaIDE/parser/parserutils.cpp | 3 ++- RedPandaIDE/parser/parserutils.h | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 2b90f899..b27ae772 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1631,6 +1631,7 @@ bool CppParser::checkForKeyword(KeywordType& keywordType) case KeywordType::None: case KeywordType::NotKeyword: case KeywordType::DeclType: + case KeywordType::Operator: return false; default: return true; @@ -1753,13 +1754,12 @@ bool CppParser::checkForTypedefStruct() bool CppParser::checkForUsing(KeywordType keywordType) { return keywordType==KeywordType::Using && (mIndex < mTokenizer.tokenCount()-1); - } void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) { if (mIndex+2>=mTokenizer.tokenCount()) { - mIndex+=2; // left's finish; + mIndex+=2; // let's finish; return; } QString currentText=mTokenizer[mIndex]->text; @@ -1773,7 +1773,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) mIndex+=2; } } else { - if (currentText=="operator") { + if (keywordType == KeywordType::Operator) { handleOperatorOverloading("", mIndex, false); diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index 5bbd3fd5..42d58ca1 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -184,8 +184,9 @@ void initParser() CppKeywords.insert("const",KeywordType::None); CppKeywords.insert("extern",KeywordType::None); + CppKeywords.insert("operator",KeywordType::Operator); + // handled elsewhere - CppKeywords.insert("operator",KeywordType::None); CppKeywords.insert("static",KeywordType::None); //struct/class/union diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index c8b46e31..f042283b 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -76,6 +76,7 @@ enum class KeywordType { Typedef, //typedef Using, //using DeclType, // decltype + Operator, //operator None, // It's a keyword but don't process here NotKeyword };