@@ -4,9 +4,7 @@ void ScopeScanner::visit(const SharedPtr<ModuleNode> &module) {
44 SharedPtr<TopLevelScope> topLevelScope = TopLevelScope::create ();
55 module ->internalScope = topLevelScope;
66 pushScope (topLevelScope);
7- for (const SharedPtr<StmtNode> &stmt: module ->childStmts ) {
8- stmt->accept (getThisSharedPtr ());
9- }
7+ ASTVisitor::visit (module );
108 popScope ();
119}
1210
@@ -29,10 +27,7 @@ void ScopeScanner::visit(const SharedPtr<FunctionDeclNode> &funcDecl) {
2927 SharedPtr<LocalScope> paramScope = LocalScope::create (topLevelScope);
3028 funcDecl->internalScope = paramScope;
3129 pushScope (paramScope);
32- for (const SharedPtr<ParmVarDeclNode> ¶mVarDecl : funcDecl->params ) {
33- paramVarDecl->accept (getThisSharedPtr ());
34- }
35- funcDecl->body ->accept (getThisSharedPtr ());
30+ ASTVisitor::visit (funcDecl);
3631 popScope ();
3732}
3833
@@ -54,84 +49,59 @@ void ScopeScanner::visit(const SharedPtr<IdentifierExprNode> &varExpr) {
5449
5550void ScopeScanner::visit (const SharedPtr<CallExprNode> &callExpr) {
5651 callExpr->scope = getCurrentScope ();
57- for (const SharedPtr<ExprNode> &argExpr: callExpr->args ) {
58- argExpr->accept (getThisSharedPtr ());
59- }
52+ ASTVisitor::visit (callExpr);
6053}
6154
6255void ScopeScanner::visit (const SharedPtr<UnaryOperatorExprNode> &uopExpr) {
6356 uopExpr->scope = getCurrentScope ();
64- uopExpr-> subExpr -> accept ( getThisSharedPtr () );
57+ ASTVisitor::visit (uopExpr );
6558}
6659
6760void ScopeScanner::visit (const SharedPtr<BinaryOperatorExprNode> &bopExpr) {
6861 bopExpr->scope = getCurrentScope ();
69- bopExpr->lhs ->accept (getThisSharedPtr ());
70- bopExpr->rhs ->accept (getThisSharedPtr ());
62+ ASTVisitor::visit (bopExpr);
7163}
7264
7365void ScopeScanner::visit (const SharedPtr<ExprStmtNode> &exprStmt) {
7466 exprStmt->scope = getCurrentScope ();
75- exprStmt-> expr -> accept ( getThisSharedPtr () );
67+ ASTVisitor::visit (exprStmt );
7668}
7769
7870void ScopeScanner::visit (const SharedPtr<CompoundStmtNode> &compStmt) {
7971 compStmt->scope = getCurrentScope ();
8072 SharedPtr<LocalScope> localScope = LocalScope::create (getCurrentScope ());
8173 compStmt->internalScope = localScope;
8274 pushScope (localScope);
83- for (const SharedPtr<StmtNode> &stmt: compStmt->childStmts ) {
84- stmt->accept (getThisSharedPtr ());
85- }
75+ ASTVisitor::visit (compStmt);
8676 popScope ();
8777}
8878
8979void ScopeScanner::visit (const SharedPtr<VarDeclStmtNode> &varDeclStmt) {
9080 varDeclStmt->scope = getCurrentScope ();
91- for (const SharedPtr<VarDeclNode> &varDecl : varDeclStmt->childVarDecls ) {
92- varDecl->accept (getThisSharedPtr ());
93- }
81+ ASTVisitor::visit (varDeclStmt);
9482}
9583
9684void ScopeScanner::visit (const SharedPtr<FunctionDeclStmtNode> &funcDeclStmt) {
9785 funcDeclStmt->scope = getCurrentScope ();
98- funcDeclStmt-> childFunctionDecl -> accept ( getThisSharedPtr () );
86+ ASTVisitor::visit (funcDeclStmt );
9987}
10088
10189void ScopeScanner::visit (const SharedPtr<IfStmtNode> &ifStmt) {
10290 ifStmt->scope = getCurrentScope ();
103- ifStmt->condition ->accept (getThisSharedPtr ());
104- ifStmt->thenBody ->accept (getThisSharedPtr ());
105- if (ifStmt->elseBody ) {
106- ifStmt->elseBody ->accept (getThisSharedPtr ());
107- }
91+ ASTVisitor::visit (ifStmt);
10892}
10993
11094void ScopeScanner::visit (const SharedPtr<WhileStmtNode> &whileStmt) {
11195 whileStmt->scope = getCurrentScope ();
112- whileStmt->condition ->accept (getThisSharedPtr ());
113- whileStmt->body ->accept (getThisSharedPtr ());
96+ ASTVisitor::visit (whileStmt);
11497}
11598
11699void ScopeScanner::visit (const SharedPtr<ForStmtNode> &forStmt) {
117100 forStmt->scope = getCurrentScope ();
118101 SharedPtr<LocalScope> forScope = LocalScope::create (getCurrentScope ());
119102 forStmt->internalScope = forScope;
120103 pushScope (forScope);
121- if (forStmt->forInitVarDecls ) {
122- forStmt->forInitVarDecls ->accept (getThisSharedPtr ());
123- } else {
124- for (const SharedPtr<ExprNode> &initExpr: forStmt->forInitExprList ) {
125- initExpr->accept (getThisSharedPtr ());
126- }
127- }
128- if (forStmt->forCondition ) {
129- forStmt->forCondition ->accept (getThisSharedPtr ());
130- }
131- for (const SharedPtr<ExprNode> &updateExpr: forStmt->forUpdate ) {
132- updateExpr->accept (getThisSharedPtr ());
133- }
134- forStmt->body ->accept (getThisSharedPtr ());
104+ ASTVisitor::visit (forStmt);
135105 popScope ();
136106}
137107
@@ -145,7 +115,5 @@ void ScopeScanner::visit(const SharedPtr<BreakStmtNode> &breakStmt) {
145115
146116void ScopeScanner::visit (const SharedPtr<ReturnStmtNode> &returnStmt) {
147117 returnStmt->scope = getCurrentScope ();
148- if (returnStmt->returnExpr ) {
149- returnStmt->returnExpr ->accept (getThisSharedPtr ());
150- }
118+ ASTVisitor::visit (returnStmt);
151119}
0 commit comments