| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package cgen | 5 package cgen |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "log" | 9 "log" |
| 10 "path/filepath" | 10 "path/filepath" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 | 442 |
| 443 func getPaddingAfter(fields []mojom_types.StructField, i int, fileGraph *mojom_f
iles.MojomFileGraph) uint32 { | 443 func getPaddingAfter(fields []mojom_types.StructField, i int, fileGraph *mojom_f
iles.MojomFileGraph) uint32 { |
| 444 // Must be a power of 2 for the remaining computation to work | 444 // Must be a power of 2 for the remaining computation to work |
| 445 const kAlignment uint32 = 8 | 445 const kAlignment uint32 = 8 |
| 446 | 446 |
| 447 // Calculate the remaining padding for the last field | 447 // Calculate the remaining padding for the last field |
| 448 if i == len(fields)-1 { | 448 if i == len(fields)-1 { |
| 449 // m = (field offset + field size) % kAlignment | 449 // m = (field offset + field size) % kAlignment |
| 450 » » m := (fields[i].Offset + mojomTypeSize(fields[i].Type, fileGraph
)) & (kAlignment - 1) | 450 » » m := (fields[i].Offset + mojomTypeByteSize(fields[i].Type, fileG
raph)) & (kAlignment - 1) |
| 451 if m != 0 { | 451 if m != 0 { |
| 452 return kAlignment - m | 452 return kAlignment - m |
| 453 } | 453 } |
| 454 return 0 | 454 return 0 |
| 455 } | 455 } |
| 456 | 456 |
| 457 // (next element's offset) | 457 // (next element's offset) |
| 458 // - (current element's offset + current element's size) | 458 // - (current element's offset + current element's size) |
| 459 » diff := int64(fields[i+1].Offset) - (int64(fields[i].Offset) + int64(moj
omTypeSize(fields[i].Type, fileGraph))) | 459 » diff := int64(fields[i+1].Offset) - (int64(fields[i].Offset) + int64(moj
omTypeByteSize(fields[i].Type, fileGraph))) |
| 460 if diff <= 0 { | 460 if diff <= 0 { |
| 461 return 0 | 461 return 0 |
| 462 } | 462 } |
| 463 return uint32(diff) | 463 return uint32(diff) |
| 464 } | 464 } |
| OLD | NEW |