sun::semantic_analysis::CallAnalyzer

sun::semantic_analysis::CallAnalyzer

class · Source (opens in a new tab)

class sun::semantic_analysis::CallAnalyzer

Resolves and checks call expressions, recording the resolved callee and argument conversions on the AST for codegen.

Types

Public Functions

CallAnalyzer

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

sun::semantic_analysis::CallAnalyzer::CallAnalyzer(SemanticContext &ctx, SemanticAnalyzer &sema, GenericSpecializer &generics, type_analysis::TypeResolver &types)

Connects call checking to semantic analysis, generic specialization, and type resolution.

Related: SemanticContext, SemanticAnalyzer, GenericSpecializer, type_analysis::TypeResolver

analyzeCall

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

void sun::semantic_analysis::CallAnalyzer::analyzeCall(CallExprAST &callExpr, sun::types::TypePtr expectedType=nullptr)

Analyze a call: resolve the callee against the argument types, check the arguments against the chosen signature, and record one ArgConversion per argument for codegen.

Related: CallExprAST, sun::types::TypePtr, ArgConversion

analyzeGenericCall

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

void sun::semantic_analysis::CallAnalyzer::analyzeGenericCall(GenericCallAST &genericCall)

Analyze name<T, ...>(args): an intrinsic, a generic class construction or a generic function call, told apart by what the name resolves to.

Related: GenericCallAST

resolveModuleQualifiedCall

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

const FunctionInfo * sun::semantic_analysis::CallAnalyzer::resolveModuleQualifiedCall(const MemberAccessAST &memberAccess, const sun::types::TypePtr &objectType, const std::vector< sun::types::TypePtr > &argTypes) const

Resolve a module-qualified call mod.foo(args...) against the actual argument types and stamp the chosen overload's declaration ID onto the member access so codegen calls exactly the selected declaration.

Returns nullptr if the module has no overload matching those arguments.

Related: FunctionInfo, MemberAccessAST, sun::types::TypePtr

Private Functions

analyzeCallArguments

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

std::vector< TypePtr > sun::semantic_analysis::CallAnalyzer::analyzeCallArguments(CallExprAST &callExpr, sun::types::TypePtr expectedType)

Analyze a call's arguments and give back their types.

Arguments go first so overload resolution has real types to match against, which means an argument that needs a hint — an array literal, an overloaded bound method reference — takes it from a provisional look at the callee. Also expands a variadic pack (f(args...)) into the concrete arguments it stands for.

Related: sun::types::TypePtr, CallExprAST

analyzeGenericClassConstruction

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

void sun::semantic_analysis::CallAnalyzer::analyzeGenericClassConstruction(GenericCallAST &genericCall)

Analyze C<T>(...): specialize the generic class, then check the arguments against the chosen constructor.

Related: GenericCallAST

analyzeGenericFunctionCall

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

void sun::semantic_analysis::CallAnalyzer::analyzeGenericFunctionCall(GenericCallAST &genericCall)

Analyze f<T>(...): resolve the template, fill in any type arguments the call left to the arguments, then specialize it.

Related: GenericCallAST

analyzeIntrinsicCall

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

void sun::semantic_analysis::CallAnalyzer::analyzeIntrinsicCall(GenericCallAST &genericCall)

Analyze an intrinsic call: the arguments only, since codegen decides what the intrinsic does.

Related: GenericCallAST

checkArgumentTypes

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

void sun::semantic_analysis::CallAnalyzer::checkArgumentTypes(CallExprAST &callExpr, const std::vector< sun::types::TypePtr > &paramTypes, const std::string &funcName, bool calleeIsIntrinsic)

Check each argument against its parameter when no overload resolution vouched for them already: literal coercion, then the implicit conversions a call site allows.

calleeIsIntrinsic unlocks the byte-pointer erasure only intrinsics may use.

Related: CallExprAST, sun::types::TypePtr

checkExternCallAllowed

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

void sun::semantic_analysis::CallAnalyzer::checkExternCallAllowed(const FunctionInfo &info, const std::string &displayName, const sun::support::Position &loc) const

Calling into C leaves everything the borrow checker and type system guarantee, so it is gated on unsafe — the same rule the equivalent intrinsics (_malloc, _free, ...) already follow.

Throws if info names a C extern and the call site is not inside an unsafe block.

Related: FunctionInfo, sun::support::Position

checkRequiresUnsafeBlock

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

void sun::semantic_analysis::CallAnalyzer::checkRequiresUnsafeBlock(const std::string &name, const sun::support::Position &loc) const

The same rule for intrinsics: those that read or write unchecked memory are gated on unsafe.

sun::codegen::intrinsics::requiresUnsafeBlock decides which, and this is where it is applied — for generic and non-generic intrinsics alike. Throws if name is one of them and the call site is not inside a block.

Related: sun::support::Position, sun::codegen::intrinsics::requiresUnsafeBlock

checkThrowPropagation

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

void sun::semantic_analysis::CallAnalyzer::checkThrowPropagation(const CallExprAST &callExpr, const CalleeResolution &callee, const std::string &funcName)

A call to something that throws must sit in a try block or in a function that itself throws.

Related: CallExprAST, CalleeResolution

expandPackArguments

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

void sun::semantic_analysis::CallAnalyzer::expandPackArguments(std::vector< std::unique_ptr< ExprAST > > &args)

Expand a variadic pack (args...) in a call's argument list into concrete, already-typed VariableReferenceAST nodes ("args.0", "args.1", ...), using the enclosing function scope's recorded variadic param.

No-op when there is no enclosing variadic param or no pack argument is present.

Related: ExprAST, VariableReferenceAST

findModuleCallee

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

SymbolMatch sun::semantic_analysis::CallAnalyzer::findModuleCallee(const MemberAccessAST &memberAccess, const sun::types::TypePtr &objectType, SymbolKind kind, const std::vector< sun::types::TypePtr > *argTypes=nullptr) const

The member a module-qualified call mod.name(args...) names, of the given kind, or an empty match when the object is not a module or the module has no such member.

Pass the argument types to pick among a function's overloads.

Related: SymbolMatch, MemberAccessAST, sun::types::TypePtr, SymbolKind

recordInitArgumentConversions

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

void sun::semantic_analysis::CallAnalyzer::recordInitArgumentConversions(GenericCallAST &genericCall)

Decide how each argument of an _init call reaches the parameters of the constructor it selects, so codegen lowers them like any constructor call.

Related: GenericCallAST

recordSpawnArgumentConversions

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

void sun::semantic_analysis::CallAnalyzer::recordSpawnArgumentConversions(GenericCallAST &genericCall)

Decide how each argument of a _spawn call reaches the spawned lambda's parameters, and mark what the thread takes over as moved.

Related: GenericCallAST

reportNoMethodForArgCount

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

void sun::semantic_analysis::CallAnalyzer::reportNoMethodForArgCount(const sun::types::ClassType &cls, const std::string &name, const std::vector< sun::types::TypePtr > &argTypes, const sun::support::Position &loc) const

Throws "No matching overload" when the class has methods called name but none of them takes argTypes.size() arguments.

Silent otherwise, so callers can still fall back on their own type-mismatch diagnostics.

Related: sun::types::ClassType, sun::types::TypePtr, sun::support::Position

resolveCallSignature

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

CallAnalyzer::CallSignature sun::semantic_analysis::CallAnalyzer::resolveCallSignature(CallExprAST &callExpr, CalleeResolution &callee, const std::vector< sun::types::TypePtr > &argTypes)

The signature the arguments are checked against, from the resolved overload, the callee's function or lambda type, or a constructor's chosen init.

Related: CallSignature, CallExprAST, CalleeResolution, sun::types::TypePtr

resolveCallee

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

CallAnalyzer::CalleeResolution sun::semantic_analysis::CallAnalyzer::resolveCallee(CallExprAST &callExpr, const std::vector< sun::types::TypePtr > &argTypes)

Resolve what a call is actually calling: an overload by name, a constructor, a method on an object, or an expression that evaluates to something callable.

Analyzes the callee and stamps the resolved name and type onto it; the checking of arguments against the result is analyzeCall's own step.

Related: CalleeResolution, CallExprAST, sun::types::TypePtr

resolveConstructorParams

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

std::optional< std::vector< TypePtr > > sun::semantic_analysis::CallAnalyzer::resolveConstructorParams(const sun::types::ClassType &classType, const std::vector< sun::types::TypePtr > &argTypes, const ExprAST &call)

The parameter list of the init overload a positional construction C(args) selects.

Throws when the class has an init but none takes these arguments, or has none at all yet arguments were given. Returns nullopt for the one silent case: no init and no arguments.

Related: sun::types::TypePtr, sun::types::ClassType, ExprAST

resolveGenericCallTarget

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

CallAnalyzer::GenericCallTarget sun::semantic_analysis::CallAnalyzer::resolveGenericCallTarget(const GenericFunctionInfo &genericInfo, const std::vector< sun::types::TypePtr > &argTypes, const std::vector< sun::types::TypePtr > &writtenTypeArgs, const std::string &displayName, std::optional< sun::support::Position > loc)

Resolve a call of a generic function, qualified or not, against its argument types.

A call may name only the leading type parameters — f<i32>(x) for f<T, U> — and leave the rest to the arguments; a call with no type arguments infers them all. Inference reads the fixed parameters only, so a call filling a pack still says what T is from its leading arguments: spawn(f, 1, 2).

Related: GenericCallTarget, GenericFunctionInfo, sun::types::TypePtr, sun::support::Position

resolveGenericFunctionCallType

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

TypePtr sun::semantic_analysis::CallAnalyzer::resolveGenericFunctionCallType(const GenericCallAST &call)

Read the selected generic signature or resolve its abstract return annotation.

Related: sun::types::TypePtr, GenericCallAST

resolveIntrinsicCallType

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

TypePtr sun::semantic_analysis::CallAnalyzer::resolveIntrinsicCallType(const GenericCallAST &call)

The result type of an intrinsic call (_sizeof, _load, _to_ref, ...).

Related: sun::types::TypePtr, GenericCallAST

resolveMemberCallee

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

CallAnalyzer::CalleeResolution sun::semantic_analysis::CallAnalyzer::resolveMemberCallee(CallExprAST &callExpr, MemberAccessAST &memberAccess, const std::vector< sun::types::TypePtr > &argTypes)

obj.m(args): a method, a module member, or a builtin type's method.

Related: CalleeResolution, CallExprAST, MemberAccessAST, sun::types::TypePtr

resolveMethodCallee

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

CallAnalyzer::CalleeResolution sun::semantic_analysis::CallAnalyzer::resolveMethodCallee(MemberAccessAST &memberAccess, const sun::types::TypePtr &objectType, const std::vector< sun::types::TypePtr > &argTypes)

obj.m(args) on a class: a callable field, or a method overload.

Related: CalleeResolution, MemberAccessAST, sun::types::TypePtr

resolveModuleQualifiedGenericCall

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

std::optional< CallAnalyzer::CalleeResolution > sun::semantic_analysis::CallAnalyzer::resolveModuleQualifiedGenericCall(const MemberAccessAST &memberAccess, const sun::types::TypePtr &objectType, const std::vector< sun::types::TypePtr > &argTypes)

Resolve a module-qualified call of a generic function, mod.f(args...) or mod.f<A>(args...), by way of resolveGenericCallTarget.

Pins the callee to what that gave and returns the resolution, whose takesPack is set when the signature cannot yet list the pack's elements. Returns nullopt if the module has no generic function of that name.

Related: CalleeResolution, MemberAccessAST, sun::types::TypePtr

resolveNamedCallee

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

CallAnalyzer::CalleeResolution sun::semantic_analysis::CallAnalyzer::resolveNamedCallee(CallExprAST &callExpr, sun::ast::VariableReferenceAST &varRef, const std::vector< sun::types::TypePtr > &argTypes)

f(args): an overload, a constructor, a generic, or a variable.

Related: CalleeResolution, CallExprAST, sun::ast::VariableReferenceAST, sun::types::TypePtr

Private Fields

ctx_

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

SemanticContext& sun::semantic_analysis::CallAnalyzer::ctx_

No documentation comment.

Related: SemanticContext

generics_

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

GenericSpecializer& sun::semantic_analysis::CallAnalyzer::generics_

No documentation comment.

Related: GenericSpecializer

resolver_

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

type_analysis::TypeResolver& sun::semantic_analysis::CallAnalyzer::resolver_

No documentation comment.

Related: type_analysis::TypeResolver

sema_

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

SemanticAnalyzer& sun::semantic_analysis::CallAnalyzer::sema_

No documentation comment.

Related: SemanticAnalyzer