From 116e98b37891091841976d1c70ec1fb39c439d8a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 27 Jul 2021 10:59:39 +0100 Subject: Improve default scope size --- src/parser.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index fcc8078f7..f1f348ff4 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5261,6 +5261,28 @@ String dir_from_path(String path) { return base_dir; } +isize calc_decl_count(Ast *decl) { + isize count = 0; + switch (decl->kind) { + case Ast_BlockStmt: + for_array(i, decl->BlockStmt.stmts) { + count += calc_decl_count(decl->BlockStmt.stmts.data[i]); + } + break; + case Ast_ValueDecl: + count = decl->ValueDecl.names.count; + break; + case Ast_ForeignBlockDecl: + count = calc_decl_count(decl->ForeignBlockDecl.body); + break; + case Ast_ImportDecl: + case Ast_ForeignImportDecl: + count = 1; + break; + } + return count; +} + bool parse_file(Parser *p, AstFile *f) { if (f->tokens.count == 0) { return true; @@ -5346,6 +5368,8 @@ bool parse_file(Parser *p, AstFile *f) { stmt->ExprStmt.expr->kind == Ast_ProcLit) { syntax_error(stmt, "Procedure literal evaluated but not used"); } + + f->total_file_decl_count += calc_decl_count(stmt); } } -- cgit v1.2.3