diff --git a/src/XML/src/FMI/fmi_xml_terminals_and_icons.c b/src/XML/src/FMI/fmi_xml_terminals_and_icons.c index 703d18ca..35902234 100644 --- a/src/XML/src/FMI/fmi_xml_terminals_and_icons.c +++ b/src/XML/src/FMI/fmi_xml_terminals_and_icons.c @@ -105,13 +105,13 @@ int fmi_xml_handle_fmiTerminalsAndIcons(fmi3_xml_parser_context_t* context, cons fmi_xml_terminals_and_icons_t* termIcon = context->termIcon; if (!data) { int ret; - if (context->currentElmID != fmi3_xml_elmID_none) { + if (context->currentElmID.termIcon != fmi_xml_elmID_termIcon_none) { fmi3_xml_parse_fatal(context, "fmiTerminalsAndIcons must be the root XML element"); return -1; } jm_log_verbose(context->callbacks, module, "Parsing XML element fmiTerminalsAndIcons"); - ret = fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiTerminalsAndIcons, fmi_attr_id_fmiVersion, 1 /* required */, + ret = fmi3_xml_parse_attr_as_string(context, FMI_ELM_TERMICON(fmi_xml_elmID_termIcon_fmiTerminalsAndIcons), FMI_ATTR_TERMICON(fmi_attr_id_fmiVersion), 1 /* required */, &(termIcon->fmi3_xml_standard_version)); if (ret) { return ret; @@ -193,7 +193,7 @@ int fmi_xml_handle_Terminal(fmi3_xml_parser_context_t* context, const char* data // parse name jm_vector(char)* bufName = fmi3_xml_reserve_parse_buffer(context, bufIdx++, 100); if (!bufName) {return -1;} - if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Terminal, fmi_attr_id_name, 1 /* required */, bufName)) {return -1;} + if (fmi3_xml_parse_attr_as_string(context, FMI_ELM_TERMICON(fmi_xml_elmID_termIcon_Terminal), FMI_ATTR_TERMICON(fmi_attr_id_name), 1 /* required */, bufName)) {return -1;} /* Add the name to the terminalsAndIcons-wide set and retrieve the pointer */ if (jm_vector_get_size(char)(bufName)) { diff --git a/src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h b/src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h index 3973b95d..34a5fac3 100644 --- a/src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h +++ b/src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h @@ -20,11 +20,13 @@ extern "C" { #endif -/* Attributes common to modelDescription.xml & terminalsAndIcons.xml - * are listed in FMI3_XML_ATTRLIST_COMMON in fmi3_xml_parser.h - */ -#define FMI_XML_ATTRLIST_TERM_ICON(EXPAND_XML_ATTRNAME) // XXX: Currently empty, but will be filled +/* Attribute names found in terminalsAndIcons.xml */ +#define FMI_XML_ATTRLIST_TERM_ICON(EXPAND_XML_ATTRNAME) \ + EXPAND_XML_ATTRNAME(fmiVersion) \ + EXPAND_XML_ATTRNAME(name) \ + EXPAND_XML_ATTRNAME(description) +/* Element names found in terminalsAndIcons.xml */ #define FMI_XML_ELMLIST_TERM_ICON(EXPAND_XML_ELMNAME) \ EXPAND_XML_ELMNAME(fmiTerminalsAndIcons) \ EXPAND_XML_ELMNAME(Terminals) \ @@ -36,24 +38,23 @@ extern "C" { /** \brief Element that can be placed under different parents get alternative names from the info struct */ #define FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_XML_ELMNAME) // TODO: Terminal should go here? -// XXX: fmi3_xml_elmID_none is defined in fmi3_xml_parser.h, not good style /* - Define XML schema structure. Used to build the 'fmi3_xml_scheme_info_t' type (in fmi3_xml_parser.c). + Define XML schema structure. Used to build the 'fmi_xml_scheme_termIcon_info_t' type (in fmi3_xml_parser.c). @sib_idx: the index in a sequence among siblings @multi_elem: if the parent can have multiple elements of this type */ -/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */ -#define fmi3_xml_scheme_fmiTerminalsAndIcons {fmi3_xml_elmID_none, fmi3_xml_elmID_none, 0, 0} +/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */ +#define fmi_xml_scheme_termIcon_fmiTerminalsAndIcons {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_none, 0, 0} -#define fmi3_xml_scheme_Terminals {fmi3_xml_elmID_none, fmi3_xml_elmID_fmiTerminalsAndIcons, 1, 0} -#define fmi3_xml_scheme_Terminal {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminals, 0, 1} -#define fmi3_xml_scheme_TerminalMemberVariable {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminal, 0, 1} -#define fmi3_xml_scheme_TerminalStreamMemberVariable {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminal, 1, 1} +#define fmi_xml_scheme_termIcon_Terminals {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_fmiTerminalsAndIcons, 1, 0} +#define fmi_xml_scheme_termIcon_Terminal {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminals, 0, 1} +#define fmi_xml_scheme_termIcon_TerminalMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 0, 1} +#define fmi_xml_scheme_termIcon_TerminalStreamMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 1, 1} // TODO: How to handle nested Terminals? -#define fmi3_xml_scheme_TerminalGraphicalRepresentation {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminal, 3, 0} +#define fmi_xml_scheme_termIcon_TerminalGraphicalRepresentation {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 3, 0} #ifdef __cplusplus } diff --git a/src/XML/src/FMI2/fmi2_xml_parser.h b/src/XML/src/FMI2/fmi2_xml_parser.h index 78d9bd66..a6d925f5 100644 --- a/src/XML/src/FMI2/fmi2_xml_parser.h +++ b/src/XML/src/FMI2/fmi2_xml_parser.h @@ -263,7 +263,7 @@ struct fmi2_xml_parser_context_t { jm_vector(char) elmData; /** - * Element ID of the last processed sibling, or fmi3_xml_elmID_none if + * Element ID of the last processed sibling, or fmi2_xml_elmID_none if * no siblings have been processed. */ fmi2_xml_elm_enu_t lastElmID; diff --git a/src/XML/src/FMI3/fmi3_xml_model_description.c b/src/XML/src/FMI3/fmi3_xml_model_description.c index 71e95110..906e5119 100644 --- a/src/XML/src/FMI3/fmi3_xml_model_description.c +++ b/src/XML/src/FMI3/fmi3_xml_model_description.c @@ -406,30 +406,30 @@ int fmi3_xml_is_valid_model_ID(const char* str) { } int fmi3_xml_handle_fmiModelDescription(fmi3_xml_parser_context_t* context, const char* data) { - jm_name_ID_map_t namingConventionMap[] = {{"flat",fmi3_naming_enu_flat}, {"structured",fmi3_naming_enu_structured}, {NULL,0}}; + jm_name_ID_map_t namingConventionMap[] = {{"flat", fmi3_naming_enu_flat}, {"structured", fmi3_naming_enu_structured}, {NULL, 0}}; fmi3_xml_model_description_t* md = context->modelDescription; if (!data) { int ret; - if (context->currentElmID != fmi3_xml_elmID_none) { + if (context->currentElmID.modelDescription != fmi3_xml_elmID_none) { fmi3_xml_parse_fatal(context, "fmi3_xml_model_description must be the root XML element"); return -1; } jm_log_verbose(context->callbacks, module, "Parsing XML element fmiModelDescription"); md->fmuKind = fmi3_fmu_kind_unknown; /* process the attributes */ - ret = fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_fmiVersion, 1, &(md->fmi3_xml_standard_version)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_modelName, 1, &(md->modelName)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_instantiationToken, 1, &(md->instantiationToken)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_description, 0, &(md->description)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_author, 0, &(md->author)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_version, 0, &(md->version)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_copyright, 0, &(md->copyright)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_license, 0, &(md->license)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_generationTool, 0, &(md->generationTool)) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_generationDateAndTime, 0, &(md->generationDateAndTime)) || - fmi3_xml_parse_attr_as_enum(context, fmi3_xml_elmID_fmiModelDescription, fmi_attr_id_variableNamingConvention, 0, (unsigned*)&(md->namingConvension), + ret = fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_fmiVersion), 1, &(md->fmi3_xml_standard_version)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_modelName), 1, &(md->modelName)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_instantiationToken), 1, &(md->instantiationToken)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_description), 0, &(md->description)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_author), 0, &(md->author)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_version), 0, &(md->version)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_copyright), 0, &(md->copyright)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_license), 0, &(md->license)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_generationTool), 0, &(md->generationTool)) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_generationDateAndTime), 0, &(md->generationDateAndTime)) || + fmi3_xml_parse_attr_as_enum (context, FMI3_ELM(fmi3_xml_elmID_fmiModelDescription), FMI3_ATTR(fmi_attr_id_variableNamingConvention), 0, (unsigned*)&(md->namingConvension), fmi3_naming_enu_flat, namingConventionMap); - return (ret); + return ret; } else { /* check that fmuKind is defined and that model identifiers are valid */ @@ -475,7 +475,7 @@ static int fmi3_xml_process_interface_type_common_attrs(fmi3_xml_parser_context_ fmi3_capabilities_enu_t providesDirDerId = fmi_attr_id_providesDirectionalDerivatives; fmi3_capabilities_enu_t providesDirDerIdOld = fmi_attr_id_providesDirectionalDerivative; - if (fmi3_xml_is_attr_defined(context, providesDirDerIdOld)) { + if (fmi3_xml_is_attr_defined(context, FMI3_ATTR(providesDirDerIdOld))) { fmi3_xml_parse_error(context, "Attribute 'providesDirectionalDerivative' has been renamed to 'providesDirectionalDerivatives'."); providesDirDerId = providesDirDerIdOld; @@ -491,50 +491,50 @@ static int fmi3_xml_process_interface_type_common_attrs(fmi3_xml_parser_context_ size_t nCapME = sizeof(capArrME); size_t nCapCS = sizeof(capArrCS); - fmi3_xml_elm_enu_t elmID; + fmi3_xml_elm_t elmID; jm_vector(char)* modelIdentifierPtr; switch (fmuKind) { - case fmi3_fmu_kind_me: - elmID = fmi3_xml_elmID_ModelExchange; - modelIdentifierPtr = &md->modelExchange.modelIdentifier; - offset = 0; - break; - case fmi3_fmu_kind_cs: - elmID = fmi3_xml_elmID_CoSimulation; - modelIdentifierPtr = &md->coSimulation.modelIdentifier; - offset = nCapME; // CS comes after ME - break; - case fmi3_fmu_kind_se: - elmID = fmi3_xml_elmID_ScheduledExecution; - modelIdentifierPtr = &md->scheduledExecution.modelIdentifier; - offset = nCapME + nCapCS; // SE comes after CS - break; - default: - fmi3_xml_parse_fatal(context, "Invalid FMU kind"); - return -1; + case fmi3_fmu_kind_me: + elmID = FMI3_ELM(fmi3_xml_elmID_ModelExchange); + modelIdentifierPtr = &md->modelExchange.modelIdentifier; + offset = 0; + break; + case fmi3_fmu_kind_cs: + elmID = FMI3_ELM(fmi3_xml_elmID_CoSimulation); + modelIdentifierPtr = &md->coSimulation.modelIdentifier; + offset = nCapME; // CS comes after ME + break; + case fmi3_fmu_kind_se: + elmID = FMI3_ELM(fmi3_xml_elmID_ScheduledExecution); + modelIdentifierPtr = &md->scheduledExecution.modelIdentifier; + offset = nCapME + nCapCS; // SE comes after CS + break; + default: + fmi3_xml_parse_fatal(context, "Invalid FMU kind"); + return -1; } - if (fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_modelIdentifier, 1, modelIdentifierPtr) + if (fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_modelIdentifier), 1, modelIdentifierPtr) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_needsExecutionTool, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_needsExecutionTool), 0, &md->capabilities[fmi3_me_needsExecutionTool + offset], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_canBeInstantiatedOnlyOncePerProcess, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_canBeInstantiatedOnlyOncePerProcess), 0, &md->capabilities[fmi3_me_canBeInstantiatedOnlyOncePerProcess + offset], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_canGetAndSetFMUState, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_canGetAndSetFMUState), 0, &md->capabilities[fmi3_me_canGetAndSetFMUState + offset], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_canSerializeFMUState, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_canSerializeFMUState), 0, &md->capabilities[fmi3_me_canSerializeFMUState + offset], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, providesDirDerId, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(providesDirDerId), 0, &md->capabilities[fmi3_me_providesDirectionalDerivatives + offset], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_providesAdjointDerivatives, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_providesAdjointDerivatives), 0, &md->capabilities[fmi3_me_providesAdjointDerivatives + offset], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_providesPerElementDependencies, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_providesPerElementDependencies), 0, &md->capabilities[fmi3_me_providesPerElementDependencies + offset], 0)) { return -1; @@ -548,8 +548,8 @@ int fmi3_xml_handle_ModelExchange(fmi3_xml_parser_context_t *context, const char jm_log_verbose(context->callbacks, module, "Parsing XML element ModelExchange"); // Reset handles for the elements that are specific under ModelExchange - fmi3_xml_set_element_handle(context, "SourceFiles", FMI3_XML_ELM_ID(SourceFiles)); - fmi3_xml_set_element_handle(context, "File", FMI3_XML_ELM_ID(File)); + fmi3_xml_set_element_handle(context, "SourceFiles", FMI3_ELM(FMI3_XML_ELM_ID(SourceFiles))); + fmi3_xml_set_element_handle(context, "File", FMI3_ELM(FMI3_XML_ELM_ID(File))); // Update fmuKind if (md->fmuKind == fmi3_fmu_kind_unknown) { @@ -564,11 +564,11 @@ int fmi3_xml_handle_ModelExchange(fmi3_xml_parser_context_t *context, const char return -1; } - fmi3_xml_elm_enu_t elmID = fmi3_xml_elmID_ModelExchange; - if (fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_needsCompletedIntegratorStep, 0, + fmi3_xml_elm_t elmID = FMI3_ELM(fmi3_xml_elmID_ModelExchange); + if (fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_needsCompletedIntegratorStep), 0, &md->capabilities[fmi3_me_needsCompletedIntegratorStep], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_providesEvaluateDiscreteStates, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_providesEvaluateDiscreteStates), 0, &md->capabilities[fmi3_me_providesEvaluateDiscreteStates], 0)) { return -1; @@ -583,8 +583,8 @@ int fmi3_xml_handle_CoSimulation(fmi3_xml_parser_context_t *context, const char* jm_log_verbose(context->callbacks, module, "Parsing XML element CoSimulation"); // Reset handles for the elements that are specific under CoSimulation - fmi3_xml_set_element_handle(context, "SourceFiles", FMI3_XML_ELM_ID(SourceFilesCS)); - fmi3_xml_set_element_handle(context, "File", FMI3_XML_ELM_ID(FileCS)); + fmi3_xml_set_element_handle(context, "SourceFiles", FMI3_ELM(FMI3_XML_ELM_ID(SourceFilesCS))); + fmi3_xml_set_element_handle(context, "File", FMI3_ELM(FMI3_XML_ELM_ID(FileCS))); // Update fmuKind if (md->fmuKind == fmi3_fmu_kind_unknown) { @@ -599,23 +599,23 @@ int fmi3_xml_handle_CoSimulation(fmi3_xml_parser_context_t *context, const char* return -1; } - fmi3_xml_elm_enu_t elmID = fmi3_xml_elmID_CoSimulation; - if (fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_canHandleVariableCommunicationStepSize, 0, + fmi3_xml_elm_t elmID = FMI3_ELM(fmi3_xml_elmID_CoSimulation); + if (fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_canHandleVariableCommunicationStepSize), 0, &md->capabilities[fmi3_cs_canHandleVariableCommunicationStepSize], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_providesIntermediateUpdate, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_providesIntermediateUpdate), 0, &md->capabilities[fmi3_cs_providesIntermediateUpdate], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_mightReturnEarlyFromDoStep, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_mightReturnEarlyFromDoStep), 0, &md->capabilities[fmi3_cs_mightReturnEarlyFromDoStep], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_canReturnEarlyAfterIntermediateUpdate, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_canReturnEarlyAfterIntermediateUpdate), 0, &md->capabilities[fmi3_cs_canReturnEarlyAfterIntermediateUpdate], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_hasEventMode, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_hasEventMode), 0, &md->capabilities[fmi3_cs_hasEventMode], 0) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_providesEvaluateDiscreteStates, 0, + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_providesEvaluateDiscreteStates), 0, &md->capabilities[fmi3_cs_providesEvaluateDiscreteStates], 0)) { return -1; @@ -624,24 +624,24 @@ int fmi3_xml_handle_CoSimulation(fmi3_xml_parser_context_t *context, const char* // NOTE: This attribute is unsigned int, so not really a capability. However, in // FMI2 it's part of the capabilities enum, so keeping it the same for FMI3. - if (fmi3_xml_parse_attr_as_uint32(context, elmID, fmi_attr_id_maxOutputDerivativeOrder, 0, + if (fmi3_xml_parse_attr_as_uint32(context, elmID, FMI3_ATTR(fmi_attr_id_maxOutputDerivativeOrder), 0, &md->capabilities[fmi3_cs_maxOutputDerivativeOrder], 0)) { return -1; } // Other non-capability attributes: - if (fmi3_xml_is_attr_defined(context, fmi_attr_id_fixedInternalStepSize)) { + if (fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_fixedInternalStepSize))) { md->coSimulation.hasFixedInternalStepSize = 1; - if (fmi3_xml_parse_attr_as_float64(context, elmID, fmi_attr_id_fixedInternalStepSize, 0, + if (fmi3_xml_parse_attr_as_float64(context, elmID, FMI3_ATTR(fmi_attr_id_fixedInternalStepSize), 0, &md->coSimulation.fixedInternalStepSize, 0)) { return -1; } } - if (fmi3_xml_is_attr_defined(context, fmi_attr_id_recommendedIntermediateInputSmoothness)) { + if (fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_recommendedIntermediateInputSmoothness))) { md->coSimulation.hasRecommendedIntermediateInputSmoothness = 1; - if (fmi3_xml_parse_attr_as_int32(context, elmID, fmi_attr_id_recommendedIntermediateInputSmoothness, 0, + if (fmi3_xml_parse_attr_as_int32(context, elmID, FMI3_ATTR(fmi_attr_id_recommendedIntermediateInputSmoothness), 0, &md->coSimulation.recommendedIntermediateInputSmoothness, 0)) { return -1; @@ -709,7 +709,7 @@ int fmi3_xml_handle_File(fmi3_xml_parser_context_t *context, const char* data) { if(!bufName) return -1; /* */ - if( fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_File, fmi_attr_id_name, 1, bufName)) + if( fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_File), FMI3_ATTR(fmi_attr_id_name), 1, bufName)) return -1; return push_back_jm_string(context, &md->sourceFilesME, bufName); } @@ -729,7 +729,7 @@ int fmi3_xml_handle_FileCS(fmi3_xml_parser_context_t *context, const char* data) if(!bufName) return -1; /* */ - if( fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_File, fmi_attr_id_name, 1, bufName)) + if( fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_File), FMI3_ATTR(fmi_attr_id_name), 1, bufName)) return -1; return push_back_jm_string(context, &md->sourceFilesCS, bufName); } @@ -759,11 +759,11 @@ int fmi3_xml_handle_Category(fmi3_xml_parser_context_t *context, const char* dat if (!bufName) return -1; /* */ - if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Category, fmi_attr_id_name, 1, bufName)) + if (fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Category), FMI3_ATTR(fmi_attr_id_name), 1, bufName)) return -1; if (push_back_jm_string(context, &md->logCategories, bufName) < 0) return -1; - if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Category, fmi_attr_id_description, 0, bufName) < 0) return -1; + if (fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Category), FMI3_ATTR(fmi_attr_id_description), 0, bufName) < 0) return -1; if (push_back_jm_string(context, &md->logCategoryDescriptions, bufName) < 0) return -1; return 0; } @@ -780,18 +780,18 @@ int fmi3_xml_handle_DefaultExperiment(fmi3_xml_parser_context_t *context, const /* process the attributes */ /* save if attributes are defined */ - md->defaultExperiment.startTimeDefined = fmi3_xml_is_attr_defined(context, fmi_attr_id_startTime); - md->defaultExperiment.stopTimeDefined = fmi3_xml_is_attr_defined(context, fmi_attr_id_stopTime); - md->defaultExperiment.toleranceDefined = fmi3_xml_is_attr_defined(context, fmi_attr_id_tolerance); - md->defaultExperiment.stepSizeDefined = fmi3_xml_is_attr_defined(context, fmi_attr_id_stepSize); + md->defaultExperiment.startTimeDefined = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_startTime)); + md->defaultExperiment.stopTimeDefined = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_stopTime)); + md->defaultExperiment.toleranceDefined = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_tolerance)); + md->defaultExperiment.stepSizeDefined = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_stepSize)); /* save attribute values: from XML if exists else defaults */ /* NOTE: the default values are hard-coded in the API documentation as well */ return ( - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_DefaultExperiment, fmi_attr_id_startTime, 0, &md->defaultExperiment.startTime, 0) || - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_DefaultExperiment, fmi_attr_id_stopTime, 0, &md->defaultExperiment.stopTime, 1) || - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_DefaultExperiment, fmi_attr_id_tolerance, 0, &md->defaultExperiment.tolerance, FMI3_DEFAULT_EXPERIMENT_TOLERANCE) || - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_DefaultExperiment, fmi_attr_id_stepSize, 0, &md->defaultExperiment.stepSize, FMI3_DEFAULT_EXPERIMENT_STEPSIZE) + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_DefaultExperiment), FMI3_ATTR(fmi_attr_id_startTime), 0, &md->defaultExperiment.startTime, 0) || + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_DefaultExperiment), FMI3_ATTR(fmi_attr_id_stopTime), 0, &md->defaultExperiment.stopTime, 1) || + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_DefaultExperiment), FMI3_ATTR(fmi_attr_id_tolerance), 0, &md->defaultExperiment.tolerance, FMI3_DEFAULT_EXPERIMENT_TOLERANCE) || + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_DefaultExperiment), FMI3_ATTR(fmi_attr_id_stepSize), 0, &md->defaultExperiment.stepSize, FMI3_DEFAULT_EXPERIMENT_STEPSIZE) ); } else { diff --git a/src/XML/src/FMI3/fmi3_xml_model_description_scheme.h b/src/XML/src/FMI3/fmi3_xml_model_description_scheme.h index d086a195..2c62980c 100644 --- a/src/XML/src/FMI3/fmi3_xml_model_description_scheme.h +++ b/src/XML/src/FMI3/fmi3_xml_model_description_scheme.h @@ -22,10 +22,11 @@ extern "C" { #endif -/* Attributes common to modelDescription.xml & terminalsAndIcons.xml - * are listed in FMI3_XML_ATTRLIST_COMMON in fmi3_xml_parser.h - */ +/* Attribute names found in modelDescription.xml */ #define FMI3_XML_ATTRLIST_MODEL_DESCR(EXPAND_XML_ATTRNAME) \ + EXPAND_XML_ATTRNAME(fmiVersion) \ + EXPAND_XML_ATTRNAME(name) \ + EXPAND_XML_ATTRNAME(description) \ EXPAND_XML_ATTRNAME(factor) \ EXPAND_XML_ATTRNAME(offset) \ EXPAND_XML_ATTRNAME(inverse) \ @@ -99,6 +100,7 @@ extern "C" { EXPAND_XML_ATTRNAME(canReturnEarlyAfterIntermediateUpdate) \ EXPAND_XML_ATTRNAME(hasEventMode) +/* Element names found in modelDescription.xml */ #define FMI3_XML_ELMLIST_MODEL_DESCR(EXPAND_XML_ELMNAME) \ EXPAND_XML_ELMNAME(fmiModelDescription) \ EXPAND_XML_ELMNAME(ModelExchange) \ @@ -174,14 +176,14 @@ extern "C" { // XXX: fmi3_xml_elmID_none & fmi3_xml_elmID_Start are defined in fmi3_xml_parser.h, got good style /* - Define XML schema structure. Used to build the 'fmi3_xml_scheme_info_t' type (in fmi3_xml_parser.c). + Define XML schema structure. Used to build the 'fmi3_xml_scheme_modelDescription_info_t' type (in fmi3_xml_parser.c). @sib_idx: the index in a sequence among siblings @multi_elem: if the parent can have multiple elements of this type */ -/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */ +/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */ #define fmi3_xml_scheme_fmiModelDescription {fmi3_xml_elmID_none, fmi3_xml_elmID_none, 0, 0} #define fmi3_xml_scheme_ModelExchange {fmi3_xml_elmID_none, fmi3_xml_elmID_fmiModelDescription, 0, 0} #define fmi3_xml_scheme_SourceFiles {fmi3_xml_elmID_none, fmi3_xml_elmID_ModelExchange, 0, 0} diff --git a/src/XML/src/FMI3/fmi3_xml_model_structure.c b/src/XML/src/FMI3/fmi3_xml_model_structure.c index e22d5715..3603d136 100644 --- a/src/XML/src/FMI3/fmi3_xml_model_structure.c +++ b/src/XML/src/FMI3/fmi3_xml_model_structure.c @@ -227,7 +227,7 @@ int fmi3_xml_handle_ModelStructure(fmi3_xml_parser_context_t* context, const cha * Any errors when parsings will result in default dependencies = depends on everyhing */ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_dependencies_t* deps, + fmi3_xml_elm_t elmID, fmi3_xml_dependencies_t* deps, size_t* numDepInd, size_t* numDepKind) { /** @@ -248,7 +248,7 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, */ - if (fmi3_xml_get_attr_str(context, elmID, fmi_attr_id_dependencies, 0, &listInd)) { + if (fmi3_xml_get_attr_str(context, elmID, FMI3_ATTR(fmi_attr_id_dependencies), 0, &listInd)) { return -1; } if (listInd) { @@ -263,12 +263,12 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, if (!ch) break; if (sscanf(cur, "%lld", &ind) != 1) { fmi3_xml_parse_error(context, "XML element '%s': could not parse item %d, character '%c' in the list for attribute 'dependencies'", - fmi3_xml_elmid_to_name(elmID), *numDepInd, ch); + fmi3_xml_elmid_to_name(context, elmID), *numDepInd, ch); return -1; } if (ind < 0) { fmi3_xml_parse_error(context, "XML element '%s': Attribute 'dependencies' contains invalid value: %lld.", - fmi3_xml_elmid_to_name(elmID), ind); + fmi3_xml_elmid_to_name(context, elmID), ind); return -1; } if (!jm_vector_push_back(size_t)(&deps->dependenciesVRs, (size_t)ind)) { @@ -297,7 +297,7 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, */ - if (fmi3_xml_get_attr_str(context, elmID, fmi_attr_id_dependenciesKind, 0, &listKind)) { + if (fmi3_xml_get_attr_str(context, elmID, FMI3_ATTR(fmi_attr_id_dependenciesKind), 0, &listKind)) { return -1; } if (listKind) { @@ -331,11 +331,11 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, } else { fmi3_xml_parse_error(context, "XML element '%s': could not parse item %d in the list for attribute 'dependenciesKind'", - fmi3_xml_elmid_to_name(elmID), *numDepKind); + fmi3_xml_elmid_to_name(context, elmID), *numDepKind); return -1; } // Check possible invalid combinations of elmID & dependenciesKind entries - if ((elmID == fmi3_xml_elmID_InitialUnknown) && + if ((elmID.modelDescription == fmi3_xml_elmID_InitialUnknown) && ((kind == fmi3_dependencies_kind_fixed) || (kind == fmi3_dependencies_kind_tunable) || (kind == fmi3_dependencies_kind_discrete))) { fmi3_xml_parse_warning(context, "XML element 'InitialUnknown': '%s' is not allowed in list for attribute 'dependenciesKind'.", @@ -352,7 +352,7 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, /* both lists are present - the number of items must match */ if (*numDepInd != *numDepKind) { fmi3_xml_parse_error(context, "XML element '%s': different number of items (%u and %u) in the lists for 'dependencies' and 'dependenciesKind'", - fmi3_xml_elmid_to_name(elmID), *numDepInd, *numDepKind); + fmi3_xml_elmid_to_name(context, elmID), *numDepInd, *numDepKind); return -1; } jm_vector_push_back(size_t)(&deps->startIndex, totNumDep + *numDepInd); @@ -374,7 +374,7 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, } else if (listKind) { fmi3_xml_parse_error(context, "XML element '%s': if `dependenciesKind` attribute is present then the `dependencies` attribute must also be present.", - fmi3_xml_elmid_to_name(elmID)); + fmi3_xml_elmid_to_name(context, elmID)); return -1; } else { /* Dependencies attribute is missing, set default dependencies */ @@ -386,7 +386,7 @@ static int fmi3_xml_parse_dependencies(fmi3_xml_parser_context_t* context, /* Wrapper for #fmi3_xml_parse_dependencies, handling failed states */ static void fmi3_xml_parse_dependencies_error_wrapper(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_dependencies_t* deps) { + fmi3_xml_elm_t elmID, fmi3_xml_dependencies_t* deps) { // number of added dependecies(Kind) entries, these are needed to clean dependencies in case of failure to parse size_t numDepInd = 0; size_t numDepKind = 0; @@ -414,7 +414,7 @@ static void fmi3_xml_parse_dependencies_error_wrapper(fmi3_xml_parser_context_t* * and the dependencies are stored in return-arg 'deps'. */ int fmi3_xml_parse_unknown(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, + fmi3_xml_elm_t elmID, jm_vector(jm_voidp) *destVarList, fmi3_xml_dependencies_t* deps) { @@ -424,7 +424,7 @@ int fmi3_xml_parse_unknown(fmi3_xml_parser_context_t* context, fmi3_value_reference_t vr; fmi3_xml_variable_t* variable; - if (fmi3_xml_parse_attr_as_uint32(context, elmID, fmi_attr_id_valueReference, 1, &vr, 0)){ + if (fmi3_xml_parse_attr_as_uint32(context, elmID, FMI3_ATTR(fmi_attr_id_valueReference), 1, &vr, 0)){ fmi3_xml_set_model_structure_invalid(ms); return -1; } @@ -449,7 +449,7 @@ int fmi3_xml_handle_Output(fmi3_xml_parser_context_t* context, const char* data) fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_model_structure_t* ms = md->modelStructure; if (!data) { - if (fmi3_xml_parse_unknown(context, fmi3_xml_elmID_Output, &ms->outputs, ms->outputDeps)) { + if (fmi3_xml_parse_unknown(context, FMI3_ELM(fmi3_xml_elmID_Output), &ms->outputs, ms->outputDeps)) { return -1; } } else { @@ -471,7 +471,7 @@ int fmi3_xml_handle_ContinuousStateDerivative(fmi3_xml_parser_context_t* context fmi3_xml_model_structure_t* ms = md->modelStructure; if (!data) { /* perform the parsing */ - if (fmi3_xml_parse_unknown(context, fmi3_xml_elmID_ContinuousStateDerivative, + if (fmi3_xml_parse_unknown(context, FMI3_ELM(fmi3_xml_elmID_ContinuousStateDerivative), &ms->continuousStateDerivatives, ms->continuousStateDerivativeDeps)) { return -1; } @@ -502,7 +502,7 @@ int fmi3_xml_handle_ClockedState(fmi3_xml_parser_context_t* context, const char* fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_model_structure_t* ms = md->modelStructure; if (!data) { - if (fmi3_xml_parse_unknown(context, fmi3_xml_elmID_ClockedState, + if (fmi3_xml_parse_unknown(context, FMI3_ELM(fmi3_xml_elmID_ClockedState), &ms->clockedStates, ms->clockedStateDeps)) { return -1; } @@ -535,7 +535,7 @@ int fmi3_xml_handle_InitialUnknown(fmi3_xml_parser_context_t* context, const cha fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_model_structure_t* ms = md->modelStructure; if (!data) { - if (fmi3_xml_parse_unknown(context, fmi3_xml_elmID_InitialUnknown, &ms->initialUnknowns, ms->initialUnknownDeps)) { + if (fmi3_xml_parse_unknown(context, FMI3_ELM(fmi3_xml_elmID_InitialUnknown), &ms->initialUnknowns, ms->initialUnknownDeps)) { return -1; } } else { @@ -561,7 +561,7 @@ int fmi3_xml_handle_EventIndicator(fmi3_xml_parser_context_t* context, const cha } if (!data) { - if (fmi3_xml_parse_unknown(context, fmi3_xml_elmID_EventIndicator, + if (fmi3_xml_parse_unknown(context, FMI3_ELM(fmi3_xml_elmID_EventIndicator), &ms->eventIndicators, ms->eventIndicatorDeps)) { return -1; } diff --git a/src/XML/src/FMI3/fmi3_xml_parser.c b/src/XML/src/FMI3/fmi3_xml_parser.c index 048dbdaf..86ab401d 100644 --- a/src/XML/src/FMI3/fmi3_xml_parser.c +++ b/src/XML/src/FMI3/fmi3_xml_parser.c @@ -29,6 +29,7 @@ #include "../FMI/fmi_xml_terminals_and_icons_impl.h" #include "fmi3_xml_parser.h" #include "JM/jm_portability.h" +#include "fmi3_xml_parser_context_impl.h" // TODO: Really needed here? static const char* module = "FMI3XML"; @@ -41,45 +42,143 @@ typedef unsigned long long int fmi3_uint_buf_t; /* same size as fmi3_int_buf_t #define UINTXX_MIN (0) #define FMI3_FLOAT32_MAX (3.402823466e+38F) /* FLT_MAX from float.h is platform-dependent (doesn't have to be 32 bit) */ +// TODO: Move these + access functions into the parser_scheme file? #define ATTR_STR(attr) #attr, -const char *fmi3_xmlAttrNames[fmi3_xml_attr_number] = { - FMI3_XML_ATTRLIST(ATTR_STR) +const jm_string fmi3_modelDescription_xmlAttrNames[fmi3_xml_modelDescription_attr_number] = { + FMI3_XML_ATTRLIST_MODEL_DESCR(ATTR_STR) }; +const jm_string fmi3_termIcon_xmlAttrNames[fmi_xml_termIcon_attr_number] = { + FMI_XML_ATTRLIST_TERM_ICON(ATTR_STR) +}; + +static jm_string fmi3_xml_get_xml_attr_name(fmi3_xml_parser_context_t* context, const fmi3_xml_attr_t enu) { + const fmi3_xml_type_t xmlType = context->xmlType; + switch (xmlType) { + case fmi3_xml_type_modelDescription: + return fmi3_modelDescription_xmlAttrNames[enu.modelDescription]; + case fmi3_xml_type_terminalAndIcons: + return fmi3_termIcon_xmlAttrNames[enu.termIcon]; + } + return "unknown"; +} + /** * The expansion of below macro is also a macro. Example: * EXPAND_ELM_SCHEME(Float64) -> fmi3_xml_scheme_Float64 -> {fmi3_xml_elmID_SimpleType, fmi3_xml_elmID_TypeDefinitions, 0, 1} */ #define EXPAND_ELM_SCHEME(elm) fmi3_xml_scheme_##elm , - -/* Global array of all scheme_info_t. Index it with fmi3_xml_elm_enu_t entries. */ -fmi3_xml_scheme_info_t fmi3_xml_scheme_info[fmi3_xml_elm_number] = { +/* Global array of all modelDescription scheme_info_t. Index it with fmi3_xml_elm_modelDescription_enu_t entries. */ +const fmi3_xml_scheme_modelDescription_info_t fmi3_xml_scheme_modelDescription_info[fmi3_xml_elm_number] = { FMI3_XML_ELMLIST_MODEL_DESCR(EXPAND_ELM_SCHEME) - FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_SCHEME) - {fmi3_xml_elm_actual_number,0,0}, + {fmi3_xml_elm_actual_number, 0, 0}, FMI3_XML_ELMLIST_ALT_MODEL_DESCR (EXPAND_ELM_SCHEME) - FMI_XML_ELMLIST_ALT_TERM_ICON (EXPAND_ELM_SCHEME) FMI3_XML_ELMLIST_ABSTRACT_MODEL_DESCR(EXPAND_ELM_SCHEME) }; +#define EXPAND_ELM_SCHEME_TERMICON(elm) fmi_xml_scheme_termIcon_##elm , +/* Global array of all terminalsAndIcons scheme_info_t. Index it with fmi_xml_elm_termIcon_enu_t entries. */ +fmi_xml_scheme_termIcon_info_t fmi_xml_scheme_termIcon_info[fmi_xml_elm_termIcon_number] = { + FMI_XML_ELMLIST_TERM_ICON(EXPAND_ELM_SCHEME_TERMICON) + {fmi_xml_elm_termIcon_actual_number, 0, 0}, + FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_SCHEME_TERMICON) +}; + +// TODO: Move to more suitable place? +static fmi3_xml_scheme_info_t fmi3_xml_get_scheme_info(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t enu) { + const fmi3_xml_type_t xmlType = context->xmlType; + + fmi3_xml_scheme_modelDescription_info_t info_modelDescription; + fmi_xml_scheme_termIcon_info_t info_termIcon; + + fmi3_xml_scheme_info_t ret; + switch (xmlType) { + case fmi3_xml_type_modelDescription: + info_modelDescription = fmi3_xml_scheme_modelDescription_info[enu.modelDescription]; + + ret.superID = FMI3_ELM(info_modelDescription.superID); + ret.parentID = FMI3_ELM(info_modelDescription.parentID); + ret.siblingIndex = info_modelDescription.siblingIndex; + ret.multipleAllowed = info_modelDescription.multipleAllowed; + break; + case fmi3_xml_type_terminalAndIcons: + info_termIcon = fmi_xml_scheme_termIcon_info[enu.termIcon]; + + ret.superID = FMI_ELM_TERMICON(info_termIcon.superID); + ret.parentID = FMI_ELM_TERMICON(info_termIcon.parentID); + ret.siblingIndex = info_termIcon.siblingIndex; + ret.multipleAllowed = info_termIcon.multipleAllowed; + break; + default: + // erroneous output + ret.superID = FMI3_ELM_ANY(FMI_XML_ELMID_NONE); + ret.parentID = FMI3_ELM_ANY(FMI_XML_ELMID_NONE); + ret.siblingIndex = -1; + ret.multipleAllowed = -1; + } + return ret; +} + #define EXPAND_ELM_NAME_FMI3(elm) { #elm, fmi3_xml_handle_##elm, fmi3_xml_elmID_##elm}, -#define EXPAND_ELM_NAME_FMI_TERM_ICON(elm) { #elm, fmi_xml_handle_##elm, fmi3_xml_elmID_##elm}, +#define EXPAND_ELM_NAME_FMI_TERM_ICON(elm) { #elm, fmi_xml_handle_##elm, fmi_xml_elmID_termIcon_##elm}, /** - * Global array of all defined fmi3_xml_element_handle_map_t structs. + * Global array of all defined fmi3_xml_modelDescription_element_handle_map_t structs. * Typical use: * Parse element name, from element name find ID, use ID to index this * array. */ -fmi3_xml_element_handle_map_t fmi3_element_handle_map[fmi3_xml_elm_number] = { +const fmi3_xml_modelDescription_element_handle_map_t fmi3_modelDescription_element_handle_map[fmi3_xml_elm_number] = { FMI3_XML_ELMLIST_MODEL_DESCR(EXPAND_ELM_NAME_FMI3) - FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_NAME_FMI_TERM_ICON) { NULL, NULL, fmi3_xml_elm_actual_number}, FMI3_XML_ELMLIST_ALT_MODEL_DESCR (EXPAND_ELM_NAME_FMI3) - FMI_XML_ELMLIST_ALT_TERM_ICON (EXPAND_ELM_NAME_FMI_TERM_ICON) FMI3_XML_ELMLIST_ABSTRACT_MODEL_DESCR(EXPAND_ELM_NAME_FMI3) }; +const fmi_xml_termIcon_element_handle_map_t fmi_termIcon_element_handle_map[fmi_xml_elm_termIcon_number] = { + FMI_XML_ELMLIST_TERM_ICON(EXPAND_ELM_NAME_FMI_TERM_ICON) + { NULL, NULL, fmi_xml_elm_termIcon_actual_number}, + FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_NAME_FMI_TERM_ICON) +}; + +// TODO: Move to more suitable place? +static fmi3_xml_element_handle_map_t fmi3_xml_get_element_handle(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t enu) { + const fmi3_xml_type_t xmlType = context->xmlType; + + fmi3_xml_modelDescription_element_handle_map_t map_modelDescription; + fmi_xml_termIcon_element_handle_map_t map_termIcon; + + fmi3_xml_element_handle_map_t ret; + switch (xmlType) { + case fmi3_xml_type_modelDescription: + map_modelDescription = fmi3_modelDescription_element_handle_map[enu.modelDescription]; + + ret.elementName = map_modelDescription.elementName; + ret.elementHandle = (fmi3_xml_element_handle_ft) map_modelDescription.elementHandle; + ret.elemID = FMI3_ELM(map_modelDescription.elemID); + break; + case fmi3_xml_type_terminalAndIcons: + map_termIcon = fmi_termIcon_element_handle_map[enu.termIcon]; + + ret.elementName = map_termIcon.elementName; + ret.elementHandle = (fmi3_xml_element_handle_ft) map_termIcon.elementHandle; + ret.elemID = FMI_ELM_TERMICON(map_termIcon.elemID); + break; + default: + // erroneous output + ret.elementName = "unknown"; + ret.elementHandle = NULL; + ret.elemID = FMI3_ELM_ANY(FMI_XML_ELMID_NONE); + } + return ret; +} + +// TODO: Move to better place? +const char* fmi3_xml_elmid_to_name(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id){ + fmi3_xml_element_handle_map_t item = fmi3_xml_get_element_handle(context, id); + return item.elementName; +} + const fmi3_xml_primitive_types_t PRIMITIVE_TYPES = { { "Float64", @@ -211,10 +310,10 @@ void fmi3_xml_parse_free_context(fmi3_xml_parser_context_t* context) { /** * Raises a generic parse error for the given attribute. */ -void fmi3_xml_parse_attr_error(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +void fmi3_xml_parse_attr_error(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, const char* attrStr) { - jm_string elmName = fmi3_element_handle_map[elmID].elementName; - jm_string attrName = fmi3_xmlAttrNames[attrID]; + jm_string elmName = fmi3_xml_elmid_to_name(context, elmID); + jm_string attrName = fmi3_xml_get_xml_attr_name(context, attrID); fmi3_xml_parse_error(context, "XML element '%s': failed to parse attribute %s='%s'", elmName, attrName, attrStr); } @@ -235,11 +334,19 @@ static size_t fmi3_xml_string_char_count(const char* str, char ch) { /* Get attribute as string without clearing the buffer entry * XXX: Be careful with using this, since the buffer entry will still be present in later elements. */ -jm_string fmi3_xml_peek_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_attr_enu_t attrID) { - return jm_vector_get_item(jm_string)(context->attrMapById, attrID); +jm_string fmi3_xml_peek_attr_str(fmi3_xml_parser_context_t* context, const fmi3_xml_attr_t attrID) { + const fmi3_xml_type_t xmlType = context->xmlType; + switch (xmlType) { + case fmi3_xml_type_modelDescription: + return jm_vector_get_item(jm_string)(context->attrMapById, attrID.modelDescription); + case fmi3_xml_type_terminalAndIcons: + return jm_vector_get_item(jm_string)(context->attrMapById, attrID.termIcon); + default: + return "unknown"; + } } -int fmi3_xml_is_attr_defined(fmi3_xml_parser_context_t* context, fmi3_xml_attr_enu_t attrID) { +int fmi3_xml_is_attr_defined(fmi3_xml_parser_context_t* context, const fmi3_xml_attr_t attrID) { return (fmi3_xml_peek_attr_str(context, attrID) != NULL); } @@ -247,16 +354,16 @@ int fmi3_xml_is_attr_defined(fmi3_xml_parser_context_t* context, fmi3_xml_attr_e * Read value from parse buffer and clear the buffer entry. * @param[out] valp : pointer to attribute value (memory still owned by expat) */ -int fmi3_xml_get_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_get_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, const char** valp) { /* Read and clear attribute */ jm_string value = fmi3_xml_peek_attr_str(context, attrID); - jm_vector_set_item(jm_string)(context->attrMapById, attrID, 0); + jm_vector_set_item(jm_string)(context->attrMapById, attrID.any, 0); if (!value && required) { - jm_string elmName = fmi3_element_handle_map[elmID].elementName; - jm_string attrName = fmi3_xmlAttrNames[attrID]; + jm_string elmName = fmi3_xml_elmid_to_name(context, elmID); + jm_string attrName = fmi3_xml_get_xml_attr_name(context, attrID); fmi3_xml_parse_error(context, "Parsing XML element '%s': required attribute '%s' not found", elmName, attrName); return -1; } @@ -269,7 +376,7 @@ int fmi3_xml_get_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t * Reads the attribute from attribute buffer as jm_vector(char). This will clear the attribute from the buffer. * @param field (return arg): Attribute value (memory owned by this vector) */ -int fmi3_xml_parse_attr_as_string(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_string(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, jm_vector(char)* field) { jm_string val; @@ -292,8 +399,8 @@ int fmi3_xml_parse_attr_as_string(fmi3_xml_parser_context_t* context, fmi3_xml_e /* Error check */ if (jm_vector_resize(char)(field, len) < len) { - jm_string elmName = fmi3_element_handle_map[elmID].elementName; - jm_string attrName = fmi3_xmlAttrNames[attrID]; + jm_string elmName = fmi3_xml_elmid_to_name(context, elmID); + jm_string attrName = fmi3_xml_get_xml_attr_name(context, attrID); fmi3_xml_parse_fatal(context, "XML element '%s': could not allocate memory for setting '%s'='%s'", elmName, attrName, val); return -1; } @@ -304,7 +411,7 @@ int fmi3_xml_parse_attr_as_string(fmi3_xml_parser_context_t* context, fmi3_xml_e return 0; } -int fmi3_xml_parse_attr_as_enum(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_enum(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, unsigned int* field, unsigned int defaultVal, jm_name_ID_map_t* nameMap) { int i = 0; @@ -332,15 +439,15 @@ int fmi3_xml_parse_attr_as_enum(fmi3_xml_parser_context_t* context, fmi3_xml_elm return 0; } -int fmi3_xml_parse_attr_as_boolean(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, - fmi3_xml_attr_enu_t attrID, int required, unsigned int* field, unsigned int defaultVal) +int fmi3_xml_parse_attr_as_boolean(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, + const fmi3_xml_attr_t attrID, int required, unsigned int* field, unsigned int defaultVal) { jm_name_ID_map_t fmi_boolean_i_dMap[] = {{"true", 1}, {"false", 0}, {"1", 1}, {"0", 0}, {0, 0}}; return fmi3_xml_parse_attr_as_enum(context,elmID, attrID,required, field, defaultVal, fmi_boolean_i_dMap); } // TODO: For FMI3, do we want to use bool in the getters for boolean attributes, or keep using unsigned int? -int fmi3_xml_parse_attr_as_bool(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_bool(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, bool* field, bool defaultVal) { jm_string strVal; @@ -363,8 +470,8 @@ int fmi3_xml_parse_attr_as_bool(fmi3_xml_parser_context_t* context, fmi3_xml_elm } else if (strcmp(strVal, "false") == 0 || strcmp(strVal, "0") == 0) { *field = false; } else { - jm_string elmName = fmi3_element_handle_map[elmID].elementName; - jm_string attrName = fmi3_xmlAttrNames[attrID]; + jm_string elmName = fmi3_xml_elmid_to_name(context, elmID); + jm_string attrName = fmi3_xml_get_xml_attr_name(context, attrID); fmi3_xml_parse_error(context, "XML element '%s': could not parse value for boolean attribute '%s'='%s'", elmName, attrName, strVal); return -1; @@ -383,8 +490,8 @@ int fmi3_xml_parse_attr_as_bool(fmi3_xml_parser_context_t* context, fmi3_xml_elm */ int fmi3_xml_parse_attr_valueref_list( fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, - fmi3_xml_attr_enu_t attrID, + fmi3_xml_elm_t elmID, + const fmi3_xml_attr_t attrID, int required, jm_vector(fmi3_value_reference_t)* vrs) { @@ -583,7 +690,7 @@ static int fmi3_xml_str_to_intXX(fmi3_xml_parser_context_t* context, int require * @param defaultVal: pointer to default value that will be used if attribute wasn't defined - * needs be of same type as 'primType' */ -int fmi3_xml_parse_attr_as_sizet(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_sizet(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, size_t* field, size_t* defaultVal) { const fmi3_xml_primitive_type_t* primType; @@ -615,7 +722,7 @@ int fmi3_xml_parse_attr_as_sizet(fmi3_xml_parser_context_t* context, fmi3_xml_el * @param defaultVal: pointer to default value that will be used if attribute wasn't defined - * needs be of same type as 'primType' */ -int fmi3_xml_parse_attr_as_intXX(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_intXX(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, void* field, void* defaultVal, const fmi3_xml_primitive_type_t* primType) { int ret; @@ -691,7 +798,7 @@ static int fmi3_xml_str_to_floatXX(fmi3_xml_parser_context_t* context, int requi field: where the float value will be stored (return arg) defaultVal: pointer to default value that will be used if attribute wasn't defined */ -int fmi3_xml_parse_attr_as_floatXX(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_floatXX(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, void* field, void* defaultVal, const fmi3_xml_primitive_type_t* primType) { int ret; jm_string strVal; @@ -711,7 +818,7 @@ int fmi3_xml_parse_attr_as_floatXX(fmi3_xml_parser_context_t* context, fmi3_xml_ /* Creates a wrapper for when the type to parse is known */ #define gen_fmi3_xml_parse_attr_as_TYPEXX(TYPE, TYPEXX) \ - int fmi3_xml_parse_attr_as_##TYPE(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, \ + int fmi3_xml_parse_attr_as_##TYPE(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, \ int required, fmi3_##TYPE##_t* field, fmi3_##TYPE##_t defaultVal) { \ return fmi3_xml_parse_attr_as_##TYPEXX(context, elmID, attrID, required, field, &defaultVal, &PRIMITIVE_TYPES.TYPE); \ } @@ -854,7 +961,7 @@ static int fmi3_xml_str_to_array( * @param arrPtr (return arg): where the array will be stored * @param arrSize (return arg): size of 'arrPtr' */ -int fmi3_xml_parse_attr_as_array(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, +int fmi3_xml_parse_attr_as_array(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_attr_t attrID, int required, void** arrPtr, size_t* arrSize, jm_string str, const fmi3_xml_primitive_type_t* primType) { if (!str) { @@ -865,8 +972,8 @@ int fmi3_xml_parse_attr_as_array(fmi3_xml_parser_context_t* context, fmi3_xml_el /* write all attributes to array of correct type */ if (fmi3_xml_str_to_array(context, str, arrPtr, arrSize, primType)) { - jm_string elmName = fmi3_element_handle_map[elmID].elementName; - jm_string attrName = fmi3_xmlAttrNames[attrID]; + jm_string elmName = fmi3_xml_elmid_to_name(context, elmID); + jm_string attrName = fmi3_xml_get_xml_attr_name(context, attrID); fmi3_xml_parse_error(context, "XML element '%s': could not parse value for %s attribute '%s'='%s'", elmName, primType->name, attrName, str); return -1; @@ -877,7 +984,7 @@ int fmi3_xml_parse_attr_as_array(fmi3_xml_parser_context_t* context, fmi3_xml_el int fmi3_xml_alloc_parse_buffer(fmi3_xml_parser_context_t* context, size_t items) { jm_vector(jm_voidp)* parseBuffer = &context->parseBuffer; - if (jm_vector_init(jm_voidp)(parseBuffer,items,context->callbacks) < items) { + if (jm_vector_init(jm_voidp)(parseBuffer, items, context->callbacks) < items) { fmi3_xml_parse_fatal(context, "Could not allocate buffer for parsing XML"); return -1; } @@ -923,16 +1030,46 @@ jm_vector(char)* fmi3_xml_reserve_parse_buffer(fmi3_xml_parser_context_t* contex return item; } -int fmi3_create_attr_map(fmi3_xml_parser_context_t* context) { +// Get size of ATTRIBUTE enum based on xmlType +static size_t fmi3_xml_get_attr_enum_size(fmi3_xml_parser_context_t* context) { + const fmi3_xml_type_t xmlType = context->xmlType; + switch (xmlType) { + case fmi3_xml_type_modelDescription: + return (size_t) fmi3_xml_modelDescription_attr_number; + case fmi3_xml_type_terminalAndIcons: + return (size_t) fmi_xml_termIcon_attr_number; + default: + // erroneous + return 0; + } +} + +// Get size of ELEMENT enum based on xmlType +static size_t fmi3_xml_get_elm_enum_size_actual(fmi3_xml_parser_context_t* context) { + const fmi3_xml_type_t xmlType = context->xmlType; + switch (xmlType) { + case fmi3_xml_type_modelDescription: + return (size_t) fmi3_xml_elm_actual_number; + case fmi3_xml_type_terminalAndIcons: + return (size_t) fmi_xml_elm_termIcon_actual_number; + default: + // erroneous + return 0; + } +} + +// TODO: Move to better place? +static int fmi3_create_attr_map(fmi3_xml_parser_context_t* context) { int i; - context->attrMapById = jm_vector_alloc(jm_string)(fmi3_xml_attr_number, fmi3_xml_attr_number, context->callbacks); + size_t attrEnumSize = fmi3_xml_get_attr_enum_size(context); + context->attrMapById = jm_vector_alloc(jm_string)(attrEnumSize, attrEnumSize, context->callbacks); if (!context->attrMapById) return -1; - context->attrMapByName = jm_vector_alloc(jm_named_ptr)(fmi3_xml_attr_number, fmi3_xml_attr_number, context->callbacks); + context->attrMapByName = jm_vector_alloc(jm_named_ptr)(attrEnumSize, attrEnumSize, context->callbacks); if (!context->attrMapByName) return -1; - for(i = 0; i < fmi3_xml_attr_number; i++) { + for (i = 0; i < attrEnumSize; i++) { jm_named_ptr map; jm_vector_set_item(jm_string)(context->attrMapById, i, 0); - map.name = fmi3_xmlAttrNames[i]; + map.name = fmi3_xml_get_xml_attr_name(context, FMI3_ATTR_ANY(i)); map.ptr = (void*)(jm_vector_get_itemp(jm_string)(context->attrMapById, i)); jm_vector_set_item(jm_named_ptr)(context->attrMapByName, i, map); } @@ -940,12 +1077,15 @@ int fmi3_create_attr_map(fmi3_xml_parser_context_t* context) { return 0; } -int fmi3_create_elm_map(fmi3_xml_parser_context_t* context) { - size_t i; - context->elmMap = jm_vector_alloc(fmi3_xml_element_handle_map_t)(fmi3_xml_elm_actual_number, fmi3_xml_elm_number, context->callbacks); +// TODO: Move to better place? +static int fmi3_create_elm_map(fmi3_xml_parser_context_t* context) { + int i; + size_t attrEnumSize = fmi3_xml_get_attr_enum_size(context); + size_t elmEnumSizeActual = fmi3_xml_get_elm_enum_size_actual(context); + context->elmMap = jm_vector_alloc(fmi3_xml_element_handle_map_t)(elmEnumSizeActual, attrEnumSize, context->callbacks); if (!context->elmMap) return -1; - for(i = 0; i < fmi3_xml_elm_actual_number; i++) { - fmi3_xml_element_handle_map_t item = fmi3_element_handle_map[i]; + for (i = 0; i < elmEnumSizeActual; i++) { + fmi3_xml_element_handle_map_t item = fmi3_xml_get_element_handle(context, FMI3_ELM_ANY(i)); jm_vector_set_item(fmi3_xml_element_handle_map_t)(context->elmMap, i, item); } jm_vector_qsort(fmi3_xml_element_handle_map_t)(context->elmMap, fmi3_xml_compare_elmName); @@ -953,7 +1093,7 @@ int fmi3_create_elm_map(fmi3_xml_parser_context_t* context) { } /** - * Sets the elementHandle and elemID for an item in the'fmi3_element_handle_map' + * Sets the elementHandle and elemID for an item in the 'fmi3_xml_element_handle_map_t' * array. * Sample use case: * When we parse an XML element name, we must know its context. For example, @@ -964,18 +1104,18 @@ int fmi3_create_elm_map(fmi3_xml_parser_context_t* context) { * * arg elm: * the actual XML element name, the item to change will be the one in - * 'fmi3_element_handle_map' that has this name + * 'fmi3_modelDescription_element_handle_map' that has this name * arg id: * get the handle and ID corresponding to the main or alternative XML * element */ -void fmi3_xml_set_element_handle(fmi3_xml_parser_context_t* context, const char* elm, fmi3_xml_elm_enu_t id) { +void fmi3_xml_set_element_handle(fmi3_xml_parser_context_t* context, const char* elm, fmi3_xml_elm_t id) { fmi3_xml_element_handle_map_t keyEl; fmi3_xml_element_handle_map_t* currentElMap; keyEl.elementName = elm; currentElMap = jm_vector_bsearch(fmi3_xml_element_handle_map_t)(context->elmMap, &keyEl, fmi3_xml_compare_elmName); - currentElMap->elementHandle = fmi3_element_handle_map[id].elementHandle;; + currentElMap->elementHandle = fmi3_xml_get_element_handle(context, id).elementHandle;; currentElMap->elemID = id; } @@ -983,31 +1123,31 @@ void fmi3_xml_set_element_handle(fmi3_xml_parser_context_t* context, const char* * Returns true if parent element's type or super type (recursively) matches * the expected type. */ -int fmi3_xml_is_valid_parent(fmi3_xml_elm_enu_t child_id, fmi3_xml_elm_enu_t parent_id) { - fmi3_xml_elm_enu_t p_id_expected = fmi3_xml_scheme_info[child_id].parentID; +int fmi3_xml_is_valid_parent(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t child_id, fmi3_xml_elm_t parent_id) { + fmi3_xml_elm_t p_id_expected = fmi3_xml_get_scheme_info(context, child_id).parentID; - while (parent_id != p_id_expected && parent_id != fmi3_xml_elmID_none) { - parent_id = fmi3_xml_scheme_info[parent_id].superID; + while (parent_id.any != p_id_expected.any && parent_id.any != FMI_XML_ELMID_NONE) { + parent_id = fmi3_xml_get_scheme_info(context, parent_id).superID; } - return parent_id == p_id_expected; + return parent_id.any == p_id_expected.any; } /** * Returns top level super type of the element. */ -int fmi3_xml_get_super_type_rec(fmi3_xml_elm_enu_t id) { - fmi3_xml_elm_enu_t id_top = id; - while (fmi3_xml_scheme_info[id_top].superID != fmi3_xml_elmID_none) { - id_top = fmi3_xml_scheme_info[id_top].superID; +int fmi3_xml_get_super_type_rec(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id) { + fmi3_xml_elm_t id_top = id; + while ((fmi3_xml_get_scheme_info(context, id_top).superID).any != FMI_XML_ELMID_NONE) { + id_top = fmi3_xml_get_scheme_info(context, id_top).superID; } - return id_top; + return id_top.any; } /** * Returns true if the top-level super types are the same. */ -int fmi3_xml_are_same_type(fmi3_xml_elm_enu_t id1, fmi3_xml_elm_enu_t id2) { - return fmi3_xml_get_super_type_rec(id1) == fmi3_xml_get_super_type_rec(id2); +int fmi3_xml_are_same_type(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id1, fmi3_xml_elm_t id2) { + return fmi3_xml_get_super_type_rec(context, id1) == fmi3_xml_get_super_type_rec(context, id2); } /** @@ -1025,10 +1165,11 @@ int fmi3_xml_are_same_type(fmi3_xml_elm_enu_t id1, fmi3_xml_elm_enu_t id2) { static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const char **attr) { fmi3_xml_element_handle_map_t keyEl; fmi3_xml_element_handle_map_t* currentElMap; - fmi3_xml_elm_enu_t currentID; + fmi3_xml_elm_t currentID; int i; fmi3_xml_parser_context_t* context = c; context->has_produced_data_warning = 0; + size_t attrEnumSize = fmi3_xml_get_attr_enum_size(context); if (context->useAnyHandleFlg) { fmi3_xml_callbacks_t* anyH = context->anyHandle; @@ -1069,19 +1210,19 @@ static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const cha context->currentElemIdStartTag = currentID; /* Check that parent-child & siblings are fine */ { - fmi3_xml_elm_enu_t parentID = context->currentElmID; - fmi3_xml_elm_enu_t siblingID = context->lastSiblingElemId; + fmi3_xml_elm_t parentID = context->currentElmID; + fmi3_xml_elm_t siblingID = context->lastSiblingElemId; - if (!fmi3_xml_is_valid_parent(currentID, parentID)) { + if (!fmi3_xml_is_valid_parent(context, currentID, parentID)) { jm_log_error(context->callbacks, module, "[Line:%u] XML element '%s' cannot be placed inside '%s', skipping", - XML_GetCurrentLineNumber(context->parser), elm, fmi3_element_handle_map[parentID].elementName); + XML_GetCurrentLineNumber(context->parser), elm, fmi3_xml_elmid_to_name(context, parentID)); context->skipElementCnt = 1; return; } - if (siblingID != fmi3_xml_elmID_none) { - if (fmi3_xml_are_same_type(currentID, siblingID)) { - if (!(fmi3_xml_scheme_info[currentID].multipleAllowed && fmi3_xml_scheme_info[siblingID].multipleAllowed)) { + if (siblingID.any != FMI_XML_ELMID_NONE) { + if (fmi3_xml_are_same_type(context, currentID, siblingID)) { + if (!(fmi3_xml_get_scheme_info(context, currentID).multipleAllowed && fmi3_xml_get_scheme_info(context, siblingID).multipleAllowed)) { jm_log_error(context->callbacks, module, "[Line:%u] Multiple instances of XML element '%s' are not allowed, skipping", XML_GetCurrentLineNumber(context->parser), elm); @@ -1089,20 +1230,20 @@ static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const cha return; } } else { - int lastSiblingIndex = fmi3_xml_scheme_info[siblingID].siblingIndex; - int curSiblingIndex = fmi3_xml_scheme_info[currentID].siblingIndex; + int lastSiblingIndex = fmi3_xml_get_scheme_info(context, siblingID).siblingIndex; + int curSiblingIndex = fmi3_xml_get_scheme_info(context, currentID).siblingIndex; if (lastSiblingIndex >= curSiblingIndex) { jm_log_error(context->callbacks, module, "[Line:%u] XML element '%s' cannot be placed after element '%s', skipping", - XML_GetCurrentLineNumber(context->parser), elm, fmi3_element_handle_map[siblingID].elementName); + XML_GetCurrentLineNumber(context->parser), elm, fmi3_xml_elmid_to_name(context, siblingID)); context->skipElementCnt = 1; return; } } } /* lastSiblingElemId references the previous sibling-element's id - set it to 'none' before handling children. */ - context->lastSiblingElemId = fmi3_xml_elmID_none; + context->lastSiblingElemId.any = FMI_XML_ELMID_NONE; } /* process the attributes */ @@ -1163,7 +1304,7 @@ static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const cha if (currentElMap->elementHandle(context, 0)) { // Need to clear buffer, otherwise non-parsed attributes of elements that failed // to parse will be parsed with next element - for (int i = 0; i < fmi3_xml_attr_number; i++) { + for (int i = 0; i < attrEnumSize; i++) { if (jm_vector_get_item(jm_string)(context->attrMapById, i)) { jm_vector_set_item(jm_string)(context->attrMapById, i, NULL); } @@ -1173,15 +1314,16 @@ static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const cha } if (context->skipElementCnt) return; /* check that the element handler has processed all the attributes */ - for (i = 0; i < fmi3_xml_attr_number; i++) { + for (i = 0; i < attrEnumSize; i++) { if (jm_vector_get_item(jm_string)(context->attrMapById, i)) { // Element has not been processed because no handler exists - jm_log_warning(context->callbacks,module, "Attribute '%s' not processed by element '%s' handle", fmi3_xmlAttrNames[i], elm); + jm_log_warning(context->callbacks, module, "Attribute '%s' not processed by element '%s' handle", + fmi3_xml_get_xml_attr_name(context, FMI3_ATTR_ANY(i)), elm); jm_vector_set_item(jm_string)(context->attrMapById, i, NULL); } } - if (context -> currentElmID != fmi3_xml_elmID_none) { /* with nested elements: put the parent on the stack */ - jm_stack_push(int)(&context->elmStack, context -> currentElmID); + if (context->currentElmID.any != FMI_XML_ELMID_NONE) { /* with nested elements: put the parent on the stack */ + jm_stack_push(int)(&context->elmStack, context->currentElmID.any); } context -> currentElmID = currentID; } @@ -1197,7 +1339,7 @@ static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const cha static void XMLCALL fmi3_parse_element_end(void* c, const char *elm) { fmi3_xml_element_handle_map_t keyEl; fmi3_xml_element_handle_map_t* currentElMap; - fmi3_xml_elm_enu_t currentID; + fmi3_xml_elm_t currentID; fmi3_xml_parser_context_t* context = c; if (context->useAnyHandleFlg && (context->anyElmCount > 0)) { @@ -1226,17 +1368,16 @@ static void XMLCALL fmi3_parse_element_end(void* c, const char *elm) { } currentID = currentElMap->elemID; - if (currentID != context -> currentElmID) { + if (currentID.any != context->currentElmID.any) { /* missmatch error */ fmi3_xml_parse_fatal(context, "Element end '%s' does not match element start '%s' in XML", elm, - fmi3_element_handle_map[context -> currentElmID].elementName); + fmi3_xml_elmid_to_name(context, context -> currentElmID)); return; } jm_vector_push_back(char)(&context->elmData, 0); if (currentElMap->elementHandle(context, jm_vector_get_itemp(char)(&context->elmData, 0) )) { - /* context->modelDescription->hasParsingError = 1;*/ return; } jm_vector_resize(char)(&context->elmData, 0); @@ -1245,10 +1386,9 @@ static void XMLCALL fmi3_parse_element_end(void* c, const char *elm) { context->lastSiblingElemId = currentID; if (jm_stack_is_empty(int)(&context->elmStack)) { - context -> currentElmID = fmi3_xml_elmID_none; - } - else { - context -> currentElmID = (fmi3_xml_elm_enu_t)jm_stack_pop(int)(&context->elmStack); + context->currentElmID.any = FMI_XML_ELMID_NONE; + } else { + context->currentElmID = FMI3_ELM_ANY(jm_stack_pop(int)(&context->elmStack)); } } @@ -1290,6 +1430,24 @@ static void XMLCALL fmi3_parse_element_data(void* c, const XML_Char *s, int len) } } +/* Allocate fmi3_xml_parser_context_t with a given xmlType */ +static fmi3_xml_parser_context_t* fmi3_xml_allocate_parser_context( + jm_callbacks* callbacks, const fmi3_xml_type_t type) { + fmi3_xml_parser_context_t* context; + // REQUIRES xmlType to be first element in struct + fmi3_xml_parser_context_t typedContext = {type}; + + context = (fmi3_xml_parser_context_t*)callbacks->calloc(1, sizeof(fmi3_xml_parser_context_t)); + if (!context) { + jm_log_fatal(callbacks, "FMIXML", "Could not allocate memory for XML parser context"); + } + // hacky way of getting around not being able to set a const variable when using calloc/malloc + memcpy(context, &typedContext, sizeof(struct fmi3_xml_parser_context_t)); + + context->callbacks = callbacks; + return context; +} + int fmi3_xml_parse_model_description(fmi3_xml_model_description_t* md, const char* filename, fmi3_xml_callbacks_t* xml_callbacks) { @@ -1298,11 +1456,8 @@ int fmi3_xml_parse_model_description(fmi3_xml_model_description_t* md, XML_Parser parser = NULL; FILE* file; - context = (fmi3_xml_parser_context_t*)md->callbacks->calloc(1, sizeof(fmi3_xml_parser_context_t)); - if (!context) { - jm_log_fatal(md->callbacks, "FMIXML", "Could not allocate memory for XML parser context"); - } - context->callbacks = md->callbacks; + context = fmi3_xml_allocate_parser_context(md->callbacks, fmi3_xml_type_modelDescription); + context->modelDescription = md; if (fmi3_xml_alloc_parse_buffer(context, 16)) return -1; if (fmi3_create_attr_map(context) || fmi3_create_elm_map(context)) { @@ -1317,8 +1472,8 @@ int fmi3_xml_parse_model_description(fmi3_xml_model_description_t* md, jm_vector_init(char)(&context->variableStartAttr, 0, context->callbacks); jm_vector_init(jm_voidp)(&context->currentStartVariableValues, 0, context->callbacks); - context->lastSiblingElemId = fmi3_xml_elmID_none; - context->currentElmID = fmi3_xml_elmID_none; + context->lastSiblingElemId.modelDescription = fmi3_xml_elmID_none; + context->currentElmID.modelDescription = fmi3_xml_elmID_none; context->anyElmCount = 0; context->useAnyHandleFlg = 0; context->useAnyHandleFlgTermIcon = 0; @@ -1398,11 +1553,7 @@ int fmi3_xml_parse_terminals_and_icons(fmi_xml_terminals_and_icons_t* termIcon, XML_Parser parser = NULL; FILE* file; - context = (fmi3_xml_parser_context_t*)termIcon->callbacks->calloc(1, sizeof(fmi3_xml_parser_context_t)); - if (!context) { - jm_log_fatal(termIcon->callbacks, "FMIXML", "Could not allocate memory for XML parser context"); - } - context->callbacks = termIcon->callbacks; + context = fmi3_xml_allocate_parser_context(termIcon->callbacks, fmi3_xml_type_terminalAndIcons); // try to open file before doing parser initialization file = fopen(filename, "rb"); @@ -1424,8 +1575,8 @@ int fmi3_xml_parse_terminals_and_icons(fmi_xml_terminals_and_icons_t* termIcon, jm_stack_init(int)(&context->elmStack, context->callbacks); jm_vector_init(char)(&context->elmData, 0, context->callbacks); - context->lastSiblingElemId = fmi3_xml_elmID_none; - context->currentElmID = fmi3_xml_elmID_none; + context->lastSiblingElemId.termIcon = fmi_xml_elmID_termIcon_none; + context->currentElmID.termIcon = fmi_xml_elmID_termIcon_none; context->anyElmCount = 0; context->useAnyHandleFlg = 0; context->useAnyHandleFlgTermIcon = 0; @@ -1490,10 +1641,6 @@ int fmi3_xml_parse_terminals_and_icons(fmi_xml_terminals_and_icons_t* termIcon, return 0; } -const char* fmi3_xml_elmid_to_name(fmi3_xml_elm_enu_t id){ - return fmi3_element_handle_map[id].elementName; -} - #define JM_TEMPLATE_INSTANCE_TYPE fmi3_xml_element_handle_map_t #include "JM/jm_vector_template.h" diff --git a/src/XML/src/FMI3/fmi3_xml_parser.h b/src/XML/src/FMI3/fmi3_xml_parser.h index 5fb6d7b9..e5c5c99a 100644 --- a/src/XML/src/FMI3/fmi3_xml_parser.h +++ b/src/XML/src/FMI3/fmi3_xml_parser.h @@ -42,8 +42,22 @@ jm_vector_declare_template(fmi3_value_reference_t) multiple elements of this type are allowed in a sequence. */ typedef struct { - fmi3_xml_elm_enu_t superID; /* ID of super type or NULL if none */ - fmi3_xml_elm_enu_t parentID; /* expected parent ID for an element */ + fmi3_xml_elm_modelDescription_enu_t superID; /* ID of super type or NULL if none */ + fmi3_xml_elm_modelDescription_enu_t parentID; /* expected parent ID for an element */ + int siblingIndex; /* index among siblings */ + int multipleAllowed; /* multiple elements of this kind kan come in a sequence as siblings*/ +} fmi3_xml_scheme_modelDescription_info_t; + +typedef struct { + fmi_xml_elm_termIcon_enu_t superID; /* ID of super type or NULL if none */ + fmi_xml_elm_termIcon_enu_t parentID; /* expected parent ID for an element */ + int siblingIndex; /* index among siblings */ + int multipleAllowed; /* multiple elements of this kind kan come in a sequence as siblings*/ +} fmi_xml_scheme_termIcon_info_t; + +typedef struct { + fmi3_xml_elm_t superID; /* ID of super type or NULL if none */ + fmi3_xml_elm_t parentID; /* expected parent ID for an element */ int siblingIndex; /* index among siblings */ int multipleAllowed; /* multiple elements of this kind kan come in a sequence as siblings*/ } fmi3_xml_scheme_info_t; @@ -90,35 +104,36 @@ void fmi3_xml_free_parse_buffer(fmi3_xml_parser_context_t* context); /** * Raises generic parse error for given attribute. */ -void fmi3_xml_parse_attr_error(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, const char* attrStr); - -int fmi3_xml_parse_attr_as_string (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, jm_vector(char)* field); -int fmi3_xml_parse_attr_as_enum (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, unsigned int* field, unsigned int defaultVal, jm_name_ID_map_t* nameMap); -int fmi3_xml_parse_attr_as_bool (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, bool* field, bool defaultVal); -int fmi3_xml_parse_attr_as_boolean(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, unsigned int* field, unsigned int defaultVal); -int fmi3_xml_parse_attr_as_intXX (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, void* field, void* defaultVal, const fmi3_xml_primitive_type_t* primType); -int fmi3_xml_parse_attr_as_int32 (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, fmi3_int32_t* field, fmi3_int32_t defaultVal); -int fmi3_xml_parse_attr_as_uint64 (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, fmi3_uint64_t* field, fmi3_uint64_t defaultVal); -int fmi3_xml_parse_attr_as_uint32 (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, fmi3_uint32_t* field, fmi3_uint32_t defaultVal); -int fmi3_xml_parse_attr_as_floatXX(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, void* field, void* defaultVal, const fmi3_xml_primitive_type_t* primType); -int fmi3_xml_parse_attr_as_float64(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, fmi3_float64_t* field, fmi3_float64_t defaultVal); -int fmi3_xml_parse_attr_as_float32(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, fmi3_float32_t* field, fmi3_float32_t defaultVal); -int fmi3_xml_parse_attr_as_sizet (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, size_t* field, size_t* defaultVal); -int fmi3_xml_parse_attr_as_array (fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, void** arrPtr, size_t* arrSize, jm_string str, const fmi3_xml_primitive_type_t* primType); - -int fmi3_xml_parse_attr_valueref_list(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required, jm_vector(fmi3_value_reference_t)* vrs); - -int fmi3_xml_is_attr_defined( fmi3_xml_parser_context_t* context, fmi3_xml_attr_enu_t attrID); -jm_string fmi3_xml_peek_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_attr_enu_t attrID); -int fmi3_xml_get_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_attr_enu_t attrID, int required,const char** valp); - -void fmi3_xml_set_element_handle(fmi3_xml_parser_context_t* context, const char* elm, fmi3_xml_elm_enu_t id); - -int fmi3_xml_is_valid_parent(fmi3_xml_elm_enu_t child_id, fmi3_xml_elm_enu_t parent_id); -int fmi3_xml_get_super_type_rec(fmi3_xml_elm_enu_t id); -int fmi3_xml_are_same_type(fmi3_xml_elm_enu_t id1, fmi3_xml_elm_enu_t id2); - -const char* fmi3_xml_elmid_to_name(fmi3_xml_elm_enu_t id); +void fmi3_xml_parse_attr_error(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, const char* attrStr); + +int fmi3_xml_parse_attr_as_string (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, jm_vector(char)* field); +int fmi3_xml_parse_attr_as_enum (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, unsigned int* field, unsigned int defaultVal, jm_name_ID_map_t* nameMap); +int fmi3_xml_parse_attr_as_bool (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, bool* field, bool defaultVal); +int fmi3_xml_parse_attr_as_boolean(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, unsigned int* field, unsigned int defaultVal); +int fmi3_xml_parse_attr_as_intXX (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, void* field, void* defaultVal, const fmi3_xml_primitive_type_t* primType); +int fmi3_xml_parse_attr_as_int32 (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, fmi3_int32_t* field, fmi3_int32_t defaultVal); +int fmi3_xml_parse_attr_as_uint64 (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, fmi3_uint64_t* field, fmi3_uint64_t defaultVal); +int fmi3_xml_parse_attr_as_uint32 (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, fmi3_uint32_t* field, fmi3_uint32_t defaultVal); +int fmi3_xml_parse_attr_as_floatXX(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, void* field, void* defaultVal, const fmi3_xml_primitive_type_t* primType); +int fmi3_xml_parse_attr_as_float64(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, fmi3_float64_t* field, fmi3_float64_t defaultVal); +int fmi3_xml_parse_attr_as_float32(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, fmi3_float32_t* field, fmi3_float32_t defaultVal); +int fmi3_xml_parse_attr_as_sizet (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, size_t* field, size_t* defaultVal); +int fmi3_xml_parse_attr_as_array (fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, void** arrPtr, size_t* arrSize, jm_string str, const fmi3_xml_primitive_type_t* primType); + +int fmi3_xml_parse_attr_valueref_list(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, jm_vector(fmi3_value_reference_t)* vrs); + +int fmi3_xml_is_attr_defined( fmi3_xml_parser_context_t* context, const fmi3_xml_attr_t attrID); +jm_string fmi3_xml_peek_attr_str(fmi3_xml_parser_context_t* context, const fmi3_xml_attr_t attrID); +int fmi3_xml_get_attr_str(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, const fmi3_xml_attr_t attrID, int required, const char** valp); + +void fmi3_xml_set_element_handle(fmi3_xml_parser_context_t* context, const char* elm, fmi3_xml_elm_t id); + +// TODO: These last 3 should probably go to a scheme file +int fmi3_xml_is_valid_parent(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t child_id, fmi3_xml_elm_t parent_id); +int fmi3_xml_get_super_type_rec(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id); +int fmi3_xml_are_same_type(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id1, fmi3_xml_elm_t id2); + +const char* fmi3_xml_elmid_to_name(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id); #ifdef __cplusplus } diff --git a/src/XML/src/FMI3/fmi3_xml_parser_context_impl.h b/src/XML/src/FMI3/fmi3_xml_parser_context_impl.h index e1445d0e..13911481 100644 --- a/src/XML/src/FMI3/fmi3_xml_parser_context_impl.h +++ b/src/XML/src/FMI3/fmi3_xml_parser_context_impl.h @@ -28,16 +28,40 @@ extern "C" { #endif +/** Flag for current XML file being handled. */ +// TODO: Might be more suited in parser.h? +typedef enum fmi3_xml_type_t { + fmi3_xml_type_modelDescription, + fmi3_xml_type_terminalAndIcons +} fmi3_xml_type_t; + +typedef struct fmi3_xml_modelDescription_element_handle_map_t fmi3_xml_modelDescription_element_handle_map_t; +typedef struct fmi_xml_termIcon_element_handle_map_t fmi_xml_termIcon_element_handle_map_t; typedef struct fmi3_xml_element_handle_map_t fmi3_xml_element_handle_map_t; +typedef int (*fmi3_xml_modelDescription_element_handle_ft)(fmi3_xml_parser_context_t* context, const char* data); +typedef int (*fmi3_xml_termIcon_element_handle_ft)(fmi3_xml_parser_context_t* context, const char* data); typedef int (*fmi3_xml_element_handle_ft)(fmi3_xml_parser_context_t* context, const char* data); +struct fmi3_xml_modelDescription_element_handle_map_t { + const char* elementName; + fmi3_xml_modelDescription_element_handle_ft elementHandle; + fmi3_xml_elm_modelDescription_enu_t elemID; +}; + +struct fmi_xml_termIcon_element_handle_map_t { + const char* elementName; + fmi3_xml_termIcon_element_handle_ft elementHandle; + fmi_xml_elm_termIcon_enu_t elemID; +}; + struct fmi3_xml_element_handle_map_t { const char* elementName; fmi3_xml_element_handle_ft elementHandle; - fmi3_xml_elm_enu_t elemID; + fmi3_xml_elm_t elemID; }; + jm_vector_declare_template(fmi3_xml_element_handle_map_t) /** @@ -45,6 +69,10 @@ jm_vector_declare_template(fmi3_xml_element_handle_map_t) */ struct fmi3_xml_parser_context_t { + /* Flag for XML being handled, e.g., modelDescription, terminalsAndIcons... + MUST BE FIRST due setting as const in fmi3_xml_allocate_parser_context */ + const fmi3_xml_type_t xmlType; + /** * This is where the parsed XML is saved. */ @@ -146,10 +174,10 @@ struct fmi3_xml_parser_context_t { jm_vector(char) variableStartAttr; /** - * Element ID of the last processed sibling, or fmi3_xml_elmID_none if + * Element ID of the last processed sibling, or FMI_XML_ELMID_NONE if * no siblings have been processed. */ - fmi3_xml_elm_enu_t lastSiblingElemId; + fmi3_xml_elm_t lastSiblingElemId; /** * Used for error checking and scheme verification. @@ -161,9 +189,9 @@ struct fmi3_xml_parser_context_t { * on enter: self * on exit: parent */ - fmi3_xml_elm_enu_t currentElmID; + fmi3_xml_elm_t currentElmID; - fmi3_xml_elm_enu_t currentElemIdStartTag; + fmi3_xml_elm_t currentElemIdStartTag; /* Variables for handling tool-specific XML elements */ int anyElmCount; diff --git a/src/XML/src/FMI3/fmi3_xml_parser_scheme.h b/src/XML/src/FMI3/fmi3_xml_parser_scheme.h index a7c071b7..6bf91dd3 100644 --- a/src/XML/src/FMI3/fmi3_xml_parser_scheme.h +++ b/src/XML/src/FMI3/fmi3_xml_parser_scheme.h @@ -25,23 +25,28 @@ related to parsing XML elements and their attributes extern "C" { #endif -/** \brief Attributes names common to modelDescription.xml & terminalsAndIcons.xml */ -#define FMI3_XML_ATTRLIST_COMMON(EXPAND_XML_ATTRNAME) \ - EXPAND_XML_ATTRNAME(fmiVersion) \ - EXPAND_XML_ATTRNAME(name) \ - EXPAND_XML_ATTRNAME(description) - -/** \brief Attribute names used in XML */ -#define FMI3_XML_ATTRLIST(EXPAND_XML_ATTRNAME) \ - FMI3_XML_ATTRLIST_COMMON (EXPAND_XML_ATTRNAME) \ - FMI3_XML_ATTRLIST_MODEL_DESCR(EXPAND_XML_ATTRNAME) \ - FMI_XML_ATTRLIST_TERM_ICON (EXPAND_XML_ATTRNAME) - #define FMI3_XML_ATTR_ID(attr) fmi_attr_id_##attr, -typedef enum fmi3_xml_attr_enu_t { - FMI3_XML_ATTRLIST(FMI3_XML_ATTR_ID) - fmi3_xml_attr_number -} fmi3_xml_attr_enu_t; +typedef enum fmi3_xml_attr_modelDescription_enu_t { + FMI3_XML_ATTRLIST_MODEL_DESCR(FMI3_XML_ATTR_ID) + fmi3_xml_modelDescription_attr_number +} fmi3_xml_attr_modelDescription_enu_t; + +#define FMI_TERMICON_XML_ATTR_ID(attr) fmi_termIcon_attr_id_##attr, +typedef enum fmi_xml_attr_termIcon_enu_t { + FMI_XML_ATTRLIST_TERM_ICON(FMI_TERMICON_XML_ATTR_ID) + fmi_xml_termIcon_attr_number +} fmi_xml_attr_termIcon_enu_t; + +typedef union fmi3_xml_attr_t { + int any; // when used in generic parser/handling context + fmi3_xml_attr_modelDescription_enu_t modelDescription; + fmi_xml_attr_termIcon_enu_t termIcon; +} fmi3_xml_attr_t; + +// Shortcuts for defining fmi3_xml_attr_t for a given enum value +#define FMI3_ATTR_ANY(enu) (fmi3_xml_attr_t){.any = enu} +#define FMI3_ATTR(enu) (fmi3_xml_attr_t){.modelDescription = enu} +#define FMI_ATTR_TERMICON(enu) (fmi3_xml_attr_t){.termIcon = enu} /* Build prototypes for all elm_handle_* functions */ typedef struct fmi3_xml_parser_context_t fmi3_xml_parser_context_t; @@ -50,28 +55,54 @@ FMI3_XML_ELMLIST_MODEL_DESCR (EXPAND_ELM_HANDLE_FMI3) FMI3_XML_ELMLIST_ALT_MODEL_DESCR (EXPAND_ELM_HANDLE_FMI3) FMI3_XML_ELMLIST_ABSTRACT_MODEL_DESCR(EXPAND_ELM_HANDLE_FMI3) -#define EXPAND_ELM_HANDLE_FMI_TERM_ICON(elm) extern int fmi_xml_handle_##elm(fmi3_xml_parser_context_t* context, const char* data); -FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_HANDLE_FMI_TERM_ICON) -FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_HANDLE_FMI_TERM_ICON) +#define EXPAND_ELM_HANDLE_FMI_TERMICON(elm) extern int fmi_xml_handle_##elm(fmi3_xml_parser_context_t* context, const char* data); +FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_HANDLE_FMI_TERMICON) +FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_HANDLE_FMI_TERMICON) /** - * Create an enum over all XML elements. This enum can be used to index + * Create an enum over all modelDescription XML elements. This enum can be used to index * the following arrays: - * - fmi3_xml_scheme_info - * - fmi3_element_handle_map + * - fmi3_xml_scheme_modelDescription_info + * - fmi3_modelDescription_element_handle_map */ #define FMI3_XML_ELM_ID(elm) fmi3_xml_elmID_##elm #define FMI3_XML_LIST_ELM_ID(elm) ,FMI3_XML_ELM_ID(elm) -typedef enum fmi3_xml_elm_enu_t { - fmi3_xml_elmID_none = -1 +#define FMI_XML_ELMID_NONE (-1) +typedef enum fmi3_xml_elm_modelDescription_enu_t { + fmi3_xml_elmID_none = FMI_XML_ELMID_NONE FMI3_XML_ELMLIST_MODEL_DESCR(FMI3_XML_LIST_ELM_ID) - FMI_XML_ELMLIST_TERM_ICON (FMI3_XML_LIST_ELM_ID) ,fmi3_xml_elm_actual_number FMI3_XML_ELMLIST_ALT_MODEL_DESCR (FMI3_XML_LIST_ELM_ID) - FMI_XML_ELMLIST_ALT_TERM_ICON (FMI3_XML_LIST_ELM_ID) FMI3_XML_ELMLIST_ABSTRACT_MODEL_DESCR(FMI3_XML_LIST_ELM_ID) ,fmi3_xml_elm_number -} fmi3_xml_elm_enu_t; +} fmi3_xml_elm_modelDescription_enu_t; + +/** + * Create an enum over all terminalsAndIcons XML elements. This enum can be used to index + * the following arrays: + * - fmi_xml_scheme_termIcon_info + * - fmi_termIcon_element_handle_map + */ +#define FMI_TERMICON_XML_ELM_ID(elm) fmi_xml_elmID_termIcon_##elm +#define FMI_TERMICON_XML_LIST_ELM_ID(elm) ,FMI_TERMICON_XML_ELM_ID(elm) +typedef enum fmi_xml_elm_termIcon_enu_t { + fmi_xml_elmID_termIcon_none = FMI_XML_ELMID_NONE + FMI_XML_ELMLIST_TERM_ICON(FMI_TERMICON_XML_LIST_ELM_ID) + ,fmi_xml_elm_termIcon_actual_number + FMI_XML_ELMLIST_ALT_TERM_ICON(FMI_TERMICON_XML_LIST_ELM_ID) + ,fmi_xml_elm_termIcon_number +} fmi_xml_elm_termIcon_enu_t; + +typedef union fmi3_xml_elm_t { + int any; // when used in generic parser/handling context + fmi3_xml_elm_modelDescription_enu_t modelDescription; + fmi_xml_elm_termIcon_enu_t termIcon; +} fmi3_xml_elm_t; + +// Shortcuts for defining fmi3_xml_elm_t for a given enum value +#define FMI3_ELM_ANY(enu) (fmi3_xml_elm_t){.any = enu} +#define FMI3_ELM(enu) (fmi3_xml_elm_t){.modelDescription = enu} +#define FMI_ELM_TERMICON(enu) (fmi3_xml_elm_t){.termIcon = enu} #ifdef __cplusplus } diff --git a/src/XML/src/FMI3/fmi3_xml_type.c b/src/XML/src/FMI3/fmi3_xml_type.c index cd9fd24a..5b039627 100644 --- a/src/XML/src/FMI3/fmi3_xml_type.c +++ b/src/XML/src/FMI3/fmi3_xml_type.c @@ -675,8 +675,8 @@ int fmi3_xml_handle_SimpleType(fmi3_xml_parser_context_t *context, const char* d return -1; /* read attributes to buffers */ - if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_SimpleType, fmi_attr_id_name, 1, bufName) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_SimpleType, fmi_attr_id_description, 0, bufDescr)) { + if (fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_SimpleType), FMI3_ATTR(fmi_attr_id_name), 1, bufName) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_SimpleType), FMI3_ATTR(fmi_attr_id_description), 0, bufDescr)) { return -1; } @@ -784,7 +784,7 @@ fmi3_xml_variable_type_base_t* fmi3_xml_alloc_variable_type_start(fmi3_xml_type_ * For TypeDefinitions: The props_t of the default type. */ fmi3_xml_float_type_props_t* fmi3_xml_parse_float_type_properties(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType) + fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType) { jm_named_ptr named, *pnamed; fmi3_xml_model_description_t* md = context->modelDescription; @@ -807,9 +807,9 @@ fmi3_xml_float_type_props_t* fmi3_xml_parse_float_type_properties(fmi3_xml_parse &md->typeDefinitions, fallbackType, sizeof(fmi3_xml_float_type_props_t)); if (!bufQuantity || !bufUnit || !bufDispUnit || !props || - fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_quantity, 0, bufQuantity) || - fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_unit, 0, bufUnit) || - fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_displayUnit, 0, bufDispUnit)) + fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_quantity), 0, bufQuantity) || + fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_unit), 0, bufUnit) || + fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_displayUnit), 0, bufDispUnit)) { fmi3_xml_parse_fatal(context, "Error parsing float type properties"); return NULL; @@ -834,11 +834,11 @@ fmi3_xml_float_type_props_t* fmi3_xml_parse_float_type_properties(fmi3_xml_parse } } - if (fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_relativeQuantity, 0, &relQuanBuf, fallbackProps->super.isRelativeQuantity) || - fmi3_xml_parse_attr_as_boolean(context, elmID, fmi_attr_id_unbounded, 0, &unboundedBuf, fallbackProps->super.isUnbounded) || - fmi3_xml_parse_attr_as_floatXX(context, elmID, fmi_attr_id_min, 0, &props->typeMin, &fallbackProps->typeMin, primType) || - fmi3_xml_parse_attr_as_floatXX(context, elmID, fmi_attr_id_max, 0, &props->typeMax, &fallbackProps->typeMax, primType) || - fmi3_xml_parse_attr_as_floatXX(context, elmID, fmi_attr_id_nominal, 0, &props->typeNominal, &fallbackProps->typeNominal, primType)) + if (fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_relativeQuantity), 0, &relQuanBuf, fallbackProps->super.isRelativeQuantity) || + fmi3_xml_parse_attr_as_boolean(context, elmID, FMI3_ATTR(fmi_attr_id_unbounded), 0, &unboundedBuf, fallbackProps->super.isUnbounded) || + fmi3_xml_parse_attr_as_floatXX(context, elmID, FMI3_ATTR(fmi_attr_id_min), 0, &props->typeMin, &fallbackProps->typeMin, primType) || + fmi3_xml_parse_attr_as_floatXX(context, elmID, FMI3_ATTR(fmi_attr_id_max), 0, &props->typeMax, &fallbackProps->typeMax, primType) || + fmi3_xml_parse_attr_as_floatXX(context, elmID, FMI3_ATTR(fmi_attr_id_nominal), 0, &props->typeNominal, &fallbackProps->typeNominal, primType)) { // NOTE: Should not need fatal error here since none of these attributes are used to // reference other parts of the XML. @@ -850,7 +850,7 @@ fmi3_xml_float_type_props_t* fmi3_xml_parse_float_type_properties(fmi3_xml_parse return props; } -int fmi3_xml_handle_FloatType(fmi3_xml_parser_context_t* context, const char* data, fmi3_xml_elm_enu_t elmID, +int fmi3_xml_handle_FloatType(fmi3_xml_parser_context_t* context, const char* data, fmi3_xml_elm_t elmID, fmi3_xml_float_type_props_t* defaultType, const fmi3_xml_primitive_type_t* primType) { if (fmi3_xml_handle_SimpleType(context, data)) return -1; @@ -872,11 +872,11 @@ int fmi3_xml_handle_FloatType(fmi3_xml_parser_context_t* context, const char* da } int fmi3_xml_handle_Float64Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_FloatType(context, data, fmi3_xml_elmID_Float64Type, &context->modelDescription->typeDefinitions.defaultFloat64Type, &PRIMITIVE_TYPES.float64); + return fmi3_xml_handle_FloatType(context, data, FMI3_ELM(fmi3_xml_elmID_Float64Type), &context->modelDescription->typeDefinitions.defaultFloat64Type, &PRIMITIVE_TYPES.float64); } int fmi3_xml_handle_Float32Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_FloatType(context, data, fmi3_xml_elmID_Float32Type, &context->modelDescription->typeDefinitions.defaultFloat32Type, &PRIMITIVE_TYPES.float32); + return fmi3_xml_handle_FloatType(context, data, FMI3_ELM(fmi3_xml_elmID_Float32Type), &context->modelDescription->typeDefinitions.defaultFloat32Type, &PRIMITIVE_TYPES.float32); } /** @@ -887,7 +887,7 @@ int fmi3_xml_handle_Float32Type(fmi3_xml_parser_context_t* context, const char* * For TypeDefinitions: The props_t of the default type. */ fmi3_xml_int_type_props_t* fmi3_xml_parse_intXX_type_properties(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType) + fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType) { fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_type_definition_list_t* td = &md->typeDefinitions; @@ -909,7 +909,7 @@ fmi3_xml_int_type_props_t* fmi3_xml_parse_intXX_type_properties(fmi3_xml_parser_ props = (fmi3_xml_int_type_props_t*)fmi3_xml_alloc_variable_or_typedef_props(td, fallbackType, sizeof(fmi3_xml_int_type_props_t)); if (!props) return NULL; - if (fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_quantity, 0, bufQuantity)) + if (fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_quantity), 0, bufQuantity)) return NULL; if (jm_vector_get_size(char)(bufQuantity)) @@ -917,14 +917,14 @@ fmi3_xml_int_type_props_t* fmi3_xml_parse_intXX_type_properties(fmi3_xml_parser_ props->quantity = quantity; - if ( fmi3_xml_parse_attr_as_intXX(context, elmID, fmi_attr_id_min, 0, &props->typeMin, &fallbackProps->typeMin, primType) || - fmi3_xml_parse_attr_as_intXX(context, elmID, fmi_attr_id_max, 0, &props->typeMax, &fallbackProps->typeMax, primType)) + if ( fmi3_xml_parse_attr_as_intXX(context, elmID, FMI3_ATTR(fmi_attr_id_min), 0, &props->typeMin, &fallbackProps->typeMin, primType) || + fmi3_xml_parse_attr_as_intXX(context, elmID, FMI3_ATTR(fmi_attr_id_max), 0, &props->typeMax, &fallbackProps->typeMax, primType)) return NULL; return props; } -int fmi3_xml_handle_IntXXType(fmi3_xml_parser_context_t *context, const char* data, fmi3_xml_elm_enu_t elemID, +int fmi3_xml_handle_IntXXType(fmi3_xml_parser_context_t *context, const char* data, fmi3_xml_elm_t elemID, fmi3_xml_int_type_props_t* defaultType, const fmi3_xml_primitive_type_t* primType) { if (fmi3_xml_handle_SimpleType(context, data)) return -1; @@ -946,35 +946,35 @@ int fmi3_xml_handle_IntXXType(fmi3_xml_parser_context_t *context, const char* da } int fmi3_xml_handle_Int64Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_Int64Type, &context->modelDescription->typeDefinitions.defaultInt64Type, &PRIMITIVE_TYPES.int64); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_Int64Type), &context->modelDescription->typeDefinitions.defaultInt64Type, &PRIMITIVE_TYPES.int64); } int fmi3_xml_handle_Int32Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_Int32Type, &context->modelDescription->typeDefinitions.defaultInt32Type, &PRIMITIVE_TYPES.int32); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_Int32Type), &context->modelDescription->typeDefinitions.defaultInt32Type, &PRIMITIVE_TYPES.int32); } int fmi3_xml_handle_Int16Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_Int16Type, &context->modelDescription->typeDefinitions.defaultInt16Type, &PRIMITIVE_TYPES.int16); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_Int16Type), &context->modelDescription->typeDefinitions.defaultInt16Type, &PRIMITIVE_TYPES.int16); } int fmi3_xml_handle_Int8Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_Int8Type, &context->modelDescription->typeDefinitions.defaultInt8Type, &PRIMITIVE_TYPES.int8); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_Int8Type), &context->modelDescription->typeDefinitions.defaultInt8Type, &PRIMITIVE_TYPES.int8); } int fmi3_xml_handle_UInt64Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_UInt64Type, &context->modelDescription->typeDefinitions.defaultUInt64Type, &PRIMITIVE_TYPES.uint64); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_UInt64Type), &context->modelDescription->typeDefinitions.defaultUInt64Type, &PRIMITIVE_TYPES.uint64); } int fmi3_xml_handle_UInt32Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_UInt32Type, &context->modelDescription->typeDefinitions.defaultUInt32Type, &PRIMITIVE_TYPES.uint32); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_UInt32Type), &context->modelDescription->typeDefinitions.defaultUInt32Type, &PRIMITIVE_TYPES.uint32); } int fmi3_xml_handle_UInt16Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_UInt16Type, &context->modelDescription->typeDefinitions.defaultUInt16Type, &PRIMITIVE_TYPES.uint16); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_UInt16Type), &context->modelDescription->typeDefinitions.defaultUInt16Type, &PRIMITIVE_TYPES.uint16); } int fmi3_xml_handle_UInt8Type(fmi3_xml_parser_context_t* context, const char* data) { - return fmi3_xml_handle_IntXXType(context, data, fmi3_xml_elmID_UInt8Type, &context->modelDescription->typeDefinitions.defaultUInt8Type, &PRIMITIVE_TYPES.uint8); + return fmi3_xml_handle_IntXXType(context, data, FMI3_ELM(fmi3_xml_elmID_UInt8Type), &context->modelDescription->typeDefinitions.defaultUInt8Type, &PRIMITIVE_TYPES.uint8); } int fmi3_xml_handle_BooleanType(fmi3_xml_parser_context_t* context, const char* data) { @@ -1000,7 +1000,7 @@ int fmi3_xml_handle_BooleanType(fmi3_xml_parser_context_t* context, const char* * For TypeDefinitions: The props_t of the default type. */ fmi3_xml_binary_type_props_t* fmi3_xml_parse_binary_type_properties(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType) + fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType) { fmi3_xml_type_definition_list_t* td = &context->modelDescription->typeDefinitions; fmi3_xml_binary_type_props_t* fallbackProps; @@ -1019,9 +1019,9 @@ fmi3_xml_binary_type_props_t* fmi3_xml_parse_binary_type_properties(fmi3_xml_par // maxSize: // without default values, needs peeking to correctly set hasAttr flag - if (fmi3_xml_peek_attr_str(context, fmi_attr_id_maxSize)) { // attribute exists + if (fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_maxSize))) { // attribute exists props->hasMaxSize = fmi3_true; - if (fmi3_xml_parse_attr_as_sizet(context, elmID, fmi_attr_id_maxSize, 0 /*required*/, + if (fmi3_xml_parse_attr_as_sizet(context, elmID, FMI3_ATTR(fmi_attr_id_maxSize), 0 /*required*/, &props->maxSize, &fallbackProps->maxSize)) { // BinaryType: fallbackProps = default; Binary: fallbackProps = declaredType props(or default) props->hasMaxSize = fallbackProps->hasMaxSize; @@ -1034,10 +1034,10 @@ fmi3_xml_binary_type_props_t* fmi3_xml_parse_binary_type_properties(fmi3_xml_par } // mimeType: - if (fmi3_xml_is_attr_defined(context, fmi_attr_id_mimeType)) { + if (fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_mimeType))) { jm_vector(char)* mimeType = fmi3_xml_reserve_parse_buffer(context, 1, 100); if (!mimeType) {return NULL;} // buffer allocation failure - if (fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_mimeType, 0, mimeType)) { + if (fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_mimeType), 0, mimeType)) { props->mimeType = fallbackProps->mimeType; // parsing failure } else { // successful parse if (jm_vector_get_size(char)(mimeType) == 0) { @@ -1063,7 +1063,7 @@ int fmi3_xml_handle_BinaryType(fmi3_xml_parser_context_t* context, const char* d fmi3_xml_binary_type_props_t* props; fmi3_xml_binary_type_props_t* defaultType = &context->modelDescription->typeDefinitions.defaultBinaryType; - props = fmi3_xml_parse_binary_type_properties(context, fmi3_xml_elmID_BinaryType, &defaultType->super); + props = fmi3_xml_parse_binary_type_properties(context, FMI3_ELM(fmi3_xml_elmID_BinaryType), &defaultType->super); if (!props) return -1; // Get the typedef already created for SimpleType and set props @@ -1082,7 +1082,7 @@ int fmi3_xml_handle_BinaryType(fmi3_xml_parser_context_t* context, const char* d * For TypeDefinitions: The props_t of the default type. */ fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType) + fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType) { fmi3_xml_type_definition_list_t* td = &context->modelDescription->typeDefinitions; fmi3_xml_clock_type_props_t* fallbackProps; @@ -1110,7 +1110,7 @@ fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parse // NOTE: The parsing of intervalVariability could maybe be relaxed to not be 'required' // for Variables if they have a non-default TypeDefinition, since then they could inherit // that attribute. However, the schema files don't allow it. - int ret = fmi3_xml_parse_attr_as_enum(context, elmID, fmi_attr_id_intervalVariability, 1 /*required*/, + int ret = fmi3_xml_parse_attr_as_enum(context, elmID, FMI3_ATTR(fmi_attr_id_intervalVariability), 1 /*required*/, &props->intervalVariability, fallbackProps->intervalVariability, intervalVariabilityMap); if (ret) { // Note: Even though this attribute is required, this does not break the API (by design) @@ -1121,28 +1121,28 @@ fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parse // The following attributes are optional, failure to parse does not stop parsing of current element // with default values // XXX: fmi3_xml_parse_as_* only considers default if parsing was successful - if (fmi3_xml_parse_attr_as_bool(context, elmID, fmi_attr_id_canBeDeactivated, 0 /*required*/, + if (fmi3_xml_parse_attr_as_bool(context, elmID, FMI3_ATTR(fmi_attr_id_canBeDeactivated), 0 /*required*/, &props->canBeDeactivated, fallbackProps->canBeDeactivated)) { props->canBeDeactivated = fallbackProps->canBeDeactivated; } - if (fmi3_xml_parse_attr_as_float32(context, elmID, fmi_attr_id_shiftDecimal, 0 /*required*/, + if (fmi3_xml_parse_attr_as_float32(context, elmID, FMI3_ATTR(fmi_attr_id_shiftDecimal), 0 /*required*/, &props->shiftDecimal, fallbackProps->shiftDecimal)) { props->shiftDecimal = fallbackProps->shiftDecimal; } - if (fmi3_xml_parse_attr_as_bool(context, elmID, fmi_attr_id_supportsFraction, 0 /*required*/, + if (fmi3_xml_parse_attr_as_bool(context, elmID, FMI3_ATTR(fmi_attr_id_supportsFraction), 0 /*required*/, &props->supportsFraction, fallbackProps->supportsFraction)) { props->supportsFraction = fallbackProps->supportsFraction; } - if (fmi3_xml_parse_attr_as_uint64(context, elmID, fmi_attr_id_shiftCounter, 0 /*required*/, + if (fmi3_xml_parse_attr_as_uint64(context, elmID, FMI3_ATTR(fmi_attr_id_shiftCounter), 0 /*required*/, &props->shiftCounter, fallbackProps->shiftCounter)) { props->shiftCounter = fallbackProps->shiftCounter; } // without default values, needs peeking to correctly set hasAttr flag // priority - if (fmi3_xml_peek_attr_str(context, fmi_attr_id_priority)) { // attribute exists + if (fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_priority))) { // attribute exists props->hasPriority = fmi3_true; - if (fmi3_xml_parse_attr_as_uint32(context, elmID, fmi_attr_id_priority, 0 /*required*/, + if (fmi3_xml_parse_attr_as_uint32(context, elmID, FMI3_ATTR(fmi_attr_id_priority), 0 /*required*/, &props->priority, fallbackProps->priority)) { // ClockType: fallbackProps = default; Clock: fallbackProps = declaredType props(or default) props->hasPriority = fallbackProps->hasPriority; @@ -1155,9 +1155,9 @@ fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parse } // resolution - if (fmi3_xml_peek_attr_str(context, fmi_attr_id_resolution)) { // attribute exists + if (fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_resolution))) { // attribute exists props->hasResolution = fmi3_true; - if (fmi3_xml_parse_attr_as_uint64(context, elmID, fmi_attr_id_resolution, 0 /*required*/, + if (fmi3_xml_parse_attr_as_uint64(context, elmID, FMI3_ATTR(fmi_attr_id_resolution), 0 /*required*/, &props->resolution, fallbackProps->resolution)) { // ClockType: fallbackProps = default; Clock: fallbackProps = declaredType props(or default) props->hasResolution = fallbackProps->hasResolution; @@ -1170,9 +1170,9 @@ fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parse } // intervalCounter - if (fmi3_xml_peek_attr_str(context, fmi_attr_id_intervalCounter)) { // attribute exists + if (fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_intervalCounter))) { // attribute exists props->hasIntervalCounter = fmi3_true; - if (fmi3_xml_parse_attr_as_uint64(context, elmID, fmi_attr_id_intervalCounter, 0 /*required*/, + if (fmi3_xml_parse_attr_as_uint64(context, elmID, FMI3_ATTR(fmi_attr_id_intervalCounter), 0 /*required*/, &props->intervalCounter, fallbackProps->intervalCounter)) { // ClockType: fallbackProps = default; Clock: fallbackProps = declaredType props(or default) props->hasIntervalCounter = fallbackProps->hasIntervalCounter; @@ -1185,9 +1185,9 @@ fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parse } // hasIntervalDecimal - if (fmi3_xml_peek_attr_str(context, fmi_attr_id_intervalDecimal)) { // attribute exists + if (fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_intervalDecimal))) { // attribute exists props->hasIntervalDecimal = fmi3_true; - if (fmi3_xml_parse_attr_as_float32(context, elmID, fmi_attr_id_intervalDecimal, 0 /*required*/, + if (fmi3_xml_parse_attr_as_float32(context, elmID, FMI3_ATTR(fmi_attr_id_intervalDecimal), 0 /*required*/, &props->intervalDecimal, fallbackProps->intervalDecimal)) { // ClockType: fallbackProps = default; Clock: fallbackProps = declaredType props(or default) props->hasIntervalDecimal = fallbackProps->hasIntervalDecimal; @@ -1211,7 +1211,7 @@ int fmi3_xml_handle_ClockType(fmi3_xml_parser_context_t* context, const char* da fmi3_xml_clock_type_props_t* props; fmi3_xml_clock_type_props_t* defaultType = &context->modelDescription->typeDefinitions.defaultClockType; - props = fmi3_xml_parse_clock_type_properties(context, fmi3_xml_elmID_ClockType, &defaultType->super); + props = fmi3_xml_parse_clock_type_properties(context, FMI3_ELM(fmi3_xml_elmID_ClockType), &defaultType->super); if (!props) return -1; // Get the typedef already created for SimpleType and set props @@ -1260,7 +1260,7 @@ int fmi3_xml_handle_EnumerationType(fmi3_xml_parser_context_t* context, const ch props->base.super.next = nextTmp; } if (!bufQuantity || !props || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Int32Type, fmi_attr_id_quantity, 0, bufQuantity) + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Int32Type), FMI3_ATTR(fmi_attr_id_quantity), 0, bufQuantity) ) return -1; if (jm_vector_get_size(char)(bufQuantity)) @@ -1318,9 +1318,9 @@ int fmi3_xml_handle_Item(fmi3_xml_parser_context_t* context, const char* data) { && (enumProps->base.super.baseType == fmi3_base_type_enum)); if (!bufName || !bufDescr || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Item, fmi_attr_id_name, 1, bufName) || - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Item, fmi_attr_id_description, 0, bufDescr) || - fmi3_xml_parse_attr_as_int32( context, fmi3_xml_elmID_Item, fmi_attr_id_value, 1, &value, 0)) { + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Item), FMI3_ATTR(fmi_attr_id_name), 1, bufName) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Item), FMI3_ATTR(fmi_attr_id_description), 0, bufDescr) || + fmi3_xml_parse_attr_as_int32( context, FMI3_ELM(fmi3_xml_elmID_Item), FMI3_ATTR(fmi_attr_id_value), 1, &value, 0)) { return -1; } descrlen = jm_vector_get_size(char)(bufDescr); @@ -1348,12 +1348,12 @@ int fmi3_xml_handle_Item(fmi3_xml_parser_context_t* context, const char* data) { * and could be found, otherwise the _props for the default type. */ fmi3_xml_variable_type_base_t* fmi3_parse_declared_type_attr(fmi3_xml_parser_context_t* context, - fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* defaultType) + fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* defaultType) { jm_named_ptr key, *found; jm_vector(char)* bufDeclaredType = fmi3_xml_reserve_parse_buffer(context, 1, 100); - fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_declaredType, 0, bufDeclaredType); + fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_declaredType), 0, bufDeclaredType); if ( !jm_vector_get_size(char)(bufDeclaredType) ) return defaultType; diff --git a/src/XML/src/FMI3/fmi3_xml_type_impl.h b/src/XML/src/FMI3/fmi3_xml_type_impl.h index 3ef4d99d..375b92be 100644 --- a/src/XML/src/FMI3/fmi3_xml_type_impl.h +++ b/src/XML/src/FMI3/fmi3_xml_type_impl.h @@ -335,12 +335,12 @@ fmi3_xml_variable_type_base_t* fmi3_xml_alloc_variable_or_typedef_props(fmi3_xml fmi3_xml_variable_type_base_t* fmi3_xml_alloc_variable_type_start(fmi3_xml_type_definition_list_t* td,fmi3_xml_variable_type_base_t* base, size_t typeSize); -fmi3_xml_float_type_props_t* fmi3_xml_parse_float_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType); -fmi3_xml_int_type_props_t* fmi3_xml_parse_intXX_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType); -fmi3_xml_binary_type_props_t* fmi3_xml_parse_binary_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType); -fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* fallbackType); +fmi3_xml_float_type_props_t* fmi3_xml_parse_float_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType); +fmi3_xml_int_type_props_t* fmi3_xml_parse_intXX_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType, const fmi3_xml_primitive_type_t* primType); +fmi3_xml_binary_type_props_t* fmi3_xml_parse_binary_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType); +fmi3_xml_clock_type_props_t* fmi3_xml_parse_clock_type_properties(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* fallbackType); -fmi3_xml_variable_type_base_t* fmi3_parse_declared_type_attr(fmi3_xml_parser_context_t *context, fmi3_xml_elm_enu_t elmID, fmi3_xml_variable_type_base_t* defaultType); +fmi3_xml_variable_type_base_t* fmi3_parse_declared_type_attr(fmi3_xml_parser_context_t *context, fmi3_xml_elm_t elmID, fmi3_xml_variable_type_base_t* defaultType); #ifdef __cplusplus } diff --git a/src/XML/src/FMI3/fmi3_xml_unit.c b/src/XML/src/FMI3/fmi3_xml_unit.c index e691b5a4..454a1bc6 100644 --- a/src/XML/src/FMI3/fmi3_xml_unit.c +++ b/src/XML/src/FMI3/fmi3_xml_unit.c @@ -202,13 +202,13 @@ int fmi3_xml_handle_BaseUnit(fmi3_xml_parser_context_t *context, const char* dat /* */ #define FMI3_PARSE_SI_BASE_UNIT_ENU(c) \ - fmi3_xml_parse_attr_as_int32(context, fmi3_xml_elmID_BaseUnit, fmi_attr_id_ ## c, 0, &(unit->SI_base_unit_exp[fmi3_SI_base_unit_ ## c]), 0) || + fmi3_xml_parse_attr_as_int32(context, FMI3_ELM(fmi3_xml_elmID_BaseUnit), FMI3_ATTR(fmi_attr_id_ ## c), 0, &(unit->SI_base_unit_exp[fmi3_SI_base_unit_ ## c]), 0) || ret = FMI3_SI_BASE_UNITS(FMI3_PARSE_SI_BASE_UNIT_ENU) /* */ - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_BaseUnit, fmi_attr_id_factor, 0, &unit->factor, 1) || + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_BaseUnit), FMI3_ATTR(fmi_attr_id_factor), 0, &unit->factor, 1) || /* */ - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_BaseUnit, fmi_attr_id_offset, 0, &unit->offset, 0); + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_BaseUnit), FMI3_ATTR(fmi_attr_id_offset), 0, &unit->offset, 0); if (unit->factor == 0) { unit->factor = 1.0; @@ -233,7 +233,7 @@ int fmi3_xml_handle_Unit(fmi3_xml_parser_context_t *context, const char* data) { if (!buf) return -1; if ( /* */ - fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_BaseUnit, fmi_attr_id_name, 1, buf) || + fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_BaseUnit), FMI3_ATTR(fmi_attr_id_name), 1, buf) || !(unit = fmi3_xml_get_parsed_unit(context, buf, 0)) ) return -1; context->lastBaseUnit = unit->baseUnit; @@ -258,7 +258,7 @@ int fmi3_xml_handle_DisplayUnit(fmi3_xml_parser_context_t *context, const char* if (!buf) return -1; /* first read the required name attribute */ /* */ - ret = fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_DisplayUnit, fmi_attr_id_name, 1, buf); + ret = fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_DisplayUnit), FMI3_ATTR(fmi_attr_id_name), 1, buf); if (ret) return ret; /* alloc memory to the correct size and put display unit on the list for the base unit */ named.ptr = 0; @@ -274,11 +274,11 @@ int fmi3_xml_handle_DisplayUnit(fmi3_xml_parser_context_t *context, const char* /* finally process the attributes */ ret = /* */ - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_DisplayUnit, fmi_attr_id_factor, 0, &dispUnit->factor, 1) || + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_DisplayUnit), FMI3_ATTR(fmi_attr_id_factor), 0, &dispUnit->factor, 1) || /* */ - fmi3_xml_parse_attr_as_float64(context, fmi3_xml_elmID_DisplayUnit, fmi_attr_id_offset, 0, &dispUnit->offset, 0) || + fmi3_xml_parse_attr_as_float64(context, FMI3_ELM(fmi3_xml_elmID_DisplayUnit), FMI3_ATTR(fmi_attr_id_offset), 0, &dispUnit->offset, 0) || /* */ - fmi3_xml_parse_attr_as_boolean(context, fmi3_xml_elmID_DisplayUnit, fmi_attr_id_inverse, 0, &dispUnit->inverse, 0); + fmi3_xml_parse_attr_as_boolean(context, FMI3_ELM(fmi3_xml_elmID_DisplayUnit), FMI3_ATTR(fmi_attr_id_inverse), 0, &dispUnit->inverse, 0); if (dispUnit->factor == 0) { dispUnit->factor = 1.0; if (!ret) { diff --git a/src/XML/src/FMI3/fmi3_xml_variable.c b/src/XML/src/FMI3/fmi3_xml_variable.c index dc21c898..33d821b4 100644 --- a/src/XML/src/FMI3/fmi3_xml_variable.c +++ b/src/XML/src/FMI3/fmi3_xml_variable.c @@ -1180,7 +1180,7 @@ void fmi3_xml_free_variable(jm_callbacks* callbacks, fmi3_xml_variable_t* var) { * The attributes are error checked. On success, the parsed variable is updated with them. */ static int fmi3_xml_variable_process_attr_causality_variability_initial(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { jm_name_ID_map_t causalityConventionMap[] = { {"parameter", fmi3_causality_enu_parameter}, @@ -1212,10 +1212,11 @@ static int fmi3_xml_variable_process_attr_causality_variability_initial(fmi3_xml unsigned int variability, defaultVariability; unsigned int initial, defaultInitial, validInitial; - bool isFloat = (elm_id == fmi3_xml_elmID_Float32) || (elm_id == fmi3_xml_elmID_Float64); + bool isFloat = ((elm_id.modelDescription == fmi3_xml_elmID_Float32) || + (elm_id.modelDescription == fmi3_xml_elmID_Float64)); // Causality: - if (fmi3_xml_parse_attr_as_enum(context, elm_id, fmi_attr_id_causality, 0, &causality, + if (fmi3_xml_parse_attr_as_enum(context, elm_id, FMI3_ATTR(fmi_attr_id_causality), 0, &causality, fmi3_causality_enu_local, causalityConventionMap)) { causality = fmi3_causality_enu_local; @@ -1229,7 +1230,7 @@ static int fmi3_xml_variable_process_attr_causality_variability_initial(fmi3_xml // Variability: defaultVariability = fmi3_get_default_valid_variability(causality, isFloat); - if (fmi3_xml_parse_attr_as_enum(context, elm_id, fmi_attr_id_variability, 0, &variability, + if (fmi3_xml_parse_attr_as_enum(context, elm_id, FMI3_ATTR(fmi_attr_id_variability), 0, &variability, defaultVariability, variabilityConventionMap)) { variability = defaultVariability; @@ -1249,7 +1250,7 @@ static int fmi3_xml_variable_process_attr_causality_variability_initial(fmi3_xml // Initial: defaultInitial = fmi3_get_default_initial(variability, causality); - if (fmi3_xml_parse_attr_as_enum(context, elm_id, fmi_attr_id_initial, 0, &initial, + if (fmi3_xml_parse_attr_as_enum(context, elm_id, FMI3_ATTR(fmi_attr_id_initial), 0, &initial, defaultInitial,initialConventionMap)) { initial = defaultInitial; @@ -1272,13 +1273,13 @@ static int fmi3_xml_variable_process_attr_causality_variability_initial(fmi3_xml } static int fmi3_xml_variable_process_attr_derivative(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { uint32_t derivative; - if (!fmi3_xml_is_attr_defined(context, fmi_attr_id_derivative)) { + if (!fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_derivative))) { return 0; } - else if (fmi3_xml_parse_attr_as_uint32(context, elm_id, fmi_attr_id_derivative, 0 /* required */, + else if (fmi3_xml_parse_attr_as_uint32(context, elm_id, FMI3_ATTR(fmi_attr_id_derivative), 0 /* required */, &derivative, 0 /* defaultVal */)) { return -1; @@ -1290,13 +1291,13 @@ static int fmi3_xml_variable_process_attr_derivative(fmi3_xml_parser_context_t* } static int fmi3_xml_variable_process_attr_previous(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { uint32_t previous; - if (!fmi3_xml_is_attr_defined(context, fmi_attr_id_previous)) { + if (!fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_previous))) { return 0; } - else if (fmi3_xml_parse_attr_as_uint32(context, elm_id, fmi_attr_id_previous, 0 /* required */, + else if (fmi3_xml_parse_attr_as_uint32(context, elm_id, FMI3_ATTR(fmi_attr_id_previous), 0 /* required */, &previous, 0 /* defaultVal */)) { return -1; @@ -1322,10 +1323,10 @@ static int fmi3_xml_variable_process_attr_previous(fmi3_xml_parser_context_t* co } static int fmi3_xml_variable_process_attr_multipleset(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { unsigned int multipleSet; - if (fmi3_xml_parse_attr_as_boolean(context, elm_id, fmi_attr_id_canHandleMultipleSetPerTimeInstant, + if (fmi3_xml_parse_attr_as_boolean(context, elm_id, FMI3_ATTR(fmi_attr_id_canHandleMultipleSetPerTimeInstant), 0 /* required */, &multipleSet, 1 /* defaultVal */)) { return -1; } @@ -1338,13 +1339,13 @@ static int fmi3_xml_variable_process_attr_multipleset(fmi3_xml_parser_context_t* } static int fmi3_xml_variable_process_attr_intermediateupdate(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { unsigned int intermediateUpdate; variable->intermediateUpdate = 0; // default, set early due to possible ignore // peek due to "must not have attribute" error check - if (!fmi3_xml_peek_attr_str(context, fmi_attr_id_intermediateUpdate)) { + if (!fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_intermediateUpdate))) { return 0; } // else: attribute exists @@ -1359,11 +1360,11 @@ static int fmi3_xml_variable_process_attr_intermediateupdate(fmi3_xml_parser_con } // Spec: "Variables of type Clock must not have the intermediateUpdate attribute" - if (elm_id == fmi3_xml_elmID_Clock) { + if (elm_id.modelDescription == fmi3_xml_elmID_Clock) { fmi3_xml_parse_warning(context, "Variables of type 'Clock' must not have the 'intermediateUpdate' attribute."); } - if (fmi3_xml_parse_attr_as_boolean(context, elm_id, fmi_attr_id_intermediateUpdate, + if (fmi3_xml_parse_attr_as_boolean(context, elm_id, FMI3_ATTR(fmi_attr_id_intermediateUpdate), 0 /* required */, &intermediateUpdate, 0 /* defaultVal */)) { return -1; } @@ -1378,10 +1379,10 @@ static int fmi3_xml_variable_process_attr_intermediateupdate(fmi3_xml_parser_con } static int fmi3_xml_variable_process_attr_clocks(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { // Attribute is optional. Avoid allocating vector unless necessary. - if (fmi3_xml_peek_attr_str(context, fmi_attr_id_clocks) == NULL) { + if (fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_clocks)) == NULL) { return 0; } @@ -1391,18 +1392,18 @@ static int fmi3_xml_variable_process_attr_clocks(fmi3_xml_parser_context_t* cont return -1; } - if (fmi3_xml_parse_attr_valueref_list(context, elm_id, fmi_attr_id_clocks, 0 /* required */, variable->clocks)) { + if (fmi3_xml_parse_attr_valueref_list(context, elm_id, FMI3_ATTR(fmi_attr_id_clocks), 0 /* required */, variable->clocks)) { return -1; } return 0; } static int fmi3_xml_variable_process_attr_reinit(fmi3_xml_parser_context_t* context, - fmi3_xml_variable_t* variable, fmi3_xml_elm_enu_t elm_id) + fmi3_xml_variable_t* variable, fmi3_xml_elm_t elm_id) { unsigned int reinit; - if (fmi3_xml_parse_attr_as_boolean(context, elm_id, fmi_attr_id_reinit, 0, &reinit, 0)) { + if (fmi3_xml_parse_attr_as_boolean(context, elm_id, FMI3_ATTR(fmi_attr_id_reinit), 0, &reinit, 0)) { return -1; } variable->reinit = (char)reinit; @@ -1442,7 +1443,7 @@ static int fmi3_xml_handle_Variable_unchecked(fmi3_xml_parser_context_t* context int atStartTag = !data; /* The real ID of the variable, such as 'Float64Variable' */ - fmi3_xml_elm_enu_t elm_id = atStartTag ? context->currentElemIdStartTag : context->currentElmID; + fmi3_xml_elm_t elm_id = atStartTag ? context->currentElemIdStartTag : context->currentElmID; fmi3_xml_model_description_t* md = context->modelDescription; if (!data) { @@ -1459,8 +1460,8 @@ static int fmi3_xml_handle_Variable_unchecked(fmi3_xml_parser_context_t* context /* Get required attributes: VR, name */ int req = 0; // |= rather than instant returns assure all attributes are parsed. - req |= fmi3_xml_parse_attr_as_uint32(context, elm_id, fmi_attr_id_valueReference, 1, &vr, 0); - req |= fmi3_xml_parse_attr_as_string(context, elm_id, fmi_attr_id_name, 1, bufName); + req |= fmi3_xml_parse_attr_as_uint32(context, elm_id, FMI3_ATTR(fmi_attr_id_valueReference), 1, &vr, 0); + req |= fmi3_xml_parse_attr_as_string(context, elm_id, FMI3_ATTR(fmi_attr_id_name), 1, bufName); if (req) { // name or valueReference failed to parse @@ -1469,7 +1470,7 @@ static int fmi3_xml_handle_Variable_unchecked(fmi3_xml_parser_context_t* context } // optional, failure to parse should only result in missing description - fmi3_xml_parse_attr_as_string(context, elm_id, fmi_attr_id_description, 0, bufDesc); + fmi3_xml_parse_attr_as_string(context, elm_id, FMI3_ATTR(fmi_attr_id_description), 0, bufDesc); if (jm_vector_get_size(char)(bufDesc)) { /* Add the description to the model-wide set and retrieve the pointer */ @@ -1513,7 +1514,7 @@ static int fmi3_xml_handle_Variable_unchecked(fmi3_xml_parser_context_t* context // Unexpected (malloc) failures still force the parser to stop via fmi_xml_parse_fatal(...) /* Save start value for processing after reading all Dimensions */ - res |= fmi3_xml_parse_attr_as_string(context, elm_id, fmi_attr_id_start, 0, &context->variableStartAttr); + res |= fmi3_xml_parse_attr_as_string(context, elm_id, FMI3_ATTR(fmi_attr_id_start), 0, &context->variableStartAttr); /* Process common attributes */ res |= fmi3_xml_variable_process_attr_causality_variability_initial(context, variable, elm_id); @@ -1631,8 +1632,8 @@ int fmi3_xml_handle_Dimension(fmi3_xml_parser_context_t* context, const char* da dim->start = 0; /* handle attributes*/ - int hasStart = fmi3_xml_is_attr_defined(context, fmi_attr_id_start); - int hasVr = fmi3_xml_is_attr_defined(context, fmi_attr_id_valueReference); + int hasStart = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_start)); + int hasVr = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_valueReference)); /* error check */ if ( !(hasStart || hasVr) ) { @@ -1648,12 +1649,12 @@ int fmi3_xml_handle_Dimension(fmi3_xml_parser_context_t* context, const char* da // Gating behing hasStart/Vr from peeking is necessary, // since fmi3_xml_parse_attr_as_* returns 0 if attribute does not exists (since it is not required) if (hasStart) { - ret = fmi3_xml_parse_attr_as_uint64(context, fmi3_xml_elmID_Dimension, fmi_attr_id_start, 0, &dim->start, 0); + ret = fmi3_xml_parse_attr_as_uint64(context, FMI3_ELM(fmi3_xml_elmID_Dimension), FMI3_ATTR(fmi_attr_id_start), 0, &dim->start, 0); dim->has_start = ret ? 0 : 1; } if (hasVr) { - ret = fmi3_xml_parse_attr_as_uint32(context, fmi3_xml_elmID_Dimension, fmi_attr_id_valueReference, 0, &dim->vr, 0); + ret = fmi3_xml_parse_attr_as_uint32(context, FMI3_ELM(fmi3_xml_elmID_Dimension), FMI3_ATTR(fmi_attr_id_valueReference), 0, &dim->vr, 0); dim->has_vr = ret ? 0 : 1; } @@ -1675,7 +1676,7 @@ int fmi3_xml_handle_Dimension(fmi3_xml_parser_context_t* context, const char* da int fmi3_xml_handle_FloatXX(fmi3_xml_parser_context_t* context, const char* data, fmi3_xml_float_type_props_t* defaultType, - fmi3_xml_elm_enu_t elmID, /* ID of the Type (not the Variable) */ // XXX: Why? + fmi3_xml_elm_t elmID, /* ID of the Type (not the Variable) */ // XXX: Why? const fmi3_xml_primitive_type_t* primType) { fmi3_xml_model_description_t* md = context->modelDescription; @@ -1702,14 +1703,14 @@ int fmi3_xml_handle_FloatXX(fmi3_xml_parser_context_t* context, const char* data if (!declaredType) return -1; /* Set type properties */ - int hasUnit = fmi3_xml_is_attr_defined(context, fmi_attr_id_unit) - || fmi3_xml_is_attr_defined(context, fmi_attr_id_displayUnit); - int hasMin = fmi3_xml_is_attr_defined(context, fmi_attr_id_min); - int hasMax = fmi3_xml_is_attr_defined(context, fmi_attr_id_max); - int hasNom = fmi3_xml_is_attr_defined(context, fmi_attr_id_nominal); - int hasQuan = fmi3_xml_is_attr_defined(context, fmi_attr_id_quantity); - int hasRelQ = fmi3_xml_is_attr_defined(context, fmi_attr_id_relativeQuantity); - int hasUnb = fmi3_xml_is_attr_defined(context, fmi_attr_id_unbounded); + int hasUnit = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_unit)) + || fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_displayUnit)); + int hasMin = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_min)); + int hasMax = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_max)); + int hasNom = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_nominal)); + int hasQuan = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_quantity)); + int hasRelQ = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_relativeQuantity)); + int hasUnb = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_unbounded)); if (hasUnit || hasMin || hasMax || hasNom || hasQuan || hasRelQ || hasUnb) { /* create a new type_props that overrides declared type's properties when necessary */ @@ -1749,7 +1750,7 @@ int fmi3_xml_handle_FloatXX(fmi3_xml_parser_context_t* context, const char* data } if (fmi3_xml_variable_is_array(variable)) { size_t nArr; /* TODO: do something with this, e.g. dimension size verification */ - if (fmi3_xml_parse_attr_as_array(context, elmID, fmi_attr_id_start, 0, (void**)&start->start, &nArr, startAttr, primType)) { + if (fmi3_xml_parse_attr_as_array(context, elmID, FMI3_ATTR(fmi_attr_id_start), 0, (void**)&start->start, &nArr, startAttr, primType)) { // start failed to parse as array // TODO: Can one get these from some sort of defaults instead? start->start.array64s = NULL; @@ -1764,7 +1765,7 @@ int fmi3_xml_handle_FloatXX(fmi3_xml_parser_context_t* context, const char* data /* restore the attribute buffer before it's used in set_attr_float */ jm_vector_set_item(jm_string)(context->attrMapById, fmi_attr_id_start, startAttr); - if (fmi3_xml_parse_attr_as_floatXX(context, elmID, fmi_attr_id_start, 0, &start->start, + if (fmi3_xml_parse_attr_as_floatXX(context, elmID, FMI3_ATTR(fmi_attr_id_start), 0, &start->start, fmi3_xml_get_type_default_value(primType->baseType), primType)) { return -1; } @@ -1782,7 +1783,7 @@ int fmi3_xml_handle_FloatXX(fmi3_xml_parser_context_t* context, const char* data int fmi3_xml_handle_IntXX(fmi3_xml_parser_context_t* context, const char* data, fmi3_xml_int_type_props_t* defaultType, - fmi3_xml_elm_enu_t elmID, /* ID of the Type (not the Variable) */ + fmi3_xml_elm_t elmID, /* ID of the Type (not the Variable) */ const fmi3_xml_primitive_type_t* primType) { /* Extract common Variable info & handle errors*/ @@ -1801,9 +1802,9 @@ int fmi3_xml_handle_IntXX(fmi3_xml_parser_context_t* context, const char* data, declaredType = fmi3_parse_declared_type_attr(context, elmID, &defaultType->super) ; if (!declaredType) return -1; - int hasMin = fmi3_xml_is_attr_defined(context, fmi_attr_id_min); - int hasMax = fmi3_xml_is_attr_defined(context, fmi_attr_id_max); - int hasQuan = fmi3_xml_is_attr_defined(context, fmi_attr_id_quantity); + int hasMin = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_min)); + int hasMax = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_max)); + int hasQuan = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_quantity)); if (hasMin || hasMax || hasQuan) { type = fmi3_xml_parse_intXX_type_properties(context, elmID, declaredType, primType); if (!type) { @@ -1830,7 +1831,7 @@ int fmi3_xml_handle_IntXX(fmi3_xml_parser_context_t* context, const char* data, } if (fmi3_xml_variable_is_array(variable)) { size_t nArr; /* TODO: do something with this, e.g. dimension size verification */ - if (fmi3_xml_parse_attr_as_array(context, elmID, fmi_attr_id_start, 0, + if (fmi3_xml_parse_attr_as_array(context, elmID, FMI3_ATTR(fmi_attr_id_start), 0, (void**)&start->start, &nArr, startAttr, primType)) { // start failed to parse as array // TODO: Can one get these from some sort of defaults instead? @@ -1853,7 +1854,7 @@ int fmi3_xml_handle_IntXX(fmi3_xml_parser_context_t* context, const char* data, fmi3_int_union_t defaultVal; defaultVal.scalar64s = 0; /* set the whole bitfield to 0 - this will evaluate to '0' for all intXX types */ - if (fmi3_xml_parse_attr_as_intXX(context, elmID, fmi_attr_id_start, 0, &start->start, &defaultVal, primType)) { + if (fmi3_xml_parse_attr_as_intXX(context, elmID, FMI3_ATTR(fmi_attr_id_start), 0, &start->start, &defaultVal, primType)) { jm_log_error(context->callbacks, module, "failed to parse start value for integer"); return -1; } @@ -1872,7 +1873,7 @@ int fmi3_xml_handle_IntXX(fmi3_xml_parser_context_t* context, const char* data, int fmi3_xml_handle_##TYPE##BITNESS(fmi3_xml_parser_context_t* context, const char* data) { \ return fmi3_xml_handle_##TYPE_NO_SIGN##XX(context, data, \ &context->modelDescription->typeDefinitions.default##TYPE##BITNESS##Type, \ - fmi3_xml_elmID_##TYPE##BITNESS, &PRIMITIVE_TYPES.TYPE_LC##BITNESS); \ + FMI3_ELM(fmi3_xml_elmID_##TYPE##BITNESS), &PRIMITIVE_TYPES.TYPE_LC##BITNESS); \ } gen_fmi3_xml_handle_TYPEXX(Float, Float, float, 64) @@ -1901,7 +1902,7 @@ int fmi3_xml_handle_Boolean(fmi3_xml_parser_context_t *context, const char* data assert(!variable->type); - variable->type = fmi3_parse_declared_type_attr(context, fmi3_xml_elmID_Boolean, &td->defaultBooleanType) ; + variable->type = fmi3_parse_declared_type_attr(context, FMI3_ELM(fmi3_xml_elmID_Boolean), &td->defaultBooleanType) ; if (!variable->type) {return -1;} } else { @@ -1918,7 +1919,7 @@ int fmi3_xml_handle_Boolean(fmi3_xml_parser_context_t *context, const char* data } if (fmi3_xml_variable_is_array(variable)) { size_t nArr; - if (fmi3_xml_parse_attr_as_array(context, fmi3_xml_elmID_Boolean, fmi_attr_id_start, + if (fmi3_xml_parse_attr_as_array(context, FMI3_ELM(fmi3_xml_elmID_Boolean), FMI3_ATTR(fmi_attr_id_start), 0, (void**)&start->start, &nArr, startAttr, &PRIMITIVE_TYPES.boolean)) { // start failed to parse as array // TODO: Can one get these from some sort of defaults instead? @@ -1937,7 +1938,7 @@ int fmi3_xml_handle_Boolean(fmi3_xml_parser_context_t *context, const char* data /* restore the attribute buffer before it's used in set_attr_boolean */ jm_vector_set_item(jm_string)(context->attrMapById, fmi_attr_id_start, startAttr); - if (fmi3_xml_parse_attr_as_boolean(context, fmi3_xml_elmID_Boolean, fmi_attr_id_start, 0, + if (fmi3_xml_parse_attr_as_boolean(context, FMI3_ELM(fmi3_xml_elmID_Boolean), FMI3_ATTR(fmi_attr_id_start), 0, (unsigned int*)&start->start.scalar32s, 0)) { return -1; } @@ -1958,19 +1959,19 @@ int fmi3_xml_handle_Binary(fmi3_xml_parser_context_t* context, const char* data) // No Variable was created return -1; // continue parsing, skips nested elements } - fmi3_xml_elm_enu_t elmID = fmi3_xml_elmID_Binary; // The ID corresponding to the actual parsed element name + fmi3_xml_elm_t elmID = FMI3_ELM(fmi3_xml_elmID_Binary); // The ID corresponding to the actual parsed element name fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_type_definition_list_t* td = &md->typeDefinitions; fmi3_xml_variable_t* variable = jm_vector_get_last(jm_voidp)(&md->variablesOrigOrder); if (!data) { - fmi3_xml_set_element_handle(context, "Start", fmi3_xml_elmID_BinaryVariableStart); + fmi3_xml_set_element_handle(context, "Start", FMI3_ELM(fmi3_xml_elmID_BinaryVariableStart)); fmi3_xml_binary_type_props_t* vProps; // Variable props fmi3_xml_variable_type_base_t* declaredType = fmi3_parse_declared_type_attr(context, elmID, &td->defaultBinaryType.super); - int hasMimeType = fmi3_xml_is_attr_defined(context, fmi_attr_id_mimeType); - int hasMaxSize = fmi3_xml_is_attr_defined(context, fmi_attr_id_maxSize); + int hasMimeType = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_mimeType)); + int hasMaxSize = fmi3_xml_is_attr_defined(context, FMI3_ATTR(fmi_attr_id_maxSize)); if (hasMimeType || hasMaxSize) { // Create binary properties: vProps = fmi3_xml_parse_binary_type_properties(context, elmID, declaredType); @@ -2037,7 +2038,7 @@ int fmi3_xml_handle_Clock(fmi3_xml_parser_context_t* context, const char* data) } if (!data) { - fmi3_xml_elm_enu_t elmID = fmi3_xml_elmID_Clock; // The ID corresponding to the actual parsed element name + fmi3_xml_elm_t elmID = FMI3_ELM(fmi3_xml_elmID_Clock); // The ID corresponding to the actual parsed element name fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_type_definition_list_t* td = &md->typeDefinitions; fmi3_xml_variable_t* variable = jm_vector_get_last(jm_voidp)(&md->variablesOrigOrder); @@ -2081,10 +2082,10 @@ int fmi3_xml_handle_String(fmi3_xml_parser_context_t *context, const char* data) fmi3_xml_variable_t* variable = jm_vector_get_last(jm_voidp)(&md->variablesOrigOrder); if (!data) { - fmi3_xml_set_element_handle(context, "Start", fmi3_xml_elmID_StringVariableStart); + fmi3_xml_set_element_handle(context, "Start", FMI3_ELM(fmi3_xml_elmID_StringVariableStart)); assert(!variable->type); - variable->type = fmi3_parse_declared_type_attr(context, fmi3_xml_elmID_String, &td->defaultStringType) ; + variable->type = fmi3_parse_declared_type_attr(context, FMI3_ELM(fmi3_xml_elmID_String), &td->defaultStringType) ; if (!variable->type) return -1; } else { @@ -2127,7 +2128,7 @@ int fmi3_xml_handle_StringVariableStart(fmi3_xml_parser_context_t* context, cons /* For each , allocate memory, copy attribute to 'value' and push back to 'vec'. */ jm_vector(jm_voidp)* vec = &context->currentStartVariableValues; const char* attr; - if (fmi3_xml_get_attr_str(context, fmi3_xml_elmID_StringVariableStart, fmi_attr_id_value, 0, &attr)) return -1; + if (fmi3_xml_get_attr_str(context, FMI3_ELM(fmi3_xml_elmID_StringVariableStart), FMI3_ATTR(fmi_attr_id_value), 0, &attr)) return -1; char* attrValue = context->callbacks->malloc(strlen(attr) + 1); strcpy(attrValue, attr); jm_vector_push_back(jm_voidp)(vec, attrValue); @@ -2155,12 +2156,12 @@ int fmi3_xml_handle_BinaryVariableStart(fmi3_xml_parser_context_t* context, cons /* For each , allocate memory, copy attribute to 'value' and push back to 'vec'. */ jm_vector(jm_voidp)* vec = &context->currentStartVariableValues; - if (!fmi3_xml_peek_attr_str(context, fmi_attr_id_value)) { + if (!fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_value))) { fmi3_xml_parse_error(context, "Start missing the required attribute 'value'"); return -1; // Parsing start element failed } const char* attr; - if (fmi3_xml_get_attr_str(context, fmi3_xml_elmID_BinaryVariableStart, fmi_attr_id_value, 0, &attr)) {return -1;} + if (fmi3_xml_get_attr_str(context, FMI3_ELM(fmi3_xml_elmID_BinaryVariableStart), FMI3_ATTR(fmi_attr_id_value), 0, &attr)) {return -1;} int len = attr ? strlen(attr) : 0; if (len == 0) { fmi3_xml_parse_error(context, "Empty value attribute in Start element"); @@ -2171,7 +2172,7 @@ int fmi3_xml_handle_BinaryVariableStart(fmi3_xml_parser_context_t* context, cons jm_vector_push_back(jm_voidp)(vec, attrAsStr); } else { jm_vector(char)* bufStartStr = fmi3_xml_reserve_parse_buffer(context, 1, 100); - if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_BinaryVariableStart, fmi_attr_id_value, 0, bufStartStr)) { + if (fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_BinaryVariableStart), FMI3_ATTR(fmi_attr_id_value), 0, bufStartStr)) { return -1; } @@ -2204,7 +2205,7 @@ fmi3_xml_enum_variable_props_t* fmi3_xml_parse_enum_properties(fmi3_xml_parser_c fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_enum_variable_props_t* props = 0; - fmi3_xml_elm_enu_t elmID = fmi3_xml_elmID_Enumeration; + fmi3_xml_elm_t elmID = FMI3_ELM(fmi3_xml_elmID_Enumeration); const char* quantity = 0; jm_vector(char)* bufQuantity = fmi3_xml_reserve_parse_buffer(context,3,100); @@ -2212,15 +2213,15 @@ fmi3_xml_enum_variable_props_t* fmi3_xml_parse_enum_properties(fmi3_xml_parser_c props = (fmi3_xml_enum_variable_props_t*)fmi3_xml_alloc_variable_or_typedef_props(&md->typeDefinitions, &md->typeDefinitions.defaultEnumType.base.super, sizeof(fmi3_xml_enum_variable_props_t)); - if (!bufQuantity || !props || fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_quantity, 0, bufQuantity)) + if (!bufQuantity || !props || fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_quantity), 0, bufQuantity)) return 0; if (jm_vector_get_size(char)(bufQuantity)) quantity = jm_string_set_put(&md->typeDefinitions.quantities, jm_vector_get_itemp(char)(bufQuantity, 0)); props->quantity = (quantity == 0) ? declaredType->quantity : quantity; - if ( fmi3_xml_parse_attr_as_int32(context, elmID, fmi_attr_id_min, 0, &props->typeMin, declaredType->typeMin) || - fmi3_xml_parse_attr_as_int32(context, elmID, fmi_attr_id_max, 0, &props->typeMax, declaredType->typeMax)) { + if ( fmi3_xml_parse_attr_as_int32(context, elmID, FMI3_ATTR(fmi_attr_id_min), 0, &props->typeMin, declaredType->typeMin) || + fmi3_xml_parse_attr_as_int32(context, elmID, FMI3_ATTR(fmi_attr_id_max), 0, &props->typeMax, declaredType->typeMax)) { return 0; } @@ -2245,14 +2246,14 @@ int fmi3_xml_handle_Enumeration(fmi3_xml_parser_context_t *context, const char* assert(!variable->type); declaredType = fmi3_parse_declared_type_attr(context, - fmi3_xml_elmID_Enumeration,&td->defaultEnumType.base.super); + FMI3_ELM(fmi3_xml_elmID_Enumeration), &td->defaultEnumType.base.super); if (!declaredType) return -1; if ( - fmi3_xml_is_attr_defined(context,fmi_attr_id_min) || - fmi3_xml_is_attr_defined(context,fmi_attr_id_max) || - fmi3_xml_is_attr_defined(context,fmi_attr_id_quantity) + fmi3_xml_is_attr_defined(context,FMI3_ATTR(fmi_attr_id_min)) || + fmi3_xml_is_attr_defined(context,FMI3_ATTR(fmi_attr_id_max)) || + fmi3_xml_is_attr_defined(context,FMI3_ATTR(fmi_attr_id_quantity)) ) { fmi3_xml_enum_variable_props_t* dtProps = 0; /* declaredType properties */ @@ -2287,7 +2288,7 @@ int fmi3_xml_handle_Enumeration(fmi3_xml_parser_context_t *context, const char* } if (fmi3_xml_variable_is_array(variable)) { size_t nArr; /* TODO: do something with this, e.g. dimension size verification */ - if (fmi3_xml_parse_attr_as_array(context, fmi3_xml_elmID_Enumeration, fmi_attr_id_start, 0, + if (fmi3_xml_parse_attr_as_array(context, FMI3_ELM(fmi3_xml_elmID_Enumeration), FMI3_ATTR(fmi_attr_id_start), 0, (void**)&start->start, &nArr, startAttr, &PRIMITIVE_TYPES.enumeration)) { // start failed to parse as array // TODO: Can one get these from some sort of defaults instead? @@ -2306,8 +2307,8 @@ int fmi3_xml_handle_Enumeration(fmi3_xml_parser_context_t *context, const char* /* restore the attribute buffer before it's used in set_attr_int */ jm_vector_set_item(jm_string)(context->attrMapById, fmi_attr_id_start, startAttr); - if (fmi3_xml_parse_attr_as_intXX(context, fmi3_xml_elmID_Enumeration, - fmi_attr_id_start, 0, &start->start.scalar64s, 0, &PRIMITIVE_TYPES.enumeration)) { + if (fmi3_xml_parse_attr_as_intXX(context, FMI3_ELM(fmi3_xml_elmID_Enumeration), + FMI3_ATTR(fmi_attr_id_start), 0, &start->start.scalar64s, 0, &PRIMITIVE_TYPES.enumeration)) { start->start.scalar64s = type->typeMin; } } @@ -2322,21 +2323,21 @@ int fmi3_xml_handle_Enumeration(fmi3_xml_parser_context_t *context, const char* int fmi3_xml_handle_Alias(fmi3_xml_parser_context_t* context, const char* data) { if (!data) { - fmi3_xml_elm_enu_t elmID = fmi3_xml_elmID_Alias; + fmi3_xml_elm_t elmID = FMI3_ELM(fmi3_xml_elmID_Alias); fmi3_xml_model_description_t* md = context->modelDescription; fmi3_xml_variable_t* baseVar = jm_vector_get_last(jm_voidp)(&md->variablesOrigOrder); size_t bufIdx = 1; // FIXME: bufDesc will have size==0 when the attribute value is the empty string, // making it indistinguishable from not being defined at all. - bool hasDesc = fmi3_xml_peek_attr_str(context, fmi_attr_id_description) != NULL; + bool hasDesc = fmi3_xml_peek_attr_str(context, FMI3_ATTR(fmi_attr_id_description)) != NULL; // Read the attributes to memory owned by FMIL: jm_vector(char)* bufName = fmi3_xml_reserve_parse_buffer(context, bufIdx++, 100); jm_vector(char)* bufDesc = fmi3_xml_reserve_parse_buffer(context, bufIdx++, 100); if (!bufName || !bufDesc) return -1; - if (fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_name, 1, bufName)) return -1; - if (fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_description, 0, bufDesc)) return -1; + if (fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_name), 1, bufName)) return -1; + if (fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_description), 0, bufDesc)) return -1; // Create the alias and set name at same time: const char* name; @@ -2370,7 +2371,7 @@ int fmi3_xml_handle_Alias(fmi3_xml_parser_context_t* context, const char* data) if (fmi3_base_type_enu_is_float(fmi3_xml_get_variable_base_type(baseVar))) { jm_vector(char)* bufDisplayUnit = fmi3_xml_reserve_parse_buffer(context, bufIdx++, 100); if (!bufDisplayUnit) return -1; - if (fmi3_xml_parse_attr_as_string(context, elmID, fmi_attr_id_displayUnit, 0, bufDisplayUnit)) return -1; + if (fmi3_xml_parse_attr_as_string(context, elmID, FMI3_ATTR(fmi_attr_id_displayUnit), 0, bufDisplayUnit)) return -1; if (jm_vector_get_size(char)(bufDisplayUnit)) { jm_named_ptr searchKey, *searchRes; searchKey.name = jm_vector_get_itemp(char)(bufDisplayUnit, 0); diff --git a/src/XML/src/FMI3/fmi3_xml_vendor_annotations.c b/src/XML/src/FMI3/fmi3_xml_vendor_annotations.c index 47531837..8712e11b 100644 --- a/src/XML/src/FMI3/fmi3_xml_vendor_annotations.c +++ b/src/XML/src/FMI3/fmi3_xml_vendor_annotations.c @@ -40,16 +40,16 @@ int fmi3_xml_handle_Annotations(fmi3_xml_parser_context_t *context, const char* } int fmi3_xml_handle_VariableTool(fmi3_xml_parser_context_t *context, const char* data) { - if(!data) { + if (!data) { size_t len; fmi3_xml_model_description_t* md = context->modelDescription; jm_vector(char)* bufName = fmi3_xml_reserve_parse_buffer(context,1,100); jm_string *pvendor; char* vendor = 0; - if(!bufName) return -1; + if (!bufName) return -1; /* */ - if( fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Tool, fmi_attr_id_name, 1, bufName)) + if (fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Tool), FMI3_ATTR(fmi_attr_id_name), 1, bufName)) return -1; pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor); len = jm_vector_get_size(char)(bufName); @@ -85,7 +85,7 @@ int fmi3_xml_handle_Tool(fmi3_xml_parser_context_t *context, const char* data) { if (!bufName) return -1; /* */ - if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Tool, fmi_attr_id_name, 1, bufName)) + if (fmi3_xml_parse_attr_as_string(context, FMI3_ELM(fmi3_xml_elmID_Tool), FMI3_ATTR(fmi_attr_id_name), 1, bufName)) return -1; pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor); len = jm_vector_get_size(char)(bufName);