MicroModelicaCCompiler  4.5.3
util.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #pragma once
21 
22 #include <fstream>
23 #include <list>
24 #include <map>
25 #include <string>
26 
27 #include <ast/ast_types.hpp>
28 #include <deps/model_dependencies.hpp>
29 #include <util/compile_flags.hpp>
30 #include <util/util_types.hpp>
31 #include <util/symbol_table.hpp>
32 #include <util/table.hpp>
33 
34 namespace MicroModelica {
35 
36 namespace IR {
37 class Equation;
38 class CompiledPackage;
39 class CompiledFunction;
40 class Function;
45 } // namespace IR
46 
47 namespace Util {
48 
50 
52 
53 #define SLASH "/"
54 #define BINOPS 18
55 
56 #if __x86_64__
57 typedef long int grp_t;
58 #else
59 typedef int grp_t;
60 #endif
61 
62 #define TAB "\t"
63 
64 class Utils {
65  public:
66  static Utils& instance()
67  {
68  static Utils _instance;
69  return _instance;
70  }
71 
72  ~Utils();
73  std::string trimString(std::string str);
74  std::string languageEspecification();
75  bool checkTypeString(std::string t);
76  bool checkExperimentAnnotations(std::string* annotation);
77  std::string opString(BinOpType bot);
78  std::string iteratorVar(int dim);
79  std::string getVarName(std::string name);
80  bool readPackage(std::string fileName, IR::CompiledPackageTable& pt);
81  Option<IR::CompiledPackage> readPackage(std::string file_name, bool full_path = false, std::string package_name = "");
82  bool searchCompiledPackage(std::string pname, CompileFlags flags);
83  std::string packagePath(std::string pname, CompileFlags flags, std::string ext = ".mo");
84  void setCompileFlags(CompileFlags flags);
85  std::string packageName(std::string name);
86  std::string environmentVariable(std::string ev);
87  std::string getFilePath(std::string file);
88  std::string getFileName(std::string file);
89  std::string baseFileName(std::string file);
90  bool checkGKLinkFunctions(std::string name) { return false; };
94  bool checkCompiledFunctions(std::string name);
95  bool checkBuiltInFunctions(std::string name);
96  inline std::string fileName() { return _file_name; };
97  inline int id() { return _ids++; };
98  Variable variable(AST_Expression exp);
99  IR::Expression variableExpression(string name, Option<IR::Range> range);
100  std::string tabs(int t);
101  CompileFlags compileFlags();
102  void setPackageFunctions(IR::FunctionTable package_functions);
104  void setPackagePrefix(std::string package_prefix);
105  std::string packagePrefix();
106  std::string generatePath(std::string path, std::string file_name);
107 
108  protected:
109  Utils();
110  bool checkCodeFiles(std::string name, std::string ext);
111  SymbolTable getValue(fstream* package, std::string token);
112  std::string packagePath(std::string name);
113 
116  map<std::string, int> _annotations;
117  std::string _binop[BINOPS];
119  std::string _file_name;
120  int _ids;
122  std::string _package_prefix;
123 };
124 
125 } // namespace Util
126 } // namespace MicroModelica
MicroModelica::Util::Utils::setPackagePrefix
void setPackagePrefix(std::string package_prefix)
Definition: util.cpp:418
MicroModelica::Util::Utils::_flags
CompileFlags _flags
Definition: util.hpp:132
MicroModelica::Util::Utils::packageFunctions
IR::FunctionTable packageFunctions()
Definition: util.cpp:412
MicroModelica::Util::Utils::languageEspecification
std::string languageEspecification()
Definition: util.cpp:108
ModelTable< std::string, CompiledPackage >
MicroModelica::IR::CompiledFunction
Definition: helpers.hpp:87
MicroModelica::Util::Utils::checkCodeFiles
bool checkCodeFiles(std::string name, std::string ext)
Definition: util.cpp:222
MicroModelica::Util::Utils::compiledFunctions
IR::CompiledFunctionTable compiledFunctions()
Definition: util.cpp:349
MicroModelica::Util::Utils::baseFileName
std::string baseFileName(std::string file)
Definition: util.cpp:338
MicroModelica::Util::ImportTable
ModelTable< std::string, std::string > ImportTable
Definition: util.hpp:66
MicroModelica::Util::Utils::packageName
std::string packageName(std::string name)
Definition: util.cpp:298
MicroModelica::Util::Utils::fileName
std::string fileName()
Definition: util.hpp:113
MicroModelica::IR::CompiledPackageTable
ModelTable< std::string, CompiledPackage > CompiledPackageTable
Definition: helpers.hpp:141
MicroModelica::Util::Utils::setPackageFunctions
void setPackageFunctions(IR::FunctionTable package_functions)
Definition: util.cpp:414
MicroModelica::Util::Utils::searchCompiledPackage
bool searchCompiledPackage(std::string pname, CompileFlags flags)
Definition: util.cpp:220
MicroModelica::Util::Utils::_package_functions
IR::FunctionTable _package_functions
Definition: util.hpp:138
MicroModelica::Util::CompileFlags
Definition: compile_flags.hpp:65
MicroModelica::IR::EquationTable
ModelTable< int, Equation > EquationTable
Definition: equation.hpp:169
symbol_table.hpp
MicroModelica::Util::Utils::setCompileFlags
void setCompileFlags(CompileFlags flags)
Definition: util.cpp:110
MicroModelica::Util::Utils::getFilePath
std::string getFilePath(std::string file)
Definition: util.cpp:316
Option
Definition: util_types.hpp:32
MicroModelica::Util::Utils::trimString
std::string trimString(std::string str)
Definition: util.cpp:91
MicroModelica::Util::Utils::compileFlags
CompileFlags compileFlags()
Definition: util.cpp:410
MicroModelica::Util::Utils::checkTypeString
bool checkTypeString(std::string t)
Definition: util.cpp:112
MicroModelica::Util::Utils::checkGKLinkFunctions
bool checkGKLinkFunctions(std::string name)
Definition: util.hpp:107
MicroModelica::Util::SymbolTable
ModelTable< std::string, std::string > SymbolTable
Definition: equation.hpp:62
MicroModelica::Util::Utils
Definition: util.hpp:81
MicroModelica::Util::Utils::getFileName
std::string getFileName(std::string file)
Definition: util.cpp:327
MicroModelica::Util::Utils::_package_prefix
std::string _package_prefix
Definition: util.hpp:139
MicroModelica::Util::Utils::_binop
std::string _binop[BINOPS]
Definition: util.hpp:134
MicroModelica::Util::Utils::checkBuiltInFunctions
bool checkBuiltInFunctions(std::string name)
Definition: util.cpp:361
MicroModelica::Util::Utils::variable
Variable variable(AST_Expression exp)
Definition: util.cpp:363
MicroModelica::Util::Utils::getValue
SymbolTable getValue(fstream *package, std::string token)
Definition: util.cpp:145
util_types.hpp
MicroModelica::Util::Utils::generatePath
std::string generatePath(std::string path, std::string file_name)
Definition: util.cpp:255
MicroModelica::Util::Utils::readPackage
bool readPackage(std::string fileName, IR::CompiledPackageTable &pt)
MicroModelica::Util::Utils::addCompiledFunction
void addCompiledFunction(IR::CompiledFunction f)
Definition: util.cpp:351
MicroModelica::Util::Utils::opString
std::string opString(BinOpType bot)
Definition: util.cpp:126
MicroModelica::Util::Utils::Utils
Utils()
Definition: util.cpp:60
MicroModelica::IR::CompiledFunctionTable
ModelTable< std::string, CompiledFunction > CompiledFunctionTable
Definition: helpers.hpp:117
MicroModelica::Util::Utils::_compiled_functions
IR::CompiledFunctionTable _compiled_functions
Definition: util.hpp:135
MicroModelica::Util::Utils::id
int id()
Definition: util.hpp:114
MicroModelica::Util::Utils::getVarName
std::string getVarName(std::string name)
Definition: util.cpp:128
compile_flags.hpp
MicroModelica::Util::Utils::variableExpression
IR::Expression variableExpression(string name, Option< IR::Range > range)
Definition: util.cpp:384
MicroModelica::Util::Utils::packagePrefix
std::string packagePrefix()
Definition: util.cpp:416
MicroModelica::Util::Utils::addCompiledFunctions
void addCompiledFunctions(IR::CompiledFunctionTable fs)
Definition: util.cpp:353
MicroModelica
Definition: files.cpp:45
MicroModelica::Util::Utils::_ids
int _ids
Definition: util.hpp:137
BINOPS
#define BINOPS
Definition: util.hpp:71
table.hpp
MicroModelica::Util::Utils::instance
static Utils & instance()
Definition: util.hpp:83
MicroModelica::Util::Utils::iteratorVar
std::string iteratorVar(int dim)
Definition: util.cpp:138
ast_types.hpp
MicroModelica::Util::grp_t
int grp_t
Definition: util.hpp:76
MicroModelica::Util::Utils::environmentVariable
std::string environmentVariable(std::string ev)
Definition: util.cpp:307
BinOpType
BinOpType
Definition: ast_types.hpp:137
MicroModelica::Util::Utils::_file_name
std::string _file_name
Definition: util.hpp:136
MicroModelica::Util::Utils::~Utils
~Utils()
Definition: util.cpp:89
MicroModelica::IR::FunctionTable
ModelTable< std::string, Function > FunctionTable
Definition: class.hpp:130
MicroModelica::Util::Utils::packagePath
std::string packagePath(std::string pname, CompileFlags flags, std::string ext=".mo")
MicroModelica::Util::Utils::_annotations
map< std::string, int > _annotations
Definition: util.hpp:133
MicroModelica::Util::Utils::checkExperimentAnnotations
bool checkExperimentAnnotations(std::string *annotation)
Definition: util.cpp:120
MicroModelica::Util::Utils::tabs
std::string tabs(int t)
Definition: util.cpp:401
MicroModelica::Util::Utils::checkCompiledFunctions
bool checkCompiledFunctions(std::string name)
Definition: util.cpp:355
MicroModelica::Util::Utils::_language_especification
std::string _language_especification
Definition: util.hpp:131