tuxji opened a new pull request #525:
URL: https://github.com/apache/daffodil/pull/525
Refactor duplicate code in Binary*CodeGenerator.scala files.
Change PState/UState member field from a string error message to a
struct error object. Make parse/unparse functions initialize that
member field if any error happens. Move checks for errors from
parse/unparse functions to their callers, e.g., "if (ustate->error)
return;".
Collect validation errors without stopping parsing or unparsing by
initializing another PState/UState member field pointing to a
validation struct with some fields. As last step, update all C files
using include-what-you-use to document what's used from each include.
Add instructions to README.md how to setup required C tool-chain
elements on Linux and Windows.
Generate daffodil-runtime2's name and version into generated_code.c
automatically so we won't need to keep it up to date.
Changelog:
In README.md, fix or disable markdownlint warnings. Expand Build
Requirements with instructions how to install C compiler, Mini-XML
library, java, and sbt on Linux and Windows. Verify/update old
hyperlinks and add new MSYS2 and clang hyperlinks.
In build.sbt, add Compile / cCompiler and ccArchiveCommand settings as
a guide to show developers how to override these default settings if
they want sbt to call the C compiler with a different name than "cc".
The sbt-cc plugin doesn't iterate through a list (${CC}, cc, gcc,
clang, zig cc) to find a C compiler like our runtime2 code does.
In daffodil_argp.c, remove argp_program_version's definition since we
now generate it automatically within generated_code.c.
In daffodil_main.c, add fflush_or_exit and change fopen_or_exit /
fclose_or_open to call continue_or_exit with error message instead of
calling exit directly. Make main print any validation diagnostics
before printing any errors since they've been split into separate
PState/UState member fields. Also make main call continue_or_exit
instead of calling error directly and pass Error structs, not strings,
to all continue_or_exit calls.
In stack.c, make stack functions call continue_or_exit instead of
calling error directly and pass Error structs, not strings, to all
continue_or_exit calls.
In xml_reader.c, make conversion functions return Error structs, not
strings, to indicate errors converting strings to primitive datums.
Make reader functions return Error structs, not strings, to indicate
errors reading XML data.
In xml_writer.c, make writer functions return Error structs, not
strings, to indicate errors writing XML data. Remove redundant stack
checking code already performed within stack fuctions.
In errors.c (new file), use switch statement inside error_message
function to centralize all error messages in one place for easier
future internationalization. Use switch statement inside
print_mybe_stop function to allow error messages to interpolate an
extra detail (string or integer) if needed. Define a single static
array that can be used to store validation diagnostics and define a
function to print validation diagnostics. Implement continue_or_exit
and eof_or_error functions here as well.
In errors.h (new file), define enumerations for each type of error
which could occur in C code. Define an Error struct to store an
enumeration and optionally an extra detail (string or integer). Also
define a Diagnostics struct to store an array of data validation
errors which should be reported separately from parse errors. Move
PState and UState structs here from infoset.h and give them member
fields pointing to data validation and parse errors. Also declare
need_diagnostics, print_diagnostics, continue_or_exit, eof_or_error
prototypes and UNUSED macro in errors.h.
In infoset.c, make walkInfosetNode and walkInfoset functions return
Error struct, not string. Remove eof_or_error_msg function (now moved
to errors.c with shorter name).
In infoset.h, change InitChoiceRD and Visit* prototypes to return
Error structs, not strings. Remove PState & UState structs,
eof_or_error_msg prototype, and UNUSED macro (all moved to errors.h).
In parsers.c, make parse_<endian>_<type> functions stop enclosing
their code in "if (!pstate->error_msg)" statements and use Error
structs, not strings. Callers are now expected to check for errors
after each call immediately. Make parse_fill_bytes use
read_stream_update_position helper macro too. Make
parse_validate_fixed report errors in separate pstate->validati field,
not pstate->error field.
In unparsers.c, make unparse_<endian>_<type> functions stop enclosing
their code in "if (!ustate->error_msg)" statements and use Error
structs, not strings. Callers are now expected to check for errors
after each call immediately. Make unparse_fill_bytes use
write_stream_update_position helper macro too. Make
unparse_validate_fixed report errors in separate ustate->validati
field, not ustate->error field.
In NestedUnion.c and ex_nums.c examples, update with freshly generated
code to illustrate code generator changes (in particular, defining
argp_program_version, adding an if statement after each parse/unparse
call to check for an error and skip rest of calls immediately, and
returning errors directly from initChoice functions with choice key
that failed to match any branch key).
In BinaryAbstractCodeGenerator.scala (new file), refactor common code
that used to be duplicated in BinaryBooleanCodeGenerator.scala,
BinaryFloatCodeGenerator.scala, and
BinaryIntegerKnownLengthCodeGenerator.scala; now they pass parameters
to binaryAbstractGenerateCode instead.
In CodeGeneratorState.scala, make all necessary changes to report
errors using structs instead of strings in generated code including
initChoice functions, add if statements after each parse/unparse call,
and generate the program name and version automatically.
In build.properties, change sbt.version from 1.4.1 to 1.4.9 to ensure
successful sbt build from scratch in a new Ubuntu or Windows VM (sbt
was getting java.lang.NoClassDefFound: scala/Serializer).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]