From 96a00c8e8d14964c8e1f45c7c3c85d321b2a1b61 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 20 May 2020 10:56:49 -0400 Subject: AST dumping via C++ Extractor reflection (#1348) * Add support for parsing array types to C++ extractor. * C++ extractor looks for 'balanced tokens'. Use for extracting array suffixes. * First pass at field dumping. * Update project for field dumping. * WIP AST Dumper. * More AST dump compiling. * Fix bug in StringSlicePool where it doesn't use the copy of the UnownedStringSlice in the map. * Add support for SLANG_RELFECTED and SLANG_UNREFLECTED More AST dump support. * Support for hierarchical dumping/flat dumping. Use SourceWriter to dump. * Add -dump-ast command line option. * Add fixes to VS project to incude AST dump. * Fix compilation on gcc. * Add fix for type ambiguity issue on x86 VS. * Fixes from merge of reducing Token size. * Fix comment about using SourceWriter. --- source/core/slang-string-slice-pool.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source/core/slang-string-slice-pool.cpp') diff --git a/source/core/slang-string-slice-pool.cpp b/source/core/slang-string-slice-pool.cpp index 24187ba5c..a0af3ba68 100644 --- a/source/core/slang-string-slice-pool.cpp +++ b/source/core/slang-string-slice-pool.cpp @@ -61,16 +61,23 @@ StringSlicePool::Handle StringSlicePool::add(const Slice& slice) bool StringSlicePool::findOrAdd(const Slice& slice, Handle& outHandle) { - Handle newHandle = Handle(m_slices.getCount()); - const Handle* handlePtr = m_map.TryGetValueOrAdd(slice, newHandle); + const Handle* handlePtr = m_map.TryGetValue(slice); if (handlePtr) { outHandle = *handlePtr; return true; } - // Need to add + // Need to add. + + // Make a copy stored in the arena UnownedStringSlice scopeSlice(m_arena.allocateString(slice.begin(), slice.getLength()), slice.getLength()); + + // Add using the arenas copy + Handle newHandle = Handle(m_slices.getCount()); + m_map.Add(scopeSlice, newHandle); + + // Add to slices list m_slices.add(scopeSlice); outHandle = newHandle; return false; -- cgit v1.2.3