| 1 | package TestPackageInheritance
|
|---|
| 2 | package BasePackage
|
|---|
| 3 | replaceable function f
|
|---|
| 4 | input Real x;
|
|---|
| 5 | output Real y;
|
|---|
| 6 | algorithm
|
|---|
| 7 | y := x;
|
|---|
| 8 | end f;
|
|---|
| 9 |
|
|---|
| 10 | replaceable partial function g
|
|---|
| 11 | input Real x;
|
|---|
| 12 | output Real y;
|
|---|
| 13 | end g;
|
|---|
| 14 | end BasePackage;
|
|---|
| 15 |
|
|---|
| 16 | package MyPackage
|
|---|
| 17 | extends BasePackage;
|
|---|
| 18 | redeclare replaceable function g
|
|---|
| 19 | input Real x;
|
|---|
| 20 | output Real y;
|
|---|
| 21 | algorithm
|
|---|
| 22 | y := 2*x;
|
|---|
| 23 | end g;
|
|---|
| 24 |
|
|---|
| 25 | replaceable function h
|
|---|
| 26 | input Real x;
|
|---|
| 27 | output Real y;
|
|---|
| 28 | algorithm
|
|---|
| 29 | y := 10*x;
|
|---|
| 30 | end h;
|
|---|
| 31 | end MyPackage;
|
|---|
| 32 |
|
|---|
| 33 | package ModifiedPackage
|
|---|
| 34 | extends MyPackage;
|
|---|
| 35 | redeclare replaceable function f
|
|---|
| 36 | input Real x;
|
|---|
| 37 | output Real y;
|
|---|
| 38 | algorithm
|
|---|
| 39 | y:= -x;
|
|---|
| 40 | end f;
|
|---|
| 41 | end ModifiedPackage;
|
|---|
| 42 |
|
|---|
| 43 | package WrongPackage
|
|---|
| 44 | extends BasePackage;
|
|---|
| 45 | redeclare replaceable function f
|
|---|
| 46 | input Real a;
|
|---|
| 47 | output Real b;
|
|---|
| 48 | algorithm
|
|---|
| 49 | b := a*5;
|
|---|
| 50 | end f;
|
|---|
| 51 | end WrongPackage;
|
|---|
| 52 |
|
|---|
| 53 | package Test
|
|---|
| 54 | model Test_f
|
|---|
| 55 | Real x = 1;
|
|---|
| 56 | Real y = MyPackage.f(x);
|
|---|
| 57 | end Test_f;
|
|---|
| 58 |
|
|---|
| 59 | model Test_g
|
|---|
| 60 | Real x = 1;
|
|---|
| 61 | Real y = MyPackage.g(x);
|
|---|
| 62 | end Test_g;
|
|---|
| 63 |
|
|---|
| 64 | model Test_h
|
|---|
| 65 | Real x = 1;
|
|---|
| 66 | Real y = MyPackage.h(x);
|
|---|
| 67 | end Test_h;
|
|---|
| 68 |
|
|---|
| 69 | model Test_f_modified
|
|---|
| 70 | Real x = 1;
|
|---|
| 71 | Real y = ModifiedPackage.f(x);
|
|---|
| 72 | end Test_f_modified;
|
|---|
| 73 |
|
|---|
| 74 | model Test_f_wrong
|
|---|
| 75 | Real x = 1;
|
|---|
| 76 | Real y = WrongPackage.f(x);
|
|---|
| 77 | end Test_f_wrong;
|
|---|
| 78 | end Test;
|
|---|
| 79 | end TestPackageInheritance;
|
|---|