Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit bfd4680

Browse files
arun3688OpenModelica-Hudson
authored andcommitted
FrontEnd unitchecking
1 parent f170480 commit bfd4680

File tree

8 files changed

+2687
-1
lines changed

8 files changed

+2687
-1
lines changed

Compiler/FrontEnd/Inst.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ import UnitAbsynBuilder;
162162
import NFSCodeFlattenRedeclare;
163163
import InstStateMachineUtil;
164164
import HashTableSM1;
165+
import NFUnitCheck;
165166

166167
import DAEDump; // BTH
167168

@@ -329,6 +330,9 @@ algorithm
329330
case (cache,ih,cdecls as _::_,path)
330331
equation
331332
(outCache,outEnv,outIH,outDAElist) = instantiateClass_dispatch(cache,ih,cdecls,path,doSCodeDep);
333+
if Flags.isSet(Flags.NF_UNITCHECK) then
334+
NFUnitCheck.unitChecking(outDAElist,outCache);
335+
end if;
332336
then
333337
(outCache,outEnv,outIH,outDAElist);
334338

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
5+
* c/o Linköpings universitet, Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
11+
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13+
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14+
* ACCORDING TO RECIPIENTS CHOICE.
15+
*
16+
* The OpenModelica software and the Open Source Modelica
17+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
18+
* from OSMC, either from the above address,
19+
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20+
* http://www.openmodelica.org, and in the OpenModelica distribution.
21+
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22+
*
23+
* This program is distributed WITHOUT ANY WARRANTY; without
24+
* even the implied warranty of MERCHANTABILITY or FITNESS
25+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27+
*
28+
* See the full OSMC Public License conditions for more details.
29+
*
30+
*/
31+
32+
encapsulated package NFHashTableCrToUnit "
33+
This file is an extension to OpenModelica.
34+
35+
Copyright (c) 2013 TU Dresden
36+
37+
All rights reserved.
38+
39+
file: HashTableCrToUnit.mo
40+
package: HashTableCrToUnit
41+
description: ComponentRef to Unit.Unit
42+
43+
44+
"
45+
46+
/* Below is the instance specific code. For each hashtable the user must define:
47+
48+
Key - The key used to uniquely define elements in a hashtable
49+
Value - The data to associate with each key
50+
hashFunc - A function that maps a key to a positive integer.
51+
keyEqual - A comparison function between two keys, returns true if equal.
52+
*/
53+
54+
/* HashTable instance specific code */
55+
56+
public import BaseHashTable;
57+
public import DAE;
58+
public import ComponentReference;
59+
public import NFUnit;
60+
61+
62+
public type Key = DAE.ComponentRef;
63+
public type Value = NFUnit.Unit;
64+
65+
public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>;
66+
public type HashTable = tuple<
67+
array<list<tuple<Key,Integer>>>,
68+
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
69+
Integer,
70+
HashTableCrefFunctionsType
71+
>;
72+
73+
partial function FuncHashKey
74+
input Key cr;
75+
input Integer mod;
76+
output Integer res;
77+
end FuncHashKey;
78+
79+
partial function FuncKeyEqual
80+
input Key cr1;
81+
input Key cr2;
82+
output Boolean res;
83+
end FuncKeyEqual;
84+
85+
partial function FuncKeyStr
86+
input Key cr;
87+
output String res;
88+
end FuncKeyStr;
89+
90+
partial function FuncValueStr
91+
input Value exp;
92+
output String res;
93+
end FuncValueStr;
94+
95+
public function emptyHashTable
96+
"
97+
Returns an empty HashTable.
98+
Using the default bucketsize..
99+
"
100+
output HashTable hashTable;
101+
algorithm
102+
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
103+
end emptyHashTable;
104+
105+
public function emptyHashTableSized
106+
"
107+
Returns an empty HashTable.
108+
Using the bucketsize size.
109+
"
110+
input Integer size;
111+
output HashTable hashTable;
112+
algorithm
113+
hashTable := BaseHashTable.emptyHashTableWork(size, (ComponentReference.hashComponentRefMod, ComponentReference.crefEqual, ComponentReference.printComponentRefStr, NFUnit.unit2string));
114+
end emptyHashTableSized;
115+
116+
annotation(__OpenModelica_Interface="frontend");
117+
end NFHashTableCrToUnit;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
5+
* c/o Linköpings universitet, Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
11+
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13+
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14+
* ACCORDING TO RECIPIENTS CHOICE.
15+
*
16+
* The OpenModelica software and the Open Source Modelica
17+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
18+
* from OSMC, either from the above address,
19+
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20+
* http://www.openmodelica.org, and in the OpenModelica distribution.
21+
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22+
*
23+
* This program is distributed WITHOUT ANY WARRANTY; without
24+
* even the implied warranty of MERCHANTABILITY or FITNESS
25+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27+
*
28+
* See the full OSMC Public License conditions for more details.
29+
*
30+
*/
31+
32+
encapsulated package NFHashTableStringToUnit "
33+
This file is an extension to OpenModelica.
34+
35+
Copyright (c) 2013 TU Dresden
36+
37+
All rights reserved.
38+
39+
file: HashTableStringToUnit.mo
40+
package: HashTableStringToUnit
41+
description: String to Unit.Unit
42+
43+
44+
"
45+
46+
/* Below is the instance specific code. For each hashtable the user must define:
47+
48+
Key - The key used to uniquely define elements in a hashtable
49+
Value - The data to associate with each key
50+
hashFunc - A function that maps a key to a positive integer.
51+
keyEqual - A comparison function between two keys, returns true if equal.
52+
*/
53+
54+
/* HashTable instance specific code */
55+
56+
public import BaseHashTable;
57+
public import System;
58+
public import NFUnit;
59+
public import Util;
60+
61+
public type Key = String;
62+
public type Value = NFUnit.Unit;
63+
64+
public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>;
65+
public type HashTable = tuple<
66+
array<list<tuple<Key,Integer>>>,
67+
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
68+
Integer,
69+
HashTableCrefFunctionsType
70+
>;
71+
72+
partial function FuncHashKey
73+
input Key cr;
74+
input Integer mod;
75+
output Integer res;
76+
end FuncHashKey;
77+
78+
partial function FuncKeyEqual
79+
input Key cr1;
80+
input Key cr2;
81+
output Boolean res;
82+
end FuncKeyEqual;
83+
84+
partial function FuncKeyStr
85+
input Key cr;
86+
output String res;
87+
end FuncKeyStr;
88+
89+
partial function FuncValueStr
90+
input Value exp;
91+
output String res;
92+
end FuncValueStr;
93+
94+
public function emptyHashTable
95+
"
96+
Returns an empty HashTable.
97+
Using the default bucketsize..
98+
"
99+
output HashTable hashTable;
100+
algorithm
101+
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
102+
end emptyHashTable;
103+
104+
public function emptyHashTableSized
105+
"
106+
Returns an empty HashTable.
107+
Using the bucketsize size.
108+
"
109+
input Integer size;
110+
output HashTable hashTable;
111+
algorithm
112+
hashTable := BaseHashTable.emptyHashTableWork(size, (System.stringHashDjb2Mod, stringEq, Util.id, NFUnit.unit2string));
113+
end emptyHashTableSized;
114+
115+
annotation(__OpenModelica_Interface="frontend");
116+
end NFHashTableStringToUnit;
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
5+
* c/o Linköpings universitet, Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
11+
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13+
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14+
* ACCORDING TO RECIPIENTS CHOICE.
15+
*
16+
* The OpenModelica software and the Open Source Modelica
17+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
18+
* from OSMC, either from the above address,
19+
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20+
* http://www.openmodelica.org, and in the OpenModelica distribution.
21+
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22+
*
23+
* This program is distributed WITHOUT ANY WARRANTY; without
24+
* even the implied warranty of MERCHANTABILITY or FITNESS
25+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27+
*
28+
* See the full OSMC Public License conditions for more details.
29+
*
30+
*/
31+
32+
encapsulated package NFHashTableUnitToString "
33+
This file is an extension to OpenModelica.
34+
35+
Copyright (c) 2013 TU Dresden
36+
37+
All rights reserved.
38+
39+
file: HashTableUnitToString.mo
40+
package: HashTableUnitToString
41+
description: Unit.Unit to String
42+
43+
44+
"
45+
46+
/* Below is the instance specific code. For each hashtable the user must define:
47+
48+
Key - The key used to uniquely define elements in a hashtable
49+
Value - The data to associate with each key
50+
hashFunc - A function that maps a key to a positive integer.
51+
keyEqual - A comparison function between two keys, returns true if equal.
52+
*/
53+
54+
/* HashTable instance specific code */
55+
56+
public import BaseHashTable;
57+
public import NFUnit;
58+
59+
public type Key = NFUnit.Unit;
60+
public type Value = String;
61+
62+
public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>;
63+
public type HashTable = tuple<
64+
array<list<tuple<Key,Integer>>>,
65+
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
66+
Integer,
67+
HashTableCrefFunctionsType
68+
>;
69+
70+
partial function FuncHashKey
71+
input Key cr;
72+
input Integer mod;
73+
output Integer res;
74+
end FuncHashKey;
75+
76+
partial function FuncKeyEqual
77+
input Key cr1;
78+
input Key cr2;
79+
output Boolean res;
80+
end FuncKeyEqual;
81+
82+
partial function FuncKeyStr
83+
input Key cr;
84+
output String res;
85+
end FuncKeyStr;
86+
87+
partial function FuncValueStr
88+
input Value exp;
89+
output String res;
90+
end FuncValueStr;
91+
92+
public function emptyHashTable
93+
"
94+
Returns an empty HashTable.
95+
Using the default bucketsize..
96+
"
97+
output HashTable hashTable;
98+
algorithm
99+
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
100+
end emptyHashTable;
101+
102+
protected function id
103+
input String inStr;
104+
output String outStr;
105+
algorithm
106+
outStr := inStr;
107+
end id;
108+
109+
public function emptyHashTableSized
110+
"
111+
Returns an empty HashTable.
112+
Using the bucketsize size.
113+
"
114+
input Integer size;
115+
output HashTable hashTable;
116+
algorithm
117+
hashTable := BaseHashTable.emptyHashTableWork(size,(NFUnit.hashUnitMod,NFUnit.unitEqual,NFUnit.unit2string,id));
118+
end emptyHashTableSized;
119+
120+
annotation(__OpenModelica_Interface="frontend");
121+
end NFHashTableUnitToString;

0 commit comments

Comments
 (0)