author | Mario de Sousa <msousa@fe.up.pt> |
Tue, 23 Aug 2011 17:18:37 +0100 | |
changeset 365 | 84ad67170c11 |
parent 339 | 06b561479e46 |
child 399 | 55b074ea7255 |
child 417 | d48f53715f77 |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
181 | 3 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
265
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
181 | 6 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
10 |
* (at your option) any later version. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
15 |
* GNU General Public License for more details. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
19 |
* |
181 | 20 |
* |
21 |
* This code is made available on the understanding that it will not be |
|
22 |
* used in safety-critical situations without a full and competent review. |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
26 |
* An IEC 61131-3 compiler. |
181 | 27 |
* |
28 |
* Based on the |
|
29 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
/* Determine the data type of a specific constant or variable. |
|
34 |
* A reference to the relevant type definition is returned. |
|
35 |
* |
|
36 |
* For example: |
|
37 |
* 22 -> returns reference to a int_type_name_c object. |
|
38 |
* 22.2 -> returns reference to a real_type_name_c object. |
|
39 |
* LREAL#22.2 -> returns reference to a lreal_type_name_c object. |
|
40 |
* etc... |
|
41 |
*/ |
|
42 |
||
43 |
||
44 |
#include "../absyntax/visitor.hh" |
|
45 |
||
339
06b561479e46
Replacing extern declaration with #include of apropriate header file
Mario de Sousa <msousa@fe.up.pt>
parents:
328
diff
changeset
|
46 |
#ifndef _SEARCH_CONSTANT_TYPE_HH |
06b561479e46
Replacing extern declaration with #include of apropriate header file
Mario de Sousa <msousa@fe.up.pt>
parents:
328
diff
changeset
|
47 |
#define _SEARCH_CONSTANT_TYPE_HH |
181 | 48 |
|
49 |
class search_constant_type_c: public search_visitor_c { |
|
50 |
||
51 |
public: |
|
52 |
/**********************/ |
|
53 |
/* B.1.3 - Data types */ |
|
54 |
/**********************/ |
|
55 |
/***********************************/ |
|
56 |
/* B 1.3.1 - Elementary Data Types */ |
|
57 |
/***********************************/ |
|
58 |
static real_type_name_c real_type_name; |
|
59 |
static sint_type_name_c sint_type_name; |
|
60 |
static lint_type_name_c lint_type_name; |
|
61 |
static dint_type_name_c dint_type_name; |
|
62 |
static date_type_name_c date_type_name; |
|
63 |
static dword_type_name_c dword_type_name; |
|
64 |
static dt_type_name_c dt_type_name; |
|
65 |
static tod_type_name_c tod_type_name; |
|
66 |
static udint_type_name_c udint_type_name; |
|
67 |
static word_type_name_c word_type_name; |
|
68 |
static wstring_type_name_c wstring_type_name; |
|
69 |
static string_type_name_c string_type_name; |
|
70 |
static lword_type_name_c lword_type_name; |
|
71 |
static uint_type_name_c uint_type_name; |
|
72 |
static lreal_type_name_c lreal_type_name; |
|
73 |
static byte_type_name_c byte_type_name; |
|
74 |
static usint_type_name_c usint_type_name; |
|
75 |
static ulint_type_name_c ulint_type_name; |
|
76 |
static bool_type_name_c bool_type_name; |
|
77 |
static time_type_name_c time_type_name; |
|
78 |
static int_type_name_c int_type_name; |
|
79 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
80 |
/* temporarily here until we remove the st_code_gen.c and il_code_gen.c files... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
81 |
static integer_c integer; |
181 | 82 |
|
83 |
/******************************************************/ |
|
84 |
/* Extensions to the base standard as defined in */ |
|
85 |
/* "Safety Software Technical Specification, */ |
|
86 |
/* Part 1: Concepts and Function Blocks, */ |
|
87 |
/* Version 1.0 – Official Release" */ |
|
88 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
89 |
/******************************************************/ |
|
257 | 90 |
|
91 |
// static safebool_type_name_c safebool_type_name; |
|
92 |
/* The following is required because the expression (TOD_var - TOD_var) will result in a data type |
|
93 |
* (in this case, TIME) that is neither of the expression elements... |
|
94 |
*/ |
|
95 |
static safetime_type_name_c safetime_type_name; |
|
96 |
static safetod_type_name_c safetod_type_name; |
|
97 |
static safedt_type_name_c safedt_type_name; |
|
98 |
||
181 | 99 |
|
100 |
||
101 |
public: |
|
102 |
symbol_c *get_type(symbol_c *constant); |
|
103 |
||
104 |
||
105 |
private: |
|
106 |
/*********************/ |
|
107 |
/* B 1.2 - Constants */ |
|
108 |
/*********************/ |
|
109 |
||
110 |
/******************************/ |
|
111 |
/* B 1.2.1 - Numeric Literals */ |
|
112 |
/******************************/ |
|
113 |
void *visit(real_c *symbol); |
|
257 | 114 |
void *visit(neg_real_c *symbol); |
181 | 115 |
void *visit(integer_c *symbol); |
257 | 116 |
void *visit(neg_integer_c *symbol); |
181 | 117 |
void *visit(binary_integer_c *symbol); |
118 |
void *visit(octal_integer_c *symbol); |
|
119 |
void *visit(hex_integer_c *symbol); |
|
120 |
||
121 |
void *visit(integer_literal_c *symbol); |
|
122 |
void *visit(real_literal_c *symbol); |
|
123 |
void *visit(bit_string_literal_c *symbol); |
|
124 |
void *visit(boolean_literal_c *symbol); |
|
125 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
126 |
void *visit(boolean_true_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
127 |
void *visit(boolean_false_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
128 |
|
181 | 129 |
/*******************************/ |
130 |
/* B.1.2.2 Character Strings */ |
|
131 |
/*******************************/ |
|
132 |
void *visit(double_byte_character_string_c *symbol); |
|
133 |
void *visit(single_byte_character_string_c *symbol); |
|
134 |
||
135 |
/***************************/ |
|
136 |
/* B 1.2.3 - Time Literals */ |
|
137 |
/***************************/ |
|
138 |
/************************/ |
|
139 |
/* B 1.2.3.1 - Duration */ |
|
140 |
/************************/ |
|
141 |
void *visit(neg_time_c *symbol); |
|
142 |
void *visit(duration_c *symbol); |
|
143 |
void *visit(fixed_point_c *symbol); |
|
144 |
void *visit(days_c *symbol); |
|
145 |
void *visit(hours_c *symbol); |
|
146 |
void *visit(minutes_c *symbol); |
|
147 |
void *visit(seconds_c *symbol); |
|
148 |
void *visit(milliseconds_c *symbol); |
|
149 |
||
150 |
/************************************/ |
|
151 |
/* B 1.2.3.2 - Time of day and Date */ |
|
152 |
/************************************/ |
|
153 |
void *visit(time_of_day_c *symbol); |
|
154 |
void *visit(daytime_c *symbol); |
|
155 |
void *visit(date_c *symbol); |
|
156 |
void *visit(date_literal_c *symbol); |
|
157 |
void *visit(date_and_time_c *symbol); |
|
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
279
diff
changeset
|
158 |
|
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
279
diff
changeset
|
159 |
/********************************/ |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
279
diff
changeset
|
160 |
/* B 1.3.3 - Derived data types */ |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
279
diff
changeset
|
161 |
/********************************/ |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
279
diff
changeset
|
162 |
void *visit(enumerated_value_c *symbol); |
181 | 163 |
}; // search_constant_type_c |
164 |
||
165 |
||
166 |
||
339
06b561479e46
Replacing extern declaration with #include of apropriate header file
Mario de Sousa <msousa@fe.up.pt>
parents:
328
diff
changeset
|
167 |
#endif /* ifndef _SEARCH_CONSTANT_TYPE_HH */ |