summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2013-11-21 00:28:07 +0000
committerNick Kledzik <kledzik@apple.com>2013-11-21 00:28:07 +0000
commit9fd7416b3b5c437e3390ea9679d77e0221bec0b5 (patch)
tree556eba1681d33365b00d13b9f331a76ccb6c39e8 /docs
parent25f01786ea6258bfddf2a051f8343b7f2b45e338 (diff)
downloadllvm-9fd7416b3b5c437e3390ea9679d77e0221bec0b5.tar.gz
llvm-9fd7416b3b5c437e3390ea9679d77e0221bec0b5.tar.bz2
llvm-9fd7416b3b5c437e3390ea9679d77e0221bec0b5.tar.xz
YAML I/O add support for validate()
MappingTrait template specializations can now have a validate() method which performs semantic checking. For details, see <http://llvm.org/docs/YamlIO.html>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r--docs/YamlIO.rst38
1 files changed, 38 insertions, 0 deletions
diff --git a/docs/YamlIO.rst b/docs/YamlIO.rst
index 5ec0a01f8d..46609a3acd 100644
--- a/docs/YamlIO.rst
+++ b/docs/YamlIO.rst
@@ -647,6 +647,44 @@ mappings, as long as they are convertable.
To check a tag, inside your mapping() method you can use io.mapTag() to specify
what the tag should be. This will also add that tag when writing yaml.
+Validation
+----------
+
+Sometimes in a yaml map, each key/value pair is valid, but the combination is
+not. This is similar to something having no syntax errors, but still having
+semantic errors. To support semantic level checking, YAML I/O allows
+an optional ``validate()`` method in a MappingTraits template specialization.
+
+When parsing yaml, the ``validate()`` method is call *after* all key/values in
+the map have been processed. Any error message returned by the ``validate()``
+method during input will be printed just a like a syntax error would be printed.
+When writing yaml, the ``validate()`` method is called *before* the yaml
+key/values are written. Any error during output will trigger an ``assert()``
+because it is a programming error to have invalid struct values.
+
+
+.. code-block:: c++
+
+ using llvm::yaml::MappingTraits;
+ using llvm::yaml::IO;
+
+ struct Stuff {
+ ...
+ };
+
+ template <>
+ struct MappingTraits<Stuff> {
+ static void mapping(IO &io, Stuff &stuff) {
+ ...
+ }
+ static StringRef validate(IO &io, Stuff &stuff) {
+ // Look at all fields in 'stuff' and if there
+ // are any bad values return a string describing
+ // the error. Otherwise return an empty string.
+ return StringRef();
+ }
+ };
+
Sequence
========