summaryrefslogtreecommitdiff
path: root/source/DataFormatters/TypeValidator.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2014-09-05 20:45:07 +0000
committerEnrico Granata <egranata@apple.com>2014-09-05 20:45:07 +0000
commit0562760c1b0e9d561ea0064774b14e0cb2971a07 (patch)
treeea19ff0bdfda114bb7390e264b313fcb48b1d932 /source/DataFormatters/TypeValidator.cpp
parent36c810672f2b7e5706fe0c6399498e7b625ba1af (diff)
Introduce the notion of a "type validator" formatter
Type Validators have the purpose of looking at a ValueObject, and making sure that there is nothing semantically wrong about the object's contents For instance, if you have a class that represents a speed, the validator might trigger if the speed value is greater than the speed of light This first patch hooks up the moving parts in the formatters subsystem, but does not link ValueObjects to TypeValidators, nor lets the SB API be exposed to validators It also lacks the notion of Python validators git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@217277 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'source/DataFormatters/TypeValidator.cpp')
-rw-r--r--source/DataFormatters/TypeValidator.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/source/DataFormatters/TypeValidator.cpp b/source/DataFormatters/TypeValidator.cpp
new file mode 100644
index 000000000..0327f5a09
--- /dev/null
+++ b/source/DataFormatters/TypeValidator.cpp
@@ -0,0 +1,61 @@
+//===-- TypeValidator.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C Includes
+
+// C++ Includes
+
+// Other libraries and framework includes
+
+// Project includes
+#include "lldb/DataFormatters/TypeValidator.h"
+#import "lldb/Core/StreamString.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TypeValidatorImpl::ValidationResult
+TypeValidatorImpl::Success ()
+{
+ return ValidationResult { ValidationResult::ResultType::eSuccess, "" };
+}
+
+TypeValidatorImpl::ValidationResult
+TypeValidatorImpl::Failure (std::string message)
+{
+ return ValidationResult { ValidationResult::ResultType::eFailure, message };
+}
+
+TypeValidatorImpl_CXX::TypeValidatorImpl_CXX (ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags& flags) :
+ TypeValidatorImpl(flags),
+ m_description(d),
+ m_validator_function(f)
+{
+}
+
+TypeValidatorImpl::ValidationResult
+TypeValidatorImpl_CXX::FormatObject (ValueObject *valobj) const
+{
+ if (!valobj)
+ return Success(); // I guess there's nothing wrong with a null valueobject..
+
+ return m_validator_function(valobj);
+}
+
+std::string
+TypeValidatorImpl_CXX::GetDescription()
+{
+ StreamString sstr;
+ sstr.Printf ("%s%s%s%s",
+ m_description.c_str(),
+ Cascades() ? "" : " (not cascading)",
+ SkipsPointers() ? " (skip pointers)" : "",
+ SkipsReferences() ? " (skip references)" : "");
+ return sstr.GetString();
+}