From af15ef43a838e4be0537da7e9dd03ad3eb71b544 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 1 Aug 2018 16:30:17 +0200 Subject: pkg/compiler: refactor checkNames Too complex. Split into 2 functions. Update #538 --- pkg/compiler/check.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index a0d0f7fed..195ca1245 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -14,6 +14,7 @@ import ( ) func (comp *compiler) typecheck() { + comp.checkDirectives() comp.checkNames() comp.checkFields() comp.checkTypedefs() @@ -31,11 +32,10 @@ func (comp *compiler) check() { comp.checkDupConsts() } -func (comp *compiler) checkNames() { +func (comp *compiler) checkDirectives() { includes := make(map[string]bool) incdirs := make(map[string]bool) defines := make(map[string]bool) - calls := make(map[string]*ast.Call) for _, decl := range comp.desc.Nodes { switch n := decl.(type) { case *ast.Include: @@ -59,6 +59,14 @@ func (comp *compiler) checkNames() { comp.error(n.Pos, "duplicate define %v", name) } defines[path] = true + } + } +} + +func (comp *compiler) checkNames() { + calls := make(map[string]*ast.Call) + for _, decl := range comp.desc.Nodes { + switch n := decl.(type) { case *ast.Resource, *ast.Struct, *ast.TypeDef: pos, typ, name := decl.Info() if reservedName[name] { -- cgit mrf-deployment