Skip to content

Commit

Permalink
Updated nfinst tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 28, 2017
1 parent 62a5fe8 commit 7befa22
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flattening/modelica/scodeinst/ClassExtends4.mo
Expand Up @@ -39,7 +39,7 @@ end ClassExtends4;

// Result:
// function SingleGasNasa.specificEnthalpy
// input ThermodynamicState state;
// input SingleGasNasa.ThermodynamicState state;
// output Real h;
// algorithm
// h := state.T;
Expand Down
33 changes: 33 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionExplicit1.mo
@@ -0,0 +1,33 @@
// name: ExternalFunctionExplicit1
// keywords:
// status: correct
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y;
external "C" y = ext(x);
end f;

model ExternalFunctionExplicit1
Real x;
algorithm
x := f(1.0);
end ExternalFunctionExplicit1;

// Result:
// function f
// input Real x;
// output Real y;
//
// external "C" y = ext(x);
// end f;
//
// class ExternalFunctionExplicit1
// Real x;
// algorithm
// x := f(1.0);
// end ExternalFunctionExplicit1;
// endResult
33 changes: 33 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionImplicit1.mo
@@ -0,0 +1,33 @@
// name: ExternalFunctionImplict1
// keywords:
// status: correct
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y;
external;
end f;

model ExternalFunctionImplict1
Real x;
algorithm
x := f(1.0);
end ExternalFunctionImplict1;

// Result:
// function f
// input Real x;
// output Real y;
//
// external "C" y = f(x);
// end f;
//
// class ExternalFunctionImplict1
// Real x;
// algorithm
// x := f(1.0);
// end ExternalFunctionImplict1;
// endResult
36 changes: 36 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionImplicit2.mo
@@ -0,0 +1,36 @@
// name: ExternalFunctionImplicit2
// keywords:
// status: correct
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y;
output Real z;
external;
end f;

model ExternalFunctionImplicit2
Real x, y;
algorithm
(x, y) := f(1.0);
end ExternalFunctionImplicit2;

// Result:
// function f
// input Real x;
// output Real y;
// output Real z;
//
// external "C" f(x, y, z);
// end f;
//
// class ExternalFunctionImplicit2
// Real x;
// Real y;
// algorithm
// (x, y) := f(1.0);
// end ExternalFunctionImplicit2;
// endResult
35 changes: 35 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionImplicit3.mo
@@ -0,0 +1,35 @@
// name: ExternalFunctionImplicit3
// keywords:
// status: correct
// cflags: -d=newInst
//
//

function f
input Real x[3];
input Real y[2, 4];
output Real z;
external;
end f;

model ExternalFunctionImplicit3
Real x;
algorithm
x := f({1, 2, 3}, {{1, 2, 3, 4}, {5, 6, 7, 8}});
end ExternalFunctionImplicit3;

// Result:
// function f
// input Real[3] x;
// input Real[2, 4] y;
// output Real z;
//
// external "C" z = f(x, size(x, 1), y, size(y, 1), size(y, 2));
// end f;
//
// class ExternalFunctionImplicit3
// Real x;
// algorithm
// x := f({1.0, 2.0, 3.0}, {{1.0, 2.0, 3.0, 4.0}, {5.0, 6.0, 7.0, 8.0}});
// end ExternalFunctionImplicit3;
// endResult
37 changes: 37 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionImplicit4.mo
@@ -0,0 +1,37 @@
// name: ExternalFunctionImplicit4
// keywords:
// status: correct
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y[3];
external;
end f;

model ExternalFunctionImplicit4
Real y[3];
algorithm
y := f(1.0);
end ExternalFunctionImplicit4;

// Result:
// function f
// input Real x;
// output Real[3] y;
//
// external "C" f(x, y, size(y, 1));
// end f;
//
// class ExternalFunctionImplicit4
// Real y[1];
// Real y[2];
// Real y[3];
// algorithm
// y := f(1.0);
// end ExternalFunctionImplicit4;
// [flattening/modelica/scodeinst/ExternalFunctionImplicit4.mo:8:1-12:6:writable] Warning: An external declaration with a single output without explicit mapping is defined as having the output as the lhs, but language C does not support this for array variables. OpenModelica will put the output as an input (as is done when there is more than 1 output), but this is not according to the Modelica Specification. Use an explicit mapping instead of the implicit one to suppress this warning.
//
// endResult
28 changes: 28 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionInvalidArg1.mo
@@ -0,0 +1,28 @@
// name: ExternalFunctionInvalidArg1
// keywords:
// status: incorrect
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y;
external y = f({1.0, 2.0, 3.0});
end f;

model ExternalFunctionInvalidArg1
Real x;
algorithm
x := f(1.0);
end ExternalFunctionInvalidArg1;

// Result:
// Error processing file: ExternalFunctionInvalidArg1.mo
// [flattening/modelica/scodeinst/ExternalFunctionInvalidArg1.mo:8:1-12:6:writable] Error: Expression {1.0, 2.0, 3.0} cannot be an external argument. Only identifiers, scalar constants, and size-expressions are allowed.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
28 changes: 28 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionInvalidLang1.mo
@@ -0,0 +1,28 @@
// name: ExternalFunctionInvalidLang1
// keywords:
// status: incorrect
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y;
external "fish" y = ext(x);
end f;

model ExternalFunctionInvalidLang1
Real x;
algorithm
x := f(1.0);
end ExternalFunctionInvalidLang1;

// Result:
// Error processing file: ExternalFunctionInvalidLang1.mo
// [flattening/modelica/scodeinst/ExternalFunctionInvalidLang1.mo:8:1-12:6:writable] Error: 'fish' is not a valid language for an external function.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
34 changes: 34 additions & 0 deletions flattening/modelica/scodeinst/ExternalFunctionInvalidSection1.mo
@@ -0,0 +1,34 @@
// name: ExternalFunctionInvalidSection1
// keywords:
// status: incorrect
// cflags: -d=newInst
//
//

function f
input Real x;
output Real y;
external "C" y = ext(x);
end f;

function f2
extends f;
algorithm
y := x;
end f2;

model ExternalFunctionInvalidSection1
Real x;
algorithm
x := f2(1.0);
end ExternalFunctionInvalidSection1;

// Result:
// Error processing file: ExternalFunctionInvalidSection1.mo
// [flattening/modelica/scodeinst/ExternalFunctionInvalidSection1.mo:14:1-18:7:writable] Error: Function f2 has more than one algorithm section or external declaration.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
25 changes: 25 additions & 0 deletions flattening/modelica/scodeinst/ExternalObject1.mo
@@ -0,0 +1,25 @@
// name: ExternalObject1
// keywords:
// status: correct
// cflags: -d=newInst
//
//

class ExternalObject1
extends ExternalObject;

function constructor
output ExternalObject1 obj;
external "C" obj = initObject();
end constructor;

function destructor
input ExternalObject1 obj;
external "C" destroyObject(obj);
end destructor;
end ExternalObject1;

// Result:
// class ExternalObject1
// end ExternalObject1;
// endResult
44 changes: 44 additions & 0 deletions flattening/modelica/scodeinst/ExternalObject2.mo
@@ -0,0 +1,44 @@
// name: ExternalObject2
// keywords:
// status: correct
// cflags: -d=newInst
//
//

class ExtObj
extends ExternalObject;

function constructor
output ExtObj obj;
external "C" obj = initObject();
end constructor;

function destructor
input ExtObj obj;
external "C" destroyObject(obj);
end destructor;
end ExtObj;

model ExternalObject2
ExtObj eo1;
ExtObj eo2;
end ExternalObject2;

// Result:
// function ExtObj.constructor
// output ExtObj obj;
//
// external "C" obj = initObject();
// end ExtObj.constructor;
//
// function ExtObj.destructor
// input ExtObj obj;
//
// external "C" destroyObject(obj);
// end ExtObj.destructor;
//
// class ExternalObject2
// ExtObj eo1;
// ExtObj eo2;
// end ExternalObject2;
// endResult
37 changes: 37 additions & 0 deletions flattening/modelica/scodeinst/ExternalObjectInvalidElement1.mo
@@ -0,0 +1,37 @@
// name: ExternalObjectInvalidElement1
// keywords:
// status: incorrect
// cflags: -d=newInst
//
//

class ExtObj
extends ExternalObject;

function constructor
output ExtObj obj;
external "C" obj = initObject();
end constructor;

function destructor
input ExtObj obj;
external "C" destroyObject(obj);
end destructor;

function f
end f;
end ExtObj;

model ExternalObjectInvalidElement1
ExtObj eo1;
end ExternalObjectInvalidElement1;

// Result:
// Error processing file: ExternalObjectInvalidElement1.mo
// [flattening/modelica/scodeinst/ExternalObjectInvalidElement1.mo:21:3-22:8:writable] Error: External object ExtObj contains invalid element 'f'.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult

0 comments on commit 7befa22

Please sign in to comment.