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/slang/slang.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 34f1402b5..82bc5e478 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -14,6 +14,8 @@ #include "slang-reflection.h" #include "slang-type-layout.h" +#include "slang-ast-dump.h" + #include "slang-state-serialize.h" #include "slang-file-system.h" @@ -996,6 +998,25 @@ void FrontEndCompileRequest::parseTranslationUnit( tokens, getSink(), languageScope); + + // Let's try dumping + + if (shouldDumpAST) + { + StringBuilder buf; + SourceWriter writer(linkage->getSourceManager(), LineDirectiveMode::None); + + ASTDumpUtil::dump(translationUnit->getModuleDecl(), ASTDumpUtil::Style::Flat, &writer); + + const String& path = sourceFile->getPathInfo().foundPath; + if (path.getLength()) + { + String fileName = Path::getFileNameWithoutExt(path); + fileName.append(".slang-ast"); + + File::writeAllText(fileName, writer.getContent()); + } + } } } -- cgit v1.2.3