From a870a861ca423bb04790916fa1b28dadd61dadd1 Mon Sep 17 00:00:00 2001 From: "Dr. Peter Droste" Date: Fri, 12 Jan 2024 15:59:29 +0100 Subject: [PATCH] Solution for issue #185 --- .../parser/rpp/pp-engine-bits.h | 29 ++++++++++++++----- .../parser/rpp/pp-environment.cpp | 13 +++++---- .../parser/rpp/pp-environment.h | 4 +-- .../parser/rpp/pp-macro-expander.h | 2 +- src/cpp/QtJambiGenerator/targets/all.h | 22 ++++++-------- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/cpp/QtJambiGenerator/parser/rpp/pp-engine-bits.h b/src/cpp/QtJambiGenerator/parser/rpp/pp-engine-bits.h index 809b7ead..2d1d70cc 100644 --- a/src/cpp/QtJambiGenerator/parser/rpp/pp-engine-bits.h +++ b/src/cpp/QtJambiGenerator/parser/rpp/pp-engine-bits.h @@ -645,7 +645,7 @@ namespace rpp { } } - assert(*__first == ')'); + assert(*__first == ')' || *__first == '\\'); ++__first; } @@ -679,11 +679,16 @@ namespace rpp { #else QByteArrayView macroName(macro_name->begin(), macro_name->size()); #endif - if(macroName=="QT_CONFIG"){ - if(definition=="0") - definition = "0"; - else - definition = "1"; + if(macroName.startsWith("QT_FEATURE_")){ + definition = "1"; + }else if(macroName.startsWith("QTJAMBI_FEATURE_")){ + QByteArray feature("QT"); + feature.append(macroName.mid(7)); + pp_fast_string _macro_name(feature.constBegin(), feature.size()); + if(rpp::pp_macro * macro = env.resolve(&_macro_name)){ + env.unbind(macro->name); + macro_name = macro->name; + } }else if(macroName.startsWith("QT_DEPRECATED_VERSION_X")){ definition = "Q_DECL_DEPRECATED_X(text)"; }else if(macroName.startsWith("QT_DEPRECATED_VERSION")){ @@ -842,6 +847,14 @@ namespace rpp { } } }else{ + if(rpp::pp_macro * macro = env.resolve(_M_current_text.c_str(), _M_current_text.size())){ + if(macro->definition && !QLatin1String(macro->definition->begin(), macro->definition->size()).contains(QLatin1String(_M_current_text.c_str(), _M_current_text.size()))){ + std::string previous_text(_M_current_text); + _M_current_text = std::string(macro->definition->begin(), macro->definition->end()); + eval_expression(macro->definition->begin(), macro->definition->end(), result); + _M_current_text = previous_text; + } + } break; } } @@ -1288,9 +1301,9 @@ namespace rpp { std::copy(__first, end_macro_name, __buffer); pp_fast_string const __tmp(__buffer, __size); + bool success = env.unbind(&__tmp); if((verbose & DEBUGLOG_UNDEF) != 0) - std::cout << "#undef " << std::string(__tmp.begin(), __tmp.end()) << std::endl; - env.unbind(&__tmp); + std::cout << "#undef " << std::string(__tmp.begin(), __tmp.end()) << (success ? "" : " failed!!!") << std::endl; __first = end_macro_name; diff --git a/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.cpp b/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.cpp index 00acdf7e..5e1de966 100644 --- a/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.cpp +++ b/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.cpp @@ -55,24 +55,27 @@ void rpp::pp_environment::bind(pp_fast_string const *__name, pp_macro const &__m x__macro.assign(__macro.definition->begin(), __macro.definition->size()); else x__macro = ""; - std::cerr << "** DEFINE " << x__name.assign(__name->begin(), __name->size()) << " " << x__macro << " ** in " << current_file << std::endl; + std::cerr << "** DEFINE " << x__name.assign(__name->begin(), __name->size()) << " " << x__macro << " ** in " << qPrintable(current_file.absoluteFilePath()) << std::endl; #endif } -void rpp::pp_environment::unbind(pp_fast_string const *__name) { +bool rpp::pp_environment::unbind(pp_fast_string const *__name) { + bool result{false}; if (pp_macro *m = resolve(__name)){ m->hidden = true; _M_featureRegistry(std::string(__name->begin()), m->definition ? std::string(m->definition->begin()) : std::string(), current_file, false); + result = true; } #ifdef DEBUG_DEFUNDEF std::string x__name = std::string((const char *)__name); - std::cerr << "** UNDEF " << x__name.assign(__name->begin(), __name->size()) << " ** in " << current_file << std::endl; + std::cerr << "** UNDEF " << x__name.assign(__name->begin(), __name->size()) << " ** in " << qPrintable(current_file.absoluteFilePath()) << std::endl; #endif + return result; } -void rpp::pp_environment::unbind(char const *__s, std::size_t __size) { +bool rpp::pp_environment::unbind(char const *__s, std::size_t __size) { rpp::pp_fast_string __tmp(__s, __size); - unbind(&__tmp); + return unbind(&__tmp); } rpp::pp_macro *rpp::pp_environment::resolve(pp_fast_string const *p_name) const { diff --git a/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.h b/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.h index bcc42944..8320eb34 100644 --- a/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.h +++ b/src/cpp/QtJambiGenerator/parser/rpp/pp-environment.h @@ -87,9 +87,9 @@ namespace rpp { void bind(pp_fast_string const *__name, pp_macro const &__macro); - void unbind(pp_fast_string const *__name); + bool unbind(pp_fast_string const *__name); - void unbind(char const *__s, std::size_t __size); + bool unbind(char const *__s, std::size_t __size); /** * Find corresponding pp_macro from hash table. diff --git a/src/cpp/QtJambiGenerator/parser/rpp/pp-macro-expander.h b/src/cpp/QtJambiGenerator/parser/rpp/pp-macro-expander.h index 8f13d096..e39fd19a 100644 --- a/src/cpp/QtJambiGenerator/parser/rpp/pp-macro-expander.h +++ b/src/cpp/QtJambiGenerator/parser/rpp/pp-macro-expander.h @@ -115,7 +115,7 @@ namespace rpp { first = skip_blanks(++first, last); lines += skip_blanks.lines; - if (first != last && *first == '#') + if (first != last && *first == '#' && !frame) break; } else if (*first == '#') { first = skip_blanks(++first, last); diff --git a/src/cpp/QtJambiGenerator/targets/all.h b/src/cpp/QtJambiGenerator/targets/all.h index b85f8c28..3c038f30 100644 --- a/src/cpp/QtJambiGenerator/targets/all.h +++ b/src/cpp/QtJambiGenerator/targets/all.h @@ -37,7 +37,7 @@ #define QT_KEYPAD_NAVIGATION #define QT_NO_STL -#define Q_BYTE_ORDER Q_BYTE_ORDER +#define Q_BYTE_ORDER 1 //qtjambi preprocessor does not understand properly #define GL_APIENTRY @@ -583,19 +583,17 @@ typedef void (*GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity, #ifndef QTJAMBI_NO_OPENGL -#include -#include - -#undef QT_CONFIG -#define QT_CONFIG(A) 0 -#endif - #ifdef QT_NO_OPENGL #undef QT_NO_OPENGL #define QT_NO_OPENGL_BRIDGE #endif -#include +#include +#include +#include + +#define QTJAMBI_FEATURE_opengles2 -1 + #include #include #include @@ -623,10 +621,8 @@ typedef void (*GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity, #include #include -#undef QT_CONFIG -#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1) - -#include +#undef QT_FEATURE_opengles2 +#define QT_FEATURE_opengles2 1 #ifdef QT_NO_OPENGL_BRIDGE #undef QT_NO_OPENGL_BRIDGE