Skip to content

Commit

Permalink
More cleanup; renamings for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Meisrimel authored and Peter Meisrimel committed Aug 7, 2024
1 parent 8ed041d commit 01322b3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C" {
#define FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_XML_ELMNAME) // TODO: Terminal should go here?

/*
Define XML schema structure. Used to build the 'fmi3_xml_termIcon_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
Expand Down
2 changes: 1 addition & 1 deletion src/XML/src/FMI3/fmi3_xml_model_description_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ 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_modelDescription_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
Expand Down
28 changes: 14 additions & 14 deletions src/XML/src/FMI3/fmi3_xml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static jm_string fmi3_xml_get_xml_attr_name(fmi3_xml_parser_context_t* context,
#define EXPAND_ELM_SCHEME(elm) fmi3_xml_scheme_##elm ,

/* Global array of all modelDescription scheme_info_t. Index it with fmi3_xml_elm_modelDescription_enu_t entries. */
const fmi3_xml_modelDescription_scheme_info_t fmi3_xml_modelDescription_scheme_info[fmi3_xml_elm_number] = {
const fmi3_xml_scheme_modelDescription_info_t fmi3_xml_scheme_modelDescription_info[fmi3_xml_elm_number] = {
FMI3_XML_ELMLIST_MODEL_DESCR(EXPAND_ELM_SCHEME)
{fmi3_xml_elm_actual_number, 0, 0},
FMI3_XML_ELMLIST_ALT_MODEL_DESCR (EXPAND_ELM_SCHEME)
Expand All @@ -79,7 +79,7 @@ const fmi3_xml_modelDescription_scheme_info_t fmi3_xml_modelDescription_scheme_i

#define EXPAND_ELM_SCHEME_TERMICON(elm) fmi_xml_scheme_termIcon_##elm ,
/* Global array of all termIcon scheme_info_t. Index it with fmi_xml_elm_termIcon_enu_t entries. */
fmi3_xml_termIcon_scheme_info_t fmi_xml_scheme_termIcon_info[fmi_xml_elm_termIcon_number] = {
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)
Expand All @@ -89,13 +89,13 @@ fmi3_xml_termIcon_scheme_info_t fmi_xml_scheme_termIcon_info[fmi_xml_elm_termIco
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_modelDescription_scheme_info_t info_modelDescription;
fmi3_xml_termIcon_scheme_info_t info_termIcon;
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_modelDescription_scheme_info[enu.modelDescription];
info_modelDescription = fmi3_xml_scheme_modelDescription_info[enu.modelDescription];

ret.superID = FMI3_ELM(info_modelDescription.superID);
ret.parentID = FMI3_ELM(info_modelDescription.parentID);
Expand All @@ -112,10 +112,10 @@ static fmi3_xml_scheme_info_t fmi3_xml_get_scheme_info(fmi3_xml_parser_context_t
break;
default:
// erroneous output
ret.superID = FMI3_ELM_ANY(-2);
ret.parentID = FMI3_ELM_ANY(-2);
ret.siblingIndex = -2;
ret.multipleAllowed = -2;
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;
}
Expand All @@ -136,7 +136,7 @@ const fmi3_xml_modelDescription_element_handle_map_t fmi3_modelDescription_eleme
FMI3_XML_ELMLIST_ABSTRACT_MODEL_DESCR(EXPAND_ELM_NAME_FMI3)
};

const fmi3_xml_termIcon_element_handle_map_t fmi3_termIcon_element_handle_map[fmi_xml_elm_termIcon_number] = {
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)
Expand All @@ -147,7 +147,7 @@ static fmi3_xml_element_handle_map_t fmi3_xml_get_element_handle(fmi3_xml_parser
const fmi3_xml_type_t xmlType = context->xmlType;

fmi3_xml_modelDescription_element_handle_map_t map_modelDescription;
fmi3_xml_termIcon_element_handle_map_t map_termIcon;
fmi_xml_termIcon_element_handle_map_t map_termIcon;

fmi3_xml_element_handle_map_t ret;
switch (xmlType) {
Expand All @@ -159,7 +159,7 @@ static fmi3_xml_element_handle_map_t fmi3_xml_get_element_handle(fmi3_xml_parser
ret.elemID = FMI3_ELM(map_modelDescription.elemID);
break;
case fmi3_xml_type_terminalAndIcons:
map_termIcon = fmi3_termIcon_element_handle_map[enu.termIcon];
map_termIcon = fmi_termIcon_element_handle_map[enu.termIcon];

ret.elementName = map_termIcon.elementName;
ret.elementHandle = (fmi3_xml_element_handle_ft) map_termIcon.elementHandle;
Expand Down Expand Up @@ -1094,7 +1094,7 @@ static int fmi3_create_elm_map(fmi3_xml_parser_context_t* context) {
}

/**
* Sets the elementHandle and elemID for an item in the'fmi3_modelDescription_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,
Expand Down Expand Up @@ -1442,7 +1442,7 @@ static fmi3_xml_parser_context_t* fmi3_xml_allocate_parser_context(
if (!context) {
jm_log_fatal(callbacks, "FMIXML", "Could not allocate memory for XML parser context");
}
// hacky way of getting around being able to set a const variable when using calloc/malloc
// 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;
Expand Down
4 changes: 2 additions & 2 deletions src/XML/src/FMI3/fmi3_xml_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ typedef struct {
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_modelDescription_scheme_info_t;
} 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*/
} fmi3_xml_termIcon_scheme_info_t;
} fmi_xml_scheme_termIcon_info_t;

typedef struct {
fmi3_xml_elm_t superID; /* ID of super type or NULL if none */
Expand Down
6 changes: 2 additions & 4 deletions src/XML/src/FMI3/fmi3_xml_parser_context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef enum fmi3_xml_type_t {
} fmi3_xml_type_t;

typedef struct fmi3_xml_modelDescription_element_handle_map_t fmi3_xml_modelDescription_element_handle_map_t;
typedef struct fmi3_xml_termIcon_element_handle_map_t fmi3_xml_termIcon_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);
Expand All @@ -49,7 +49,7 @@ struct fmi3_xml_modelDescription_element_handle_map_t {
fmi3_xml_elm_modelDescription_enu_t elemID;
};

struct fmi3_xml_termIcon_element_handle_map_t {
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;
Expand All @@ -62,8 +62,6 @@ struct fmi3_xml_element_handle_map_t {
};


// jm_vector_declare_template(fmi3_xml_modelDescription_element_handle_map_t)
// jm_vector_declare_template(fmi3_xml_termIcon_element_handle_map_t)
jm_vector_declare_template(fmi3_xml_element_handle_map_t)

/**
Expand Down
10 changes: 8 additions & 2 deletions src/XML/src/FMI3/fmi3_xml_parser_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ FMI_XML_ELMLIST_TERM_ICON (EXPAND_ELM_HANDLE_FMI_TERM_ICON)
FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_ELM_HANDLE_FMI_TERM_ICON)

/**
* 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_modelDescription_scheme_info
* - fmi3_xml_scheme_modelDescription_info
* - fmi3_modelDescription_element_handle_map
*/
#define FMI3_XML_ELM_ID(elm) fmi3_xml_elmID_##elm
Expand All @@ -77,6 +77,12 @@ typedef enum fmi3_xml_elm_modelDescription_enu_t {
,fmi3_xml_elm_number
} 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 {
Expand Down

0 comments on commit 01322b3

Please sign in to comment.