Skip to content

Commit

Permalink
tentative successful separation
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Meisrimel authored and Peter Meisrimel committed Aug 5, 2024
1 parent 408eb79 commit 773d292
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/XML/src/FMI/fmi_xml_terminals_and_icons.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int fmi_xml_handle_fmiTerminalsAndIcons(fmi3_xml_parser_context_t* context, cons
}
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_termIcon_xml_elmID_fmiTerminalsAndIcons, fmi_attr_id_fmiVersion, 1 /* required */,
&(termIcon->fmi3_xml_standard_version));
if (ret) {
return ret;
Expand Down Expand Up @@ -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_termIcon_xml_elmID_Terminal, 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)) {
Expand Down
22 changes: 11 additions & 11 deletions src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ extern "C" {
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_modelDescription_elmID_none, fmi3_xml_modelDescription_elmID_none, 0, 0}
// #define fmi3_xml_scheme_fmiTerminalsAndIcons {fmi3_xml_modelDescription_elmID_none, fmi3_xml_modelDescription_elmID_none, 0, 0}

#define fmi3_xml_scheme_Terminals {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_fmiTerminalsAndIcons, 1, 0}
#define fmi3_xml_scheme_Terminal {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminals, 0, 1}
#define fmi3_xml_scheme_TerminalMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 0, 1}
#define fmi3_xml_scheme_TerminalStreamMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 1, 1}
// #define fmi3_xml_scheme_Terminals {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_fmiTerminalsAndIcons, 1, 0}
// #define fmi3_xml_scheme_Terminal {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminals, 0, 1}
// #define fmi3_xml_scheme_TerminalMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 0, 1}
// #define fmi3_xml_scheme_TerminalStreamMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 1, 1}
// TODO: How to handle nested Terminals?
#define fmi3_xml_scheme_TerminalGraphicalRepresentation {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 3, 0}
// #define fmi3_xml_scheme_TerminalGraphicalRepresentation {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 3, 0}
// TODO: List formatting + use terminals and Icons type
// TODO: rename to include termIcon in name?

Expand All @@ -62,12 +62,12 @@ extern "C" {
// TODO: Right hand side: fmi_termIcon rename
#define fmi_termIcon_xml_scheme_fmiTerminalsAndIcons {fmi3_xml_modelDescription_elmID_none, fmi3_xml_modelDescription_elmID_none, 0, 0}

#define fmi_termIcon_xml_scheme_Terminals {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_fmiTerminalsAndIcons, 1, 0}
#define fmi_termIcon_xml_scheme_Terminal {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminals, 0, 1}
#define fmi_termIcon_xml_scheme_TerminalMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 0, 1}
#define fmi_termIcon_xml_scheme_TerminalStreamMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 1, 1}
#define fmi_termIcon_xml_scheme_Terminals {fmi3_xml_modelDescription_elmID_none, fmi_termIcon_xml_elmID_fmiTerminalsAndIcons, 1, 0}
#define fmi_termIcon_xml_scheme_Terminal {fmi3_xml_modelDescription_elmID_none, fmi_termIcon_xml_elmID_Terminals, 0, 1}
#define fmi_termIcon_xml_scheme_TerminalMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi_termIcon_xml_elmID_Terminal, 0, 1}
#define fmi_termIcon_xml_scheme_TerminalStreamMemberVariable {fmi3_xml_modelDescription_elmID_none, fmi_termIcon_xml_elmID_Terminal, 1, 1}
// TODO: How to handle nested Terminals?
#define fmi_termIcon_xml_scheme_TerminalGraphicalRepresentation {fmi3_xml_modelDescription_elmID_none, fmi3_xml_elmID_Terminal, 3, 0}
#define fmi_termIcon_xml_scheme_TerminalGraphicalRepresentation {fmi3_xml_modelDescription_elmID_none, fmi_termIcon_xml_elmID_Terminal, 3, 0}

#ifdef __cplusplus
}
Expand Down
23 changes: 10 additions & 13 deletions src/XML/src/FMI3/fmi3_xml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ static jm_string fmi3_xml_get_xml_attr_name(fmi3_xml_parser_context_t* context,
/* Global array of all modelDescription scheme_info_t. Index it with fmi3_xml_modelDescription_elm_enu_t entries. */
const fmi3_xml_modelDescription_scheme_info_t fmi3_xml_modelDescription_scheme_info[fmi3_xml_modelDescription_elm_number] = {
FMI3_XML_ELMLIST_MODEL_DESCR(EXPAND_ELM_SCHEME)
FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_SCHEME)
{fmi3_xml_modelDescription_elm_actual_number,0,0},
{fmi3_xml_modelDescription_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)
};

Expand All @@ -91,7 +89,7 @@ const fmi3_xml_modelDescription_scheme_info_t fmi3_xml_modelDescription_scheme_i
/* Global array of all termIcon scheme_info_t. Index it with fmi3_xml_termIcon_elm_enu_t entries. */
fmi3_xml_termIcon_scheme_info_t fmi_termIcon_xml_scheme_info[fmi3_xml_termIcon_elm_number] = {
FMI_XML_ELMLIST_TERM_ICON(EXPAND_ELM_SCHEME_TERMICON)
{fmi3_xml_termIcon_elm_actual_number,0,0},
{fmi3_xml_termIcon_elm_actual_number, 0, 0},
FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_SCHEME_TERMICON)
};

Expand Down Expand Up @@ -136,7 +134,7 @@ static fmi3_xml_scheme_info_t fmi3_xml_get_scheme_info(fmi3_xml_parser_context_t
}

#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_termIcon_xml_elmID_##elm},

/**
* Global array of all defined fmi3_xml_modelDescription_element_handle_map_t structs.
Expand All @@ -146,17 +144,15 @@ static fmi3_xml_scheme_info_t fmi3_xml_get_scheme_info(fmi3_xml_parser_context_t
*/
const fmi3_xml_modelDescription_element_handle_map_t fmi3_modelDescription_element_handle_map[fmi3_xml_modelDescription_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_modelDescription_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 fmi3_xml_termIcon_element_handle_map_t fmi3_termIcon_element_handle_map[fmi3_xml_termIcon_elm_number] = {
FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_NAME_FMI_TERM_ICON)
FMI_XML_ELMLIST_TERM_ICON(EXPAND_ELM_NAME_FMI_TERM_ICON)
{ NULL, NULL, fmi3_xml_termIcon_elm_actual_number},
FMI_XML_ELMLIST_ALT_TERM_ICON (EXPAND_ELM_NAME_FMI_TERM_ICON)
FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_NAME_FMI_TERM_ICON)
};

// TODO: Move to more suitable place?
Expand Down Expand Up @@ -1220,6 +1216,7 @@ static void XMLCALL fmi3_parse_element_start(void *c, const char *elm, const cha
int i;
fmi3_xml_parser_context_t* context = c;
context->has_produced_data_warning = 0;
size_t mapSize = fmi3_get_map_size(context);

if (context->useAnyHandleFlg) {
fmi3_xml_callbacks_t* anyH = context->anyHandle;
Expand Down Expand Up @@ -1354,7 +1351,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_modelDescription_xml_attr_number; i++) {
for (int i = 0; i < mapSize; i++) {
if (jm_vector_get_item(jm_string)(context->attrMapById, i)) {
jm_vector_set_item(jm_string)(context->attrMapById, i, NULL);
}
Expand All @@ -1364,7 +1361,7 @@ 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_modelDescription_xml_attr_number; i++) {
for (i = 0; i < mapSize; 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_xml_get_xml_attr_name(context, i), elm);
Expand Down Expand Up @@ -1605,8 +1602,8 @@ int fmi3_xml_parse_terminals_and_icons(fmi_xml_terminals_and_icons_t* termIcon,
FILE* file;

// TODO
context = fmi3_xml_allocate_parser_context(termIcon->callbacks, fmi3_xml_type_modelDescription);
// context = fmi3_xml_allocate_parser_context(termIcon->callbacks, fmi3_xml_type_terminalAndIcons);
// context = fmi3_xml_allocate_parser_context(termIcon->callbacks, fmi3_xml_type_modelDescription);
context = fmi3_xml_allocate_parser_context(termIcon->callbacks, fmi3_xml_type_terminalAndIcons);

// try to open file before doing parser initialization
file = fopen(filename, "rb");
Expand Down
12 changes: 1 addition & 11 deletions src/XML/src/FMI3/fmi3_xml_parser_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ extern "C" {
/** \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)
FMI3_XML_ATTRLIST_MODEL_DESCR(EXPAND_XML_ATTRNAME)

#define FMI3_XML_ATTR_ID(attr) fmi_attr_id_##attr,
typedef enum fmi3_xml_modelDescription_attr_enu_t {
Expand All @@ -53,13 +52,6 @@ typedef enum fmi3_xml_termIcon_attr_enu_t {
} fmi3_xml_termIcon_attr_enu_t;

typedef int fmi3_xml_attr_enu_t;
// typedef union fmi3_xml_attr_enu_t {
// fmi3_xml_modelDescription_attr_enu_t modelDescription;
// fmi3_xml_termIcon_attr_enu_t termIcon;
// } fmi3_xml_attr_enu_t;

// #define FMI3_MODELDESCRIPTION_ATTR(attr) (const fmi3_xml_attr_enu_t){.modelDescription = attr}
// #define FMI_TERMICON_ATTR(attr) (const fmi3_xml_attr_enu_t){.termIcon = attr}

/* Build prototypes for all elm_handle_* functions */
typedef struct fmi3_xml_parser_context_t fmi3_xml_parser_context_t;
Expand All @@ -85,10 +77,8 @@ FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_HANDLE_FMI_TERM_ICON)
typedef enum fmi3_xml_modelDescription_elm_enu_t {
fmi3_xml_modelDescription_elmID_none = -1
FMI3_XML_ELMLIST_MODEL_DESCR(FMI3_XML_LIST_ELM_ID)
FMI_XML_ELMLIST_TERM_ICON (FMI3_XML_LIST_ELM_ID)
,fmi3_xml_modelDescription_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_modelDescription_elm_number
} fmi3_xml_modelDescription_elm_enu_t;
Expand Down

0 comments on commit 773d292

Please sign in to comment.