summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/YAMLIOTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [YAML] Quote multiline string scalarsIlya Biryukov2018-05-301-0/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Otherwise, the YAML parser breaks when trying to read them back in 'key: multiline_string_value' cases. This patch fixes a problem when serializing structs which contain multi-line strings. E.g., if we try to serialize the following struct ``` { "key1": "first line\nsecond line", "key2": "another string" }` ``` Before this patch, we got the YAML output that failed to parse: ``` key1: first line second line key2: another string ``` After the patch, we get: ``` key1: 'first line second line' key2: another string ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47468 llvm-svn: 333527
* [YAML] Remove unit test of multibyte non-printable escaping that uses C++11 ↵Graydon Hoare2018-03-271-1/+0
| | | | | | escapes llvm-svn: 328665
* [YAML] Escape non-printable multibyte UTF8 in Output::scalarString.Graydon Hoare2018-03-271-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The existing YAML Output::scalarString code path includes a partial and incorrect implementation of YAML escaping logic. In particular, the logic put in place in rL321283 escapes non-printable bytes only if they are not part of a multibyte UTF8 sequence; implicitly this means that all multibyte UTF8 sequences -- printable and non -- are passed through verbatim. The simplest solution to this is to direct the Output::scalarString method to use the standalone yaml::escape function, and this _almost_ works, except that the existing code in that function _over_ escapes: any multibyte UTF8 sequence is escaped, even printable ones. While this is permitted for YAML, it is also more aggressive (and hard to read for non-English locales) than necessary, and the entire point of rL321283 was to back off such aggressive over-escaping. So in this change, I have both redirected Output::scalarString to use yaml::escape _and_ modified yaml::escape to optionally restrict its escaping to non-printables. This preserves behaviour of any existing clients while giving them a path to more moderate escaping should they desire. Reviewers: JDevlieghere, thegameg, MatzeB, vladimir.plyashkun Reviewed By: thegameg Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D44863 llvm-svn: 328661
* [YAML] Plain scalars can not begin with most indicators.Haojian Wu2018-01-221-0/+4
| | | | | | | | | | | | | | | | | | | Summary: Discovered when clangd loads YAML symbols, some symbol documentations start with indicators (e.g. "-"), but YAML prints them as plain scalars (no quotes), which make the YAML parser fail to parse. For these kind of strings, we need quotes. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, ioeric, llvm-commits, cfe-commits Differential Revision: https://reviews.llvm.org/D42362 llvm-svn: 323097
* [YAML] Refactor escaping unittestsFrancis Visoiu Mistrih2017-12-211-111/+24
| | | | llvm-svn: 321284
* [YAML] Fix UTF-8 handlingFrancis Visoiu Mistrih2017-12-211-0/+28
| | | | | | | | Previous YAML quoting patches broke UTF-8 printing in YAML: see https://reviews.llvm.org/D41290#961801. Differential Revision: https://reviews.llvm.org/D41490 llvm-svn: 321283
* [YAML] Add support for non-printable charactersFrancis Visoiu Mistrih2017-12-181-4/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | LLVM IR function names which disable mangling start with '\01' (https://www.llvm.org/docs/LangRef.html#identifiers). When an identifier like "\01@abc@" gets dumped to MIR, it is quoted, but only with single quotes. http://www.yaml.org/spec/1.2/spec.html#id2770814: "The allowed character range explicitly excludes the C0 control block allowed), the surrogate block #xD800-#xDFFF, #xFFFE, and #xFFFF." http://www.yaml.org/spec/1.2/spec.html#id2776092: "All non-printable characters must be escaped. [...] Note that escape sequences are only interpreted in double-quoted scalars." This patch adds support for printing escaped non-printable characters between double quotes if needed. Should also fix PR31743. Differential Revision: https://reviews.llvm.org/D41290 llvm-svn: 320996
* [YAMLTraits] Add filename support to yaml::InputAlex Bradbury2017-07-171-0/+16
| | | | | | | | | | | | | | | | | | | Summary: The current yaml::Input constructor takes a StringRef of data as its first parameter, discarding any filename information that may have been present when a YAML file was opened. Add an alterate yaml::Input constructor that takes a MemoryBufferRef, which can have a filename associated with it. This leads to clearer diagnostic messages. Sponsored By: DARPA, AFRL Reviewed By: arphaman Differential Revision: https://reviews.llvm.org/D35398 Patch by: Jonathan Anderson (trombonehero) llvm-svn: 308172
* Fix ODR violations due to abuse of LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTORRichard Smith2017-06-301-14/+16
| | | | | | | | | | | | | | | | | | | | | | | | This is a short-term fix for PR33650 aimed to get the modules build bots green again. Remove all the places where we use the LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR macros to try to locally specialize a global template for a global type. That's not how C++ works. Instead, we now centrally define how to format vectors of fundamental types and of string (std::string and StringRef). We use flow formatting for the former cases, since that's the obvious right thing to do; in the latter case, it's less clear what the right choice is, but flow formatting is really bad for some cases (due to very long strings), so we pick block formatting. (Many of the cases that were using flow formatting for strings are improved by this change.) Other than the flow -> block formatting change for some vectors of strings, this should result in no functionality change. Differential Revision: https://reviews.llvm.org/D34907 Corresponding updates to clang, clang-tools-extra, and lld to follow. llvm-svn: 306878
* Re-sort #include lines for unittests. This uses a slightly modifiedChandler Carruth2017-06-061-1/+0
| | | | | | | | | | | | | | | clang-format (https://reviews.llvm.org/D33932) to keep primary headers at the top and handle new utility headers like 'gmock' consistently with other utility headers. No other change was made. I did no manual edits, all of this is clang-format. This should allow other changes to have more clear and focused diffs, and is especially motivated by moving some headers into more focused libraries. llvm-svn: 304786
* Align all scalar numbers to LLVM_YAML_IS_FLOW_SEQUENCE_VECTORJonas Hahnfeld2017-04-041-8/+8
| | | | | | | | | Otherwise, yamlize in YAMLTraits.h might be wrongly defined. This makes some AMDGPU tests fail when LLVM_LINK_LLVM_DYLIB is set. Differential Revision: https://reviews.llvm.org/D30508 llvm-svn: 299415
* Support: Add YAML I/O support for custom mappings.Peter Collingbourne2017-01-041-0/+62
| | | | | | | | This will be used to YAMLify parts of the module summary. Differential Revision: https://reviews.llvm.org/D28014 llvm-svn: 290935
* Improve error handling in YAML parsingMehdi Amini2016-11-281-0/+8
| | | | | | | | | | | | Some scanner errors were not checked and reported by the parser. Fix PR30934. Recommit r288014 after fixing unittest. Patch by: Serge Guelton <serge.guelton@telecom-bretagne.eu> Differential Revision: https://reviews.llvm.org/D26419 llvm-svn: 288071
* Revert "Improve error handling in YAML parsing"Mehdi Amini2016-11-281-8/+0
| | | | | | This reverts commit r288014, the unittest isn't passing llvm-svn: 288015
* Improve error handling in YAML parsingMehdi Amini2016-11-281-0/+8
| | | | | | | | | | | | Some scanner errors were not checked and reported by the parser. Fix PR30934 Patch by: Serge Guelton <serge.guelton@telecom-bretagne.eu> Differential Revision: https://reviews.llvm.org/D26419 llvm-svn: 288014
* [YAMLIO] Add the ability to map with context.Zachary Turner2016-09-081-0/+69
| | | | | | | | | | | | | | | | | | | | | mapping a yaml field to an object in code has always been a stateless operation. You could still pass state by using the `setContext` function of the YAMLIO object, but this represented global state for the entire yaml input. In order to have context-sensitive state, it is necessary to pass this state in at the granularity of an individual mapping. This patch adds support for this type of context-sensitive state. You simply pass an additional argument of type T to the `mapRequired` or `mapOptional` functions, and provided you have specialized a `MappingContextTraits<U, T>` class with the appropriate mapping function, you can pass this context into the mapping function. Reviewed By: chandlerc Differential Revision: https://reviews.llvm.org/D24162 llvm-svn: 280977
* [yaml] Add a ScalarTraits for mapping endian aware types.Zachary Turner2016-06-071-0/+106
| | | | | | | | | | This allows mapping of any endian-aware type whose underlying type (e.g. uint32_t) provides a ScalarTraits specialization. Reviewed by: majnemer Differential Revision: http://reviews.llvm.org/D21057 llvm-svn: 272049
* [NFC] Header cleanupMehdi Amini2016-04-181-1/+0
| | | | | | | | | | | | | | Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
* Revert r239972 (YAML: Assign a value returned by the default constructor to ↵Alex Lorenz2015-06-171-28/+0
| | | | | | | | the value in an optional mapping). This change breaks clang-format tests. llvm-svn: 239976
* YAML: Assign a value returned by the default constructor to the value in an ↵Alex Lorenz2015-06-171-0/+28
| | | | | | | | | | | | | | optional mapping. This commit ensures that a value that's passed into YAML's IO mapOptional method is going to be assigned a value returned by the default constructor for that value's type when the appropriate key is not present in the YAML mapping. Reviewers: Duncan P. N. Exon Smith Differential Revision: http://reviews.llvm.org/D10492 llvm-svn: 239972
* YAML traits need to be in the llvm::yaml namespace.Frederic Riss2015-05-291-8/+8
| | | | | | | Hope this fixes the bits, eg: http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/27147 llvm-svn: 238586
* [YAMLIO] Make line-wrapping configurable and test it.Frederic Riss2015-05-291-0/+120
| | | | | | | | | | | | | | | | Summary: We would wrap flow mappings and sequences when they go over a hardcoded 70 characters limit. Make the wrapping column configurable (and default to 70 co the change should be NFC for current users). Passing 0 allows to completely suppress the wrapping which makes it easier to handle in tools like FileCheck. Reviewers: bogner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10109 llvm-svn: 238584
* YAML: Add support for literal block scalar I/O.Alex Lorenz2015-05-141-0/+140
| | | | | | | | | | | | | This commit gives the users of the YAML Traits I/O library the ability to serialize scalars using the YAML literal block scalar notation by allowing them to implement a specialization of the `BlockScalarTraits` struct for their custom types. Reviewers: Duncan P. N. Exon Smith Differential Revision: http://reviews.llvm.org/D9613 llvm-svn: 237404
* YAML: Add an optional 'flow' field to the mapping trait to allow flow ↵Alex Lorenz2015-05-041-0/+85
| | | | | | | | | | | | | mapping output. This patch adds an optional 'flow' field to the MappingTrait class so that yaml IO will be able to output flow mappings. Reviewers: Justin Bogner Differential Revision: http://reviews.llvm.org/D9450 llvm-svn: 236456
* YAML: Fix the output of sequences that contain flow sequences. Alex Lorenz2015-05-011-0/+65
| | | | | | | | | | | | | | | | | | | | | | | This patch fixes a bug where the YAML Output class emitted a sequence of flow sequences without the '-' characters. Before: seq: [ a, b ] [ c, d ] After: seq: - [ a, b ] - [ c, d ] Reviewers: Justin Bogner Differential Revision: http://reviews.llvm.org/D9206 llvm-svn: 236329
* Detect malformed YAML sequence in yaml::Input::beginSequence()Justin Bogner2015-03-021-0/+86
| | | | | | | | | | | | | | | | | | | | | When reading a yaml::SequenceTraits object, YAMLIO does not report an error if the yaml item is not a sequence. Instead, YAMLIO reads an empty sequence. For example: --- seq: foo: 1 bar: 2 ... If `seq` is a SequenceTraits object, then reading the above yaml will yield `seq` as an empty sequence. Fix this to report an error for the above mapping ("not a sequence") Patch by William Fisher. Thanks! llvm-svn: 230976
* Fix bug 20125 - clang-format segfaults on bad config.Rafael Espindola2014-08-081-0/+7
| | | | | | | The problem was in unchecked dyn_cast inside of Input::createHNodes. Patch by Roman Kashitsyn! llvm-svn: 215205
* [C++11] Use 'nullptr'.Craig Topper2014-06-081-24/+24
| | | | llvm-svn: 210442
* Make this operator bool() explicit to match the standard library.Rafael Espindola2014-06-031-24/+24
| | | | llvm-svn: 210072
* YAMLIO: Allow scalars to dictate quotation rulesDavid Majnemer2014-04-101-0/+38
| | | | | | | Introduce ScalarTraits::mustQuote which determines whether or not a StringRef needs quoting before it is acceptable to output. llvm-svn: 205955
* Revert "Revert "YAMLIO: Encode ambiguous hex strings explicitly""David Majnemer2014-04-091-0/+10
| | | | | | | | | Don't quote octal compatible strings if they are only two wide, they aren't ambiguous. This reverts commit r205857 which reverted r205857. llvm-svn: 205914
* Revert "YAMLIO: Encode ambiguous hex strings explicitly"Filipe Cabecinhas2014-04-091-10/+0
| | | | | | | | This reverts commit r205839. It broke several tests in lld. llvm-svn: 205857
* YAMLIO: Encode ambiguous hex strings explicitlyDavid Majnemer2014-04-091-0/+10
| | | | | | | | | | YAMLIO would turn a BinaryRef into the string 0000000004000000. However, the leading zero causes parsers to interpret it as being an octal number instead of a hexadecimal one. Instead, escape such strings as needed. llvm-svn: 205839
* YAML I/O add support for validate()Nick Kledzik2013-11-211-3/+43
| | | | | | | MappingTrait template specializations can now have a validate() method which performs semantic checking. For details, see <http://llvm.org/docs/YamlIO.html>. llvm-svn: 195286
* revert r194655Nick Kledzik2013-11-211-70/+0
| | | | llvm-svn: 195285
* YAML I/O - Added default trait support for std:string. Making another ↵John Thompson2013-11-191-0/+31
| | | | | | attempt at this, this time doing a clean build on Linux, and running the LLVM, clang, and extra tests, to try to make sure there's no problems. llvm-svn: 195134
* Recover gracefully when deserializing invalid YAML input.Alexander Kornienko2013-11-181-46/+116
| | | | | | | | | Fixes http://llvm.org/PR16221, http://llvm.org/PR15927 Phabricator: http://llvm-reviews.chandlerc.com/D1236 Patch by Andrew Tulloch! llvm-svn: 195016
* remove extra semicolonNick Kledzik2013-11-141-1/+1
| | | | llvm-svn: 194658
* Add dyn_cast<> support to YAML I/O's IO classNick Kledzik2013-11-141-0/+70
| | | | llvm-svn: 194655
* Add simple support for tags in YAML I/ONick Kledzik2013-11-141-0/+85
| | | | llvm-svn: 194644
* Reverting my r193344 checkin due to build breakage.John Thompson2013-10-241-31/+0
| | | | llvm-svn: 193350
* Added std::string as a built-in type for mapping.John Thompson2013-10-241-0/+31
| | | | llvm-svn: 193344
* Re-submit r190469: YAMLIO: Fix string quoting logic.Rui Ueyama2013-09-111-0/+57
| | | | llvm-svn: 190485
* Revert "YAMLIO: Fix string quoting logic." (r190469)Hans Wennborg2013-09-111-57/+0
| | | | | | It was turning the buildbots red. llvm-svn: 190480
* Remove trailing whitespaceRui Ueyama2013-09-111-3/+3
| | | | llvm-svn: 190472
* YAMLIO: Fix string quoting logic.Rui Ueyama2013-09-111-0/+57
| | | | | | | | YAMLIO printed a string as is without quotes unless it contains a newline character. That did not suffice. We also need to quote a string if it starts with a backquote, quote, double quote or atsign, or it's the empty string. llvm-svn: 190469
* Removing a spurious semi-colon; this macro expands into a namespace.Aaron Ballman2013-08-161-1/+1
| | | | llvm-svn: 188525
* Tighten up the yamilizer so it stops eliding empty sequences if the embedded ↵Aaron Ballman2013-08-151-0/+63
| | | | | | | | empty sequence is the first key/value in a map which is itself in a sequence. Patch with help from Nick Kledzik. llvm-svn: 188508
* Replace memcpys by a static_cast and an integral promotion.Dmitri Gribenko2013-01-101-6/+4
| | | | llvm-svn: 172108
* Fix coding styleDmitri Gribenko2013-01-101-5/+3
| | | | llvm-svn: 172107
OpenPOWER on IntegriCloud