author | mjsousa |
Sun, 14 Dec 2014 19:15:29 +0000 | |
changeset 964 | 5f4dfe6670da |
parent 958 | 7474d2cd1d6e |
child 971 | 8aee27d46208 |
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" |
|
596
4efb11e44065
Add ERROR_MSG macro && move extract_XXX() functions to constant_folding.cc
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
49 |
#include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
181 | 50 |
|
51 |
||
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
52 |
/* pointer to singleton instance */ |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
53 |
search_base_type_c *search_base_type_c::search_base_type_singleton = NULL; |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
54 |
|
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
55 |
|
181 | 56 |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
57 |
search_base_type_c::search_base_type_c(void) {current_basetype_name = NULL; current_basetype = NULL; current_equivtype = NULL;} |
181 | 58 |
|
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
59 |
/* static method! */ |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
60 |
void search_base_type_c::create_singleton(void) { |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
61 |
if (NULL == search_base_type_singleton) search_base_type_singleton = new search_base_type_c(); |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
62 |
if (NULL == search_base_type_singleton) ERROR; |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
63 |
} |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
64 |
|
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
65 |
/* static method! */ |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
66 |
symbol_c *search_base_type_c::get_equivtype_decl(symbol_c *symbol) { |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
67 |
create_singleton(); |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
68 |
if (NULL == symbol) return NULL; |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
69 |
search_base_type_singleton->current_basetype_name = NULL; |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
70 |
search_base_type_singleton->current_basetype = NULL; |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
71 |
search_base_type_singleton->current_equivtype = NULL; |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
72 |
symbol_c *basetype = (symbol_c *)symbol->accept(*search_base_type_singleton); |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
73 |
if (NULL != search_base_type_singleton->current_equivtype) |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
74 |
return search_base_type_singleton->current_equivtype; |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
75 |
return basetype; |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
76 |
} |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
77 |
|
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
78 |
/* static method! */ |
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
|
79 |
symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
80 |
create_singleton(); |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
81 |
if (NULL == symbol) return NULL; |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
82 |
search_base_type_singleton->current_basetype_name = NULL; |
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
83 |
search_base_type_singleton->current_basetype = NULL; |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
84 |
search_base_type_singleton->current_equivtype = NULL; |
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
85 |
return (symbol_c *)symbol->accept(*search_base_type_singleton); |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
86 |
} |
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
87 |
|
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
88 |
/* static method! */ |
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
|
89 |
symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
90 |
create_singleton(); |
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
91 |
if (NULL == symbol) return NULL; |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
92 |
search_base_type_singleton->current_basetype_name = NULL; |
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
93 |
search_base_type_singleton->current_basetype = NULL; |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
94 |
search_base_type_singleton->current_equivtype = NULL; |
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
95 |
symbol->accept(*search_base_type_singleton); |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
96 |
return (symbol_c *)search_base_type_singleton->current_basetype_name; |
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
|
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 |
|
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 |
/* 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
|
103 |
/*************************/ |
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 |
/*******************************************/ |
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 |
/* 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
|
107 |
/*******************************************/ |
945
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
921
diff
changeset
|
108 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
921
diff
changeset
|
109 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
921
diff
changeset
|
110 |
void *search_base_type_c::handle_datatype_identifier(token_c *type_name) { |
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
|
111 |
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
|
112 |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
113 |
this->current_basetype_name = type_name; |
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
114 |
/* if we have reached this point, it is because the current_basetype is not yet pointing to the base datatype we are looking for, |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
115 |
* so we will be searching for the delcaration of the type named in type_name, which might be the base datatype (we search recursively!) |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
116 |
*/ |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
117 |
this->current_basetype = NULL; |
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
|
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 |
/* 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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
|
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
|
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
|
128 |
/* 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
|
129 |
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
|
130 |
|
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
|
131 |
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
|
132 |
} |
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
|
133 |
|
958
7474d2cd1d6e
Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents:
945
diff
changeset
|
134 |
void *search_base_type_c::visit( identifier_c *type_name) {return handle_datatype_identifier(type_name);} |
7474d2cd1d6e
Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents:
945
diff
changeset
|
135 |
void *search_base_type_c::visit(derived_datatype_identifier_c *type_name) {return handle_datatype_identifier(type_name);} |
7474d2cd1d6e
Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents:
945
diff
changeset
|
136 |
void *search_base_type_c::visit( poutype_identifier_c *type_name) {return handle_datatype_identifier(type_name);} |
945
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
921
diff
changeset
|
137 |
|
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
|
138 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
139 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
140 |
/* B 1.2 - Constants */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
141 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
142 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
143 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
144 |
/* 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
|
145 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
146 |
/* 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
|
147 |
* 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
|
148 |
* 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
|
149 |
* 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
|
150 |
* 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
|
151 |
* 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
|
152 |
*/ |
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
153 |
void *search_base_type_c::visit(real_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
154 |
void *search_base_type_c::visit(neg_real_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
155 |
void *search_base_type_c::visit(integer_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
156 |
void *search_base_type_c::visit(neg_integer_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
157 |
void *search_base_type_c::visit(binary_integer_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
158 |
void *search_base_type_c::visit(octal_integer_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
159 |
void *search_base_type_c::visit(hex_integer_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
160 |
void *search_base_type_c::visit(boolean_true_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
161 |
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
|
162 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
163 |
|
181 | 164 |
/***********************************/ |
165 |
/* B 1.3.1 - Elementary Data Types */ |
|
166 |
/***********************************/ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
167 |
void *search_base_type_c::visit(time_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
168 |
void *search_base_type_c::visit(bool_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
169 |
void *search_base_type_c::visit(sint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
170 |
void *search_base_type_c::visit(int_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
171 |
void *search_base_type_c::visit(dint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
172 |
void *search_base_type_c::visit(lint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
173 |
void *search_base_type_c::visit(usint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
174 |
void *search_base_type_c::visit(uint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
175 |
void *search_base_type_c::visit(udint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
176 |
void *search_base_type_c::visit(ulint_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
177 |
void *search_base_type_c::visit(real_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
178 |
void *search_base_type_c::visit(lreal_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
179 |
void *search_base_type_c::visit(date_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
180 |
void *search_base_type_c::visit(tod_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
181 |
void *search_base_type_c::visit(dt_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
182 |
void *search_base_type_c::visit(byte_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
183 |
void *search_base_type_c::visit(word_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
184 |
void *search_base_type_c::visit(dword_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
185 |
void *search_base_type_c::visit(lword_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
186 |
void *search_base_type_c::visit(string_type_name_c *symbol) {return (void *)symbol;} |
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
187 |
void *search_base_type_c::visit(wstring_type_name_c *symbol) {return (void *)symbol;} |
257 | 188 |
|
189 |
||
181 | 190 |
/******************************************************/ |
191 |
/* Extensions to the base standard as defined in */ |
|
192 |
/* "Safety Software Technical Specification, */ |
|
193 |
/* Part 1: Concepts and Function Blocks, */ |
|
194 |
/* Version 1.0 – Official Release" */ |
|
195 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
196 |
/******************************************************/ |
|
257 | 197 |
|
198 |
void *search_base_type_c::visit(safetime_type_name_c *symbol) {return (void *)symbol;} |
|
199 |
void *search_base_type_c::visit(safebool_type_name_c *symbol) {return (void *)symbol;} |
|
200 |
void *search_base_type_c::visit(safesint_type_name_c *symbol) {return (void *)symbol;} |
|
201 |
void *search_base_type_c::visit(safeint_type_name_c *symbol) {return (void *)symbol;} |
|
202 |
void *search_base_type_c::visit(safedint_type_name_c *symbol) {return (void *)symbol;} |
|
203 |
void *search_base_type_c::visit(safelint_type_name_c *symbol) {return (void *)symbol;} |
|
204 |
void *search_base_type_c::visit(safeusint_type_name_c *symbol) {return (void *)symbol;} |
|
205 |
void *search_base_type_c::visit(safeuint_type_name_c *symbol) {return (void *)symbol;} |
|
206 |
void *search_base_type_c::visit(safeudint_type_name_c *symbol) {return (void *)symbol;} |
|
207 |
void *search_base_type_c::visit(safeulint_type_name_c *symbol) {return (void *)symbol;} |
|
208 |
void *search_base_type_c::visit(safereal_type_name_c *symbol) {return (void *)symbol;} |
|
209 |
void *search_base_type_c::visit(safelreal_type_name_c *symbol) {return (void *)symbol;} |
|
210 |
void *search_base_type_c::visit(safedate_type_name_c *symbol) {return (void *)symbol;} |
|
211 |
void *search_base_type_c::visit(safetod_type_name_c *symbol) {return (void *)symbol;} |
|
212 |
void *search_base_type_c::visit(safedt_type_name_c *symbol) {return (void *)symbol;} |
|
213 |
void *search_base_type_c::visit(safebyte_type_name_c *symbol) {return (void *)symbol;} |
|
214 |
void *search_base_type_c::visit(safeword_type_name_c *symbol) {return (void *)symbol;} |
|
215 |
void *search_base_type_c::visit(safedword_type_name_c *symbol) {return (void *)symbol;} |
|
216 |
void *search_base_type_c::visit(safelword_type_name_c *symbol) {return (void *)symbol;} |
|
217 |
void *search_base_type_c::visit(safestring_type_name_c *symbol) {return (void *)symbol;} |
|
218 |
void *search_base_type_c::visit(safewstring_type_name_c *symbol) {return (void *)symbol;} |
|
181 | 219 |
|
220 |
/********************************/ |
|
921
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
221 |
/* B.1.3.2 - Generic data types */ |
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
222 |
/********************************/ |
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
223 |
void *search_base_type_c::visit(generic_type_any_c *symbol) {return (void *)symbol;} |
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
224 |
|
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
225 |
/********************************/ |
181 | 226 |
/* B 1.3.3 - Derived data types */ |
227 |
/********************************/ |
|
228 |
/* simple_type_name ':' simple_spec_init */ |
|
229 |
void *search_base_type_c::visit(simple_type_declaration_c *symbol) { |
|
230 |
return symbol->simple_spec_init->accept(*this); |
|
231 |
} |
|
232 |
/* simple_specification ASSIGN constant */ |
|
233 |
void *search_base_type_c::visit(simple_spec_init_c *symbol) { |
|
234 |
return symbol->simple_specification->accept(*this); |
|
235 |
} |
|
236 |
||
237 |
/* subrange_type_name ':' subrange_spec_init */ |
|
238 |
void *search_base_type_c::visit(subrange_type_declaration_c *symbol) { |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
239 |
this->current_equivtype = symbol; |
181 | 240 |
return symbol->subrange_spec_init->accept(*this); |
241 |
} |
|
242 |
||
243 |
/* subrange_specification ASSIGN signed_integer */ |
|
244 |
void *search_base_type_c::visit(subrange_spec_init_c *symbol) { |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
245 |
if (NULL == this->current_equivtype) |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
246 |
this->current_equivtype = symbol; |
181 | 247 |
return symbol->subrange_specification->accept(*this); |
248 |
} |
|
249 |
||
250 |
/* integer_type_name '(' subrange')' */ |
|
251 |
void *search_base_type_c::visit(subrange_specification_c *symbol) { |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
252 |
if (NULL == this->current_equivtype) |
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
253 |
this->current_equivtype = symbol; |
181 | 254 |
return symbol->integer_type_name->accept(*this); |
255 |
} |
|
256 |
||
257 |
/* signed_integer DOTDOT signed_integer */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
258 |
void *search_base_type_c::visit(subrange_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 259 |
|
260 |
/* enumerated_type_name ':' enumerated_spec_init */ |
|
261 |
void *search_base_type_c::visit(enumerated_type_declaration_c *symbol) { |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
262 |
this->current_basetype_name = symbol->enumerated_type_name; |
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
263 |
/* NOTE: We want search_base_type_c to return a enumerated_type_declaration_c as the base datatpe if possible |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
264 |
* (i.e. if it is a named datatype declared inside a TYPE ... END_TYPE declarations, as opposed to an |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
265 |
* anonymous datatype declared in a VAR ... AND_VAR declaration). |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
266 |
* However, we cannot return this symbol just yet, as it may not be the final base datatype. |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
267 |
* So we store it in a temporary current_basetype variable! |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
268 |
*/ |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
269 |
this->current_basetype = symbol; |
181 | 270 |
return symbol->enumerated_spec_init->accept(*this); |
271 |
} |
|
272 |
||
273 |
/* enumerated_specification ASSIGN enumerated_value */ |
|
274 |
void *search_base_type_c::visit(enumerated_spec_init_c *symbol) { |
|
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
275 |
// current_basetype may have been set in the previous enumerated_type_declaration_c visitor, in which case we do not want to overwrite the value! |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
276 |
if (NULL == this->current_basetype) |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
277 |
this->current_basetype = symbol; |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
278 |
/* NOTE: the following line may call either the visitor to |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
279 |
* - identifier_c, in which case this is not yet the base datatype we are looking for (it will set current_basetype to NULL!) |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
280 |
* - enumerated_value_list_c, in which case we have found the base datatype. |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
281 |
*/ |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
282 |
return symbol->enumerated_specification->accept(*this); |
181 | 283 |
} |
284 |
||
285 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
286 |
/* enumerated_value_list ',' enumerated_value */ |
|
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
619
diff
changeset
|
287 |
void *search_base_type_c::visit(enumerated_value_list_c *symbol) { |
726
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
288 |
// current_basetype may have been set in the previous enumerated_type_declaration_c or enumerated_spec_init_c visitors, in which case we do not want to overwrite the value! |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
289 |
if (NULL == this->current_basetype) |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
290 |
this->current_basetype = symbol; |
9b61eb4f00dc
Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
291 |
return (void *)current_basetype; |
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
619
diff
changeset
|
292 |
} |
181 | 293 |
|
294 |
/* enumerated_type_name '#' identifier */ |
|
295 |
// SYM_REF2(enumerated_value_c, type, value) |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
296 |
void *search_base_type_c::visit(enumerated_value_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 297 |
|
298 |
/* identifier ':' array_spec_init */ |
|
299 |
void *search_base_type_c::visit(array_type_declaration_c *symbol) { |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
300 |
this->current_basetype_name = symbol->identifier; |
181 | 301 |
return symbol->array_spec_init->accept(*this); |
302 |
} |
|
303 |
||
304 |
/* array_specification [ASSIGN array_initialization} */ |
|
305 |
/* array_initialization may be NULL ! */ |
|
306 |
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
|
307 |
/* 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
|
308 |
* 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
|
309 |
* 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
|
310 |
*/ |
181 | 311 |
return symbol->array_specification->accept(*this); |
312 |
} |
|
313 |
||
314 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
315 |
void *search_base_type_c::visit(array_specification_c *symbol) {return (void *)symbol;} |
181 | 316 |
|
317 |
/* helper symbol for array_specification */ |
|
318 |
/* array_subrange_list ',' subrange */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
319 |
void *search_base_type_c::visit(array_subrange_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 320 |
|
321 |
/* array_initialization: '[' array_initial_elements_list ']' */ |
|
322 |
/* helper symbol for array_initialization */ |
|
323 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
324 |
void *search_base_type_c::visit(array_initial_elements_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 325 |
|
326 |
/* integer '(' [array_initial_element] ')' */ |
|
327 |
/* array_initial_element may be NULL ! */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
328 |
void *search_base_type_c::visit(array_initial_elements_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 329 |
|
330 |
/* structure_type_name ':' structure_specification */ |
|
331 |
/* NOTE: structure_specification will point to either a |
|
332 |
* initialized_structure_c |
|
333 |
* OR A |
|
334 |
* structure_element_declaration_list_c |
|
335 |
*/ |
|
336 |
void *search_base_type_c::visit(structure_type_declaration_c *symbol) { |
|
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
337 |
this->current_basetype_name = symbol->structure_type_name; |
181 | 338 |
return symbol->structure_specification->accept(*this); |
339 |
} |
|
340 |
||
412
aad38592bdde
Fix bug with InOut variable of structured type
Laurent Bessard
parents:
377
diff
changeset
|
341 |
/* var1_list ':' structure_type_name */ |
aad38592bdde
Fix bug with InOut variable of structured type
Laurent Bessard
parents:
377
diff
changeset
|
342 |
void *search_base_type_c::visit(structured_var_declaration_c *symbol) { |
625 | 343 |
return symbol; |
412
aad38592bdde
Fix bug with InOut variable of structured type
Laurent Bessard
parents:
377
diff
changeset
|
344 |
} |
aad38592bdde
Fix bug with InOut variable of structured type
Laurent Bessard
parents:
377
diff
changeset
|
345 |
|
181 | 346 |
/* structure_type_name ASSIGN structure_initialization */ |
347 |
/* structure_initialization may be NULL ! */ |
|
348 |
void *search_base_type_c::visit(initialized_structure_c *symbol) { |
|
349 |
return symbol->structure_type_name->accept(*this); |
|
350 |
} |
|
351 |
||
352 |
/* helper symbol for structure_declaration */ |
|
353 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
354 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
355 |
void *search_base_type_c::visit(structure_element_declaration_list_c *symbol) {return (void *)symbol;} |
181 | 356 |
|
357 |
/* structure_element_name ':' *_spec_init */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
358 |
void *search_base_type_c::visit(structure_element_declaration_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 359 |
|
360 |
/* helper symbol for structure_initialization */ |
|
361 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
362 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
363 |
void *search_base_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 364 |
|
365 |
/* structure_element_name ASSIGN value */ |
|
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
366 |
void *search_base_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
181 | 367 |
|
368 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
369 |
/* |
|
370 |
SYM_REF4(string_type_declaration_c, string_type_name, |
|
371 |
elementary_string_type_name, |
|
372 |
string_type_declaration_size, |
|
373 |
string_type_declaration_init) // may be == NULL! |
|
374 |
*/ |
|
909
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
375 |
void *search_base_type_c::visit(string_type_declaration_c *symbol) {return (void *)symbol;} |
181 | 376 |
|
808
7a6b53d61ea3
Consider fb_name_decl_c a non base data type class!
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
377 |
|
810
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
808
diff
changeset
|
378 |
/* function_block_type_name ASSIGN structure_initialization */ |
808
7a6b53d61ea3
Consider fb_name_decl_c a non base data type class!
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
379 |
/* structure_initialization -> may be NULL ! */ |
810
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
808
diff
changeset
|
380 |
// SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization) |
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
808
diff
changeset
|
381 |
void *search_base_type_c::visit(fb_spec_init_c *symbol) { |
808
7a6b53d61ea3
Consider fb_name_decl_c a non base data type class!
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
382 |
return symbol->function_block_type_name->accept(*this); |
7a6b53d61ea3
Consider fb_name_decl_c a non base data type class!
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
383 |
} |
7a6b53d61ea3
Consider fb_name_decl_c a non base data type class!
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
384 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
385 |
|
810
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
808
diff
changeset
|
386 |
|
909
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
387 |
/* ref_spec: REF_TO (non_generic_type_name | function_block_type_name) */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
388 |
// SYM_REF1(ref_spec_c, type_name) |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
389 |
void *search_base_type_c::visit(ref_spec_c *symbol) {return (void *)symbol;} |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
390 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
391 |
/* For the moment, we do not support initialising reference data types */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
392 |
/* ref_spec_init: ref_spec [ ASSIGN ref_initialization ]; */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
393 |
/* NOTE: ref_initialization may be NULL!! */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
394 |
// SYM_REF2(ref_spec_init_c, ref_spec, ref_initialization) |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
395 |
void *search_base_type_c::visit(ref_spec_init_c *symbol) { |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
396 |
return symbol->ref_spec->accept(*this); |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
397 |
} |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
398 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
399 |
/* ref_type_decl: identifier ':' ref_spec_init */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
400 |
// SYM_REF2(ref_type_decl_c, ref_type_name, ref_spec_init) |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
401 |
void *search_base_type_c::visit(ref_type_decl_c *symbol) { |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
402 |
this->current_basetype_name = symbol->ref_type_name; |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
403 |
return symbol->ref_spec_init->accept(*this); |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
404 |
} |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
405 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
406 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
858
diff
changeset
|
407 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
408 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
409 |
/* 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
|
410 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
411 |
/* 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
|
412 |
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
413 |
void *search_base_type_c::visit(function_block_declaration_c *symbol) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
414 |
return (void *)symbol; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
415 |
} |
617
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
416 |
|
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
417 |
|
43e00c10dc49
Change code formatting (alignment)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
418 |
|
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
419 |
/*********************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
420 |
/* B.1.6 Sequential function chart elements */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
421 |
/*********************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
422 |
/* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
423 |
// SYM_REF2(initial_step_c, step_name, action_association_list) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
424 |
void *search_base_type_c::visit(initial_step_c *symbol) { |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
425 |
this->current_basetype_name = NULL; /* this pseudo data type does not have a type name! */ |
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
426 |
return (void *)symbol; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
427 |
} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
428 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
429 |
/* STEP step_name ':' action_association_list END_STEP */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
430 |
// SYM_REF2(step_c, step_name, action_association_list) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
431 |
void *search_base_type_c::visit(step_c *symbol) { |
858
c5f145364a4f
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
mjsousa
parents:
854
diff
changeset
|
432 |
this->current_basetype_name = NULL; /* this pseudo data type does not have a type name! */ |
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
433 |
return (void *)symbol; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
434 |
} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
617
diff
changeset
|
435 |