Untyped AST (uAST)

This section contains definitions declared in the chpl::uast namespace.

namespace chpl::uast

Typedefs

using ASTList = std::vector<owned<ASTNode>>

ASTList is just a list that owns some AST nodes.

Enums

enum BlockStyle

An enum representing whether a construct’s body is preceded by a keyword, a block, or both. For example:

// This would be BlockStyle::IMPLICIT:
for i in 0..15 do writeln(i);

// This would be BlockStyle::EXPLICIT:
for i in 0..15 {
  writeln(i);
}

// This would be BlockStyle::UNNECESSARY_KEYWORD_AND_BLOCK:
for i in 0..15 do {
  writeln(i);
}

Values:

enumerator IMPLICIT
enumerator EXPLICIT
enumerator UNNECESSARY_KEYWORD_AND_BLOCK
enum IntentList

A centralized list containing all intent and storage specifiers.

Values:

enumerator DEFAULT
enumerator VAR
enumerator CONST
enumerator CONST_REF
enumerator REF
enumerator IN
enumerator CONST_IN
enumerator OUT
enumerator INOUT
enumerator INDEX
enumerator PARAM
enumerator TYPE

Functions

static inline ASTList makeASTList(owned<ASTNode> ast)

Create an ASTList containing a single ast element, transferring ownership of that element to the list.

bool updateASTList(ASTList &keep, ASTList &addin)

Update an AST list with some replacement AST.

It’s kindof like swapping ‘keep’ and ‘addin’ but it tries to keep old AST nodes when they are the same. This allows for more reuse of results in the query framework.

‘keep’ is some old AST ‘addin’ is some new AST we wish to replace it with

on exit, ‘keep’ stores the AST we need to ‘keep’, and anything not kept is stored in ‘addin’. On exit, the order of nodes stored in ‘addin’ does not matter.

The function returns ‘true’ if anything changed in ‘keep’.

void markASTList(Context *context, const ASTList &keep)

Mark UniqueStrings in an AST list.

bool isExpressionASTList(const ASTList &list)

Returns true if this list only contains Expressions.

class AggregateDecl : public chpl::uast::TypeDecl
#include <AggregateDecl.h>

This is the parent class combining functionality for class, record, and union declarations.

The contained decls can be: Variable Function TupleDecl MultiDecl TypeDecl Comment

Subclassed by chpl::uast::Class, chpl::uast::Record, chpl::uast::Union

Public Functions

inline AggregateDecl(ASTTag tag, ASTList children, int attributesChildNum, Decl::Visibility vis, Decl::Linkage linkage, int linkageNameChildNum, UniqueString name, int elementsChildNum, int numElements)
virtual ~AggregateDecl() = 0
inline ASTListIteratorPair<Expression> declOrComments() const

Return a way to iterate over the contained Decls and Comments.

inline int numDeclOrComments() const

Return the number of Decls and Comments contained in this AggregateDecl.

inline const Expression *declOrComment(int i) const

Return the i’th Decl in this AggregateDecl.

inline ASTListNoCommentsIteratorPair<Decl> decls() const

Return a way to iterate over the contained Decls (ignoring Comments)

class Array : public chpl::uast::Expression
#include <Array.h>

This class represents an array expression. For example:

// Example 1:
var a = [ 1, 2, 3 ];

An array expression will never contain comments.

Public Functions

~Array() override = default
inline ASTListIteratorPair<Expression> exprs() const

Return a way to iterate over the expressions of this array.

inline int numExprs() const

Return the number of expressions in this array.

inline const Expression *expr(int i) const

Return the i’th expression in this array.

Public Static Functions

static owned<Array> build(Builder *builder, Location loc, ASTList exprs)

Create and return an Array expression.

class As : public chpl::uast::Expression
#include <As.h>

This class represents an ‘as’ expression. As expressions are used within use clauses to rename a symbol in the current scope. For example:

// Here an as clause is used to rename 'Foo' to 'X'.
use Foo as X;

Public Functions

~As() override = default
inline const Expression *symbol() const

Return the original name specified by this as expression.

inline const Identifier *rename() const

Return the rename specified by this as expression.

Public Static Functions

static owned<As> build(Builder *builder, Location loc, owned<Expression> symbol, owned<Identifier> rename)

Create and return an as expression.

template<typename CastToType>
class ASTListIterator
#include <ASTList.h>

Defines an iterator over the AST list elements. The iterator hides the ownership (it always returns a pointer e.g. ASTNode*) and casts elements to a particular type.

Public Types

using iterator_category = std::random_access_iterator_tag
using value_type = const CastToType*
using difference_type = ASTList::const_iterator::difference_type
using pointer = const CastToType**
using reference = const CastToType*&

Public Functions

ASTListIterator() = default
inline explicit ASTListIterator(ASTList::const_iterator it)
~ASTListIterator() = default
ASTListIterator<CastToType> &operator=(const ASTListIterator<CastToType> &it) = default
inline bool operator==(const ASTListIterator<CastToType> rhs) const
inline bool operator!=(const ASTListIterator<CastToType> rhs) const
inline const CastToType *operator*() const
inline const CastToType *operator->() const
inline ASTListIterator<CastToType> &operator++()
inline ASTListIterator<CastToType> operator++(int)
inline ASTListIterator<CastToType> &operator--()
inline ASTListIterator<CastToType> operator--(int)
inline ASTListIterator<CastToType> operator+(const difference_type rhs) const
inline ASTListIterator<CastToType> operator-(const difference_type rhs) const
inline difference_type operator-(const ASTListIterator<CastToType> rhs) const
inline bool operator<(const ASTListIterator<CastToType> rhs) const
inline bool operator>(const ASTListIterator<CastToType> rhs) const
inline bool operator<=(const ASTListIterator<CastToType> rhs) const
inline bool operator>=(const ASTListIterator<CastToType> rhs) const
inline const ASTListIterator<CastToType> &operator+=(const difference_type &rhs)
inline const ASTListIterator<CastToType> &operator-=(const difference_type &rhs)
inline const CastToType *operator[](const int rhs)
template<typename CastToType>
struct ASTListIteratorPair

Public Functions

inline ASTListIteratorPair(ASTList::const_iterator begin, ASTList::const_iterator end)
~ASTListIteratorPair() = default
inline ASTListIterator<CastToType> begin() const
inline ASTListIterator<CastToType> end() const
template<typename CastToType>
class ASTListNoCommentsIterator
#include <Comment.h>

Defines an iterator over the AST list elements that ignores comments. The iterator hides the ownership (it always returns a pointer e.g. ASTNode*) and casts elements to a particular type.

Public Types

using iterator_category = std::forward_iterator_tag
using value_type = const CastToType*
using difference_type = ASTList::const_iterator::difference_type
using pointer = const CastToType**
using reference = const CastToType*&

Public Functions

ASTListNoCommentsIterator() = default
inline explicit ASTListNoCommentsIterator(ASTList::const_iterator start, ASTList::const_iterator end)
~ASTListNoCommentsIterator() = default
ASTListNoCommentsIterator<CastToType> &operator=(const ASTListNoCommentsIterator<CastToType> &it) = default
inline bool operator==(const ASTListNoCommentsIterator<CastToType> rhs) const
inline bool operator!=(const ASTListNoCommentsIterator<CastToType> rhs) const
inline const CastToType *operator*() const
inline const CastToType *operator->() const
inline ASTListNoCommentsIterator<CastToType> &operator++()
inline ASTListNoCommentsIterator<CastToType> operator++(int)
inline bool operator<(const ASTListNoCommentsIterator<CastToType> rhs) const
inline bool operator>(const ASTListNoCommentsIterator<CastToType> rhs) const
inline bool operator<=(const ASTListNoCommentsIterator<CastToType> rhs) const
inline bool operator>=(const ASTListNoCommentsIterator<CastToType> rhs) const
template<typename CastToType>
struct ASTListNoCommentsIteratorPair

Public Functions

inline ASTListNoCommentsIteratorPair(ASTList::const_iterator begin, ASTList::const_iterator end)
~ASTListNoCommentsIteratorPair() = default
inline ASTListNoCommentsIterator<CastToType> begin() const
inline ASTListNoCommentsIterator<CastToType> end() const
class ASTNode
#include <ASTNode.h>

This is the base class for AST types.

Every AST class has: a tag (indicating which AST class it is) an ID (a sort of scoped location used as a key in maps) a list of child AST nodes

The list of child nodes is included in ASTNode to allow for generic tree traversals of the AST.

Functions like someAst->isCall() / someAst->toCall() are available and generated for all AST types.

std::less is defined for every AST class and it compares IDs.

Subclassed by chpl::uast::Expression

Public Functions

virtual ~ASTNode() = 0
inline ASTTag tag() const

Returns the tag indicating which ASTNode subclass this is.

inline ID id() const

Returns the ID of this AST node.

inline int numChildren() const

Returns the number of child AST nodes in the tree directly under this one.

inline ASTListIteratorPair<ASTNode> children() const

Return a way to iterate over the children.

inline const ASTNode *child(int i) const

Returns the i’th child AST node in the tree directly under this one. This function returns a “borrow” of the AST node. It is managed by this object.

inline bool contains(const ASTNode *other) const

Returns ‘true’ if this symbol contains another AST node. This is an operation on the IDs.

bool shallowMatch(const ASTNode *other) const
bool completeMatch(const ASTNode *other) const
template<typename ReturnType, typename Visitor>
inline ReturnType dispatch(Visitor &v) const

The dispatch function supports calling a method according to the tag (aka runtime type) of a uast node. It does not itself visit children of the uast node (but of course the called visit function is free to do so).

It is a template and the Visitor argument should provide functions like

MyReturnType MyVisitor::visit(const uast::Expression* ast); MyReturnType MyVisitor::visit(const uast::Variable* ast);

and these will be invoked according to C++ overload resolution (where in particular an exact match will be preferred).

It is generally necessary to specify the ReturnType when calling it, e.g.

ast->dispatch<MyReturnType>(myVisitor);

The return type currently needs to be default constructable.

template<typename Visitor>
inline void traverse(Visitor &v) const

The traverse function supports calling a method according to the tag (aka runtime type) of a uast node and calling that method also on the children of the uast node.

It is a template and the Visitor argument should provide functions like

bool MyTraverser::enter(const uast::Expression* ast); void MyTraverser::exit(const uast::Expression* ast); bool MyTraverser::enter(const uast::Variable* ast); void MyTraverser::exit(const uast::Variable* ast);

and these will be invoked according to C++ overload resolution (where in particular an exact match will be preferred).

The enter method returns whether or not the children should be visited. In particular, when visiting a node:

First, the enter method is called.
If enter returns true, the children are visited.
Then the exit method is called (whether or not enter returned true).

Unlike dispatch, this function doesn’t support returning a value.

The traverse function can be called like this:

traverse(myTraverser, ast);

Public Static Functions

static bool updateAST(owned<ASTNode> &keep, owned<ASTNode> &addin)
static void markAST(Context *context, const ASTNode *keep)
static void dump(const ASTNode *ast, int leadingSpaces = 0)
class Attributes : public chpl::uast::Expression
#include <Attributes.h>

This class represents a collection of attributes which are associated with a particular declaration.

Compiler pragmas and deprecation messages (both intended for internal use only) are both examples of attributes.

Public Types

using PragmaIterable = Iterable<std::set<PragmaTag>>

Public Functions

~Attributes() override = default
inline bool hasPragma(PragmaTag tag) const

Returns true if the given pragma is set for this attributes.

inline PragmaIterable pragmas() const

Iterate over the pragmas stored in this attributes.

inline bool isDeprecated() const

Returns true if the declaration associated with this attributes is deprecated.

inline UniqueString deprecationMessage() const

Returns a deprecation message, or the empty string if it is not set.

Public Static Functions

static owned<Attributes> build(Builder *builder, Location loc, std::set<PragmaTag> pragmas, bool isDeprecated, UniqueString deprecationMessage)
class Begin : public chpl::uast::SimpleBlockLike
#include <Begin.h>

This class represents a begin statement. For example:

// Example 1:
var x = 0;
begin {
  writeln(x);
}

Public Functions

inline const WithClause *withClause() const

Returns the with clause of this begin statement, or nullptr if there is none.

Public Static Functions

static owned<Begin> build(Builder *builder, Location loc, owned<WithClause> withClause, BlockStyle blockStyle, ASTList stmts)

Create and return a begin statement.

class Block : public chpl::uast::SimpleBlockLike
#include <Block.h>

This class represents a { } block.

Public Functions

~Block() override = default

Public Static Functions

static owned<Block> build(Builder *builder, Location loc, ASTList stmts)

Create and return a Block containing the passed stmts.

class BoolLiteral : public chpl::uast::Literal
#include <BoolLiteral.h>

This class represents a boolean literal.

Public Functions

~BoolLiteral() override = default
inline bool value() const

Returns the value of this bool literal.

Public Static Functions

static owned<BoolLiteral> build(Builder *builder, Location loc, bool value)

Create and return a BoolLiteral.

class BracketLoop : public chpl::uast::IndexableLoop
#include <BracketLoop.h>

This class represents a bracket loop. For example:

// Example 1:
[i in 0..15] writeln(i);

Public Functions

~BracketLoop() override = default

Public Static Functions

static owned<BracketLoop> build(Builder *builder, Location loc, owned<Decl> index, owned<Expression> iterand, owned<WithClause> withClause, BlockStyle blockStyle, owned<Block> body, bool isExpressionLevel)

Create and return a bracket loop.

class Break : public chpl::uast::Expression
#include <Break.h>

This class represents a break statement. For example:

var i = 0;
while true {
  if i >= 16 then break;
  writeln(i);
  i += 1;
}

Public Functions

inline const Identifier *target() const

Returns the target of this break statement, or nullptr if there is none.

Public Static Functions

static owned<Break> build(Builder *builder, Location loc, owned<Identifier> target)

Create and return a break statement.

class Builder
#include <Builder.h>

This class helps to build AST. It should only build AST from one file at a time.

Public Functions

inline Context *context() const
void addToplevelExpression(owned<Expression> e)

Save a toplevel expression in to the builder. This is called by the parser.

void addError(ErrorMessage)

Save an error.

void noteLocation(ASTNode *ast, Location loc)

Record the location of an AST element.

BuilderResult result()

Assign IDs to all of the AST elements added as toplevel expressions to this builder and return the result. This function clears these elements from the builder and it becomes empty.

Public Static Functions

static owned<Builder> build(Context *context, const char *filepath)
static bool astTagIndicatesNewIdScope(asttags::ASTTag tag)

Certain uAST nodes, - Function, Module, Class, Record, Union, Enum - all create a new ID scope. This function returns true for AST tags with this property.

class BuilderResult
#include <BuilderResult.h>

This type records the result of building some AST.

Public Types

using ErrorIterable = Iterable<std::vector<ErrorMessage>>

Public Functions

BuilderResult()

Construct an empty BuilderResult

BuilderResult(UniqueString filePath)

Construct a BuilderResult that records a particular file path.

inline UniqueString filePath() const

Return the file path this result refers to

inline int numTopLevelExpressions() const

return the number of top-level expressions

inline const ASTNode *topLevelExpression(int i) const

return the i’th top-level expression

inline ASTListIteratorPair<ASTNode> topLevelExpressions() const

iterate over the parsed top-level expressions

inline const Module *singleModule()

If the top-level expressions contain only a single Module, return it. Otherwise, return nullptr.

inline int numErrors() const

return the number of errors

inline const ErrorMessage &error(int i) const

return the i’th error

inline ErrorIterable errors() const

Iterate over the errors.

const ASTNode *idToAst(ID id) const

Find the ASTNode* corresponding to a particular ID, or return nullptr if there is not one in this result.

Location idToLocation(ID id, UniqueString path) const

Find the Location for a particular ID. Returns a location just to path if none is found.

ID idToParentId(ID id) const

Find the ID for a parent given an ID. Returns the empty ID if none is found

BuilderResult(BuilderResult&&) = default
BuilderResult(const BuilderResult&) = delete
BuilderResult &operator=(const BuilderResult&) = delete
void swap(BuilderResult &other)

Public Static Functions

static bool update(BuilderResult &keep, BuilderResult &addin)
static void mark(Context *context, const BuilderResult &keep)
class BytesLiteral : public chpl::uast::StringLikeLiteral
#include <BytesLiteral.h>

This class represents a bytes literal, for example b"hello" and b’’ bytes contents here ‘’’`.

Public Functions

~BytesLiteral() override = default
inline UniqueString str() const

Returns the value of this bytes literal as a UniqueString which does not include the quotes.

Public Static Functions

static owned<BytesLiteral> build(Builder *builder, Location loc, const std::string &value, StringLikeLiteral::QuoteStyle quotes)
class Call : public chpl::uast::Expression
#include <Call.h>

This abstract class represents something call-like. It represents a called expression as well as a number of actuals.

For example f(1,2), f is the called expression and 1, 2 are the actuals.

Subclassed by chpl::uast::FnCall, chpl::uast::OpCall, chpl::uast::PrimCall, chpl::uast::Reduce, chpl::uast::Scan, chpl::uast::Tuple, chpl::uast::Zip

Public Functions

virtual ~Call() override = 0
inline ASTListIteratorPair<Expression> actuals() const

Returns an iterable expression over the actuals of a call.

inline int numActuals() const
inline const Expression *actual(int i) const
inline const Expression *calledExpression() const

Returns the called expression, or nullptr if there is not for this call.

Note that some subclasses of Call will never have a called expression and will always return nullptr from this function.

class Catch : public chpl::uast::Expression
#include <Catch.h>

This class represents a catch block. For example:

try {
  someCallThatWillThrow();
} catch {
  writeln('Error!');
}

Public Functions

~Catch() override = default
inline const Variable *error() const

Returns the error handled by this catch, or nullptr if there is none.

inline const Block *body() const

Return the block containing the body of this catch.

inline ASTListIteratorPair<Expression> stmts() const

Iterate over the statements contained in the body of this catch.

inline int numStmts() const

Return the number of statements contained in the body of this catch.

inline const Expression *stmt(int i) const

Return the i’th statement contained in the body of this catch.

inline bool hasParensAroundError() const

Return true if the error of this catch block has parens arounds its declaration.

Public Static Functions

static owned<Catch> build(Builder *builder, Location loc, owned<Variable> error, owned<Block> body, bool hasParensAroundError)

Create and return a catch.

class Class : public chpl::uast::AggregateDecl
#include <Class.h>

This class represents a class declaration. For example:

class MyClass : ParentClass {
  var a: int;
  proc method() { }
}

The class itself (MyClass) is represented by a Class AST node.

Public Functions

~Class() override = default
inline const Expression *parentClass() const

Return the Expression indicating the parent class or nullptr if there was none.

Public Static Functions

static owned<Class> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, UniqueString name, owned<Expression> parentClass, ASTList contents)
class Cobegin : public chpl::uast::Expression
#include <Cobegin.h>

This class represents a cobegin statement. For example:

// Example 1:
var x = 0;
cobegin {
  writeln(x);
}

Public Functions

inline const WithClause *withClause() const

Returns the with clause of this cobegin statement, or nullptr if there is none.

inline ASTListIteratorPair<Expression> taskBodies() const

Return a way to iterate over the task bodies.

inline int numTaskBodies() const

Return the number of task bodies in this.

inline const Expression *taskBody(int i) const

Return the i’th task body in this.

Public Static Functions

static owned<Cobegin> build(Builder *builder, Location loc, owned<WithClause> withClause, ASTList taskBodies)

Create and return a cobegin statement.

class Coforall : public chpl::uast::IndexableLoop
#include <Coforall.h>

This class represents a coforall loop. For example:

// Example 1:
coforall i in 0..15 {
  writeln(i);
}

Public Functions

~Coforall() override = default

Public Static Functions

static owned<Coforall> build(Builder *builder, Location loc, owned<Decl> index, owned<Expression> iterand, owned<WithClause> withClause, BlockStyle blockStyle, owned<Block> body)

Create and return a coforall loop.

class Comment : public chpl::uast::Expression
#include <Comment.h>

This class represents a comment that might be used for documentation. Not all comments are represented in the AST (since the comments could go anywhere and that would be hard to represent). However, comments that are at a statement level will be represented with this type.

Public Functions

~Comment() override = default
inline const char *c_str() const

Returns the contents of this comment, including the comment characters (e.g. //) as a C string.

inline const std::string &str() const

Returns the contents of this comment, including the comment characters (e.g. //) as a C++ string.

Public Static Functions

static owned<Comment> build(Builder *builder, Location loc, std::string c)
class Conditional : public chpl::uast::Expression
#include <Conditional.h>

This class represents a conditional. For example:

// Example 1:
const flag = false;
if flag then writeln('a'); else writeln('b');

Public Functions

~Conditional() override = default
inline const Expression *condition() const

Get the condition of this conditional.

inline const Block *thenBlock() const

Return the Block containing the then statements.

inline ASTListIteratorPair<Expression> thenStmts() const

Iterate over the statements in the then block of this conditional.

inline int numThenStmts() const

Get the number of statements in the then block of this conditional.

inline const Expression *thenStmt(int i) const

Get the i’th statement in the then block of this conditional.

inline BlockStyle thenBlockStyle() const

Returns the block style of the then block of this conditional.

inline bool hasElseBlock() const

Returns true if this conditional has an else block.

inline const Block *elseBlock() const

Return the Block containing the else statements, or nullptr if this Conditional has no else.

inline ASTListIteratorPair<Expression> elseStmts() const

Iterate over the statements in the else block of this conditional.

inline int numElseStmts() const

Get the number of statements in the else block of this conditional. If there is no else block, returns 0.

inline const Expression *elseStmt(int i) const

Get the i’th statement in the else block of this conditional. It is an error to call this function if there is no else block.

inline BlockStyle elseBlockStyle() const

Returns the block style of the else block of this conditional.

inline bool isExpressionLevel() const

Return true if this conditional is at an expression level.

Public Static Functions

static owned<Conditional> build(Builder *builder, Location loc, owned<Expression> condition, BlockStyle thenBlockStyle, owned<Block> thenBlock, BlockStyle elseBlockStyle, owned<Block> elseBlock, bool isExpressionLevel)

Create and return a conditional.

static owned<Conditional> build(Builder *builder, Location loc, owned<Expression> condition, BlockStyle thenBlockStyle, owned<Block> thenBlock, bool isExpressionLevel)

Create and return a conditional without an else block.

class Continue : public chpl::uast::Expression
#include <Continue.h>

This class represents a continue statement. For example:

for i in 0..15 {
  if !(i % 2) then continue;
  writeln(i);
}

Public Functions

inline const Identifier *target() const

Returns the target of this continue statement, or nullptr if there is none.

Public Static Functions

static owned<Continue> build(Builder *builder, Location loc, owned<Identifier> target)

Create and return a continue statement.

class CStringLiteral : public chpl::uast::StringLikeLiteral
#include <CStringLiteral.h>

This class represents a C string literal, for example c"hello".

Public Functions

~CStringLiteral() override = default
inline UniqueString str() const

Returns the value of this c string literal as a UniqueString which does not include the quotes.

Public Static Functions

static owned<CStringLiteral> build(Builder *builder, Location loc, const std::string &value, StringLikeLiteral::QuoteStyle quotes)
class Decl : public chpl::uast::Expression
#include <Decl.h>

This is an abstract base class for declarations. Note that most Decls inherit from NamedDecl, however these declarations might be contained in MultiDecl or TupleDecl.

Subclassed by chpl::uast::ForwardingDecl, chpl::uast::MultiDecl, chpl::uast::NamedDecl, chpl::uast::TupleDecl

Public Types

enum Visibility

Values:

enumerator DEFAULT_VISIBILITY
enumerator PUBLIC
enumerator PRIVATE
enum Linkage

Values:

enumerator DEFAULT_LINKAGE
enumerator EXTERN
enumerator EXPORT

Public Functions

virtual ~Decl() = 0
inline Visibility visibility() const

Return the visibility of this declaration, e.g. “PUBLIC” or “PRIVATE”.

inline Linkage linkage() const

Return the linkage of this declaration, e.g. “EXTERN” or “EXPORT”.

inline const Expression *linkageName() const

Return the linkage name expression, e.g. “f_c_name” in the below, or nullptr if there is none.

extern "f_c_name" proc f(arg) { }

inline const Attributes *attributes() const

Return the attributes associated with this declaration, or nullptr if none exist.

class Defer : public chpl::uast::SimpleBlockLike
#include <Defer.h>

This class represents a defer block. For example:

// Example 1:
proc deferExample() {
  defer {
    writeln('bar');
  }
  writeln('foo');
}
deferExample();

This code will write ‘bar’ after ‘foo’ due to use of the defer block.

Public Functions

~Defer() override = default

Public Static Functions

static owned<Defer> build(Builder *builder, Location loc, BlockStyle blockStyle, ASTList stmts)

Create and return a Defer containing the passed stmts.

class Delete : public chpl::uast::Expression
#include <Delete.h>

This class represents a delete statement. For example:

// Example 1:
var c = new unmanaged C();
delete c;

Public Functions

inline ASTListIteratorPair<Expression> exprs() const

Return a way to iterate over the expressions of this delete statement.

inline int numExprs() const

Return the number of expressions in this delete statement.

inline const Expression *expr(int i) const

Return the i’th expression in this delete statement.

Public Static Functions

static owned<Delete> build(Builder *builder, Location loc, ASTList exprs)

Create and return a delete statement.

class Domain : public chpl::uast::Expression
#include <Domain.h>

This class represents a domain expression. For example:

// Example 1:
var d = { 'foo', 'bar', 'baz' };

A domain expression will never contain comments.

Public Functions

~Domain() override = default
inline ASTListIteratorPair<Expression> exprs() const

Return a way to iterate over the expressions of this domain.

inline int numExprs() const

Return the number of expressions in this domain.

inline const Expression *expr(int i) const

Return the i’th expression in this domain.

Public Static Functions

static owned<Domain> build(Builder *builder, Location loc, ASTList exprs)

Create and return a Domain expression.

class Dot : public chpl::uast::Expression
#include <Dot.h>

This class represents a dot expression. A dot expression might be:

a method call field access qualified access within a module or enum

For example, a.b, this.type, Module.myFunc are dot expressions.

Consider myObject.myMethod(), or x.f(a=3). These are method calls that also involve Dot expressions. These are represented as an FnCall containing a Dot expression. For example, for x.f(a=3), it is represented as

FnCall(calledExpression=x.f, actuals=[3], names=[a]);

where the x.f is a Dot expression.

Public Functions

~Dot() override = default
inline const Expression *receiver() const

Returns the left-hand-side of the Dot expression

inline UniqueString field() const

Returns the name of the field or method accessed by the Dot expression

Public Static Functions

static owned<Dot> build(Builder *builder, Location loc, owned<Expression> receiver, UniqueString fieldName)
class DoWhile : public chpl::uast::Loop
#include <DoWhile.h>

This class represents a do-while loop. For example:

// Example 1:
var i = 0;
do {
  writeln(i);
  i += 1;
} while i < 5;

Public Functions

~DoWhile() override = default
inline const Expression *condition() const

Return the condition of this do-while loop.

Public Static Functions

static owned<DoWhile> build(Builder *builder, Location loc, BlockStyle blockStyle, owned<Block> body, owned<Expression> condition)

Create and return a do-while loop.

class Enum : public chpl::uast::TypeDecl
#include <Enum.h>

This class represents an enum declaration. For example:

enum myEnum { a, b = 2, c }

The enum itself (myEnum) is represented by an Enum AST node. The Enum AST node contains EnumElementDecls which contain the EnumElements (for a, b, c in the example).

Public Functions

~Enum() override = default
inline ASTListIteratorPair<Expression> declOrComments() const

Return a way to iterate over the EnumElements and Comments.

inline int numDeclOrComments() const

Return the number of EnumElements and Comments contained in this Enum.

inline const Expression *declOrComment(int i) const

Return the i’th EnumElement or Comment in this Enum.

inline ASTListNoCommentsIteratorPair<EnumElement> enumElements() const

Return a way to iterate over the EnumElements (ignoring Comments)

Public Static Functions

static owned<Enum> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, UniqueString name, ASTList stmts)
class EnumElement : public chpl::uast::NamedDecl
#include <EnumElement.h>

This class represents an element in an enum. For example, a, b, c in the below are EnumElements.

enum myEnum { a, b = 2, c }

Public Functions

~EnumElement() override = default
inline const Expression *initExpression() const

Returns the init expression for this EnumElement or nullptr if there was none.

Public Static Functions

static owned<EnumElement> build(Builder *builder, Location loc, owned<Attributes> attributes, UniqueString name, owned<Expression> initExpression)
static owned<EnumElement> build(Builder *builder, Location loc, owned<Attributes> attributes, UniqueString name)
class ErroneousExpression : public chpl::uast::Expression
#include <ErroneousExpression.h>

This class represents some missing AST due to an error.

Public Functions

~ErroneousExpression() = default

Public Static Functions

static owned<ErroneousExpression> build(Builder *builder, Location loc)
class Expression : public chpl::uast::ASTNode
#include <Expression.h>

This is an abstract base class for expressions

Subclassed by chpl::uast::Array, chpl::uast::As, chpl::uast::Attributes, chpl::uast::Break, chpl::uast::Call, chpl::uast::Catch, chpl::uast::Cobegin, chpl::uast::Comment, chpl::uast::Conditional, chpl::uast::Continue, chpl::uast::Decl, chpl::uast::Delete, chpl::uast::Domain, chpl::uast::Dot, chpl::uast::ErroneousExpression, chpl::uast::ExternBlock, chpl::uast::Identifier, chpl::uast::Import, chpl::uast::Label, chpl::uast::Literal, chpl::uast::Loop, chpl::uast::New, chpl::uast::Range, chpl::uast::Return, chpl::uast::Select, chpl::uast::SimpleBlockLike, chpl::uast::Throw, chpl::uast::Try, chpl::uast::TypeQuery, chpl::uast::Use, chpl::uast::VisibilityClause, chpl::uast::WithClause, chpl::uast::Yield

Public Functions

virtual ~Expression() = 0
class ExternBlock : public chpl::uast::Expression
#include <ExternBlock.h>

This class represents an extern block. For example:

extern {
  int cAdd(int a, int b) {
    return a + b;
  }

  writeln(cAdd(2, 2));
}

Public Functions

~ExternBlock() override = default
inline const std::string &code() const

Public Static Functions

static owned<ExternBlock> build(Builder *builder, Location loc, std::string code)

Create and return an ExternBlock with the given C code.

class FnCall : public chpl::uast::Call
#include <FnCall.h>

This class represents a call to a function.

For example f(1,2), is a call to a function f.

Note that calls to paren-less free functions are not represented with this type since early in compilation they are just Identifiers.

For example, in

proc x { }

x; // here 'x' is represented as an Identifier, not as a Call

Public Functions

~FnCall() override = default
inline bool isNamedActual(int i) const

Returns whether actual i is named as with ‘f(a=3)’ where the actual is 3 and the name is ‘a’.

inline UniqueString actualName(int i) const

Returns the name of the actual, if used; otherwise the empty string

inline bool callUsedSquareBrackets() const

Returns true if the call used square brackets e.g. f[1]; the alternative is parentheses e.g. f(1).

Public Static Functions

static owned<FnCall> build(Builder *builder, Location loc, owned<Expression> calledExpression, ASTList actuals, std::vector<UniqueString> actualNames, bool callUsedSquareBrackets)
static owned<FnCall> build(Builder *builder, Location loc, owned<Expression> calledExpression, ASTList actuals, bool callUsedSquareBrackets)
static owned<FnCall> build(Builder *builder, Location loc, owned<Expression> calledExpression, bool callUsedSquareBrackets)
class For : public chpl::uast::IndexableLoop
#include <For.h>

This class represents a for loop. For example:

// Example 1:
for i in myRange {
  var x;
}

Public Functions

~For() override = default
inline bool isParam() const

Returns true if this for loop is param.

Public Static Functions

static owned<For> build(Builder *builder, Location loc, owned<Decl> index, owned<Expression> iterand, BlockStyle blockStyle, owned<Block> body, bool isExpressionLevel, bool isParam)

Create and return a for loop.

class Forall : public chpl::uast::IndexableLoop
#include <Forall.h>

This class represents a forall loop. For example:

// Example 1:
var x: atomic int;
forall i in myRange {
  x.fetchAdd(i);
}

Public Functions

~Forall() override = default

Public Static Functions

static owned<Forall> build(Builder *builder, Location loc, owned<Decl> index, owned<Expression> iterand, owned<WithClause> withClause, BlockStyle blockStyle, owned<Block> body, bool isExpressionLevel)

Create and return a forall loop.

class Foreach : public chpl::uast::IndexableLoop
#include <Foreach.h>

This class represents a foreach loop. For example:

// Example 1:
var x: atomic int;
foreach i in myRange with (ref x) {
  x.fetchAdd(i);
}

Public Functions

~Foreach() override = default

Public Static Functions

static owned<Foreach> build(Builder *builder, Location loc, owned<Decl> index, owned<Expression> iterand, owned<WithClause> withClause, BlockStyle blockStyle, owned<Block> body)

Create and return a foreach loop.

class Formal : public chpl::uast::VarLikeDecl
#include <Formal.h>

This class represents a formal. For example, x is a formal in the below:

proc f( x ) { }

The Formals are stored inside of a Function.

Public Types

enum Intent

Values:

enumerator DEFAULT_INTENT
enumerator CONST
enumerator CONST_REF
enumerator REF
enumerator IN
enumerator CONST_IN
enumerator OUT
enumerator INOUT
enumerator PARAM
enumerator TYPE

Public Functions

~Formal() override = default
inline Intent intent() const

Returns the intent of the formal, e.g. in proc f(const ref y: int), the formal y has intent const ref.

Public Static Functions

static owned<Formal> build(Builder *builder, Location loc, owned<Attributes> attributes, UniqueString name, Formal::Intent intent, owned<Expression> typeExpression, owned<Expression> initExpression)
class ForwardingDecl : public chpl::uast::Decl
#include <ForwardingDecl.h>

This class represents a forwarding statement. Forwarding allows a record or class to specify that certain method calls will be forwarded to a particular expression.

record MyCircle {
  forwarding var impl: MyCircleImpl;
}

record MyCircle {
  var impl: MyCircleImpl;
  forwarding impl except area;
}

The forwarding statement stores an expression that is either a VisibilityClause, a FnCall, or a Variable.

Public Functions

~ForwardingDecl() override = default
inline const Expression *expr() const

Returns the child for this ForwardingDecl or nullptr if there was none.

Public Static Functions

static owned<ForwardingDecl> build(Builder *builder, Location loc, owned<Attributes> attributes, owned<Expression> expr)
static owned<ForwardingDecl> build(Builder *builder, Location loc, owned<Attributes> attributes, owned<Expression> expr, Decl::Visibility visibility)
class Function : public chpl::uast::NamedDecl
#include <Function.h>

This class represents a function. For example:

proc f(arg) { }

proc g(x: int = 32) where something() { }

iter myiter() { }

operator =(ref lhs, rhs) { }

each of these is a Function.

Public Types

enum Kind

Values:

enumerator PROC
enumerator ITER
enumerator OPERATOR
enum ReturnIntent

Values:

enumerator DEFAULT_RETURN_INTENT
enumerator CONST
enumerator CONST_REF
enumerator REF
enumerator PARAM
enumerator TYPE

Public Functions

~Function() override = default
inline Kind kind() const
inline ReturnIntent returnIntent() const
inline bool isInline() const
inline bool isOverride() const
inline bool throws() const
inline bool isPrimaryMethod() const
inline bool isParenless() const
inline ASTListIteratorPair<Decl> formals() const

Return a way to iterate over the formals, including the method receiver, if present, as the first formal. This iterator may yield nodes of type Formal, TupleDecl, or VarArgFormal.

inline int numFormals() const

Return the number of Formals

inline const Decl *formal(int i) const

Return the i’th formal

inline const Formal *thisFormal() const

Returns the Formal for the ‘this’ formal argument, or ‘nullptr’ if there is none.

inline bool isMethod() const

Returns ‘true’ if this Function represents a method.

inline const Expression *returnType() const

Returns the expression for the return type or nullptr if there was none.

inline const Expression *whereClause() const

Returns the expression for the where clause or nullptr if there was none.

inline ASTListIteratorPair<Expression> lifetimeClauses() const

Return a way to iterate over the lifetime clauses.

inline int numLifetimeClauses() const

Return the number of lifetime clauses

inline const Expression *lifetimeClause(int i) const

Return the i’th lifetime clause

inline const Block *body() const

Return the function’s body, or nullptr if there is none.

inline ASTListIteratorPair<Expression> stmts() const

Return a way to iterate over the statements in the function body.

inline int numStmts() const

Return the number of statements in the function body or 0 if there is no function body.

inline const Expression *stmt(int i) const

Return the i’th statement in the function body. It is an error to call this function if there isn’t one.

Public Static Functions

static owned<Function> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, Decl::Linkage linkage, owned<Expression> linkageName, UniqueString name, bool inline_, bool override_, Function::Kind kind, owned<Formal> receiver, Function::ReturnIntent returnIntent, bool throws, bool primaryMethod, bool parenless, ASTList formals, owned<Expression> returnType, owned<Expression> where, ASTList lifetime, owned<Block> body)
class Identifier : public chpl::uast::Expression
#include <Identifier.h>

This class represents a reference to a symbol by name. E.g. in

var x = 1; // here, 'x' is not an Identifier (it is the declared symbol)
f(x);      // here, 'f' and 'x' are Identifiers

Public Functions

~Identifier() override = default
inline UniqueString name() const

Public Static Functions

static owned<Identifier> build(Builder *builder, Location loc, UniqueString name)
class ImagLiteral : public chpl::uast::NumericLiteral<double, types::RealParam>
#include <ImagLiteral.h>

This class represents an imaginary floating point literal, e.g. 10.4i.

Public Functions

~ImagLiteral() override = default

Public Static Functions

static owned<ImagLiteral> build(Builder *builder, Location loc, double value, UniqueString text)
class Import : public chpl::uast::Expression
#include <Import.h>

This class represents an import statement. For example:

// Example 1:
import Foo, Bar as A;

This creates an import statement that has two visibility clauses, ‘Foo’ and ‘Bar as A’.

Public Functions

inline Decl::Visibility visibility() const

Return the visibility of this import statement.

inline ASTListIteratorPair<VisibilityClause> visibilityClauses() const

Return a way to iterate over the visibility clauses.

inline int numVisibilityClauses() const

Return the number of visibility clauses in this import statement.

inline const VisibilityClause *visibilityClause(int i) const

Return the i’th visibility clause in this import statement.

Public Static Functions

static owned<Import> build(Builder *builder, Location loc, Decl::Visibility visibility, ASTList visibilityClauses)

Create and return an import statement.

class IndexableLoop : public chpl::uast::Loop
#include <IndexableLoop.h>

This abstract class represents an indexable loop.

Subclassed by chpl::uast::BracketLoop, chpl::uast::Coforall, chpl::uast::For, chpl::uast::Forall, chpl::uast::Foreach

Public Functions

virtual ~IndexableLoop() override = 0
inline const Decl *index() const

Returns the index declaration of this indexable loop, or nullptr if there is none.

inline const Expression *iterand() const

Returns the iterand of this indexable loop.

inline const WithClause *withClause() const

Returns the with clause of this indexable loop, or nullptr if there is none.

inline bool isExpressionLevel() const

Returns true if this indexable loop appears at the expression level.

class IntLiteral : public chpl::uast::NumericLiteral<int64_t, types::IntParam>
#include <IntLiteral.h>

This class represents a signed integer literal. All integer literals that are not too big are signed integer literals, i.e. have the type int. However there are no negative literals. Negative numbers are created by applying the unary - operator.

Public Functions

~IntLiteral() override = default

Public Static Functions

static owned<IntLiteral> build(Builder *builder, Location loc, int64_t value, UniqueString text)
class Label : public chpl::uast::Expression
#include <Label.h>

This class represents a label. For example:

label outer for i in 0..15 do
  label inner while true do
    if i == 12 then break outer; else break inner;

Public Functions

~Label() override = default
inline const Loop *loop() const

Return the loop of this label statement.

inline UniqueString name() const

Return the name of this label statement.

Public Static Functions

static owned<Label> build(Builder *builder, Location loc, UniqueString name, owned<Loop> loop)

Create and return a label statement.

class Literal : public chpl::uast::Expression
#include <Literal.h>

This is an abstract base class for literals. Literals are fixed values in the source code, like 1, 30.24, and “x”.

Subclassed by chpl::uast::BoolLiteral, chpl::uast::NumericLiteral< ValueT, ParamT >, chpl::uast::StringLikeLiteral, chpl::uast::NumericLiteral< double, types::RealParam >, chpl::uast::NumericLiteral< int64_t, types::IntParam >, chpl::uast::NumericLiteral< uint64_t, types::UintParam >

Public Functions

virtual ~Literal() = 0
inline const types::Param *param() const

Returns the value stored in this Literal as a types::Param.

class Local : public chpl::uast::SimpleBlockLike
#include <Local.h>

This class represents a local statement. For example:

// Example 1:
const flag = true;
local flag {
  var x = 0;
  writeln(x);
}

// Example 2:
var x = 0;
local do writeln(x);

Public Functions

inline const Expression *condition() const

Returns the condition of this local statement, or nullptr if there is none.

Public Static Functions

static owned<Local> build(Builder *builder, Location loc, BlockStyle blockStyle, ASTList stmts)

Create and return a local statement containing the passed statements.

static owned<Local> build(Builder *builder, Location loc, owned<Expression> condition, BlockStyle blockStyle, ASTList stmts)

Create and return a local statement with the given condition and containing the passed statements.

class Loop : public chpl::uast::Expression
#include <Loop.h>

This abstract class represents some sort of loop.

Subclassed by chpl::uast::DoWhile, chpl::uast::IndexableLoop, chpl::uast::While

Public Functions

virtual ~Loop() override = 0
inline const Block *body() const
inline ASTListIteratorPair<Expression> stmts() const

Return a way to iterate over the statements of this loop.

inline int numStmts() const

Return the number of statements in the loop.

inline const Expression *stmt(int i) const

Return the i’th statement in the loop.

inline BlockStyle blockStyle() const

Returns the block style of the current loop.

class Module : public chpl::uast::NamedDecl
#include <Module.h>

This class represents a module declaration. For example:

module M { }

is a declaration for a module named M.

Public Types

enum Kind

Values:

enumerator DEFAULT_MODULE_KIND
enumerator PROTOTYPE
enumerator IMPLICIT

Public Functions

~Module() override = default
inline Kind kind() const

Return the kind of this module (e.g. ‘PROTOTYPE’ or ‘IMPLICIT’);

inline ASTListIteratorPair<Expression> stmts() const

Iterate over the statements in this module.

inline int numStmts() const

Return the number of statements in this module.

inline const Expression *stmt(int i) const

Get the i’th statement in this module.

Public Static Functions

static owned<Module> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, UniqueString name, Module::Kind kind, ASTList stmts)
class MultiDecl : public chpl::uast::Decl
#include <MultiDecl.h>

This class represents a declaration for multiple variables.

E.g.

var a, b:int, c, d = 1;
var x: int, y = 3, z: real;

Each of the lines above is represented by a MultiDecl containing a list of VariableDecls. Note that the initial value and/or type is inferred from later declarations.

Since the MultiDecl does not itself have a name, it is not a NamedDecl. Rather, it can contain NamedDecls.

Public Functions

~MultiDecl() override = default
inline ASTListIteratorPair<Expression> declOrComments() const

Return a way to iterate over the contained VariableDecls and Comments.

inline int numDeclOrComments() const

Return the number of VariableDecls and Comments contained.

inline const Expression *declOrComment(int i) const

Return the i’th contained VariableDecl or Comment.

inline ASTListNoCommentsIteratorPair<Decl> decls() const

Return a way to iterate over the contained Decls (ignoring Comments)

Public Static Functions

static owned<MultiDecl> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, Decl::Linkage linkage, ASTList varDecls)
class NamedDecl : public chpl::uast::Decl
#include <NamedDecl.h>

This is an abstract base class for declarations that carry a name.

Subclassed by chpl::uast::EnumElement, chpl::uast::Function, chpl::uast::Module, chpl::uast::TypeDecl, chpl::uast::VarLikeDecl

Public Functions

virtual ~NamedDecl() = 0
inline UniqueString name() const
class New : public chpl::uast::Expression
#include <New.h>

This class represents a new expression. For example:

var foo = new bar(a = 1, 2);

The initialization expression of foo is an FnCall where the base expression is a New node (representing ‘new bar’).

Public Types

enum Management

Possible management flavors for a new expression.

Values:

enumerator DEFAULT_MANAGEMENT
enumerator BORROWED
enumerator OWNED
enumerator SHARED
enumerator UNMANAGED

Public Functions

inline const Expression *typeExpression() const

Returns the type expression of this new expression.

inline Management management() const

Returns the management style of this new expression.

Public Static Functions

static owned<New> build(Builder *builder, Location loc, owned<Expression> typeExpression, Management management)

Create and return a new expression with the given type expression and management style.

template<typename ValueT, typename ParamT>
class NumericLiteral : public chpl::uast::Literal
#include <NumericLiteral.h>

This is an abstract parent class for int/real/imag numeric literals.

Public Functions

virtual ~NumericLiteral() = 0
inline ValueT value() const

Returns the value of this NumericLiteral.

inline UniqueString text() const

Returns the number as it was written in the source code (as a string)

class On : public chpl::uast::SimpleBlockLike
#include <On.h>

This class represents an on statement. For example:

// Example 1:
var x = 0;
on Locales[1] do writeln(x);

Public Functions

inline const Expression *destination() const

Returns the destination of this on statement.

Public Static Functions

static owned<On> build(Builder *builder, Location loc, owned<Expression> destination, BlockStyle blockStyle, ASTList stmts)

Create and return an on statement.

class OpCall : public chpl::uast::Call
#include <OpCall.h>

This class represents a call to an operator.

For example a + b and x = y are calls to operators (where + and = are the operators called).

Public Functions

~OpCall() override = default
inline UniqueString op() const

Returns the name of the operator called

inline bool isBinaryOp() const

Returns true if this is a binary operator

inline bool isUnaryOp() const

Returns true if this is a unary operator

Public Static Functions

static owned<OpCall> build(Builder *builder, Location loc, UniqueString op, owned<Expression> lhs, owned<Expression> rhs)
static owned<OpCall> build(Builder *builder, Location loc, UniqueString op, owned<Expression> expr)
class PrimCall : public chpl::uast::Call
#include <PrimCall.h>

This class represents a call to a primitive (which only appears in low-level code).

__primitive("=", x, y)

Public Functions

~PrimCall() override = default
inline PrimitiveTag prim() const

Returns the enum value of the primitive called

Public Static Functions

static owned<PrimCall> build(Builder *builder, Location loc, PrimitiveTag prim, ASTList actuals)
class Range : public chpl::uast::Expression
#include <Range.h>

This class represents a range expression. For example:

// Example 1:
var r = 0..15;

Public Types

enum OpKind

Values:

enumerator DEFAULT
enumerator OPEN_HIGH

Public Functions

~Range() override = default
inline OpKind opKind() const

Returns the operator kind used to constrct this range.

inline const Expression *lowerBound() const

Returns the lower bound of this range, or nullptr if there is none.

inline const Expression *upperBound() const

Returns the upper bound of this range, or nullptr if there is none.

Public Static Functions

static owned<Range> build(Builder *builder, Location loc, OpKind opKind, owned<Expression> lowerBound, owned<Expression> upperBound)

Create and return a range expression.

class RealLiteral : public chpl::uast::NumericLiteral<double, types::RealParam>
#include <RealLiteral.h>

This class represents a floating point literal that is not imaginary. That is, it is a “real” number. Examples include 0.0, and 3e24.

Public Functions

~RealLiteral() override = default

Public Static Functions

static owned<RealLiteral> build(Builder *builder, Location loc, double value, UniqueString text)
class Record : public chpl::uast::AggregateDecl
#include <Record.h>

This class represents a record declaration. For example:

record myRecord {
  var a: int;
  proc method() { }
}

The record itself (myRecord) is represented by a Record AST node.

Public Functions

~Record() override = default

Public Static Functions

static owned<Record> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, Decl::Linkage linkage, owned<Expression> linkageName, UniqueString name, ASTList contents)
class Reduce : public chpl::uast::Call
#include <Reduce.h>

This class represents a reduction.

Public Functions

~Reduce() override = default
inline UniqueString op() const

Returns the reduction operator. It may be either a regular operator (e.g. ‘+’, ‘-‘) or the name of a class.

Public Static Functions

static owned<Reduce> build(Builder *builder, Location loc, UniqueString op, owned<Expression> expr)

Create and return a reduction.

class Return : public chpl::uast::Expression
#include <Return.h>

This class represents a return statement. For example:

// Example 1:
proc foo(): int {
  return 0;
}

Public Functions

~Return() override = default
inline const Expression *value() const

Returns the value of this return statement, or nullptr if there is none.

Public Static Functions

static owned<Return> build(Builder *builder, Location loc, owned<Expression> value)

Create and return a return statement. If value is nullptr, then there is no return value.

class Scan : public chpl::uast::Call
#include <Scan.h>

This class represents a scan expression. For example:

..code-block :: chapel

var A: [1..3] int = 1; // Prints ‘1 2 3’ writeln(+ scan A);

The scan expression is ‘+ scan A’.

Public Functions

~Scan() override = default
inline UniqueString op() const

Returns the scan operator. It may be either a regular operator (e.g. ‘+’, ‘-‘) or the name of a class.

Public Static Functions

static owned<Scan> build(Builder *builder, Location loc, UniqueString op, owned<Expression> expr)

Create and return a scan.

class Select : public chpl::uast::Expression
#include <Select.h>

This class represents a select statement. For example:

// Example 1:
const i = 2;
select i {
  when 0 do writeln('zero');
  otherwise do writeln('number: ', i);
}

Public Functions

inline const Expression *expr() const

Returns the expression of this select statement.

inline int numWhenStmts() const

Returns the number of when statements in this select statement.

inline const When *whenStmt(int i) const

Return the i’th when statement in this select statement.

inline ASTListIteratorPair<When> whenStmts() const

Iterate over the when statements in this select statement.

Public Static Functions

static owned<Select> build(Builder *builder, Location loc, owned<Expression> expr, ASTList whenStmts)

Create and return a select statement.

class Serial : public chpl::uast::SimpleBlockLike
#include <Serial.h>

This class represents a serial statement. For example:

// Example 1:
const flag = true;
serial flag {
  var x = 0;
  writeln(x);
}

// Example 2:
var x = 0;
serial do writeln(x);

Public Functions

inline const Expression *condition() const

Returns the condition of this serial statement, or nullptr if there is none.

Public Static Functions

static owned<Serial> build(Builder *builder, Location loc, BlockStyle blockStyle, ASTList stmts)

Create and return a serial statement containing the passed statements.

static owned<Serial> build(Builder *builder, Location loc, owned<Expression> condition, BlockStyle blockStyle, ASTList stmts)

Create and return a serial statement with the given condition and containing the passed statements.

class SimpleBlockLike : public chpl::uast::Expression
#include <SimpleBlockLike.h>

This class represents any sort of block-like construct. Candidates for use of this abstract class have:

  • Simple-to-no (e.g. Local, or Block) control flow

  • A body that may be enclosed by curly braces

  • A body containing statements that execute serially

Thus Begin would be a candidate for this class (because while it spawns a new task, the contained statements execute serially), while Cobegin would not because the contained statements each execute in a different task.

Conditional would not be a candidate for this class because its control flow is slightly more complex than “conditionally execute entire block”. This is because the conditional may have an else block.

Subclassed by chpl::uast::Begin, chpl::uast::Block, chpl::uast::Defer, chpl::uast::Local, chpl::uast::On, chpl::uast::Serial, chpl::uast::Sync, chpl::uast::When

Public Functions

virtual ~SimpleBlockLike() override = 0
inline ASTListIteratorPair<Expression> stmts() const

Return a way to iterate over the statements.

inline int numStmts() const

Return the number of statements in this.

inline const Expression *stmt(int i) const

Return the i’th statement in this.

inline BlockStyle blockStyle() const

Get the block style of this.

class StringLikeLiteral : public chpl::uast::Literal
#include <StringLikeLiteral.h>

This is an abstract parent class for string/bytes/c-string literals.

Subclassed by chpl::uast::BytesLiteral, chpl::uast::CStringLiteral, chpl::uast::StringLiteral

Public Types

enum QuoteStyle

Values:

enumerator SINGLE
enumerator DOUBLE
enumerator TRIPLE_SINGLE
enumerator TRIPLE_DOUBLE

Public Functions

virtual ~StringLikeLiteral() = 0
inline QuoteStyle quoteStyle() const

Returns the type of quotes used for this string literal.

class StringLiteral : public chpl::uast::StringLikeLiteral
#include <StringLiteral.h>

This class represents a string literal, for example "hello" and ‘’ string contents here ‘’’`.

Public Functions

~StringLiteral() override = default
inline UniqueString str() const

Returns the value of this string literal as a UniqueString which does not include the quotes.

Public Static Functions

static owned<StringLiteral> build(Builder *builder, Location loc, const std::string &value, StringLikeLiteral::QuoteStyle quotes)
class Sync : public chpl::uast::SimpleBlockLike
#include <Sync.h>

This class represents a sync statement. For example:

// Example 1:
proc syncExample() {
  sync {
    begin task1();
    begin task2();
  }
  writeln("Task 1 and 2 complete");
}
syncExample();

This code will wait for both task1 and task2 to complete before printing due to use of the sync block.

Public Functions

~Sync() override = default

Public Static Functions

static owned<Sync> build(Builder *builder, Location loc, BlockStyle blockStyle, ASTList stmts)

Create and return a Sync containing the passed stmts.

class TaskVar : public chpl::uast::VarLikeDecl
#include <TaskVar.h>

This class represents a task variable. Task variables are declared in with clauses. For example:

var a: atomic int;
forall x in 1..15 with (ref a) do
  a.fetchAdd(x);

Creates a task variable ‘a’ which refers to the outer variable ‘a’ by ref intent.

Public Types

enum Intent

Values:

enumerator VAR
enumerator CONST
enumerator CONST_REF
enumerator REF
enumerator IN
enumerator CONST_IN

Public Functions

~TaskVar() override = default
inline Intent intent() const

Returns the intent of this task variable.

Public Static Functions

static owned<TaskVar> build(Builder *builder, Location loc, owned<Attributes> attributes, UniqueString name, TaskVar::Intent intent, owned<Expression> typeExpression, owned<Expression> initExpression)
class Throw : public chpl::uast::Expression
#include <Throw.h>

This class represents a throw statement. For example:

// Example 1:
proc mayThrow() throws {
  throw new Error();
}

Public Functions

inline const Expression *errorExpression() const

Return the error expression of this throw statement.

Public Static Functions

static owned<Throw> build(Builder *builder, Location loc, owned<Expression> expr)

Create and return a throw statement.

class Try : public chpl::uast::Expression
#include <Try.h>

This class represents a try statement or try expression. For example:

// Example of a try expression:
var x = try! foo();

// Example of a try statement:
try! {
  foo();
} catch e: FooError {
  halt('A FooError occurred');
}

A try statement may contain a number of catch blocks (represented by the Catch uAST node), while a try expression will never contain a catch block.

Public Functions

~Try() override = default
inline ASTListIteratorPair<Expression> stmts() const

Iterate over the statements contained in this try.

inline int numStmts() const

Return the number of statements contained in this try.

inline const Expression *stmt(int i) const

Get the i’th statement in the body of this try.

inline ASTListIteratorPair<Catch> handlers() const

Iterate over the catch blocks contained in this try.

inline int numHandlers() const

Return the number of catch blocks contained in this try.

inline const Catch *handler(int i) const

Return the i’th catch block contained in this try.

inline bool isExpressionLevel() const

Return true if this try is at an expression level.

inline bool isTryBang() const

Return true if this try should halt when an error is not handled.

Public Static Functions

static owned<Try> build(Builder *builder, Location loc, ASTList stmts, ASTList catches, bool isTryBang)

Create and return a try statement.

static owned<Try> build(Builder *builder, Location loc, owned<Expression> expr, bool isTryBang, bool isExpressionLevel)

Create and return a try expression.

class Tuple : public chpl::uast::Call
#include <Tuple.h>

This class represents a tuple literal. For example:

// Here '(1, 2, 3)' is a tuple literal.
var x = (1, 2, 3);

Public Functions

~Tuple() override = default

Public Static Functions

static owned<Tuple> build(Builder *builder, Location loc, ASTList exprs)

Create and return a tuple.

class TupleDecl : public chpl::uast::Decl
#include <TupleDecl.h>

This class represents a tuple variable declaration

E.g.

var (a, b) = (1,2);
var (c, _) = (3.0,"hi");
var (d, e) = returnTuple();

Each of the lines above is represented by a MultiDecl containing a list of VariableDecls. Note that the initial value and/or type is inferred from later declarations.

Since the Tuple does not itself have a name, it is not a NamedDecl. Rather, it can contain NamedDecls.

Public Types

enum IntentOrKind

Values:

enumerator DEFAULT
enumerator VAR
enumerator CONST
enumerator CONST_REF
enumerator REF
enumerator IN
enumerator CONST_IN
enumerator OUT
enumerator INOUT
enumerator INDEX
enumerator PARAM
enumerator TYPE

Public Functions

~TupleDecl() override = default
inline IntentOrKind intentOrKind() const

Returns the intent or kind of the tuple (var / in / param etc).

inline ASTListIteratorPair<Decl> decls() const

Return a way to iterate over the contained Decls (which are each Variables or TupleDecls).

inline int numDecls() const

Return the number of Decls contained within this TupleDecl.

inline const Decl *decl(int i) const

Return the i’th contained Decl.

inline const Expression *typeExpression() const

Returns the type expression used in this TupleDecl’s declaration, or nullptr if there wasn’t one.

inline const Expression *initExpression() const

Returns the init expression used in this TupleDecl’s declaration, or nullptr if there wasn’t one.

Public Static Functions

static owned<TupleDecl> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, Decl::Linkage linkage, IntentOrKind intentOrKind, ASTList elements, owned<Expression> typeExpression, owned<Expression> initExpression)
class TypeDecl : public chpl::uast::NamedDecl
#include <TypeDecl.h>

This is an abstract base class for Symbols defining a type (e.g. classes, records, enums).

Subclassed by chpl::uast::AggregateDecl, chpl::uast::Enum

Public Functions

virtual ~TypeDecl() = 0
class TypeQuery : public chpl::uast::Expression
#include <TypeQuery.h>

This class represents a type query.

// Here ?D is a type query which names the domain of A.
proc foo(A: [?D] int) {
  for idx in D do writeln(idx, A[idx]);
}

Public Functions

~TypeQuery() override = default
inline UniqueString name() const

Returns the name of this type query, e.g. in proc foo(?x), this method would return the x portion of the type query ?x.

Public Static Functions

static owned<TypeQuery> build(Builder *builder, Location loc, UniqueString name)
class UintLiteral : public chpl::uast::NumericLiteral<uint64_t, types::UintParam>
#include <UintLiteral.h>

This class represents an unsigned integer literal. It is only used for integers too large to fit into int64_t. Such integer literals have type uint.

Public Functions

~UintLiteral() override = default

Public Static Functions

static owned<UintLiteral> build(Builder *builder, Location loc, uint64_t value, UniqueString text)
class Union : public chpl::uast::AggregateDecl
#include <Union.h>

This class represents a union declaration. For example:

union myUnion {
  var a: int;
  var b: real;
}

The union itself (myUnion) is represented by a Union AST node.

Public Functions

~Union() override = default

Public Static Functions

static owned<Union> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, Decl::Linkage linkage, owned<Expression> linkageName, UniqueString name, ASTList contents)
class Use : public chpl::uast::Expression
#include <Use.h>

This class represents a use statement. For example:

// Example 1:
use Foo, Bar as A;

This creates a use statement that has two visibility clauses, ‘Foo’ and ‘Bar as A’.

Public Functions

inline Decl::Visibility visibility() const

Return the visibility of this use statement.

inline ASTListIteratorPair<VisibilityClause> visibilityClauses() const

Return a way to iterate over the visibility clauses.

inline int numVisibilityClauses() const

Return the number of visibility clauses in this use statement.

inline const VisibilityClause *visibilityClause(int i) const

Return the i’th visibility clause in this use statement.

Public Static Functions

static owned<Use> build(Builder *builder, Location loc, Decl::Visibility visibility, ASTList visibilityClauses)

Create and return a use statement.

class VarArgFormal : public chpl::uast::VarLikeDecl
#include <VarArgFormal.h>

This class represents a varargs formal.

proc f(x: int ...?k) {
  writeln(x);
}

Here x is a formal that may take a variable number of actual arguments, the number of which is denoted by the TypeQuery ?k.

Public Functions

~VarArgFormal() override = default
inline Formal::Intent intent() const

Returns the intent of the varargs formal, e.g. in proc f(ref x: int ...?k), the formal x has intent ref.

inline const Expression *count() const

Returns the count expression of the varargs formal, e.g. in proc f(ref x: int ...?k), the count expression is the TypeQuery ?k.

If the count expression does not exist then nullptr is returned.

Public Static Functions

static owned<VarArgFormal> build(Builder *builder, Location loc, owned<Attributes> attributes, UniqueString name, Formal::Intent intent, owned<Expression> typeExpression, owned<Expression> count)
class Variable : public chpl::uast::VarLikeDecl
#include <Variable.h>

This class represents a variable. For example:

var a = 1;
ref b = a;
const c = 2;
const ref d = c;
param e = "hi";

class C {
  var f: int;
}

each of a-f are Variables.

Public Types

enum Kind

Values:

enumerator VAR
enumerator CONST
enumerator CONST_REF
enumerator REF
enumerator PARAM
enumerator TYPE
enumerator INDEX

Public Functions

~Variable() override = default
inline Kind kind() const

Returns the kind of the variable (var / const / param etc).

inline bool isConfig() const

Returns true if this variable is a config variable.

inline bool isField() const

Returns true if this Variable represents a field.

Public Static Functions

static owned<Variable> build(Builder *builder, Location loc, owned<Attributes> attributes, Decl::Visibility vis, Decl::Linkage linkage, owned<Expression> linkageName, UniqueString name, Variable::Kind kind, bool isConfig, bool isField, owned<Expression> typeExpression, owned<Expression> initExpression)
class VarLikeDecl : public chpl::uast::NamedDecl
#include <VarLikeDecl.h>

This abstract class represents any sort of variable-like declaration. This includes things like fields, formals, or variables.

Subclassed by chpl::uast::Formal, chpl::uast::TaskVar, chpl::uast::VarArgFormal, chpl::uast::Variable

Public Functions

virtual ~VarLikeDecl() = 0
inline IntentList storageKind() const

Returns the storage kind (e.g. type, param, in, etc). Subclasses have more specific functions that return the subset appropriate for that subclass.

inline const Expression *typeExpression() const

Returns the type expression used in this VarLikeDecl’s declaration, or nullptr if there wasn’t one.

inline const Expression *initExpression() const

Returns the init expression used in this VarLikeDecl’s declaration, or nullptr if there wasn’t one.

class VisibilityClause : public chpl::uast::Expression
#include <VisibilityClause.h>

This class represents a visibility clause. Visibility clauses make up the contents of Use and Import statements. For example:

// This contains two visibility clauses, 'Foo as X' and 'Baz as Y'.
use Foo as X, Baz as Y;

// This contains one visibility clause, 'Baz as Z'.
import Baz as Z;

Public Types

enum LimitationKind

These values represent the kind of limitations possessed by a visibility clause. Visibility clauses within use statements may have limitations of kind ‘EXCEPT’, ‘ONLY’, or ‘NONE’. Those within import statements may have have limitations of kind ‘BRACES’ or ‘NONE’.

If the limitation kind is ‘NONE’, then the visibility clause should have no limitations. If the kind is ‘BRACES’ or ‘EXCEPT’, then the visibility clause should have one or more limitations. If the kind is ‘ONLY’, then it may have zero or more limitations.

Values:

enumerator BRACES
enumerator EXCEPT
enumerator ONLY
enumerator NONE

Public Functions

~VisibilityClause() override = default
inline const Expression *symbol() const

Get the symbol of this visibility clause. It may be a Dot, As, or Identifier.

inline LimitationKind limitationKind() const

Return the kind of limitations contained by this visibility clause.

inline ASTListIteratorPair<Expression> limitations() const

Return a way to iterate over the limitations of this visibility clause.

inline int numLimitations() const

Return the number of limitations contained in this visibility clause.

inline const Expression *limitation(int i) const

Return the i’th limitation of this visibility clause. If the limitation kind is ‘EXCEPT’, then the limitations will all be Identifier. If the limitation kind is ‘ONLY’ or ‘BRACES’, then the limitations may be Identifer or As expressions.

Public Static Functions

static owned<VisibilityClause> build(Builder *builder, Location loc, owned<Expression> symbol)

Create and return a visibility clause.

static owned<VisibilityClause> build(Builder *builder, Location loc, owned<Expression> symbol, LimitationKind limitationKind, ASTList limitations)

Create and return a visibility clause.

class When : public chpl::uast::SimpleBlockLike
#include <When.h>

This class represents a when statement. When statements make up the body of the select statement.

Public Functions

inline int numCaseExprs() const

Returns the number of case expressions for this when statement.

inline const Expression *caseExpr(int i) const

Returns the i’th case of this when statement.

inline ASTListIteratorPair<Expression> caseExprs() const

Return a way to iterate over the cases of this when statement.

inline bool isOtherwise() const

Returns true if this when statement uses the otherwise keyword.

Public Static Functions

static owned<When> build(Builder *builder, Location loc, ASTList caseExprs, BlockStyle blockStyle, ASTList stmts)

Create and return a when statement. If ‘caseExprs’ is empty then ‘isOtherwise()’ will evaluate to true.

class While : public chpl::uast::Loop
#include <While.h>

This class represents a while loop. For example:

// Example 1:
var i = 0;
while i < 5 {
  writeln(i);
  i += 1;
}

Public Functions

~While() override = default
inline const Expression *condition() const

Return the condition of this while loop.

Public Static Functions

static owned<While> build(Builder *builder, Location loc, owned<Expression> condition, BlockStyle blockStyle, owned<Block> stmts)

Create and return a while loop.

class WithClause : public chpl::uast::Expression
#include <WithClause.h>

This class represents a with clause. For example:

// Example 1:
forall myRange with (var x = 0) {
  writeln(x);
}

Creates a forall loop that has a with clause which declares a single task variable named ‘x’.

Public Functions

inline ASTListIteratorPair<Expression> exprs() const

Return a way to iterate over the expressions of this with clause.

inline int numExprs() const

Return the number of expressions in this with clause.

inline const Expression *expr(int i) const

Return the i’th expression in this with clause.

Public Static Functions

static owned<WithClause> build(Builder *builder, Location loc, ASTList exprs)

Create and return a with clause.

class Yield : public chpl::uast::Expression
#include <Yield.h>

This class represents a yield statement. For example:

// Example 1:
iter foo(): int {
  for i in range 0..15 do yield i;
}

Public Functions

~Yield() override = default
inline const Expression *value() const

Returns the value of this yield statement.

Public Static Functions

static owned<Yield> build(Builder *builder, Location loc, owned<Expression> value)

Create and return a yield statement. The value formal cannot be nullptr.

class Zip : public chpl::uast::Call
#include <Zip.h>

This class represents a zip expression.

Public Functions

~Zip() override = default

Public Static Functions

static owned<Zip> build(Builder *builder, Location loc, ASTList actuals)

Create and return a zip expression.

namespace asttags

Enums

enum ASTTag

This enum is used to identify which AST class a node is.

Values:

enumerator NUM_AST_TAGS

Functions

const char *tagToString(ASTTag tag)
namespace pragmatags

Enums

enum PragmaTag

Values:

enumerator PRAGMA_UNKNOWN
enumerator NUM_KNOWN_PRAGMAS

Functions

const char *pragmaTagToName(PragmaTag tag)

Return the string name associated with a PragmaTag

PragmaTag pragmaNameToTag(const char *name)

Return the PragmaTag associated with a const char*

namespace primtags

Enums

enum PrimitiveTag

An enum containing the various PrimOp values e.g. PRIM_MOVE.

Values:

enumerator NUM_KNOWN_PRIMS

Functions

const char *primTagToName(PrimitiveTag tag)

Return the string name associated with a PrimitiveTag

PrimitiveTag primNameToTag(const char *name)

Return the PrimitiveTag associated with a const char*