[fidl] Use uint32_t to represent sizes
Change-Id: I89fad69b3207f5b9e8855d577f9d4ba74b72c077
diff --git a/system/host/fidl/include/fidl/flat_ast.h b/system/host/fidl/include/fidl/flat_ast.h
index 4f53556..b075ea8 100644
--- a/system/host/fidl/include/fidl/flat_ast.h
+++ b/system/host/fidl/include/fidl/flat_ast.h
@@ -58,7 +58,7 @@
IntType value_;
};
-using Size = IntConstant<uint64_t>;
+using Size = IntConstant<uint32_t>;
// TODO(TO-701) Handle multipart names.
struct Name {
@@ -123,19 +123,19 @@
Identifier,
};
- explicit Type(Kind kind, uint64_t size)
+ explicit Type(Kind kind, uint32_t size)
: kind(kind), size(size) {}
const Kind kind;
// Set at construction time for most Types. Identifier types get
// this set later, during compilation.
- uint64_t size;
+ uint32_t size;
bool operator<(const Type& other) const;
};
struct ArrayType : public Type {
- ArrayType(uint64_t size, std::unique_ptr<Type> element_type, Size element_count)
+ ArrayType(uint32_t size, std::unique_ptr<Type> element_type, Size element_count)
: Type(Kind::Array, size),
element_type(std::move(element_type)),
element_count(std::move(element_count)) {}
@@ -214,7 +214,7 @@
};
struct PrimitiveType : public Type {
- static uint64_t SubtypeSize(types::PrimitiveSubtype subtype) {
+ static uint32_t SubtypeSize(types::PrimitiveSubtype subtype) {
switch (subtype) {
case types::PrimitiveSubtype::Bool:
case types::PrimitiveSubtype::Int8:
diff --git a/system/host/fidl/include/fidl/json_generator.h b/system/host/fidl/include/fidl/json_generator.h
index 5d781fb..bf6d979 100644
--- a/system/host/fidl/include/fidl/json_generator.h
+++ b/system/host/fidl/include/fidl/json_generator.h
@@ -63,7 +63,7 @@
void Generate(bool value);
void Generate(StringView value);
void Generate(SourceLocation value);
- void Generate(uint64_t value);
+ void Generate(uint32_t value);
void Generate(types::HandleSubtype value);
void Generate(types::Nullability value);
diff --git a/system/host/fidl/include/fidl/type_shape.h b/system/host/fidl/include/fidl/type_shape.h
index 50e9438..f82e23b 100644
--- a/system/host/fidl/include/fidl/type_shape.h
+++ b/system/host/fidl/include/fidl/type_shape.h
@@ -9,7 +9,7 @@
class TypeShape {
public:
- constexpr TypeShape(uint64_t size, uint64_t alignment)
+ constexpr TypeShape(uint32_t size, uint32_t alignment)
: size_(size), alignment_(alignment) {}
constexpr TypeShape()
: TypeShape(0u, 0u) {}
@@ -17,17 +17,17 @@
TypeShape(const TypeShape&) = default;
TypeShape& operator=(const TypeShape&) = default;
- uint64_t Size() const { return size_; }
- uint64_t Alignment() const { return alignment_; }
+ uint32_t Size() const { return size_; }
+ uint32_t Alignment() const { return alignment_; }
private:
- uint64_t size_;
- uint64_t alignment_;
+ uint32_t size_;
+ uint32_t alignment_;
};
class FieldShape {
public:
- explicit FieldShape(TypeShape typeshape, uint64_t offset = 0u)
+ explicit FieldShape(TypeShape typeshape, uint32_t offset = 0u)
: typeshape_(typeshape),
offset_(offset) {}
FieldShape()
@@ -36,16 +36,16 @@
TypeShape& Typeshape() { return typeshape_; }
TypeShape Typeshape() const { return typeshape_; }
- uint64_t Size() const { return typeshape_.Size(); }
- uint64_t Alignment() const { return typeshape_.Alignment(); }
- uint64_t Offset() const { return offset_; }
+ uint32_t Size() const { return typeshape_.Size(); }
+ uint32_t Alignment() const { return typeshape_.Alignment(); }
+ uint32_t Offset() const { return offset_; }
void SetTypeshape(TypeShape typeshape) { typeshape_ = typeshape; }
- void SetOffset(uint64_t offset) { offset_ = offset; }
+ void SetOffset(uint32_t offset) { offset_ = offset; }
private:
TypeShape typeshape_;
- uint64_t offset_;
+ uint32_t offset_;
};
#endif // ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_
diff --git a/system/host/fidl/lib/flat_ast.cpp b/system/host/fidl/lib/flat_ast.cpp
index b741479..7f9995b 100644
--- a/system/host/fidl/lib/flat_ast.cpp
+++ b/system/host/fidl/lib/flat_ast.cpp
@@ -46,7 +46,7 @@
constexpr TypeShape kFloat64TypeShape = TypeShape(8u, 8u);
constexpr TypeShape kPointerTypeShape = TypeShape(8u, 8u);
-uint64_t AlignTo(uint64_t size, uint64_t alignment) {
+uint32_t AlignTo(uint32_t size, uint32_t alignment) {
auto mask = alignment - 1;
size += mask;
size &= ~mask;
@@ -54,8 +54,8 @@
}
TypeShape CStructTypeShape(std::vector<FieldShape*>* fields) {
- uint64_t size = 0u;
- uint64_t alignment = 1u;
+ uint32_t size = 0u;
+ uint32_t alignment = 1u;
for (FieldShape* field : *fields) {
field->SetOffset(size);
@@ -69,8 +69,8 @@
}
TypeShape CUnionTypeShape(const std::vector<flat::Union::Member>& members) {
- uint64_t size = 0u;
- uint64_t alignment = 1u;
+ uint32_t size = 0u;
+ uint32_t alignment = 1u;
for (const auto& member : members) {
const auto& fieldshape = member.fieldshape;
size = std::max(size, fieldshape.Size());
@@ -85,7 +85,7 @@
return CStructTypeShape(fields);
}
-TypeShape ArrayTypeShape(TypeShape element, uint64_t count) {
+TypeShape ArrayTypeShape(TypeShape element, uint32_t count) {
return TypeShape(element.Size() * count, element.Alignment());
}
@@ -141,7 +141,7 @@
// so on.
bool Library::ParseSize(std::unique_ptr<raw::Constant> raw_constant, Size* out_size) {
- uint64_t value;
+ uint32_t value;
if (!ParseIntegerConstant(raw_constant.get(), &value)) {
*out_size = Size();
return false;
@@ -167,7 +167,7 @@
if (!ParseSize(std::move(array_type->element_count), &element_count))
return false;
// TODO(kulakowski) Overflow checking.
- uint64_t size = element_count.Value() * element_type->size;
+ uint32_t size = element_count.Value() * element_type->size;
*out_type = std::make_unique<ArrayType>(size, std::move(element_type), std::move(element_count));
break;
}
diff --git a/system/host/fidl/lib/json_generator.cpp b/system/host/fidl/lib/json_generator.cpp
index d7960f3..a77deca 100644
--- a/system/host/fidl/lib/json_generator.cpp
+++ b/system/host/fidl/lib/json_generator.cpp
@@ -50,10 +50,6 @@
*file << value;
}
-void EmitUint64(std::ostream* file, uint64_t value) {
- *file << value;
-}
-
void EmitNewline(std::ostream* file) {
*file << "\n";
}
@@ -174,8 +170,8 @@
EmitString(&json_file_, value.data());
}
-void JSONGenerator::Generate(uint64_t value) {
- EmitUint64(&json_file_, value);
+void JSONGenerator::Generate(uint32_t value) {
+ EmitUint32(&json_file_, value);
}
void JSONGenerator::Generate(types::HandleSubtype value) {
diff --git a/system/host/fidl/lib/tables_generator.cpp b/system/host/fidl/lib/tables_generator.cpp
index 9a6f4c7..9bdcb73 100644
--- a/system/host/fidl/lib/tables_generator.cpp
+++ b/system/host/fidl/lib/tables_generator.cpp
@@ -272,8 +272,8 @@
if (iter != vector_type_map_.end())
return iter->second;
auto coded_element_type = Compile(vector_type->element_type.get());
- uint64_t max_count = vector_type->element_count.Value();
- uint64_t element_size = vector_type->element_type->size;
+ uint32_t max_count = vector_type->element_count.Value();
+ uint32_t element_size = vector_type->element_type->size;
StringView element_name = coded_element_type->coded_name;
auto name = NameCodedVector(element_name, max_count, vector_type->nullability);
auto coded_vector_type = std::make_unique<coded::VectorType>(std::move(name), coded_element_type, max_count, element_size, vector_type->nullability);