Skip to content

Commit eadd441

Browse files
committed
fix: 修复脚本的 pragma 报错不精准和调试监视新增相关问题;
1 parent 8555e05 commit eadd441

File tree

12 files changed

+344
-331
lines changed

12 files changed

+344
-331
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ if(WINGHEX_ANGEL_LSP)
768768
OUTPUT ${DIST_JS}
769769
WORKING_DIRECTORY ${NODE_SUBDIR}
770770
COMMAND ${CMAKE_COMMAND} -E echo "[1] npm ci (local deps)"
771-
COMMAND ${NPM_EXE} ci --silent
771+
COMMAND ${NPM_EXE} ci
772772
COMMAND ${CMAKE_COMMAND} -E echo "[2] building with esbuild"
773773
COMMAND ${NPX_EXE} tsc
774774
COMMAND ${ESBUILD_CMD}

lang/en_US/winghex_en_US.ts

Lines changed: 88 additions & 88 deletions
Large diffs are not rendered by default.

lang/zh_CN/winghex_zh_CN.ts

Lines changed: 88 additions & 88 deletions
Large diffs are not rendered by default.

lang/zh_TW/winghex_zh_TW.ts

Lines changed: 88 additions & 88 deletions
Large diffs are not rendered by default.

src/class/aspreprocesser.cpp

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
330330
while (p < s.size() && s[p].isSpace())
331331
p++;
332332
QString rest = s.mid(p);
333-
static QRegularExpression re(R"(^(\w+)\b(.*)$)");
333+
static QRegularExpression re(QStringLiteral(R"(^(\w+)\b(.*)$)"));
334334
auto m = re.match(rest);
335335
QString kw = m.hasMatch() ? m.captured(1) : QString();
336336
QString args = m.hasMatch() ? m.captured(2) : QString();
@@ -341,7 +341,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
341341
flushCurrLine();
342342
};
343343

344-
if (kw == "define" || kw == "undef") {
344+
if (kw == QStringLiteral("define") || kw == QStringLiteral("undef")) {
345345
// Always forbidden in script
346346
PreprocError e{
347347
PreprocErrorCode::ERR_SOURCE_DEFINE_FORBIDDEN,
@@ -355,47 +355,45 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
355355
return;
356356
}
357357

358-
if (kw == "pragma") {
358+
if (kw == QStringLiteral("pragma")) {
359359
if (pragmaCallback) {
360360
auto r = pragmaCallback(args, this, m_currentSource);
361-
if (r) {
362-
auto c = r->info;
363-
if (!c.isEmpty()) {
364-
PreprocError e{PreprocErrorCode::ERR_SUCCESS,
365-
Severity::Info,
366-
m_currentSource,
367-
dStartLine,
368-
dStartCol,
369-
c};
370-
errorReport(e);
371-
}
372-
c = r->warn;
373-
if (!c.isEmpty()) {
374-
PreprocError e{PreprocErrorCode::ERR_SUCCESS,
375-
Severity::Info,
376-
m_currentSource,
377-
dStartLine,
378-
dStartCol,
379-
c};
380-
errorReport(e);
381-
}
382-
c = r->error;
383-
if (!c.isEmpty()) {
384-
PreprocError e{PreprocErrorCode::ERR_ERROR,
385-
Severity::Error,
386-
m_currentSource,
387-
dStartLine,
388-
dStartCol,
389-
c};
390-
errorReport(e);
391-
}
361+
auto c = r.info;
362+
if (!c.isEmpty()) {
363+
PreprocError e{PreprocErrorCode::ERR_SUCCESS,
364+
Severity::Info,
365+
m_currentSource,
366+
dStartLine,
367+
dStartCol,
368+
c};
369+
errorReport(e);
370+
}
371+
c = r.warn;
372+
if (!c.isEmpty()) {
373+
PreprocError e{PreprocErrorCode::ERR_SUCCESS,
374+
Severity::Info,
375+
m_currentSource,
376+
dStartLine,
377+
dStartCol,
378+
c};
379+
errorReport(e);
380+
}
381+
c = r.error;
382+
if (!c.isEmpty()) {
383+
PreprocError e{PreprocErrorCode::ERR_ERROR,
384+
Severity::Error,
385+
m_currentSource,
386+
dStartLine,
387+
dStartCol,
388+
c};
389+
errorReport(e);
392390
}
393391
}
394392
emitBlankLine();
395393
return;
396394
}
397395

398-
if (kw == "include") {
396+
if (kw == QStringLiteral("include")) {
399397
// parse include token
400398
QString incPath;
401399
bool isAngled = false;
@@ -446,7 +444,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
446444
return;
447445
}
448446

449-
if (kw == "if") {
447+
if (kw == QStringLiteral("if")) {
450448
QString expanded = expandExpressionForIf(args, m_currentSource,
451449
dStartLine, dStartCol);
452450
auto er = evalExpression(expanded, m_currentSource, dStartLine,
@@ -468,7 +466,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
468466
return;
469467
}
470468

471-
if (kw == "ifdef") {
469+
if (kw == QStringLiteral("ifdef")) {
472470
QByteArray ba = args.toUtf8();
473471
QString name = parseFirstIdentifierInBA(ba);
474472
if (name.isEmpty()) {
@@ -502,7 +500,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
502500
return;
503501
}
504502

505-
if (kw == "ifndef") {
503+
if (kw == QStringLiteral("ifndef")) {
506504
QByteArray ba = args.toUtf8();
507505
QString name = parseFirstIdentifierInBA(ba);
508506
if (name.isEmpty()) {
@@ -534,7 +532,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
534532
return;
535533
}
536534

537-
if (kw == "elif") {
535+
if (kw == QStringLiteral("elif")) {
538536
if (condStack.isEmpty()) {
539537
PreprocError e{PreprocErrorCode::ERR_ELIF_ELSE_WITHOUT_IF,
540538
Severity::Error,
@@ -566,7 +564,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
566564
return;
567565
}
568566

569-
if (kw == "else") {
567+
if (kw == QStringLiteral("else")) {
570568
if (condStack.isEmpty()) {
571569
PreprocError e{PreprocErrorCode::ERR_ELIF_ELSE_WITHOUT_IF,
572570
Severity::Error,
@@ -588,7 +586,7 @@ void AsPreprocesser::processBuffer(const QByteArray &buf,
588586
return;
589587
}
590588

591-
if (kw == "endif") {
589+
if (kw == QStringLiteral("endif")) {
592590
if (condStack.isEmpty()) {
593591
PreprocError e{PreprocErrorCode::ERR_ELIF_ELSE_WITHOUT_IF,
594592
Severity::Error,

src/class/aspreprocesser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AsPreprocesser {
6767
const QString &file, qint64 line, qint64 column, PreprocErrorCode code,
6868
Severity severity, const QString &message)>;
6969

70-
using CPragamaCallback = std::function<std::optional<WingHex::PragmaResult>(
70+
using CPragamaCallback = std::function<WingHex::PragmaResult(
7171
const QString &pragmaText, AsPreprocesser *builder,
7272
const QString &sectionname)>;
7373

src/class/pluginsystem.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,27 +3111,35 @@ bool PluginSystem::dispatchEvent(IWingPlugin::RegisteredEvent event,
31113111
return true;
31123112
}
31133113

3114-
std::optional<PragmaResult>
3115-
PluginSystem::processPragma(const QString &section, const QString &plgId,
3116-
const QStringList &params) {
3117-
3114+
PragmaResult PluginSystem::processPragma(const QString &section,
3115+
const QString &plgId,
3116+
const QStringList &params) {
31183117
auto &es = _evplgs[WingHex::IWingPlugin::RegisteredEvent::ScriptPragma];
31193118
auto r =
31203119
std::find_if(es.constBegin(), es.constEnd(), [plgId](IWingPlugin *p) {
31213120
return plgId.compare(getPUID(p), Qt::CaseInsensitive) == 0;
31223121
});
31233122
if (r == es.constEnd()) {
31243123
PragmaResult res;
3125-
res.error.append(QStringLiteral("Unknown pragma command %1 with %2")
3126-
.arg(params.join(' '), plgId));
3124+
res.error.append(
3125+
QStringLiteral("Unknown pragma module '%1'").arg(plgId));
31273126
return res;
31283127
}
31293128
auto plg = *r;
31303129
if (!_pragmaedPlg.contains(plg)) {
31313130
plg->eventOnScriptPragmaInit();
31323131
_pragmaedPlg.append(plg);
31333132
}
3134-
return plg->eventOnScriptPragma(section, params);
3133+
3134+
auto ret = plg->eventOnScriptPragma(section, params);
3135+
if (ret) {
3136+
return ret.value();
3137+
} else {
3138+
PragmaResult res;
3139+
res.error.append(QStringLiteral("Unknown pragma command %1 with %2")
3140+
.arg(params.join(' '), plgId));
3141+
return res;
3142+
}
31353143
}
31363144

31373145
IWingDevice *PluginSystem::ext2Device(const QString &ext) {

src/class/pluginsystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ class PluginSystem : public QObject {
164164
bool dispatchEvent(IWingPlugin::RegisteredEvent event,
165165
const QVariantList &params);
166166

167-
std::optional<WingHex::PragmaResult>
168-
processPragma(const QString &section, const QString &plgId,
169-
const QStringList &params);
167+
WingHex::PragmaResult processPragma(const QString &section,
168+
const QString &plgId,
169+
const QStringList &params);
170170

171171
IWingDevice *ext2Device(const QString &ext);
172172

src/class/scriptmachine.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,10 +1387,9 @@ QString ScriptMachine::debug_backtrace() {
13871387
return {};
13881388
}
13891389

1390-
std::optional<PragmaResult>
1391-
ScriptMachine::pragmaCallback(const QString &pragmaText,
1392-
AsPreprocesser *builder,
1393-
const QString &sectionname) {
1390+
PragmaResult ScriptMachine::pragmaCallback(const QString &pragmaText,
1391+
AsPreprocesser *builder,
1392+
const QString &sectionname) {
13941393
asIScriptEngine *engine = builder->getEngine();
13951394

13961395
// Filter the pragmaText so only what is of interest remains

src/class/scriptmachine.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ class ScriptMachine {
191191
static void returnContextCallback(asIScriptEngine *engine,
192192
asIScriptContext *ctx, void *param);
193193

194-
static std::optional<WingHex::PragmaResult>
195-
pragmaCallback(const QString &pragmaText, AsPreprocesser *builder,
196-
const QString &sectionname);
194+
static WingHex::PragmaResult pragmaCallback(const QString &pragmaText,
195+
AsPreprocesser *builder,
196+
const QString &sectionname);
197197

198198
static void debug_break();
199199

0 commit comments

Comments
 (0)