[Chapel Merge] Translate uAST to old AST

Branch: refs/heads/master
Revision: 4990275
Author: mppf
Log Message:

Merge pull request #17919 from mppf/translate-uast

Translate uAST to old AST

This PR adjusts the --compiler-library-parser flag to run some new
code to translate from uAST to the AST used by the production compiler.
Not all uAST classes have been translated so far but we do have calls and
function declarations.

The translation itself is implemented in the new convert-uast.cpp file.
It takes the approach of having per-type functions e.g.
convertFunction, convertVariable, ... and having these return the old
AST that they produce. Then there is a convertAST that uses the
ASTClassesList macros to dispatch to the appropriate convert* function
in the event we do not already know the type we are converting.

In working on this PR I encountered several issues with uAST that the PR
addresses:

  • this PR adjusts the astlocT type from the production compiler to be
    able to store a uAST ID which can be used to compute the source
    location. That way, the uAST frontend need not save these locations
    unless they are used & when we get to incrementally constructing the
    old AST from the uAST we can have more reuse if the source locations
    change. In order to handle this, changed the astlocT type to use
    methods for accessing the line/filename instead of fields.
  • there were problems in ID assignment and the saving of locations for
    uAST nodes. In particular the previous strategy didn't handle nested
    modules or top-level modules correctly when assigning IDs to modules.
    It was assigning the empty ID to each top-level module.
  • adjusts the very incomplete uAST dumper to store IDs in a column on
    the left to make it easier to read
  • adjusted the uAST literal support to store the text of the literal
    instead of the base
  • added some code to the compiler library to handle adding string
    escapes since the uAST strings are stored unescaped but the production
    compiler stores escaped strings
  • removed some unused code from compiler/include that was causing
    problems when compiling the uAST headers in the production compiler

Future Work:

  • add tests or a testing mode for --compiler-library-parser
  • consider renaming the --compiler-library-parser flag to, say,
    --next-frontend

Reviewed by @dlongnecke-cray - thanks!

  • [x] full local testing

    Modified Files:
    A compiler/include/convert-uast.h
    A compiler/next/include/chpl/uast/all-uast.h
    A compiler/next/include/chpl/util/string-escapes.h
    A compiler/next/lib/util/string-escapes.cpp
    A compiler/next/test/util/CMakeLists.txt
    A compiler/next/test/util/testQuoteStrings.cpp
    A compiler/passes/convert-uast.cpp
    R compiler/include/extern.h
    M compiler/AST/AstDumpToNode.cpp
    M compiler/AST/baseAST.cpp
    M compiler/AST/build.cpp
    M compiler/codegen/codegen.cpp
    M compiler/include/astlocs.h
    M compiler/include/build.h
    M compiler/include/chpl.h
    M compiler/llvm/clangUtil.cpp
    M compiler/llvm/llvmDebug.cpp
    M compiler/next/include/chpl/frontend/frontend-queries.h
    M compiler/next/include/chpl/queries/Context.h
    M compiler/next/include/chpl/queries/ID.h
    M compiler/next/include/chpl/queries/UniqueString.h
    M compiler/next/include/chpl/uast/ASTClassesList.h
    M compiler/next/include/chpl/uast/ASTNode.h
    M compiler/next/include/chpl/uast/Builder.h
    M compiler/next/include/chpl/uast/ImagLiteral.h
    M compiler/next/include/chpl/uast/IntLiteral.h
    M compiler/next/include/chpl/uast/NumericLiteral.h
    M compiler/next/include/chpl/uast/RealLiteral.h
    M compiler/next/include/chpl/uast/UintLiteral.h
    M compiler/next/lib/frontend/Parser/ParserContextImpl.h
    M compiler/next/lib/frontend/Parser/chpl.ypp
    M compiler/next/lib/frontend/Parser/parser-dependencies.h
    M compiler/next/lib/frontend/frontend-queries.cpp
    M compiler/next/lib/queries/Context.cpp
    M compiler/next/lib/queries/ID.cpp
    M compiler/next/lib/uast/ASTNode.cpp
    M compiler/next/lib/uast/Builder.cpp
    M compiler/next/lib/uast/ImagLiteral.cpp
    M compiler/next/lib/uast/IntLiteral.cpp
    M compiler/next/lib/uast/RealLiteral.cpp
    M compiler/next/lib/uast/UintLiteral.cpp
    M compiler/next/lib/util/CMakeLists.txt
    M compiler/next/lib/util/Makefile.include
    M compiler/next/test/CMakeLists.txt
    M compiler/next/test/frontend/testFrontendQueries.cpp
    M compiler/next/test/frontend/testInteractive.cpp
    M compiler/next/test/frontend/testParseNumericLiterals.cpp
    M compiler/next/test/uast/testBuildIDs.cpp
    M compiler/parser/parser.cpp
    M compiler/passes/Makefile.share
    M compiler/passes/checkParsed.cpp
    M compiler/passes/externCResolve.cpp
    M compiler/passes/scopeResolve.cpp
    M compiler/resolution/callDestructors.cpp
    M compiler/resolution/nilChecking.cpp
    M compiler/resolution/postFold.cpp
    M compiler/util/astlocs.cpp
    M compiler/util/misc.cpp

    Compare: Comparing 58b4bb62f999...4990275c880b · chapel-lang/chapel · GitHub