sun::semantic_analysis::ExpressionAnalyzer

sun::semantic_analysis::ExpressionAnalyzer

class · Source (opens in a new tab)

class sun::semantic_analysis::ExpressionAnalyzer

Resolves expressions and checks their types, conversions, and value access.

Public Functions

ExpressionAnalyzer

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

sun::semantic_analysis::ExpressionAnalyzer::ExpressionAnalyzer(SemanticContext &context, SemanticAnalyzer &analyzer)

Borrows the session context and the cooperating analysis services.

Related: SemanticContext, SemanticAnalyzer

analyzeArrayLiteral

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeArrayLiteral(sun::ast::ArrayLiteralAST &arrLit, sun::types::TypePtr expectedType=nullptr)

Resolves declarations and checks types in this array literal, recording the results on its syntax nodes.

Related: sun::ast::ArrayLiteralAST, sun::types::TypePtr

analyzeBinaryExpr

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeBinaryExpr(sun::ast::BinaryExprAST &binExpr, sun::types::TypePtr expectedType)

Resolves declarations and checks types in this binary expression, recording the results on its syntax nodes.

Related: sun::ast::BinaryExprAST, sun::types::TypePtr

analyzeExpression

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeExpression(sun::ast::ExprAST &expr, sun::types::TypePtr expectedType=nullptr)

Checks a value expression after declaration and statement dispatch.

Related: sun::ast::ExprAST, sun::types::TypePtr

analyzeIndexExpr

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeIndexExpr(sun::ast::IndexAST &arrIdx)

Resolves declarations and checks types in this index expression, recording the results on its syntax nodes.

Related: sun::ast::IndexAST

analyzeLambdaExpr

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeLambdaExpr(sun::ast::LambdaAST &lambda)

Resolves declarations and checks types in this lambda expression, recording the results on its syntax nodes.

Related: sun::ast::LambdaAST

analyzeMemberAccess

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeMemberAccess(sun::ast::MemberAccessAST &memberAccess, sun::types::TypePtr expectedType)

Resolves declarations and checks types in this member access, recording the results on its syntax nodes.

Related: sun::ast::MemberAccessAST, sun::types::TypePtr

analyzeNumberLiteral

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeNumberLiteral(sun::ast::ExprAST &expr, sun::types::TypePtr expectedType)

Value expressions (analysis_expressions.cpp).

Related: sun::ast::ExprAST, sun::types::TypePtr, analysis_expressions.cpp

analyzeQualifiedName

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeQualifiedName(sun::ast::QualifiedNameAST &qualName)

Resolves declarations and checks types in this qualified name, recording the results on its syntax nodes.

Related: sun::ast::QualifiedNameAST

analyzeSliceExpr

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeSliceExpr(sun::ast::ExprAST &expr)

Resolves declarations and checks types in this slice expression, recording the results on its syntax nodes.

Related: sun::ast::ExprAST

analyzeTernaryExpr

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeTernaryExpr(sun::ast::TernaryExprAST &ternary, sun::types::TypePtr expectedType)

Resolves declarations and checks types in this ternary expression, recording the results on its syntax nodes.

Related: sun::ast::TernaryExprAST, sun::types::TypePtr

analyzeUnaryExpr

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeUnaryExpr(sun::ast::UnaryExprAST &unaryExpr)

Resolves declarations and checks types in this unary expression, recording the results on its syntax nodes.

Related: sun::ast::UnaryExprAST

checkArgumentPlaces

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

void sun::semantic_analysis::ExpressionAnalyzer::checkArgumentPlaces(const std::vector< std::unique_ptr< sun::ast::ExprAST > > &args, const std::vector< sun::types::TypePtr > &paramTypes, const std::string &callee, const sun::support::Position &loc)

An argument bound to a ref T parameter must be a mutable place; one bound to a by-value compound parameter is a move (see checkMoveSource).

Related: sun::ast::ExprAST, sun::types::TypePtr, sun::support::Position

checkExternVariableAccessAllowed

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

void sun::semantic_analysis::ExpressionAnalyzer::checkExternVariableAccessAllowed(const VariableInfo &info, const std::string &displayName, const sun::support::Position &loc) const

Reject access to C-owned global storage outside an unsafe block.

(Calls into C and unsafe intrinsics are gated the same way by CallAnalyzer.)

Related: VariableInfo, sun::support::Position, CallAnalyzer

checkIntegerDivision

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

void sun::semantic_analysis::ExpressionAnalyzer::checkIntegerDivision(const sun::ast::ExprAST &lhs, const sun::ast::ExprAST &rhs, sun::parsing::TokenKind op, const sun::support::Position &location)

Requires a handler or throwing function unless integer division is safe.

Related: sun::ast::ExprAST, sun::parsing::TokenKind, sun::support::Position

checkMethodReceiver

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

bool sun::semantic_analysis::ExpressionAnalyzer::checkMethodReceiver(const sun::ast::ExprAST &receiver, const std::string &name, bool methodIsConst, bool isConstructor, const sun::support::Position &loc)

Calling method on receiver: a non-const method needs a mutable receiver.

Returns true when the receiver is immutable, so a ref T result must be downgraded to const ref T.

Related: sun::ast::ExprAST, sun::support::Position

checkMoveSource

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

void sun::semantic_analysis::ExpressionAnalyzer::checkMoveSource(const sun::ast::ExprAST &value, const sun::support::Position &loc)

value is consumed by value: a compound field read out of an immutable object (a partial move) or a constant global is rejected.

Related: sun::ast::ExprAST, sun::support::Position

checkUnsafeCall

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

void sun::semantic_analysis::ExpressionAnalyzer::checkUnsafeCall(bool requiresUnsafe, const std::string &name, const sun::support::Position &loc) const

Require an unsafe block when a call has a caller-side safety contract.

Related: sun::support::Position

immutableBaseOf

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

std::string sun::semantic_analysis::ExpressionAnalyzer::immutableBaseOf(const sun::ast::ExprAST &place)

Constness.

A place (x, x.f, x[i], this.f, a ? x : y, a call result) cannot be changed when its base is a const variable, a const ref, or this inside a const method. Returns why, or an empty string when the place may be changed.

Related: sun::ast::ExprAST

rejectBorrowOfByValueCapture

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

void sun::semantic_analysis::ExpressionAnalyzer::rejectBorrowOfByValueCapture(const sun::ast::ExprAST &target, const sun::support::Position &loc)

Throw when target names a variable the enclosing lambda picked up without a capture list.

That capture is the closure's own copy, so a borrow of it would alias the copy rather than the original. Every borrow site calls this, so the explanation is worded once.

Related: sun::ast::ExprAST, sun::support::Position

requireMutablePlace

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

void sun::semantic_analysis::ExpressionAnalyzer::requireMutablePlace(const sun::ast::ExprAST &place, const std::string &action, const sun::support::Position &loc)

Throws "Cannot <action> <why>" when place cannot be changed.

Related: sun::ast::ExprAST, sun::support::Position

resolveClassMemberType

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

TypePtr sun::semantic_analysis::ExpressionAnalyzer::resolveClassMemberType(const sun::ast::MemberAccessAST &expr, const sun::types::TypePtr &objectType, const std::string &memberName)

Resolve the receiver member and enforce access rules.

Related: sun::types::TypePtr, sun::ast::MemberAccessAST

resolveMemberType

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

TypePtr sun::semantic_analysis::ExpressionAnalyzer::resolveMemberType(const sun::ast::MemberAccessAST &expr)

Resolve a member against its prepared receiver and record its identity.

Related: sun::types::TypePtr, sun::ast::MemberAccessAST

resolveModuleMemberType

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

TypePtr sun::semantic_analysis::ExpressionAnalyzer::resolveModuleMemberType(const sun::ast::MemberAccessAST &expr, const sun::types::TypePtr &objectType, const std::string &memberName)

Resolve the receiver member and enforce access rules.

Related: sun::types::TypePtr, sun::ast::MemberAccessAST

resolveModuleReference

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

TypePtr sun::semantic_analysis::ExpressionAnalyzer::resolveModuleReference(const sun::ast::ExprAST &expr)

Resolve a module identity and enforce its visibility.

Related: sun::types::TypePtr, sun::ast::ExprAST

resolveTypeParameterMemberType

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

TypePtr sun::semantic_analysis::ExpressionAnalyzer::resolveTypeParameterMemberType(const sun::ast::MemberAccessAST &expr, const sun::types::TypePtr &objectType, const std::string &memberName)

Resolve the receiver member and enforce access rules.

Related: sun::types::TypePtr, sun::ast::MemberAccessAST

resolveVariableReferenceType

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

TypePtr sun::semantic_analysis::ExpressionAnalyzer::resolveVariableReferenceType(const sun::ast::VariableReferenceAST &expr)

Resolve a variable or callable name, recording its declaration identity.

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

validateBorrowTarget

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

void sun::semantic_analysis::ExpressionAnalyzer::validateBorrowTarget(const sun::ast::ExprAST &target, const sun::support::Position &loc)

Throw unless target is something a borrow can bind: an addressable lvalue that is not a slice, a class index result, or a packed field.

Related: sun::ast::ExprAST, sun::support::Position

Private Functions

analyzeStructLiteral

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

void sun::semantic_analysis::ExpressionAnalyzer::analyzeStructLiteral(sun::ast::StructLiteralAST &literal, const sun::types::TypePtr &expectedType)

Resolve a { field: value } literal against the type the context expects.

A struct literal has no type of its own, so without an expected class type there is nothing to check the field names against.

Related: sun::ast::StructLiteralAST, sun::types::TypePtr

maybeResolveBoundMethodRef

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

void sun::semantic_analysis::ExpressionAnalyzer::maybeResolveBoundMethodRef(sun::ast::MemberAccessAST &memberAccess, sun::types::TypePtr expectedType)

If the member access names a class method in value position, resolve it as a bound method reference: pick the overload (using expectedType when the name is overloaded), set a LambdaType resolved type and the isBoundMethodRef flag.

No-op for fields, non-class receivers, and call-position callees (those never route through here).

Related: sun::ast::MemberAccessAST, sun::types::TypePtr, LambdaType

Private Fields

ctx_

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

SemanticContext& sun::semantic_analysis::ExpressionAnalyzer::ctx_

No documentation comment.

Related: SemanticContext

sema_

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

SemanticAnalyzer& sun::semantic_analysis::ExpressionAnalyzer::sema_

No documentation comment.

Related: SemanticAnalyzer