Skip to content

Commit

Permalink
FrontEnd unitchecking
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 authored and OpenModelica-Hudson committed Dec 2, 2016
1 parent f170480 commit bfd4680
Show file tree
Hide file tree
Showing 8 changed files with 2,687 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -162,6 +162,7 @@ import UnitAbsynBuilder;
import NFSCodeFlattenRedeclare;
import InstStateMachineUtil;
import HashTableSM1;
import NFUnitCheck;

import DAEDump; // BTH

Expand Down Expand Up @@ -329,6 +330,9 @@ algorithm
case (cache,ih,cdecls as _::_,path)
equation
(outCache,outEnv,outIH,outDAElist) = instantiateClass_dispatch(cache,ih,cdecls,path,doSCodeDep);
if Flags.isSet(Flags.NF_UNITCHECK) then
NFUnitCheck.unitChecking(outDAElist,outCache);
end if;
then
(outCache,outEnv,outIH,outDAElist);

Expand Down
117 changes: 117 additions & 0 deletions Compiler/NFFrontEnd/NFHashTableCrToUnit.mo
@@ -0,0 +1,117 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

encapsulated package NFHashTableCrToUnit "
This file is an extension to OpenModelica.

Copyright (c) 2013 TU Dresden

All rights reserved.

file: HashTableCrToUnit.mo
package: HashTableCrToUnit
description: ComponentRef to Unit.Unit


"

/* Below is the instance specific code. For each hashtable the user must define:
Key - The key used to uniquely define elements in a hashtable
Value - The data to associate with each key
hashFunc - A function that maps a key to a positive integer.
keyEqual - A comparison function between two keys, returns true if equal.
*/

/* HashTable instance specific code */

public import BaseHashTable;
public import DAE;
public import ComponentReference;
public import NFUnit;


public type Key = DAE.ComponentRef;
public type Value = NFUnit.Unit;

public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>;
public type HashTable = tuple<
array<list<tuple<Key,Integer>>>,
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
Integer,
HashTableCrefFunctionsType
>;

partial function FuncHashKey
input Key cr;
input Integer mod;
output Integer res;
end FuncHashKey;

partial function FuncKeyEqual
input Key cr1;
input Key cr2;
output Boolean res;
end FuncKeyEqual;

partial function FuncKeyStr
input Key cr;
output String res;
end FuncKeyStr;

partial function FuncValueStr
input Value exp;
output String res;
end FuncValueStr;

public function emptyHashTable
"
Returns an empty HashTable.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size.
"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size, (ComponentReference.hashComponentRefMod, ComponentReference.crefEqual, ComponentReference.printComponentRefStr, NFUnit.unit2string));
end emptyHashTableSized;

annotation(__OpenModelica_Interface="frontend");
end NFHashTableCrToUnit;
116 changes: 116 additions & 0 deletions Compiler/NFFrontEnd/NFHashTableStringToUnit.mo
@@ -0,0 +1,116 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

encapsulated package NFHashTableStringToUnit "
This file is an extension to OpenModelica.

Copyright (c) 2013 TU Dresden

All rights reserved.

file: HashTableStringToUnit.mo
package: HashTableStringToUnit
description: String to Unit.Unit


"

/* Below is the instance specific code. For each hashtable the user must define:
Key - The key used to uniquely define elements in a hashtable
Value - The data to associate with each key
hashFunc - A function that maps a key to a positive integer.
keyEqual - A comparison function between two keys, returns true if equal.
*/

/* HashTable instance specific code */

public import BaseHashTable;
public import System;
public import NFUnit;
public import Util;

public type Key = String;
public type Value = NFUnit.Unit;

public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>;
public type HashTable = tuple<
array<list<tuple<Key,Integer>>>,
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
Integer,
HashTableCrefFunctionsType
>;

partial function FuncHashKey
input Key cr;
input Integer mod;
output Integer res;
end FuncHashKey;

partial function FuncKeyEqual
input Key cr1;
input Key cr2;
output Boolean res;
end FuncKeyEqual;

partial function FuncKeyStr
input Key cr;
output String res;
end FuncKeyStr;

partial function FuncValueStr
input Value exp;
output String res;
end FuncValueStr;

public function emptyHashTable
"
Returns an empty HashTable.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size.
"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size, (System.stringHashDjb2Mod, stringEq, Util.id, NFUnit.unit2string));
end emptyHashTableSized;

annotation(__OpenModelica_Interface="frontend");
end NFHashTableStringToUnit;
121 changes: 121 additions & 0 deletions Compiler/NFFrontEnd/NFHashTableUnitToString.mo
@@ -0,0 +1,121 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

encapsulated package NFHashTableUnitToString "
This file is an extension to OpenModelica.

Copyright (c) 2013 TU Dresden

All rights reserved.

file: HashTableUnitToString.mo
package: HashTableUnitToString
description: Unit.Unit to String


"

/* Below is the instance specific code. For each hashtable the user must define:
Key - The key used to uniquely define elements in a hashtable
Value - The data to associate with each key
hashFunc - A function that maps a key to a positive integer.
keyEqual - A comparison function between two keys, returns true if equal.
*/

/* HashTable instance specific code */

public import BaseHashTable;
public import NFUnit;

public type Key = NFUnit.Unit;
public type Value = String;

public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>;
public type HashTable = tuple<
array<list<tuple<Key,Integer>>>,
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
Integer,
HashTableCrefFunctionsType
>;

partial function FuncHashKey
input Key cr;
input Integer mod;
output Integer res;
end FuncHashKey;

partial function FuncKeyEqual
input Key cr1;
input Key cr2;
output Boolean res;
end FuncKeyEqual;

partial function FuncKeyStr
input Key cr;
output String res;
end FuncKeyStr;

partial function FuncValueStr
input Value exp;
output String res;
end FuncValueStr;

public function emptyHashTable
"
Returns an empty HashTable.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

protected function id
input String inStr;
output String outStr;
algorithm
outStr := inStr;
end id;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size.
"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,(NFUnit.hashUnitMod,NFUnit.unitEqual,NFUnit.unit2string,id));
end emptyHashTableSized;

annotation(__OpenModelica_Interface="frontend");
end NFHashTableUnitToString;

0 comments on commit bfd4680

Please sign in to comment.