sun::semantic_analysis::DeclarationAnalyzer
class · Source (opens in a new tab)
class sun::semantic_analysis::DeclarationAnalyzerChecks declarations and signatures and tracks global initializer dependencies.
Public Functions
- DeclarationAnalyzer
- analyzeDeclareType
- analyzeFunctionDefinition
- analyzeGlobal
- analyzeModuleDefinition
- analyzeMoonScope
- analyzeReferenceCreation
- analyzeVariableCreation
- analyzeVariableDeclaration
- applyFunctionInfoToProto
- checkAnnotationLifetimes
- checkSignatureLifetimes
- ensureGlobalAnalyzed
- ensureModuleGlobalAnalyzed
- getFunctionInfo
- getLambdaInfo
- isTrackedGlobal
- registerModuleVariable
- tryAnalyzeDeclaration
- validateTypeParameter
- verifyGlobalVarIsNotRepeated
DeclarationAnalyzer
public · function · Source (opens in a new tab)
sun::semantic_analysis::DeclarationAnalyzer::DeclarationAnalyzer(SemanticContext &context, SemanticAnalyzer &analyzer)Borrows the session context and the cooperating analysis services.
Related: SemanticContext, SemanticAnalyzer
analyzeDeclareType
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeDeclareType(sun::ast::DeclareTypeAST &declareExpr)Resolves declarations and checks types in this declare type, recording the results on its syntax nodes.
Related: sun::ast::DeclareTypeAST
analyzeFunctionDefinition
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeFunctionDefinition(sun::ast::FunctionAST &func)Resolves declarations and checks types in this function definition, recording the results on its syntax nodes.
Related: sun::ast::FunctionAST
analyzeGlobal
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeGlobal(sun::ast::VariableCreationAST &global, SemanticScope &scope)Analyzes a file-scope or module-scope variable once, whether the walk over the program reached it or an earlier use asked for it first.
scope is the file or module scope that declares it. Reports a cycle when the variable's own initializer leads back to it.
Related: sun::ast::VariableCreationAST, SemanticScope
analyzeModuleDefinition
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeModuleDefinition(sun::ast::ModuleAST &nsDecl)Resolves declarations and checks types in this module definition, recording the results on its syntax nodes.
Related: sun::ast::ModuleAST
analyzeMoonScope
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeMoonScope(sun::ast::ExprAST &expr)Resolves declarations and checks types in this moon scope, recording the results on its syntax nodes.
Related: sun::ast::ExprAST
analyzeReferenceCreation
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeReferenceCreation(sun::ast::ReferenceCreationAST &refCreate)Resolves declarations and checks types in this reference creation, recording the results on its syntax nodes.
Related: sun::ast::ReferenceCreationAST
analyzeVariableCreation
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeVariableCreation(sun::ast::VariableCreationAST &varCreate)Bindings and assignments (analysis_statements.cpp).
Related: sun::ast::VariableCreationAST, analysis_statements.cpp
analyzeVariableDeclaration
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::analyzeVariableDeclaration(sun::ast::VariableCreationAST &varCreate)Analyzes a variable declaration that is not tracked as a pending global: resolves its type, checks its initializer and declares it in the current scope.
Related: sun::ast::VariableCreationAST
applyFunctionInfoToProto
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::applyFunctionInfoToProto(sun::ast::PrototypeAST &proto, const FunctionInfo &info)Apply FunctionInfo to a prototype (sets captures, param types, return type).
Related: sun::ast::PrototypeAST, FunctionInfo
checkAnnotationLifetimes
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::checkAnnotationLifetimes(const sun::ast::TypeAnnotation &annot, const sun::support::Position &location)Reject any lifetime name the annotation uses (recursively, through element, parameter, return and argument positions) that is neither an active declared name nor the builtin 'this where 'this is legal.
Related: sun::ast::TypeAnnotation, sun::support::Position
checkSignatureLifetimes
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::checkSignatureLifetimes(const sun::ast::PrototypeAST &proto, const sun::support::Position &location)Validate a signature's lifetime declarations (no duplicates, no collision with the enclosing class's names) and every lifetime name its parameter and return annotations use.
Related: sun::ast::PrototypeAST, sun::support::Position
ensureGlobalAnalyzed
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::ensureGlobalAnalyzed(const std::string &name)Globals may be used before the line that declares them.
If name refers to a global that has not been analyzed yet, analyzes its declaration now, in the scope it was declared in, so the lookup that follows finds it.
ensureModuleGlobalAnalyzed
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::ensureModuleGlobalAnalyzed(const std::string &modulePath, const std::string &name)The same, for a global named through its module: module.name.
getFunctionInfo
public · function · Source (opens in a new tab)
FunctionInfo sun::semantic_analysis::DeclarationAnalyzer::getFunctionInfo(sun::ast::FunctionAST &func, bool allowInterfaceReturn=false)Extract function signature info (param types, captures, explicit return type).
Sets captures on the prototype and handles auto-ref conversion for params. Does NOT register the function — caller is responsible for that. Returns FunctionInfo with returnType set if explicit, nullptr if needs inference. Only bodyless interface requirements may allow an interface return contract; executable functions must return concrete values or views.
Related: FunctionInfo, sun::ast::FunctionAST
getLambdaInfo
public · function · Source (opens in a new tab)
FunctionInfo sun::semantic_analysis::DeclarationAnalyzer::getLambdaInfo(sun::ast::LambdaAST &lambda)The same for a lambda: parameter types, captures, and return type.
Related: FunctionInfo, sun::ast::LambdaAST
isTrackedGlobal
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::DeclarationAnalyzer::isTrackedGlobal(const sun::ast::VariableCreationAST &varCreate)Reports whether the declaration table tracks this node as a global of the current scope.
A second declaration of a name is not tracked, and is reported as a duplicate when it is declared.
Related: sun::ast::VariableCreationAST
registerModuleVariable
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::registerModuleVariable(sun::ast::VariableCreationAST &varCreate)Registers an analyzed module variable under the module's qualified names, so module.name finds it.
Related: sun::ast::VariableCreationAST
tryAnalyzeDeclaration
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::DeclarationAnalyzer::tryAnalyzeDeclaration(sun::ast::ExprAST &expr)Checks declaration nodes and returns false for other syntax.
Related: sun::ast::ExprAST
validateTypeParameter
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::validateTypeParameter(const sun::types::TypePtr &type, const sun::ast::ExprAST &node)Validate that a type parameter exists when the type is a TypeParameterType.
Throws an error with source location if the type parameter is not found.
Related: sun::types::TypePtr, sun::ast::ExprAST
verifyGlobalVarIsNotRepeated
public · function · Source (opens in a new tab)
void sun::semantic_analysis::DeclarationAnalyzer::verifyGlobalVarIsNotRepeated(const sun::ast::VariableCreationAST &global) constReports a cycle when global is already being analyzed further up the stack, meaning its initializer leads back to itself.
The error lists each global along the cycle, for example A -> B -> A.
Related: sun::ast::VariableCreationAST
Private Functions
buildCaptures
private · function · Source (opens in a new tab)
std::vector< sun::ast::Capture > sun::semantic_analysis::DeclarationAnalyzer::buildCaptures(const sun::ast::LambdaAST &lambda)The variables a lambda captures, marking the ones its [ref x] list asks to capture by reference.
Related: sun::ast::Capture, sun::ast::LambdaAST
validateAndResolveParamTypes
private · function · Source (opens in a new tab)
std::vector< TypePtr > sun::semantic_analysis::DeclarationAnalyzer::validateAndResolveParamTypes(sun::ast::PrototypeAST &proto, std::optional< sun::support::Position > loc=std::nullopt, bool allowByValueObjects=false)Validate parameter names and resolve their types from prototype.
Throws if any parameter name is reserved; applies auto-ref conversion. Returns the resolved param types and sets them on the prototype.
allowByValueObjects exempts C externs from REQUIRE_REF_FOR_COMPOUND_PARAMS when that policy is enabled: passing a struct by value is what the C ABI specifies, so it is the callee's signature rather than a Sun choice.
Related: sun::types::TypePtr, sun::ast::PrototypeAST, sun::support::Position
Private Fields
ctx_
private · variable · Source (opens in a new tab)
SemanticContext& sun::semantic_analysis::DeclarationAnalyzer::ctx_No documentation comment.
Related: SemanticContext
globalsInProgress_
private · variable · Source (opens in a new tab)
std::vector<const sun::ast::VariableCreationAST *> sun::semantic_analysis::DeclarationAnalyzer::globalsInProgress_No documentation comment.
Related: sun::ast::VariableCreationAST
sema_
private · variable · Source (opens in a new tab)
SemanticAnalyzer& sun::semantic_analysis::DeclarationAnalyzer::sema_No documentation comment.
Related: SemanticAnalyzer