()
| 36 | } |
| 37 | |
| 38 | func (c *declChecker) check() []error { |
| 39 | p := c.decl.DeclaredAtom |
| 40 | var seenDocAtom bool |
| 41 | expectedArgs := make(map[ast.Variable]struct{}, len(p.Args)) |
| 42 | for _, arg := range p.Args { |
| 43 | v, ok := arg.(ast.Variable) |
| 44 | if !ok { |
| 45 | c.errs = append(c.errs, fmt.Errorf("Decl requires an atom with variables got %v", arg)) |
| 46 | continue |
| 47 | } |
| 48 | expectedArgs[v] = struct{}{} |
| 49 | } |
| 50 | if c.errs != nil { |
| 51 | return c.errs |
| 52 | } |
| 53 | for _, descrAtom := range c.decl.Descr { |
| 54 | sym := descrAtom.Predicate.Symbol |
| 55 | switch sym { |
| 56 | case ast.DescrDoc: |
| 57 | if seenDocAtom { |
| 58 | c.errs = append(c.errs, fmt.Errorf("descr[] can only have one doc atom")) |
| 59 | } |
| 60 | seenDocAtom = true |
| 61 | if len(descrAtom.Args) == 0 { |
| 62 | c.errs = append(c.errs, fmt.Errorf("descr atom must not be empty")) |
| 63 | continue |
| 64 | } |
| 65 | for _, docArg := range descrAtom.Args { |
| 66 | c.checkStringConstant(docArg) |
| 67 | } |
| 68 | case ast.DescrArg: |
| 69 | if len(descrAtom.Args) < 2 { |
| 70 | c.errs = append(c.errs, fmt.Errorf("arg atom must have at least 2 args")) |
| 71 | continue |
| 72 | } |
| 73 | firstArg := descrAtom.Args[0] |
| 74 | v, ok := firstArg.(ast.Variable) |
| 75 | if !ok { |
| 76 | c.errs = append(c.errs, fmt.Errorf("arg atom must have variable as arg, got%v", firstArg)) |
| 77 | continue |
| 78 | } |
| 79 | if _, ok := expectedArgs[v]; !ok { |
| 80 | c.errs = append(c.errs, fmt.Errorf("arg atom for an unknown variable %v", v)) |
| 81 | continue |
| 82 | } |
| 83 | delete(expectedArgs, v) |
| 84 | for _, argArg := range descrAtom.Args[1:] { |
| 85 | c.checkStringConstant(argArg) |
| 86 | } |
| 87 | default: |
| 88 | // We ignore unknown descr atoms. |
| 89 | } |
| 90 | } |
| 91 | if c.decl.IsExternal() && len(c.decl.Modes()) != 1 { |
| 92 | c.errs = append(c.errs, fmt.Errorf("external predicate must have exactly one mode")) |
| 93 | } |
| 94 | if !c.decl.IsSynthetic() && len(expectedArgs) > 0 && len(expectedArgs) != len(p.Args) { |
| 95 | c.errs = append(c.errs, fmt.Errorf("missing arg atoms for arguments %v", expectedArgs)) |
no test coverage detected