-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
153 lines (107 loc) · 5.48 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef PLC_EMULATOR__UTILS_H_
#define PLC_EMULATOR__UTILS_H_
#include <string>
#include <vector>
#include <unordered_map>
extern "C" {
#include <fcntl.h>
#include <sys/mman.h>
};
#include "config.pb.h"
#include "system_specification.pb.h"
namespace plc_emulator {
class DataType;
class Variable;
class Config;
struct DataTypeFieldAttributes;
class Utils {
public:
static void InitializeDataType(Config *config,
DataType *new_data_type,
const config::DataType &data_type_spec);
static void InitializeAccessDataType(Config *config,
DataType *new_data_type,
config::DataType &data_type_spec);
static bool ExtractFromStorageSpec(std::string storage_spec,
int *mem_type,
int *byte_offset,
int *bit_offset);
static std::string GetElementaryDataTypeName(config::DataTypeCategory category);
static int GetOpType(int var_op);
static bool ExtractFromAccessStorageSpec(Config *config,
std::string storage_spec,
int *mem_type,
int *byte_offset,
int *bit_offset,
std::string &candidate_resource_name);
static std::string GetInstallationDirectory();
static std::string ResolveAlias(std::string alias, Config *config);
static std::string Getinitial_valueForArrayIdx(int i,
std::string initial_value,
DataType *element_data_type,
Config *config);
static bool TestEqPointers(Variable *p, Variable *q);
static bool IsFieldTypePtr(int if_type);
static void ValidatePOUDefinition(Variable *pou_var, Config *config);
static bool FileExists(const char *filename);
static char *MakeSharedMmap(int n_elements, std::string filename);
static Variable *GetVariable(std::string nested_field_name,
Config *config);
static bool GetFieldAttributesForAccessPath(std::string access_path,
Config *configuration,
struct DataTypeFieldAttributesStruct &attrs);
static bool ReadAccessCheck(Config *configuration,
std::string calling_pou_type,
std::string nested_field_name);
static bool WriteAccessCheck(Config *configuration,
std::string calling_pou_type,
std::string nested_field_name);
static Variable *ReallocateTmpVariable(Config *configuration,
Variable *var,
DataType *new_data_type,
std::string initial_value);
static Variable *BoolToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *ByteToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *WordToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *DWordToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *QWordToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *CharToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *ShortToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *IntToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *LongToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *FloatToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *DoubleToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *TimeToAny(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *DateTimeToTime(Config *configuration,
Variable *var, DataType *new_datatype);
static Variable *DateTimeToDate(Config *configuration,
Variable *var, DataType *new_datatype);
static bool IsNumType(DataType *data_type);
static bool IsBitType(DataType *data_type);
static bool IsRealType(DataType *data_type);
static bool SameClassOfDataTypes(DataType *DT1, DataType *DT2);
static DataType *GetMostAppropriateTypeCast(Variable *Cr,
std::vector<Variable *> &ops);
static bool GenerateFullSpecification(
std::string system_spec_path,
config::Specification &full_specification);
static bool IsOperandImmediate(std::string op);
static void ExtractCallInterfaceMapping(
std::unordered_map<std::string, std::string> &vars_to_set,
std::unordered_map<std::string, std::string> &vars_to_get,
std::string full_if_name);
};
}
#endif