mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Revert "Implement INCLUDE_ONCE directive (#1481)"
This reverts commit 5f07095f6d.
This commit is contained in:
@@ -17,12 +17,6 @@
|
|||||||
|
|
||||||
#include "asm/lexer.hpp"
|
#include "asm/lexer.hpp"
|
||||||
|
|
||||||
enum IncludeType {
|
|
||||||
INCLUDE_NORMAL,
|
|
||||||
INCLUDE_PRE,
|
|
||||||
INCLUDE_ONCE
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FileStackNode {
|
struct FileStackNode {
|
||||||
FileStackNodeType type;
|
FileStackNodeType type;
|
||||||
Either<
|
Either<
|
||||||
@@ -70,7 +64,7 @@ void fstk_SetPreIncludeFile(std::string const &path);
|
|||||||
std::optional<std::string> fstk_FindFile(std::string const &path);
|
std::optional<std::string> fstk_FindFile(std::string const &path);
|
||||||
|
|
||||||
bool yywrap();
|
bool yywrap();
|
||||||
void fstk_RunInclude(std::string const &path, IncludeType type);
|
void fstk_RunInclude(std::string const &path, bool updateStateNow);
|
||||||
void fstk_RunMacro(std::string const ¯oName, std::shared_ptr<MacroArgs> macroArgs);
|
void fstk_RunMacro(std::string const ¯oName, std::shared_ptr<MacroArgs> macroArgs);
|
||||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, ContentSpan const &span);
|
void fstk_RunRept(uint32_t count, int32_t reptLineNo, ContentSpan const &span);
|
||||||
void fstk_RunFor(
|
void fstk_RunFor(
|
||||||
|
|||||||
12
man/rgbasm.5
12
man/rgbasm.5
@@ -2158,17 +2158,7 @@ calls infinitely (or until you run out of memory, whichever comes first).
|
|||||||
INCLUDE "irq.inc"
|
INCLUDE "irq.inc"
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
You may also ensure a file only gets included once by using
|
You may also implicitly
|
||||||
.Ic INCLUDE_ONCE
|
|
||||||
instead of
|
|
||||||
.Ic INCLUDE .
|
|
||||||
This will skip including a file if it has already been included before (with
|
|
||||||
.Ic INCLUDE ,
|
|
||||||
.Ic INCLUDE_ONCE ,
|
|
||||||
or
|
|
||||||
.Fl P ) .
|
|
||||||
.Pp
|
|
||||||
You can implicitly
|
|
||||||
.Ic INCLUDE
|
.Ic INCLUDE
|
||||||
a file before the source file with the
|
a file before the source file with the
|
||||||
.Fl P
|
.Fl P
|
||||||
|
|||||||
@@ -6,11 +6,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
@@ -47,8 +45,8 @@ size_t maxRecursionDepth;
|
|||||||
|
|
||||||
// The first include path for `fstk_FindFile` to try is none at all
|
// The first include path for `fstk_FindFile` to try is none at all
|
||||||
static std::vector<std::string> includePaths = {""};
|
static std::vector<std::string> includePaths = {""};
|
||||||
|
|
||||||
static std::string preIncludeName;
|
static std::string preIncludeName;
|
||||||
static std::set<std::pair<dev_t, ino_t>> includedFiles;
|
|
||||||
|
|
||||||
std::string const &FileStackNode::dump(uint32_t curLineNo) const {
|
std::string const &FileStackNode::dump(uint32_t curLineNo) const {
|
||||||
if (data.holds<std::vector<uint32_t>>()) {
|
if (data.holds<std::vector<uint32_t>>()) {
|
||||||
@@ -293,11 +291,11 @@ static Context &newReptContext(int32_t reptLineNo, ContentSpan const &span, uint
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fstk_RunInclude(std::string const &path, IncludeType type) {
|
void fstk_RunInclude(std::string const &path, bool preInclude) {
|
||||||
std::optional<std::string> fullPath = fstk_FindFile(path);
|
std::optional<std::string> fullPath = fstk_FindFile(path);
|
||||||
|
|
||||||
if (!fullPath) {
|
if (!fullPath) {
|
||||||
if (generatedMissingIncludes && type != INCLUDE_PRE) {
|
if (generatedMissingIncludes && !preInclude) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n", path.c_str(), strerror(errno));
|
printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n", path.c_str(), strerror(errno));
|
||||||
failedOnMissingInclude = true;
|
failedOnMissingInclude = true;
|
||||||
@@ -307,24 +305,6 @@ void fstk_RunInclude(std::string const &path, IncludeType type) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The pair of device ID and serial number uniquely identify a file, with `stat()`
|
|
||||||
// following symbolic links to identify the actual file.
|
|
||||||
struct stat statBuf;
|
|
||||||
if (stat(fullPath->c_str(), &statBuf) != 0) {
|
|
||||||
error("Failed to stat file '%s': %s\n", fullPath->c_str(), strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::pair<dev_t, ino_t> inode{statBuf.st_dev, statBuf.st_ino};
|
|
||||||
|
|
||||||
if (type == INCLUDE_ONCE && includedFiles.find(inode) != includedFiles.end()) {
|
|
||||||
if (verbose) {
|
|
||||||
printf("File '%s' already included, skipping INCLUDE_ONCE", path.c_str());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
includedFiles.insert(inode);
|
|
||||||
|
|
||||||
if (!newFileContext(*fullPath, false))
|
if (!newFileContext(*fullPath, false))
|
||||||
fatalerror("Failed to set up lexer for file include\n");
|
fatalerror("Failed to set up lexer for file include\n");
|
||||||
}
|
}
|
||||||
@@ -415,5 +395,5 @@ void fstk_Init(std::string const &mainPath, size_t maxDepth) {
|
|||||||
maxRecursionDepth = maxDepth;
|
maxRecursionDepth = maxDepth;
|
||||||
|
|
||||||
if (!preIncludeName.empty())
|
if (!preIncludeName.empty())
|
||||||
fstk_RunInclude(preIncludeName, INCLUDE_PRE);
|
fstk_RunInclude(preIncludeName, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ static std::unordered_map<std::string, int, CaseInsensitive, CaseInsensitive> ke
|
|||||||
{"INCHARMAP", T_(OP_INCHARMAP) },
|
{"INCHARMAP", T_(OP_INCHARMAP) },
|
||||||
|
|
||||||
{"INCLUDE", T_(POP_INCLUDE) },
|
{"INCLUDE", T_(POP_INCLUDE) },
|
||||||
{"INCLUDE_ONCE", T_(POP_INCLUDE_ONCE) },
|
|
||||||
{"PRINT", T_(POP_PRINT) },
|
{"PRINT", T_(POP_PRINT) },
|
||||||
{"PRINTLN", T_(POP_PRINTLN) },
|
{"PRINTLN", T_(POP_PRINTLN) },
|
||||||
{"EXPORT", T_(POP_EXPORT) },
|
{"EXPORT", T_(POP_EXPORT) },
|
||||||
|
|||||||
@@ -236,7 +236,6 @@
|
|||||||
%token POP_IF "IF"
|
%token POP_IF "IF"
|
||||||
%token POP_INCBIN "INCBIN"
|
%token POP_INCBIN "INCBIN"
|
||||||
%token POP_INCLUDE "INCLUDE"
|
%token POP_INCLUDE "INCLUDE"
|
||||||
%token POP_INCLUDE_ONCE "INCLUDE_ONCE"
|
|
||||||
%token POP_LOAD "LOAD"
|
%token POP_LOAD "LOAD"
|
||||||
%token POP_MACRO "MACRO"
|
%token POP_MACRO "MACRO"
|
||||||
%token POP_NEWCHARMAP "NEWCHARMAP"
|
%token POP_NEWCHARMAP "NEWCHARMAP"
|
||||||
@@ -465,7 +464,6 @@ line_directive:
|
|||||||
| for
|
| for
|
||||||
| break
|
| break
|
||||||
| include
|
| include
|
||||||
| include_once
|
|
||||||
| if
|
| if
|
||||||
// It's important that all of these require being at line start for `skipIfBlock`
|
// It's important that all of these require being at line start for `skipIfBlock`
|
||||||
| elif
|
| elif
|
||||||
@@ -1142,15 +1140,7 @@ export_def:
|
|||||||
|
|
||||||
include:
|
include:
|
||||||
label POP_INCLUDE string endofline {
|
label POP_INCLUDE string endofline {
|
||||||
fstk_RunInclude($3, INCLUDE_NORMAL);
|
fstk_RunInclude($3, false);
|
||||||
if (failedOnMissingInclude)
|
|
||||||
YYACCEPT;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
include_once:
|
|
||||||
label POP_INCLUDE_ONCE string endofline {
|
|
||||||
fstk_RunInclude($3, INCLUDE_ONCE);
|
|
||||||
if (failedOnMissingInclude)
|
if (failedOnMissingInclude)
|
||||||
YYACCEPT;
|
YYACCEPT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
INCLUDE_ONCE "include-once.inc"
|
|
||||||
INCLUDE_ONCE "include-once.inc"
|
|
||||||
INCLUDE_ONCE "include-link.inc"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
DEF HELLO EQU 1
|
|
||||||
@@ -11,12 +11,9 @@ input="$(mktemp)"
|
|||||||
output="$(mktemp)"
|
output="$(mktemp)"
|
||||||
errput="$(mktemp)"
|
errput="$(mktemp)"
|
||||||
|
|
||||||
# Create a symbolic link for the `include-once.asm` test case.
|
|
||||||
ln include-once.inc include-link.inc
|
|
||||||
|
|
||||||
# Immediate expansion is the desired behavior.
|
# Immediate expansion is the desired behavior.
|
||||||
# shellcheck disable=SC2064
|
# shellcheck disable=SC2064
|
||||||
trap "rm -f ${o@Q} ${gb@Q} ${input@Q} ${output@Q} ${errput@Q} include-link.inc" EXIT
|
trap "rm -f ${o@Q} ${gb@Q} ${input@Q} ${output@Q} ${errput@Q}" EXIT
|
||||||
|
|
||||||
tests=0
|
tests=0
|
||||||
failed=0
|
failed=0
|
||||||
|
|||||||
Reference in New Issue
Block a user