From 3529e8dfeaf07d0d115a1bea8784149c38972e92 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sun, 24 Oct 2021 23:31:26 +0800 Subject: [PATCH] - fix: can't correctly handle '&&' and '||' in the #if directive (and correctly parse windows.h header file) --- NEWS.md | 1 + RedPandaIDE/parser/cpppreprocessor.cpp | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index ef8fc383..2945c93e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ Version 0.7.3 - enhancement: "use utf8 by default" in editor's misc setting - fix: syntax issues not correctly cleared when the file was saved as another name. - enhancement: when running a program, redirect a data file to its stdin + - fix: can't correctly handle '&&' and '||' in the #if directive (and correctly parse windows.h header file) Version 0.7.2 - fix: rainbow parenthesis stop functioning when change editor's general options diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 78ee0c0e..6967394b 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -1320,21 +1320,21 @@ bool CppPreprocessor::evalNumber(const QString &expr, int &result, int &pos) if (s.endsWith("LL",Qt::CaseInsensitive)) { s.remove(s.length()-2,2); - result = s.toLongLong(&ok,0); + result = s.toLongLong(&ok); } else if (s.endsWith("L",Qt::CaseInsensitive)) { s.remove(s.length()-1,1); - result = s.toLong(&ok,0); + result = s.toLong(&ok); } else if (s.endsWith("ULL",Qt::CaseInsensitive)) { s.remove(s.length()-3,3); - result = s.toULongLong(&ok,0); + result = s.toULongLong(&ok); } else if (s.endsWith("UL",Qt::CaseInsensitive)) { s.remove(s.length()-2,2); - result = s.toULong(&ok,0); + result = s.toULong(&ok); } else if (s.endsWith("U",Qt::CaseInsensitive)) { s.remove(s.length()-1,1); - result = s.toUInt(&ok,0); + result = s.toUInt(&ok); } else { - result = s.toInt(&ok,0); + result = s.toInt(&ok); } return ok; } @@ -1578,7 +1578,9 @@ bool CppPreprocessor::evalBitAndExpr(const QString &expr, int &result, int &pos) while (true) { if (!skipSpaces(expr,pos)) break; - if (expr[pos]=='&') { + if (expr[pos]=='&' + && (pos == expr.length() + || expr[pos+1]!='&')) { pos++; int rightResult; if (!evalEqualExpr(expr,rightResult,pos)) @@ -1626,7 +1628,9 @@ bool CppPreprocessor::evalBitOrExpr(const QString &expr, int &result, int &pos) while (true) { if (!skipSpaces(expr,pos)) break; - if (expr[pos] == '|') { + if (expr[pos] == '|' + && (pos == expr.length() + || expr[pos+1]!='|')) { pos++; int rightResult; if (!evalBitXorExpr(expr,rightResult,pos))