From ef3f7698e40a9f94d9293d6ad2ac20e9fd7b2aaf Mon Sep 17 00:00:00 2001 From: Christoph Hart Date: Tue, 15 Oct 2024 14:29:12 +0200 Subject: [PATCH] - SNEX: fix index templates not working --- hi_snex/snex_core/snex_jit_BaseCompiler.h | 7 ++++ hi_snex/snex_core/snex_jit_Inliner.cpp | 2 + .../snex_jit/snex_jit_OperationsSymbols.cpp | 2 +- .../snex_parser/snex_jit_FunctionParser.cpp | 2 + .../test_files/index/index14.h | 33 ++++++++++++++++ .../test_files/struct/inner_getter.h | 39 +++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tools/snex_playground/test_files/index/index14.h create mode 100644 tools/snex_playground/test_files/struct/inner_getter.h diff --git a/hi_snex/snex_core/snex_jit_BaseCompiler.h b/hi_snex/snex_core/snex_jit_BaseCompiler.h index a51a2cbc22..914ce9eef5 100644 --- a/hi_snex/snex_core/snex_jit_BaseCompiler.h +++ b/hi_snex/snex_core/snex_jit_BaseCompiler.h @@ -250,8 +250,15 @@ class BaseCompiler bool useCodeSnippetInErrorMessage() const { return useCodeSnippet; } + bool& isProcessingInlineFunction() + { + return inlineProcessFlag; + } + private: + bool inlineProcessFlag = false; + bool useCodeSnippet = false; FunctionClass::Ptr mathFunctions; diff --git a/hi_snex/snex_core/snex_jit_Inliner.cpp b/hi_snex/snex_core/snex_jit_Inliner.cpp index 10046ead4f..15a240a49d 100644 --- a/hi_snex/snex_core/snex_jit_Inliner.cpp +++ b/hi_snex/snex_core/snex_jit_Inliner.cpp @@ -229,6 +229,8 @@ struct SyntaxTreeInlineData : public InlineData for (int i = 0; i <= currentStatement->currentPass; i++) { + ScopedValueSetter ip(c->isProcessingInlineFunction(), true); + auto thisPass = (BaseCompiler::Pass)i; BaseCompiler::ScopedPassSwitcher svs(c, thisPass); c->executePass(thisPass, s, e.get()); diff --git a/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp b/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp index 7f6083ffe5..b191ab2e5e 100644 --- a/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp +++ b/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp @@ -653,7 +653,7 @@ void Operations::ThisPointer::process(BaseCompiler* compiler, BaseScope* scope) { auto thisType = dynamic_cast(type.get()); - if(thisType != currentClass) + if(thisType != currentClass && !compiler->isProcessingInlineFunction()) { // Apparently we need to allow different template parameters to go through // here so we check the namespaced identifier diff --git a/hi_snex/snex_parser/snex_jit_FunctionParser.cpp b/hi_snex/snex_parser/snex_jit_FunctionParser.cpp index de5eab76be..77d415b965 100644 --- a/hi_snex/snex_parser/snex_jit_FunctionParser.cpp +++ b/hi_snex/snex_parser/snex_jit_FunctionParser.cpp @@ -479,6 +479,8 @@ juce::Result SyntaxTreeInlineParser::flush() try { + ScopedValueSetter svs(d->expression->currentCompiler->isProcessingInlineFunction(), true); + if (d->expression->currentCompiler == nullptr) d->location.throwError("Internal compiler error"); diff --git a/tools/snex_playground/test_files/index/index14.h b/tools/snex_playground/test_files/index/index14.h new file mode 100644 index 0000000000..11a9054065 --- /dev/null +++ b/tools/snex_playground/test_files/index/index14.h @@ -0,0 +1,33 @@ +/* +BEGIN_TEST_DATA + f: main + ret: int + args: int + input: 12 + output: 12 + error: "" + filename: "index/index14" +END_TEST_DATA +*/ + +struct MyClass +{ + span data = { 1, 2, 12, 4 }; + + int process() const + { + index::clamped<0, false> idx; + idx = 2; + + return data[idx]; + } + +}; + +int main(int input) +{ + MyClass obj; + + return obj.process(); +} + diff --git a/tools/snex_playground/test_files/struct/inner_getter.h b/tools/snex_playground/test_files/struct/inner_getter.h new file mode 100644 index 0000000000..4cdac75852 --- /dev/null +++ b/tools/snex_playground/test_files/struct/inner_getter.h @@ -0,0 +1,39 @@ +/* +BEGIN_TEST_DATA + f: main + ret: int + args: int + input: 12 + output: 12 + error: "" + filename: "struct/inner_getter" +END_TEST_DATA +*/ + +struct Outer +{ + struct Inner + { + int getX() + { + return x; + } + + int x = 12; + }; + + int getFromInner() + { + return data.getX(); + } + + Inner data; +}; + +int main(int input) +{ + Outer obj; + + return obj.getFromInner(); +} +