diff --git a/crypto/func/func.cpp b/crypto/func/func.cpp index 416376b8..7847184f 100644 --- a/crypto/func/func.cpp +++ b/crypto/func/func.cpp @@ -77,6 +77,37 @@ bool SymValCodeFunc::does_need_codegen() const { // in the future, we may want to implement a true AST inlining for `inline` functions also } +void GlobalPragma::enable(SrcLocation loc) { + if (deprecated_from_v_) { + loc.show_warning(PSTRING() << "#pragma " << name_ << + " is deprecated since FunC v" << deprecated_from_v_ << + ". Please, remove this line from your code."); + return; + } + + enabled_ = true; + locs_.push_back(std::move(loc)); +} + +void GlobalPragma::check_enable_in_libs() { + if (locs_.empty()) { + return; + } + for (const SrcLocation& loc : locs_) { + if (loc.fdescr->is_main) { + return; + } + } + locs_[0].show_warning(PSTRING() << "#pragma " << name_ + << " is enabled in included libraries, it may change the behavior of your code. " + << "Add this #pragma to the main source file to suppress this warning."); +} + +void GlobalPragma::always_on_and_deprecated(const char *deprecated_from_v) { + deprecated_from_v_ = deprecated_from_v; + enabled_ = true; +} + td::Result fs_read_callback(ReadCallback::Kind kind, const char* query) { switch (kind) { case ReadCallback::Kind::ReadFile: { diff --git a/crypto/func/func.h b/crypto/func/func.h index 07737cb9..14064189 100644 --- a/crypto/func/func.h +++ b/crypto/func/func.h @@ -1769,27 +1769,14 @@ class GlobalPragma { bool enabled() const { return enabled_; } - void enable(SrcLocation loc) { - enabled_ = true; - locs_.push_back(std::move(loc)); - } - void check_enable_in_libs() { - if (locs_.empty()) { - return; - } - for (const SrcLocation& loc : locs_) { - if (loc.fdescr->is_main) { - return; - } - } - locs_[0].show_warning(PSTRING() << "#pragma " << name_ - << " is enabled in included libraries, it may change the behavior of your code. " - << "Add this #pragma to the main source file to suppress this warning."); - } + void enable(SrcLocation loc); + void check_enable_in_libs(); + void always_on_and_deprecated(const char *deprecated_from_v); private: std::string name_; bool enabled_ = false; + const char *deprecated_from_v_ = nullptr; std::vector locs_; }; extern GlobalPragma pragma_allow_post_modification, pragma_compute_asm_ltr, pragma_remove_unused_functions;