class
compiler::ResolveExpr
sys::Obj compiler::CompilerSupport compiler::CompilerStep compiler::ResolveExpr
Walk the AST to resolve:
- Manage local variable scope
- Resolve loop for breaks and continues
- Resolve LocalDefStmt.init into full assignment expression
- Resolve Expr.ctype
- Resolve UknownVarExpr -> LocalVarExpr, FieldExpr, or CallExpr
- Resolve CallExpr to their CMethod
Slots
-
private Void bindToMethodVar(LocalDefStmt def)
Bind the specified local variable definition to a MethodVar (and register number).
- blockStackSource
-
Block[] blockStack := Block[,]
-
private Block currentBlock()
Get the current block which defines our scope. We make a special case for "for" loops which can declare variables.
- curryCountSource
-
Int curryCount := 0
- enterBlockSource
-
override Void enterBlock(Block block)
Overrides compiler::Visitor.enterBlock
Doc inherited from compiler::Visitor.enterBlock
Callback when entering a block.
- enterMethodDefSource
-
override Void enterMethodDef(MethodDef m)
Overrides compiler::CompilerStep.enterMethodDef
- enterStmtSource
-
override Void enterStmt(Stmt stmt)
Overrides compiler::Visitor.enterStmt
Doc inherited from compiler::Visitor.enterStmt
Callback when entering a stmt.
- exitBlockSource
-
override Void exitBlock(Block block)
Overrides compiler::Visitor.exitBlock
Doc inherited from compiler::Visitor.exitBlock
Callback when exiting a block.
- exitSymbolDefSource
-
override Void exitSymbolDef(SymbolDef s)
Overrides compiler::Visitor.exitSymbolDef
Doc inherited from compiler::Visitor.exitSymbolDef
Callback when exiting a symbol definition.
-
private Stmt? findLoop()
- inClosureSource
-
Bool inClosure := false
-
private Void initMethodVars()
Setup the MethodVars for the parameters.
-
private Bool isBlockInScope(Block? block)
Check if the specified block is currently in scope. We make a specialcase for "for" loops which can declare variables.
-
private Str:MethodVar localsInScope()
Get a list of all the local method variables that are currently in scope.
- makeSource
-
new make(Compiler compiler)
-
private Expr resolveAssign(BinaryExpr expr)
Resolve an assignment operation
-
private Expr resolveCall(CallExpr call)
Resolve a call to it's Method and return type.
-
private Expr resolveCallOnLocalVar(CallExpr call, LocalVarExpr binding)
Resolve the () operator on a local variable - if the local is a Method, then () is syntactic sugar for Method.callx()
-
private Void resolveClosure(ClosureExpr expr)
ClosureExpr will just output its substitute expression. But we take this opportunity to capture the local variables in the closure's scope and cache them on the ClosureExpr. We also do variable name checking.
-
private Expr resolveConstruction(CallExpr call)
Resolve a construction call Type(args)
-
private Void resolveContinue(ContinueStmt stmt)
-
private Expr resolveCurry(CurryExpr expr)
CurryExpr
-
private Expr resolveDsl(DslExpr expr)
Resolve a DSL
-
private Expr resolveElvis(BinaryExpr expr)
Resolve "x ?: y" expression
-
private Expr resolveIndexedAssign(ShortcutExpr orig)
If we have an assignment against an indexed shortcut such as x[y] += z, then process specially to return a IndexedAssignExpr subclass of ShortcutExpr.
-
private Expr resolveIt(ItExpr expr)
Resolve it keyword expression
-
private Expr resolveList(ListLiteralExpr expr)
Resolve list literal
-
private MethodVar? resolveLocal(Str name, Location loc)
Resolve a local variable using current scope based on the block stack and possibly the scope of a closure.
-
private Void resolveLocalVarDef(LocalDefStmt def)
-
private Expr resolveMap(MapLiteralExpr expr)
Resolve map literal
-
private Expr resolveShortcut(ShortcutExpr expr)
Resolve ShortcutExpr.
-
private Expr resolveSlotLiteral(SlotLiteralExpr expr)
Resolve slot literal
-
private Expr resolveStorage(UnknownVarExpr var)
Resolve storage operator
-
private Expr resolveSuper(SuperExpr expr)
Resolve super keyword expression
-
private Expr resolveSymbol(SymbolExpr expr)
Resolve symbol literal
-
private Expr resolveTernary(TernaryExpr expr)
Resolve "x ? y : z" ternary expression
-
private Expr resolveThis(ThisExpr expr)
Resolve this keyword expression
-
private Expr resolveVar(UnknownVarExpr var)
Resolve an UnknownVar to its replacement node.
- runSource
-
override Void run()
Overrides compiler::CompilerStep.run
Doc inherited from compiler::CompilerStep.run
Run the step
- stmtStackSource
-
Stmt[] stmtStack := Stmt[,]
- visitExprSource
-
override Expr visitExpr(Expr expr)
Overrides compiler::Visitor.visitExpr
Doc inherited from compiler::Visitor.visitExpr
Call to visit an expression. Return expr or a new expression if doing a replacement for the expression in the abstract syntax tree.
- visitStmtSource
-
override Stmt[]? visitStmt(Stmt stmt)
Overrides compiler::Visitor.visitStmt
Doc inherited from compiler::Visitor.visitStmt
Callback when visiting a stmt. Return a list to replace the statement with new statements, or return null to keep existing statement.