Lines Matching refs:comp
16 func (comp *compiler) typecheck() {
17 comp.checkDirectives()
18 comp.checkNames()
19 comp.checkFields()
20 comp.checkTypedefs()
21 comp.checkTypes()
24 func (comp *compiler) check() {
25 comp.checkTypeValues()
26 comp.checkAttributeValues()
27 comp.checkUnused()
28 comp.checkRecursion()
29 comp.checkLenTargets()
30 comp.checkConstructors()
31 comp.checkVarlens()
32 comp.checkDupConsts()
35 func (comp *compiler) checkDirectives() {
39 for _, decl := range comp.desc.Nodes {
45 comp.error(n.Pos, "duplicate include %q", name)
52 comp.error(n.Pos, "duplicate incdir %q", name)
59 comp.error(n.Pos, "duplicate define %v", name)
66 func (comp *compiler) checkNames() {
68 for _, decl := range comp.desc.Nodes {
73 comp.error(pos, "%v uses reserved name %v", typ, name)
77 comp.error(pos, "%v name %v conflicts with builtin type", typ, name)
80 if prev := comp.resources[name]; prev != nil {
81 comp.error(pos, "type %v redeclared, previously declared as resource at %v",
85 if prev := comp.typedefs[name]; prev != nil {
86 comp.error(pos, "type %v redeclared, previously declared as type alias at %v",
90 if prev := comp.structs[name]; prev != nil {
92 comp.error(pos, "type %v redeclared, previously declared as %v at %v",
98 comp.resources[name] = n
100 comp.typedefs[name] = n
102 comp.structs[name] = n
110 comp.error(n.Pos, "flags uses reserved name %v", name)
113 if prev := comp.intFlags[name]; prev != nil {
114 comp.error(n.Pos, "flags %v redeclared, previously declared at %v",
118 comp.intFlags[name] = n
122 comp.error(n.Pos, "string flags uses reserved name %v", name)
126 comp.error(n.Pos, "string flags %v conflicts with builtin flags", name)
129 if prev := comp.strFlags[name]; prev != nil {
130 comp.error(n.Pos, "string flags %v redeclared, previously declared at %v",
134 comp.strFlags[name] = n
138 comp.error(n.Pos, "syscall %v redeclared, previously declared at %v",
146 func (comp *compiler) checkFields() {
148 for _, decl := range comp.desc.Nodes {
152 comp.checkStructFields(n, typ, name)
156 comp.checkStructFields(n.Struct, "template "+typ, n.Name.Name)
160 comp.checkFieldGroup(n.Args, "argument", "syscall "+name)
162 comp.error(n.Pos, "syscall %v has %v arguments, allowed maximum is %v",
169 func (comp *compiler) checkStructFields(n *ast.Struct, typ, name string) {
170 comp.checkFieldGroup(n.Fields, "field", typ+" "+name)
172 comp.error(n.Pos, "%v %v has no fields, need at least 1 field", typ, name)
176 func (comp *compiler) checkFieldGroup(fields []*ast.Field, what, ctx string) {
181 comp.error(f.Pos, "reserved %v name %v in %v", what, fn, ctx)
184 comp.error(f.Pos, "duplicate %v %v in %v", what, fn, ctx)
190 func (comp *compiler) checkTypedefs() {
191 for _, decl := range comp.desc.Nodes {
196 err0 := comp.errors
197 comp.checkType(checkCtx{}, n.Type, checkIsTypedef)
198 if err0 != comp.errors {
200 delete(comp.typedefs, n.Name.Name)
207 comp.error(arg.Pos, "duplicate type argument %v", arg.Name)
216 comp.error(arg.Pos, "type argument %v must be ALL_CAPS",
226 func (comp *compiler) checkTypes() {
227 for _, decl := range comp.desc.Nodes {
230 comp.checkType(checkCtx{}, n.Base, checkIsResourceBase)
232 comp.checkStruct(checkCtx{}, n)
235 comp.checkType(checkCtx{}, a.Type, checkIsArg)
238 comp.checkType(checkCtx{}, n.Ret, checkIsArg|checkIsRet)
244 func (comp *compiler) checkTypeValues() {
245 for _, decl := range comp.desc.Nodes {
248 comp.foreachType(decl, func(t *ast.Type, desc *typeDesc,
251 desc.CheckConsts(comp, t, args, base)
255 check(comp, arg)
263 func (comp *compiler) checkAttributeValues() {
264 for _, decl := range comp.desc.Nodes {
270 if comp.structIsVarlen(n.Name.Name) {
271 comp.error(attr.Pos, "varlen %v %v has size attribute",
276 comp.error(attr.Args[0].Pos, "size attribute has bad value %v"+
285 func (comp *compiler) checkLenTargets() {
286 for _, decl := range comp.desc.Nodes {
290 comp.checkLenType(arg.Type, arg.Name.Name, n.Args, nil, make(map[string]bool), true)
296 func (comp *compiler) checkLenType(t *ast.Type, name string, fields []*ast.Field,
298 desc := comp.getTypeDesc(t)
300 s := comp.structs[t.Ident]
311 comp.checkLenType(fld.Type, fld.Name.Name, fields, parents, checked, false)
315 _, args, _ := comp.getArgsBase(t, "", prog.DirIn, isArg)
319 comp.checkLenTarget(t, name, arg.Ident, fields, parents)
321 comp.checkLenType(arg, name, fields, parents, checked, argDesc.IsArg)
326 func (comp *compiler) checkLenTarget(t *ast.Type, name, target string, fields []*ast.Field, parents…
328 comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target)
333 comp.error(t.Pos, "%v target %v does not exist", t.Ident, target)
342 comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target)
346 desc, args, _ := comp.getArgsBase(inner, "", prog.DirIn, false)
352 desc, args, _ = comp.getArgsBase(inner, "", prog.DirIn, false)
354 if desc == typeArray && comp.isVarlen(args[0]) {
355 comp.warning(t.Pos, "len target %v refer to an array with"+
371 comp.error(t.Pos, "%v target %v does not exist", t.Ident, target)
374 func (comp *compiler) collectUsed(all bool) (structs, flags, strflags map[string]bool) {
378 for _, decl := range comp.desc.Nodes {
385 comp.collectUsedType(structs, flags, strflags, arg.Type, true)
388 comp.collectUsedType(structs, flags, strflags, n.Ret, true)
395 func (comp *compiler) collectUsedType(structs, flags, strflags map[string]bool, t *ast.Type, isArg …
396 desc := comp.getTypeDesc(t)
398 r := comp.resources[t.Ident]
401 r = comp.resources[r.Base.Ident]
410 s := comp.structs[t.Ident]
412 comp.collectUsedType(structs, flags, strflags, fld.Type, false)
426 _, args, _ := comp.getArgsBase(t, "", prog.DirIn, isArg)
429 comp.collectUsedType(structs, flags, strflags, arg, desc.Args[i].IsArg)
434 func (comp *compiler) checkUnused() {
435 comp.used, _, _ = comp.collectUsed(false)
436 structs, flags, strflags := comp.collectUsed(true)
439 for name, n := range comp.intFlags {
441 comp.error(n.Pos, "unused flags %v", name)
444 for name, n := range comp.strFlags {
446 comp.error(n.Pos, "unused string flags %v", name)
449 for name, n := range comp.resources {
451 comp.error(n.Pos, "unused resource %v", name)
454 for name, n := range comp.structs {
457 comp.error(n.Pos, "unused %v %v", typ, name)
460 for name, n := range comp.typedefs {
461 if !comp.usedTypedefs[name] {
462 comp.error(n.Pos, "unused type %v", name)
472 func (comp *compiler) checkConstructors() {
475 for _, decl := range comp.desc.Nodes {
479 comp.checkTypeCtors(arg.Type, prog.DirIn, true, ctors, checked)
482 comp.checkTypeCtors(n.Ret, prog.DirOut, true, ctors, checked)
486 for _, decl := range comp.desc.Nodes {
490 if !ctors[name] && comp.used[name] {
491 comp.error(n.Pos, "resource %v can't be created"+
499 func (comp *compiler) checkTypeCtors(t *ast.Type, dir prog.Dir, isArg bool,
501 desc := comp.getTypeDesc(t)
509 r := comp.resources[t.Ident]
512 r = comp.resources[r.Base.Ident]
518 s := comp.structs[t.Ident]
526 comp.checkTypeCtors(fld.Type, dir, false, ctors, checked)
533 _, args, _ := comp.getArgsBase(t, "", dir, isArg)
536 comp.checkTypeCtors(arg, dir, desc.Args[i].IsArg, ctors, checked)
541 func (comp *compiler) checkRecursion() {
543 for _, decl := range comp.desc.Nodes {
546 comp.checkResourceRecursion(n)
549 comp.checkStructRecursion(checked, n, path)
554 func (comp *compiler) checkResourceRecursion(n *ast.Resource) {
563 comp.error(n.Pos, "recursive resource %v", chain)
567 n = comp.resources[n.Base.Ident]
577 func (comp *compiler) checkStructRecursion(checked map[string]bool, n *ast.Struct, path []pathElem)…
592 comp.error(path[0].Pos, "recursive declaration: %v (mark some pointers as opt)", str)
602 comp.recurseField(checked, f.Type, path)
608 func (comp *compiler) recurseField(checked map[string]bool, t *ast.Type, path []pathElem) {
609 desc := comp.getTypeDesc(t)
611 comp.checkStructRecursion(checked, comp.structs[t.Ident], path)
614 _, args, base := comp.getArgsBase(t, "", prog.DirIn, false)
620 comp.recurseField(checked, arg, path)
625 func (comp *compiler) checkStruct(ctx checkCtx, n *ast.Struct) {
631 comp.checkType(ctx, f.Type, flags)
635 comp.error(attr.Pos, "unexpected %v, expect attribute", unexpected)
639 comp.error(attr.Pos2, "unexpected ':'")
644 comp.parseUnionAttrs(n)
646 comp.parseStructAttrs(n)
664 func (comp *compiler) checkType(ctx checkCtx, t *ast.Type, flags checkFlags) {
666 comp.error(t.Pos, "unexpected %v, expect type", unexpected)
669 desc := comp.getTypeDesc(t)
671 comp.error(t.Pos, "unknown type %v", t.Ident)
675 err0 := comp.errors
678 comp.replaceTypedef(&ctx, t, flags)
679 if err0 == comp.errors {
680 comp.checkType(ctx, t, flags)
684 err0 := comp.errors
685 comp.checkTypeBasic(t, desc, flags)
686 if err0 != comp.errors {
689 args := comp.checkTypeArgs(t, desc, flags)
690 if err0 != comp.errors {
699 comp.checkType(ctx, arg, innerFlags)
701 comp.checkTypeArg(t, arg, desc.Args[i])
704 if err0 != comp.errors {
708 _, args, base := comp.getArgsBase(t, "", prog.DirIn, flags&checkIsArg != 0)
709 desc.Check(comp, t, args, base)
713 func (comp *compiler) checkTypeBasic(t *ast.Type, desc *typeDesc, flags checkFlags) {
716 comp.error(t.Pos2, "unexpected ':'")
720 comp.error(t.Pos2, "unexpected ':', only struct fields can be bitfields")
725 comp.error(t.Pos, "%v can't be type alias target", t.Ident)
729 comp.error(t.Pos, "%v can't be resource base (int types can)", t.Ident)
734 canBeArg, canBeRet = desc.CanBeArgRet(comp, t)
737 comp.error(t.Pos, "%v can't be syscall return", t.Ident)
741 comp.error(t.Pos, "%v can't be syscall argument", t.Ident)
746 func (comp *compiler) checkTypeArgs(t *ast.Type, desc *typeDesc, flags checkFlags) []*ast.Type {
750 comp.error(opt.Pos, "opt can't have arguments")
757 comp.error(opt.Pos, "%v can't be marked as opt", what)
767 comp.error(t.Pos, "wrong number of arguments for type %v, expect %v",
774 comp.checkTypeArg(t, base, typeArgBase)
779 func (comp *compiler) replaceTypedef(ctx *checkCtx, t *ast.Type, flags checkFlags) {
781 comp.usedTypedefs[typedefName] = true
783 comp.error(t.Pos, "type alias %v with ':'", t.Ident)
786 typedef := comp.typedefs[typedefName]
798 comp.error(t.Pos, "type instantiation loop: %v", path)
807 comp.error(t.Pos, "type %v is not a template", typedefName)
809 comp.error(t.Pos, "template %v needs %v arguments instead of %v",
817 if !comp.instantiate(t, typedef.Args, args) {
821 if comp.structs[fullTypeName] == nil {
824 if !comp.instantiate(inst, typedef.Args, args) {
827 comp.checkStruct(*ctx, inst)
828 comp.desc.Nodes = append(comp.desc.Nodes, inst)
829 comp.structs[fullTypeName] = inst
838 desc := comp.getTypeDesc(t)
849 func (comp *compiler) instantiate(templ ast.Node, params []*ast.Ident, args []*ast.Type) bool {
857 err0 := comp.errors
866 comp.error(templArg.Pos, "both template parameter %v and its usage"+
884 return err0 == comp.errors
887 func (comp *compiler) checkTypeArg(t, arg *ast.Type, argDesc namedArg) {
891 comp.error(arg.Pos, "unexpected %v for %v argument of %v type, expect %+v",
896 comp.error(arg.Pos, "unexpected value %v for %v argument of %v type, expect %+v",
902 comp.error(arg.Pos, "unexpected %v for %v argument of %v type, expect %v",
908 comp.error(arg.Pos2, "unexpected ':'")
912 comp.error(arg.Pos, "%v argument has subargs", argDesc.Name)
916 desc.Check(comp, arg)
986 func (comp *compiler) checkVarlens() {
987 for _, decl := range comp.desc.Nodes {
990 comp.checkVarlen(n)
995 func (comp *compiler) isVarlen(t *ast.Type) bool {
996 desc, args, _ := comp.getArgsBase(t, "", prog.DirIn, false)
997 return desc.Varlen != nil && desc.Varlen(comp, t, args)
1000 func (comp *compiler) isZeroSize(t *ast.Type) bool {
1001 desc, args, _ := comp.getArgsBase(t, "", prog.DirIn, false)
1002 return desc.ZeroSize != nil && desc.ZeroSize(comp, t, args)
1005 func (comp *compiler) checkVarlen(n *ast.Struct) {
1009 if varlen, _ := comp.parseUnionAttrs(n); varlen {
1013 if packed, _, _ := comp.parseStructAttrs(n); packed {
1021 if comp.isVarlen(f.Type) {
1023 comp.error(f.Pos, "variable size field %v in non-varlen union %v",
1026 comp.error(f.Pos, "variable size field %v in the middle of non-packed struct %v",
1033 func (comp *compiler) checkDupConsts() {
1044 for _, decl := range comp.desc.Nodes {
1047 comp.checkDupConstsCall(n, dups)
1057 func (comp *compiler) checkDupConstsCall(n *ast.Call, dups map[string]map[string]dupConstArg) {
1067 desc := comp.getTypeDesc(arg.Type)
1089 comp.error(n.Pos, "call %v: duplicate const %v, previously used in call %v at %v",