author | Mario de Sousa <msousa@fe.up.pt> |
Fri, 01 Apr 2011 12:19:32 +0100 | |
changeset 266 | 2f6d8866ec8d |
parent 265 | 4d222f46f8cc |
child 279 | c0453b7f99df |
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) |
181 | 5 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
6 |
* 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
|
7 |
* 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
|
8 |
* 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
|
9 |
* (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
|
10 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
11 |
* 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
|
12 |
* 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
|
13 |
* 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
|
14 |
* 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
|
15 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
16 |
* 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
|
17 |
* 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
|
18 |
* |
181 | 19 |
* |
20 |
* This code is made available on the understanding that it will not be |
|
21 |
* used in safety-critical situations without a full and competent review. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
25 |
* An IEC 61131-3 compiler. |
181 | 26 |
* |
27 |
* Based on the |
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
29 |
* |
|
30 |
*/ |
|
31 |
||
32 |
/* Determine the data type of a specific constant or variable. |
|
33 |
* A reference to the relevant type definition is returned. |
|
34 |
* |
|
35 |
* For example: |
|
36 |
* 22 -> returns reference to a int_type_name_c object. |
|
37 |
* 22.2 -> returns reference to a real_type_name_c object. |
|
38 |
* LREAL#22.2 -> returns reference to a lreal_type_name_c object. |
|
39 |
* etc... |
|
40 |
*/ |
|
41 |
||
42 |
||
43 |
#include "../absyntax/visitor.hh" |
|
44 |
||
45 |
||
46 |
class search_constant_type_c: public search_visitor_c { |
|
47 |
||
48 |
public: |
|
49 |
/**********************/ |
|
50 |
/* B.1.3 - Data types */ |
|
51 |
/**********************/ |
|
52 |
/***********************************/ |
|
53 |
/* B 1.3.1 - Elementary Data Types */ |
|
54 |
/***********************************/ |
|
55 |
static real_type_name_c real_type_name; |
|
56 |
static sint_type_name_c sint_type_name; |
|
57 |
static lint_type_name_c lint_type_name; |
|
58 |
static dint_type_name_c dint_type_name; |
|
59 |
static date_type_name_c date_type_name; |
|
60 |
static dword_type_name_c dword_type_name; |
|
61 |
static dt_type_name_c dt_type_name; |
|
62 |
static tod_type_name_c tod_type_name; |
|
63 |
static udint_type_name_c udint_type_name; |
|
64 |
static word_type_name_c word_type_name; |
|
65 |
static wstring_type_name_c wstring_type_name; |
|
66 |
static string_type_name_c string_type_name; |
|
67 |
static lword_type_name_c lword_type_name; |
|
68 |
static uint_type_name_c uint_type_name; |
|
69 |
static lreal_type_name_c lreal_type_name; |
|
70 |
static byte_type_name_c byte_type_name; |
|
71 |
static usint_type_name_c usint_type_name; |
|
72 |
static ulint_type_name_c ulint_type_name; |
|
73 |
static bool_type_name_c bool_type_name; |
|
74 |
static time_type_name_c time_type_name; |
|
75 |
static int_type_name_c int_type_name; |
|
76 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
77 |
/* 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
|
78 |
static integer_c integer; |
181 | 79 |
|
80 |
/******************************************************/ |
|
81 |
/* Extensions to the base standard as defined in */ |
|
82 |
/* "Safety Software Technical Specification, */ |
|
83 |
/* Part 1: Concepts and Function Blocks, */ |
|
84 |
/* Version 1.0 – Official Release" */ |
|
85 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
86 |
/******************************************************/ |
|
257 | 87 |
|
88 |
// static safebool_type_name_c safebool_type_name; |
|
89 |
/* The following is required because the expression (TOD_var - TOD_var) will result in a data type |
|
90 |
* (in this case, TIME) that is neither of the expression elements... |
|
91 |
*/ |
|
92 |
static safetime_type_name_c safetime_type_name; |
|
93 |
static safetod_type_name_c safetod_type_name; |
|
94 |
static safedt_type_name_c safedt_type_name; |
|
95 |
||
181 | 96 |
|
97 |
||
98 |
public: |
|
99 |
symbol_c *get_type(symbol_c *constant); |
|
100 |
||
101 |
||
102 |
private: |
|
103 |
/*********************/ |
|
104 |
/* B 1.2 - Constants */ |
|
105 |
/*********************/ |
|
106 |
||
107 |
/******************************/ |
|
108 |
/* B 1.2.1 - Numeric Literals */ |
|
109 |
/******************************/ |
|
110 |
void *visit(real_c *symbol); |
|
257 | 111 |
void *visit(neg_real_c *symbol); |
181 | 112 |
void *visit(integer_c *symbol); |
257 | 113 |
void *visit(neg_integer_c *symbol); |
181 | 114 |
void *visit(binary_integer_c *symbol); |
115 |
void *visit(octal_integer_c *symbol); |
|
116 |
void *visit(hex_integer_c *symbol); |
|
117 |
||
118 |
void *visit(integer_literal_c *symbol); |
|
119 |
void *visit(real_literal_c *symbol); |
|
120 |
void *visit(bit_string_literal_c *symbol); |
|
121 |
void *visit(boolean_literal_c *symbol); |
|
122 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
|
181 | 126 |
/*******************************/ |
127 |
/* B.1.2.2 Character Strings */ |
|
128 |
/*******************************/ |
|
129 |
void *visit(double_byte_character_string_c *symbol); |
|
130 |
void *visit(single_byte_character_string_c *symbol); |
|
131 |
||
132 |
/***************************/ |
|
133 |
/* B 1.2.3 - Time Literals */ |
|
134 |
/***************************/ |
|
135 |
/************************/ |
|
136 |
/* B 1.2.3.1 - Duration */ |
|
137 |
/************************/ |
|
138 |
void *visit(neg_time_c *symbol); |
|
139 |
void *visit(duration_c *symbol); |
|
140 |
void *visit(fixed_point_c *symbol); |
|
141 |
void *visit(days_c *symbol); |
|
142 |
void *visit(hours_c *symbol); |
|
143 |
void *visit(minutes_c *symbol); |
|
144 |
void *visit(seconds_c *symbol); |
|
145 |
void *visit(milliseconds_c *symbol); |
|
146 |
||
147 |
/************************************/ |
|
148 |
/* B 1.2.3.2 - Time of day and Date */ |
|
149 |
/************************************/ |
|
150 |
void *visit(time_of_day_c *symbol); |
|
151 |
void *visit(daytime_c *symbol); |
|
152 |
void *visit(date_c *symbol); |
|
153 |
void *visit(date_literal_c *symbol); |
|
154 |
void *visit(date_and_time_c *symbol); |
|
155 |
}; // search_constant_type_c |
|
156 |
||
157 |
||
158 |