sun::ast::PrototypeAST

sun::ast::PrototypeAST

class · Source (opens in a new tab)

class sun::ast::PrototypeAST

Top-level nodes (not derived from ExprAST).

Public Functions

PrototypeAST

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

sun::ast::PrototypeAST::PrototypeAST(std::string Name, std::vector< std::pair< std::string, TypeAnnotation > > args, std::optional< TypeAnnotation > retType=std::nullopt, std::vector< TypeParameter > typeParams={}, std::optional< VariadicParam > variadicParam=std::nullopt)

Creates this syntax node and takes ownership of any supplied child expressions.

Related: TypeAnnotation, TypeParameter, VariadicParam

canThrow

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

bool sun::ast::PrototypeAST::canThrow() const

Check if this function can throw (declared with "throws IError").

clearComputedAnalysis

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

void sun::ast::PrototypeAST::clearComputedAnalysis() const

Clear the resolved signature while retaining declaration identities.

clearTypeParameters

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

void sun::ast::PrototypeAST::clearTypeParameters()

Removes generic parameters after a declaration is specialized.

clone

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

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

Clone the prototype via protobuf serialization (deep copy).

Related: PrototypeAST

declarationIdentity

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

sun::semantic_analysis::DeclarationIdentity & sun::ast::PrototypeAST::declarationIdentity() const

Access identities for the function and its parameters.

Related: sun::semantic_analysis::DeclarationIdentity

getAllParamNames

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

std::vector< std::string > sun::ast::PrototypeAST::getAllParamNames() const

Their names, in the same order.

A pack's elements are args.0, args.1, … — the names the body's expanded references resolve against.

getAllParamTypes

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

std::vector< TypePtr > sun::ast::PrototypeAST::getAllParamTypes() const

The full parameter list this specialization is emitted with: the fixed parameters followed by the pack's elements.

Codegen appends them in this order, so every argument check lines up against the same list.

Related: TypePtr

getAnalysis

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

const PrototypeAnalysis * sun::ast::PrototypeAST::getAnalysis() const

Returns the analysis stored by this object.

Related: PrototypeAnalysis

getArgNames

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

std::vector< std::string > sun::ast::PrototypeAST::getArgNames() const

Returns the parameter names.

getArgs

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

const std::vector< std::pair< std::string, TypeAnnotation > > & sun::ast::PrototypeAST::getArgs() const

Provides the ordered arguments associated with this expression.

Related: TypeAnnotation

getCaptures

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

const std::vector< Capture > & sun::ast::PrototypeAST::getCaptures() const

Return computed captures, or an empty list before analysis.

Related: Capture

getConstRefCaptureNames

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

const std::vector< std::string > & sun::ast::PrototypeAST::getConstRefCaptureNames() const

Returns the names of captures borrowed without write access.

getDeclarationId

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

DeclarationId sun::ast::PrototypeAST::getDeclarationId() const

Return this function's identity in the current analysis session.

Related: DeclarationId

getDoc

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

const std::string & sun::ast::PrototypeAST::getDoc() const

Comment written above the function (see doc_comments.h).

Related: doc_comments.h

getLifetimeParameters

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

const std::vector< LifetimeParameter > & sun::ast::PrototypeAST::getLifetimeParameters() const

Provides the declared lifetime parameters used to check borrowed values.

Related: LifetimeParameter

getLinkName

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

const std::string & sun::ast::PrototypeAST::getLinkName() const

The symbol to emit: the as name when given, otherwise the Sun name.

getLocation

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

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

Returns the source position used for diagnostics.

Related: sun::support::Position

getMutableArgs

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

std::vector< std::pair< std::string, TypeAnnotation > > & sun::ast::PrototypeAST::getMutableArgs()

Returns the modifiable argument expressions.

Related: TypeAnnotation

getName

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

const std::string & sun::ast::PrototypeAST::getName() const

Returns the declared name used to identify this object.

getOwnedCaptureNames

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

const std::vector< std::string > & sun::ast::PrototypeAST::getOwnedCaptureNames() const

Returns the names of captures whose ownership was transferred.

getQualifiedName

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

const sun::semantic_analysis::QualifiedName & sun::ast::PrototypeAST::getQualifiedName() const

Qualified name (after semantic analysis qualifies it).

Related: sun::semantic_analysis::QualifiedName

getRefCaptureNames

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

const std::vector< std::string > & sun::ast::PrototypeAST::getRefCaptureNames() const

Returns the names of borrowed captures.

getResolvedParamTypes

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

const std::vector< TypePtr > & sun::ast::PrototypeAST::getResolvedParamTypes() const

Returns the parameter types selected by analysis.

Related: TypePtr

getResolvedReturnType

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

TypePtr sun::ast::PrototypeAST::getResolvedReturnType() const

Returns the resolved return type stored by this object.

Related: TypePtr

getResolvedVariadicTypes

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

const std::vector< TypePtr > & sun::ast::PrototypeAST::getResolvedVariadicTypes() const

Returns the concrete variadic parameter types.

Related: TypePtr

getReturnType

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

const std::optional< TypeAnnotation > & sun::ast::PrototypeAST::getReturnType() const

Returns the semantic type of the function result.

Related: TypeAnnotation

getType

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

ASTNodeType sun::ast::PrototypeAST::getType() const

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

Related: ASTNodeType

getTypeBindings

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

const std::vector< std::pair< std::string, TypePtr > > & sun::ast::PrototypeAST::getTypeBindings() const

Returns the type bindings stored by this object.

Related: TypePtr

getTypeParameterNames

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

std::vector< std::string > sun::ast::PrototypeAST::getTypeParameterNames() const

Returns the names used to bind generic arguments during specialization.

getTypeParameters

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

const std::vector< TypeParameter > & sun::ast::PrototypeAST::getTypeParameters() const

Generic method support.

Related: TypeParameter

getVariadicParam

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

const VariadicParam & sun::ast::PrototypeAST::getVariadicParam() const

Returns the variadic parameter declaration.

Related: VariadicParam

getVariadicParamName

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

const std::string & sun::ast::PrototypeAST::getVariadicParamName() const

The pack's name, or empty when the signature declares no pack.

getVariadicTypeAnnotation

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

const TypeAnnotation & sun::ast::PrototypeAST::getVariadicTypeAnnotation() const

Returns the variadic parameter type annotation.

Related: TypeAnnotation

hasAnalysis

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

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

Reports whether this object has analysis.

hasClosure

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

bool sun::ast::PrototypeAST::hasClosure() const

Report whether analysis found a closure environment.

hasLinkName

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

bool sun::ast::PrototypeAST::hasLinkName() const

Explicit C symbol from extern function sunName(...) T as "c_name";.

Lets a Sun-side name differ from the symbol actually linked against.

hasQualifiedName

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

bool sun::ast::PrototypeAST::hasQualifiedName() const

Reports whether a name including the enclosing scopes has been assigned.

hasRefCaptures

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

bool sun::ast::PrototypeAST::hasRefCaptures() const

True if the closure holds state bound to the frame that built it: a borrow of a local, or a value it owns and drops there.

Either way the closure must not outlive that frame.

hasResolvedParamTypes

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

bool sun::ast::PrototypeAST::hasResolvedParamTypes() const

Reports whether this object has resolved param types.

hasResolvedReturnType

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

bool sun::ast::PrototypeAST::hasResolvedReturnType() const

Reports whether this object has resolved return type.

hasResolvedVariadicTypes

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

bool sun::ast::PrototypeAST::hasResolvedVariadicTypes() const

Reports whether this object has resolved variadic types.

hasReturnType

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

bool sun::ast::PrototypeAST::hasReturnType() const

Reports whether this object has return type.

hasTypeBindings

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

bool sun::ast::PrototypeAST::hasTypeBindings() const

Reports whether this object has type bindings.

hasVariadicParam

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

bool sun::ast::PrototypeAST::hasVariadicParam() const

The trailing args... pack, when the signature declares one.

Callers that only want a piece of it have the three shorthands below.

Related: args

hasVariadicTypeAnnotation

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

bool sun::ast::PrototypeAST::hasVariadicTypeAnnotation() const

Reports whether this object has variadic type annotation.

isCVariadic

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

bool sun::ast::PrototypeAST::isCVariadic() const

C-style trailing varargs: fn(fmt: raw_ptr<u8>, ...).

Unrelated to the named args... pack above — this one binds no name and only affects the LLVM function type's isVarArg flag. Extern declarations only.

Related: args

isConstMethod

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

bool sun::ast::PrototypeAST::isConstMethod() const

A class/interface method declared const method: its body may not change this, and it may be called on a constant receiver.

isConstRefCapture

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

bool sun::ast::PrototypeAST::isConstRefCapture(const std::string &name) const

True if name was written [const ref name] rather than [ref name].

isGeneric

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

bool sun::ast::PrototypeAST::isGeneric() const

Reports whether this declaration still has unbound type parameters.

isOwnedCapture

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

bool sun::ast::PrototypeAST::isOwnedCapture(const std::string &name) const

True if name was written in the capture list without ref.

isTemplate

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

bool sun::ast::PrototypeAST::isTemplate() const

Emitted as one function per specialization: either because it has type parameters, or because its args... pack is keyed on the call's argument types.

A pack-only template has no type arguments but many arities.

A specialization keeps its pack — codegen needs the name to number the elements — so what marks it as no longer a template is that the pack's types are resolved, the same way clearTypeParameters() does for <T>.

Related: args, clearTypeParameters()

isUnsafeMethod

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

bool sun::ast::PrototypeAST::isUnsafeMethod() const

Whether callers must uphold this method's safety contract.

paramTypeNamed

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

TypePtr sun::ast::PrototypeAST::paramTypeNamed(const std::string &name) const

The declared type of the parameter named name, or null if there is no such parameter.

Codegen walks a function's LLVM arguments, which are named from getAllParamNames(), so asking by name rather than by index keeps the two lists from drifting — and a closure or fat-pointer argument, which is not a parameter at all, simply answers null.

Related: TypePtr, getAllParamNames()

resetAnalysisSession

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

void sun::ast::PrototypeAST::resetAnalysisSession() const

Drop all annotations when discarding the owning session.

setCVariadic

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

void sun::ast::PrototypeAST::setCVariadic(bool v)

Updates the C variadic-call setting.

setCaptures

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

void sun::ast::PrototypeAST::setCaptures(const std::vector< Capture > &caps)

Record the bindings selected for this closure in the current session.

Related: Capture

setConstMethod

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

void sun::ast::PrototypeAST::setConstMethod(bool v)

Marks whether the method receives its object without write access.

setConstRefCaptureNames

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

void sun::ast::PrototypeAST::setConstRefCaptureNames(std::vector< std::string > names)

Updates the names of captures borrowed without write access.

setDeclarationId

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

void sun::ast::PrototypeAST::setDeclarationId(DeclarationId id) const

Assign the identity shared by the function and its prototype.

Related: DeclarationId

setDoc

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

void sun::ast::PrototypeAST::setDoc(std::string doc)

Stores the source documentation comment for this declaration.

setLifetimeParameters

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

void sun::ast::PrototypeAST::setLifetimeParameters(std::vector< LifetimeParameter > params)

Lifetime parameter support.

Related: LifetimeParameter

setLinkName

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

void sun::ast::PrototypeAST::setLinkName(std::string name)

Updates the link name stored by this object.

setLocation

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

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

Sets the source position used for diagnostics.

Related: sun::support::Position

setName

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

void sun::ast::PrototypeAST::setName(std::string name)

Updates the name stored by this object.

setOwnedCaptureNames

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

void sun::ast::PrototypeAST::setOwnedCaptureNames(std::vector< std::string > names)

Updates the names of captures whose ownership was transferred.

setQualifiedName

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

void sun::ast::PrototypeAST::setQualifiedName(sun::semantic_analysis::QualifiedName qname)

Records the declaration name together with its enclosing scopes.

Related: sun::semantic_analysis::QualifiedName

setRefCaptureNames

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

void sun::ast::PrototypeAST::setRefCaptureNames(std::vector< std::string > names)

Names declared in the lambda's [ref x, ...] capture list (parser-derived source of truth; Capture::kind is derived from it during analysis).

Related: Capture::kind

setResolvedParamTypes

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

void sun::ast::PrototypeAST::setResolvedParamTypes(std::vector< TypePtr > types)

Resolved types for specialized generic functions Set during instantiation, used by codegen to skip type annotation conversion.

Related: TypePtr

setResolvedReturnType

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

void sun::ast::PrototypeAST::setResolvedReturnType(TypePtr type)

Updates the resolved return type stored by this object.

Related: TypePtr

setResolvedVariadicTypes

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

void sun::ast::PrototypeAST::setResolvedVariadicTypes(std::vector< TypePtr > types)

The pack's element types for this specialization, in order.

An empty list is still a resolved pack — the call simply passed nothing.

Related: TypePtr

setReturnType

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

void sun::ast::PrototypeAST::setReturnType(TypeAnnotation type)

Set the return type (used by semantic analyzer for type inference).

Related: TypeAnnotation

setTypeBindings

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

void sun::ast::PrototypeAST::setTypeBindings(std::vector< std::pair< std::string, TypePtr > > bindings)

Type parameter bindings for specialized generic functions.

Related: TypePtr

setUnsafeMethod

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

void sun::ast::PrototypeAST::setUnsafeMethod(bool v)

Mark a method as requiring an unsafe block at each call.

Private Functions

analysis

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

PrototypeAnalysis & sun::ast::PrototypeAST::analysis() const

Lazy accessor for analysis data.

Related: PrototypeAnalysis

Private Fields

Name

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

std::string sun::ast::PrototypeAST::Name

No documentation comment.

analysis_

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

std::unique_ptr<PrototypeAnalysis> sun::ast::PrototypeAST::analysis_

No documentation comment.

Related: PrototypeAnalysis

args

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

std::vector<std::pair<std::string, TypeAnnotation> > sun::ast::PrototypeAST::args

No documentation comment.

Related: TypeAnnotation

cVariadic_

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

bool sun::ast::PrototypeAST::cVariadic_ = false

No documentation comment.

constMethod_

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

bool sun::ast::PrototypeAST::constMethod_ = false

No documentation comment.

constRefCaptureNames

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

std::vector<std::string> sun::ast::PrototypeAST::constRefCaptureNames

No documentation comment.

doc_

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

std::string sun::ast::PrototypeAST::doc_

No documentation comment.

lifetimeParameters

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

std::vector<LifetimeParameter> sun::ast::PrototypeAST::lifetimeParameters

No documentation comment.

Related: LifetimeParameter

linkName_

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

std::optional<std::string> sun::ast::PrototypeAST::linkName_

No documentation comment.

location_

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

sun::support::Position sun::ast::PrototypeAST::location_

No documentation comment.

Related: sun::support::Position

ownedCaptureNames

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

std::vector<std::string> sun::ast::PrototypeAST::ownedCaptureNames

No documentation comment.

refCaptureNames

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

std::vector<std::string> sun::ast::PrototypeAST::refCaptureNames

No documentation comment.

returnType

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

std::optional<TypeAnnotation> sun::ast::PrototypeAST::returnType

No documentation comment.

Related: TypeAnnotation

typeParameters

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

std::vector<TypeParameter> sun::ast::PrototypeAST::typeParameters

No documentation comment.

Related: TypeParameter

unsafeMethod_

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

bool sun::ast::PrototypeAST::unsafeMethod_ = false

No documentation comment.

variadicParam_

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

std::optional<VariadicParam> sun::ast::PrototypeAST::variadicParam_

No documentation comment.

Related: VariadicParam