mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-11 11:26:00 -05:00
readCDefines() - don't crash on invalid expressions, add better debugging info
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define PARSEUTIL_H
|
||||
|
||||
#include "heallocation.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
@@ -10,6 +11,30 @@
|
||||
enum TokenType {
|
||||
Number,
|
||||
Operator,
|
||||
Error,
|
||||
};
|
||||
|
||||
class DebugInfo {
|
||||
public:
|
||||
DebugInfo(QString file, QStringList lines) {
|
||||
this->file = file;
|
||||
this->lines = lines;
|
||||
};
|
||||
QString file;
|
||||
int line;
|
||||
bool err;
|
||||
QStringList lines;
|
||||
void error(QString expression, QString token) {
|
||||
int lineNo = 0;
|
||||
for (QString line_ : lines) {
|
||||
lineNo++;
|
||||
if (line_.contains(expression)) {
|
||||
this->line = lineNo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
logError(QString("%1:%2: unknown identifier found in expression: '%3'.").arg(file).arg(line).arg(token));
|
||||
}
|
||||
};
|
||||
|
||||
class Token {
|
||||
@@ -22,6 +47,8 @@ public:
|
||||
this->operatorPrecedence = -1;
|
||||
} else if (type == "operator") {
|
||||
this->operatorPrecedence = precedenceMap[value];
|
||||
} else if (type == "error") {
|
||||
this->type = TokenType::Error;
|
||||
}
|
||||
}
|
||||
static QMap<QString, int> precedenceMap;
|
||||
@@ -33,10 +60,11 @@ public:
|
||||
class ParseUtil
|
||||
{
|
||||
public:
|
||||
ParseUtil();
|
||||
ParseUtil(QString, QString);
|
||||
void strip_comment(QString*);
|
||||
QList<QStringList>* parseAsm(QString);
|
||||
int evaluateDefine(QString, QMap<QString, int>*);
|
||||
DebugInfo *debug;
|
||||
private:
|
||||
QList<Token> tokenizeExpression(QString expression, QMap<QString, int>* knownIdentifiers);
|
||||
QList<Token> generatePostfix(QList<Token> tokens);
|
||||
|
||||
Reference in New Issue
Block a user