MCPcopy Create free account
hub / github.com/ZDoom/gzdoom / ParseOneScript

Function ParseOneScript

src/common/scripting/frontend/zcc_parser.cpp:412–541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410//**--------------------------------------------------------------------------
411
412PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
413{
414 FScanner sc;
415 void *parser;
416 ZCCToken value;
417 int lumpnum = baselump;
418 auto fileno = fileSystem.GetFileContainer(lumpnum);
419
420 state.FileNo = fileno;
421
422 if (TokenMap.CountUsed() == 0)
423 {
424 InitTokenMap();
425 }
426
427 parser = ZCCParseAlloc(malloc);
428
429#ifndef NDEBUG
430 FILE *f = nullptr;
431 const char *tracefile = Args->CheckValue("-tracefile");
432 if (tracefile != nullptr)
433 {
434 f = fopen(tracefile, "w");
435 char prompt = '\0';
436 ZCCParseTrace(f, &prompt);
437 }
438#endif
439
440 sc.OpenLumpNum(lumpnum);
441 sc.SetParseVersion({ 2, 4 }); // To get 'version' we need parse version 2.4 for the initial test
442 auto saved = sc.SavePos();
443
444 if (sc.GetToken())
445 {
446 if (sc.TokenType == TK_Version)
447 {
448 char *endp;
449 sc.MustGetString();
450 state.ParseVersion.major = (int16_t)clamp<unsigned long long>(strtoull(sc.String, &endp, 10), 0, USHRT_MAX);
451 if (*endp != '.')
452 {
453 sc.ScriptError("Bad version directive");
454 }
455 state.ParseVersion.minor = (int16_t)clamp<unsigned long long>(strtoll(endp + 1, &endp, 10), 0, USHRT_MAX);
456 if (*endp == '.')
457 {
458 state.ParseVersion.revision = (int16_t)clamp<unsigned long long>(strtoll(endp + 1, &endp, 10), 0, USHRT_MAX);
459 }
460 else state.ParseVersion.revision = 0;
461 if (*endp != 0)
462 {
463 sc.ScriptError("Bad version directive");
464 }
465 if (state.ParseVersion.major == USHRT_MAX || state.ParseVersion.minor == USHRT_MAX || state.ParseVersion.revision == USHRT_MAX)
466 {
467 sc.ScriptError("Bad version directive");
468 }
469 if (state.ParseVersion > MakeVersion(VER_MAJOR, VER_MINOR, VER_REVISION))

Callers 1

ParseScriptsFunction · 0.85

Calls 15

InitTokenMapFunction · 0.85
strtoullFunction · 0.85
strtollFunction · 0.85
MakeVersionFunction · 0.85
ParseSingleFileFunction · 0.85
I_FatalErrorFunction · 0.85
I_ErrorFunction · 0.85
ZCC_PrintASTFunction · 0.85
GetFileContainerMethod · 0.80
CountUsedMethod · 0.80
SetParseVersionMethod · 0.80
SavePosMethod · 0.80

Tested by

no test coverage detected