Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store XML line number in variables #392

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions fmusim/FMIModelDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static FMIModelDescription* readModelDescriptionFMI1(xmlNodePtr root) {

FMIModelVariable* variable = &modelDescription->modelVariables[i];

variable->line = variableNode->line;
variable->name = (char*)xmlGetProp(variableNode, (xmlChar*)"name");
variable->description = (char*)xmlGetProp(variableNode, (xmlChar*)"description");

Expand Down Expand Up @@ -290,6 +291,7 @@ static FMIModelDescription* readModelDescriptionFMI2(xmlNodePtr root) {

FMIModelVariable* variable = &modelDescription->modelVariables[i];

variable->line = variableNode->line;
variable->name = (char*)xmlGetProp(variableNode, (xmlChar*)"name");
variable->description = (char*)xmlGetProp(variableNode, (xmlChar*)"description");

Expand Down Expand Up @@ -463,16 +465,17 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) {

FMIModelVariable* variable = &modelDescription->modelVariables[i];

xmlNodePtr node = xpathObj->nodesetval->nodeTab[i];
xmlNodePtr variableNode = xpathObj->nodesetval->nodeTab[i];

variable->name = (char*)xmlGetProp(node, (xmlChar*)"name");
variable->description = (char*)xmlGetProp(node, (xmlChar*)"description");
variable->line = variableNode->line;
variable->name = (char*)xmlGetProp(variableNode, (xmlChar*)"name");
variable->description = (char*)xmlGetProp(variableNode, (xmlChar*)"description");

FMIVariableType type;

const char* name = (char*)node->name;
const char* name = (char*)variableNode->name;

const char* variability = (char*)xmlGetProp(node, (xmlChar*)"variability");
const char* variability = (char*)xmlGetProp(variableNode, (xmlChar*)"variability");

if (!variability) {
variable->variability = -1; // infer from type
Expand Down Expand Up @@ -552,13 +555,13 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) {
}
}

const char* vr = (char*)xmlGetProp(node, (xmlChar*)"valueReference");
const char* vr = (char*)xmlGetProp(variableNode, (xmlChar*)"valueReference");

variable->valueReference = FMIValueReferenceForLiteral(vr);

free(vr);

const char* causality = (char*)xmlGetProp(node, (xmlChar*)"causality");
const char* causality = (char*)xmlGetProp(variableNode, (xmlChar*)"causality");

if (!causality) {
variable->causality = FMILocal;
Expand All @@ -580,9 +583,9 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) {

free(causality);

variable->derivative = (FMIModelVariable*)xmlGetProp(node, (xmlChar*)"derivative");
variable->derivative = (FMIModelVariable*)xmlGetProp(variableNode, (xmlChar*)"derivative");

xmlXPathObjectPtr xpathObj2 = xmlXPathNodeEval(node, ".//Dimension", xpathCtx);
xmlXPathObjectPtr xpathObj2 = xmlXPathNodeEval(variableNode, ".//Dimension", xpathCtx);

for (size_t j = 0; j < xpathObj2->nodesetval->nodeNr; j++) {

Expand Down
1 change: 1 addition & 0 deletions fmusim/FMIModelDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct FMIModelVariable {
size_t nDimensions;
FMIDimension* dimensions;
FMIModelVariable* derivative;
unsigned short line;

};

Expand Down
Loading