From 837a155b3d33035ee0739858f4ab25c65048ad6c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 1 Mar 2021 15:37:46 -0500 Subject: Doc improvements (#1729) * #include an absolute path didn't work - because paths were taken to always be relative. * Split out AST 'printing'. * Replace listener with List
* Section -> Part. * Kind -> Type Flags -> Kind for ASTPrinter::Part * Improve comments around ASTPrinter. * toString -> toText on Val derived types. toText appends to a StringBuilder. * Added toSlice free function. Added operator<< for Val derived types. Use << where appropriate in doing toText. * More work at mark down output. * Fill in sourceloc for enum case. Add more sophisticated location determination for EnumCase. Refactored documentation output into DocMarkdownWriter. * Improvements for sig output. --- source/slang/slang.cpp | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index e02715015..21f60c090 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1639,25 +1639,7 @@ void FrontEndCompileRequest::parseTranslationUnit( } } - if (shouldDocument) - { - RefPtr markup(new DocMarkup); - markup->extract(translationUnit->getModuleDecl(), getSourceManager(), getSink()); - - // Extract to a file - const String& path = sourceFile->getPathInfo().foundPath; - if (path.getLength()) - { - String fileName = Path::getFileNameWithoutExt(path); - fileName.append(".md"); - - StringBuilder buf; - DocumentationUtil::writeMarkdown(markup, buf); - - File::writeAllText(fileName, buf); - } - } #if 0 // Test serialization @@ -1816,6 +1798,38 @@ SlangResult FrontEndCompileRequest::executeActionsInner() if (getSink()->getErrorCount() != 0) return SLANG_FAIL; + // After semantic checking is performed we can try and output doc information for this + if (shouldDocument) + { + // Not 100% clear where best to get the ASTBuilder from, but from the linkage shouldn't + // cause any problems with scoping + ASTBuilder* astBuilder = getLinkage()->getASTBuilder(); + + for (TranslationUnitRequest* translationUnit : translationUnits) + { + RefPtr markup(new DocMarkup); + + markup->extract(translationUnit->getModuleDecl(), getSourceManager(), getSink()); + + // Hmm.. we can have multiple sourcefiles. So fir now we just pick the first, so as to come up with + // a reasonable name + SourceFile* sourceFile = translationUnit->getSourceFiles()[0]; + + // Extract to a file + const String& path = sourceFile->getPathInfo().foundPath; + if (path.getLength()) + { + String fileName = Path::getFileNameWithoutExt(path); + fileName.append(".md"); + + StringBuilder buf; + DocumentationUtil::writeMarkdown(markup, astBuilder, buf); + + File::writeAllText(fileName, buf); + } + } + } + // Look up all the entry points that are expected, // and use them to populate the `program` member. // -- cgit v1.2.3