author | Mario de Sousa <msousa@fe.up.pt> |
Tue, 17 Apr 2012 14:21:31 +0100 | |
changeset 519 | 018093957030 |
parent 417 | d48f53715f77 |
child 596 | 4efb11e44065 |
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 |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
3 |
* |
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
4 |
* Copyright (C) 2003-2012 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 |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
diff
changeset
|
6 |
* |
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 on which another data type is based on. |
|
34 |
* If a new default initial value is given, we DO NOT consider it a |
|
35 |
* new base class, and continue looking further! |
|
36 |
* |
|
37 |
* E.g. TYPE new_int_t : INT; END_TYPE; |
|
38 |
* TYPE new_int2_t : INT = 2; END_TYPE; |
|
39 |
* TYPE new_subr_t : INT (4..5); END_TYPE; |
|
40 |
* |
|
41 |
* new_int_t is really an INT!! |
|
42 |
* new_int2_t is also really an INT!! |
|
43 |
* new_subr_t is also really an INT!! |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
44 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
45 |
* Note that a FB declaration is also considered a base type, as |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
46 |
* we may have FB instances declared of a specific FB type. |
181 | 47 |
*/ |
48 |
#include "absyntax_utils.hh" |
|
49 |
||
50 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
51 |
/* function defined in main.cc */ |
|
52 |
extern void error_exit(const char *file_name, int line_no); |
|
53 |
||
54 |
||
55 |
||
56 |
search_base_type_c::search_base_type_c(void) {current_type_name = NULL;} |
|
57 |
||
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
58 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
59 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
60 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
61 |
symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
62 |
if (NULL == symbol) |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
63 |
return NULL; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
64 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
65 |
return (symbol_c *)symbol->accept(*this); |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
66 |
} |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
67 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
68 |
symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
69 |
if (NULL == symbol) |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
70 |
return NULL; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
71 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
72 |
current_type_name = NULL; /* just to be on the safe side... */ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
73 |
symbol->accept(*this); |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
74 |
return (symbol_c *)current_type_name; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
75 |
} |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
76 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
77 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
78 |
/* Note by MJS: The following two functions definately do not belong in this class!! Maybe create a new utility class? |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
79 |
* I will need to clean this up when the opportunity arises! |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
80 |
*/ |
181 | 81 |
|
82 |
bool search_base_type_c::type_is_subrange(symbol_c* type_decl) { |
|
83 |
this->is_subrange = false; |
|
84 |
type_decl->accept(*this); |
|
85 |
return this->is_subrange; |
|
86 |
} |
|
87 |
||
88 |
bool search_base_type_c::type_is_enumerated(symbol_c* type_decl) { |
|
89 |
this->is_enumerated = false; |
|
90 |
type_decl->accept(*this); |
|
91 |
return this->is_enumerated; |
|
92 |
} |
|
93 |
||
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
94 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
95 |
/*************************/ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
96 |
/* B.1 - Common elements */ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
97 |
/*************************/ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
98 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
99 |
/*******************************************/ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
100 |
/* B 1.1 - Letters, digits and identifiers */ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
101 |
/*******************************************/ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
102 |
void *search_base_type_c::visit(identifier_c *type_name) { |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
103 |
symbol_c *type_decl; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
104 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
105 |
this->current_type_name = type_name; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
106 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
107 |
/* look up the type declaration... */ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
108 |
type_decl = type_symtable.find_value(type_name); |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
109 |
if (type_decl != type_symtable.end_value()) |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
110 |
return type_decl->accept(*this); |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
111 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
112 |
type_decl = function_block_type_symtable.find_value(type_name); |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
113 |
if (type_decl != function_block_type_symtable.end_value()) |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
114 |
return type_decl->accept(*this); |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
115 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
116 |
/* Type declaration not found!! */ |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
117 |
ERROR; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
118 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
119 |
return NULL; |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
120 |
} |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
121 |
|
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
122 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
123 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
124 |
/* B 1.2 - Constants */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
125 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
126 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
127 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
128 |
/* B 1.2.1 - Numeric Literals */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
129 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
130 |
/* Numeric literals without any explicit type cast have unknown data type, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
131 |
* so we continue considering them as their own basic data types until |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
132 |
* they can be resolved (for example, when using '30+x' where 'x' is a LINT variable, the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
133 |
* numeric literal '30' must then be considered a LINT so the ADD function may be called |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
134 |
* with all inputs of the same data type. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
135 |
* If 'x' were a SINT, then the '30' would have to be a SINT too! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
136 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
137 |
void *search_base_type_c::visit(real_c *symbol) {return (void *)symbol;} |
257 | 138 |
void *search_base_type_c::visit(neg_real_c *symbol) {return (void *)symbol;} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
139 |
void *search_base_type_c::visit(integer_c *symbol) {return (void *)symbol;} |
257 | 140 |
void *search_base_type_c::visit(neg_integer_c *symbol) {return (void *)symbol;} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
141 |
void *search_base_type_c::visit(binary_integer_c *symbol) {return (void *)symbol;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
142 |
void *search_base_type_c::visit(octal_integer_c *symbol) {return (void *)symbol;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
143 |
void *search_base_type_c::visit(hex_integer_c *symbol) {return (void *)symbol;} |
257 | 144 |
void *search_base_type_c::visit(boolean_true_c *symbol) {return (void *)symbol;} |
145 |
void *search_base_type_c::visit(boolean_false_c *symbol) {return (void *)symbol;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
146 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
147 |
|
181 | 148 |
/***********************************/ |
149 |
/* B 1.3.1 - Elementary Data Types */ |
|
150 |
/***********************************/ |
|
151 |
void *search_base_type_c::visit(time_type_name_c *symbol) {return (void *)symbol;} |
|
152 |
void *search_base_type_c::visit(bool_type_name_c *symbol) {return (void *)symbol;} |
|
153 |
void *search_base_type_c::visit(sint_type_name_c *symbol) {return (void *)symbol;} |
|
154 |
void *search_base_type_c::visit(int_type_name_c *symbol) {return (void *)symbol;} |
|
155 |
void *search_base_type_c::visit(dint_type_name_c *symbol) {return (void *)symbol;} |
|
156 |
void *search_base_type_c::visit(lint_type_name_c *symbol) {return (void *)symbol;} |
|
157 |
void *search_base_type_c::visit(usint_type_name_c *symbol) {return (void *)symbol;} |
|
158 |
void *search_base_type_c::visit(uint_type_name_c *symbol) {return (void *)symbol;} |
|
159 |
void *search_base_type_c::visit(udint_type_name_c *symbol) {return (void *)symbol;} |
|
160 |
void *search_base_type_c::visit(ulint_type_name_c *symbol) {return (void *)symbol;} |
|
161 |
void *search_base_type_c::visit(real_type_name_c *symbol) {return (void *)symbol;} |
|
162 |
void *search_base_type_c::visit(lreal_type_name_c *symbol) {return (void *)symbol;} |
|
163 |
void *search_base_type_c::visit(date_type_name_c *symbol) {return (void *)symbol;} |
|
164 |
void *search_base_type_c::visit(tod_type_name_c *symbol) {return (void *)symbol;} |
|
165 |
void *search_base_type_c::visit(dt_type_name_c *symbol) {return (void *)symbol;} |
|
166 |
void *search_base_type_c::visit(byte_type_name_c *symbol) {return (void *)symbol;} |
|
167 |
void *search_base_type_c::visit(word_type_name_c *symbol) {return (void *)symbol;} |
|
168 |
void *search_base_type_c::visit(dword_type_name_c *symbol) {return (void *)symbol;} |
|
169 |
void *search_base_type_c::visit(lword_type_name_c *symbol) {return (void *)symbol;} |
|
170 |
void *search_base_type_c::visit(string_type_name_c *symbol) {return (void *)symbol;} |
|
171 |
void *search_base_type_c::visit(wstring_type_name_c *symbol) {return (void *)symbol;} |
|
257 | 172 |
|
173 |
||
181 | 174 |
/******************************************************/ |
175 |
/* Extensions to the base standard as defined in */ |
|
176 |
/* "Safety Software Technical Specification, */ |
|
177 |
/* Part 1: Concepts and Function Blocks, */ |
|
178 |
/* Version 1.0 – Official Release" */ |
|
179 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
180 |
/******************************************************/ |
|
257 | 181 |
|
182 |
void *search_base_type_c::visit(safetime_type_name_c *symbol) {return (void *)symbol;} |
|
183 |
void *search_base_type_c::visit(safebool_type_name_c *symbol) {return (void *)symbol;} |
|
184 |
void *search_base_type_c::visit(safesint_type_name_c *symbol) {return (void *)symbol;} |
|
185 |
void *search_base_type_c::visit(safeint_type_name_c *symbol) {return (void *)symbol;} |
|
186 |
void *search_base_type_c::visit(safedint_type_name_c *symbol) {return (void *)symbol;} |
|
187 |
void *search_base_type_c::visit(safelint_type_name_c *symbol) {return (void *)symbol;} |
|
188 |
void *search_base_type_c::visit(safeusint_type_name_c *symbol) {return (void *)symbol;} |
|
189 |
void *search_base_type_c::visit(safeuint_type_name_c *symbol) {return (void *)symbol;} |
|
190 |
void *search_base_type_c::visit(safeudint_type_name_c *symbol) {return (void *)symbol;} |
|
191 |
void *search_base_type_c::visit(safeulint_type_name_c *symbol) {return (void *)symbol;} |
|
192 |
void *search_base_type_c::visit(safereal_type_name_c *symbol) {return (void *)symbol;} |
|
193 |
void *search_base_type_c::visit(safelreal_type_name_c *symbol) {return (void *)symbol;} |
|
194 |
void *search_base_type_c::visit(safedate_type_name_c *symbol) {return (void *)symbol;} |
|
195 |
void *search_base_type_c::visit(safetod_type_name_c *symbol) {return (void *)symbol;} |
|
196 |
void *search_base_type_c::visit(safedt_type_name_c *symbol) {return (void *)symbol;} |
|
197 |
void *search_base_type_c::visit(safebyte_type_name_c *symbol) {return (void *)symbol;} |
|
198 |
void *search_base_type_c::visit(safeword_type_name_c *symbol) {return (void *)symbol;} |
|
199 |
void *search_base_type_c::visit(safedword_type_name_c *symbol) {return (void *)symbol;} |
|
200 |
void *search_base_type_c::visit(safelword_type_name_c *symbol) {return (void *)symbol;} |
|
201 |
void *search_base_type_c::visit(safestring_type_name_c *symbol) {return (void *)symbol;} |
|
202 |
void *search_base_type_c::visit(safewstring_type_name_c *symbol) {return (void *)symbol;} |
|
181 | 203 |
|
204 |
/********************************/ |
|
205 |
/* B 1.3.3 - Derived data types */ |
|
206 |
/********************************/ |
|
207 |
/* simple_type_name ':' simple_spec_init */ |
|
208 |
void *search_base_type_c::visit(simple_type_declaration_c *symbol) { |
|
209 |
return symbol->simple_spec_init->accept(*this); |
|
210 |
} |
|
211 |
/* simple_specification ASSIGN constant */ |
|
212 |
void *search_base_type_c::visit(simple_spec_init_c *symbol) { |
|
213 |
return symbol->simple_specification->accept(*this); |
|
214 |
} |
|
215 |
||
216 |
/* subrange_type_name ':' subrange_spec_init */ |
|
217 |
void *search_base_type_c::visit(subrange_type_declaration_c *symbol) { |
|
218 |
return symbol->subrange_spec_init->accept(*this); |
|
219 |
} |
|
220 |
||
221 |
/* subrange_specification ASSIGN signed_integer */ |
|
222 |
void *search_base_type_c::visit(subrange_spec_init_c *symbol) { |
|
223 |
this->is_subrange = true; |
|
224 |
return symbol->subrange_specification->accept(*this); |
|
225 |
} |
|
226 |
||
227 |
/* integer_type_name '(' subrange')' */ |
|
228 |
void *search_base_type_c::visit(subrange_specification_c *symbol) { |
|
229 |
return symbol->integer_type_name->accept(*this); |
|
230 |
} |
|
231 |
||
232 |
/* signed_integer DOTDOT signed_integer */ |
|
233 |
void *search_base_type_c::visit(subrange_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
234 |
||
235 |
/* enumerated_type_name ':' enumerated_spec_init */ |
|
236 |
void *search_base_type_c::visit(enumerated_type_declaration_c *symbol) { |
|
237 |
this->current_type_name = symbol->enumerated_type_name; |
|
238 |
return symbol->enumerated_spec_init->accept(*this); |
|
239 |
} |
|
240 |
||
241 |
/* enumerated_specification ASSIGN enumerated_value */ |
|
242 |
void *search_base_type_c::visit(enumerated_spec_init_c *symbol) { |
|
243 |
this->is_enumerated = true; |
|
244 |
return symbol->enumerated_specification->accept(*this); |
|
245 |
} |
|
246 |
||
247 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
248 |
/* enumerated_value_list ',' enumerated_value */ |
|
249 |
void *search_base_type_c::visit(enumerated_value_list_c *symbol) { |
|
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
250 |
return (void *)symbol; |
181 | 251 |
} |
252 |
||
253 |
/* enumerated_type_name '#' identifier */ |
|
254 |
// SYM_REF2(enumerated_value_c, type, value) |
|
255 |
void *search_base_type_c::visit(enumerated_value_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
256 |
||
257 |
/* identifier ':' array_spec_init */ |
|
258 |
void *search_base_type_c::visit(array_type_declaration_c *symbol) { |
|
259 |
this->current_type_name = symbol->identifier; |
|
260 |
return symbol->array_spec_init->accept(*this); |
|
261 |
} |
|
262 |
||
263 |
/* array_specification [ASSIGN array_initialization} */ |
|
264 |
/* array_initialization may be NULL ! */ |
|
265 |
void *search_base_type_c::visit(array_spec_init_c *symbol) { |
|
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
266 |
/* Note that the 'array_specification' may be either an identifier of a previsously defined array type, |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
267 |
* or an array_specification_c, so we can not stop here and simply return a array_spec_init_c, |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
268 |
* especially if we are looking for the base class! |
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
269 |
*/ |
181 | 270 |
return symbol->array_specification->accept(*this); |
271 |
} |
|
272 |
||
273 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
274 |
void *search_base_type_c::visit(array_specification_c *symbol) { |
|
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
377
diff
changeset
|
275 |
return symbol; |
181 | 276 |
} |
277 |
||
278 |
/* helper symbol for array_specification */ |
|
279 |
/* array_subrange_list ',' subrange */ |
|
280 |
void *search_base_type_c::visit(array_subrange_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
281 |
||
282 |
/* array_initialization: '[' array_initial_elements_list ']' */ |
|
283 |
/* helper symbol for array_initialization */ |
|
284 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
285 |
void *search_base_type_c::visit(array_initial_elements_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
286 |
||
287 |
/* integer '(' [array_initial_element] ')' */ |
|
288 |
/* array_initial_element may be NULL ! */ |
|
289 |
void *search_base_type_c::visit(array_initial_elements_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
290 |
||
291 |
/* structure_type_name ':' structure_specification */ |
|
292 |
/* NOTE: structure_specification will point to either a |
|
293 |
* initialized_structure_c |
|
294 |
* OR A |
|
295 |
* structure_element_declaration_list_c |
|
296 |
*/ |
|
297 |
void *search_base_type_c::visit(structure_type_declaration_c *symbol) { |
|
298 |
this->current_type_name = symbol->structure_type_name; |
|
299 |
return symbol->structure_specification->accept(*this); |
|
300 |
} |
|
301 |
||
302 |
/* structure_type_name ASSIGN structure_initialization */ |
|
303 |
/* structure_initialization may be NULL ! */ |
|
304 |
void *search_base_type_c::visit(initialized_structure_c *symbol) { |
|
305 |
return symbol->structure_type_name->accept(*this); |
|
306 |
} |
|
307 |
||
308 |
/* helper symbol for structure_declaration */ |
|
309 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
310 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
311 |
void *search_base_type_c::visit(structure_element_declaration_list_c *symbol) { |
|
312 |
return (void *)symbol; |
|
313 |
} |
|
314 |
||
315 |
/* structure_element_name ':' *_spec_init */ |
|
316 |
void *search_base_type_c::visit(structure_element_declaration_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
317 |
||
318 |
/* helper symbol for structure_initialization */ |
|
319 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
320 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
321 |
void *search_base_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
322 |
||
323 |
/* structure_element_name ASSIGN value */ |
|
324 |
void *search_base_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
325 |
||
326 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
327 |
/* |
|
328 |
SYM_REF4(string_type_declaration_c, string_type_name, |
|
329 |
elementary_string_type_name, |
|
330 |
string_type_declaration_size, |
|
331 |
string_type_declaration_init) // may be == NULL! |
|
332 |
*/ |
|
333 |
void *search_base_type_c::visit(string_type_declaration_c *symbol) {return symbol;} |
|
334 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
335 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
336 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
337 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
338 |
/* B 1.5.2 - Function Blocks */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
339 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
340 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
341 |
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
342 |
void *search_base_type_c::visit(function_block_declaration_c *symbol) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
343 |
return symbol; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
344 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
345 |