How to use parseIntType method of compiler Package

Best Syzkaller code snippet using compiler.parseIntType

types.go

Source:types.go Github

copy

Full Screen

...69 // Big-endian resources can always be converted to non-big-endian,70 // since we will always revert bytes during copyout and during copyin,71 // so the result is the same as not reverting at all.72 // Big-endian resources are also not implemented and don't have tests.73 _, be := comp.parseIntType(t.Ident)74 return !be75 },76 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {77 typeArgBase.Type.Check(comp, t)78 if len(args) > 0 && len(args[0].Colon) == 0 {79 comp.error(args[0].Pos, "first argument of %v needs to be a range", t.Ident)80 }81 },82 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {83 if len(args) > 0 && len(args[0].Colon) != 0 {84 begin := args[0].Value85 end := args[0].Colon[0].Value86 size, _ := comp.parseIntType(t.Ident)87 size = size * 888 if len(t.Colon) != 0 {89 // Integer is bitfield.90 size = t.Colon[0].Value91 }92 maxUInt := uint64(1<<size - 1)93 maxSInt := uint64(1<<(size-1) - 1)94 if len(args) > 1 && begin == 0 && int64(end) == -1 {95 // intN[0:-1, align] is a special value for 'all possible values', but aligned.96 end = maxUInt97 } else if end-begin > 1<<64-1<<32 {98 comp.error(args[0].Pos, "bad int range [%v:%v]", begin, end)99 return100 }101 // range is in [0:MAX_UINT]102 inUnsignedBase := begin <= maxUInt && end <= maxUInt103 // range is in [-MIN_SINT:MAX_SINT]104 inSignedBase := begin+maxSInt <= maxUInt && end+maxSInt <= maxUInt105 if size < 64 && !inUnsignedBase && !inSignedBase {106 comp.error(args[0].Colon[0].Pos, "int range [%v:%v] is too large for base type of size %v",107 begin, end, size)108 return109 }110 if len(args) > 1 && args[1].Value != 0 && (end-begin)/args[1].Value == 0 {111 comp.error(args[1].Pos, "int alignment %v is too large for range [%v:%v]",112 args[1].Value, begin, end)113 }114 }115 },116 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {117 size, be := comp.parseIntType(t.Ident)118 kind, rangeBegin, rangeEnd, align := prog.IntPlain, uint64(0), uint64(0), uint64(0)119 if len(args) > 0 {120 rangeArg := args[0]121 kind, rangeBegin, rangeEnd = prog.IntRange, rangeArg.Value, rangeArg.Value122 if len(rangeArg.Colon) != 0 {123 rangeEnd = rangeArg.Colon[0].Value124 }125 if len(args) > 1 {126 align = args[1].Value127 }128 }129 var bitLen uint64130 if len(t.Colon) != 0 {131 bitLen = t.Colon[0].Value132 }133 base.TypeSize = size134 return &prog.IntType{135 IntTypeCommon: genIntCommon(base.TypeCommon, bitLen, be),136 Kind: kind,137 RangeBegin: rangeBegin,138 RangeEnd: rangeEnd,139 Align: align,140 }141 },142}143var typePtr = &typeDesc{144 Names: []string{"ptr", "ptr64"},145 CanBeArgRet: canBeArg,146 CanBeTypedef: true,147 Args: []namedArg{{Name: "direction", Type: typeArgDir}, {Name: "type", Type: typeArgType}},148 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {149 base.TypeSize = comp.ptrSize150 if t.Ident == "ptr64" {151 base.TypeSize = 8152 }153 return &prog.PtrType{154 TypeCommon: base.TypeCommon,155 Elem: comp.genType(args[1], 0),156 ElemDir: genDir(args[0]),157 }158 },159}160var typeVoid = &typeDesc{161 Names: []string{"void"},162 CantBeOpt: true,163 ZeroSize: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {164 return true165 },166 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {167 base.TypeSize = 0 // the only type with static size 0168 return &prog.BufferType{169 TypeCommon: base.TypeCommon,170 Kind: prog.BufferBlobRange,171 RangeBegin: 0,172 RangeEnd: 0,173 }174 },175}176var typeArray = &typeDesc{177 Names: []string{"array"},178 CanBeTypedef: true,179 CantBeOpt: true,180 OptArgs: 1,181 Args: []namedArg{{Name: "type", Type: typeArgType}, {Name: "size", Type: typeArgSizeRange}},182 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {183 if len(args) > 1 && args[1].Value == 0 && (len(args[1].Colon) == 0 || args[1].Colon[0].Value == 0) {184 comp.error(args[1].Pos, "arrays of size 0 are not supported")185 }186 },187 Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {188 if comp.isZeroSize(args[0]) {189 return false190 }191 if comp.isVarlen(args[0]) {192 return true193 }194 if len(args) > 1 {195 return len(args[1].Colon) != 0 && args[1].Value != args[1].Colon[0].Value196 }197 return true198 },199 ZeroSize: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {200 return comp.isZeroSize(args[0])201 },202 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {203 elemType := comp.genType(args[0], 0)204 kind, begin, end := prog.ArrayRandLen, uint64(0), uint64(0)205 if len(args) > 1 {206 kind, begin, end = prog.ArrayRangeLen, args[1].Value, args[1].Value207 if len(args[1].Colon) != 0 {208 end = args[1].Colon[0].Value209 }210 }211 if it, ok := elemType.(*prog.IntType); ok && it.Kind == prog.IntPlain && it.TypeSize == 1 {212 // Special case: buffer is better mutated.213 bufKind := prog.BufferBlobRand214 base.TypeSize = 0215 if kind == prog.ArrayRangeLen {216 bufKind = prog.BufferBlobRange217 if begin == end {218 base.TypeSize = begin * elemType.Size()219 }220 }221 return &prog.BufferType{222 TypeCommon: base.TypeCommon,223 Kind: bufKind,224 RangeBegin: begin,225 RangeEnd: end,226 }227 }228 // TypeSize is assigned later in layoutArray.229 return &prog.ArrayType{230 TypeCommon: base.TypeCommon,231 Elem: elemType,232 Kind: kind,233 RangeBegin: begin,234 RangeEnd: end,235 }236 },237}238var typeLen = &typeDesc{239 Names: []string{"len", "bytesize", "bytesize2", "bytesize4", "bytesize8", "bitsize", "offsetof"},240 CanBeArgRet: canBeArg,241 CantBeOpt: true,242 NeedBase: true,243 Args: []namedArg{{Name: "len target", Type: typeArgLenTarget}},244 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {245 var bitSize uint64246 var offset bool247 switch t.Ident {248 case "bytesize":249 bitSize = 8250 case "bytesize2", "bytesize4", "bytesize8":251 byteSize, _ := strconv.ParseUint(t.Ident[8:], 10, 8)252 bitSize = byteSize * 8253 case "bitsize":254 bitSize = 1255 case "offsetof":256 bitSize = 8257 offset = true258 }259 path := []string{args[0].Ident}260 for _, col := range args[0].Colon {261 path = append(path, col.Ident)262 }263 return &prog.LenType{264 IntTypeCommon: base,265 Path: path,266 BitSize: bitSize,267 Offset: offset,268 }269 },270}271var typeConst = &typeDesc{272 Names: []string{"const"},273 CanBeArgRet: canBeArg,274 CanBeTypedef: true,275 CantBeOpt: true,276 NeedBase: true,277 Args: []namedArg{{Name: "value", Type: typeArgInt}},278 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {279 v := args[0].Value280 bitSize := base.TypeBitSize()281 if constOverflowsBase(v, base) {282 comp.error(args[0].Pos, "const val 0x%x does not fit into %v bits", v, bitSize)283 }284 args[0].Value = v & (uint64(1)<<bitSize - 1)285 },286 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {287 return &prog.ConstType{288 IntTypeCommon: base,289 Val: args[0].Value,290 }291 },292}293func constOverflowsBase(v uint64, base prog.IntTypeCommon) bool {294 size := base.TypeBitSize()295 if size == 64 {296 return false297 }298 mask := uint64(1)<<size - 1299 v1 := v & mask300 if int64(v1<<(64-size)) < 0 && int64(v) < 0 {301 v1 |= ^mask302 }303 return v1 != v304}305var typeArgLenTarget = &typeArg{306 Kind: kindIdent,307 MaxColon: 10,308}309var typeFlags = &typeDesc{310 Names: []string{"flags"},311 CanBeArgRet: canBeArg,312 CanBeTypedef: true,313 CantBeOpt: true,314 NeedBase: true,315 Args: []namedArg{{Name: "flags", Type: typeArgFlags}},316 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {317 name := args[0].Ident318 if name == "xdp_mmap_offsets" && comp.ptrSize == 4 {319 // TODO(dvyukov): this sucks a lot. It seems that out 32-bit mmap is wrong.320 // The syscall accepts number of pages as int32, but we pass offset in bytes.321 // As the result large XDP consts don't fit into the arg.322 return323 }324 f := comp.intFlags[name]325 for _, val := range f.Values {326 if constOverflowsBase(val.Value, base) {327 comp.error(args[0].Pos, "%v %v=0x%x doesn't fit into %v bits",328 name, val.Ident, val.Value, base.TypeBitSize())329 }330 }331 },332 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {333 name := args[0].Ident334 base.TypeName = name335 f := comp.intFlags[name]336 values := genIntArray(f.Values)337 if len(values) == 0 || len(values) == 1 && values[0] == 0 {338 // We can get this if all values are unsupported consts.339 // Also generate const[0] if we have only 1 flags value which is 0,340 // this is the intention in all existing cases (e.g. an enum with types341 // of something, but there is really only 1 type exists).342 return &prog.ConstType{343 IntTypeCommon: base,344 Val: 0,345 }346 }347 sort.Slice(values, func(i, j int) bool {348 return values[i] < values[j]349 })350 return &prog.FlagsType{351 IntTypeCommon: base,352 Vals: values,353 BitMask: isBitmask(values),354 }355 },356}357func isBitmask(values []uint64) bool {358 if values[0] == 0 {359 // 0 can't be part of bitmask, this helps to handle important360 // case like "0, 1" and "0, 1, 2" that would be detected361 // as bitmask otherwise.362 return false363 }364 var combined uint64365 for _, v := range values {366 if v&combined != 0 {367 return false368 }369 combined |= v370 }371 return true372}373var typeArgFlags = &typeArg{374 Kind: kindIdent,375 Check: func(comp *compiler, t *ast.Type) {376 if comp.intFlags[t.Ident] == nil {377 comp.error(t.Pos, "unknown flags %v", t.Ident)378 return379 }380 },381}382var typeVMA = &typeDesc{383 Names: []string{"vma", "vma64"},384 CanBeArgRet: canBeArg,385 OptArgs: 1,386 Args: []namedArg{{Name: "size range", Type: typeArgSizeRange}},387 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {388 var begin, end uint64389 if len(args) > 0 {390 begin, end = args[0].Value, args[0].Value391 if len(args[0].Colon) != 0 {392 end = args[0].Colon[0].Value393 }394 }395 base.TypeSize = comp.ptrSize396 if t.Ident == "vma64" {397 base.TypeSize = 8398 }399 return &prog.VmaType{400 TypeCommon: base.TypeCommon,401 RangeBegin: begin,402 RangeEnd: end,403 }404 },405}406var typeCsum = &typeDesc{407 Names: []string{"csum"},408 NeedBase: true,409 CantBeOpt: true,410 OptArgs: 1,411 Args: []namedArg{412 {Name: "csum target", Type: typeArgLenTarget},413 {Name: "kind", Type: typeArgCsumType},414 {Name: "proto", Type: typeArgInt},415 },416 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {417 if len(args) > 2 && genCsumKind(args[1]) != prog.CsumPseudo {418 comp.error(args[2].Pos, "only pseudo csum can have proto")419 }420 if len(args[0].Colon) != 0 {421 comp.error(args[0].Colon[0].Pos, "path expressions are not implemented for csum")422 }423 },424 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {425 var proto uint64426 if len(args) > 2 {427 proto = args[2].Value428 }429 return &prog.CsumType{430 IntTypeCommon: base,431 Buf: args[0].Ident,432 Kind: genCsumKind(args[1]),433 Protocol: proto,434 }435 },436}437var typeArgCsumType = &typeArg{438 Kind: kindIdent,439 Names: []string{"inet", "pseudo"},440}441func genCsumKind(t *ast.Type) prog.CsumKind {442 switch t.Ident {443 case "inet":444 return prog.CsumInet445 case "pseudo":446 return prog.CsumPseudo447 default:448 panic(fmt.Sprintf("unknown csum kind %q", t.Ident))449 }450}451var typeProc = &typeDesc{452 Names: []string{"proc"},453 CanBeArgRet: canBeArg,454 CanBeTypedef: true,455 NeedBase: true,456 Args: []namedArg{457 {Name: "range start", Type: typeArgInt},458 {Name: "per-proc values", Type: typeArgInt},459 },460 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {461 start := args[0].Value462 perProc := args[1].Value463 if perProc == 0 {464 comp.error(args[1].Pos, "proc per-process values must not be 0")465 return466 }467 size := base.TypeSize * 8468 max := uint64(1) << size469 if size == 64 {470 max = ^uint64(0)471 }472 if start >= max {473 comp.error(args[0].Pos, "values starting from %v overflow base type", start)474 } else if perProc > (max-start)/prog.MaxPids {475 comp.error(args[0].Pos, "values starting from %v with step %v overflow base type for %v procs",476 start, perProc, prog.MaxPids)477 }478 },479 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {480 return &prog.ProcType{481 IntTypeCommon: base,482 ValuesStart: args[0].Value,483 ValuesPerProc: args[1].Value,484 }485 },486}487var typeText = &typeDesc{488 Names: []string{"text"},489 CantBeOpt: true,490 Args: []namedArg{{Name: "kind", Type: typeArgTextType}},491 Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {492 return true493 },494 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {495 base.TypeSize = 0496 return &prog.BufferType{497 TypeCommon: base.TypeCommon,498 Kind: prog.BufferText,499 Text: genTextType(args[0]),500 }501 },502}503var typeArgTextType = &typeArg{504 Kind: kindIdent,505 Names: []string{"target", "x86_real", "x86_16", "x86_32", "x86_64", "arm64"},506}507func genTextType(t *ast.Type) prog.TextKind {508 switch t.Ident {509 case "target":510 return prog.TextTarget511 case "x86_real":512 return prog.TextX86Real513 case "x86_16":514 return prog.TextX86bit16515 case "x86_32":516 return prog.TextX86bit32517 case "x86_64":518 return prog.TextX86bit64519 case "arm64":520 return prog.TextArm64521 default:522 panic(fmt.Sprintf("unknown text type %q", t.Ident))523 }524}525const (526 stringnoz = "stringnoz"527)528var typeString = &typeDesc{529 Names: []string{"string", stringnoz},530 CanBeTypedef: true,531 OptArgs: 2,532 Args: []namedArg{533 {Name: "literal or flags", Type: typeArgStringFlags},534 {Name: "size", Type: typeArgInt},535 },536 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {537 if t.Ident == stringnoz && len(args) > 1 {538 comp.error(args[0].Pos, "fixed-size string can't be non-zero-terminated")539 }540 },541 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {542 if len(args) > 1 {543 size := args[1].Value544 vals := comp.genStrings(t, args)545 for _, s := range vals {546 if uint64(len(s)) > size {547 comp.error(args[0].Pos, "string value %q exceeds buffer length %v",548 s, size)549 }550 }551 }552 },553 Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {554 return comp.stringSize(t, args) == varlenString555 },556 ZeroSize: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {557 return comp.stringSize(t, args) == 0558 },559 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {560 if len(args) > 0 && args[0].Ident == "filename" {561 base.TypeName = "filename"562 base.TypeSize = 0563 if len(args) >= 2 {564 base.TypeSize = args[1].Value565 }566 return &prog.BufferType{567 TypeCommon: base.TypeCommon,568 Kind: prog.BufferFilename,569 NoZ: t.Ident == stringnoz,570 }571 }572 subkind := ""573 if len(args) > 0 && args[0].Ident != "" {574 subkind = args[0].Ident575 }576 vals := comp.genStrings(t, args)577 base.TypeSize = comp.stringSize(t, args)578 if base.TypeSize == varlenString {579 base.TypeSize = 0580 }581 return &prog.BufferType{582 TypeCommon: base.TypeCommon,583 Kind: prog.BufferString,584 SubKind: subkind,585 Values: vals,586 NoZ: t.Ident == stringnoz,587 }588 },589}590func (comp *compiler) genStrings(t *ast.Type, args []*ast.Type) []string {591 var vals []string592 if len(args) > 0 {593 if args[0].HasString {594 vals = append(vals, args[0].String)595 } else {596 vals = genStrArray(comp.strFlags[args[0].Ident].Values)597 }598 }599 if t.Ident == stringnoz {600 return vals601 }602 var size uint64603 if len(args) > 1 {604 size = args[1].Value605 }606 for i, s := range vals {607 s += "\x00"608 for uint64(len(s)) < size {609 s += "\x00"610 }611 vals[i] = s612 }613 return vals614}615const varlenString = ^uint64(0)616// stringSize returns static string size, or varlenString if it is variable length.617func (comp *compiler) stringSize(t *ast.Type, args []*ast.Type) uint64 {618 switch len(args) {619 case 0:620 return varlenString // a random string621 case 1:622 var z uint64623 if t.Ident == "string" {624 z = 1625 }626 if args[0].HasString {627 return uint64(len(args[0].String)) + z // string constant628 }629 size := varlenString630 for _, s := range comp.strFlags[args[0].Ident].Values {631 s1 := uint64(len(s.Value)) + z632 if size != varlenString && size != s1 {633 return varlenString // strings of different lengths634 }635 size = s1636 }637 return size // all strings have the same length638 case 2:639 return args[1].Value // have explicit length640 default:641 panic("too many string args")642 }643}644var typeArgStringFlags = &typeArg{645 Check: func(comp *compiler, t *ast.Type) {646 if !t.HasString && t.Ident == "" {647 comp.error(t.Pos, "unexpected int %v, string arg must be a string literal or string flags", t.Value)648 return649 }650 if t.Ident != "" && comp.strFlags[t.Ident] == nil {651 comp.error(t.Pos, "unknown string flags %v", t.Ident)652 return653 }654 },655}656var typeFmt = &typeDesc{657 Names: []string{"fmt"},658 CanBeTypedef: true,659 CantBeOpt: true,660 Args: []namedArg{661 {Name: "format", Type: typeFmtFormat},662 {Name: "value", Type: typeArgType, IsArg: true},663 },664 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {665 desc, _, _ := comp.getArgsBase(args[1], true)666 switch desc {667 case typeResource, typeInt, typeLen, typeFlags, typeProc:668 default:669 comp.error(t.Pos, "bad fmt value %v, expect an integer", args[1].Ident)670 return671 }672 },673 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {674 var format prog.BinaryFormat675 var size uint64676 switch args[0].Ident {677 case "dec":678 format = prog.FormatStrDec679 size = 20680 case "hex":681 format = prog.FormatStrHex682 size = 18683 case "oct":684 format = prog.FormatStrOct685 size = 23686 }687 typ := comp.genType(args[1], comp.ptrSize)688 switch t := typ.(type) {689 case *prog.ResourceType:690 t.ArgFormat = format691 t.TypeSize = size692 case *prog.IntType:693 t.ArgFormat = format694 t.TypeSize = size695 case *prog.LenType:696 t.ArgFormat = format697 t.TypeSize = size698 case *prog.FlagsType:699 t.ArgFormat = format700 t.TypeSize = size701 case *prog.ProcType:702 t.ArgFormat = format703 t.TypeSize = size704 default:705 panic(fmt.Sprintf("unexpected type: %#v", typ))706 }707 return typ708 },709}710var typeFmtFormat = &typeArg{711 Names: []string{"dec", "hex", "oct"},712 Kind: kindIdent,713}714// typeArgType is used as placeholder for any type (e.g. ptr target type).715var typeArgType = &typeArg{}716var typeResource = &typeDesc{717 // No Names, but getTypeDesc knows how to match it.718 CanBeArgRet: canBeArgRet,719 CanBeResourceBase: func(comp *compiler, t *ast.Type) bool {720 return true721 },722 // Gen is assigned below to avoid initialization loop.723}724func init() {725 typeResource.Gen = func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {726 // Find and generate base type to get its size.727 var baseType *ast.Type728 for r := comp.resources[t.Ident]; r != nil; {729 baseType = r.Base730 r = comp.resources[r.Base.Ident]731 }732 baseProgType := comp.genType(baseType, 0)733 base.TypeSize = baseProgType.Size()734 return &prog.ResourceType{735 TypeCommon: base.TypeCommon,736 ArgFormat: baseProgType.Format(),737 }738 }739}740var typeStruct = &typeDesc{741 // No Names, but getTypeDesc knows how to match it.742 CantBeOpt: true,743 CanBeTypedef: true,744 // Varlen/Gen are assigned below due to initialization cycle.745}746func init() {747 typeStruct.CanBeArgRet = func(comp *compiler, t *ast.Type) (bool, bool) {748 // Allow unions to be arg if all options can be arg.749 s := comp.structs[t.Ident]750 if !s.IsUnion {751 return false, false752 }753 canBeArg := true754 for _, fld := range s.Fields {755 desc := comp.getTypeDesc(fld.Type)756 if desc == nil || desc == typeStruct || desc.CanBeArgRet == nil {757 return false, false758 }759 canBeArg1, _ := desc.CanBeArgRet(comp, fld.Type)760 if !canBeArg1 {761 canBeArg = false762 }763 }764 return canBeArg, false765 }766 typeStruct.Varlen = func(comp *compiler, t *ast.Type, args []*ast.Type) bool {767 return comp.structIsVarlen(t.Ident)768 }769 typeStruct.ZeroSize = func(comp *compiler, t *ast.Type, args []*ast.Type) bool {770 for _, fld := range comp.structs[t.Ident].Fields {771 if !comp.isZeroSize(fld.Type) {772 return false773 }774 }775 return true776 }777 typeStruct.Gen = func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {778 if typ := comp.structTypes[t.Ident]; typ != nil {779 return typ780 }781 s := comp.structs[t.Ident]782 common := genCommon(t.Ident, sizeUnassigned, false)783 common.IsVarlen = typeStruct.Varlen(comp, t, args)784 var typ prog.Type785 if s.IsUnion {786 typ = &prog.UnionType{787 TypeCommon: common,788 }789 } else {790 typ = &prog.StructType{791 TypeCommon: common,792 }793 }794 // Need to cache type in structTypes before generating fields to break recursion.795 comp.structTypes[t.Ident] = typ796 fields := comp.genFieldArray(s.Fields, make([]uint64, len(s.Fields)))797 if s.IsUnion {798 typ.(*prog.UnionType).Fields = fields799 } else {800 typ.(*prog.StructType).Fields = fields801 }802 return typ803 }804}805var typeTypedef = &typeDesc{806 // No Names, but getTypeDesc knows how to match it.807 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {808 panic("must not be called")809 },810}811var typeArgDir = &typeArg{812 Kind: kindIdent,813 Names: []string{"in", "out", "inout"},814}815func genDir(t *ast.Type) prog.Dir {816 switch t.Ident {817 case "in":818 return prog.DirIn819 case "out":820 return prog.DirOut821 case "inout":822 return prog.DirInOut823 default:824 panic(fmt.Sprintf("unknown direction %q", t.Ident))825 }826}827var typeArgInt = &typeArg{828 Kind: kindInt,829}830var typeArgIntRange = &typeArg{831 Kind: kindInt,832 MaxColon: 1,833}834var typeArgIntAlign = &typeArg{835 Kind: kindInt,836 MaxColon: 0,837 CheckConsts: func(comp *compiler, t *ast.Type) {838 if t.Value <= 1 {839 comp.error(t.Pos, "bad int alignment %v", t.Value)840 }841 },842}843// Size of array and vma's.844var typeArgSizeRange = &typeArg{845 Kind: kindInt,846 MaxColon: 1,847 CheckConsts: func(comp *compiler, t *ast.Type) {848 end := t.Value849 if len(t.Colon) != 0 {850 end = t.Colon[0].Value851 }852 const maxVal = 1e6853 if t.Value > end || t.Value > maxVal || end > maxVal {854 comp.error(t.Pos, "bad size range [%v:%v]", t.Value, end)855 }856 },857}858// Base type of const/len/etc. Same as typeInt, but can't have range.859var typeArgBase = namedArg{860 Name: "base type",861 Type: &typeArg{862 Names: []string{"int8", "int16", "int32", "int64", "int16be", "int32be", "int64be", "intptr"},863 MaxColon: 1,864 Check: func(comp *compiler, t *ast.Type) {865 if len(t.Colon) != 0 {866 col := t.Colon[0]867 if col.Ident != "" {868 comp.error(col.Pos, "literal const bitfield sizes are not supported")869 return870 }871 if col.Value == 0 {872 // This was not supported historically873 // and does not work the way C bitfields of size 0 work.874 // We could allow this, but then we need to make875 // this work the way C bitfields work.876 comp.error(col.Pos, "bitfields of size 0 are not supported")877 }878 size, _ := comp.parseIntType(t.Ident)879 if col.Value > size*8 {880 comp.error(col.Pos, "bitfield of size %v is too large for base type of size %v",881 col.Value, size*8)882 }883 }884 },885 },886}887var (888 builtinTypes = make(map[string]*typeDesc)889 builtinDescs *ast.Description890 // To avoid weird cases like ptr[in, in] and ptr[out, opt].891 reservedName = map[string]bool{892 "opt": true,...

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1import java.io.*;2import java.util.*;3import java.util.regex.*;4import java.util.stream.*;5import java.util.function.*;6import java.util.concurrent.*;7import java.util.concurrent.atomic.*;8import java.util.concurrent.locks.*;9import java.util.concurrent.atomic.*;10import java.util.concurrent.atomic.AtomicInteger;11import java.util.concurrent.atomic.AtomicReference;12import java.util.concurrent.atomic.AtomicReferenceArray;13import java.util.concurrent.atomic.AtomicLongArray;14import java.util.concurrent.atomic.AtomicLong;15import java.util.concurrent.atomic.AtomicIntegerArray;16import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;17import java.util.concurrent.atomic.AtomicMarkableReference;18import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;19import java.util.concurrent.atomic.AtomicStampedReference;20import java.util.concurrent.locks.*;21import java.util.concurrent.locks.AbstractQueuedSynchronizer;22import java.util.concurrent.locks.AbstractOwnableSynchronizer;23import java.util.concurrent.locks.Condition;24import java.util.concurrent.locks.Lock;25import java.util.concurrent.locks.LockSupport;26import java.util.concurrent.locks.ReadWriteLock;27import java.util.concurrent.locks.ReentrantLock;28import java.util.concurrent.locks.ReentrantReadWriteLock;29import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;30import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;31import java.util.concurrent.locks.StampedLock;32import java.util.function.*;33import java.util.function.BiConsumer;34import java.util.function.BiFunction;35import java.util.function.BinaryOperator;36import java.util.function.BooleanSupplier;37import java.util.function.Consumer;38import java.util.function.DoubleBinaryOperator;39import java.util.function.DoubleConsumer;40import java.util.function.DoubleFunction;41import java.util.function.DoublePredicate;42import java.util.function.DoubleSupplier;43import java.util.function.DoubleToIntFunction;44import java.util.function.DoubleToLongFunction;45import java.util.function.DoubleUnaryOperator;46import java.util.function.Function;47import java.util.function.IntBinaryOperator;48import java.util.function.IntConsumer;49import java.util.function.IntFunction;50import java.util.function.IntPredicate;51import java.util.function.IntSupplier;52import java.util.function.IntToDoubleFunction;53import java.util.function.IntToLongFunction;54import java.util.function.IntUnaryOperator;55import java.util.function.LongBinaryOperator;56import java.util.function.LongConsumer;57import java.util.function.LongFunction;58import java.util.function.LongPredicate;59import java.util.function.LongSupplier;60import java.util.function.LongToDoubleFunction;61import java.util.function.LongToIntFunction;62import java.util.function.LongUnaryOperator;63import java.util.function.ObjDouble

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1import "fmt"2type compiler struct {3}4func (c compiler) parseIntType() {5fmt.Println("Parsing int type")6}7func main() {8c.parseIntType()9}10import "fmt"11type compiler struct {12}13func (c compiler) parseIntType() {14fmt.Println("Parsing int type")15}16func main() {17c.parseIntType()18}19import "fmt"20type compiler struct {21}22func (c compiler) parseIntType() {23fmt.Println("Parsing int type")24}25func main() {26c.parseIntType()27}28import "fmt"29type compiler struct {30}31func (c compiler) parseIntType() {32fmt.Println("Parsing int type")33}34func main() {35c.parseIntType()36}37import "fmt"38type compiler struct {39}40func (c compiler) parseIntType() {41fmt.Println("Parsing int type")42}43func main() {44c.parseIntType()45}46import "fmt"47type compiler struct {48}49func (c compiler) parseIntType() {50fmt.Println("Parsing int type")51}52func main() {53c.parseIntType()54}55import "fmt"56type compiler struct {57}58func (c compiler) parseIntType() {59fmt.Println("Parsing int type")60}61func main() {62c.parseIntType()63}

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Value of a is ", a)4}5import "fmt"6func main() {7 fmt.Println("Value of a is ", a)8}9import "fmt"10func main() {11 fmt.Println("Value of a is ", a)12}13import "fmt"14func main() {15 fmt.Println("Value of a is ", a)16}17import "fmt"18func main() {19 fmt.Println("Value of a is ", a)20}21import "fmt"22func main() {23 fmt.Println("Value of a is ", a)24}25import "fmt"26func main() {27 fmt.Println("Value of a is ", a)28}29import "fmt"30func main() {31 fmt.Println("Value of a is ", a)32}33import "fmt"34func main() {35 fmt.Println("Value of a is ", a)36}37import "fmt"38func main() {39 fmt.Println("Value of a is ", a)40}41import "fmt"42func main() {43 fmt.Println("Value of a is ", a)

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1import java.io.*;2import java.util.*;3import java.lang.*;4import java.math.*;5import java.text.*;6import java.util.regex.*;7import java.io.BufferedReader;8import java.io.IOException;9import java.io.InputStreamReader;10import java.util.*;11import java.util.StringTokenizer;12public class Solution {13 public static void main(String[] args) throws IOException {14 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));15 StringTokenizer st = new StringTokenizer(br.readLine());16 int n = Integer.parseInt(st.nextToken());17 int m = Integer.parseInt(st.nextToken());18 int[] arr = new int[n];19 st = new StringTokenizer(br.readLine());20 for (int i = 0; i < n; i++) {21 arr[i] = Integer.parseInt(st.nextToken());22 }23 int[][] queries = new int[m][3];24 for (int i = 0; i < m; i++) {25 st = new StringTokenizer(br.readLine());26 for (int j = 0; j < 3; j++) {27 queries[i][j] = Integer.parseInt(st.nextToken());28 }29 }30 int[] res = parseIntType(arr, queries);31 for (int i = 0; i < res.length; i++) {32 System.out.print(res[i] + " ");33 }34 }35 public static int[] parseIntType(int[] arr, int[][] queries) {36 int[] res = new int[queries.length];37 for (int i = 0; i < queries.length; i++) {38 int sum = 0;39 for (int j = queries[i][0] - 1; j < queries[i][1]; j++) {40 sum += arr[j];41 }42 res[i] = sum / queries[i][2];43 }44 return res;45 }46}47Time Complexity: O(n*m) where n is the number of elements in the array and m is the number of queries48Space Complexity: O(m) where m is the number of queries

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1int main()2{3 string str = "1234";4 int x = compiler.parseIntType(str);5 cout << x << endl;6 return 0;7}

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 compiler := new(Compiler)4 compiler.readInputFile(inputFile)5 compiler.parseTokens()6 compiler.generateAssemblyCode()7 compiler.writeAssemblyCodeToFile(outputFile)8}9type Compiler struct {10}11type Token struct {12}13func (compiler *Compiler) readInputFile(inputFile string) {14 file, err := os.Open(inputFile)15 if err != nil {16 fmt.Println("Error: File not found")17 os.Exit(1)18 }19 defer file.Close()20 for {21 _, err := fmt.Fscanln(file, &line)22 if err != nil {23 }24 lineTokens := strings.Split(line, " ")25 for _, token := range lineTokens {26 if token != "" {27 tokenObj := new(Token)28 tokenObj.tokenType = compiler.getTokenType(token)29 compiler.tokens = append(compiler.tokens, *tokenObj)30 }31 }

Full Screen

Full Screen

parseIntType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 file, err := os.Open("2.in")4 if err != nil {5 fmt.Println("Error opening file")6 }7 defer file.Close()8 scanner := bufio.NewScanner(file)9 file2, err := os.Create("2.out")10 if err != nil {11 fmt.Println("Error creating file")12 }13 defer file2.Close()14 writer := bufio.NewWriter(file2)15 for scanner.Scan() {16 line := scanner.Text()17 splitLine := strings.Fields(line)18 length := len(splitLine)19 if length == 0 {20 fmt.Fprintln(writer)21 } else {22 if firstWord == "int" || firstWord == "float" || firstWord == "string" {23 if length == 2 {24 splitWord := strings.Split(splitLine[1], ":")25 if len(splitWord) == 1 {26 fmt.Fprintln(writer, "PUSH", splitWord[0], "0")27 } else {28 size, _ := strconv.Atoi(splitWord[1])

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful