checker: split fn_decl into functions to cleanup (#9226)

pull/9176/head^2
zakuro 2021-03-11 03:18:48 +09:00 committed by GitHub
parent 791dec7b01
commit ef73e07e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 48 deletions

View File

@ -285,7 +285,13 @@ fn (mut c Checker) check_valid_pascal_case(name string, identifier string, pos t
pub fn (mut c Checker) type_decl(node ast.TypeDecl) { pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
match node { match node {
ast.AliasTypeDecl { ast.AliasTypeDecl { c.alias_type_decl(node) }
ast.FnTypeDecl { c.fn_type_decl(node) }
ast.SumTypeDecl { c.sum_type_decl(node) }
}
}
pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
// TODO Replace `c.file.mod.name != 'time'` by `it.language != .v` once available // TODO Replace `c.file.mod.name != 'time'` by `it.language != .v` once available
if c.file.mod.name != 'time' && c.file.mod.name != 'builtin' { if c.file.mod.name != 'time' && c.file.mod.name != 'builtin' {
c.check_valid_pascal_case(node.name, 'type alias', node.pos) c.check_valid_pascal_case(node.name, 'type alias', node.pos)
@ -300,8 +306,9 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
} else if typ_sym.kind == .chan { } else if typ_sym.kind == .chan {
c.error('aliases of `chan` types are not allowed.', node.pos) c.error('aliases of `chan` types are not allowed.', node.pos)
} }
} }
ast.FnTypeDecl {
pub fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) {
c.check_valid_pascal_case(node.name, 'fn type', node.pos) c.check_valid_pascal_case(node.name, 'fn type', node.pos)
typ_sym := c.table.get_type_symbol(node.typ) typ_sym := c.table.get_type_symbol(node.typ)
fn_typ_info := typ_sym.info as table.FnType fn_typ_info := typ_sym.info as table.FnType
@ -316,8 +323,9 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
c.error("type `$arg_sym.name` doesn't exist", node.pos) c.error("type `$arg_sym.name` doesn't exist", node.pos)
} }
} }
} }
ast.SumTypeDecl {
pub fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
c.check_valid_pascal_case(node.name, 'sum type', node.pos) c.check_valid_pascal_case(node.name, 'sum type', node.pos)
mut names_used := []string{} mut names_used := []string{}
for variant in node.variants { for variant in node.variants {
@ -335,8 +343,6 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
} }
names_used << sym.name names_used << sym.name
} }
}
}
} }
pub fn (mut c Checker) interface_decl(decl ast.InterfaceDecl) { pub fn (mut c Checker) interface_decl(decl ast.InterfaceDecl) {