sun::ast
namespace · Source (opens in a new tab)
Defines syntax-tree nodes and the annotations used to analyze them.
Interface contract preparation, default-body analysis, and conformance.
Represents parsed Sun declarations, expressions, and statements.
Defines declarations and expressions checked by interface analysis.
Classes
- sun::ast::ArrayIndexAST (public)
- sun::ast::ArrayLiteralAST (public)
- sun::ast::BinaryExprAST (public)
- sun::ast::BlockExprAST (public)
- sun::ast::BoolLiteralAST (public)
- sun::ast::BreakAST (public)
- sun::ast::CallExprAST (public)
- sun::ast::CharLiteralAST (public)
- sun::ast::ClassDefinitionAST (public)
- sun::ast::CompoundAssignmentAST (public)
- sun::ast::ContinueAST (public)
- sun::ast::DeclareTypeAST (public)
- sun::ast::EnumDefinitionAST (public)
- sun::ast::ExprAST (public)
- sun::ast::ForExprAST (public)
- sun::ast::ForInExprAST (public)
- sun::ast::FunctionAST (public)
- sun::ast::GenericCallAST (public)
- sun::ast::IfExprAST (public)
- sun::ast::IndexAST (public)
- sun::ast::IndexedAssignmentAST (public)
- sun::ast::InterfaceDefinitionAST (public)
- sun::ast::InterpolatedStringAST (public)
- sun::ast::LambdaAST (public)
- sun::ast::ManifestAST (public)
- sun::ast::MatchExprAST (public)
- sun::ast::MemberAccessAST (public)
- sun::ast::MemberAssignmentAST (public)
- sun::ast::ModuleAST (public)
- sun::ast::MoonScopeAST (public)
- sun::ast::NullLiteralAST (public)
- sun::ast::NumberExprAST (public)
- sun::ast::PackExpansionAST (public)
- sun::ast::ParenExprAST (public)
- sun::ast::PrototypeAST (public)
- sun::ast::QualifiedNameAST (public)
- sun::ast::ReferenceCreationAST (public)
- sun::ast::ReturnExprAST (public)
- sun::ast::SliceExprAST (public)
- sun::ast::StringLiteralAST (public)
- sun::ast::StructLiteralAST (public)
- sun::ast::TernaryExprAST (public)
- sun::ast::ThisExprAST (public)
- sun::ast::ThrowExprAST (public)
- sun::ast::TryCatchExprAST (public)
- sun::ast::UnaryExprAST (public)
- sun::ast::UnsafeBlockAST (public)
- sun::ast::UsingAST (public)
- sun::ast::VariableAssignmentAST (public)
- sun::ast::VariableCreationAST (public)
- sun::ast::VariableReferenceAST (public)
- sun::ast::WhileExprAST (public)
Structs
- sun::ast::ExprAnalysis (public)
- sun::ast::ReturnAnalysis (public)
- sun::ast::StructLiteralAnalysis (public)
- sun::ast::PrototypeAnalysis (public)
- sun::ast::FunctionAnalysis (public)
- sun::ast::ClassAnalysis (public)
- sun::ast::InterfaceAnalysis (public)
- sun::ast::ForInAnalysis (public)
- sun::ast::MemberAccessAnalysis (public)
- sun::ast::CallAnalysis (public)
- sun::ast::GenericCallAnalysis (public)
- sun::ast::DeclareTypeAnalysis (public)
- sun::ast::VariableAnalysis (public)
- sun::ast::TypeParameter (public)
- sun::ast::LifetimeParameter (public)
- sun::ast::VariadicParam (public)
- sun::ast::Capture (public)
- sun::ast::ClassFieldDecl (public)
- sun::ast::ClassMethodDecl (public)
- sun::ast::ImplementedInterfaceAST (public)
- sun::ast::EnumVariantDecl (public)
- sun::ast::InterfaceFieldDecl (public)
- sun::ast::InterfaceMethodDecl (public)
- sun::ast::ManifestMoonDependency (public)
- sun::ast::ManifestSunDependency (public)
- sun::ast::ManifestProtoDependency (public)
- sun::ast::ManifestArchiveDependency (public)
- sun::ast::ManifestTargetBlock (public)
- sun::ast::PatternBinding (public)
- sun::ast::MatchArm (public)
- sun::ast::CatchClause (public)
- sun::ast::ArrayDimension (public)
- sun::ast::TypeAnnotation (public)
- sun::ast::TypeConstraint (public)
Functions
- clearResolvedTypes
- cloneExprVector
- cloneTypeAnnotationVector
- collectFreeVariables
- collectFreeVariablesInBlock
- exprDiverges
- forEachChild
- isImportedMoon
- lifetimeParameterNames
- typeParameterNames
clearResolvedTypes
public · function · Source (opens in a new tab)
void sun::ast::clearResolvedTypes(const ExprAST &expr)Forgets the types analysis recorded on a tree, including match arm tags and binding types, so a copy of a generic body can be analyzed afresh.
Clears this node's type, its match arm annotations, then every child.
Visits every child, including lambda and function bodies. Declaration identities and other annotations are kept.
Related: ExprAST
cloneExprVector
public · function · Source (opens in a new tab)
std::vector< std::unique_ptr< ExprAST > > sun::ast::cloneExprVector(const std::vector< std::unique_ptr< ExprAST > > &vec)Helper to clone a vector of unique_ptr<ExprAST>.
Related: ExprAST
cloneTypeAnnotationVector
public · function · Source (opens in a new tab)
std::vector< std::unique_ptr< TypeAnnotation > > sun::ast::cloneTypeAnnotationVector(const std::vector< std::unique_ptr< TypeAnnotation > > &vec)Helper to clone a vector of unique_ptr<TypeAnnotation>.
Related: TypeAnnotation
collectFreeVariables
public · function · Source (opens in a new tab)
std::set< std::string > sun::ast::collectFreeVariables(const ExprAST &expr, const std::set< std::string > &bound)The variables an expression reads or writes but does not declare: what a lambda has to capture.
bound names the ones already in scope. Nested functions, types and modules are skipped, since they cannot reach an enclosing local.
Related: ExprAST
collectFreeVariablesInBlock
public · function · Source (opens in a new tab)
std::set< std::string > sun::ast::collectFreeVariablesInBlock(const BlockExprAST &block, std::set< std::string > bound)The same over a block, adding each declaration to bound as it is reached so later statements do not count it as free.
Walks a block in order, binding each declaration for the statements after it.
Related: BlockExprAST
exprDiverges
public · function · Source (opens in a new tab)
bool sun::ast::exprDiverges(const ExprAST &expr)True when control never falls out of expr: it ends in a return or a throw, or is an if whose branches all do.
Reports whether evaluating this expression always exits the current control-flow path.
Whatever such an expression did cannot reach the code that follows it, so a pass that carries state forward should leave it behind.
A break or continue counts: code after it in the same block or arm never runs, even though the enclosing loop carries on.
Related: ExprAST
forEachChild
public · function · Source (opens in a new tab)
void sun::ast::forEachChild(const ExprAST &node, const ChildFn &fn)Calls fn for each direct child expression of node, in source order.
Visits each directly owned expression child of a syntax node.
Unlike ExprAST::forEachChildSlot (a rewriting hook that forwards through strongly typed children), this visits every child, including function bodies, class and interface methods, slice bounds, match patterns and struct literal values. Used by tooling that walks the tree (language server lookups).
Related: ExprAST, ChildFn, ExprAST::forEachChildSlot
isImportedMoon
public · function · Source (opens in a new tab)
bool sun::ast::isImportedMoon(const ExprAST &node)True if the node wraps the stubs of an imported .moon rather than the sources of the bundle being built.
Passes that only act on the program's own code use this to skip over imports.
Related: ExprAST
lifetimeParameterNames
public · function · Source (opens in a new tab)
std::vector< std::string > sun::ast::lifetimeParameterNames(const std::vector< LifetimeParameter > ¶ms)The names of the lifetime parameters, in declaration order.
Related: LifetimeParameter
typeParameterNames
public · function · Source (opens in a new tab)
std::vector< std::string > sun::ast::typeParameterNames(const std::vector< TypeParameter > ¶ms)The names alone, for the many places that only care what a parameter is called (substitution, scope registration).
Related: TypeParameter
Enums
ASTNodeType
public · enum · Source (opens in a new tab)
enum class sun::ast::ASTNodeTypeIdentifies the syntax-node shapes handled by compiler visitors.
NUMBER
NUMBER
No documentation comment.
STRING_LITERAL
STRING_LITERAL
No documentation comment.
CHAR_LITERAL
CHAR_LITERAL
No documentation comment.
NULL_LITERAL
NULL_LITERAL
No documentation comment.
BOOL_LITERAL
BOOL_LITERAL
No documentation comment.
ARRAY_LITERAL
ARRAY_LITERAL
No documentation comment.
STRUCT_LITERAL
STRUCT_LITERAL
No documentation comment.
ARRAY_INDEX
ARRAY_INDEX
No documentation comment.
INDEX
INDEX
No documentation comment.
SLICE
SLICE
No documentation comment.
VARIABLE_REFERENCE
VARIABLE_REFERENCE
No documentation comment.
VARIABLE_CREATION
VARIABLE_CREATION
No documentation comment.
VARIABLE_ASSIGNMENT
VARIABLE_ASSIGNMENT
No documentation comment.
REFERENCE_CREATION
REFERENCE_CREATION
No documentation comment.
BINARY
BINARY
No documentation comment.
UNARY
UNARY
No documentation comment.
CALL
CALL
No documentation comment.
PROTOTYPE
PROTOTYPE
No documentation comment.
FUNCTION
FUNCTION
No documentation comment.
LAMBDA
LAMBDA
No documentation comment.
IF
IF
No documentation comment.
MATCH
MATCH
No documentation comment.
FOR_LOOP
FOR_LOOP
No documentation comment.
FOR_IN_LOOP
FOR_IN_LOOP
No documentation comment.
WHILE_LOOP
WHILE_LOOP
No documentation comment.
BLOCK
BLOCK
No documentation comment.
INDEXED_ASSIGNMENT
INDEXED_ASSIGNMENT
No documentation comment.
RETURN
RETURN
No documentation comment.
IMPORT
IMPORT
No documentation comment.
IMPORT_SCOPE
IMPORT_SCOPE
No documentation comment.
MANIFEST
MANIFEST
No documentation comment.
MODULE
MODULE
No documentation comment.
USING
USING
No documentation comment.
QUALIFIED_NAME
QUALIFIED_NAME
No documentation comment.
CLASS_DEFINITION
CLASS_DEFINITION
No documentation comment.
INTERFACE_DEFINITION
INTERFACE_DEFINITION
No documentation comment.
ENUM_DEFINITION
ENUM_DEFINITION
No documentation comment.
MEMBER_ACCESS
MEMBER_ACCESS
No documentation comment.
THIS
THIS
No documentation comment.
MEMBER_ASSIGNMENT
MEMBER_ASSIGNMENT
No documentation comment.
TRY_CATCH
TRY_CATCH
No documentation comment.
THROW
THROW
No documentation comment.
BREAK_STMT
BREAK_STMT
No documentation comment.
CONTINUE_STMT
CONTINUE_STMT
No documentation comment.
GENERIC_CALL
GENERIC_CALL
No documentation comment.
PACK_EXPANSION
PACK_EXPANSION
No documentation comment.
DECLARE_TYPE
DECLARE_TYPE
No documentation comment.
UNSAFE_BLOCK
UNSAFE_BLOCK
No documentation comment.
MOON_SCOPE
MOON_SCOPE
No documentation comment.
COMPOUND_ASSIGNMENT
COMPOUND_ASSIGNMENT
No documentation comment.
TERNARY
TERNARY
No documentation comment.
INTERPOLATED_STRING
INTERPOLATED_STRING
No documentation comment.
PAREN_EXPR
PAREN_EXPR
No documentation comment.
BlockKind
public · enum · Source (opens in a new tab)
enum class sun::ast::BlockKindWhich construct a block is the body of.
In the language, only two kinds evaluate to their last statement — a match arm's body and an unsafe block's body. Every other kind is a statement body whose trailing expression is not a value; in value position, { ... } always means a struct literal, never a block. The one exception is Value, which has no syntax at all: it is what the compiler's own lowerings make when they need a block that carries a value (string interpolation).
Anonymous
Anonymous
No documentation comment.
MatchArm
MatchArm
No documentation comment.
Unsafe
Unsafe
No documentation comment.
Function
Function
No documentation comment.
If
If
No documentation comment.
Loop
Loop
No documentation comment.
Try
Try
No documentation comment.
Catch
Catch
No documentation comment.
Module
Module
No documentation comment.
Value
Value
No documentation comment.
CaptureKind
public · enum · Source (opens in a new tab)
enum class sun::ast::CaptureKindHow a lambda takes hold of a variable from the enclosing scope.
These are the three mutually exclusive ways; whether the binding is writable inside the lambda is a separate question (Capture::isConst).
Related: Capture::isConst
ByValue
ByValue
No documentation comment.
Owned
Owned
No documentation comment.
Borrow
Borrow
No documentation comment.
FieldWriteKind
public · enum · Source (opens in a new tab)
enum class sun::ast::FieldWriteKindWhat a write to a field does to whatever the field held before it.
The field-initialization walk proves which one holds for every write — there is no run-time case.
ReplacesValue
ReplacesValue
No documentation comment.
StartsLife
StartsLife
No documentation comment.
Type Aliases
ChildFn
public · typedef · Source (opens in a new tab)
using sun::ast::ChildFn = std::function<void(const ExprAST&)>A callback invoked for each directly owned syntax-tree child.
Related: ExprAST