author | laurent |
Sat, 05 Dec 2009 18:35:38 +0100 | |
changeset 225 | 36d05588f91b |
parent 202 | da1a8186f86f |
child 257 | 90782e241346 |
permissions | -rw-r--r-- |
181 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
/* Determine the data type of a specific constant or variable. |
|
26 |
* A reference to the relevant type definition is returned. |
|
27 |
* |
|
28 |
* For example: |
|
29 |
* 22 -> returns reference to a int_type_name_c object. |
|
30 |
* 22.2 -> returns reference to a real_type_name_c object. |
|
31 |
* LREAL#22.2 -> returns reference to a lreal_type_name_c object. |
|
32 |
* etc... |
|
33 |
*/ |
|
34 |
||
35 |
||
36 |
#include "../absyntax/visitor.hh" |
|
37 |
||
38 |
||
39 |
class search_constant_type_c: public search_visitor_c { |
|
40 |
||
41 |
public: |
|
42 |
/**********************/ |
|
43 |
/* B.1.3 - Data types */ |
|
44 |
/**********************/ |
|
45 |
/***********************************/ |
|
46 |
/* B 1.3.1 - Elementary Data Types */ |
|
47 |
/***********************************/ |
|
48 |
static real_type_name_c real_type_name; |
|
49 |
static sint_type_name_c sint_type_name; |
|
50 |
static lint_type_name_c lint_type_name; |
|
51 |
static dint_type_name_c dint_type_name; |
|
52 |
static date_type_name_c date_type_name; |
|
53 |
static dword_type_name_c dword_type_name; |
|
54 |
static dt_type_name_c dt_type_name; |
|
55 |
static tod_type_name_c tod_type_name; |
|
56 |
static udint_type_name_c udint_type_name; |
|
57 |
static word_type_name_c word_type_name; |
|
58 |
static wstring_type_name_c wstring_type_name; |
|
59 |
static string_type_name_c string_type_name; |
|
60 |
static lword_type_name_c lword_type_name; |
|
61 |
static uint_type_name_c uint_type_name; |
|
62 |
static lreal_type_name_c lreal_type_name; |
|
63 |
static byte_type_name_c byte_type_name; |
|
64 |
static usint_type_name_c usint_type_name; |
|
65 |
static ulint_type_name_c ulint_type_name; |
|
66 |
static bool_type_name_c bool_type_name; |
|
67 |
static time_type_name_c time_type_name; |
|
68 |
static int_type_name_c int_type_name; |
|
69 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
70 |
/* |
181 | 71 |
static constant_real_type_name_c constant_real_type_name; |
72 |
static constant_int_type_name_c constant_int_type_name; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
73 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
74 |
/* 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
|
75 |
static integer_c integer; |
181 | 76 |
|
77 |
/******************************************************/ |
|
78 |
/* Extensions to the base standard as defined in */ |
|
79 |
/* "Safety Software Technical Specification, */ |
|
80 |
/* Part 1: Concepts and Function Blocks, */ |
|
81 |
/* Version 1.0 – Official Release" */ |
|
82 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
83 |
/******************************************************/ |
|
84 |
static safebool_type_name_c safebool_type_name; |
|
85 |
||
86 |
||
87 |
public: |
|
88 |
symbol_c *get_type(symbol_c *constant); |
|
89 |
||
90 |
||
91 |
private: |
|
92 |
/*********************/ |
|
93 |
/* B 1.2 - Constants */ |
|
94 |
/*********************/ |
|
95 |
||
96 |
/******************************/ |
|
97 |
/* B 1.2.1 - Numeric Literals */ |
|
98 |
/******************************/ |
|
99 |
void *visit(real_c *symbol); |
|
100 |
void *visit(integer_c *symbol); |
|
101 |
void *visit(binary_integer_c *symbol); |
|
102 |
void *visit(octal_integer_c *symbol); |
|
103 |
void *visit(hex_integer_c *symbol); |
|
104 |
||
105 |
void *visit(integer_literal_c *symbol); |
|
106 |
void *visit(real_literal_c *symbol); |
|
107 |
void *visit(bit_string_literal_c *symbol); |
|
108 |
void *visit(boolean_literal_c *symbol); |
|
109 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
|
181 | 113 |
/*******************************/ |
114 |
/* B.1.2.2 Character Strings */ |
|
115 |
/*******************************/ |
|
116 |
void *visit(double_byte_character_string_c *symbol); |
|
117 |
void *visit(single_byte_character_string_c *symbol); |
|
118 |
||
119 |
/***************************/ |
|
120 |
/* B 1.2.3 - Time Literals */ |
|
121 |
/***************************/ |
|
122 |
/************************/ |
|
123 |
/* B 1.2.3.1 - Duration */ |
|
124 |
/************************/ |
|
125 |
void *visit(neg_time_c *symbol); |
|
126 |
void *visit(duration_c *symbol); |
|
127 |
void *visit(fixed_point_c *symbol); |
|
128 |
void *visit(days_c *symbol); |
|
129 |
void *visit(hours_c *symbol); |
|
130 |
void *visit(minutes_c *symbol); |
|
131 |
void *visit(seconds_c *symbol); |
|
132 |
void *visit(milliseconds_c *symbol); |
|
133 |
||
134 |
/************************************/ |
|
135 |
/* B 1.2.3.2 - Time of day and Date */ |
|
136 |
/************************************/ |
|
137 |
void *visit(time_of_day_c *symbol); |
|
138 |
void *visit(daytime_c *symbol); |
|
139 |
void *visit(date_c *symbol); |
|
140 |
void *visit(date_literal_c *symbol); |
|
141 |
void *visit(date_and_time_c *symbol); |
|
142 |
}; // search_constant_type_c |
|
143 |
||
144 |
||
145 |