diff --git a/fmusim/FMIModelDescription.c b/fmusim/FMIModelDescription.c index 4d1aa190..390cf010 100644 --- a/fmusim/FMIModelDescription.c +++ b/fmusim/FMIModelDescription.c @@ -186,8 +186,6 @@ static FMIModelDescription* readModelDescriptionFMI1(xmlNodePtr root) { xmlXPathFreeContext(xpathCtx); - nProblems += FMIValidateVariableNames(modelDescription); - if (nProblems > 0) { FMIFreeModelDescription(modelDescription); modelDescription = NULL; @@ -403,8 +401,6 @@ static FMIModelDescription* readModelDescriptionFMI2(xmlNodePtr root) { nProblems += FMIValidateModelDescription(modelDescription); - nProblems += FMIValidateVariableNames(modelDescription); - if (nProblems > 0) { FMIFreeModelDescription(modelDescription); modelDescription = NULL; @@ -681,8 +677,6 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) { nProblems += FMIValidateModelDescription(modelDescription); - nProblems += FMIValidateVariableNames(modelDescription); - if (nProblems > 0) { FMIFreeModelDescription(modelDescription); modelDescription = NULL; @@ -990,10 +984,35 @@ static bool isLegalCombination(FMIModelVariable* variable) { return false; } +void set_input_string(const char* in); + +void end_lexical_scan(void); + +void yyerror(const FMIModelVariable* variable, const char* s) { + printf("\"%s\" (line %d) is not a valid variable name for variableNamingConvention=\"structured\".\n", variable->name, variable->line); +} + size_t FMIValidateModelDescription(const FMIModelDescription* modelDescription) { size_t nProblems = 0; + // validate structured variable names + if (modelDescription->variableNamingConvention == FMIStructured) { + + for (size_t i = 0; i < modelDescription->nModelVariables; i++) { + + const FMIModelVariable* variable = &modelDescription->modelVariables[i]; + + set_input_string(variable->name); + + if (yyparse(variable)) { + nProblems++; + } + + end_lexical_scan(); + } + } + // check combinations of causality, variability, and initial for (size_t i = 0; i < modelDescription->nModelVariables; i++) { @@ -1025,37 +1044,6 @@ size_t FMIValidateModelDescription(const FMIModelDescription* modelDescription) return nProblems; } -/* Declarations */ -void set_input_string(const char* in); -void end_lexical_scan(void); - -void yyerror(const FMIModelVariable* variable, const char* s) { - printf("\"%s\" (line %d) is not a valid variable name for variableNamingConvention=\"structured\".\n", variable->name, variable->line); -} - -size_t FMIValidateVariableNames(const FMIModelDescription* modelDescription) { - - size_t nProblems = 0; - - if (modelDescription->variableNamingConvention == FMIStructured) { - - for (size_t i = 0; i < modelDescription->nModelVariables; i++) { - - const FMIModelVariable* variable = &modelDescription->modelVariables[i]; - - set_input_string(variable->name); - - if (yyparse(variable)) { - nProblems++; - } - - end_lexical_scan(); - } - } - - return nProblems; -} - void FMIDumpModelDescription(FMIModelDescription* modelDescription, FILE* file) { fprintf(file, "FMI Version 3.0\n"); diff --git a/fmusim/FMIModelDescription.h b/fmusim/FMIModelDescription.h index 489bcd5d..b02ce694 100644 --- a/fmusim/FMIModelDescription.h +++ b/fmusim/FMIModelDescription.h @@ -145,6 +145,4 @@ FMIModelVariable* FMIModelVariableForIndexLiteral(const FMIModelDescription* mod size_t FMIValidateModelDescription(const FMIModelDescription* modelDescription); -size_t FMIValidateVariableNames(const FMIModelDescription* modelDescription); - void FMIDumpModelDescription(FMIModelDescription* modelDescription, FILE* file);