[Chapel Merge] next: Add AST node for new expressions (#17722)

Branch: refs/heads/master
Revision: 8cf8c2d
Author: dlongnecke-cray
Log Message:

Merge pull request #17722 from dlongnecke-cray/next-add-new

next: Add AST node for new expressions (#17722)

This is for compiler/next.

Add a new AST node called New which represents new expressions.
This interpretation of New is somewhat different in that New
nodes now appear only as the base expression of a call. E.g., for
the following code:

x = new r(a=b, c);

This creates a FnCall node where the called expression is new r
(which is a New node).

Shown in mockup AST:

  Lhs: Identifier(x)
  Rhs: FnCall
    calledExpr: New(r)
    args: (a=b, c)

The parser has to build New nodes in a kind of strange fashion.
Given the following rule:

new_maybe_decorated expr %prec TNEW

And the following new expression:

new r(a=b, c)

Then $2 (the expr) is actually a function call. What the parser action
does is remove the called expression from the function call (the
r part) and swap it back in for a New expression (so new r

We cannot apply new_expr in call_base_expr because new calls
actually have a lower precedence than function calls. In practice, I
don't know if this would matter based on a precursory reading of the
current grammar, but I didn't want to risk it.

Reviewed by @lydia-duncan and @mppf. Thanks!


  • [x] All compiler/next tests pass

Signed-off-by: David Longnecker dlongnecke-cray@users.noreply.github.com

Modified Files:
A compiler/next/include/chpl/uast/New.h

A compiler/next/lib/uast/New.cpp
A compiler/next/test/frontend/testParseNew.cpp
M compiler/next/include/chpl/uast/ASTClassesList.h
M compiler/next/include/chpl/uast/Builder.h
M compiler/next/lib/frontend/Parser/ParserContext.h
M compiler/next/lib/frontend/Parser/ParserContextImpl.h
M compiler/next/lib/frontend/Parser/chapel.ypp
M compiler/next/lib/frontend/Parser/parser-dependencies.h
M compiler/next/lib/uast/CMakeLists.txt
M compiler/next/test/frontend/CMakeLists.txt

Compare: https://github.com/chapel-lang/chapel/compare/e9aa84d8f388...8cf8c2d75b5d