diff options
author | mikhnenko <mikhnenko@yandex-team.com> | 2024-07-11 10:52:12 +0300 |
---|---|---|
committer | mikhnenko <mikhnenko@yandex-team.com> | 2024-07-11 11:06:19 +0300 |
commit | 7c8960adda8aad0056fa7043bfb5bada4a951b59 (patch) | |
tree | 44978b4793670b3547e0237bc129d14c7e188bf5 | |
parent | 106eb9386cdc7e5efd77e96b6a63626eefa43056 (diff) | |
download | ydb-7c8960adda8aad0056fa7043bfb5bada4a951b59.tar.gz |
Put yaml-cpp under yamaker
766a1eb0f14d0c936f2f5f009f3a0db57a12029e
-rw-r--r-- | contrib/libs/yaml-cpp/CONTRIBUTING.md | 26 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/README.md | 58 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/SECURITY.md | 13 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/include/yaml-cpp/contrib/anchordict.h | 40 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/include/yaml-cpp/contrib/graphbuilder.h | 149 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/src/contrib/graphbuilder.cpp | 16 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.cpp | 94 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.h | 86 | ||||
-rw-r--r-- | contrib/libs/yaml-cpp/ya.make | 17 |
9 files changed, 494 insertions, 5 deletions
diff --git a/contrib/libs/yaml-cpp/CONTRIBUTING.md b/contrib/libs/yaml-cpp/CONTRIBUTING.md new file mode 100644 index 0000000000..5705fe2bcf --- /dev/null +++ b/contrib/libs/yaml-cpp/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# Style + +This project is formatted with [clang-format][fmt] using the style file at the root of the repository. Please run clang-format before sending a pull request. + +In general, try to follow the style of surrounding code. We mostly follow the [Google C++ style guide][cpp-style]. + +Commit messages should be in the imperative mood, as described in the [Git contributing file][git-contrib]: + +> Describe your changes in imperative mood, e.g. "make xyzzy do frotz" +> instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy +> to do frotz", as if you are giving orders to the codebase to change +> its behaviour. + +[fmt]: http://clang.llvm.org/docs/ClangFormat.html +[cpp-style]: https://google.github.io/styleguide/cppguide.html +[git-contrib]: http://git.kernel.org/cgit/git/git.git/tree/Documentation/SubmittingPatches?id=HEAD + +# Tests + +Please verify the tests pass by running the target `test/yaml-cpp-tests`. + +If you are adding functionality, add tests accordingly. + +# Pull request process + +Every pull request undergoes a code review. Unfortunately, github's code review process isn't great, but we'll manage. During the code review, if you make changes, add new commits to the pull request for each change. Once the code review is complete, rebase against the master branch and squash into a single commit. diff --git a/contrib/libs/yaml-cpp/README.md b/contrib/libs/yaml-cpp/README.md new file mode 100644 index 0000000000..70c231445d --- /dev/null +++ b/contrib/libs/yaml-cpp/README.md @@ -0,0 +1,58 @@ +# yaml-cpp ![Build Status](https://github.com/jbeder/yaml-cpp/actions/workflows/build.yml/badge.svg) [![Documentation](https://codedocs.xyz/jbeder/yaml-cpp.svg)](https://codedocs.xyz/jbeder/yaml-cpp/) + +`yaml-cpp` is a [YAML](http://www.yaml.org/) parser and emitter in C++ matching the [YAML 1.2 spec](http://www.yaml.org/spec/1.2/spec.html). + +## Usage + +See [Tutorial](https://github.com/jbeder/yaml-cpp/wiki/Tutorial) and [How to Emit YAML](https://github.com/jbeder/yaml-cpp/wiki/How-To-Emit-YAML) for reference. For the old API (until 0.5.0), see [How To Parse A Document](https://github.com/jbeder/yaml-cpp/wiki/How-To-Parse-A-Document-(Old-API)). + +## Any Problems? + +If you find a bug, post an [issue](https://github.com/jbeder/yaml-cpp/issues)! If you have questions about how to use yaml-cpp, please post it on http://stackoverflow.com and tag it [`yaml-cpp`](http://stackoverflow.com/questions/tagged/yaml-cpp). + +## How to Build + +`yaml-cpp` uses [CMake](http://www.cmake.org) to support cross-platform building. Install [CMake](http://www.cmake.org) _(Resources -> Download)_ before proceeding. The basic steps to build are: + +**Note:** If you don't use the provided installer for your platform, make sure that you add `CMake`'s bin folder to your path. + +#### 1. Navigate into the source directory, create build folder and run `CMake`: + +```sh +mkdir build +cd build +cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=on|OFF] .. +``` + + * The `generator` option is the build system you'd like to use. Run `cmake` without arguments to see a full list of available generators. + * On Windows, you might use "Visual Studio 12 2013" (VS 2013 32-bits), or "Visual Studio 14 2015 Win64" (VS 2015 64-bits). + * On OS X, you might use "Xcode". + * On a UNIX-like system, omit the option (for a Makefile). + + * `yaml-cpp` builds a static library by default, you may want to build a shared library by specifying `-DYAML_BUILD_SHARED_LIBS=ON`. + + * For more options on customizing the build, see the [CMakeLists.txt](https://github.com/jbeder/yaml-cpp/blob/master/CMakeLists.txt) file. + +#### 2. Build it! + * The command you'll need to run depends on the generator you chose earlier. + +**Note:** To clean up, just remove the `build` directory. + +## Recent Releases + +[yaml-cpp 0.6.0](https://github.com/jbeder/yaml-cpp/releases/tag/yaml-cpp-0.6.0) released! This release requires C++11, and no longer depends on Boost. + +[yaml-cpp 0.3.0](https://github.com/jbeder/yaml-cpp/releases/tag/release-0.3.0) is still available if you want the old API. + +**The old API will continue to be supported, and will still receive bugfixes!** The 0.3.x and 0.4.x versions will be old API releases, and 0.5.x and above will all be new API releases. + +# API Documentation + +The autogenerated API reference is hosted on [CodeDocs](https://codedocs.xyz/jbeder/yaml-cpp/index.html) + +# Third Party Integrations + +The following projects are not officially supported: + +- [Qt wrapper](https://gist.github.com/brcha/d392b2fe5f1e427cc8a6) +- [UnrealEngine Wrapper](https://github.com/jwindgassen/UnrealYAML) diff --git a/contrib/libs/yaml-cpp/SECURITY.md b/contrib/libs/yaml-cpp/SECURITY.md new file mode 100644 index 0000000000..06a17511b9 --- /dev/null +++ b/contrib/libs/yaml-cpp/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +Security updates are applied only to the latest release. + +## Reporting a Vulnerability + +If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. + +Please disclose it at [security advisory](https://github.com/jbeder/yaml-cpp/security/advisories/new). + +This project is maintained by a team of volunteers on a reasonable-effort basis. As such, vulnerabilities will be disclosed in a best effort base. diff --git a/contrib/libs/yaml-cpp/include/yaml-cpp/contrib/anchordict.h b/contrib/libs/yaml-cpp/include/yaml-cpp/contrib/anchordict.h new file mode 100644 index 0000000000..1b7809b875 --- /dev/null +++ b/contrib/libs/yaml-cpp/include/yaml-cpp/contrib/anchordict.h @@ -0,0 +1,40 @@ +#ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include <vector> + +#include "../anchor.h" + +namespace YAML { +/** + * An object that stores and retrieves values correlating to {@link anchor_t} + * values. + * + * <p>Efficient implementation that can make assumptions about how + * {@code anchor_t} values are assigned by the {@link Parser} class. + */ +template <class T> +class AnchorDict { + public: + AnchorDict() : m_data{} {} + void Register(anchor_t anchor, T value) { + if (anchor > m_data.size()) { + m_data.resize(anchor); + } + m_data[anchor - 1] = value; + } + + T Get(anchor_t anchor) const { return m_data[anchor - 1]; } + + private: + std::vector<T> m_data; +}; +} // namespace YAML + +#endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/contrib/libs/yaml-cpp/include/yaml-cpp/contrib/graphbuilder.h b/contrib/libs/yaml-cpp/include/yaml-cpp/contrib/graphbuilder.h new file mode 100644 index 0000000000..dbffd921e6 --- /dev/null +++ b/contrib/libs/yaml-cpp/include/yaml-cpp/contrib/graphbuilder.h @@ -0,0 +1,149 @@ +#ifndef GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/mark.h" +#include <string> + +namespace YAML { +class Parser; + +// GraphBuilderInterface +// . Abstraction of node creation +// . pParentNode is always nullptr or the return value of one of the NewXXX() +// functions. +class GraphBuilderInterface { + public: + virtual ~GraphBuilderInterface() = 0; + + // Create and return a new node with a null value. + virtual void *NewNull(const Mark &mark, void *pParentNode) = 0; + + // Create and return a new node with the given tag and value. + virtual void *NewScalar(const Mark &mark, const std::string &tag, + void *pParentNode, const std::string &value) = 0; + + // Create and return a new sequence node + virtual void *NewSequence(const Mark &mark, const std::string &tag, + void *pParentNode) = 0; + + // Add pNode to pSequence. pNode was created with one of the NewXxx() + // functions and pSequence with NewSequence(). + virtual void AppendToSequence(void *pSequence, void *pNode) = 0; + + // Note that no moew entries will be added to pSequence + virtual void SequenceComplete(void *pSequence) { (void)pSequence; } + + // Create and return a new map node + virtual void *NewMap(const Mark &mark, const std::string &tag, + void *pParentNode) = 0; + + // Add the pKeyNode => pValueNode mapping to pMap. pKeyNode and pValueNode + // were created with one of the NewXxx() methods and pMap with NewMap(). + virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) = 0; + + // Note that no more assignments will be made in pMap + virtual void MapComplete(void *pMap) { (void)pMap; } + + // Return the node that should be used in place of an alias referencing + // pNode (pNode by default) + virtual void *AnchorReference(const Mark &mark, void *pNode) { + (void)mark; + return pNode; + } +}; + +// Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines +// Node, Sequence, and Map types. Sequence and Map must derive from Node +// (unless Node is defined as void). Impl must also implement function with +// all of the same names as the virtual functions in GraphBuilderInterface +// -- including the ones with default implementations -- but with the +// prototypes changed to accept an explicit Node*, Sequence*, or Map* where +// appropriate. +template <class Impl> +class GraphBuilder : public GraphBuilderInterface { + public: + typedef typename Impl::Node Node; + typedef typename Impl::Sequence Sequence; + typedef typename Impl::Map Map; + + GraphBuilder(Impl &impl) : m_impl(impl) { + Map *pMap = nullptr; + Sequence *pSeq = nullptr; + Node *pNode = nullptr; + + // Type consistency checks + pNode = pMap; + pNode = pSeq; + } + + GraphBuilderInterface &AsBuilderInterface() { return *this; } + + virtual void *NewNull(const Mark &mark, void *pParentNode) { + return CheckType<Node>(m_impl.NewNull(mark, AsNode(pParentNode))); + } + + virtual void *NewScalar(const Mark &mark, const std::string &tag, + void *pParentNode, const std::string &value) { + return CheckType<Node>( + m_impl.NewScalar(mark, tag, AsNode(pParentNode), value)); + } + + virtual void *NewSequence(const Mark &mark, const std::string &tag, + void *pParentNode) { + return CheckType<Sequence>( + m_impl.NewSequence(mark, tag, AsNode(pParentNode))); + } + virtual void AppendToSequence(void *pSequence, void *pNode) { + m_impl.AppendToSequence(AsSequence(pSequence), AsNode(pNode)); + } + virtual void SequenceComplete(void *pSequence) { + m_impl.SequenceComplete(AsSequence(pSequence)); + } + + virtual void *NewMap(const Mark &mark, const std::string &tag, + void *pParentNode) { + return CheckType<Map>(m_impl.NewMap(mark, tag, AsNode(pParentNode))); + } + virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) { + m_impl.AssignInMap(AsMap(pMap), AsNode(pKeyNode), AsNode(pValueNode)); + } + virtual void MapComplete(void *pMap) { m_impl.MapComplete(AsMap(pMap)); } + + virtual void *AnchorReference(const Mark &mark, void *pNode) { + return CheckType<Node>(m_impl.AnchorReference(mark, AsNode(pNode))); + } + + private: + Impl &m_impl; + + // Static check for pointer to T + template <class T, class U> + static T *CheckType(U *p) { + return p; + } + + static Node *AsNode(void *pNode) { return static_cast<Node *>(pNode); } + static Sequence *AsSequence(void *pSeq) { + return static_cast<Sequence *>(pSeq); + } + static Map *AsMap(void *pMap) { return static_cast<Map *>(pMap); } +}; + +void *BuildGraphOfNextDocument(Parser &parser, + GraphBuilderInterface &graphBuilder); + +template <class Impl> +typename Impl::Node *BuildGraphOfNextDocument(Parser &parser, Impl &impl) { + GraphBuilder<Impl> graphBuilder(impl); + return static_cast<typename Impl::Node *>( + BuildGraphOfNextDocument(parser, graphBuilder)); +} +} + +#endif // GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/contrib/libs/yaml-cpp/src/contrib/graphbuilder.cpp b/contrib/libs/yaml-cpp/src/contrib/graphbuilder.cpp new file mode 100644 index 0000000000..0352054cd7 --- /dev/null +++ b/contrib/libs/yaml-cpp/src/contrib/graphbuilder.cpp @@ -0,0 +1,16 @@ +#include "graphbuilderadapter.h" + +#include "yaml-cpp/parser.h" // IWYU pragma: keep + +namespace YAML { +class GraphBuilderInterface; + +void* BuildGraphOfNextDocument(Parser& parser, + GraphBuilderInterface& graphBuilder) { + GraphBuilderAdapter eventHandler(graphBuilder); + if (parser.HandleNextDocument(eventHandler)) { + return eventHandler.RootNode(); + } + return nullptr; +} +} // namespace YAML diff --git a/contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.cpp b/contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.cpp new file mode 100644 index 0000000000..c386a9277c --- /dev/null +++ b/contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.cpp @@ -0,0 +1,94 @@ +#include "graphbuilderadapter.h" +#include "yaml-cpp/contrib/graphbuilder.h" + +namespace YAML { +struct Mark; + +int GraphBuilderAdapter::ContainerFrame::sequenceMarker; + +void GraphBuilderAdapter::OnNull(const Mark &mark, anchor_t anchor) { + void *pParent = GetCurrentParent(); + void *pNode = m_builder.NewNull(mark, pParent); + RegisterAnchor(anchor, pNode); + + DispositionNode(pNode); +} + +void GraphBuilderAdapter::OnAlias(const Mark &mark, anchor_t anchor) { + void *pReffedNode = m_anchors.Get(anchor); + DispositionNode(m_builder.AnchorReference(mark, pReffedNode)); +} + +void GraphBuilderAdapter::OnScalar(const Mark &mark, const std::string &tag, + anchor_t anchor, const std::string &value) { + void *pParent = GetCurrentParent(); + void *pNode = m_builder.NewScalar(mark, tag, pParent, value); + RegisterAnchor(anchor, pNode); + + DispositionNode(pNode); +} + +void GraphBuilderAdapter::OnSequenceStart(const Mark &mark, + const std::string &tag, + anchor_t anchor, + EmitterStyle::value /* style */) { + void *pNode = m_builder.NewSequence(mark, tag, GetCurrentParent()); + m_containers.push(ContainerFrame(pNode)); + RegisterAnchor(anchor, pNode); +} + +void GraphBuilderAdapter::OnSequenceEnd() { + void *pSequence = m_containers.top().pContainer; + m_containers.pop(); + + DispositionNode(pSequence); +} + +void GraphBuilderAdapter::OnMapStart(const Mark &mark, const std::string &tag, + anchor_t anchor, + EmitterStyle::value /* style */) { + void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent()); + m_containers.push(ContainerFrame(pNode, m_pKeyNode)); + m_pKeyNode = nullptr; + RegisterAnchor(anchor, pNode); +} + +void GraphBuilderAdapter::OnMapEnd() { + void *pMap = m_containers.top().pContainer; + m_pKeyNode = m_containers.top().pPrevKeyNode; + m_containers.pop(); + DispositionNode(pMap); +} + +void *GraphBuilderAdapter::GetCurrentParent() const { + if (m_containers.empty()) { + return nullptr; + } + return m_containers.top().pContainer; +} + +void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode) { + if (anchor) { + m_anchors.Register(anchor, pNode); + } +} + +void GraphBuilderAdapter::DispositionNode(void *pNode) { + if (m_containers.empty()) { + m_pRootNode = pNode; + return; + } + + void *pContainer = m_containers.top().pContainer; + if (m_containers.top().isMap()) { + if (m_pKeyNode) { + m_builder.AssignInMap(pContainer, m_pKeyNode, pNode); + m_pKeyNode = nullptr; + } else { + m_pKeyNode = pNode; + } + } else { + m_builder.AppendToSequence(pContainer, pNode); + } +} +} // namespace YAML diff --git a/contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.h b/contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.h new file mode 100644 index 0000000000..c1cbcffdca --- /dev/null +++ b/contrib/libs/yaml-cpp/src/contrib/graphbuilderadapter.h @@ -0,0 +1,86 @@ +#ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include <cstdlib> +#include <map> +#include <stack> + +#include "yaml-cpp/anchor.h" +#include "yaml-cpp/contrib/anchordict.h" +#include "yaml-cpp/emitterstyle.h" +#include "yaml-cpp/eventhandler.h" + +namespace YAML { +class GraphBuilderInterface; +struct Mark; +} // namespace YAML + +namespace YAML { +class GraphBuilderAdapter : public EventHandler { + public: + GraphBuilderAdapter(GraphBuilderInterface& builder) + : m_builder(builder), + m_containers{}, + m_anchors{}, + m_pRootNode(nullptr), + m_pKeyNode(nullptr) {} + GraphBuilderAdapter(const GraphBuilderAdapter&) = delete; + GraphBuilderAdapter(GraphBuilderAdapter&&) = delete; + GraphBuilderAdapter& operator=(const GraphBuilderAdapter&) = delete; + GraphBuilderAdapter& operator=(GraphBuilderAdapter&&) = delete; + + virtual void OnDocumentStart(const Mark& mark) { (void)mark; } + virtual void OnDocumentEnd() {} + + virtual void OnNull(const Mark& mark, anchor_t anchor); + virtual void OnAlias(const Mark& mark, anchor_t anchor); + virtual void OnScalar(const Mark& mark, const std::string& tag, + anchor_t anchor, const std::string& value); + + virtual void OnSequenceStart(const Mark& mark, const std::string& tag, + anchor_t anchor, EmitterStyle::value style); + virtual void OnSequenceEnd(); + + virtual void OnMapStart(const Mark& mark, const std::string& tag, + anchor_t anchor, EmitterStyle::value style); + virtual void OnMapEnd(); + + void* RootNode() const { return m_pRootNode; } + + private: + struct ContainerFrame { + ContainerFrame(void* pSequence) + : pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {} + ContainerFrame(void* pMap, void* pPreviousKeyNode) + : pContainer(pMap), pPrevKeyNode(pPreviousKeyNode) {} + + void* pContainer; + void* pPrevKeyNode; + + bool isMap() const { return pPrevKeyNode != &sequenceMarker; } + + private: + static int sequenceMarker; + }; + typedef std::stack<ContainerFrame> ContainerStack; + typedef AnchorDict<void*> AnchorMap; + + GraphBuilderInterface& m_builder; + ContainerStack m_containers; + AnchorMap m_anchors; + void* m_pRootNode; + void* m_pKeyNode; + + void* GetCurrentParent() const; + void RegisterAnchor(anchor_t anchor, void* pNode); + void DispositionNode(void* pNode); +}; +} // namespace YAML + +#endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/contrib/libs/yaml-cpp/ya.make b/contrib/libs/yaml-cpp/ya.make index e5f28b57ec..937283a624 100644 --- a/contrib/libs/yaml-cpp/ya.make +++ b/contrib/libs/yaml-cpp/ya.make @@ -1,3 +1,5 @@ +# Generated by devtools/yamaker from nixpkgs 24.05. + LIBRARY() LICENSE(MIT) @@ -6,16 +8,21 @@ LICENSE_TEXTS(.yandex_meta/licenses.list.txt) VERSION(0.8.0) -ORIGINAL_SOURCE(https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz) +ORIGINAL_SOURCE(https://github.com/jbeder/yaml-cpp/archive/0.8.0.tar.gz) -NO_UTIL() +ADDINCL( + GLOBAL contrib/libs/yaml-cpp/include + contrib/libs/yaml-cpp/src +) -NO_WSHADOW() +NO_COMPILER_WARNINGS() -ADDINCL(GLOBAL contrib/libs/yaml-cpp/include) +NO_UTIL() SRCS( src/binary.cpp + src/contrib/graphbuilder.cpp + src/contrib/graphbuilderadapter.cpp src/convert.cpp src/depthguard.cpp src/directives.cpp @@ -27,9 +34,9 @@ SRCS( src/exceptions.cpp src/exp.cpp src/memory.cpp - src/nodebuilder.cpp src/node.cpp src/node_data.cpp + src/nodebuilder.cpp src/nodeevents.cpp src/null.cpp src/ostream_wrapper.cpp |