import ASTNode from "../ast/ASTNode"; import { AnonymousFunctionExpr, FunctionCallExpr, LcForCExpr, LcForExpr, LcLetExpr, LetExpr, LookupExpr } from "../ast/expressions"; import ScadFile from "../ast/ScadFile"; import { BlockStmt, FunctionDeclarationStmt, ModuleDeclarationStmt, ModuleInstantiationStmt } from "../ast/statements"; import ASTMutator from "../ASTMutator"; import ErrorCollector from "../ErrorCollector"; import Scope from "./Scope"; export default class SymbolResolver extends ASTMutator { private errorCollector; /** * Represents the scope where the resolver has descended. * It initially is null, but the resolver should encounter a NodeWithScope * and set this to the scope of that node. */ currentScope: Scope | null; isInCallee: boolean; constructor(errorCollector: ErrorCollector, /** * Represents the scope where the resolver has descended. * It initially is null, but the resolver should encounter a NodeWithScope * and set this to the scope of that node. */ currentScope?: Scope | null, isInCallee?: boolean); visitLookupExpr(n: LookupExpr): ASTNode; visitModuleInstantiationStmt(n: ModuleInstantiationStmt): ASTNode; /** * visitFunctionCallExpr switches the SymbolResolver into a special mode where * it falls back to resolving named functions when processing lookup expressions. * This behaviour tries to mimic the behaviour of OpenSCAD's function call resolution, * it is not perfect, since you can abuse this to do things like assign a named function * to a variable which is not allowed in OpenSCAD. So this covers all but the most * pathological cases. * @param n * @returns */ visitFunctionCallExpr(n: FunctionCallExpr): ASTNode; private copyWithNextScope; private copyWithIsInCallee; visitBlockStmt(n: BlockStmt): ASTNode; visitLetExpr(n: LetExpr): ASTNode; visitScadFile(n: ScadFile): ASTNode; visitFunctionDeclarationStmt(n: FunctionDeclarationStmt): ASTNode; visitModuleDeclarationStmt(n: ModuleDeclarationStmt): ASTNode; visitLcLetExpr(n: LcLetExpr): ASTNode; visitLcForExpr(n: LcForExpr): ASTNode; visitLcForCExpr(n: LcForCExpr): ASTNode; visitAnonymousFunctionExpr(n: AnonymousFunctionExpr): ASTNode; }