2021-08-13 22:53:26 +08:00
|
|
|
#ifndef CPPTOKENIZER_H
|
|
|
|
#define CPPTOKENIZER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include "parserutils.h"
|
|
|
|
|
2021-08-14 22:52:37 +08:00
|
|
|
class CppTokenizer
|
2021-08-13 22:53:26 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Token {
|
|
|
|
QString text;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
using PToken = std::shared_ptr<Token>;
|
|
|
|
using TokenList = QVector<PToken>;
|
2021-08-14 22:52:37 +08:00
|
|
|
explicit CppTokenizer();
|
2021-08-13 22:53:26 +08:00
|
|
|
|
2021-08-14 18:55:42 +08:00
|
|
|
void reset();
|
|
|
|
void tokenize(const QStringList& buffer);
|
|
|
|
void dumpTokens(const QString& fileName);
|
2021-08-15 16:49:37 +08:00
|
|
|
const TokenList& tokens();
|
|
|
|
PToken operator[](int i);
|
|
|
|
int tokenCount();
|
2021-08-13 22:53:26 +08:00
|
|
|
private:
|
|
|
|
void addToken(const QString& sText, int iLine);
|
2021-08-14 12:33:02 +08:00
|
|
|
void advance();
|
2021-08-13 22:53:26 +08:00
|
|
|
void countLines();
|
|
|
|
PToken getToken(int index);
|
2021-08-14 12:33:02 +08:00
|
|
|
|
2021-08-13 22:53:26 +08:00
|
|
|
QString getArguments();
|
|
|
|
QString getForInit();
|
2021-08-14 12:33:02 +08:00
|
|
|
QString getNextToken(
|
|
|
|
bool bSkipParenthesis = false,
|
|
|
|
bool bSkipArray = false,
|
|
|
|
bool bSkipBlock = false);
|
2021-08-13 22:53:26 +08:00
|
|
|
QString getNumber();
|
|
|
|
QString getPreprocessor();
|
|
|
|
QString getWord(
|
|
|
|
bool bSkipParenthesis = false,
|
|
|
|
bool bSkipArray = false,
|
|
|
|
bool bSkipBlock = false);
|
|
|
|
bool isArguments();
|
|
|
|
bool isForInit();
|
2021-08-14 12:33:02 +08:00
|
|
|
bool isNumber();
|
|
|
|
bool isPreprocessor();
|
|
|
|
bool isWord();
|
2021-08-13 22:53:26 +08:00
|
|
|
void simplify(QString& output);
|
|
|
|
void simplifyArgs(QString& output);
|
2021-08-14 12:33:02 +08:00
|
|
|
void skipAssignment();
|
|
|
|
void skipDoubleQuotes();
|
|
|
|
void skipPair(const QChar& cStart, const QChar cEnd, const QSet<QChar>& failChars = QSet<QChar>());
|
|
|
|
void skipRawString();
|
|
|
|
void skipSingleQuote();
|
|
|
|
void skipSplitLine();
|
|
|
|
void skipTemplateArgs();
|
|
|
|
void skipToEOL();
|
|
|
|
void skipToNextToken();
|
2021-08-13 22:53:26 +08:00
|
|
|
bool openFile(const QString& fileName);
|
2021-08-14 12:33:02 +08:00
|
|
|
bool isLetterChar(const QChar& ch);
|
|
|
|
bool isHexChar(const QChar& ch);
|
|
|
|
bool isDigitChar(const QChar& ch);
|
|
|
|
bool isSpaceChar(const QChar& ch);
|
|
|
|
bool isLineChar(const QChar& ch);
|
|
|
|
bool isBlankChar(const QChar& ch);
|
|
|
|
bool isOperatorChar(const QChar& ch);
|
|
|
|
|
|
|
|
bool currentWordEquals(QChar* wordStart, QChar *wordEnd, const QString& text);
|
2021-08-13 22:53:26 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
QStringList mBuffer;
|
|
|
|
QString mBufferStr;
|
|
|
|
QChar* mStart;
|
|
|
|
QChar* mCurrent;
|
|
|
|
QChar* mLineCount;
|
|
|
|
int mCurrentLine;
|
|
|
|
QString mLastToken;
|
|
|
|
TokenList mTokenList;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CPPTOKENIZER_H
|