diff --git a/migrate_cpp/cpp_refactoring/var_decl.cpp b/migrate_cpp/cpp_refactoring/var_decl.cpp index 0fb383022754..6c33271d8168 100644 --- a/migrate_cpp/cpp_refactoring/var_decl.cpp +++ b/migrate_cpp/cpp_refactoring/var_decl.cpp @@ -21,41 +21,82 @@ VarDecl::VarDecl(std::map& in_replacements, this); } +// Helper function for printing TypeLocClass. Useful for debugging. +LLVM_ATTRIBUTE_UNUSED +static auto TypeLocClassToString(clang::TypeLoc::TypeLocClass c) + -> std::string { + switch (c) { + // Mirrors the definition in clang/AST/TypeLoc.h in order to print names. +#define ABSTRACT_TYPE(Class, Base) +#define TYPE(Class, Base) \ + case clang::TypeLoc::Class: \ + return #Class; +#include "clang/AST/TypeNodes.inc" + case clang::TypeLoc::Qualified: + return "Qualified"; + } +} + // Returns a string for the type. static auto GetTypeStr(const clang::VarDecl* decl, const clang::SourceManager& sm, const clang::LangOptions& lang_opts) -> std::string { + // Built a vector of class information, because we'll be traversing reverse + // order to construct the final type. auto type_loc = decl->getTypeSourceInfo()->getTypeLoc(); - std::vector segments; + std::vector> segments; while (!type_loc.isNull()) { - switch (type_loc.getTypeLocClass()) { - case clang::TypeLoc::LValueReference: - case clang::TypeLoc::RValueReference: - case clang::TypeLoc::Pointer: - case clang::TypeLoc::Auto: - case clang::TypeLoc::Qualified: - segments.push_back(type_loc.getLocalSourceRange()); - type_loc = type_loc.getNextTypeLoc(); - break; - - default: - // For non-auto types, use the canonical type, which adds things like - // namespace qualifiers. - return clang::QualType::getAsString(decl->getType().split(), lang_opts); + std::string text; + auto qualifiers = type_loc.getType().getLocalQualifiers(); + std::string qual_str; + if (!qualifiers.empty()) { + qual_str = qualifiers.getAsString(); } + auto range = + clang::CharSourceRange::getTokenRange(type_loc.getLocalSourceRange()); + std::string range_str = + clang::Lexer::getSourceText(range, sm, lang_opts).str(); + + // Make a list of segments with their TypeLocClass for reconstruction of the + // string. Locally, we will have a qualifier (such as `const`) and a type + // string (such as `int`) which is also used. + auto type_loc_class = type_loc.getTypeLocClass(); + if (qual_str.empty()) { + segments.push_back({type_loc_class, range_str}); + } else if (range_str.empty()) { + segments.push_back({type_loc_class, qual_str}); + } else { + segments.push_back({type_loc_class, qual_str + " " + range_str}); + } + + type_loc = type_loc.getNextTypeLoc(); } - // Sort type segments as they're written in the file. This avoids needing to - // understand TypeLoc traversal ordering. - std::sort(segments.begin(), segments.end(), - [](clang::SourceRange a, clang::SourceRange b) { - return a.getBegin() < b.getBegin(); - }); - + // Construct the final type based on the class of each step. This reverses to + // start from the "inside" of the type and go "out" when constructing + // type_str. std::string type_str; - for (const auto& segment : segments) { - type_str += clang::Lexer::getSourceText( - clang::CharSourceRange::getTokenRange(segment), sm, lang_opts); + auto prev_class = clang::TypeLoc::Auto; // Placeholder class, used in loop. + for (const auto& [type_loc_class, text] : llvm::reverse(segments)) { + switch (type_loc_class) { + case clang::TypeLoc::Elaborated: + type_str.insert(0, text); + break; + case clang::TypeLoc::Qualified: + if (prev_class == clang::TypeLoc::Pointer) { + type_str += " " + text; + } else { + if (!type_str.empty()) { + type_str.insert(0, " "); + } + type_str.insert(0, text); + } + break; + default: + type_str += text; + break; + } + prev_class = type_loc_class; } return type_str; } diff --git a/migrate_cpp/cpp_refactoring/var_decl_test.cpp b/migrate_cpp/cpp_refactoring/var_decl_test.cpp index 718c3e31d4e3..48d346bd4914 100644 --- a/migrate_cpp/cpp_refactoring/var_decl_test.cpp +++ b/migrate_cpp/cpp_refactoring/var_decl_test.cpp @@ -24,7 +24,29 @@ TEST_F(VarDeclTest, Declaration) { TEST_F(VarDeclTest, DeclarationArray) { constexpr char Before[] = "int i[4];"; - constexpr char After[] = "var i: int [4];"; + constexpr char After[] = "var i: int[4];"; + ExpectReplacement(Before, After); +} + +TEST_F(VarDeclTest, DeclarationConstArray) { + constexpr char Before[] = "const int i[] = {0, 1};"; + constexpr char After[] = "let i: const int[];"; + ExpectReplacement(Before, After); +} + +TEST_F(VarDeclTest, DeclarationConstPointer) { + // TODO: Include init. + // TODO: Fix j replacement location. + constexpr char Before[] = R"cpp( + int i = 0; + int* const j = &i; + const int* k = &i; + )cpp"; + constexpr char After[] = R"( + var i: int; + int* const let j: int* const; + var k: const int*; + )"; ExpectReplacement(Before, After); } @@ -39,7 +61,7 @@ TEST_F(VarDeclTest, DeclarationCommaArray) { // TODO: Maybe replace the comma with a `;`. // TODO: Need to handle j's array. constexpr char Before[] = "int i[4], j[4];"; - constexpr char After[] = "var i: int [4], j[4];"; + constexpr char After[] = "var i: int[4], j[4];"; ExpectReplacement(Before, After); } @@ -48,7 +70,7 @@ TEST_F(VarDeclTest, DeclarationCommaPointers) { // TODO: Need to handle j's pointer. // constexpr char After[] = "var i: int *, var j: int *;"; constexpr char Before[] = "int *i, *j;"; - constexpr char After[] = "var i: int *, *j;"; + constexpr char After[] = "var i: int*, *j;"; ExpectReplacement(Before, After); } @@ -67,14 +89,13 @@ TEST_F(VarDeclTest, Auto) { TEST_F(VarDeclTest, AutoRef) { // TODO: Include init. - // TODO: j should have const. constexpr char Before[] = R"cpp( auto i = 0; const auto& j = i; )cpp"; constexpr char After[] = R"( var i: auto; - var j: auto&; + var j: const auto&; )"; ExpectReplacement(Before, After); } @@ -88,7 +109,7 @@ TEST_F(VarDeclTest, Const) { TEST_F(VarDeclTest, ConstPointer) { constexpr char Before[] = "const int* i;"; - constexpr char After[] = "var i: const int *;"; + constexpr char After[] = "var i: const int*;"; ExpectReplacement(Before, After); } @@ -137,7 +158,7 @@ TEST_F(VarDeclTest, ParamStruct) { )cpp"; constexpr char After[] = R"( struct Circle {}; - auto Draw(times: int, circle: const Circle &) -> bool; + auto Draw(times: int, circle: const Circle&) -> bool; )"; ExpectReplacement(Before, After); } @@ -167,7 +188,7 @@ TEST_F(VarDeclTest, RangeFor) { )cpp"; constexpr char After[] = R"( void Foo() { - var items: int [1]; + var items: int[]; for (int i : items) { var j: int; } @@ -176,5 +197,27 @@ TEST_F(VarDeclTest, RangeFor) { ExpectReplacement(Before, After); } +TEST_F(VarDeclTest, Template) { + constexpr char Before[] = R"cpp( + template + struct R {}; + + template + struct S {}; + + R> x; + )cpp"; + constexpr char After[] = R"( + template + struct R {}; + + template + struct S {}; + + var x: R>; + )"; + ExpectReplacement(Before, After); +} + } // namespace } // namespace Carbon diff --git a/third_party/examples/woff2/carbon/include/woff2/decode.carbon b/third_party/examples/woff2/carbon/include/woff2/decode.carbon index 23961eb97ec2..49f0fb0ac4f8 100644 --- a/third_party/examples/woff2/carbon/include/woff2/decode.carbon +++ b/third_party/examples/woff2/carbon/include/woff2/decode.carbon @@ -16,20 +16,20 @@ namespace woff2 { // Compute the size of the final uncompressed font, or 0 on error. -fn ComputeWOFF2FinalSize(data: const uint8_t *, length: size_t) -> size_t; +fn ComputeWOFF2FinalSize(data: const uint8_t*, length: size_t) -> size_t; // Decompresses the font into the target buffer. The result_length should // be the same as determined by ComputeFinalSize(). Returns true on successful // decompression. // DEPRECATED; please prefer the version that takes a WOFF2Out* -fn ConvertWOFF2ToTTF(result: uint8_t *, result_length: size_t, - data: const uint8_t *, length: size_t) -> bool; +fn ConvertWOFF2ToTTF(result: uint8_t*, result_length: size_t, + data: const uint8_t*, length: size_t) -> bool; // Decompresses the font into out. Returns true on success. // Works even if WOFF2Header totalSfntSize is wrong. // Please prefer this API. -fn ConvertWOFF2ToTTF(data: const uint8_t *, length: size_t, - out: woff2::WOFF2Out *) -> bool; +fn ConvertWOFF2ToTTF(data: const uint8_t*, length: size_t, + out: WOFF2Out*) -> bool; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/include/woff2/encode.carbon b/third_party/examples/woff2/carbon/include/woff2/encode.carbon index 8d696c1a6bc7..10db7f42844d 100644 --- a/third_party/examples/woff2/carbon/include/woff2/encode.carbon +++ b/third_party/examples/woff2/carbon/include/woff2/encode.carbon @@ -25,18 +25,18 @@ struct WOFF2Params { }; // Returns an upper bound on the size of the compressed file. -fn MaxWOFF2CompressedSize(data: const uint8_t *, length: size_t) -> size_t; -fn MaxWOFF2CompressedSize(data: const uint8_t *, length: size_t, - extended_metadata: const std::string &) -> size_t; +fn MaxWOFF2CompressedSize(data: const uint8_t*, length: size_t) -> size_t; +fn MaxWOFF2CompressedSize(data: const uint8_t*, length: size_t, + extended_metadata: const std::string&) -> size_t; // Compresses the font into the target buffer. *result_length should be at least // the value returned by MaxWOFF2CompressedSize(), upon return, it is set to the // actual compressed size. Returns true on successful compression. -fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, - result: uint8_t *, result_length: size_t *) -> bool; -fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, - result: uint8_t *, result_length: size_t *, - params: const woff2::WOFF2Params &) -> bool; +fn ConvertTTFToWOFF2(data: const uint8_t*, length: size_t, + result: uint8_t*, result_length: size_t*) -> bool; +fn ConvertTTFToWOFF2(data: const uint8_t*, length: size_t, + result: uint8_t*, result_length: size_t*, + params: const WOFF2Params&) -> bool; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/include/woff2/output.carbon b/third_party/examples/woff2/carbon/include/woff2/output.carbon index d722345543de..d3828fa28898 100644 --- a/third_party/examples/woff2/carbon/include/woff2/output.carbon +++ b/third_party/examples/woff2/carbon/include/woff2/output.carbon @@ -34,11 +34,11 @@ class WOFF2Out { // Append n bytes of data from buf. // Return true if all written, false otherwise. - fn auto Write(buf: const void *, n: size_t) -> bool = 0; + fn auto Write(buf: const void*, n: size_t) -> bool = 0; // Write n bytes of data from buf at offset. // Return true if all written, false otherwise. - fn auto Write(buf: const void *, offset: size_t, n: size_t) -> bool = 0; + fn auto Write(buf: const void*, offset: size_t, n: size_t) -> bool = 0; fn auto Size() -> size_t = 0; }; @@ -51,10 +51,10 @@ class WOFF2StringOut : public WOFF2Out { // Create a writer that writes its data to buf. // buf->size() will grow to at most max_size // buf may be sized (e.g. using EstimateWOFF2FinalSize) or empty. - explicit WOFF2StringOut(buf: std::string *); + explicit WOFF2StringOut(buf: std::string*); - fn Write(buf: const void *, n: size_t) -> bool override; - fn Write(buf: const void *, offset: size_t, n: size_t) -> bool override; + fn Write(buf: const void*, n: size_t) -> bool override; + fn Write(buf: const void*, offset: size_t, n: size_t) -> bool override; fn Size() -> size_t override { return offset_; } fn MaxSize() -> size_t { return max_size_; } fn SetMaxSize(max_size: size_t); @@ -70,10 +70,10 @@ class WOFF2StringOut : public WOFF2Out { class WOFF2MemoryOut : public WOFF2Out { public: // Create a writer that writes its data to buf. - WOFF2MemoryOut(buf: uint8_t *, buf_size: size_t); + WOFF2MemoryOut(buf: uint8_t*, buf_size: size_t); - fn Write(buf: const void *, n: size_t) -> bool override; - fn Write(buf: const void *, offset: size_t, n: size_t) -> bool override; + fn Write(buf: const void*, n: size_t) -> bool override; + fn Write(buf: const void*, offset: size_t, n: size_t) -> bool override; fn Size() -> size_t override { return offset_; } private: uint8_t* buf_; diff --git a/third_party/examples/woff2/carbon/src/buffer.carbon b/third_party/examples/woff2/carbon/src/buffer.carbon index ffb8e9fdb424..ceee4c8df42f 100644 --- a/third_party/examples/woff2/carbon/src/buffer.carbon +++ b/third_party/examples/woff2/carbon/src/buffer.carbon @@ -57,7 +57,7 @@ inline bool Failure(const char *f, int l, const char *fn) { // ----------------------------------------------------------------------------- class Buffer { public: - Buffer(data: const uint8_t *, len: size_t) + Buffer(data: const uint8_t*, len: size_t) : buffer_(data), length_(len), offset_(0) { } @@ -66,7 +66,7 @@ class Buffer { return Read(nullptr, n_bytes); } - fn Read(data: uint8_t *, n_bytes: size_t) -> bool { + fn Read(data: uint8_t*, n_bytes: size_t) -> bool { if (n_bytes > 1024 * 1024 * 1024) { return FONT_COMPRESSION_FAILURE(); } @@ -81,7 +81,7 @@ class Buffer { return true; } - fn auto ReadU8(value: uint8_t *) -> bool { + fn auto ReadU8(value: uint8_t*) -> bool { if (offset_ + 1 > length_) { return FONT_COMPRESSION_FAILURE(); } @@ -90,7 +90,7 @@ class Buffer { return true; } - fn ReadU16(value: uint16_t *) -> bool { + fn ReadU16(value: uint16_t*) -> bool { if (offset_ + 2 > length_) { return FONT_COMPRESSION_FAILURE(); } @@ -100,11 +100,11 @@ class Buffer { return true; } - fn ReadS16(value: int16_t *) -> bool { + fn ReadS16(value: int16_t*) -> bool { return ReadU16(reinterpret_cast(value)); } - fn ReadU24(value: uint32_t *) -> bool { + fn ReadU24(value: uint32_t*) -> bool { if (offset_ + 3 > length_) { return FONT_COMPRESSION_FAILURE(); } @@ -115,7 +115,7 @@ class Buffer { return true; } - fn ReadU32(value: uint32_t *) -> bool { + fn ReadU32(value: uint32_t*) -> bool { if (offset_ + 4 > length_) { return FONT_COMPRESSION_FAILURE(); } @@ -125,11 +125,11 @@ class Buffer { return true; } - fn ReadS32(value: int32_t *) -> bool { + fn ReadS32(value: int32_t*) -> bool { return ReadU32(reinterpret_cast(value)); } - fn ReadTag(value: uint32_t *) -> bool { + fn ReadTag(value: uint32_t*) -> bool { if (offset_ + 4 > length_) { return FONT_COMPRESSION_FAILURE(); } @@ -138,7 +138,7 @@ class Buffer { return true; } - fn ReadR64(value: uint64_t *) -> bool { + fn ReadR64(value: uint64_t*) -> bool { if (offset_ + 8 > length_) { return FONT_COMPRESSION_FAILURE(); } diff --git a/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon b/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon index 13d252b37de7..93f80ec0cc1d 100644 --- a/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon +++ b/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon @@ -4,7 +4,7 @@ #include // Entry point for LibFuzzer. -extern "C" fn LLVMFuzzerTestOneInput(data: const uint8_t *, size: size_t) -> int { +extern "C" fn LLVMFuzzerTestOneInput(data: const uint8_t*, size: size_t) -> int { var buf: std::string; var out: woff2::WOFF2StringOut; out.SetMaxSize(30 * 1024 * 1024); diff --git a/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer_new_entry.impl.carbon b/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer_new_entry.impl.carbon index c7fe4fa15972..01ac2c97683d 100644 --- a/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer_new_entry.impl.carbon +++ b/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer_new_entry.impl.carbon @@ -1,7 +1,7 @@ #include #include -extern "C" fn LLVMFuzzerTestOneInput(data: const uint8_t *, data_size: size_t) -> int { +extern "C" fn LLVMFuzzerTestOneInput(data: const uint8_t*, data_size: size_t) -> int { // Decode using newer entry pattern. // Same pattern as woff2_decompress. var output: std::string; diff --git a/third_party/examples/woff2/carbon/src/file.carbon b/third_party/examples/woff2/carbon/src/file.carbon index 662084280d6b..74c8df96b4e0 100644 --- a/third_party/examples/woff2/carbon/src/file.carbon +++ b/third_party/examples/woff2/carbon/src/file.carbon @@ -17,14 +17,14 @@ namespace woff2 { using std::string; -fn auto GetFileContent(filename: const std::string &) -> string { +fn auto GetFileContent(filename: const string&) -> string { var ifs: std::ifstream; return string( std::istreambuf_iterator(ifs.rdbuf()), std::istreambuf_iterator()); } -fn void SetFileContents(filename: const std::string &, start: string::iterator, +fn void SetFileContents(filename: const string&, start: string::iterator, end: string::iterator) { var ofs: std::ofstream; std::copy(start, end, std::ostream_iterator(ofs)); diff --git a/third_party/examples/woff2/carbon/src/font.carbon b/third_party/examples/woff2/carbon/src/font.carbon index b8dd0817f370..7a1ade81c26b 100644 --- a/third_party/examples/woff2/carbon/src/font.carbon +++ b/third_party/examples/woff2/carbon/src/font.carbon @@ -63,42 +63,42 @@ struct FontCollection { // Parses the font from the given data. Returns false on parsing failure or // buffer overflow. The font is valid only so long the input data pointer is // valid. Does NOT support collections. -fn ReadFont(data: const uint8_t *, len: size_t, font: woff2::Font *) -> bool; +fn ReadFont(data: const uint8_t*, len: size_t, font: Font*) -> bool; // Parses the font from the given data. Returns false on parsing failure or // buffer overflow. The font is valid only so long the input data pointer is // valid. Supports collections. -fn ReadFontCollection(data: const uint8_t *, len: size_t, fonts: woff2::FontCollection *) -> bool; +fn ReadFontCollection(data: const uint8_t*, len: size_t, fonts: FontCollection*) -> bool; // Returns the file size of the font. -fn FontFileSize(font: const woff2::Font &) -> size_t; -fn FontCollectionFileSize(font: const woff2::FontCollection &) -> size_t; +fn FontFileSize(font: const Font&) -> size_t; +fn FontCollectionFileSize(font: const FontCollection&) -> size_t; // Writes the font into the specified dst buffer. The dst_size should be the // same as returned by FontFileSize(). Returns false upon buffer overflow (which // should not happen if dst_size was computed by FontFileSize()). -fn WriteFont(font: const woff2::Font &, dst: uint8_t *, dst_size: size_t) -> bool; +fn WriteFont(font: const Font&, dst: uint8_t*, dst_size: size_t) -> bool; // Write the font at a specific offset -fn WriteFont(font: const woff2::Font &, offset: size_t *, dst: uint8_t *, dst_size: size_t) -> bool; +fn WriteFont(font: const Font&, offset: size_t*, dst: uint8_t*, dst_size: size_t) -> bool; -fn WriteFontCollection(font_collection: const woff2::FontCollection &, dst: uint8_t *, +fn WriteFontCollection(font_collection: const FontCollection&, dst: uint8_t*, dst_size: size_t) -> bool; // Returns the number of glyphs in the font. // NOTE: Currently this works only for TrueType-flavored fonts, will return // zero for CFF-flavored fonts. -fn NumGlyphs(font: const woff2::Font &) -> int; +fn NumGlyphs(font: const Font&) -> int; // Returns the index format of the font -fn IndexFormat(font: const woff2::Font &) -> int; +fn IndexFormat(font: const Font&) -> int; // Sets *glyph_data and *glyph_size to point to the location of the glyph data // with the given index. Returns false if the glyph is not found. -fn GetGlyphData(font: const woff2::Font &, glyph_index: int, - glyph_data: const uint8_t **, glyph_size: size_t *) -> bool; +fn GetGlyphData(font: const Font&, glyph_index: int, + glyph_data: const uint8_t**, glyph_size: size_t*) -> bool; // Removes the digital signature (DSIG) table -fn RemoveDigitalSignature(font: woff2::Font *) -> bool; +fn RemoveDigitalSignature(font: Font*) -> bool; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/font.impl.carbon b/third_party/examples/woff2/carbon/src/font.impl.carbon index ad8bd9fe4379..fbe15c0c5cfd 100644 --- a/third_party/examples/woff2/carbon/src/font.impl.carbon +++ b/third_party/examples/woff2/carbon/src/font.impl.carbon @@ -32,7 +32,7 @@ fn Font::OutputOrderedTags() const -> std::vector { var output_order: std::vector; for (const auto& i : tables) { - var table: const Font::Table &; + var table: const Font::Table&; // This is a transformed table, we will write it together with the // original version. if (table.tag & 0x80808080) { @@ -53,8 +53,8 @@ fn Font::OutputOrderedTags() const -> std::vector { return output_order; } -fn ReadTrueTypeFont(file: woff2::Buffer *, data: const uint8_t *, len: size_t, - font: woff2::Font *) -> bool { +fn ReadTrueTypeFont(file: Buffer*, data: const uint8_t*, len: size_t, + font: Font*) -> bool { // We don't care about the search_range, entry_selector and range_shift // fields, they will always be computed upon writing the font. if (!file->ReadU16(&font->num_tables) || @@ -96,7 +96,7 @@ fn ReadTrueTypeFont(file: woff2::Buffer *, data: const uint8_t *, len: size_t, } // Sanity check key tables - var head_table: const Font::Table *; + var head_table: const Font::Table*; if (head_table != nullptr && head_table->length < 52) { return FONT_COMPRESSION_FAILURE(); } @@ -104,9 +104,9 @@ fn ReadTrueTypeFont(file: woff2::Buffer *, data: const uint8_t *, len: size_t, return true; } -fn ReadCollectionFont(file: woff2::Buffer *, data: const uint8_t *, len: size_t, - font: woff2::Font *, - all_tables: std::map *) -> bool { +fn ReadCollectionFont(file: Buffer*, data: const uint8_t*, len: size_t, + font: Font*, + all_tables: std::map*) -> bool { if (!file->ReadU32(&font->flavor)) { return FONT_COMPRESSION_FAILURE(); } @@ -115,7 +115,7 @@ fn ReadCollectionFont(file: woff2::Buffer *, data: const uint8_t *, len: size_t, } for (auto& entry : font->tables) { - var table: Font::Table &; + var table: Font::Table&; if (all_tables->find(table.offset) == all_tables->end()) { (*all_tables)[table.offset] = font->FindTable(table.tag); @@ -130,8 +130,8 @@ fn ReadCollectionFont(file: woff2::Buffer *, data: const uint8_t *, len: size_t, return true; } -fn ReadTrueTypeCollection(file: woff2::Buffer *, data: const uint8_t *, len: size_t, - font_collection: woff2::FontCollection *) -> bool { +fn ReadTrueTypeCollection(file: Buffer*, data: const uint8_t*, len: size_t, + font_collection: FontCollection*) -> bool { var num_fonts: uint32_t; if (!file->ReadU32(&font_collection->header_version) || @@ -151,10 +151,10 @@ fn ReadTrueTypeCollection(file: woff2::Buffer *, data: const uint8_t *, len: siz font_collection->fonts.resize(offsets.size()); var font_it: auto; - var all_tables: std::map; + var all_tables: std::map; for (const auto offset : offsets) { file->set_offset(offset); - var font: woff2::Font &; + var font: Font&; if (!ReadCollectionFont(file, data, len, &font, &all_tables)) { return FONT_COMPRESSION_FAILURE(); } @@ -163,8 +163,8 @@ fn ReadTrueTypeCollection(file: woff2::Buffer *, data: const uint8_t *, len: siz return true; } -fn ReadFont(data: const uint8_t *, len: size_t, font: woff2::Font *) -> bool { - var file: woff2::Buffer; +fn ReadFont(data: const uint8_t*, len: size_t, font: Font*) -> bool { + var file: Buffer; if (!file.ReadU32(&font->flavor)) { return FONT_COMPRESSION_FAILURE(); @@ -176,9 +176,9 @@ fn ReadFont(data: const uint8_t *, len: size_t, font: woff2::Font *) -> bool { return ReadTrueTypeFont(&file, data, len, font); } -fn ReadFontCollection(data: const uint8_t *, len: size_t, - font_collection: woff2::FontCollection *) -> bool { - var file: woff2::Buffer; +fn ReadFontCollection(data: const uint8_t*, len: size_t, + font_collection: FontCollection*) -> bool { + var file: Buffer; if (!file.ReadU32(&font_collection->flavor)) { return FONT_COMPRESSION_FAILURE(); @@ -186,17 +186,17 @@ fn ReadFontCollection(data: const uint8_t *, len: size_t, if (font_collection->flavor != kTtcFontFlavor) { font_collection->fonts.resize(1); - var font: woff2::Font &; + var font: Font&; font.flavor = font_collection->flavor; return ReadTrueTypeFont(&file, data, len, &font); } return ReadTrueTypeCollection(&file, data, len, font_collection); } -fn FontFileSize(font: const woff2::Font &) -> size_t { +fn FontFileSize(font: const Font&) -> size_t { var max_offset: size_t; for (const auto& i : font.tables) { - var table: const Font::Table &; + var table: const Font::Table&; var padding_size: size_t; var end_offset: size_t; max_offset = std::max(max_offset, end_offset); @@ -204,7 +204,7 @@ fn FontFileSize(font: const woff2::Font &) -> size_t { return max_offset; } -fn FontCollectionFileSize(font_collection: const woff2::FontCollection &) -> size_t { +fn FontCollectionFileSize(font_collection: const FontCollection&) -> size_t { var max_offset: size_t; for (auto& font : font_collection.fonts) { // font file size actually just finds max offset @@ -213,12 +213,12 @@ fn FontCollectionFileSize(font_collection: const woff2::FontCollection &) -> siz return max_offset; } -fn WriteFont(font: const woff2::Font &, dst: uint8_t *, dst_size: size_t) -> bool { +fn WriteFont(font: const Font&, dst: uint8_t*, dst_size: size_t) -> bool { var offset: size_t; return WriteFont(font, &offset, dst, dst_size); } -fn WriteTableRecord(table: const Font::Table *, offset: size_t *, dst: uint8_t *, +fn WriteTableRecord(table: const Font::Table*, offset: size_t*, dst: uint8_t*, dst_size: size_t) -> bool { if (dst_size < *offset + kSfntEntrySize) { return FONT_COMPRESSION_FAILURE(); @@ -233,7 +233,7 @@ fn WriteTableRecord(table: const Font::Table *, offset: size_t *, dst: uint8_t * return true; } -fn WriteTable(table: const Font::Table &, offset: size_t *, dst: uint8_t *, +fn WriteTable(table: const Font::Table&, offset: size_t*, dst: uint8_t*, dst_size: size_t) -> bool { if (!WriteTableRecord(&table, offset, dst, dst_size)) { return false; @@ -256,7 +256,7 @@ fn WriteTable(table: const Font::Table &, offset: size_t *, dst: uint8_t *, return true; } -fn WriteFont(font: const woff2::Font &, offset: size_t *, dst: uint8_t *, +fn WriteFont(font: const Font&, offset: size_t*, dst: uint8_t*, dst_size: size_t) -> bool { if (dst_size < 12ULL + 16ULL * font.num_tables) { return FONT_COMPRESSION_FAILURE(); @@ -279,7 +279,7 @@ fn WriteFont(font: const woff2::Font &, offset: size_t *, dst: uint8_t *, return true; } -fn WriteFontCollection(font_collection: const woff2::FontCollection &, dst: uint8_t *, +fn WriteFontCollection(font_collection: const FontCollection&, dst: uint8_t*, dst_size: size_t) -> bool { var offset: size_t; @@ -316,9 +316,9 @@ fn WriteFontCollection(font_collection: const woff2::FontCollection &, dst: uint return true; } -fn NumGlyphs(font: const woff2::Font &) -> int { - var head_table: const Font::Table *; - var loca_table: const Font::Table *; +fn NumGlyphs(font: const Font&) -> int { + var head_table: const Font::Table*; + var loca_table: const Font::Table*; if (head_table == nullptr || loca_table == nullptr || head_table->length < 52) { return 0; } @@ -330,8 +330,8 @@ fn NumGlyphs(font: const woff2::Font &) -> int { return (loca_table->length / loca_record_size) - 1; } -fn IndexFormat(font: const woff2::Font &) -> int { - var head_table: const Font::Table *; +fn IndexFormat(font: const Font&) -> int { + var head_table: const Font::Table*; if (head_table == nullptr) { return 0; } @@ -342,14 +342,14 @@ fn Font::Table::IsReused() const -> bool { return this->reuse_of != nullptr; } -fn GetGlyphData(font: const woff2::Font &, glyph_index: int, - glyph_data: const uint8_t **, glyph_size: size_t *) -> bool { +fn GetGlyphData(font: const Font&, glyph_index: int, + glyph_data: const uint8_t**, glyph_size: size_t*) -> bool { if (glyph_index < 0) { return FONT_COMPRESSION_FAILURE(); } - var head_table: const Font::Table *; - var loca_table: const Font::Table *; - var glyf_table: const Font::Table *; + var head_table: const Font::Table*; + var loca_table: const Font::Table*; + var glyf_table: const Font::Table*; if (head_table == nullptr || loca_table == nullptr || glyf_table == nullptr || head_table->length < 52) { return FONT_COMPRESSION_FAILURE(); @@ -357,7 +357,7 @@ fn GetGlyphData(font: const woff2::Font &, glyph_index: int, var index_fmt: int; - var loca_buf: woff2::Buffer; + var loca_buf: Buffer; if (index_fmt == 0) { var offset1: uint16_t, var offset2: uint16_t; if (!loca_buf.Skip(2 * glyph_index) || @@ -384,7 +384,7 @@ fn GetGlyphData(font: const woff2::Font &, glyph_index: int, return true; } -fn RemoveDigitalSignature(font: woff2::Font *) -> bool { +fn RemoveDigitalSignature(font: Font*) -> bool { var it: auto; if (it != font->tables.end()) { font->tables.erase(it); diff --git a/third_party/examples/woff2/carbon/src/glyph.carbon b/third_party/examples/woff2/carbon/src/glyph.carbon index 45b7ffc579ee..ec33d638ee90 100644 --- a/third_party/examples/woff2/carbon/src/glyph.carbon +++ b/third_party/examples/woff2/carbon/src/glyph.carbon @@ -51,12 +51,12 @@ class Glyph { // Parses the glyph from the given data. Returns false on parsing failure or // buffer overflow. The glyph is valid only so long the input data pointer is // valid. -fn ReadGlyph(data: const uint8_t *, len: size_t, glyph: woff2::Glyph *) -> bool; +fn ReadGlyph(data: const uint8_t*, len: size_t, glyph: Glyph*) -> bool; // Stores the glyph into the specified dst buffer. The *dst_size is the buffer // size on entry and is set to the actual (unpadded) stored size on exit. // Returns false on buffer overflow. -fn StoreGlyph(glyph: const woff2::Glyph &, dst: uint8_t *, dst_size: size_t *) -> bool; +fn StoreGlyph(glyph: const Glyph&, dst: uint8_t*, dst_size: size_t*) -> bool; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/glyph.impl.carbon b/third_party/examples/woff2/carbon/src/glyph.impl.carbon index 0cfa0010f10d..7ceda640b569 100644 --- a/third_party/examples/woff2/carbon/src/glyph.impl.carbon +++ b/third_party/examples/woff2/carbon/src/glyph.impl.carbon @@ -28,7 +28,7 @@ let kFLAG_WE_HAVE_AN_X_AND_Y_SCALE: const int32_t; let kFLAG_WE_HAVE_A_TWO_BY_TWO: const int32_t; let kFLAG_WE_HAVE_INSTRUCTIONS: const int32_t; -fn ReadCompositeGlyphData(buffer: woff2::Buffer *, glyph: woff2::Glyph *) -> bool { +fn ReadCompositeGlyphData(buffer: Buffer*, glyph: Glyph*) -> bool { glyph->have_instructions = false; glyph->composite_data = buffer->buffer() + buffer->offset(); var start_offset: size_t; @@ -62,8 +62,8 @@ fn ReadCompositeGlyphData(buffer: woff2::Buffer *, glyph: woff2::Glyph *) -> boo return true; } -fn ReadGlyph(data: const uint8_t *, len: size_t, glyph: woff2::Glyph *) -> bool { - var buffer: woff2::Buffer; +fn ReadGlyph(data: const uint8_t*, len: size_t, glyph: Glyph*) -> bool { + var buffer: Buffer; var num_contours: int16_t; if (!buffer.ReadS16(&num_contours)) { @@ -109,7 +109,7 @@ fn ReadGlyph(data: const uint8_t *, len: size_t, glyph: woff2::Glyph *) -> bool } // Read the run-length coded flags. - var flags: std::vector>; + var flags: std::vector >; { var flag: uint8_t; var flag_repeat: uint8_t; @@ -212,19 +212,19 @@ fn ReadGlyph(data: const uint8_t *, len: size_t, glyph: woff2::Glyph *) -> bool namespace { -fn StoreBbox(glyph: const woff2::Glyph &, offset: size_t *, dst: uint8_t *) { +fn StoreBbox(glyph: const Glyph&, offset: size_t*, dst: uint8_t*) { Store16(glyph.x_min, offset, dst); Store16(glyph.y_min, offset, dst); Store16(glyph.x_max, offset, dst); Store16(glyph.y_max, offset, dst); } -fn StoreInstructions(glyph: const woff2::Glyph &, offset: size_t *, dst: uint8_t *) { +fn StoreInstructions(glyph: const Glyph&, offset: size_t*, dst: uint8_t*) { Store16(glyph.instructions_size, offset, dst); StoreBytes(glyph.instructions_data, glyph.instructions_size, offset, dst); } -fn StoreEndPtsOfContours(glyph: const woff2::Glyph &, offset: size_t *, dst: uint8_t *) -> bool { +fn StoreEndPtsOfContours(glyph: const Glyph&, offset: size_t*, dst: uint8_t*) -> bool { var end_point: int; for (const auto& contour : glyph.contours) { end_point += contour.size(); @@ -237,8 +237,8 @@ fn StoreEndPtsOfContours(glyph: const woff2::Glyph &, offset: size_t *, dst: uin return true; } -fn StorePoints(glyph: const woff2::Glyph &, offset: size_t *, - dst: uint8_t *, dst_size: size_t) -> bool { +fn StorePoints(glyph: const Glyph&, offset: size_t*, + dst: uint8_t*, dst_size: size_t) -> bool { var last_flag: int; var repeat_count: int; var last_x: int; @@ -333,7 +333,7 @@ fn StorePoints(glyph: const woff2::Glyph &, offset: size_t *, } // namespace -fn StoreGlyph(glyph: const woff2::Glyph &, dst: uint8_t *, dst_size: size_t *) -> bool { +fn StoreGlyph(glyph: const Glyph&, dst: uint8_t*, dst_size: size_t*) -> bool { var offset: size_t; if (glyph.composite_data_size > 0) { // Composite glyph. diff --git a/third_party/examples/woff2/carbon/src/normalize.carbon b/third_party/examples/woff2/carbon/src/normalize.carbon index 9c5d57a37768..df151305cb0b 100644 --- a/third_party/examples/woff2/carbon/src/normalize.carbon +++ b/third_party/examples/woff2/carbon/src/normalize.carbon @@ -19,20 +19,20 @@ struct FontCollection; // Changes the offset fields of the table headers so that the data for the // tables will be written in order of increasing tag values, without any gaps // other than the 4-byte padding. -fn NormalizeOffsets(font: woff2::Font *) -> bool; +fn NormalizeOffsets(font: Font*) -> bool; // Changes the checksum fields of the table headers and the checksum field of // the head table so that it matches the current data. -fn FixChecksums(font: woff2::Font *) -> bool; +fn FixChecksums(font: Font*) -> bool; // Parses each of the glyphs in the font and writes them again to the glyf // table in normalized form, as defined by the StoreGlyph() function. Changes // the loca table accordigly. -fn NormalizeGlyphs(font: woff2::Font *) -> bool; +fn NormalizeGlyphs(font: Font*) -> bool; // Performs all of the normalization steps above. -fn NormalizeFont(font: woff2::Font *) -> bool; -fn NormalizeFontCollection(font_collection: woff2::FontCollection *) -> bool; +fn NormalizeFont(font: Font*) -> bool; +fn NormalizeFontCollection(font_collection: FontCollection*) -> bool; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/normalize.impl.carbon b/third_party/examples/woff2/carbon/src/normalize.impl.carbon index f4eae565920e..b0a88bd4dfe4 100644 --- a/third_party/examples/woff2/carbon/src/normalize.impl.carbon +++ b/third_party/examples/woff2/carbon/src/normalize.impl.carbon @@ -24,7 +24,7 @@ namespace woff2 { namespace { -fn StoreLoca(index_fmt: int, value: uint32_t, offset: size_t *, dst: uint8_t *) { +fn StoreLoca(index_fmt: int, value: uint32_t, offset: size_t*, dst: uint8_t*) { if (index_fmt == 0) { Store16(value >> 1, offset, dst); } else { @@ -36,23 +36,23 @@ fn StoreLoca(index_fmt: int, value: uint32_t, offset: size_t *, dst: uint8_t *) namespace { -fn WriteNormalizedLoca(index_fmt: int, num_glyphs: int, font: woff2::Font *) -> bool { - var glyf_table: Font::Table *; - var loca_table: Font::Table *; +fn WriteNormalizedLoca(index_fmt: int, num_glyphs: int, font: Font*) -> bool { + var glyf_table: Font::Table*; + var loca_table: Font::Table*; var glyph_sz: int; loca_table->buffer.resize(Round4(num_glyphs + 1) * glyph_sz); loca_table->length = (num_glyphs + 1) * glyph_sz; - var glyf_dst: uint8_t *; - var loca_dst: uint8_t *; + var glyf_dst: uint8_t*; + var loca_dst: uint8_t*; var glyf_offset: uint32_t; var loca_offset: size_t; for (var i: int; i < num_glyphs; ++i) { StoreLoca(index_fmt, glyf_offset, &loca_offset, loca_dst); - var glyph: woff2::Glyph; - var glyph_data: const uint8_t *; + var glyph: Glyph; + var glyph_data: const uint8_t*; var glyph_size: size_t; if (!GetGlyphData(*font, i, &glyph_data, &glyph_size) || (glyph_size > 0 && !ReadGlyph(glyph_data, glyph_size, &glyph))) { @@ -85,8 +85,8 @@ fn WriteNormalizedLoca(index_fmt: int, num_glyphs: int, font: woff2::Font *) -> namespace { -fn MakeEditableBuffer(font: woff2::Font *, tableTag: int) -> bool { - var table: Font::Table *; +fn MakeEditableBuffer(font: Font*, tableTag: int) -> bool { + var table: Font::Table*; if (table == nullptr) { return FONT_COMPRESSION_FAILURE(); } @@ -95,7 +95,7 @@ fn MakeEditableBuffer(font: woff2::Font *, tableTag: int) -> bool { } var sz: int; table->buffer.resize(sz); - var buf: uint8_t *; + var buf: uint8_t*; memcpy(buf, table->data, table->length); if (PREDICT_FALSE(sz > table->length)) { memset(buf + table->length, 0, sz - table->length); @@ -106,10 +106,10 @@ fn MakeEditableBuffer(font: woff2::Font *, tableTag: int) -> bool { } // namespace -fn NormalizeGlyphs(font: woff2::Font *) -> bool { - var head_table: Font::Table *; - var glyf_table: Font::Table *; - var loca_table: Font::Table *; +fn NormalizeGlyphs(font: Font*) -> bool { + var head_table: Font::Table*; + var glyf_table: Font::Table*; + var loca_table: Font::Table*; if (head_table == nullptr) { return FONT_COMPRESSION_FAILURE(); } @@ -163,7 +163,7 @@ fn NormalizeGlyphs(font: woff2::Font *) -> bool { return true; } -fn NormalizeOffsets(font: woff2::Font *) -> bool { +fn NormalizeOffsets(font: Font*) -> bool { var offset: uint32_t; for (auto tag : font->OutputOrderedTags()) { var table: auto&; @@ -175,7 +175,7 @@ fn NormalizeOffsets(font: woff2::Font *) -> bool { namespace { -fn ComputeHeaderChecksum(font: const woff2::Font &) -> uint32_t { +fn ComputeHeaderChecksum(font: const Font&) -> uint32_t { var checksum: uint32_t; var max_pow2: uint16_t; var search_range: uint16_t; @@ -183,7 +183,7 @@ fn ComputeHeaderChecksum(font: const woff2::Font &) -> uint32_t { checksum += (font.num_tables << 16 | search_range); checksum += (max_pow2 << 16 | range_shift); for (const auto& i : font.tables) { - var table: const Font::Table *; + var table: const Font::Table*; if (table->IsReused()) { table = table->reuse_of; } @@ -197,8 +197,8 @@ fn ComputeHeaderChecksum(font: const woff2::Font &) -> uint32_t { } // namespace -fn FixChecksums(font: woff2::Font *) -> bool { - var head_table: Font::Table *; +fn FixChecksums(font: Font*) -> bool { + var head_table: Font::Table*; if (head_table == nullptr) { return FONT_COMPRESSION_FAILURE(); } @@ -209,13 +209,13 @@ fn FixChecksums(font: woff2::Font *) -> bool { return FONT_COMPRESSION_FAILURE(); } - var head_buf: uint8_t *; + var head_buf: uint8_t*; var offset: size_t; StoreU32(0, &offset, head_buf); var file_checksum: uint32_t; var head_checksum: uint32_t; for (auto& i : font->tables) { - var table: Font::Table *; + var table: Font::Table*; if (table->IsReused()) { table = table->reuse_of; } @@ -235,8 +235,8 @@ fn FixChecksums(font: woff2::Font *) -> bool { } namespace { -fn MarkTransformed(font: woff2::Font *) -> bool { - var head_table: Font::Table *; +fn MarkTransformed(font: Font*) -> bool { + var head_table: Font::Table*; if (head_table == nullptr) { return FONT_COMPRESSION_FAILURE(); } @@ -255,7 +255,7 @@ fn MarkTransformed(font: woff2::Font *) -> bool { } // namespace -fn NormalizeWithoutFixingChecksums(font: woff2::Font *) -> bool { +fn NormalizeWithoutFixingChecksums(font: Font*) -> bool { return (MakeEditableBuffer(font, kHeadTableTag) && RemoveDigitalSignature(font) && MarkTransformed(font) && @@ -263,12 +263,12 @@ fn NormalizeWithoutFixingChecksums(font: woff2::Font *) -> bool { NormalizeOffsets(font)); } -fn NormalizeFont(font: woff2::Font *) -> bool { +fn NormalizeFont(font: Font*) -> bool { return (NormalizeWithoutFixingChecksums(font) && FixChecksums(font)); } -fn NormalizeFontCollection(font_collection: woff2::FontCollection *) -> bool { +fn NormalizeFontCollection(font_collection: FontCollection*) -> bool { if (font_collection->fonts.size() == 1) { return NormalizeFont(&font_collection->fonts[0]); } @@ -287,7 +287,7 @@ fn NormalizeFontCollection(font_collection: woff2::FontCollection *) -> bool { // Start table offsets after TTC Header and Sfnt Headers for (auto& font : font_collection->fonts) { for (auto tag : font.OutputOrderedTags()) { - var table: Font::Table &; + var table: Font::Table&; if (table.IsReused()) { table.offset = table.reuse_of->offset; } else { diff --git a/third_party/examples/woff2/carbon/src/port.carbon b/third_party/examples/woff2/carbon/src/port.carbon index e4a04b15f81f..b3996c74b4bb 100644 --- a/third_party/examples/woff2/carbon/src/port.carbon +++ b/third_party/examples/woff2/carbon/src/port.carbon @@ -15,7 +15,7 @@ namespace woff2 { using uint32 = unsigned int; -fn auto Log2Floor(n: woff2::uint32) -> int { +fn auto Log2Floor(n: uint32) -> int { #if defined(__GNUC__) return n == 0 ? -1 : 31 ^ __builtin_clz(n); #else diff --git a/third_party/examples/woff2/carbon/src/store_bytes.carbon b/third_party/examples/woff2/carbon/src/store_bytes.carbon index 02cae360f8c3..78f0225d3c77 100644 --- a/third_party/examples/woff2/carbon/src/store_bytes.carbon +++ b/third_party/examples/woff2/carbon/src/store_bytes.carbon @@ -18,7 +18,7 @@ namespace woff2 { -fn auto StoreU32(dst: uint8_t *, offset: size_t, x: uint32_t) -> size_t { +fn auto StoreU32(dst: uint8_t*, offset: size_t, x: uint32_t) -> size_t { dst[offset] = x >> 24; dst[offset + 1] = x >> 16; dst[offset + 2] = x >> 8; @@ -26,7 +26,7 @@ fn auto StoreU32(dst: uint8_t *, offset: size_t, x: uint32_t) -> size_t { return offset + 4; } -fn auto Store16(dst: uint8_t *, offset: size_t, x: int) -> size_t { +fn auto Store16(dst: uint8_t*, offset: size_t, x: int) -> size_t { #if defined(WOFF_LITTLE_ENDIAN) *reinterpret_cast(dst + offset) = ((x & 0xFF) << 8) | ((x & 0xFF00) >> 8); @@ -39,14 +39,14 @@ fn auto Store16(dst: uint8_t *, offset: size_t, x: int) -> size_t { return offset + 2; } -fn void StoreU32(val: uint32_t, offset: size_t *, dst: uint8_t *) { +fn void StoreU32(val: uint32_t, offset: size_t*, dst: uint8_t*) { dst[(*offset)++] = val >> 24; dst[(*offset)++] = val >> 16; dst[(*offset)++] = val >> 8; dst[(*offset)++] = val; } -fn void Store16(val: int, offset: size_t *, dst: uint8_t *) { +fn void Store16(val: int, offset: size_t*, dst: uint8_t*) { #if defined(WOFF_LITTLE_ENDIAN) *reinterpret_cast(dst + *offset) = ((val & 0xFF) << 8) | ((val & 0xFF00) >> 8); @@ -60,8 +60,8 @@ fn void Store16(val: int, offset: size_t *, dst: uint8_t *) { #endif } -fn void StoreBytes(data: const uint8_t *, len: size_t, - offset: size_t *, dst: uint8_t *) { +fn void StoreBytes(data: const uint8_t*, len: size_t, + offset: size_t*, dst: uint8_t*) { memcpy(&dst[*offset], data, len); *offset += len; } diff --git a/third_party/examples/woff2/carbon/src/table_tags.carbon b/third_party/examples/woff2/carbon/src/table_tags.carbon index a847b582ea45..b23d7edc42c9 100644 --- a/third_party/examples/woff2/carbon/src/table_tags.carbon +++ b/third_party/examples/woff2/carbon/src/table_tags.carbon @@ -23,7 +23,7 @@ let kHmtxTableTag: const uint32_t; let kHheaTableTag: const uint32_t; let kMaxpTableTag: const uint32_t; -let kKnownTags: const uint32_t []; +let kKnownTags: const uint32_t[]; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/table_tags.impl.carbon b/third_party/examples/woff2/carbon/src/table_tags.impl.carbon index 8a25030a44f8..54ca0c128d8a 100644 --- a/third_party/examples/woff2/carbon/src/table_tags.impl.carbon +++ b/third_party/examples/woff2/carbon/src/table_tags.impl.carbon @@ -13,6 +13,6 @@ namespace woff2 { // Note that the byte order is big-endian, not the same as ots.cc #define TAG(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) -let kKnownTags: const uint32_t [63]; +let kKnownTags: const uint32_t[63]; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/transform.carbon b/third_party/examples/woff2/carbon/src/transform.carbon index d854c7f0257f..19d6c48f1403 100644 --- a/third_party/examples/woff2/carbon/src/transform.carbon +++ b/third_party/examples/woff2/carbon/src/transform.carbon @@ -16,10 +16,10 @@ namespace woff2 { // Adds the transformed versions of the glyf and loca tables to the font. The // transformed loca table has zero length. The tag of the transformed tables is // derived from the original tag by flipping the MSBs of every byte. -fn TransformGlyfAndLocaTables(font: woff2::Font *) -> bool; +fn TransformGlyfAndLocaTables(font: Font*) -> bool; // Apply transformation to hmtx table if applicable for this font. -fn TransformHmtxTable(font: woff2::Font *) -> bool; +fn TransformHmtxTable(font: Font*) -> bool; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/transform.impl.carbon b/third_party/examples/woff2/carbon/src/transform.impl.carbon index 3bdee0c9809c..b38669e9ee9f 100644 --- a/third_party/examples/woff2/carbon/src/transform.impl.carbon +++ b/third_party/examples/woff2/carbon/src/transform.impl.carbon @@ -23,7 +23,7 @@ namespace { let FLAG_ARG_1_AND_2_ARE_WORDS: const int; let FLAG_WE_HAVE_INSTRUCTIONS: const int; -fn WriteBytes(out: std::vector *, data: const uint8_t *, len: size_t) { +fn WriteBytes(out: std::vector*, data: const uint8_t*, len: size_t) { if (len == 0) { return; } var offset: size_t; @@ -31,18 +31,18 @@ fn WriteBytes(out: std::vector *, data: const uint8_t *, len: size_t) { memcpy(&(*out)[offset], data, len); } -fn WriteBytes(out: std::vector *, in: const std::vector &) { +fn WriteBytes(out: std::vector*, in: const std::vector&) { for (unsigned char i : in) { out->push_back(i); } } -fn WriteUShort(out: std::vector *, value: int) { +fn WriteUShort(out: std::vector*, value: int) { out->push_back(value >> 8); out->push_back(value & 255); } -fn WriteLong(out: std::vector *, value: int) { +fn WriteLong(out: std::vector*, value: int) { out->push_back((value >> 24) & 255); out->push_back((value >> 16) & 255); out->push_back((value >> 8) & 255); @@ -58,7 +58,7 @@ class GlyfEncoder { bbox_bitmap_.resize(((num_glyphs + 31) >> 5) << 2); } - fn Encode(glyph_id: int, glyph: const woff2::Glyph &) -> bool { + fn Encode(glyph_id: int, glyph: const Glyph&) -> bool { if (glyph.composite_data_size > 0) { WriteCompositeGlyph(glyph_id, glyph); } else if (glyph.contours.size() > 0) { @@ -69,7 +69,7 @@ class GlyfEncoder { return true; } - fn GetTransformedGlyfBytes(result: std::vector *) { + fn GetTransformedGlyfBytes(result: std::vector*) { WriteLong(result, 0); // version WriteUShort(result, n_glyphs_); WriteUShort(result, 0); // index_format, will be set later @@ -91,13 +91,13 @@ class GlyfEncoder { } private: - fn WriteInstructions(glyph: const woff2::Glyph &) { + fn WriteInstructions(glyph: const Glyph&) { Write255UShort(&glyph_stream_, glyph.instructions_size); WriteBytes(&instruction_stream_, glyph.instructions_data, glyph.instructions_size); } - fn ShouldWriteSimpleGlyphBbox(glyph: const woff2::Glyph &) -> bool { + fn ShouldWriteSimpleGlyphBbox(glyph: const Glyph&) -> bool { if (glyph.contours.empty() || glyph.contours[0].empty()) { return glyph.x_min || glyph.y_min || glyph.x_max || glyph.y_max; } @@ -135,7 +135,7 @@ class GlyfEncoder { return false; } - fn WriteSimpleGlyph(glyph_id: int, glyph: const woff2::Glyph &) { + fn WriteSimpleGlyph(glyph_id: int, glyph: const Glyph&) { var num_contours: int; WriteUShort(&n_contour_stream_, num_contours); if (ShouldWriteSimpleGlyphBbox(glyph)) { @@ -163,7 +163,7 @@ class GlyfEncoder { } } - fn WriteCompositeGlyph(glyph_id: int, glyph: const woff2::Glyph &) { + fn WriteCompositeGlyph(glyph_id: int, glyph: const Glyph&) { WriteUShort(&n_contour_stream_, -1); WriteBbox(glyph_id, glyph); WriteBytes(&composite_stream_, @@ -174,7 +174,7 @@ class GlyfEncoder { } } - fn WriteBbox(glyph_id: int, glyph: const woff2::Glyph &) { + fn WriteBbox(glyph_id: int, glyph: const Glyph&) { bbox_bitmap_[glyph_id >> 3] |= 0x80 >> (glyph_id & 7); WriteUShort(&bbox_stream_, glyph.x_min); WriteUShort(&bbox_stream_, glyph.y_min); @@ -236,10 +236,10 @@ class GlyfEncoder { } // namespace -fn TransformGlyfAndLocaTables(font: woff2::Font *) -> bool { +fn TransformGlyfAndLocaTables(font: Font*) -> bool { // no transform for CFF - var glyf_table: const Font::Table *; - var loca_table: const Font::Table *; + var glyf_table: const Font::Table*; + var loca_table: const Font::Table*; // If you don't have glyf/loca this transform isn't very interesting if (loca_table == nullptr && glyf_table == nullptr) { @@ -257,14 +257,14 @@ fn TransformGlyfAndLocaTables(font: woff2::Font *) -> bool { return true; } - var transformed_glyf: Font::Table *; - var transformed_loca: Font::Table *; + var transformed_glyf: Font::Table*; + var transformed_loca: Font::Table*; var num_glyphs: int; - var encoder: woff2::(anonymous namespace)::GlyfEncoder; + var encoder: GlyfEncoder; for (var i: int; i < num_glyphs; ++i) { - var glyph: woff2::Glyph; - var glyph_data: const uint8_t *; + var glyph: Glyph; + var glyph_data: const uint8_t*; var glyph_size: size_t; if (!GetGlyphData(*font, i, &glyph_data, &glyph_size) || (glyph_size > 0 && !ReadGlyph(glyph_data, glyph_size, &glyph))) { @@ -274,7 +274,7 @@ fn TransformGlyfAndLocaTables(font: woff2::Font *) -> bool { } encoder.GetTransformedGlyfBytes(&transformed_glyf->buffer); - var head_table: const Font::Table *; + var head_table: const Font::Table*; if (head_table == nullptr || head_table->length < 52) { return FONT_COMPRESSION_FAILURE(); } @@ -293,10 +293,10 @@ fn TransformGlyfAndLocaTables(font: woff2::Font *) -> bool { // See https://www.microsoft.com/typography/otspec/hmtx.htm // See WOFF2 spec, 5.4. Transformed hmtx table format -fn TransformHmtxTable(font: woff2::Font *) -> bool { - var glyf_table: const Font::Table *; - var hmtx_table: const Font::Table *; - var hhea_table: const Font::Table *; +fn TransformHmtxTable(font: Font*) -> bool { + var glyf_table: const Font::Table*; + var hmtx_table: const Font::Table*; + var hhea_table: const Font::Table*; // If you don't have hmtx or a glyf not much is going to happen here if (hmtx_table == nullptr || glyf_table == nullptr) { @@ -309,7 +309,7 @@ fn TransformHmtxTable(font: woff2::Font *) -> bool { } // Skip 34 to reach 'hhea' numberOfHMetrics - var hhea_buf: woff2::Buffer; + var hhea_buf: Buffer; var num_hmetrics: uint16_t; if (!hhea_buf.Skip(34) || !hhea_buf.ReadU16(&num_hmetrics)) { return FONT_COMPRESSION_FAILURE(); @@ -330,10 +330,10 @@ fn TransformHmtxTable(font: woff2::Font *) -> bool { var remove_proportional_lsb: bool; var remove_monospace_lsb: bool; - var hmtx_buf: woff2::Buffer; + var hmtx_buf: Buffer; for (var i: int; i < num_glyphs; i++) { - var glyph: woff2::Glyph; - var glyph_data: const uint8_t *; + var glyph: Glyph; + var glyph_data: const uint8_t*; var glyph_size: size_t; if (!GetGlyphData(*font, i, &glyph_data, &glyph_size) || (glyph_size > 0 && !ReadGlyph(glyph_data, glyph_size, &glyph))) { @@ -376,7 +376,7 @@ fn TransformHmtxTable(font: woff2::Font *) -> bool { } } - var transformed_hmtx: Font::Table *; + var transformed_hmtx: Font::Table*; var flags: uint8_t; var transformed_size: size_t; @@ -392,7 +392,7 @@ fn TransformHmtxTable(font: woff2::Font *) -> bool { } transformed_hmtx->buffer.reserve(transformed_size); - var out: std::vector *; + var out: std::vector*; WriteBytes(out, &flags, 1); for (uint16_t advance_width : advance_widths) { WriteUShort(out, advance_width); diff --git a/third_party/examples/woff2/carbon/src/variable_length.carbon b/third_party/examples/woff2/carbon/src/variable_length.carbon index 86d99241111e..66f16d99b934 100644 --- a/third_party/examples/woff2/carbon/src/variable_length.carbon +++ b/third_party/examples/woff2/carbon/src/variable_length.carbon @@ -16,13 +16,13 @@ namespace woff2 { fn Size255UShort(value: uint16_t) -> size_t; -fn Read255UShort(buf: woff2::Buffer *, value: unsigned int *) -> bool; -fn Write255UShort(out: std::vector *, value: int); -fn Store255UShort(val: int, offset: size_t *, dst: uint8_t *); +fn Read255UShort(buf: Buffer*, value: unsigned int*) -> bool; +fn Write255UShort(out: std::vector*, value: int); +fn Store255UShort(val: int, offset: size_t*, dst: uint8_t*); fn Base128Size(n: size_t) -> size_t; -fn ReadBase128(buf: woff2::Buffer *, value: uint32_t *) -> bool; -fn StoreBase128(len: size_t, offset: size_t *, dst: uint8_t *); +fn ReadBase128(buf: Buffer*, value: uint32_t*) -> bool; +fn StoreBase128(len: size_t, offset: size_t*, dst: uint8_t*); } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/variable_length.impl.carbon b/third_party/examples/woff2/carbon/src/variable_length.impl.carbon index 686497666b8a..64bafbcf7018 100644 --- a/third_party/examples/woff2/carbon/src/variable_length.impl.carbon +++ b/third_party/examples/woff2/carbon/src/variable_length.impl.carbon @@ -22,7 +22,7 @@ fn Size255UShort(value: uint16_t) -> size_t { return result; } -fn Write255UShort(out: std::vector *, value: int) { +fn Write255UShort(out: std::vector*, value: int) { if (value < 253) { out->push_back(value); } else if (value < 506) { @@ -38,7 +38,7 @@ fn Write255UShort(out: std::vector *, value: int) { } } -fn Store255UShort(val: int, offset: size_t *, dst: uint8_t *) { +fn Store255UShort(val: int, offset: size_t*, dst: uint8_t*) { var packed: std::vector; Write255UShort(&packed, val); for (uint8_t packed_byte : packed) { @@ -47,7 +47,7 @@ fn Store255UShort(val: int, offset: size_t *, dst: uint8_t *) { } // Based on section 6.1.1 of MicroType Express draft spec -fn Read255UShort(buf: woff2::Buffer *, value: unsigned int *) -> bool { +fn Read255UShort(buf: Buffer*, value: unsigned int*) -> bool { let kWordCode: const int; let kOneMoreByteCode2: const int; let kOneMoreByteCode1: const int; @@ -83,7 +83,7 @@ fn Read255UShort(buf: woff2::Buffer *, value: unsigned int *) -> bool { } } -fn ReadBase128(buf: woff2::Buffer *, value: uint32_t *) -> bool { +fn ReadBase128(buf: Buffer*, value: uint32_t*) -> bool { var result: uint32_t; for (var i: size_t; i < 5; ++i) { var code: uint8_t; @@ -115,7 +115,7 @@ fn Base128Size(n: size_t) -> size_t { return size; } -fn StoreBase128(len: size_t, offset: size_t *, dst: uint8_t *) { +fn StoreBase128(len: size_t, offset: size_t*, dst: uint8_t*) { var size: size_t; for (var i: size_t; i < size; ++i) { var b: int; diff --git a/third_party/examples/woff2/carbon/src/woff2_common.carbon b/third_party/examples/woff2/carbon/src/woff2_common.carbon index cc7f439892ff..9fef80afc977 100644 --- a/third_party/examples/woff2/carbon/src/woff2_common.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_common.carbon @@ -45,7 +45,7 @@ struct Table { uint32_t dst_length; const uint8_t* dst_data; - fn operator<(other: const woff2::Table &) const -> bool { + fn operator<(other: const Table&) const -> bool { return tag < other.tag; } }; @@ -57,7 +57,7 @@ struct Table { fn CollectionHeaderSize(header_version: uint32_t, num_fonts: uint32_t) -> size_t; // Compute checksum over size bytes of buf -fn ComputeULongSum(buf: const uint8_t *, size: size_t) -> uint32_t; +fn ComputeULongSum(buf: const uint8_t*, size: size_t) -> uint32_t; } // namespace woff2 diff --git a/third_party/examples/woff2/carbon/src/woff2_common.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_common.impl.carbon index 68794426f2fc..c7984fefc9e1 100644 --- a/third_party/examples/woff2/carbon/src/woff2_common.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_common.impl.carbon @@ -15,7 +15,7 @@ namespace woff2 { -fn ComputeULongSum(buf: const uint8_t *, size: size_t) -> uint32_t { +fn ComputeULongSum(buf: const uint8_t*, size: size_t) -> uint32_t { var checksum: uint32_t; var aligned_size: size_t; for (var i: size_t; i < aligned_size; i += 4) { diff --git a/third_party/examples/woff2/carbon/src/woff2_compress.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_compress.impl.carbon index ec15360b5c60..bb6fa9bd709d 100644 --- a/third_party/examples/woff2/carbon/src/woff2_compress.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_compress.impl.carbon @@ -12,7 +12,7 @@ #include -fn main(argc: int, argv: char **) -> int { +fn main(argc: int, argv: char**) -> int { using std::string; if (argc != 2) { @@ -20,15 +20,15 @@ fn main(argc: int, argv: char **) -> int { return 1; } - var filename: std::string; - var outfilename: std::string; + var filename: string; + var outfilename: string; fprintf(stdout, "Processing %s => %s\n", filename.c_str(), outfilename.c_str()); - var input: std::string; + var input: string; - var input_data: auto*; + var input_data: const auto*; var output_size: size_t; - var output: std::string; + var output: string; var output_data: auto*; var params: woff2::WOFF2Params; diff --git a/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon index 5401d390dc2a..2cb588610ef0 100644 --- a/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon @@ -112,7 +112,7 @@ fn WithSign(flag: int, baseval: int) -> int { return (flag & 1) ? baseval : -baseval; } -fn _SafeIntAddition(a: int, b: int, result: int *) -> bool { +fn _SafeIntAddition(a: int, b: int, result: int*) -> bool { if (PREDICT_FALSE( ((a > 0) && (b > std::numeric_limits::max() - a)) || ((a < 0) && (b < std::numeric_limits::min() - a)))) { @@ -122,8 +122,8 @@ fn _SafeIntAddition(a: int, b: int, result: int *) -> bool { return true; } -fn TripletDecode(flags_in: const uint8_t *, in: const uint8_t *, in_size: size_t, - n_points: unsigned int, result: woff2::Point *, in_bytes_consumed: size_t *) -> bool { +fn TripletDecode(flags_in: const uint8_t*, in: const uint8_t*, in_size: size_t, + n_points: unsigned int, result: Point*, in_bytes_consumed: size_t*) -> bool { var x: int; var y: int; @@ -191,9 +191,9 @@ fn TripletDecode(flags_in: const uint8_t *, in: const uint8_t *, in_size: size_t // This function stores just the point data. On entry, dst points to the // beginning of a simple glyph. Returns true on success. -fn StorePoints(n_points: unsigned int, points: const woff2::Point *, +fn StorePoints(n_points: unsigned int, points: const Point*, n_contours: unsigned int, instruction_length: unsigned int, - dst: uint8_t *, dst_size: size_t, glyph_size: size_t *) -> bool { + dst: uint8_t*, dst_size: size_t, glyph_size: size_t*) -> bool { // I believe that n_contours < 65536, in which case this is safe. However, a // comment and/or an assert would be good. var flag_offset: unsigned int; @@ -205,7 +205,7 @@ fn StorePoints(n_points: unsigned int, points: const woff2::Point *, var y_bytes: unsigned int; for (var i: unsigned int; i < n_points; ++i) { - var point: const woff2::Point &; + var point: const Point&; var flag: int; var dx: int; var dy: int; @@ -292,7 +292,7 @@ fn StorePoints(n_points: unsigned int, points: const woff2::Point *, // Compute the bounding box of the coordinates, and store into a glyf buffer. // A precondition is that there are at least 10 bytes available. // dst should point to the beginning of a 'glyf' record. -fn ComputeBbox(n_points: unsigned int, points: const woff2::Point *, dst: uint8_t *) { +fn ComputeBbox(n_points: unsigned int, points: const Point*, dst: uint8_t*) { var x_min: int; var y_min: int; var x_max: int; @@ -320,8 +320,8 @@ fn ComputeBbox(n_points: unsigned int, points: const woff2::Point *, dst: uint8_ } -fn SizeOfComposite(composite_stream: woff2::Buffer, size: size_t *, - have_instructions: bool *) -> bool { +fn SizeOfComposite(composite_stream: Buffer, size: size_t*, + have_instructions: bool*) -> bool { var start_offset: size_t; var we_have_instructions: bool; @@ -355,8 +355,8 @@ fn SizeOfComposite(composite_stream: woff2::Buffer, size: size_t *, return true; } -fn Pad4(out: woff2::WOFF2Out *) -> bool { - var zeroes: uint8_t [3]; +fn Pad4(out: WOFF2Out*) -> bool { + var zeroes: uint8_t[]; if (PREDICT_FALSE(out->Size() + 3 < out->Size())) { return FONT_COMPRESSION_FAILURE(); } @@ -370,8 +370,8 @@ fn Pad4(out: woff2::WOFF2Out *) -> bool { } // Build TrueType loca table -fn StoreLoca(loca_values: const std::vector &, index_format: int, - checksum: uint32_t *, out: woff2::WOFF2Out *) -> bool { +fn StoreLoca(loca_values: const std::vector&, index_format: int, + checksum: uint32_t*, out: WOFF2Out*) -> bool { // TODO(user) figure out what index format to use based on whether max // offset fits into uint16_t or not let loca_size: const uint64_t; @@ -380,7 +380,7 @@ fn StoreLoca(loca_values: const std::vector &, index_format: int, return FONT_COMPRESSION_FAILURE(); } var loca_content: std::vector; - var dst: uint8_t *; + var dst: uint8_t*; var offset: size_t; for (unsigned int value : loca_values) { if (index_format) { @@ -397,14 +397,14 @@ fn StoreLoca(loca_values: const std::vector &, index_format: int, } // Reconstruct entire glyf table based on transformed original -fn ReconstructGlyf(data: const uint8_t *, glyf_table: woff2::Table *, - glyf_checksum: uint32_t *, loca_table: woff2::Table *, - loca_checksum: uint32_t *, info: woff2::(anonymous namespace)::WOFF2FontInfo *, - out: woff2::WOFF2Out *) -> bool { +fn ReconstructGlyf(data: const uint8_t*, glyf_table: Table*, + glyf_checksum: uint32_t*, loca_table: Table*, + loca_checksum: uint32_t*, info: WOFF2FontInfo*, + out: WOFF2Out*) -> bool { let kNumSubStreams: const int; - var file: woff2::Buffer; + var file: Buffer; var version: uint32_t; - var substreams: std::vector>; + var substreams: std::vector >; let glyf_start: const size_t; if (PREDICT_FALSE(!file.ReadU32(&version))) { @@ -438,19 +438,19 @@ fn ReconstructGlyf(data: const uint8_t *, glyf_table: woff2::Table *, substreams[i] = std::make_pair(data + offset, substream_size); offset += substream_size; } - var n_contour_stream: woff2::Buffer; - var n_points_stream: woff2::Buffer; - var flag_stream: woff2::Buffer; - var glyph_stream: woff2::Buffer; - var composite_stream: woff2::Buffer; - var bbox_stream: woff2::Buffer; - var instruction_stream: woff2::Buffer; + var n_contour_stream: Buffer; + var n_points_stream: Buffer; + var flag_stream: Buffer; + var glyph_stream: Buffer; + var composite_stream: Buffer; + var bbox_stream: Buffer; + var instruction_stream: Buffer; var loca_values: std::vector; var n_points_vec: std::vector; - var points: std::unique_ptr; + var points: std::unique_ptr; var points_size: size_t; - var bbox_bitmap: const uint8_t *; + var bbox_bitmap: const uint8_t*; // Safe because num_glyphs is bounded var bitmap_length: unsigned int; if (!bbox_stream.Skip(bitmap_length)) { @@ -459,7 +459,7 @@ fn ReconstructGlyf(data: const uint8_t *, glyf_table: woff2::Table *, // Temp buffer for glyph's. var glyph_buf_size: size_t; - var glyph_buf: std::unique_ptr; + var glyph_buf: std::unique_ptr; info->x_mins.resize(info->num_glyphs); for (var i: unsigned int; i < info->num_glyphs; ++i) { @@ -539,8 +539,8 @@ fn ReconstructGlyf(data: const uint8_t *, glyf_table: woff2::Table *, flag_size > flag_stream.length() - flag_stream.offset())) { return FONT_COMPRESSION_FAILURE(); } - var flags_buf: const uint8_t *; - var triplet_buf: const uint8_t *; + var flags_buf: const uint8_t*; + var triplet_buf: const uint8_t*; var triplet_size: size_t; var triplet_bytes_consumed: size_t; if (points_size < total_n_points) { @@ -625,7 +625,7 @@ fn ReconstructGlyf(data: const uint8_t *, glyf_table: woff2::Table *, // We may need x_min to reconstruct 'hmtx' if (n_contours > 0) { - var x_min_buf: woff2::Buffer; + var x_min_buf: Buffer; if (PREDICT_FALSE(!x_min_buf.ReadS16(&info->x_mins[i]))) { return FONT_COMPRESSION_FAILURE(); } @@ -646,7 +646,7 @@ fn ReconstructGlyf(data: const uint8_t *, glyf_table: woff2::Table *, return true; } -fn FindTable(tables: std::vector *, tag: uint32_t) -> Table* { +fn FindTable(tables: std::vector*, tag: uint32_t) -> Table* { for (Table* table : *tables) { if (table->tag == tag) { return table; @@ -656,10 +656,10 @@ fn FindTable(tables: std::vector
*, tag: uint32_t) -> Table* { } // Get numberOfHMetrics, https://www.microsoft.com/typography/otspec/hhea.htm -fn ReadNumHMetrics(data: const uint8_t *, data_size: size_t, - num_hmetrics: uint16_t *) -> bool { +fn ReadNumHMetrics(data: const uint8_t*, data_size: size_t, + num_hmetrics: uint16_t*) -> bool { // Skip 34 to reach 'hhea' numberOfHMetrics - var buffer: woff2::Buffer; + var buffer: Buffer; if (PREDICT_FALSE(!buffer.Skip(34) || !buffer.ReadU16(num_hmetrics))) { return FONT_COMPRESSION_FAILURE(); } @@ -667,14 +667,14 @@ fn ReadNumHMetrics(data: const uint8_t *, data_size: size_t, } // http://dev.w3.org/webfonts/WOFF2/spec/Overview.html#hmtx_table_format -fn ReconstructTransformedHmtx(transformed_buf: const uint8_t *, +fn ReconstructTransformedHmtx(transformed_buf: const uint8_t*, transformed_size: size_t, num_glyphs: uint16_t, num_hmetrics: uint16_t, - x_mins: const std::vector &, - checksum: uint32_t *, - out: woff2::WOFF2Out *) -> bool { - var hmtx_buff_in: woff2::Buffer; + x_mins: const std::vector&, + checksum: uint32_t*, + out: WOFF2Out*) -> bool { + var hmtx_buff_in: Buffer; var hmtx_flags: uint8_t; if (PREDICT_FALSE(!hmtx_buff_in.ReadU8(&hmtx_flags))) { @@ -747,7 +747,7 @@ fn ReconstructTransformedHmtx(transformed_buf: const uint8_t *, // bake me a shiny new hmtx table var hmtx_output_size: uint32_t; var hmtx_table: std::vector; - var dst: uint8_t *; + var dst: uint8_t*; var dst_offset: size_t; for (var i: uint32_t; i < num_glyphs; i++) { if (i < num_hmetrics) { @@ -764,8 +764,8 @@ fn ReconstructTransformedHmtx(transformed_buf: const uint8_t *, return true; } -fn Woff2Uncompress(dst_buf: uint8_t *, dst_size: size_t, - src_buf: const uint8_t *, src_size: size_t) -> bool { +fn Woff2Uncompress(dst_buf: uint8_t*, dst_size: size_t, + src_buf: const uint8_t*, src_size: size_t) -> bool { var uncompressed_size: size_t; var result: BrotliDecoderResult; if (PREDICT_FALSE(result != BROTLI_DECODER_RESULT_SUCCESS || @@ -775,11 +775,11 @@ fn Woff2Uncompress(dst_buf: uint8_t *, dst_size: size_t, return true; } -fn ReadTableDirectory(file: woff2::Buffer *, tables: std::vector
*, +fn ReadTableDirectory(file: Buffer*, tables: std::vector
*, num_tables: size_t) -> bool { var src_offset: uint32_t; for (var i: size_t; i < num_tables; ++i) { - var table: woff2::Table *; + var table: Table*; var flag_byte: uint8_t; if (PREDICT_FALSE(!file->ReadU8(&flag_byte))) { return FONT_COMPRESSION_FAILURE(); @@ -834,11 +834,11 @@ fn ReadTableDirectory(file: woff2::Buffer *, tables: std::vector
*, } // Writes a single Offset Table entry -fn StoreOffsetTable(result: uint8_t *, offset: size_t, flavor: uint32_t, +fn StoreOffsetTable(result: uint8_t*, offset: size_t, flavor: uint32_t, num_tables: uint16_t) -> size_t { offset = StoreU32(result, offset, flavor); // sfnt version offset = Store16(result, offset, num_tables); // num_tables - var max_pow2: unsigned int; + var max_pow2: unsigned; while (1u << (max_pow2 + 1) <= num_tables) { max_pow2++; } @@ -850,7 +850,7 @@ fn StoreOffsetTable(result: uint8_t *, offset: size_t, flavor: uint32_t, return offset; } -fn StoreTableEntry(result: uint8_t *, offset: uint32_t, tag: uint32_t) -> size_t { +fn StoreTableEntry(result: uint8_t*, offset: uint32_t, tag: uint32_t) -> size_t { offset = StoreU32(result, offset, tag); offset = StoreU32(result, offset, 0); offset = StoreU32(result, offset, 0); @@ -859,7 +859,7 @@ fn StoreTableEntry(result: uint8_t *, offset: uint32_t, tag: uint32_t) -> size_t } // First table goes after all the headers, table directory, etc -fn ComputeOffsetToFirstTable(hdr: const woff2::(anonymous namespace)::WOFF2Header &) -> uint64_t { +fn ComputeOffsetToFirstTable(hdr: const WOFF2Header&) -> uint64_t { var offset: uint64_t; if (hdr.header_version) { offset = CollectionHeaderSize(hdr.header_version, hdr.ttc_fonts.size()) @@ -871,8 +871,8 @@ fn ComputeOffsetToFirstTable(hdr: const woff2::(anonymous namespace)::WOFF2Heade return offset; } -fn Tables(hdr: woff2::(anonymous namespace)::WOFF2Header *, font_index: size_t) -> std::vector { - var tables: std::vector
; +fn Tables(hdr: WOFF2Header*, font_index: size_t) -> std::vector { + var tables: std::vector; if (PREDICT_FALSE(hdr->header_version)) { for (auto index : hdr->ttc_fonts[font_index].table_indices) { tables.push_back(&hdr->tables[index]); @@ -887,20 +887,20 @@ fn Tables(hdr: woff2::(anonymous namespace)::WOFF2Header *, font_index: size_t) // Offset tables assumed to have been written in with 0's initially. // WOFF2Header isn't const so we can use [] instead of at() (which upsets FF) -fn ReconstructFont(transformed_buf: uint8_t *, +fn ReconstructFont(transformed_buf: uint8_t*, let transformed_buf_size: const uint32_t, - metadata: woff2::(anonymous namespace)::RebuildMetadata *, - hdr: woff2::(anonymous namespace)::WOFF2Header *, + metadata: RebuildMetadata*, + hdr: WOFF2Header*, font_index: size_t, - out: woff2::WOFF2Out *) -> bool { + out: WOFF2Out*) -> bool { var dest_offset: size_t; - var table_entry: uint8_t [12]; - var info: woff2::(anonymous namespace)::WOFF2FontInfo *; - var tables: std::vector
; + var table_entry: uint8_t[12]; + var info: WOFF2FontInfo*; + var tables: std::vector; // 'glyf' without 'loca' doesn't make sense - var glyf_table: const woff2::Table *; - var loca_table: const woff2::Table *; + var glyf_table: const Table*; + var loca_table: const Table*; if (PREDICT_FALSE(static_cast(glyf_table) != static_cast(loca_table))) { #ifdef FONT_COMPRESSION_BIN @@ -926,7 +926,7 @@ fn ReconstructFont(transformed_buf: uint8_t *, var loca_checksum: uint32_t; for (var i: size_t; i < tables.size(); i++) { - var table: woff2::Table &; + var table: Table&; var checksum_key: std::pair; var reused: bool; @@ -969,7 +969,7 @@ fn ReconstructFont(transformed_buf: uint8_t *, if (table.tag == kGlyfTableTag) { table.dst_offset = dest_offset; - var loca_table: woff2::Table *; + var loca_table: Table*; if (PREDICT_FALSE(!ReconstructGlyf(transformed_buf + table.src_offset, &table, &checksum, loca_table, &loca_checksum, info, out))) { return FONT_COMPRESSION_FAILURE(); @@ -1020,12 +1020,12 @@ fn ReconstructFont(transformed_buf: uint8_t *, } // Update 'head' checkSumAdjustment. We already set it to 0 and summed font. - var head_table: woff2::Table *; + var head_table: Table*; if (head_table) { if (PREDICT_FALSE(head_table->dst_length < 12)) { return FONT_COMPRESSION_FAILURE(); } - var checksum_adjustment: uint8_t [4]; + var checksum_adjustment: uint8_t[4]; StoreU32(checksum_adjustment, 0, 0xB1B0AFBA - font_checksum); if (PREDICT_FALSE(!out->Write(checksum_adjustment, head_table->dst_offset + 8, 4))) { @@ -1036,8 +1036,8 @@ fn ReconstructFont(transformed_buf: uint8_t *, return true; } -fn ReadWOFF2Header(data: const uint8_t *, length: size_t, hdr: woff2::(anonymous namespace)::WOFF2Header *) -> bool { - var file: woff2::Buffer; +fn ReadWOFF2Header(data: const uint8_t*, length: size_t, hdr: WOFF2Header*) -> bool { + var file: Buffer; var signature: uint32_t; if (PREDICT_FALSE(!file.ReadU32(&signature) || signature != kWoff2Signature || @@ -1103,7 +1103,7 @@ fn ReadWOFF2Header(data: const uint8_t *, length: size_t, hdr: woff2::(anonymous } // Before we sort for output the last table end is the uncompressed size. - var last_table: woff2::Table &; + var last_table: Table&; hdr->uncompressed_size = last_table.src_offset + last_table.src_length; if (PREDICT_FALSE(hdr->uncompressed_size < last_table.src_offset)) { return FONT_COMPRESSION_FAILURE(); @@ -1126,7 +1126,7 @@ fn ReadWOFF2Header(data: const uint8_t *, length: size_t, hdr: woff2::(anonymous hdr->ttc_fonts.resize(num_fonts); for (var i: uint32_t; i < num_fonts; i++) { - var ttc_font: woff2::(anonymous namespace)::TtcFont &; + var ttc_font: TtcFont&; var num_tables: uint32_t; if (PREDICT_FALSE(!Read255UShort(&file, &num_tables) || !num_tables)) { return FONT_COMPRESSION_FAILURE(); @@ -1149,7 +1149,7 @@ fn ReadWOFF2Header(data: const uint8_t *, length: size_t, hdr: woff2::(anonymous } ttc_font.table_indices[j] = table_idx; - var table: const woff2::Table &; + var table: const Table&; if (table.tag == kLocaTableTag) { loca_idx = table_idx; } @@ -1219,8 +1219,8 @@ fn ReadWOFF2Header(data: const uint8_t *, length: size_t, hdr: woff2::(anonymous } // Write everything before the actual table data -fn WriteHeaders(metadata: woff2::(anonymous namespace)::RebuildMetadata *, - hdr: woff2::(anonymous namespace)::WOFF2Header *, out: woff2::WOFF2Out *) -> bool { +fn WriteHeaders(metadata: RebuildMetadata*, + hdr: WOFF2Header*, out: WOFF2Out*) -> bool { var output: std::vector; // Re-order tables in output (OTSpec) order @@ -1243,7 +1243,7 @@ fn WriteHeaders(metadata: woff2::(anonymous namespace)::RebuildMetadata *, } // Start building the font - var result: uint8_t *; + var result: uint8_t*; var offset: size_t; if (hdr->header_version) { // TTC header @@ -1265,7 +1265,7 @@ fn WriteHeaders(metadata: woff2::(anonymous namespace)::RebuildMetadata *, // write Offset Tables and store the location of each in TTC Header metadata->font_infos.resize(hdr->ttc_fonts.size()); for (var i: size_t; i < hdr->ttc_fonts.size(); i++) { - var ttc_font: woff2::(anonymous namespace)::TtcFont &; + var ttc_font: TtcFont&; // write Offset Table location into TTC Header offset_table = StoreU32(result, offset_table, offset); @@ -1302,8 +1302,8 @@ fn WriteHeaders(metadata: woff2::(anonymous namespace)::RebuildMetadata *, } // namespace -fn ComputeWOFF2FinalSize(data: const uint8_t *, length: size_t) -> size_t { - var file: woff2::Buffer; +fn ComputeWOFF2FinalSize(data: const uint8_t*, length: size_t) -> size_t { + var file: Buffer; var total_length: uint32_t; if (!file.Skip(16) || @@ -1313,16 +1313,16 @@ fn ComputeWOFF2FinalSize(data: const uint8_t *, length: size_t) -> size_t { return total_length; } -fn ConvertWOFF2ToTTF(result: uint8_t *, result_length: size_t, - data: const uint8_t *, length: size_t) -> bool { - var out: woff2::WOFF2MemoryOut; +fn ConvertWOFF2ToTTF(result: uint8_t*, result_length: size_t, + data: const uint8_t*, length: size_t) -> bool { + var out: WOFF2MemoryOut; return ConvertWOFF2ToTTF(data, length, &out); } -fn ConvertWOFF2ToTTF(data: const uint8_t *, length: size_t, - out: woff2::WOFF2Out *) -> bool { - var metadata: woff2::(anonymous namespace)::RebuildMetadata; - var hdr: woff2::(anonymous namespace)::WOFF2Header; +fn ConvertWOFF2ToTTF(data: const uint8_t*, length: size_t, + out: WOFF2Out*) -> bool { + var metadata: RebuildMetadata; + var hdr: WOFF2Header; if (!ReadWOFF2Header(data, length, &hdr)) { return FONT_COMPRESSION_FAILURE(); } @@ -1339,7 +1339,7 @@ fn ConvertWOFF2ToTTF(data: const uint8_t *, length: size_t, return FONT_COMPRESSION_FAILURE(); } - var src_buf: const uint8_t *; + var src_buf: const uint8_t*; var uncompressed_buf: std::vector; if (PREDICT_FALSE(hdr.uncompressed_size < 1)) { return FONT_COMPRESSION_FAILURE(); diff --git a/third_party/examples/woff2/carbon/src/woff2_decompress.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_decompress.impl.carbon index 75f6c857527c..83da899db9d6 100644 --- a/third_party/examples/woff2/carbon/src/woff2_decompress.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_decompress.impl.carbon @@ -13,7 +13,7 @@ #include -fn main(argc: int, argv: char **) -> int { +fn main(argc: int, argv: char**) -> int { using std::string; if (argc != 2) { @@ -21,13 +21,13 @@ fn main(argc: int, argv: char **) -> int { return 1; } - var filename: std::string; - var outfilename: std::string; + var filename: string; + var outfilename: string; // Note: update woff2_dec_fuzzer_new_entry.cc if this pattern changes. - var input: std::string; - var raw_input: auto*; - var output: std::string; + var input: string; + var raw_input: const auto*; + var output: string; var out: woff2::WOFF2StringOut; let ok: const bool; diff --git a/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon index e3d894b98948..d4caceea553f 100644 --- a/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon @@ -38,8 +38,8 @@ using std::vector; let kWoff2HeaderSize: const size_t; let kWoff2EntrySize: const size_t; -fn Compress(data: const uint8_t *, let len: const size_t, result: uint8_t *, - result_len: uint32_t *, mode: BrotliEncoderMode, quality: int) -> bool { +fn Compress(data: const uint8_t*, let len: const size_t, result: uint8_t*, + result_len: uint32_t*, mode: BrotliEncoderMode, quality: int) -> bool { var compressed_len: size_t; if (BrotliEncoderCompress(quality, BROTLI_DEFAULT_WINDOW, mode, len, data, &compressed_len, result) == 0) { @@ -49,15 +49,15 @@ fn Compress(data: const uint8_t *, let len: const size_t, result: uint8_t *, return true; } -fn Woff2Compress(data: const uint8_t *, let len: const size_t, - result: uint8_t *, result_len: uint32_t *, +fn Woff2Compress(data: const uint8_t*, let len: const size_t, + result: uint8_t*, result_len: uint32_t*, quality: int) -> bool { return Compress(data, len, result, result_len, BROTLI_MODE_FONT, quality); } -fn TextCompress(data: const uint8_t *, let len: const size_t, - result: uint8_t *, result_len: uint32_t *, +fn TextCompress(data: const uint8_t*, let len: const size_t, + result: uint8_t*, result_len: uint32_t*, quality: int) -> bool { return Compress(data, len, result, result_len, BROTLI_MODE_TEXT, quality); @@ -71,7 +71,7 @@ fn KnownTableIndex(tag: uint32_t) -> int { return 63; } -fn StoreTableEntry(table: const woff2::Table &, offset: size_t *, dst: uint8_t *) { +fn StoreTableEntry(table: const Table&, offset: size_t*, dst: uint8_t*) { var flag_byte: uint8_t; dst[(*offset)++] = flag_byte; // The index here is treated as a set of flag bytes because @@ -86,7 +86,7 @@ fn StoreTableEntry(table: const woff2::Table &, offset: size_t *, dst: uint8_t * } } -fn TableEntrySize(table: const woff2::Table &) -> size_t { +fn TableEntrySize(table: const Table&) -> size_t { var flag_byte: uint8_t; var size: size_t; size += Base128Size(table.src_length); @@ -96,8 +96,8 @@ fn TableEntrySize(table: const woff2::Table &) -> size_t { return size; } -fn ComputeWoff2Length(font_collection: const woff2::FontCollection &, - tables: const std::vector
&, +fn ComputeWoff2Length(font_collection: const FontCollection&, + tables: const std::vector
&, index_by_tag_offset: std::map, uint16_t>, compressed_data_length: size_t, extended_metadata_length: size_t) -> size_t { @@ -117,7 +117,7 @@ fn ComputeWoff2Length(font_collection: const woff2::FontCollection &, for (const auto& font : font_collection.fonts) { size += Size255UShort(font.tables.size()); // 255UInt16 numTables for (const auto& entry : font.tables) { - var table: const Font::Table &; + var table: const Font::Table&; // no collection entry for xform table if (table.tag & 0x80808080) { continue; } @@ -137,11 +137,11 @@ fn ComputeWoff2Length(font_collection: const woff2::FontCollection &, return size; } -fn ComputeUncompressedLength(font: const woff2::Font &) -> size_t { +fn ComputeUncompressedLength(font: const Font&) -> size_t { // sfnt header + offset table var size: size_t; for (const auto& entry : font.tables) { - var table: const Font::Table &; + var table: const Font::Table&; if (table.tag & 0x80808080) { continue; // xform tables don't stay } if (table.IsReused()) { continue; // don't have to pay twice @@ -151,7 +151,7 @@ fn ComputeUncompressedLength(font: const woff2::Font &) -> size_t { return size; } -fn ComputeUncompressedLength(font_collection: const woff2::FontCollection &) -> size_t { +fn ComputeUncompressedLength(font_collection: const FontCollection&) -> size_t { if (font_collection.flavor != kTtcFontFlavor) { return ComputeUncompressedLength(font_collection.fonts[0]); } @@ -162,10 +162,10 @@ fn ComputeUncompressedLength(font_collection: const woff2::FontCollection &) -> return size; } -fn ComputeTotalTransformLength(font: const woff2::Font &) -> size_t { +fn ComputeTotalTransformLength(font: const Font&) -> size_t { var total: size_t; for (const auto& i : font.tables) { - var table: const Font::Table &; + var table: const Font::Table&; if (table.IsReused()) { continue; } @@ -180,12 +180,12 @@ fn ComputeTotalTransformLength(font: const woff2::Font &) -> size_t { } // namespace -fn MaxWOFF2CompressedSize(data: const uint8_t *, length: size_t) -> size_t { +fn MaxWOFF2CompressedSize(data: const uint8_t*, length: size_t) -> size_t { return MaxWOFF2CompressedSize(data, length, ""); } -fn MaxWOFF2CompressedSize(const uint8_t* /*data*/: const uint8_t * /*data*/, length: size_t, - extended_metadata: const std::string &) -> size_t { +fn MaxWOFF2CompressedSize(const uint8_t* /*data*/: const uint8_t* /*data*/, length: size_t, + extended_metadata: const string&) -> size_t { // Except for the header size, which is 32 bytes larger in woff2 format, // all other parts should be smaller (table header in short format, // transformations and compression). Just to be sure, we will give some @@ -197,7 +197,7 @@ fn CompressedBufferSize(original_size: uint32_t) -> uint32_t { return 1.2 * original_size + 10240; } -fn TransformFontCollection(font_collection: woff2::FontCollection *) -> bool { +fn TransformFontCollection(font_collection: FontCollection*) -> bool { for (auto& font : font_collection->fonts) { if (!TransformGlyfAndLocaTables(&font)) { #ifdef FONT_COMPRESSION_BIN @@ -210,17 +210,17 @@ fn TransformFontCollection(font_collection: woff2::FontCollection *) -> bool { return true; } -fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, - result: uint8_t *, result_length: size_t *) -> bool { - var params: woff2::WOFF2Params; +fn ConvertTTFToWOFF2(data: const uint8_t*, length: size_t, + result: uint8_t*, result_length: size_t*) -> bool { + var params: WOFF2Params; return ConvertTTFToWOFF2(data, length, result, result_length, params); } -fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, - result: uint8_t *, result_length: size_t *, - params: const woff2::WOFF2Params &) -> bool { - var font_collection: woff2::FontCollection; +fn ConvertTTFToWOFF2(data: const uint8_t*, length: size_t, + result: uint8_t*, result_length: size_t*, + params: const WOFF2Params&) -> bool { + var font_collection: FontCollection; if (!ReadFontCollection(data, length, &font_collection)) { #ifdef FONT_COMPRESSION_BIN fprintf(stderr, "Parsing of the input font failed.\n"); @@ -237,8 +237,8 @@ fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, } else { // glyf/loca use 11 to flag "not transformed" for (auto& font : font_collection.fonts) { - var glyf_table: Font::Table *; - var loca_table: Font::Table *; + var glyf_table: Font::Table*; + var loca_table: Font::Table*; if (glyf_table) { glyf_table->flag_byte |= 0xc0; } @@ -267,12 +267,12 @@ fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, var transform_offset: size_t; for (const auto& font : font_collection.fonts) { for (const auto tag : font.OutputOrderedTags()) { - var original: const Font::Table &; + var original: const Font::Table&; if (original.IsReused()) { continue; } if (tag & 0x80808080) { continue; } - var table_to_store: const Font::Table *; + var table_to_store: const Font::Table*; if (table_to_store == nullptr) { table_to_store = &original; } @@ -323,7 +323,7 @@ fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, for (const auto& font : font_collection.fonts) { for (const auto tag : font.OutputOrderedTags()) { - var src_table: const Font::Table &; + var src_table: const Font::Table&; if (src_table.IsReused()) { continue; } @@ -335,13 +335,13 @@ fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, return false; } - var table: woff2::Table; + var table: Table; table.tag = src_table.tag; table.flags = src_table.flag_byte; table.src_length = src_table.length; table.transform_length = src_table.length; - var transformed_data: const uint8_t *; - var transformed_table: const Font::Table *; + var transformed_data: const uint8_t*; + var transformed_table: const Font::Table*; if (transformed_table != nullptr) { table.flags = transformed_table->flag_byte; table.flags |= kWoff2FlagsTransform; @@ -410,7 +410,7 @@ fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, var num_tables: uint16_t; for (const auto& entry : font.tables) { - var table: const Font::Table &; + var table: const Font::Table&; if (table.tag & 0x80808080) { continue; // don't write xform tables } num_tables++; @@ -419,7 +419,7 @@ fn ConvertTTFToWOFF2(data: const uint8_t *, length: size_t, StoreU32(font.flavor, &offset, result); for (const auto& entry : font.tables) { - var table: const Font::Table &; + var table: const Font::Table&; if (table.tag & 0x80808080) { continue; // don't write xform tables } diff --git a/third_party/examples/woff2/carbon/src/woff2_info.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_info.impl.carbon index b7704e2bd6d4..0563cb32fe99 100644 --- a/third_party/examples/woff2/carbon/src/woff2_info.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_info.impl.carbon @@ -19,11 +19,11 @@ fn PrintTag(tag: int) -> std::string { if (tag & 0x80808080) { return std::string("_xfm"); // print _xfm for xform tables (else garbage) } - var printable: char [4]; + var printable: char[]; return std::string(printable, 4); } -fn main(argc: int, argv: char **) -> int { +fn main(argc: int, argv: char**) -> int { using std::string; if (argc != 2) { @@ -31,11 +31,11 @@ fn main(argc: int, argv: char **) -> int { return 1; } - var filename: std::string; - var outfilename: std::string; + var filename: string; + var outfilename: string; fprintf(stdout, "Processing %s => %s\n", filename.c_str(), outfilename.c_str()); - var input: std::string; + var input: string; var file: woff2::Buffer; diff --git a/third_party/examples/woff2/carbon/src/woff2_out.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_out.impl.carbon index 9980990bb8b8..77ed73233414 100644 --- a/third_party/examples/woff2/carbon/src/woff2_out.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_out.impl.carbon @@ -12,16 +12,16 @@ using std::string; namespace woff2 { -WOFF2StringOut::WOFF2StringOut(buf: std::string *) +WOFF2StringOut::WOFF2StringOut(buf: string*) : buf_(buf), max_size_(kDefaultMaxSize), offset_(0) {} -fn WOFF2StringOut::Write(buf: const void *, n: size_t) -> bool { +fn WOFF2StringOut::Write(buf: const void*, n: size_t) -> bool { return Write(buf, offset_, n); } -fn WOFF2StringOut::Write(buf: const void *, offset: size_t, n: size_t) -> bool { +fn WOFF2StringOut::Write(buf: const void*, offset: size_t, n: size_t) -> bool { if (offset > max_size_ || n > max_size_ - offset) { return false; } @@ -45,16 +45,16 @@ fn WOFF2StringOut::SetMaxSize(max_size: size_t) { } } -WOFF2MemoryOut::WOFF2MemoryOut(buf: uint8_t *, buf_size: size_t) +WOFF2MemoryOut::WOFF2MemoryOut(buf: uint8_t*, buf_size: size_t) : buf_(buf), buf_size_(buf_size), offset_(0) {} -fn WOFF2MemoryOut::Write(buf: const void *, n: size_t) -> bool { +fn WOFF2MemoryOut::Write(buf: const void*, n: size_t) -> bool { return Write(buf, offset_, n); } -fn WOFF2MemoryOut::Write(buf: const void *, offset: size_t, n: size_t) -> bool { +fn WOFF2MemoryOut::Write(buf: const void*, offset: size_t, n: size_t) -> bool { if (offset > buf_size_ || n > buf_size_ - offset) { return false; }