From 4b15c6e2a15f9d1d7c2586af8a7811e7b43ac799 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 12 Dec 2019 09:25:01 -0800 Subject: [PATCH] [lldb/Host] Use cmakedefine01 for LLDB_ENABLE_LIBXML2 This keeps things consistent with out other optional dependencies. But more importantly it won't silently fail when you forget to include Config.h. --- lldb/include/lldb/Host/Config.h.cmake | 2 +- lldb/include/lldb/Host/XML.h | 4 +-- lldb/source/Host/common/XML.cpp | 58 +++++++++++++++++------------------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake index eaa5404..7f0588a 100644 --- a/lldb/include/lldb/Host/Config.h.cmake +++ b/lldb/include/lldb/Host/Config.h.cmake @@ -39,7 +39,7 @@ #cmakedefine01 LLDB_ENABLE_LIBEDIT -#cmakedefine LLDB_ENABLE_LIBXML2 +#cmakedefine01 LLDB_ENABLE_LIBXML2 #cmakedefine LLDB_DISABLE_PYTHON diff --git a/lldb/include/lldb/Host/XML.h b/lldb/include/lldb/Host/XML.h index 3875453..ca51d30 100644 --- a/lldb/include/lldb/Host/XML.h +++ b/lldb/include/lldb/Host/XML.h @@ -11,7 +11,7 @@ #include "lldb/Host/Config.h" -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 #include #endif @@ -27,7 +27,7 @@ namespace lldb_private { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 typedef xmlNodePtr XMLNodeImpl; typedef xmlDocPtr XMLDocumentImpl; #else diff --git a/lldb/source/Host/common/XML.cpp b/lldb/source/Host/common/XML.cpp index 4289117..28d1f5a 100644 --- a/lldb/source/Host/common/XML.cpp +++ b/lldb/source/Host/common/XML.cpp @@ -22,7 +22,7 @@ XMLDocument::XMLDocument() : m_document(nullptr) {} XMLDocument::~XMLDocument() { Clear(); } void XMLDocument::Clear() { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (m_document) { xmlDocPtr doc = m_document; m_document = nullptr; @@ -43,7 +43,7 @@ void XMLDocument::ErrorCallback(void *ctx, const char *format, ...) { } bool XMLDocument::ParseFile(const char *path) { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 Clear(); xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback); m_document = xmlParseFile(path); @@ -54,7 +54,7 @@ bool XMLDocument::ParseFile(const char *path) { bool XMLDocument::ParseMemory(const char *xml, size_t xml_length, const char *url) { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 Clear(); xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback); m_document = xmlReadMemory(xml, (int)xml_length, url, nullptr, 0); @@ -64,7 +64,7 @@ bool XMLDocument::ParseMemory(const char *xml, size_t xml_length, } XMLNode XMLDocument::GetRootElement(const char *required_name) { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { XMLNode root_node(xmlDocGetRootElement(m_document)); if (required_name) { @@ -82,7 +82,7 @@ XMLNode XMLDocument::GetRootElement(const char *required_name) { llvm::StringRef XMLDocument::GetErrors() const { return m_errors.GetString(); } bool XMLDocument::XMLEnabled() { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 return true; #else return false; @@ -100,7 +100,7 @@ XMLNode::~XMLNode() {} void XMLNode::Clear() { m_node = nullptr; } XMLNode XMLNode::GetParent() const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return XMLNode(m_node->parent); else @@ -111,7 +111,7 @@ XMLNode XMLNode::GetParent() const { } XMLNode XMLNode::GetSibling() const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return XMLNode(m_node->next); else @@ -122,7 +122,7 @@ XMLNode XMLNode::GetSibling() const { } XMLNode XMLNode::GetChild() const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return XMLNode(m_node->children); @@ -136,7 +136,7 @@ XMLNode XMLNode::GetChild() const { llvm::StringRef XMLNode::GetAttributeValue(const char *name, const char *fail_value) const { const char *attr_value = nullptr; -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) attr_value = (const char *)xmlGetProp(m_node, (const xmlChar *)name); @@ -153,7 +153,7 @@ llvm::StringRef XMLNode::GetAttributeValue(const char *name, bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value, uint64_t fail_value, int base) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 llvm::StringRef str_value = GetAttributeValue(name, ""); #else llvm::StringRef str_value; @@ -164,14 +164,14 @@ bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value, } void XMLNode::ForEachChildNode(NodeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) GetChild().ForEachSiblingNode(callback); #endif } void XMLNode::ForEachChildElement(NodeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 XMLNode child = GetChild(); if (child) child.ForEachSiblingElement(callback); @@ -180,7 +180,7 @@ void XMLNode::ForEachChildElement(NodeCallback const &callback) const { void XMLNode::ForEachChildElementWithName(const char *name, NodeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 XMLNode child = GetChild(); if (child) child.ForEachSiblingElementWithName(name, callback); @@ -188,7 +188,7 @@ void XMLNode::ForEachChildElementWithName(const char *name, } void XMLNode::ForEachAttribute(AttributeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { for (xmlAttrPtr attr = m_node->properties; attr != nullptr; @@ -211,7 +211,7 @@ void XMLNode::ForEachAttribute(AttributeCallback const &callback) const { } void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // iterate through all siblings @@ -224,7 +224,7 @@ void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const { } void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // iterate through all siblings @@ -242,7 +242,7 @@ void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const { void XMLNode::ForEachSiblingElementWithName( const char *name, NodeCallback const &callback) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // iterate through all siblings @@ -270,7 +270,7 @@ void XMLNode::ForEachSiblingElementWithName( } llvm::StringRef XMLNode::GetName() const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { if (m_node->name) return llvm::StringRef((const char *)m_node->name); @@ -281,7 +281,7 @@ llvm::StringRef XMLNode::GetName() const { bool XMLNode::GetElementText(std::string &text) const { text.clear(); -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { bool success = false; if (m_node->type == XML_ELEMENT_NODE) { @@ -303,7 +303,7 @@ bool XMLNode::GetElementText(std::string &text) const { bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value, int base) const { bool success = false; -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { std::string text; if (GetElementText(text)) @@ -317,7 +317,7 @@ bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value, bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const { bool success = false; -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { std::string text; if (GetElementText(text)) { @@ -332,7 +332,7 @@ bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const { } bool XMLNode::NameIs(const char *name) const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // In case we are looking for a nullptr name or an exact pointer match @@ -348,7 +348,7 @@ bool XMLNode::NameIs(const char *name) const { XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const { XMLNode result_node; -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 ForEachChildElementWithName( name, [&result_node](const XMLNode &node) -> bool { result_node = node; @@ -363,7 +363,7 @@ XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const { bool XMLNode::IsValid() const { return m_node != nullptr; } bool XMLNode::IsElement() const { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return m_node->type == XML_ELEMENT_NODE; #endif @@ -371,7 +371,7 @@ bool XMLNode::IsElement() const { } XMLNode XMLNode::GetElementForPath(const NamePath &path) { -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { if (path.empty()) @@ -431,7 +431,7 @@ bool ApplePropertyList::GetValueAsString(const char *key, XMLNode ApplePropertyList::GetValueNode(const char *key) const { XMLNode value_node; -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { m_dict_node.ForEachChildElementWithName( @@ -455,7 +455,7 @@ XMLNode ApplePropertyList::GetValueNode(const char *key) const { bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node, std::string &value) { value.clear(); -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (node.IsValid()) { llvm::StringRef element_name = node.GetName(); if (element_name == "true" || element_name == "false") { @@ -471,7 +471,7 @@ bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node, return false; } -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 namespace { @@ -533,7 +533,7 @@ StructuredData::ObjectSP CreatePlistValue(XMLNode node) { StructuredData::ObjectSP ApplePropertyList::GetStructuredData() { StructuredData::ObjectSP root_sp; -#if defined(LLDB_ENABLE_LIBXML2) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { return CreatePlistValue(m_dict_node); } -- 2.7.4