author | Mario de Sousa <msousa@fe.up.pt> |
Fri, 01 Apr 2011 10:06:19 +0100 | |
changeset 264 | 6facabd9c2cd |
parent 257 | 90782e241346 |
child 265 | 4d222f46f8cc |
permissions | -rwxr-xr-x |
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 |
/* 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
|
71 |
static integer_c integer; |
181 | 72 |
|
73 |
/******************************************************/ |
|
74 |
/* Extensions to the base standard as defined in */ |
|
75 |
/* "Safety Software Technical Specification, */ |
|
76 |
/* Part 1: Concepts and Function Blocks, */ |
|
77 |
/* Version 1.0 – Official Release" */ |
|
78 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
79 |
/******************************************************/ |
|
257 | 80 |
|
81 |
// static safebool_type_name_c safebool_type_name; |
|
82 |
/* The following is required because the expression (TOD_var - TOD_var) will result in a data type |
|
83 |
* (in this case, TIME) that is neither of the expression elements... |
|
84 |
*/ |
|
85 |
static safetime_type_name_c safetime_type_name; |
|
86 |
static safetod_type_name_c safetod_type_name; |
|
87 |
static safedt_type_name_c safedt_type_name; |
|
88 |
||
181 | 89 |
|
90 |
||
91 |
public: |
|
92 |
symbol_c *get_type(symbol_c *constant); |
|
93 |
||
94 |
||
95 |
private: |
|
96 |
/*********************/ |
|
97 |
/* B 1.2 - Constants */ |
|
98 |
/*********************/ |
|
99 |
||
100 |
/******************************/ |
|
101 |
/* B 1.2.1 - Numeric Literals */ |
|
102 |
/******************************/ |
|
103 |
void *visit(real_c *symbol); |
|
257 | 104 |
void *visit(neg_real_c *symbol); |
181 | 105 |
void *visit(integer_c *symbol); |
257 | 106 |
void *visit(neg_integer_c *symbol); |
181 | 107 |
void *visit(binary_integer_c *symbol); |
108 |
void *visit(octal_integer_c *symbol); |
|
109 |
void *visit(hex_integer_c *symbol); |
|
110 |
||
111 |
void *visit(integer_literal_c *symbol); |
|
112 |
void *visit(real_literal_c *symbol); |
|
113 |
void *visit(bit_string_literal_c *symbol); |
|
114 |
void *visit(boolean_literal_c *symbol); |
|
115 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
|
181 | 119 |
/*******************************/ |
120 |
/* B.1.2.2 Character Strings */ |
|
121 |
/*******************************/ |
|
122 |
void *visit(double_byte_character_string_c *symbol); |
|
123 |
void *visit(single_byte_character_string_c *symbol); |
|
124 |
||
125 |
/***************************/ |
|
126 |
/* B 1.2.3 - Time Literals */ |
|
127 |
/***************************/ |
|
128 |
/************************/ |
|
129 |
/* B 1.2.3.1 - Duration */ |
|
130 |
/************************/ |
|
131 |
void *visit(neg_time_c *symbol); |
|
132 |
void *visit(duration_c *symbol); |
|
133 |
void *visit(fixed_point_c *symbol); |
|
134 |
void *visit(days_c *symbol); |
|
135 |
void *visit(hours_c *symbol); |
|
136 |
void *visit(minutes_c *symbol); |
|
137 |
void *visit(seconds_c *symbol); |
|
138 |
void *visit(milliseconds_c *symbol); |
|
139 |
||
140 |
/************************************/ |
|
141 |
/* B 1.2.3.2 - Time of day and Date */ |
|
142 |
/************************************/ |
|
143 |
void *visit(time_of_day_c *symbol); |
|
144 |
void *visit(daytime_c *symbol); |
|
145 |
void *visit(date_c *symbol); |
|
146 |
void *visit(date_literal_c *symbol); |
|
147 |
void *visit(date_and_time_c *symbol); |
|
148 |
}; // search_constant_type_c |
|
149 |
||
150 |
||
151 |