Skip to content

Commit af94a8e

Browse files
authored
Implement ASC_ignoreFile pragma (#15)
1 parent b2d55a6 commit af94a8e

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

src/scriptCompiler.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class MyLogger : public StdOutLogger {
3434

3535
static MyLogger vmlogger;
3636

37-
ScriptCompiler::ScriptCompiler(const std::vector<std::filesystem::path>& includePaths) {
37+
void ScriptCompiler::init()
38+
{
3839
vmlogger.setEnabled(loglevel::trace, false);
3940
vm = std::make_unique<sqf::runtime::runtime>(vmlogger, sqf::runtime::runtime::runtime_conf{});
4041

@@ -54,20 +55,25 @@ ScriptCompiler::ScriptCompiler(const std::vector<std::filesystem::path>& include
5455
// CommandList::init(*vm);
5556
// //sqf::commandmap::get().init();
5657
//});
58+
59+
addPragma({ "ASC_ignoreFile", [this](const sqf::runtime::parser::pragma& m,
60+
::sqf::runtime::runtime& runtime,
61+
const ::sqf::runtime::diagnostics::diag_info dinf,
62+
const ::sqf::runtime::fileio::pathinfo location,
63+
const std::string& data) -> std::string
64+
{
65+
ignoreCurrentFile = true;
66+
return {}; // string return type is wrong, isn't used for anything
67+
} });
68+
}
69+
70+
ScriptCompiler::ScriptCompiler(const std::vector<std::filesystem::path>& includePaths) {
71+
init();
5772
initIncludePaths(includePaths);
5873
}
5974

6075
ScriptCompiler::ScriptCompiler() {
61-
vmlogger.setEnabled(loglevel::trace, false);
62-
vm = std::make_unique<sqf::runtime::runtime>(vmlogger, sqf::runtime::runtime::runtime_conf{});
63-
64-
vm->fileio(std::make_unique<sqf::fileio::impl_default>(vmlogger));
65-
vm->parser_config(std::make_unique<sqf::parser::config::parser>(vmlogger));
66-
vm->parser_preprocessor(std::make_unique<sqf::parser::preprocessor::impl_default>(vmlogger));
67-
vm->parser_sqf(std::make_unique<sqf::parser::sqf::parser>(vmlogger));
68-
69-
CommandList::init(*vm);
70-
76+
init();
7177
}
7278

7379
CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path physicalPath, std::filesystem::path virtualPath) {
@@ -100,6 +106,14 @@ CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path physicalPat
100106
//__debugbreak();
101107
return CompiledCodeData();
102108
}
109+
110+
if (ignoreCurrentFile)
111+
{
112+
std::cout << "File " << physicalPath.generic_string() << " skipped due to ASC_ignoreFile pragma\n";
113+
ignoreCurrentFile = false;
114+
return CompiledCodeData();
115+
}
116+
103117
bool errorflag = false;
104118

105119

src/scriptCompiler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using astnode = sqf::parser::sqf::bison::astnode;
1515

1616
class ScriptCompiler {
17+
void init();
1718
public:
1819
ScriptCompiler(const std::vector<std::filesystem::path>& includePaths);
1920
ScriptCompiler();
@@ -38,4 +39,5 @@ class ScriptCompiler {
3839
ScriptConstantArray ASTParseArray(CompiledCodeData& output, CompileTempData& temp, const OptimizerModuleBase::Node& node) const;
3940
void ASTToInstructions(CompiledCodeData& output, CompileTempData& temp, std::vector<ScriptInstruction>& instructions, const OptimizerModuleBase::Node& node) const;
4041
std::unique_ptr<sqf::runtime::runtime> vm;
42+
bool ignoreCurrentFile = false;
4143
};

0 commit comments

Comments
 (0)