diff --git a/atdna/main.cpp b/atdna/main.cpp index 1b14d4d..aec931e 100644 --- a/atdna/main.cpp +++ b/atdna/main.cpp @@ -1870,26 +1870,19 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor if (alignVal) { fileOut << " /* " << fieldName << " */\n"; - if (alignVal == 32) - { - if (!p) - fileOut << " " ATHENA_DNA_READER ".seekAlign32();\n"; - else - fileOut << " " ATHENA_DNA_WRITER ".seekAlign32();\n"; - } - else if (align.isPowerOf2()) + if (align.isPowerOf2()) { if (!p) fileOut << " " ATHENA_DNA_READER ".seek((" ATHENA_DNA_READER ".position() + " << alignVal-1 << ") & ~" << alignVal-1 << ", athena::Begin);\n"; else - fileOut << " " ATHENA_DNA_WRITER ".seek((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") & ~" << alignVal-1 << ", athena::Begin);\n"; + fileOut << " " ATHENA_DNA_WRITER ".writeZeroTo((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") & ~" << alignVal-1 << ");\n"; } else { if (!p) fileOut << " " ATHENA_DNA_READER ".seek((" ATHENA_DNA_READER ".position() + " << alignVal-1 << ") / " << alignVal << " * " << alignVal << ", athena::Begin);\n"; else - fileOut << " " ATHENA_DNA_WRITER ".seek((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") / " << alignVal << " * " << alignVal << ", athena::Begin);\n"; + fileOut << " " ATHENA_DNA_WRITER ".writeZeroTo((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") / " << alignVal << " * " << alignVal << ");\n"; } } } diff --git a/include/athena/IStreamWriter.hpp b/include/athena/IStreamWriter.hpp index ae50c0f..c3940a0 100644 --- a/include/athena/IStreamWriter.hpp +++ b/include/athena/IStreamWriter.hpp @@ -24,6 +24,17 @@ public: */ inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);} + /** @brief Writes zero up to specified absolute offset.
+ */ + inline void writeZeroTo(atInt64 pos) + { + atInt64 delta = pos - position(); + if (delta <= 0) + return; + for (atInt64 i=0 ; i