From dcf37eca8ae5cfd55c5e07df52ed0c28a4e79c53 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Thu, 12 Aug 2021 11:29:26 +0800 Subject: [PATCH] work save: cpp parser - preprocessor : remove comments before preprocess --- RedPandaIDE/parser/cpppreprocessor.cpp | 115 ++++++++++++++++++++++++- RedPandaIDE/parser/cpppreprocessor.h | 14 ++- 2 files changed, 124 insertions(+), 5 deletions(-) diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 8dbfb36e..66129d20 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -356,12 +356,12 @@ void CppPreprocessor::openInclude(const QString &fileName, QTextStream stream) // Process it mIndex = parsedFile->index; mFileName = parsedFile->fileName; + parsedFile->buffer = removeComments(parsedFile->buffer); mBuffer = parsedFile->buffer; - // Trim all lines - for (int i=0;i 0) { diff --git a/RedPandaIDE/parser/cpppreprocessor.h b/RedPandaIDE/parser/cpppreprocessor.h index 1258f5d4..d2dc455e 100644 --- a/RedPandaIDE/parser/cpppreprocessor.h +++ b/RedPandaIDE/parser/cpppreprocessor.h @@ -19,6 +19,18 @@ using PParsedFile = std::shared_ptr; class CppPreprocessor : public QObject { Q_OBJECT + + enum class ContentType { + AnsiCComment, + CppComment, + String, + Character, + EscapeSequence, + RawStringPrefix, + RawString, + Other + }; + public: explicit CppPreprocessor(QObject *parent = nullptr); @@ -70,7 +82,7 @@ private: PFileIncludes getFileIncludesEntry(const QString& FileName); void addDefinesInFile(const QString& fileName); - void preprocessBuffer(); + QStringList removeComments(const QStringList& text); /* * '_','a'..'z','A'..'Z','0'..'9' */