1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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

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)
@ -301,7 +307,8 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
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
@ -317,7 +324,8 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
} }
} }
} }
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 {
@ -336,8 +344,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) {
c.check_valid_pascal_case(decl.name, 'interface name', decl.pos) c.check_valid_pascal_case(decl.name, 'interface name', decl.pos)