sun::ast::ExprAST

sun::ast::ExprAST

class · Source (opens in a new tab)

class sun::ast::ExprAST

Base syntax node carrying source positions and semantic analysis annotations.

Inherited by

Public Functions

clearComputedAnalysis

public · function · Source (opens in a new tab)

virtual void sun::ast::ExprAST::clearComputedAnalysis() const

Discard computed results while preserving this session's identities.

clearResolvedType

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::clearResolvedType() const

Discards the cached type so analysis can resolve it again.

clone

public · function · Source (opens in a new tab)

std::unique_ptr< ExprAST > sun::ast::ExprAST::clone() const

Clone this AST node (deep copy) via protobuf serialization roundtrip.

This approach is less error-prone than manual cloning as it automatically handles all fields through the proto schema.

Related: ExprAST

declarationIdentity

public · function · Source (opens in a new tab)

virtual sun::semantic_analysis::DeclarationIdentity & sun::ast::ExprAST::declarationIdentity() const

Access declaration and parameter identities retained within a session.

Related: sun::semantic_analysis::DeclarationIdentity

dotLabel

public · function · Source (opens in a new tab)

virtual std::string sun::ast::ExprAST::dotLabel() const =0

Label for DOT graph visualization (includes type name).

dump

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::dump() const

Print to stderr (easier to call from debugger than toString()).

Related: toString()

forEachChildSlot

public · function · Source (opens in a new tab)

virtual void sun::ast::ExprAST::forEachChildSlot(const ChildSlotFn &)

Visits replaceable child expressions so tree passes can rewrite them in place.

Related: ChildSlotFn

getColumn

public · function · Source (opens in a new tab)

int sun::ast::ExprAST::getColumn() const

Returns the source column used to report this node in diagnostics.

getDeclarationId

public · function · Source (opens in a new tab)

virtual DeclarationId sun::ast::ExprAST::getDeclarationId() const

Read the declaration identity without allocating computed analysis.

Related: DeclarationId

getLine

public · function · Source (opens in a new tab)

int sun::ast::ExprAST::getLine() const

Returns the source line used to report this node in diagnostics.

getLocation

public · function · Source (opens in a new tab)

const sun::support::Position & sun::ast::ExprAST::getLocation() const

Returns the source position used for diagnostics.

Related: sun::support::Position

getModuleDeclaration

public · function · Source (opens in a new tab)

const std::optional< PortableDeclarationKey > & sun::ast::ExprAST::getModuleDeclaration() const

The original module denoted by this expression or retained using target.

Related: PortableDeclarationKey

getResolvedType

public · function · Source (opens in a new tab)

sun::types::TypePtr sun::ast::ExprAST::getResolvedType() const

Returns the type assigned by semantic analysis, if available.

Related: sun::types::TypePtr

getSourceFileId

public · function · Source (opens in a new tab)

SourceFileId sun::ast::ExprAST::getSourceFileId() const

The source unit whose imports apply to this node.

Related: SourceFileId

getSymbolPrefix

public · function · Source (opens in a new tab)

const std::string & sun::ast::ExprAST::getSymbolPrefix() const

Symbol prefix for moon library isolation (content hash).

getTargetDeclarationId

public · function · Source (opens in a new tab)

DeclarationId sun::ast::ExprAST::getTargetDeclarationId() const

Return the declaration selected by semantic resolution.

Related: DeclarationId

getType

public · function · Source (opens in a new tab)

virtual ASTNodeType sun::ast::ExprAST::getType() const =0

Returns the syntax-node kind used to dispatch tree visitors.

Related: ASTNodeType

getVisibility

public · function · Source (opens in a new tab)

Visibility sun::ast::ExprAST::getVisibility() const

Declaration visibility (meaningful on declaration nodes only).

Related: Visibility

hasAnalysis

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::hasAnalysis() const

Reports whether this object has analysis.

hasResolvedType

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::hasResolvedType() const

Reports whether semantic analysis has assigned a type.

inheritSourceFile

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::inheritSourceFile(SourceFileId id)

Fill missing source identities without changing imported subtrees.

Related: SourceFileId

isBlock

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isBlock() const

Reports whether this syntax node represents a lexical block.

isFunction

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isFunction() const

Reports whether this syntax node represents a function definition.

isLambda

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isLambda() const

Reports whether this syntax node represents a lambda expression.

isLvalue

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isLvalue() const

Returns true if this expression is an lvalue (can be assigned to, has a stable address).

Includes variables, member access, and indexing.

isMoved

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isMoved() const

Moved flag: set by borrow checker when ownership is transferred (returned, assigned to variable/field, passed by value).

Moved expressions should not have deinit called - the destination owns the data.

isPrecompiled

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isPrecompiled() const

Precompiled flag (for definitions loaded from .moon files).

isPublic

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isPublic() const

Reports whether this declaration is accessible outside its defining scope.

isReturn

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isReturn() const

Reports whether this syntax node represents a return statement.

isTemporary

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::isTemporary() const

Returns true if this expression is a temporary (rvalue) that will be destroyed at the end of the statement.

Temporaries include:

  • Constructor/function calls that return class values (CALL, GENERIC_CALL)
  • Literals that produce class values Named variables (VARIABLE_REFERENCE) and member accesses are NOT temporaries.

resetAnalysisSession

public · function · Source (opens in a new tab)

virtual void sun::ast::ExprAST::resetAnalysisSession() const

Discard all annotations when the owning analysis session is discarded.

setDeclarationId

public · function · Source (opens in a new tab)

virtual void sun::ast::ExprAST::setDeclarationId(DeclarationId id) const

Assign the identity allocated by the owning analysis session.

Related: DeclarationId

setLocation

setLocation(sun::support::Position loc)

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setLocation(sun::support::Position loc)

Source location tracking.

Related: sun::support::Position

setLocation(int line, int column)

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setLocation(int line, int column)

Sets the source position used for diagnostics.

setModuleDeclaration

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setModuleDeclaration(PortableDeclarationKey name)

Bind a module reference without changing its source spelling.

Related: PortableDeclarationKey

setMoved

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setMoved(bool value) const

Records whether ownership of this expression has already been transferred.

setPrecompiled

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setPrecompiled(bool value)

Marks whether this node came from an already compiled library.

setResolvedType

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setResolvedType(sun::types::TypePtr type) const

Type annotation set by semantic analyzer (delegates to analysis).

Related: sun::types::TypePtr

setSkipCodegen

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setSkipCodegen(bool value)

Controls whether code generation omits this declaration.

setSourceFileId

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setSourceFileId(SourceFileId id)

Preserve the source context when parsing or synthesizing a node.

Related: SourceFileId

setSymbolPrefix

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setSymbolPrefix(const std::string &prefix)

Sets the prefix used to keep generated library symbols distinct.

setTargetDeclarationId

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setTargetDeclarationId(DeclarationId id) const

Record a resolved reference without changing the source spelling.

Related: DeclarationId

setVisibility

public · function · Source (opens in a new tab)

void sun::ast::ExprAST::setVisibility(Visibility v)

Sets which scopes may access this declaration.

Related: Visibility

shouldSkipCodegen

public · function · Source (opens in a new tab)

bool sun::ast::ExprAST::shouldSkipCodegen() const

Skip codegen flag (set by semantic analyzer for diamond import duplicates).

toString

public · function · Source (opens in a new tab)

virtual std::string sun::ast::ExprAST::toString() const =0

Debug representation of this AST node.

~ExprAST

public · function · Source (opens in a new tab)

virtual sun::ast::ExprAST::~ExprAST()=default

Destroys this object and releases its owned members.

Public Type Aliases

ChildSlotFn

public · typedef · Source (opens in a new tab)

using sun::ast::ExprAST::ChildSlotFn =  std::function<void(std::unique_ptr<ExprAST>&)>

Invoke fn on every direct child slot that holds a replaceable expression (used by AST-rewriting passes, e.g.

lowering). Strongly-typed children (e.g. a BlockExprAST member) cannot be replaced, so overrides forward into them instead of exposing their slot.

Related: ExprAST, BlockExprAST

Protected Functions

ExprAST

ExprAST()=default

protected · function · Source (opens in a new tab)

sun::ast::ExprAST::ExprAST()=default

Creates a base syntax node without a source position or analysis annotations.

ExprAST(sun::support::Position loc)

protected · function · Source (opens in a new tab)

sun::ast::ExprAST::ExprAST(sun::support::Position loc)

Creates a base syntax node at the supplied source position.

Related: sun::support::Position

analysis

protected · function · Source (opens in a new tab)

ExprAnalysis & sun::ast::ExprAST::analysis() const

Accessor for analysis data - calls ensureAnalysis to allocate correct type.

Related: ExprAnalysis

cloneBase

protected · function · Source (opens in a new tab)

void sun::ast::ExprAST::cloneBase(ExprAST &dest) const

Copy base class fields to a cloned node.

Called by derived clone() methods.

Related: ExprAST, clone()

ensureAnalysis

protected · function · Source (opens in a new tab)

virtual void sun::ast::ExprAST::ensureAnalysis() const

Virtual method to ensure analysis is allocated with the correct type Derived classes with specialized analysis types should override this.

Protected Fields

analysis_

protected · variable · Source (opens in a new tab)

std::unique_ptr<ExprAnalysis> sun::ast::ExprAST::analysis_

No documentation comment.

Related: ExprAnalysis

location_

protected · variable · Source (opens in a new tab)

sun::support::Position sun::ast::ExprAST::location_

No documentation comment.

Related: sun::support::Position

moduleDeclaration_

protected · variable · Source (opens in a new tab)

std::optional<PortableDeclarationKey> sun::ast::ExprAST::moduleDeclaration_

When set, this expression IS a fully qualified module name, identified by its defining bundle and original module path.

For a using statement, this identifies its target module instead of the statement itself. Used only by variable references, qualified names, member accesses, and using statements. Lookup uses this identity directly, without resolving source aliases in the caller. Source spelling is kept for formatting and diagnostics.

Related: PortableDeclarationKey

precompiled_

protected · variable · Source (opens in a new tab)

bool sun::ast::ExprAST::precompiled_ = false

No documentation comment.

skipCodegen_

protected · variable · Source (opens in a new tab)

bool sun::ast::ExprAST::skipCodegen_ = false

No documentation comment.

sourceFileId_

protected · variable · Source (opens in a new tab)

SourceFileId sun::ast::ExprAST::sourceFileId_ = 0

No documentation comment.

Related: SourceFileId

symbolPrefix_

protected · variable · Source (opens in a new tab)

std::string sun::ast::ExprAST::symbolPrefix_

No documentation comment.

visibility_

protected · variable · Source (opens in a new tab)

Visibility sun::ast::ExprAST::visibility_ = Visibility::Private

No documentation comment.

Related: Visibility