From 8f0895e0f8257da2fd10b6325931627a9a1792ba Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 11 Nov 2020 09:56:50 -0500 Subject: Include hierarchy output (#1595) * #include an absolute path didn't work - because paths were taken to always be relative. * Improve diagnostic for token pasting. * Token paste location test. * Output include hierarchy. * WIP on includes hierarchy. * Improved include hierarchy output - to handle source files without tokens. Improved test case. * Small comment improvements. Fixed a typo with not returning a reference. * Slight simplification of the ViewInitiatingHierarchy, by adding GetOrAddValue to Dictionary. * Remove the need for ViewInitiatingHierarchy type. * Improve output of path in diagnostic for includes hierarchy. * Remove comment in diagnostic for token-paste-location.slang * Update command line docs to include `-output-includes` Co-authored-by: Yong He --- source/core/slang-dictionary.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/core') diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h index 2bd58f1c6..df5ee520d 100644 --- a/source/core/slang-dictionary.h +++ b/source/core/slang-dictionary.h @@ -359,6 +359,27 @@ namespace Slang throw InvalidOperationException("Inconsistent find result returned. This is a bug in Dictionary implementation."); } + /// This differs from TryGetValueOrAdd, in that it always returns the Value held in the Dictionary. + /// If there isn't already an entry for 'key', a value is added with defaultValue. + TValue& GetOrAddValue(const TKey& key, const TValue& defaultValue) + { + Rehash(); + auto pos = FindPosition(key); + if (pos.ObjectPosition != -1) + { + return hashMap[pos.ObjectPosition].Value; + } + else if (pos.InsertionPosition != -1) + { + // Make pair + KeyValuePair kvPair(_Move(key), _Move(defaultValue)); + _count++; + return _Insert(_Move(kvPair), pos.InsertionPosition); + } + else + throw InvalidOperationException("Inconsistent find result returned. This is a bug in Dictionary implementation."); + } + bool ContainsKey(const TKey& key) const { if (bucketSizeMinusOne == -1) -- cgit v1.2.3