Skip to content

Commit

Permalink
Fixed compile time warnings in fmi 1.0 cs and me drivers. Mainly casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
cxbrooks committed Jun 4, 2014
1 parent c739415 commit 7881bb7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
5 changes: 4 additions & 1 deletion fmu10/src/co_simulation/fmusim_cs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ static int simulate(FMU* fmu, double tEnd, double h, fmiBoolean loggingOn, char
}

int main(int argc, char *argv[]) {
#if WINDOWS
const char* fmuFileName;

#else
char* fmuFileName;
#endif
// parse command line arguments and load the FMU
double tEnd = 1.0;
double h=0.1;
Expand Down
9 changes: 7 additions & 2 deletions fmu10/src/model_exchange/fmusim_me/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <string.h> //strerror()
#include "fmi_me.h"
#include "sim_support.h"

Expand All @@ -45,7 +46,7 @@ FMU fmu; // the fmu to simulate
// state events are checked and fired only at the end of an Euler step.
// the simulator may therefore miss state events and fires state events typically too late.
static int simulate(FMU* fmu, double tEnd, double h, fmiBoolean loggingOn, char separator) {
int i, n;
int i;
double dt, tPre;
fmiBoolean timeEvent, stateEvent, stepEvent;
double time;
Expand Down Expand Up @@ -87,7 +88,7 @@ static int simulate(FMU* fmu, double tEnd, double h, fmiBoolean loggingOn, char
z = (double *) calloc(nz, sizeof(double));
prez = (double *) calloc(nz, sizeof(double));
}
if (!x || !xdot || nz>0 && (!z || !prez)) return error("out of memory");
if ((!x || !xdot || nz>0) && (!z || !prez)) return error("out of memory");

// open result file
if (!(file=fopen(RESULT_FILE, "w"))) {
Expand Down Expand Up @@ -210,7 +211,11 @@ static int simulate(FMU* fmu, double tEnd, double h, fmiBoolean loggingOn, char
}

int main(int argc, char *argv[]) {
#if WINDOWS
const char* fmuFileName;
#else
char* fmuFileName;
#endif

// parse command line arguments and load the FMU
double tEnd = 1.0;
Expand Down
2 changes: 1 addition & 1 deletion fmu10/src/shared/sim_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static int loadDll(const char* dllPath, FMU *fmu) {
if (s==0) {
s = 1; // work around bug for FMUs exported using Dymola 2012 and SimulationX 3.x
fmu->getTypesPlatform = (fGetTypesPlatform) getAdr(&s, fmu, "fmiGetModelTypesPlatform");
if (s==1) printf(" using fmiGetModelTypesPlatform instead\n", dllPath);
if (s==1) printf(" using fmiGetModelTypesPlatform instead\n");
}
fmu->instantiateSlave = (fInstantiateSlave) getAdr(&s, fmu, "fmiInstantiateSlave");
fmu->initializeSlave = (fInitializeSlave) getAdr(&s, fmu, "fmiInitializeSlave");
Expand Down
51 changes: 31 additions & 20 deletions fmu10/src/shared/xml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ static int checkEnumValue(const char* enu);
// Returns -1 or a globally unique id for the value such that
// enuNames[id] is the string representation of the enum value.
Enu getEnumValue(void* element, Att a, ValueStatus* vs) {
// FIXME: Under Mac OS X: warning
// shared/xml_parser.c:121:14: warning: implicit conversion from enumeration type
// 'ValueStatus' to different enumeration type 'Enu' [-Wconversion]
// Enu id = valueDefined;
// FIXME: valueDefined, valueMissing and valueIllegal are enum ValueStatus
// enu_flat etc. are enum Enu.
const char* value = getString(element, a);
Enu id = valueDefined;
if (!value) {
Expand Down Expand Up @@ -206,8 +212,8 @@ ScalarVariable* getVariableByName(ModelDescription* md, const char* name) {
// Real, String, Boolean define own base types.
int sameBaseType(Elm t1, Elm t2){
return t1==t2 ||
t1==elm_Enumeration && t2==elm_Integer ||
t2==elm_Enumeration && t1==elm_Integer;
(t1==elm_Enumeration && t2==elm_Integer) ||
(t2==elm_Enumeration && t1==elm_Integer);
}

// returns NULL if variable not found or vr==fmiUndefinedValueReference
Expand Down Expand Up @@ -256,7 +262,6 @@ const char * getDescription(ModelDescription* md, ScalarVariable* sv) {
const char * getVariableAttributeString(ModelDescription* md,
fmiValueReference vr, Elm type, Att a){
const char* value;
const char* declaredType;
Type* tp;
ScalarVariable* sv = getVariable(md, vr, type);
if (!sv) return NULL;
Expand Down Expand Up @@ -695,15 +700,18 @@ void printElement(int indent, void* element){
// print child nodes
indent += 2;
switch (getAstNodeType(e->type)) {
case astElement:
// FIXME: Should we do anything for astElements?
break;
case astListElement:
printList(indent, ((ListElement*)e)->list);
printList(indent, (void **) ((ListElement*)e)->list);
break;
case astScalarVariable:
printElement(indent, ((Type*)e)->typeSpec);
printList(indent, ((ScalarVariable*)e)->directDependencies);
printList(indent, (void **) ((ScalarVariable*)e)->directDependencies);
break;
case astType:
printElement(indent, ((Type*)e)->typeSpec);
printElement(indent, (void **) ((Type*)e)->typeSpec);
break;
case astCoSimulation: {
CoSimulation* cs = (CoSimulation*)e;
Expand All @@ -713,11 +721,11 @@ void printElement(int indent, void* element){
}
case astModelDescription: {
ModelDescription *md = (ModelDescription*)e;
printList(indent, md->unitDefinitions);
printList(indent, md->typeDefinitions);
printList(indent, (void **) md->unitDefinitions);
printList(indent, (void **) md->typeDefinitions);
printElement(indent, md->defaultExperiment);
printList(indent, md->vendorAnnotations);
printList(indent, md->modelVariables);
printList(indent, (void **) md->vendorAnnotations);
printList(indent, (void **) md->modelVariables);
printElement(indent, md->cosimulation);
break;
}
Expand All @@ -733,23 +741,26 @@ static void printList(int indent, void** list){
// -------------------------------------------------------------------------
// free memory of the AST

static void freeList(void** list);
static void freeList(void** /*list*/);

void freeElement(void* element){
int i;
Element* e = (Element*)element;
if (!e) return;
// free attributes
for (i=0; i<e->n; i+=2)
free(e->attributes[i+1]);
free((void *)e->attributes[i+1]);
if (e->attributes) free(e->attributes);
// free child nodes
switch (getAstNodeType(e->type)) {
case astElement:
// FIXME: Should we do anything for astElements?
break;
case astListElement:
freeList(((ListElement*)e)->list);
freeList((void **) ((ListElement*)e)->list);
break;
case astScalarVariable:
freeList(((ScalarVariable*)e)->directDependencies);
freeList((void **) ((ScalarVariable*)e)->directDependencies);
case astType:
freeElement(((Type*)e)->typeSpec);
break;
Expand All @@ -761,11 +772,11 @@ void freeElement(void* element){
}
case astModelDescription: {
ModelDescription* md = (ModelDescription*)e;
freeList(md->unitDefinitions);
freeList(md->typeDefinitions);
freeList((void **) md->unitDefinitions);
freeList((void **) md->typeDefinitions);
freeElement(md->defaultExperiment);
freeList(md->vendorAnnotations);
freeList(md->modelVariables);
freeList((void **) md->vendorAnnotations);
freeList((void **) md->modelVariables);
freeElement(md->cosimulation);
break;
}
Expand All @@ -791,7 +802,7 @@ ModelDescription* validate(ModelDescription* md) {
if (md->modelVariables)
for (i=0; md->modelVariables[i]; i++){
ScalarVariable* sv = (ScalarVariable*)md->modelVariables[i];
char* declaredType = getString(sv->typeSpec, att_declaredType);
char* declaredType = (char *)getString(sv->typeSpec, att_declaredType);
Type* decltype = getDeclaredType(md, declaredType);
if (declaredType && decltype==NULL) {
printf("Warning: Declared type %s of variable %s not found in modelDescription.xml\n", declaredType, getName(sv));
Expand Down Expand Up @@ -841,7 +852,7 @@ ModelDescription* parse(const char* xmlPath) {
if (!XML_Parse(parser, text, n, done)){
printf("Parse error in file %s at line %d:\n%s\n",
xmlPath,
XML_GetCurrentLineNumber(parser),
(int) XML_GetCurrentLineNumber(parser),
XML_ErrorString(XML_GetErrorCode(parser)));
while (! stackIsEmpty(stack)) md = stackPop(stack);
if (md) freeElement(md);
Expand Down

0 comments on commit 7881bb7

Please sign in to comment.