diff --git a/libabckit/include/libabckit/c/declarations.h b/libabckit/include/libabckit/c/declarations.h index cdb47a6affd4a1b95e0c3983b22e89d3d53a192e..71ae126d75739b5b213b9170327dbdee8bd8e156 100644 --- a/libabckit/include/libabckit/c/declarations.h +++ b/libabckit/include/libabckit/c/declarations.h @@ -58,6 +58,8 @@ struct AbckitCoreClassField; struct AbckitCoreInterfaceField; struct AbckitCoreEnumField; struct AbckitCoreFunctionParam; +struct AbckitCoreInterface; +struct AbckitCoreInterfaceField; struct AbckitArktsModule; struct AbckitArktsNamespace; @@ -76,6 +78,7 @@ struct AbckitArktsAnnotationInterface; struct AbckitArktsAnnotationInterfaceField; struct AbckitArktsImportDescriptor; struct AbckitArktsExportDescriptor; +struct AbckitArktsInterface; struct AbckitJsModule; struct AbckitJsClass; diff --git a/libabckit/include/libabckit/c/extensions/arkts/metadata_arkts.h b/libabckit/include/libabckit/c/extensions/arkts/metadata_arkts.h index 75ae09989ed57b09b772dc1bb771b3ace296e632..14d130bbc0e5d55fd8df55627e7341942797f0fc 100644 --- a/libabckit/include/libabckit/c/extensions/arkts/metadata_arkts.h +++ b/libabckit/include/libabckit/c/extensions/arkts/metadata_arkts.h @@ -971,7 +971,7 @@ struct CAPI_EXPORT AbckitArktsModifyApi { * @param [ in ] name - Name of the interface to be created. * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `name` is NULL. */ - AbckitArktsInterface *(*createInterface)(const char *name); + AbckitArktsInterface *(*createInterface)(const char *name, AbckitArktsModule *owningModule); /* ======================================== * Module Field diff --git a/libabckit/include/libabckit/cpp/abckit_cpp.h b/libabckit/include/libabckit/cpp/abckit_cpp.h index b1a01274b8c327ffedcb7e58c4ae6cc288d6fdf8..de8876659df2103e5e23b5e50859e0e7e46d66ad 100644 --- a/libabckit/include/libabckit/cpp/abckit_cpp.h +++ b/libabckit/include/libabckit/cpp/abckit_cpp.h @@ -1,17 +1,17 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #ifndef CPP_ABCKIT_H #define CPP_ABCKIT_H @@ -40,6 +40,7 @@ #include "./headers/core/import_descriptor.h" #include "./headers/core/module.h" #include "./headers/core/namespace.h" +#include "./headers/core/interface.h" #include "./headers/arkts/annotation_element.h" #include "./headers/arkts/annotation_interface_field.h" @@ -51,6 +52,7 @@ #include "./headers/arkts/import_descriptor.h" #include "./headers/arkts/module.h" #include "./headers/arkts/namespace.h" +#include "./headers/arkts/interface.h" #include "./headers/js/export_descriptor.h" #include "./headers/js/import_descriptor.h" @@ -67,6 +69,7 @@ #include "./headers/core/function_impl.h" #include "./headers/core/export_descriptor_impl.h" #include "./headers/core/import_descriptor_impl.h" +#include "./headers/core/interface_impl.h" #include "./headers/arkts/annotation_interface_field_impl.h" #include "./headers/arkts/annotation_interface_impl.h" @@ -78,6 +81,7 @@ #include "./headers/arkts/export_descriptor_impl.h" #include "./headers/arkts/import_descriptor_impl.h" #include "./headers/arkts/namespace_impl.h" +#include "./headers/arkts/interface_impl.h" #include "./headers/js/export_descriptor_impl.h" #include "./headers/js/import_descriptor_impl.h" diff --git a/libabckit/include/libabckit/cpp/headers/arkts/interface.h b/libabckit/include/libabckit/cpp/headers/arkts/interface.h new file mode 100644 index 0000000000000000000000000000000000000000..a577942b468e907d42a809e00ba565fc74ffd284 --- /dev/null +++ b/libabckit/include/libabckit/cpp/headers/arkts/interface.h @@ -0,0 +1,179 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef CPP_ABCKIT_ARKTS_INTERFACE_H +#define CPP_ABCKIT_ARKTS_INTERFACE_H + +#include "../core/interface.h" +#include "../core/field.h" +#include "../core/annotation.h" +#include "../core/module.h" +#include "../base_concepts.h" +#include "./function.h" +#include "./module.h" +#include "../config.h" + +#include + +namespace abckit::arkts { + +/** +* @brief ArkTS Interface +*/ +class Interface final : public core::Interface { + // To access private constructor. + friend class abckit::File; + friend class arkts::Function; + friend class arkts::Annotation; + friend class arkts::Module; + friend class abckit::DefaultHash; + friend class abckit::traits::TargetCheckCast; + + +public: + /** + * @brief Constructor Arkts API Interface from the Core API with compatibility check + * @param coreOther - Core API Interface + */ + explicit Interface(const core::Interface &coreOther); + + /** + * @brief Construct a new Interface object + * @param other + */ + Interface(const Interface &other) = default; + + /** + * @brief Constructor + * @param other + * @return Interface& + */ + Interface &operator=(const Interface &other) = default; + + /** + * @brief Construct a new Interface object + * @param other + */ + Interface(Interface &&other) = default; + + /** + * @brief Constructor + * @param other + * @return Interface& + */ + Interface &operator=(Interface &&other) = default; + + /** + * @brief Destroy the Interface object + */ + ~Interface() override = default; + + /** + * @brief Get Interface file + * @return File + */ + const File *GetFile() const; + + /** + * @brief Get Interface name + * @return std::string + */ + std::string GetName() const; + + /** + * @brief Returns module for this Interface. + * @return Owning core::Module. + */ + core::Module GetModule() const; + + /** + * @brief Add a super interface to this interface. + * @param superInterface The super interface to add. + * @return true if added successfully, false otherwise. + */ + bool AddSuperInterface(const Interface &superInterface) const; + + /** + * @brief Remove a super interface from this interface. + * @param superInterface The super interface to remove. + * @return true if removed successfully, false otherwise. + */ + bool RemoveSuperInterface(const Interface &superInterface) const; + + /** + * @brief Set the name of the interface. + * @param name The new name. + * @return true if set successfully, false otherwise. + */ + bool SetName(std::string_view name) const; + + /** + * @brief Add a method to this interface. + * @param method The method to add. + * @return true if added successfully, false otherwise. + */ + bool AddMethod(const Function &method) const; + + /** + * @brief Remove a method from this interface. + * @param method The method to remove. + * @return true if removed successfully, false otherwise. + */ + bool RemoveMethod(const Function &method) const; + + /** + * @brief Set owning module for this interface + * @param owningModule The owning module to set. + * @return true if set successfully, false otherwise. + */ + bool SetOwningModule(const Module &owningModule) const; + + /** + * @brief Set parent function for this interface + * @param function The parent function to set. + * @return true if set successfully, false otherwise. + */ + bool SetParentFunction(const Function &function) const; + + /** + * @brief Create an interface + * @param name name for this interface. + * @param owningModule The module to own this interface. + * @return Newly created Interface. + */ + static Interface Create(std::string_view name, const Module &owningModule); + +private: + Interface(AbckitArktsInterface *iface, const ApiConfig *conf, const File *file) + : core::Interface(reinterpret_cast(iface), conf, file) + { + SetResource(file); + } + // Optionally, add ArkTS-specific members here + +protected: + /** + * @brief Get the Api Config object + * @return const ApiConfig* + */ + const ApiConfig *GetApiConfig() const override + { + return core::Interface::GetApiConfig(); + } +}; + +} // namespace abckit::arkts + +#endif // CPP_ABCKIT_ARKTS_INTERFACE_H \ No newline at end of file diff --git a/libabckit/include/libabckit/cpp/headers/arkts/interface_impl.h b/libabckit/include/libabckit/cpp/headers/arkts/interface_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..61d55f933b93c4bfcb2554db03e7ac8c2b3f565f --- /dev/null +++ b/libabckit/include/libabckit/cpp/headers/arkts/interface_impl.h @@ -0,0 +1,134 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef CPP_ABCKIT_ARKTS_INTERFACE_IMPL_H +#define CPP_ABCKIT_ARKTS_INTERFACE_IMPL_H + +#include "./interface.h" +#include "./module.h" +#include "../config.h" + +namespace abckit::arkts { + +inline const File *Interface::GetFile() const +{ + const ApiConfig *conf = GetApiConfig(); + AbckitFile *file = conf->cIapi_->interfaceGetFile(GetView()); + CheckError(conf); + return reinterpret_cast(file); +} + +inline std::string Interface::GetName() const +{ + const ApiConfig *conf = GetApiConfig(); + AbckitString *cString = conf->cIapi_->interfaceGetName(GetView()); + CheckError(conf); + std::string str = conf->cIapi_->abckitStringToString(cString); + CheckError(conf); + return str; +} + +inline core::Module Interface::GetModule() const +{ + const ApiConfig *conf = GetApiConfig(); + AbckitArktsModule *module = reinterpret_cast( + conf->cIapi_->interfaceGetModule(GetView())); + CheckError(conf); + return core::Module(reinterpret_cast(module), conf, GetResource()); +} + +inline bool Interface::AddSuperInterface(const Interface &superInterface) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceAddSuperInterface( + reinterpret_cast(GetView()), + reinterpret_cast(superInterface.GetView())); + CheckError(conf); + return result; +} + +inline bool Interface::RemoveSuperInterface(const Interface &superInterface) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceRemoveSuperInterface( + reinterpret_cast(GetView()), + reinterpret_cast(superInterface.GetView())); + CheckError(conf); + return result; +} + +inline bool Interface::SetName(std::string_view name) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceSetName( + reinterpret_cast(GetView()), + std::string(name).c_str()); + CheckError(conf); + return result; +} + +inline bool Interface::AddMethod(const Function &method) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceAddMethod( + reinterpret_cast(GetView()), + reinterpret_cast(method.GetView())); + CheckError(conf); + return result; +} + +inline bool Interface::RemoveMethod(const Function &method) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceRemoveMethod( + reinterpret_cast(GetView()), + reinterpret_cast(method.GetView())); + CheckError(conf); + return result; +} + +inline bool Interface::SetOwningModule(const Module &owningModule) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceSetOwningModule( + reinterpret_cast(GetView()), + reinterpret_cast(owningModule.GetView())); + CheckError(conf); + return result; +} + +inline bool Interface::SetParentFunction(const Function &function) const +{ + const ApiConfig *conf = GetApiConfig(); + bool result = conf->cArktsMapi_->interfaceSetParentFunction( + reinterpret_cast(GetView()), + reinterpret_cast(function.GetView())); + CheckError(conf); + return result; +} + +inline Interface Interface::Create(std::string_view name, const Module &owningModule) +{ + const ApiConfig *conf = owningModule.GetApiConfig(); + AbckitArktsInterface *iface = conf->cArktsMapi_->createInterface( + std::string(name).c_str(), + reinterpret_cast(owningModule.GetView())); + CheckError(conf); + return Interface(iface, conf, owningModule.GetResource()); +} + +} // namespace abckit::arkts + +#endif // CPP_ABCKIT_ARKTS_INTERFACE_IMPL_H \ No newline at end of file diff --git a/libabckit/include/libabckit/cpp/headers/config.h b/libabckit/include/libabckit/cpp/headers/config.h index e1fbc72995fc1e56de14724ed54de2726ad33b8b..61499ea4b578fc7618d004ff4394c31f4ab27d7f 100644 --- a/libabckit/include/libabckit/cpp/headers/config.h +++ b/libabckit/include/libabckit/cpp/headers/config.h @@ -53,6 +53,8 @@ class AnnotationElement; class AnnotationInterfaceField; class ImportDescriptor; class ExportDescriptor; +class Interface; +class InterfaceField; } // namespace core namespace arkts { @@ -66,6 +68,7 @@ class AnnotationElement; class AnnotationInterfaceField; class ImportDescriptor; class ExportDescriptor; +class Interface; } // namespace arkts namespace js { @@ -114,6 +117,8 @@ class ApiConfig final { friend core::ImportDescriptor; /// \relates abckit::core::ExportDescriptor friend core::ExportDescriptor; + /// \relates abckit::core::Interface + friend core::Interface; /// \relates abckit::arkts::Module friend arkts::Module; @@ -135,6 +140,8 @@ class ApiConfig final { friend arkts::ImportDescriptor; /// \relates abckit::arkts::ExportDescriptor friend arkts::ExportDescriptor; + /// \relates abckit::arkts::Interface + friend arkts::Interface; /// \relates abckit::js::Module friend js::Module; diff --git a/libabckit/include/libabckit/cpp/headers/core/annotation.h b/libabckit/include/libabckit/cpp/headers/core/annotation.h index 93584b0c49f84ad06aaf60ea8c6522bccb2ad761..241fb7add852094f7200861bbeb294fb0cdbe04b 100644 --- a/libabckit/include/libabckit/cpp/headers/core/annotation.h +++ b/libabckit/include/libabckit/cpp/headers/core/annotation.h @@ -35,6 +35,8 @@ class Annotation : public ViewInResource { friend class arkts::Function; /// @brief core::Class friend class core::Class; + /// @brief core::Interface + friend class core::Interface; /// @brief arkts::Class friend class arkts::Class; /// @brief arkts::Function diff --git a/libabckit/include/libabckit/cpp/headers/core/field.h b/libabckit/include/libabckit/cpp/headers/core/field.h index 074241513eefe7f310014b65daa615a4f0a662a0..767265af7cbb00d9ebbd297f647540815dfdcbca 100644 --- a/libabckit/include/libabckit/cpp/headers/core/field.h +++ b/libabckit/include/libabckit/cpp/headers/core/field.h @@ -151,6 +151,8 @@ class InterfaceField : public View { // We restrict constructors in order to prevent C/C++ API mix-up by user. /// @brief abckit::DefaultHash friend class abckit::DefaultHash; + /// @brief to access private constructor + friend class abckit::core::Interface; protected: /// @brief Core API View type diff --git a/libabckit/include/libabckit/cpp/headers/core/function.h b/libabckit/include/libabckit/cpp/headers/core/function.h index 2cf57846f8ad0918be2a353a4a8ea3680a8dd588..dca14b039409c203eb49cccb7f0f772aec5a0d46 100644 --- a/libabckit/include/libabckit/cpp/headers/core/function.h +++ b/libabckit/include/libabckit/cpp/headers/core/function.h @@ -37,6 +37,8 @@ class Function : public ViewInResource { /// @brief to access private constructor friend class core::Module; /// @brief to access private constructor + friend class core::Interface; + /// @brief to access private constructor friend class abckit::Instruction; /// @brief abckit::DefaultHash friend class abckit::DefaultHash; @@ -46,6 +48,8 @@ class Function : public ViewInResource { friend class abckit::File; /// @brief to access private constructor friend class arkts::Namespace; + /// @brief to access private constructor + friend class arkts::Interface; protected: /// @brief Core API View type diff --git a/libabckit/include/libabckit/cpp/headers/core/interface.h b/libabckit/include/libabckit/cpp/headers/core/interface.h new file mode 100644 index 0000000000000000000000000000000000000000..75ec5f6ab544f7789f234d5757d4152b88aa7974 --- /dev/null +++ b/libabckit/include/libabckit/cpp/headers/core/interface.h @@ -0,0 +1,149 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef CPP_ABCKIT_CORE_INTERFACE_H +#define CPP_ABCKIT_CORE_INTERFACE_H + +#include "../base_classes.h" +#include "./field.h" + + +#include +#include + +namespace abckit::core { + +/** +* @brief Interface +*/ +class Interface : public ViewInResource { + /// @brief to access private constructor + friend class core::Class; + /// @brief to access private constructor + friend class core::Namespace; + /// @brief to access private constructor + friend class core::Module; + /// @brief to access private constructor + friend class core::Annotation; + /// @brief to access private constructor + friend class core::Function; + /// @brief abckit::Interface + friend class arkts::Interface; + /// @brief abckit::DefaultHash + friend class abckit::DefaultHash; + +protected: + /// @brief Core API View type + using CoreViewT = Interface; + +public: + /** + * @brief Construct a new Interface object + * @param other + */ + Interface(const Interface &other) = default; // CC-OFF(G.CLS.07): design decision + + /** + * @brief Constructor + * @param other + * @return Interface& + */ + Interface &operator=(const Interface &other) = default; + + /** + * @brief Construct a new Interface object + * @param other + */ + Interface(Interface &&other) = default; // CC-OFF(G.CLS.07): design decision + + /** + * @brief Constructor + * @param other + * @return Interface& + */ + Interface &operator=(Interface &&other) = default; + + /** + * @brief Destroy the Interface object + */ + ~Interface() override = default; + + /** + * @brief Convert an ArktsInterface to CoreInterface. + * @param iface The ArktsInterface to convert. + * @return The converted CoreInterface, or nullptr if conversion failed. + */ + AbckitCoreInterface* ArktsInterfaceToCoreInterface(AbckitArktsInterface *iface) const; + + /** + * @brief Convert a CoreInterface to ArktsInterface. + * @param iface The CoreInterface to convert. + * @return The converted ArktsInterface, or nullptr if conversion failed. + */ + AbckitArktsInterface* CoreInterfaceToArktsInterface(AbckitCoreInterface *iface) const; + + /** + * @brief Enumerates super interfaces of this Interface, invoking callback `cb` for each super interface. + * The return value of `cb` is used as a signal to continue (true) or early-exit (false) enumeration. + * @param cb Callback that will be invoked. + * @return `false` if was early exited. Otherwise - `true`. + */ + bool EnumerateSuperInterfaces(const std::function &cb) const; + + /** + * @brief Enumerates methods of this Interface, invoking callback `cb` for each method. + * The return value of `cb` is used as a signal to continue (true) or early-exit (false) enumeration. + * @param cb Callback that will be invoked. + * @return `false` if was early exited. Otherwise - `true`. + */ + bool EnumerateMethods(const std::function &cb) const; + + /** + * @brief Enumerates annotations of this Interface, invoking callback `cb` for each annotation. + * The return value of `cb` is used as a signal to continue (true) or early-exit (false) enumeration. + * @param cb Callback that will be invoked. + * @return `false` if was early exited. Otherwise - `true`. + */ + bool EnumerateAnnotations(const std::function &cb) const; + + /** + * @brief Enumerates fields of this Interface, invoking callback `cb` for each field. + * The return value of `cb` is used as a signal to continue (true) or early-exit (false) enumeration. + * @param cb Callback that will be invoked. + * @return `false` if was early exited. Otherwise - `true`. + */ + bool EnumerateFields(const std::function &cb) const; +private: + + Interface(AbckitCoreInterface *iface, const ApiConfig *conf, const File *file) + : ViewInResource(iface), conf_(conf) + { + SetResource(file); + } + const ApiConfig *conf_; +protected: + /** + * @brief Get the Api Config object + * @return const ApiConfig* + */ + const ApiConfig *GetApiConfig() const override + { + return conf_; + } +}; + +} // namespace abckit::core + +#endif // CPP_ABCKIT_CORE_INTERFACE_H \ No newline at end of file diff --git a/libabckit/include/libabckit/cpp/headers/core/interface_impl.h b/libabckit/include/libabckit/cpp/headers/core/interface_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..8e1aadc660464cbb02c0d1a85045a0faef974780 --- /dev/null +++ b/libabckit/include/libabckit/cpp/headers/core/interface_impl.h @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef CPP_ABCKIT_CORE_INTERFACE_IMPL_H +#define CPP_ABCKIT_CORE_INTERFACE_IMPL_H + +#include "./interface.h" +#include "./module.h" +#include "../config.h" + +namespace abckit::core { + +inline bool Interface::EnumerateSuperInterfaces(const std::function &cb) const +{ + Payload &> payload {cb, GetApiConfig(), GetResource()}; + + bool isNormalExit = GetApiConfig()->cIapi_->interfaceEnumerateSuperInterfaces( + GetView(), &payload, [](AbckitCoreInterface *superIface, void *data) { + const auto &payload = *static_cast &> *>(data); + return payload.data(core::Interface(superIface, payload.config, payload.resource)); + }); + CheckError(GetApiConfig()); + return isNormalExit; +} + +inline bool Interface::EnumerateMethods(const std::function &cb) const +{ + Payload &> payload {cb, GetApiConfig(), GetResource()}; + + bool isNormalExit = GetApiConfig()->cIapi_->interfaceEnumerateMethods( + GetView(), &payload, [](AbckitCoreFunction *func, void *data) { + const auto &payload = *static_cast &> *>(data); + return payload.data(core::Function(func, payload.config, payload.resource)); + }); + CheckError(GetApiConfig()); + return isNormalExit; +} + +inline bool Interface::EnumerateAnnotations(const std::function &cb) const +{ + Payload &> payload {cb, GetApiConfig(), GetResource()}; + + bool isNormalExit = GetApiConfig()->cIapi_->interfaceEnumerateAnnotations( + GetView(), &payload, [](AbckitCoreAnnotation *anno, void *data) { + const auto &payload = *static_cast &> *>(data); + return payload.data(core::Annotation(anno, payload.config, payload.resource)); + }); + CheckError(GetApiConfig()); + return isNormalExit; +} + +inline bool Interface::EnumerateFields(const std::function &cb) const +{ + Payload &> payload {cb, GetApiConfig(), GetResource()}; + + bool isNormalExit = GetApiConfig()->cIapi_->interfaceEnumerateFields( + GetView(), &payload, [](AbckitCoreInterfaceField *field, void *data) { + const auto &payload = *static_cast &> *>(data); + return payload.data(core::InterfaceField(field, payload.config)); + }); + CheckError(GetApiConfig()); + return isNormalExit; +} + +} // namespace abckit::core + +#endif // CPP_ABCKIT_CORE_INTERFACE_IMPL_H \ No newline at end of file diff --git a/libabckit/include/libabckit/cpp/headers/core/module.h b/libabckit/include/libabckit/cpp/headers/core/module.h index 0d44c74e1dd0d47a38dbe6bf0d83544a4748999d..ad517c0f6f3d981fd930638372fecd4b84babc91 100644 --- a/libabckit/include/libabckit/cpp/headers/core/module.h +++ b/libabckit/include/libabckit/cpp/headers/core/module.h @@ -21,6 +21,7 @@ #include "./export_descriptor.h" #include "./namespace.h" #include "./annotation_interface.h" +#include "./interface.h" namespace abckit::core { @@ -43,6 +44,10 @@ class Module : public ViewInResource { friend class core::Class; /// @brief to access private constructor friend class core::Function; + /// @brief to access private constructor + friend class core::Interface; + /// @brief to access private constructor + friend class arkts::Interface; /// @brief abckit::DefaultHash friend class abckit::DefaultHash; /// @brief abckit::DynamicIsa @@ -226,6 +231,16 @@ public: */ bool EnumerateAnnotationInterfaces(const std::function &cb) const; + /** + * @brief Enumerates interfaces of the Module, invoking callback `cb` for each interface. + * @return `false` if was early exited. Otherwise - `true`. + * @param [ in ] cb - Callback that will be invoked. Should return `false` on early exit and `true` when iterations + * should continue. + * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. + * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if 'cb' is false. + */ + bool EnumerateInterfaces(const std::function &cb) const; + private: bool GetClassesInner(std::vector &classes) const; diff --git a/libabckit/include/libabckit/cpp/headers/core/module_impl.h b/libabckit/include/libabckit/cpp/headers/core/module_impl.h index a4bb1f2c782f8573b1a32ccc0403ae2c811c247c..944eb766e03d1f12244ae46400428a5ed74fa9d5 100644 --- a/libabckit/include/libabckit/cpp/headers/core/module_impl.h +++ b/libabckit/include/libabckit/cpp/headers/core/module_impl.h @@ -291,6 +291,19 @@ inline bool Module::EnumerateAnnotationInterfaces(const std::function &cb) const +{ + Payload &> payload {cb, GetApiConfig(), GetResource()}; + + auto isNormalExit = + GetApiConfig()->cIapi_->moduleEnumerateInterfaces(GetView(), &payload, [](AbckitCoreInterface *iface, void *data) { + const auto &payload = *static_cast &> *>(data); + return payload.data(core::Interface(iface, payload.config, payload.resource)); + }); + CheckError(GetApiConfig()); + return isNormalExit; +} + } // namespace abckit::core #endif // CPP_ABCKIT_CORE_MODULE_IMPL_H diff --git a/libabckit/src/adapter_static/metadata_modify_static.cpp b/libabckit/src/adapter_static/metadata_modify_static.cpp index 58f4070a070212b0abf4ca19c4166500911171a2..7d12c4231ca1ff21ca0f5a257ce19cf55107832b 100644 --- a/libabckit/src/adapter_static/metadata_modify_static.cpp +++ b/libabckit/src/adapter_static/metadata_modify_static.cpp @@ -36,6 +36,9 @@ #include "static_core/compiler/optimizer/optimizations/move_constants.h" #include "static_core/compiler/optimizer/optimizations/lowering.h" #include "static_core/bytecode_optimizer/reg_encoder.h" +#include "static_core/abc2program/abc2program_driver.h" +#include "static_core/abc2program/abc_file_entity_processor.h" +#include "static_core/assembler/assembly-emitter.h" #include #include @@ -44,6 +47,18 @@ // NOLINTNEXTLINE(google-build-using-namespace) using namespace ark; +class AbcFileEntityProcessorBridge : public ark::abc2program::AbcFileEntityProcessor { +public: + using ark::abc2program::AbcFileEntityProcessor::AbcFileEntityProcessor; + + template + static void CallSetEntityAttributeValue(T &entity, const std::function &shouldSet, + std::string_view attribute, const char *value) + { + SetEntityAttributeValue(entity, shouldSet, attribute, value); + } +}; + namespace libabckit { // ======================================== @@ -278,4 +293,18 @@ AbckitValue *FindOrCreateValueStringStatic(AbckitFile *file, const char *value, return FindOrCreateValueStringStaticImpl(file, std::string(value, len)); } +ark::pandasm::Record *SetRecordAttributeValue() +{ + auto record = std::make_unique( + "Iface", ark::panda_file::SourceLang::ETS + ); + AbcFileEntityProcessorBridge::CallSetEntityAttributeValue( + *record, + []() { return true; }, + "access.record", + "public" + ); + return record.release(); +} + } // namespace libabckit diff --git a/libabckit/src/adapter_static/metadata_modify_static.h b/libabckit/src/adapter_static/metadata_modify_static.h index 6692f314723e7bf3e82c35cc0416fbd3d070bc57..65126addca2fc17a5c6fdca23a68986c0f12bc72 100644 --- a/libabckit/src/adapter_static/metadata_modify_static.h +++ b/libabckit/src/adapter_static/metadata_modify_static.h @@ -47,4 +47,10 @@ AbckitValue *FindOrCreateValueDoubleStatic(AbckitFile *file, double value); AbckitValue *FindOrCreateValueStringStatic(AbckitFile *file, const char *value, size_t len); } // namespace libabckit +namespace ark { namespace pandasm { struct Record; } } +namespace libabckit { +ark::pandasm::Record* SetRecordAttributeValue(); +} + + #endif diff --git a/libabckit/src/helpers_common.cpp b/libabckit/src/helpers_common.cpp index db817bc2e0b6a02c53c635641708293f360999b3..4596feb5e0ab6c7cd2fac9c8ab13701300e08056 100644 --- a/libabckit/src/helpers_common.cpp +++ b/libabckit/src/helpers_common.cpp @@ -56,6 +56,20 @@ bool ModuleEnumerateAnnotationInterfacesHelper(AbckitCoreModule *m, void *data, return true; } +bool ModuleEnumerateInterfacesHelper(AbckitCoreModule *m, void *data, + bool (*cb)(AbckitCoreInterface *iface, void *data)) +{ + LIBABCKIT_LOG_FUNC; + LIBABCKIT_BAD_ARGUMENT(m, false) + LIBABCKIT_BAD_ARGUMENT(cb, false) + for (auto &iface : m->interfaces) { + if (!cb(iface.get(), data)) { + return false; + } + } + return true; +} + bool ClassEnumerateMethodsHelper(AbckitCoreClass *klass, void *data, bool (*cb)(AbckitCoreFunction *method, void *data)) { LIBABCKIT_LOG_FUNC; diff --git a/libabckit/src/helpers_common.h b/libabckit/src/helpers_common.h index efe73e6acc4a531b79dca935fdecfbbfac352cfe..4792f8a5c8b2f86d83520ff97977385021f8d1e4 100644 --- a/libabckit/src/helpers_common.h +++ b/libabckit/src/helpers_common.h @@ -25,7 +25,8 @@ bool ModuleEnumerateTopLevelFunctionsHelper(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreFunction *function, void *data)); bool ModuleEnumerateAnnotationInterfacesHelper(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreAnnotationInterface *ai, void *data)); - +bool ModuleEnumerateInterfacesHelper(AbckitCoreModule *m, void *data, + bool (*cb)(AbckitCoreInterface *iface, void *data)); bool ClassEnumerateMethodsHelper(AbckitCoreClass *klass, void *data, bool (*cb)(AbckitCoreFunction *method, void *data)); diff --git a/libabckit/src/metadata_arkts_inspect_impl.cpp b/libabckit/src/metadata_arkts_inspect_impl.cpp index 47ac707460d631884a3a626fac9b61e9735145bf..5f43185209f40fd20d3eb2c56e04bb2a7d8eb5e4 100644 --- a/libabckit/src/metadata_arkts_inspect_impl.cpp +++ b/libabckit/src/metadata_arkts_inspect_impl.cpp @@ -179,16 +179,19 @@ extern "C" bool ArktsClassIsAbstract(AbckitArktsClass *klass) extern "C" AbckitCoreInterface *ArktsInterfaceToCoreInterface(AbckitArktsInterface *iface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - return nullptr; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + LIBABCKIT_BAD_ARGUMENT(iface, nullptr); + return iface->core; } extern "C" AbckitArktsInterface *CoreInterfaceToArktsInterface(AbckitCoreInterface *iface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - return nullptr; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + LIBABCKIT_BAD_ARGUMENT(iface, nullptr); + LIBABCKIT_CHECK_ARKTS_TARGET(iface->owningModule); + return iface->GetArkTSImpl(); } /* ======================================== @@ -660,6 +663,12 @@ bool ArkTSModuleEnumerateAnnotationInterfaces(AbckitCoreModule *m, void *data, return ModuleEnumerateAnnotationInterfacesHelper(m, data, cb); } +bool ArkTSModuleEnumerateInterfaces(AbckitCoreModule *m, void *data, + bool (*cb)(AbckitCoreInterface *iface, void *data)) +{ + return ModuleEnumerateInterfacesHelper(m, data, cb); +} + // ======================================== // Module // ======================================== diff --git a/libabckit/src/metadata_arkts_inspect_impl.h b/libabckit/src/metadata_arkts_inspect_impl.h index 3f711629db0f038dde482b3f1945177fac4fe06d..173656ab6c74ab4737355dc7a6c21c5393d410d0 100644 --- a/libabckit/src/metadata_arkts_inspect_impl.h +++ b/libabckit/src/metadata_arkts_inspect_impl.h @@ -36,6 +36,8 @@ bool ArkTSModuleEnumerateAnonymousFunctions(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreFunction *function, void *data)); bool ArkTSModuleEnumerateAnnotationInterfaces(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreAnnotationInterface *ai, void *data)); +bool ArkTSModuleEnumerateInterfaces(AbckitCoreModule *m, void *data, + bool (*cb)(AbckitCoreInterface *iface, void *data)); // ======================================== // Namespace diff --git a/libabckit/src/metadata_arkts_modify_impl.cpp b/libabckit/src/metadata_arkts_modify_impl.cpp index b3ab8c53298c9b8d088924be4efa4d130aac2fda..b181216d3528552f1f6b911707ef06356f0cfaf6 100644 --- a/libabckit/src/metadata_arkts_modify_impl.cpp +++ b/libabckit/src/metadata_arkts_modify_impl.cpp @@ -376,26 +376,65 @@ extern "C" bool ClassSetParentFunction(AbckitArktsClass *klass, AbckitArktsFunct extern "C" bool InterfaceAddSuperInterface(AbckitArktsInterface *iface, AbckitArktsInterface *superIface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)superIface; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, false); + LIBABCKIT_BAD_ARGUMENT(superIface, false); + + // Check if the target is unsupported + if (iface->core->owningModule->target != ABCKIT_TARGET_ARK_TS_V2) { + statuses::SetLastError(ABCKIT_STATUS_UNSUPPORTED); + return false; + } + + std::unique_ptr superIf_ptr(superIface->core); + + iface->core->superinterfaces.emplace_back(std::move(superIf_ptr)); + return true; } extern "C" bool InterfaceRemoveSuperInterface(AbckitArktsInterface *iface, AbckitArktsInterface *superIface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)superIface; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, false); + LIBABCKIT_BAD_ARGUMENT(superIface, false); + + // Check if the target is unsupported + if (iface->core->owningModule->target != ABCKIT_TARGET_ARK_TS_V2) { + statuses::SetLastError(ABCKIT_STATUS_UNSUPPORTED); + return false; + } + + // Remove the super interface from the current interface + auto superIt = std::find_if( + iface->core->superinterfaces.begin(), iface->core->superinterfaces.end(), + [superIface](const auto& ptr) { + return ptr.get() == superIface->core; + }); + if (superIt != iface->core->superinterfaces.end()) { + iface->core->superinterfaces.erase(superIt); + } + + return true; } extern "C" bool InterfaceSetName(AbckitArktsInterface *iface, const char *name) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)name; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + if (iface == nullptr || name == nullptr) { + statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); + return false; + } + if (iface->core->owningModule->target != ABCKIT_TARGET_ARK_TS_V2) { + statuses::SetLastError(ABCKIT_STATUS_UNSUPPORTED); + return false; + } + iface->core->name = new AbckitString{std::string_view(name)}; + return true; } extern "C" bool InterfaceAddField(AbckitArktsInterface *iface, AbckitArktsInterfaceField *field) @@ -416,43 +455,115 @@ extern "C" bool InterfaceRemoveField(AbckitArktsInterface *iface, AbckitArktsInt extern "C" bool InterfaceAddMethod(AbckitArktsInterface *iface, AbckitArktsFunction *method) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)method; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + LIBABCKIT_BAD_ARGUMENT(iface, false); + LIBABCKIT_BAD_ARGUMENT(method, false); + + if (iface == nullptr || method == nullptr) { + libabckit::statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); + return false; + } + + std::unique_ptr method_ptr(method->core); + iface->core->methods.emplace_back(std::move(method_ptr)); + + return true; } extern "C" bool InterfaceRemoveMethod(AbckitArktsInterface *iface, AbckitArktsFunction *method) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)method; - return false; + if (iface == nullptr || method == nullptr) { + libabckit::statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); + return false; + } + + auto &methods = iface->core->methods; + auto it = std::find_if(methods.begin(), methods.end(), + [method](const auto& ptr) { + return ptr.get() == method->core; + }); + if (it == methods.end()) { + return false; + } + methods.erase(it); + + libabckit::statuses::SetLastError(ABCKIT_STATUS_NO_ERROR); + + return true; } -extern "C" bool InterfaceSetOwningModule(AbckitArktsInterface *iface, AbckitArktsModule *module) +extern "C" bool InterfaceSetOwningModule(AbckitArktsInterface *iface, AbckitArktsModule *owningModule) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)module; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + if (iface == nullptr || owningModule == nullptr) { + statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); + return false; + } + if (iface->core->owningModule->target != ABCKIT_TARGET_ARK_TS_V2) { + statuses::SetLastError(ABCKIT_STATUS_UNSUPPORTED); + return false; + } + iface->core->owningModule = owningModule->core; + + return true; } -extern "C" bool InterfaceSetParentFunction(AbckitArktsInterface *iface, AbckitArktsFunction *func) +extern "C" bool InterfaceSetParentFunction(AbckitArktsInterface *iface, AbckitArktsFunction *method) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)func; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + if (iface == nullptr || method == nullptr) { + statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); + return false; + } + if (iface->core->owningModule->target != ABCKIT_TARGET_ARK_TS_V2) { + statuses::SetLastError(ABCKIT_STATUS_UNSUPPORTED); + return false; + } + for (const auto &fun : iface->core->methods) { + if (fun.get() == method->core) { + iface->core->parentFunction = method->core; + return true; + } + } + statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); return false; } -extern "C" AbckitArktsInterface *CreateInterface(const char *name) +extern "C" AbckitTarget IfaceModuleGetTarget(AbckitArktsModule *m) { - LIBABCKIT_UNIMPLEMENTED; - (void)name; - return nullptr; + LIBABCKIT_IMPLEMENTED; + LIBABCKIT_BAD_ARGUMENT(m, ABCKIT_TARGET_UNKNOWN); + + return m->core->target; +} + +extern "C" AbckitArktsInterface *CreateInterface(const char *name, AbckitArktsModule *owningModule) +{ + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(name, nullptr); + LIBABCKIT_BAD_ARGUMENT(owningModule, nullptr); + if (IfaceModuleGetTarget(owningModule) != ABCKIT_TARGET_ARK_TS_V2) { + LIBABCKIT_UNREACHABLE; + return nullptr; + } + auto *iface = new AbckitCoreInterface(); + iface->name = new AbckitString {std::string_view(name)}; + iface->owningModule = owningModule->core; + + auto *record = SetRecordAttributeValue(); + + iface->impl = std::make_unique(record); + std::get>(iface->impl)->core = iface; + + return std::get>(iface->impl).get(); } + // ======================================== // Module Field // ======================================== diff --git a/libabckit/src/metadata_inspect_impl.cpp b/libabckit/src/metadata_inspect_impl.cpp index c55b6be243f990bca9cfc3c7fd4e154cb5782906..c5565b2b7b8e5354f8fba04ecfe1ae80b3eb8a9a 100644 --- a/libabckit/src/metadata_inspect_impl.cpp +++ b/libabckit/src/metadata_inspect_impl.cpp @@ -198,11 +198,22 @@ extern "C" bool ModuleEnumerateClasses(AbckitCoreModule *m, void *data, bool (*c extern "C" bool ModuleEnumerateInterfaces(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreInterface *iface, void *data)) { - LIBABCKIT_UNIMPLEMENTED; - (void)m; - (void)data; - (void)cb; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + LIBABCKIT_BAD_ARGUMENT(m, false) + LIBABCKIT_BAD_ARGUMENT(cb, false) + + switch (ModuleGetTarget(m)) { + case ABCKIT_TARGET_ARK_TS_V1: + case ABCKIT_TARGET_ARK_TS_V2: + return ArkTSModuleEnumerateInterfaces(m, data, cb); + case ABCKIT_TARGET_JS: + return false; + case ABCKIT_TARGET_UNKNOWN: + return UnknownModuleEnumerateStub(m); + default: + LIBABCKIT_UNREACHABLE; + } } extern "C" bool ModuleEnumerateEnums(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreEnum *enm, void *data)) @@ -601,63 +612,112 @@ extern "C" bool ClassEnumerateFields(AbckitCoreClass *klass, void *data, extern "C" AbckitFile *InterfaceGetFile(AbckitCoreInterface *iface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - return nullptr; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, nullptr); + + return iface->owningModule->file; } extern "C" AbckitCoreModule *InterfaceGetModule(AbckitCoreInterface *iface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - return nullptr; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, nullptr); + + return iface->owningModule; } extern "C" AbckitString *InterfaceGetName(AbckitCoreInterface *iface) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - return nullptr; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, nullptr); + + return iface->name; } extern "C" bool InterfaceEnumerateSuperInterfaces(AbckitCoreInterface *iface, void *data, bool (*cb)(AbckitCoreInterface *iface, void *data)) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)data; - (void)cb; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, false); + LIBABCKIT_BAD_ARGUMENT(cb, false); + + switch (ModuleGetTarget(iface->owningModule)) { + case ABCKIT_TARGET_ARK_TS_V1: + case ABCKIT_TARGET_ARK_TS_V2: + return InterfaceEnumerateSuperInterfaces(iface, data, cb); + case ABCKIT_TARGET_JS: + return false; + default: + LIBABCKIT_UNREACHABLE; + } } extern "C" bool InterfaceEnumerateMethods(AbckitCoreInterface *iface, void *data, bool (*cb)(AbckitCoreFunction *func, void *data)) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)data; - (void)cb; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, false) + LIBABCKIT_BAD_ARGUMENT(cb, false) + + switch (ModuleGetTarget(iface->owningModule)) { + case ABCKIT_TARGET_ARK_TS_V1: + case ABCKIT_TARGET_ARK_TS_V2: + return InterfaceEnumerateMethods(iface, data, cb); + case ABCKIT_TARGET_JS: + return false; + default: + LIBABCKIT_UNREACHABLE; + } } extern "C" bool InterfaceEnumerateAnnotations(AbckitCoreInterface *iface, void *data, bool (*cb)(AbckitCoreAnnotation *anno, void *data)) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)data; - (void)cb; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, false) + LIBABCKIT_BAD_ARGUMENT(cb, false) + + switch (ModuleGetTarget(iface->owningModule)) { + case ABCKIT_TARGET_ARK_TS_V1: + case ABCKIT_TARGET_ARK_TS_V2: + return InterfaceEnumerateAnnotations(iface, data, cb); + case ABCKIT_TARGET_JS: + return false; + default: + LIBABCKIT_UNREACHABLE; + } } extern "C" bool InterfaceEnumerateFields(AbckitCoreInterface *iface, void *data, bool (*cb)(AbckitCoreInterfaceField *field, void *data)) { - LIBABCKIT_UNIMPLEMENTED; - (void)iface; - (void)data; - (void)cb; - return false; + LIBABCKIT_CLEAR_LAST_ERROR; + LIBABCKIT_IMPLEMENTED; + + LIBABCKIT_BAD_ARGUMENT(iface, false) + LIBABCKIT_BAD_ARGUMENT(cb, false) + + switch (ModuleGetTarget(iface->owningModule)) { + case ABCKIT_TARGET_ARK_TS_V1: + case ABCKIT_TARGET_ARK_TS_V2: + return InterfaceEnumerateFields(iface, data, cb); + case ABCKIT_TARGET_JS: + return false; + default: + LIBABCKIT_UNREACHABLE; + } } // ======================================== diff --git a/libabckit/src/metadata_inspect_impl.h b/libabckit/src/metadata_inspect_impl.h index 22c818baaa8ed5ebe51b96345c22f9eb0096b8d1..4bb51842e29a47a05e33f7100741f40b3d491d37 100644 --- a/libabckit/src/metadata_inspect_impl.h +++ b/libabckit/src/metadata_inspect_impl.h @@ -1066,7 +1066,17 @@ struct AbckitCoreEnumField { }; struct AbckitArktsInterface { + std::variant impl; + ark::pandasm::Record *GetStaticImpl() + { + return std::get(impl); + } AbckitCoreInterface *core = nullptr; + AbckitArktsInterface() = default; + explicit AbckitArktsInterface(ark::pandasm::Record *record) + { + impl = reinterpret_cast(record); + } }; struct AbckitCoreInterface { @@ -1074,6 +1084,10 @@ struct AbckitCoreInterface { * Back link to the module. */ AbckitCoreModule *owningModule = nullptr; + /* + * Back link to the parent function. + */ + AbckitCoreFunction *parentFunction = nullptr; /* * Name of the interface. */ @@ -1081,23 +1095,25 @@ struct AbckitCoreInterface { /* * Table to store the methods of the interface. */ - std::unordered_map> methods; + std::vector> methods; /* * Table to store the fields of the interface. */ - std::unordered_map> fields; + std::vector> fields; /* * Table to store the annotations of the interface. */ - std::unordered_map> annotations; + std::vector> annotations; /* * Table to store the classes implement the interface. */ - std::unordered_map classes; + std::vector classes; /* * Table to store the super interfaces of the interface. */ - std::unordered_map superinterfaces; + std::vector> superinterfaces; + + AbckitTarget target = ABCKIT_TARGET_UNKNOWN; std::variant> impl; AbckitArktsInterface *GetArkTSImpl() diff --git a/libabckit/tests/helpers/helpers_nullptr.cpp b/libabckit/tests/helpers/helpers_nullptr.cpp index cbbc54e471289464788c0a73af18bd44c9795793..0fb9c491f7b9767172c6b1e6485e9e95203ad464 100644 --- a/libabckit/tests/helpers/helpers_nullptr.cpp +++ b/libabckit/tests/helpers/helpers_nullptr.cpp @@ -99,6 +99,10 @@ namespace libabckit::test::helpers_nullptr { reinterpret_cast(0x1); [[maybe_unused]] static const AbckitJsExternalModuleCreateParams *g_constAbckitJsExternalmodulecreateparams = reinterpret_cast(0x1); +[[maybe_unused]] static AbckitArktsInterface *g_abckitArktsInterface = + reinterpret_cast< AbckitArktsInterface *>(0x1); +[[maybe_unused]] static AbckitCoreInterface *g_abckitCoreInterface = + reinterpret_cast< AbckitCoreInterface *>(0x1); // NOLINTEND(cppcoreguidelines-pro-type-cstyle-cast) static const char *GetConstChar() @@ -1918,4 +1922,119 @@ void TestNullptr(AbckitArktsNamespace *(*apiToCheck)(AbckitCoreNamespace *)) ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); } +void TestNullptr(AbckitArktsInterface *(*apiToCheck)(const char *, AbckitArktsModule *)) +{ + ASSERT_EQ(apiToCheck(nullptr, g_abckitArktsModule), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + std::string name = std::string("test"); + const char *nameCStr = name.c_str(); + ASSERT_EQ(apiToCheck(nameCStr, nullptr), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, const char *)) +{ + ASSERT_EQ(apiToCheck(g_abckitArktsInterface, nullptr), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + std::string name = std::string("test"); + const char *nameCStr = name.c_str(); + ASSERT_EQ(apiToCheck(nullptr, nameCStr), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsInterface *)) +{ + ASSERT_EQ(apiToCheck(nullptr, g_abckitArktsInterface), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + ASSERT_EQ(apiToCheck(g_abckitArktsInterface, nullptr), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(AbckitFile *(*apiToCheck)(AbckitCoreInterface *)) +{ + ASSERT_EQ(apiToCheck(nullptr), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(AbckitString *(*apiToCheck)(AbckitCoreInterface *)) +{ + ASSERT_EQ(apiToCheck(nullptr), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(AbckitCoreModule *(*apiToCheck)(AbckitCoreInterface *)) +{ + ASSERT_EQ(apiToCheck(nullptr), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreInterface *, void *))) +{ + apiToCheck(nullptr, g_void, [](AbckitCoreInterface *, void *) { return false; }); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + apiToCheck(g_abckitCoreInterface, g_void, nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreFunction *, void *))) +{ + apiToCheck(nullptr, g_void, [](AbckitCoreFunction *, void *) { return false; }); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + apiToCheck(g_abckitCoreInterface, g_void, nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreAnnotation *, void *))) +{ + apiToCheck(nullptr, g_void, [](AbckitCoreAnnotation *, void *) { return false; }); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + apiToCheck(g_abckitCoreInterface, g_void, nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreInterfaceField *, void *))) +{ + apiToCheck(nullptr, g_void, [](AbckitCoreInterfaceField *, void *) { return false; }); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + apiToCheck(g_abckitCoreInterface, g_void, nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsFunction *)) +{ + ASSERT_EQ(apiToCheck(nullptr, g_abckitArktsMethod), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + ASSERT_EQ(apiToCheck(g_abckitArktsInterface, nullptr), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsModule *)) +{ + ASSERT_EQ(apiToCheck(nullptr, g_abckitArktsModule), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); + + ASSERT_EQ(apiToCheck(g_abckitArktsInterface, nullptr), false); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(AbckitCoreInterface *(*apiToCheck)(AbckitArktsInterface *)) +{ + ASSERT_EQ(apiToCheck(nullptr), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + +void TestNullptr(AbckitArktsInterface *(*apiToCheck)(AbckitCoreInterface *)) +{ + ASSERT_EQ(apiToCheck(nullptr), nullptr); + ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_BAD_ARGUMENT); +} + } // namespace libabckit::test::helpers_nullptr diff --git a/libabckit/tests/helpers/helpers_nullptr.h b/libabckit/tests/helpers/helpers_nullptr.h index c946af3c2d227af5d0cc02bbbc7078720e7aa156..a6614a246579613d302c6224e530628cbacbb48e 100644 --- a/libabckit/tests/helpers/helpers_nullptr.h +++ b/libabckit/tests/helpers/helpers_nullptr.h @@ -305,6 +305,23 @@ void TestNullptr(AbckitCoreExportDescriptor *(*apiToCheck)(AbckitJsExportDescrip void TestNullptr(AbckitJsImportDescriptor *(*apiToCheck)(AbckitCoreImportDescriptor *)); void TestNullptr(AbckitLiteral *(*apiToCheck)(AbckitFile *, AbckitLiteralArray *)); +void TestNullptr(AbckitArktsInterface *(*apiToCheck)(const char *, AbckitArktsModule *)); +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsInterface *)); +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsInterface *)); +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, const char *)); +void TestNullptr(AbckitFile *(*apiToCheck)(AbckitCoreInterface *)); +void TestNullptr(AbckitString *(*apiToCheck)(AbckitCoreInterface *)); +void TestNullptr(AbckitCoreModule *(*apiToCheck)(AbckitCoreInterface *)); +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreInterface *, void *))); +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreFunction *, void *))); +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreAnnotation *, void *))); +void TestNullptr(bool (*apiToCheck)(AbckitCoreInterface *, void *, bool (*cb)(AbckitCoreInterfaceField *, void *))); +void TestNullptr(AbckitArktsInterface *(*apiToCheck)(const char *, AbckitArktsModule *)); +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsFunction *)); +void TestNullptr(bool (*apiToCheck)(AbckitArktsInterface *, AbckitArktsModule *)); +void TestNullptr(AbckitCoreInterface *(*apiToCheck)(AbckitArktsInterface *)); +void TestNullptr(AbckitArktsInterface *(*apiToCheck)(AbckitCoreInterface *)); + } // namespace libabckit::test::helpers_nullptr #endif /*LIBABCKIT_TESTS_INVALID_HELPERS */ diff --git a/libabckit/tests/mock/cpp_helpers_mock.h b/libabckit/tests/mock/cpp_helpers_mock.h index b001a92c0ae8b5262c6f09529bf7a45975d68730..269623c450294f2f3961a38b49dd4762af4d77f6 100644 --- a/libabckit/tests/mock/cpp_helpers_mock.h +++ b/libabckit/tests/mock/cpp_helpers_mock.h @@ -122,6 +122,28 @@ inline abckit::arkts::Function GetMockArktsFunction(const abckit::File &file) return f; } +inline abckit::core::Interface GetMockCoreInterface(const abckit::File &file) +{ + abckit::core::Module mod = GetMockCoreModule(file); + std::vector interfaces; + + mod.EnumerateInterfaces([&interfaces](abckit::core::Interface iface) -> bool { + interfaces.push_back(iface); + return true; + }); + + EXPECT_TRUE(CheckMockedApi("ModuleEnumerateInterfaces")); + + return interfaces.front(); +} + +inline abckit::arkts::Interface GetMockArktsInterface(const abckit::File &file) +{ + auto f = abckit::arkts::Interface(GetMockCoreInterface(file)); + EXPECT_TRUE(CheckMockedApi("CoreInterfaceToArktsInterface")); + return f; +} + inline abckit::core::Annotation GetMockCoreAnnotation(const abckit::File &file) { abckit::core::Function func = GetMockCoreFunction(file); diff --git a/libabckit/tests/mock/tests/core/cpp_api_interface.cpp b/libabckit/tests/mock/tests/core/cpp_api_interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c7cf8cf2363a078b35760611eb43060b1c8de4a5 --- /dev/null +++ b/libabckit/tests/mock/tests/core/cpp_api_interface.cpp @@ -0,0 +1,173 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "include/cpp/abckit_cpp.h" +#include "tests/mock/check_mock.h" +#include "src/mock/mock_values.h" +#include "tests/mock/cpp_helpers_mock.h" +#include + +namespace libabckit::cpp_test { + +class LibAbcKitCppMockCoreTestInterface : public ::testing::Test {}; + +// Test: test-kind=mock, api=Interface::GetFile, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_GetFile) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + abckit::mock::helpers::GetMockArktsInterface(f).GetFile(); + ASSERT_TRUE(CheckMockedApi("InterfaceGetFile")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::GetName, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_GetName) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + abckit::mock::helpers::GetMockArktsInterface(f).GetName(); + ASSERT_TRUE(CheckMockedApi("AbckitStringToString")); + ASSERT_TRUE(CheckMockedApi("InterfaceGetName")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::GetModule, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_GetModule) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + abckit::mock::helpers::GetMockArktsInterface(f).GetModule(); + ASSERT_TRUE(CheckMockedApi("InterfaceGetModule")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::AddSuperInterface, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_AddSuperInterface) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.AddSuperInterface(iface); + ASSERT_TRUE(CheckMockedApi("InterfaceAddSuperInterface")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::RemoveSuperInterface, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_RemoveSuperInterface) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.RemoveSuperInterface(iface); + ASSERT_TRUE(CheckMockedApi("InterfaceRemoveSuperInterface")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::SetName, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_SetName) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.SetName("newName"); + ASSERT_TRUE(CheckMockedApi("InterfaceSetName")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::EnumerateSuperInterfaces, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_EnumerateSuperInterfaces) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.EnumerateSuperInterfaces([](const abckit::core::Interface &) { return true; }); + ASSERT_TRUE(CheckMockedApi("InterfaceEnumerateSuperInterfaces")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::EnumerateMethods, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_EnumerateMethods) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.EnumerateMethods([](const abckit::core::Function &) { return true; }); + ASSERT_TRUE(CheckMockedApi("InterfaceEnumerateMethods")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::EnumerateAnnotations, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_EnumerateAnnotations) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.EnumerateAnnotations([](const abckit::core::Annotation &) { return true; }); + ASSERT_TRUE(CheckMockedApi("InterfaceEnumerateAnnotations")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + +// Test: test-kind=mock, api=Interface::EnumerateFields, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestInterface, Interface_EnumerateFields) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + auto iface = abckit::mock::helpers::GetMockArktsInterface(f); + iface.EnumerateFields([](const abckit::core::InterfaceField &) { return true; }); + ASSERT_TRUE(CheckMockedApi("InterfaceEnumerateFields")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} +} // namespace libabckit::cpp_test \ No newline at end of file diff --git a/libabckit/tests/mock/tests/core/cpp_api_module.cpp b/libabckit/tests/mock/tests/core/cpp_api_module.cpp index 659d1cae5d5e84460c7b04497a2b514d5022e24f..d9fad1a6ddff6ba4876928b6b83089e05f7b897b 100644 --- a/libabckit/tests/mock/tests/core/cpp_api_module.cpp +++ b/libabckit/tests/mock/tests/core/cpp_api_module.cpp @@ -267,4 +267,19 @@ TEST_F(LibAbcKitCppMockCoreTestModule, Module_EnumerateAnnotationInterfaces) ASSERT_TRUE(CheckMockedStackEmpty()); } +// Test: test-kind=mock, api=Module::EnumerateInterfaces, abc-kind=ArkTS1, category=internal, extension=cpp +TEST_F(LibAbcKitCppMockCoreTestModule, Module_EnumerateInterfaces) +{ + ASSERT_TRUE(CheckMockedStackEmpty()); + { + abckit::File f(DEFAULT_PATH); + ASSERT_TRUE(CheckMockedApi("OpenAbc")); + abckit::mock::helpers::GetMockCoreModule(f).EnumerateInterfaces( + DEFAULT_LAMBDA(abckit::core::Interface)); + ASSERT_TRUE(CheckMockedApi("ModuleEnumerateInterfaces")); + } + ASSERT_TRUE(CheckMockedApi("CloseFile")); + ASSERT_TRUE(CheckMockedStackEmpty()); +} + } // namespace libabckit::cpp_test \ No newline at end of file diff --git a/libabckit/tests/null_args_tests/null_args_tests_ArktsInspectApiImpl_0.cpp b/libabckit/tests/null_args_tests/null_args_tests_ArktsInspectApiImpl_0.cpp index 62e82487d22cbab0b1cce3afba94156d08bf4643..d5e412e3ea525a4113e48093e4f7cc9828cce5d7 100644 --- a/libabckit/tests/null_args_tests/null_args_tests_ArktsInspectApiImpl_0.cpp +++ b/libabckit/tests/null_args_tests/null_args_tests_ArktsInspectApiImpl_0.cpp @@ -146,6 +146,20 @@ TEST_F(LibAbcKitNullptrTestsArktsInspectApiImpl0, coreClassToArktsClass) helpers_nullptr::TestNullptr(g_arktsInspectApiImp->coreClassToArktsClass); } +// Test: test-kind=api, api=ArktsInspectApiImpl::arktsInterfaceToCoreInterface, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsArktsInspectApiImpl0, arktsInterfaceToCoreInterface) +{ + helpers_nullptr::TestNullptr(g_arktsInspectApiImp->arktsInterfaceToCoreInterface); +} + +// Test: test-kind=api, api=ArktsInspectApiImpl::coreInterfaceToArktsInterface, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsArktsInspectApiImpl0, coreInterfaceToArktsInterface) +{ + helpers_nullptr::TestNullptr(g_arktsInspectApiImp->coreInterfaceToArktsInterface); +} + // Test: test-kind=api, api=ArktsInspectApiImpl::coreExportDescriptorToArktsExportDescriptor, // abc-kind=NoABC, category=negative-nullptr, extension=c TEST_F(LibAbcKitNullptrTestsArktsInspectApiImpl0, coreExportDescriptorToArktsExportDescriptor) diff --git a/libabckit/tests/null_args_tests/null_args_tests_ArktsModifyApiImpl_0.cpp b/libabckit/tests/null_args_tests/null_args_tests_ArktsModifyApiImpl_0.cpp index e7cc6895fad2baf0ae9895679a58e63e2286796e..24102452cedceb8d44b3a3bf6d38dc5ba7137a7e 100644 --- a/libabckit/tests/null_args_tests/null_args_tests_ArktsModifyApiImpl_0.cpp +++ b/libabckit/tests/null_args_tests/null_args_tests_ArktsModifyApiImpl_0.cpp @@ -132,4 +132,61 @@ TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, moduleRemoveImport) helpers_nullptr::TestNullptr(g_arktsModifyApiImp->moduleRemoveImport); } +// Test: test-kind=api, api=ModifyApiImpl::interfaceAddSuperInterface, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceAddSuperInterface) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceAddSuperInterface); +} + +// Test: test-kind=api, api=ModifyApiImpl::interfaceRemoveSuperInterface, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceRemoveSuperInterface) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceRemoveSuperInterface); +} + +// Test: test-kind=api, api=ModifyApiImpl::interfaceSetName, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceSetName) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceSetName); +} + +// Test: test-kind=api, api=ModifyApiImpl::interfaceAddMethod, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceAddMethod) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceAddMethod); +} + +// Test: test-kind=api, api=ModifyApiImpl::interfaceRemoveMethod, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceRemoveMethod) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceRemoveMethod); +} + +// Test: test-kind=api, api=ModifyApiImpl::interfaceSetOwningModule, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceSetOwningModule) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceSetOwningModule); +} + +// Test: test-kind=api, api=ModifyApiImpl::interfaceSetParentFunction, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, interfaceSetParentFunction) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->interfaceSetParentFunction); +} + +// Test: test-kind=api, api=ModifyApiImpl::createInterface, +// abc-kind=NoABC, category=negative-nullptr +TEST_F(LibAbcKitNullptrTestsArktsModifyApiImpl0, createInterface) +{ + helpers_nullptr::TestNullptr(g_arktsModifyApiImp->createInterface); +} + + } // namespace libabckit::test diff --git a/libabckit/tests/null_args_tests/null_args_tests_InspectApiImpl_0.cpp b/libabckit/tests/null_args_tests/null_args_tests_InspectApiImpl_0.cpp index 2692bfb2ec7760058d34b5e1158b52e488a6a91d..f546f0f1819f0335ca43d08dd21b1577cf0d2736 100644 --- a/libabckit/tests/null_args_tests/null_args_tests_InspectApiImpl_0.cpp +++ b/libabckit/tests/null_args_tests/null_args_tests_InspectApiImpl_0.cpp @@ -216,6 +216,55 @@ TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, createGraphFromFunction) helpers_nullptr::TestNullptr(g_inspectApiImp->createGraphFromFunction); } +/ Test: test-kind=api, api=InspectApiImpl::interfaceGetFile, + // abc-kind=NoABC, category=negative-nullptr, extension=c + TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceGetFile) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceGetFile); +} + +// Test: test-kind=api, api=InspectApiImpl::interfaceGetModule, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceGetModule) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceGetModule); +} + +// Test: test-kind=api, api=InspectApiImpl::interfaceGetName, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceGetName) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceGetName); +} + +// Test: test-kind=api, api=InspectApiImpl::interfaceEnumerateSuperInterfaces, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceEnumerateSuperInterfaces) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceEnumerateSuperInterfaces); +} + +// Test: test-kind=api, api=InspectApiImpl::interfaceEnumerateMethods, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceEnumerateMethods) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceEnumerateMethods); +} + +// Test: test-kind=api, api=InspectApiImpl::interfaceEnumerateAnnotations, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceEnumerateAnnotations) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceEnumerateAnnotations); +} + +// Test: test-kind=api, api=InspectApiImpl::interfaceEnumerateFields, +// abc-kind=NoABC, category=negative-nullptr, extension=c +TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, interfaceEnumerateFields) +{ + helpers_nullptr::TestNullptr(g_inspectApiImp->interfaceEnumerateFields); +} + // Test: test-kind=api, api=InspectApiImpl::exportDescriptorGetAlias, // abc-kind=NoABC, category=negative-nullptr, extension=c TEST_F(LibAbcKitNullptrTestsInspectApiImpl0, exportDescriptorGetAlias)