author | mjsousa |
Sun, 28 Dec 2014 13:29:47 +0000 | |
changeset 980 | 9ed5aff159db |
parent 972 | bc90dd4bbf4f |
child 994 | 66dc2ef40e70 |
permissions | -rwxr-xr-x |
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:
diff
changeset
|
1 |
/* |
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:
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
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:
diff
changeset
|
3 |
* |
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:
diff
changeset
|
4 |
* Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
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:
diff
changeset
|
5 |
* Copyright (C) 2012 Manuele Conti (manuele.conti@sirius-es.it) |
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:
diff
changeset
|
6 |
* Copyright (C) 2012 Matteo Facchinetti (matteo.facchinetti@sirius-es.it) |
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:
diff
changeset
|
7 |
* |
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:
diff
changeset
|
8 |
* This program is free software: you can redistribute it and/or modify |
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:
diff
changeset
|
9 |
* it under the terms of the GNU General Public License as published by |
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:
diff
changeset
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
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:
diff
changeset
|
11 |
* (at your option) any later version. |
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:
diff
changeset
|
12 |
* |
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:
diff
changeset
|
13 |
* This program is distributed in the hope that it will be useful, |
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:
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
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:
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
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:
diff
changeset
|
16 |
* GNU General Public License for more details. |
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:
diff
changeset
|
17 |
* |
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:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License |
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:
diff
changeset
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
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:
diff
changeset
|
20 |
* |
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:
diff
changeset
|
21 |
* |
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:
diff
changeset
|
22 |
* This code is made available on the understanding that it will not be |
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:
diff
changeset
|
23 |
* used in safety-critical situations without a full and competent review. |
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:
diff
changeset
|
24 |
*/ |
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:
diff
changeset
|
25 |
|
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:
diff
changeset
|
26 |
/* |
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:
diff
changeset
|
27 |
* An IEC 61131-3 compiler. |
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:
diff
changeset
|
28 |
* |
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:
diff
changeset
|
29 |
* Based on the |
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:
diff
changeset
|
30 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
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:
diff
changeset
|
31 |
* |
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:
diff
changeset
|
32 |
*/ |
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:
diff
changeset
|
33 |
|
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:
diff
changeset
|
34 |
|
541 | 35 |
/* TODO - things yet not checked by this data type checker... |
36 |
* |
|
37 |
* - check variable declarations |
|
38 |
* - check data type declarations |
|
39 |
* - check inside configurations (variable declarations) |
|
40 |
* - check SFC code |
|
41 |
* - must fix S and R IL functions (includes potientialy fixing stage4 code!) |
|
42 |
*/ |
|
43 |
||
44 |
||
552 | 45 |
/* NOTE: The algorithm implemented here assumes that flow control analysis has already been completed! |
46 |
* BEFORE running this visitor, be sure to CALL the flow_control_analysis_c visitor! |
|
47 |
*/ |
|
48 |
||
49 |
||
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:
diff
changeset
|
50 |
/* |
552 | 51 |
* Fill the candidate datatype list for all symbols that may legally 'have' a data type (e.g. variables, literals, function calls, expressions, etc.) |
52 |
* |
|
53 |
* The candidate datatype list will be filled with a list of all the data types that expression may legally take. |
|
54 |
* For example, the very simple literal '0' (as in foo := 0), may represent a: |
|
55 |
* BOOL, BYTE, WORD, DWORD, LWORD, USINT, SINT, UINT, INT, UDINT, DINT, ULINT, LINT (as well as the SAFE versions of these data tyes too!) |
|
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
56 |
* |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
57 |
* WARNING: This visitor class starts off by building a map of all enumeration constants that are defined in the source code (i.e. a library_c symbol), |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
58 |
* and this map is later used to determine the datatpe of each use of an enumeration constant. By implication, the fill_candidate_datatypes_c |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
59 |
* visitor class will only work corretly if it is asked to visit a symbol of class library_c!! |
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:
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:
diff
changeset
|
61 |
|
604
2989051a0a64
Fixing includes to define INTxx_MAX etc...
Mario de Sousa <msousa@fe.up.pt>
parents:
603
diff
changeset
|
62 |
#include <../main.hh> /* required for UINT64_MAX, INT64_MAX, INT64_MIN, ... */ |
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:
diff
changeset
|
63 |
#include "fill_candidate_datatypes.hh" |
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:
diff
changeset
|
64 |
#include "datatype_functions.hh" |
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:
diff
changeset
|
65 |
#include <typeinfo> |
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:
diff
changeset
|
66 |
#include <list> |
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:
diff
changeset
|
67 |
#include <string> |
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:
diff
changeset
|
68 |
#include <string.h> |
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:
diff
changeset
|
69 |
#include <strings.h> |
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:
diff
changeset
|
70 |
|
965
c9eeb67ba939
Small code re-organization of how const values are stored in symbol_c (can now be accessed through member functions, instead of macros)
mjsousa
parents:
958
diff
changeset
|
71 |
|
c9eeb67ba939
Small code re-organization of how const values are stored in symbol_c (can now be accessed through member functions, instead of macros)
mjsousa
parents:
958
diff
changeset
|
72 |
#define GET_CVALUE(dtype, symbol) ((symbol)->const_value._##dtype.get()) |
c9eeb67ba939
Small code re-organization of how const values are stored in symbol_c (can now be accessed through member functions, instead of macros)
mjsousa
parents:
958
diff
changeset
|
73 |
#define VALID_CVALUE(dtype, symbol) ((symbol)->const_value._##dtype.is_valid()) |
c9eeb67ba939
Small code re-organization of how const values are stored in symbol_c (can now be accessed through member functions, instead of macros)
mjsousa
parents:
958
diff
changeset
|
74 |
#define IS_OVERFLOW(dtype, symbol) ((symbol)->const_value._##dtype.is_overflow()) |
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
75 |
|
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
76 |
|
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:
diff
changeset
|
77 |
/* set to 1 to see debug info during execution */ |
454
099aa5d655de
Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents:
453
diff
changeset
|
78 |
static int debug = 0; |
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:
diff
changeset
|
79 |
|
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
80 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
81 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
82 |
/*****************************************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
83 |
/* */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
84 |
/* A small helper class... */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
85 |
/* */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
86 |
/*****************************************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
87 |
|
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
88 |
/* Add to the global_enumerated_value_symtable the global enum value constants, i.e. the enum constants used in the enumerated |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
89 |
* datatypes that are defined inside a TYPE ... END_TYPE declaration. |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
90 |
*/ |
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
91 |
/* NOTE: we do not store any NULL values in this symbol table, so we can safely use NULL and the null value. */ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
92 |
|
972
bc90dd4bbf4f
Change dsymbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents:
965
diff
changeset
|
93 |
typedef dsymtable_c<symbol_c *> enumerated_value_symtable_t; |
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
94 |
static enumerated_value_symtable_t global_enumerated_value_symtable; |
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
95 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
96 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
97 |
class populate_globalenumvalue_symtable_c: public iterator_visitor_c { |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
98 |
private: |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
99 |
symbol_c *current_enumerated_type; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
100 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
101 |
public: |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
102 |
populate_globalenumvalue_symtable_c(void) {current_enumerated_type = NULL;}; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
103 |
~populate_globalenumvalue_symtable_c(void) {} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
104 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
105 |
public: |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
106 |
/*************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
107 |
/* B.1 - Common elements */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
108 |
/*************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
109 |
/**********************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
110 |
/* B.1.3 - Data types */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
111 |
/**********************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
112 |
/********************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
113 |
/* B 1.3.3 - Derived data types */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
114 |
/********************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
115 |
/* enumerated_type_name ':' enumerated_spec_init */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
116 |
void *visit(enumerated_type_declaration_c *symbol) { |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
117 |
//current_enumerated_type = symbol->enumerated_type_name; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
118 |
current_enumerated_type = symbol; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
119 |
symbol->enumerated_spec_init->accept(*this); |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
120 |
current_enumerated_type = NULL; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
121 |
return NULL; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
122 |
} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
123 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
124 |
/* enumerated_specification ASSIGN enumerated_value */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
125 |
void *visit(enumerated_spec_init_c *symbol) { |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
126 |
return symbol->enumerated_specification->accept(*this); |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
127 |
} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
128 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
129 |
/* [enumerated_type_name '#'] identifier */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
130 |
void *visit(enumerated_value_c *symbol) { |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
131 |
if (current_enumerated_type == NULL) ERROR; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
132 |
if (symbol->type != NULL) ERROR; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
133 |
|
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
134 |
enumerated_value_symtable_t::iterator lower = global_enumerated_value_symtable.lower_bound(symbol->value); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
135 |
enumerated_value_symtable_t::iterator upper = global_enumerated_value_symtable.upper_bound(symbol->value); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
136 |
for (; lower != upper; lower++) |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
137 |
if (lower->second == current_enumerated_type) { |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
138 |
/* The same identifier is used more than once as an enumerated value/constant inside the same enumerated datat type! */ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
139 |
return NULL; /* No need to insert it! It is already in the table! */ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
140 |
} |
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
141 |
|
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
142 |
global_enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
143 |
return NULL; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
144 |
} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
145 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
146 |
/**************************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
147 |
/* B.1.5 - Program organization units */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
148 |
/**************************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
149 |
/* B 1.5.1 - Functions */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
150 |
void *visit(function_declaration_c *symbol) {return NULL;} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
151 |
/* B 1.5.2 - Function Blocks */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
152 |
void *visit(function_block_declaration_c *symbol) {return NULL;} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
153 |
/* B 1.5.3 - Programs */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
154 |
void *visit(program_declaration_c *symbol) {return NULL;} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
155 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
156 |
}; /* populate_globalenumvalue_symtable_c */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
157 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
158 |
static populate_globalenumvalue_symtable_c populate_globalenumvalue_symtable; |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
159 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
160 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
161 |
/*****************************************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
162 |
/* */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
163 |
/* A small helper class... */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
164 |
/* */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
165 |
/*****************************************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
166 |
|
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
167 |
/* Add to the local_enumerated_value_symtable the local enum value constants */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
168 |
/* Notes: |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
169 |
* Some enumerations are |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
170 |
* (A) declared anonymously inside a VAR ... END_VAR declaration |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
171 |
* (e.g. VAR enum_var : (enumvalue1, enumvalue2); END_VAR) |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
172 |
* while others are |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
173 |
* (B) declared (with a name) inside a TYPE .. END_TYPE declaration. |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
174 |
* |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
175 |
* Values in (A) are added to the enumerated_value_symtable in absyntaxt_utils.cc. |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
176 |
* Values in (B) are only in scope inside the POU with the VAR END_VAR declaration. |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
177 |
* |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
178 |
* This class will add the enum values in (B) to the local_enumerated_value_symtable. |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
179 |
* |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
180 |
* If a locally defined enum value is identical to another locally defined enum_value, a |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
181 |
* duplicate entry is created. |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
182 |
* However, if a locally defined enum value is identical to another globally defined enum_value, the |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
183 |
* corresponding entry in local_enumerated_value_symtable is also set to the local datatype. |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
184 |
* This is because anonynous locally feined enum datatypes are anonymous, and its enum values cannot therefore |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
185 |
* be disambiguated using EnumType#enum_value (since the enum type does not have a name, it is anonymous!). |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
186 |
* For this reason we implement the semantics where locally defined enum values, when in scope, will 'cover' |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
187 |
* the globally defined enum value with the same name/identifier. |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
188 |
* For example: |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
189 |
* |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
190 |
* TYPE GlobalEnumT: (xxx1, xxx2, xxx3) END_TYPE |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
191 |
* |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
192 |
* FUNCTION_BLOCK FOO |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
193 |
* VAR_INPUT |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
194 |
* GlobalEnumVar: GlobalEnumT; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
195 |
* LocalEnumVar : (xxx1, yyy2, yyy3); |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
196 |
* END_VAR |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
197 |
* LocalEnumVar := xxx1; <-- We consider it OK!!! xxx1 will reference the anonymous type used for LocalEnumVar |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
198 |
* GlobalEnumVar := xxx1; <-- We consider it an error. xxx1 will reference the anonymous type used for LocalEnumVar |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
199 |
* GlobalEnumVar := GlobalEnumT#xxx1; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
200 |
* END_FUNCTION_BLOCK |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
201 |
*/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
202 |
|
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
203 |
static enumerated_value_symtable_t local_enumerated_value_symtable; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
204 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
205 |
|
738
e47cc8c954db
Start to move enumeration declaration checking to its own class.
Mario de Sousa <msousa@fe.up.pt>
parents:
735
diff
changeset
|
206 |
class populate_localenumvalue_symtable_c: public iterator_visitor_c { |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
207 |
private: |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
208 |
symbol_c *current_enumerated_type; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
209 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
210 |
public: |
738
e47cc8c954db
Start to move enumeration declaration checking to its own class.
Mario de Sousa <msousa@fe.up.pt>
parents:
735
diff
changeset
|
211 |
populate_localenumvalue_symtable_c(void) {current_enumerated_type = NULL;}; |
e47cc8c954db
Start to move enumeration declaration checking to its own class.
Mario de Sousa <msousa@fe.up.pt>
parents:
735
diff
changeset
|
212 |
~populate_localenumvalue_symtable_c(void) {} |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
213 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
214 |
public: |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
215 |
/*************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
216 |
/* B.1 - Common elements */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
217 |
/*************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
218 |
/**********************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
219 |
/* B.1.3 - Data types */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
220 |
/**********************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
221 |
/********************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
222 |
/* B 1.3.3 - Derived data types */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
223 |
/********************************/ |
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
224 |
/* TYPE type_declaration_list END_TYPE */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
225 |
void *visit(data_type_declaration_c *symbol) {return NULL;} // do not visit the type declarations!! |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
226 |
|
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
227 |
/* enumerated_specification ASSIGN enumerated_value */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
228 |
void *visit(enumerated_spec_init_c *symbol) { |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
229 |
current_enumerated_type = symbol; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
230 |
symbol->enumerated_specification->accept(*this); |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
231 |
/* DO NOT visit the symbol->enumerated_value !!! */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
232 |
current_enumerated_type = NULL; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
233 |
return NULL; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
234 |
} |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
235 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
236 |
/* [enumerated_type_name '#'] identifier */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
237 |
void *visit(enumerated_value_c *symbol) { |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
238 |
/* if the enumerated_value_c is not inside a enumerated_spec_init_c (e.g. used as the inital value of a variable), we simply return */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
239 |
if (current_enumerated_type == NULL) return NULL; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
240 |
/* this is really an ERROR! The initial value may use the syntax NUM_TYPE#enum_value, but in that case we should have return'd in the above statement !! */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
241 |
if (symbol->type != NULL) ERROR; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
242 |
|
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
243 |
enumerated_value_symtable_t::iterator lower = local_enumerated_value_symtable.lower_bound(symbol->value); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
244 |
enumerated_value_symtable_t::iterator upper = local_enumerated_value_symtable.upper_bound(symbol->value); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
245 |
for (; lower != upper; lower++) |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
246 |
if (lower->second == current_enumerated_type) { |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
247 |
/* The same identifier is used more than once as an enumerated value/constant inside the same enumerated datat type! */ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
248 |
return NULL; /* No need to insert it! It is already in the table! */ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
249 |
} |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
250 |
|
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
251 |
/* add it to the local symbol table. */ |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
252 |
local_enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
253 |
return NULL; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
254 |
} |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
255 |
}; // class populate_enumvalue_symtable_c |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
256 |
|
738
e47cc8c954db
Start to move enumeration declaration checking to its own class.
Mario de Sousa <msousa@fe.up.pt>
parents:
735
diff
changeset
|
257 |
static populate_localenumvalue_symtable_c populate_enumvalue_symtable; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
258 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
259 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
260 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
261 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
262 |
/*****************************************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
263 |
/* */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
264 |
/* Main FILL candidate datatypes algorithm... */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
265 |
/* */ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
266 |
/*****************************************************/ |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
267 |
|
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
268 |
|
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:
diff
changeset
|
269 |
fill_candidate_datatypes_c::fill_candidate_datatypes_c(symbol_c *ignore) { |
661
f537c3315f83
Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents:
652
diff
changeset
|
270 |
il_operand = NULL; |
f537c3315f83
Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents:
652
diff
changeset
|
271 |
prev_il_instruction = NULL; |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
272 |
search_var_instance_decl = NULL; |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
273 |
current_enumerated_spec_type = NULL; |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
274 |
current_scope = 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:
diff
changeset
|
275 |
} |
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:
diff
changeset
|
276 |
|
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:
diff
changeset
|
277 |
fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) { |
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:
diff
changeset
|
278 |
} |
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:
diff
changeset
|
279 |
|
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
280 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
281 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
282 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
283 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
284 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
285 |
|
478
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
286 |
symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]) { |
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:
diff
changeset
|
287 |
int k; |
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:
diff
changeset
|
288 |
/* find a widening table entry compatible */ |
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:
diff
changeset
|
289 |
for (k = 0; NULL != widen_table[k].left; k++) |
478
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
290 |
if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right))) |
476
38d85e9a0507
Add check widening status for IL operator.
Manuele Conti <conti.ma@alice.it>
parents:
473
diff
changeset
|
291 |
return widen_table[k].result; |
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:
diff
changeset
|
292 |
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:
diff
changeset
|
293 |
} |
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:
diff
changeset
|
294 |
|
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
295 |
|
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
296 |
/* add a data type to a candidate data type list, while guaranteeing no duplicate entries! */ |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
297 |
/* Returns true if it really did add the datatype to the list, or false if it was already present in the list! */ |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
298 |
bool fill_candidate_datatypes_c::add_datatype_to_candidate_list(symbol_c *symbol, symbol_c *datatype) { |
478
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
299 |
/* If it is an invalid data type, do not insert! |
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
300 |
* NOTE: it reduces overall code size to do this test here, instead of doing every time before calling the add_datatype_to_candidate_list() function. |
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
301 |
*/ |
676
ca4f17211251
Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
666
diff
changeset
|
302 |
if (!get_datatype_info_c::is_type_valid(datatype)) /* checks for NULL and invalid_type_name_c */ |
478
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
303 |
return false; |
b13feab3b918
Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents:
476
diff
changeset
|
304 |
|
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
305 |
if (search_in_candidate_datatype_list(datatype, symbol->candidate_datatypes) >= 0) |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
306 |
/* already in the list, Just return! */ |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
307 |
return false; |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
308 |
|
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
309 |
/* not yet in the candidate data type list, so we insert it now! */ |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
310 |
symbol->candidate_datatypes.push_back(datatype); |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
311 |
return true; |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
312 |
} |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
313 |
|
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
314 |
|
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
315 |
bool fill_candidate_datatypes_c::add_2datatypes_to_candidate_list(symbol_c *symbol, symbol_c *datatype1, symbol_c *datatype2) { |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
316 |
add_datatype_to_candidate_list(symbol, datatype1); |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
317 |
add_datatype_to_candidate_list(symbol, datatype2); |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
318 |
return true; |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
319 |
} |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
320 |
|
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
321 |
|
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
322 |
|
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
323 |
void fill_candidate_datatypes_c::remove_incompatible_datatypes(symbol_c *symbol) { |
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
324 |
#ifdef __REMOVE__ |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
325 |
#error __REMOVE__ macro already exists. Choose another name! |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
326 |
#endif |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
327 |
#define __REMOVE__(datatype)\ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
328 |
remove_from_candidate_datatype_list(&get_datatype_info_c::datatype, symbol->candidate_datatypes);\ |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
329 |
remove_from_candidate_datatype_list(&get_datatype_info_c::safe##datatype, symbol->candidate_datatypes); |
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
330 |
|
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
331 |
{/* Remove unsigned data types */ |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
332 |
uint64_t value = 0; |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
333 |
if (VALID_CVALUE( uint64, symbol)) value = GET_CVALUE(uint64, symbol); |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
334 |
if (IS_OVERFLOW ( uint64, symbol)) value = (uint64_t)UINT32_MAX + (uint64_t)1; |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
335 |
|
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
336 |
if (value > 1 ) {__REMOVE__(bool_type_name);} |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
337 |
if (value > UINT8_MAX ) {__REMOVE__(usint_type_name); __REMOVE__( byte_type_name);} |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
338 |
if (value > UINT16_MAX ) {__REMOVE__( uint_type_name); __REMOVE__( word_type_name);} |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
339 |
if (value > UINT32_MAX ) {__REMOVE__(udint_type_name); __REMOVE__(dword_type_name);} |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
340 |
if (IS_OVERFLOW( uint64, symbol)) {__REMOVE__(ulint_type_name); __REMOVE__(lword_type_name);} |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
341 |
} |
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
342 |
|
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
343 |
{/* Remove signed data types */ |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
344 |
int64_t value = 0; |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
345 |
if (VALID_CVALUE( int64, symbol)) value = GET_CVALUE(int64, symbol); |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
346 |
if (IS_OVERFLOW ( int64, symbol)) value = (int64_t)INT32_MAX + (int64_t)1; |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
347 |
|
609
9ab033d2bb55
signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents:
607
diff
changeset
|
348 |
if ((value < INT8_MIN) || (value > INT8_MAX)) {__REMOVE__(sint_type_name);} |
9ab033d2bb55
signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents:
607
diff
changeset
|
349 |
if ((value < INT16_MIN) || (value > INT16_MAX)) {__REMOVE__( int_type_name);} |
9ab033d2bb55
signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents:
607
diff
changeset
|
350 |
if ((value < INT32_MIN) || (value > INT32_MAX)) {__REMOVE__(dint_type_name);} |
9ab033d2bb55
signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents:
607
diff
changeset
|
351 |
if (IS_OVERFLOW( int64, symbol)) {__REMOVE__(lint_type_name);} |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
352 |
} |
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
353 |
|
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
354 |
{/* Remove floating point data types */ |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
355 |
real64_t value = 0; |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
356 |
if (VALID_CVALUE( real64, symbol)) value = GET_CVALUE(real64, symbol); |
610
50b708dff319
fix bug: remove REAL from candidate datatypes when real constant has overflowed.
Mario de Sousa <msousa@fe.up.pt>
parents:
609
diff
changeset
|
357 |
if (IS_OVERFLOW ( real64, symbol)) value = (real64_t)REAL32_MAX + (real64_t)1; |
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
358 |
if (value > REAL32_MAX ) {__REMOVE__( real_type_name);} |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
359 |
if (value < -REAL32_MAX ) {__REMOVE__( real_type_name);} |
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
360 |
if (IS_OVERFLOW( real64, symbol)) {__REMOVE__(lreal_type_name);} |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
361 |
} |
607
be9ba3531afb
cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents:
605
diff
changeset
|
362 |
#undef __REMOVE__ |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
363 |
} |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
364 |
|
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
365 |
|
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
366 |
/* returns true if compatible function/FB invocation, otherwise returns false */ |
424
43d73e28eca8
Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents:
422
diff
changeset
|
367 |
/* Assumes that the candidate_datatype lists of all the parameters being passed haved already been filled in */ |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
368 |
/* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
369 |
* All parameters being passed to the called function MUST be in the parameter list to which f_call points to! |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
370 |
* This means that, for non formal function calls in IL, de current (default value) must be artificially added to the |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
371 |
* beginning of the parameter list BEFORE calling handle_function_call(). |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
372 |
*/ |
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
373 |
bool fill_candidate_datatypes_c::match_nonformal_call(symbol_c *f_call, symbol_c *f_decl) { |
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
374 |
symbol_c *call_param_value, *param_datatype; |
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:
diff
changeset
|
375 |
identifier_c *param_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:
diff
changeset
|
376 |
function_param_iterator_c fp_iterator(f_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:
diff
changeset
|
377 |
function_call_param_iterator_c fcp_iterator(f_call); |
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:
diff
changeset
|
378 |
int extensible_parameter_highest_index = -1; |
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:
diff
changeset
|
379 |
unsigned int i; |
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:
diff
changeset
|
380 |
|
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:
diff
changeset
|
381 |
/* Iterating through the non-formal parameters of the function call */ |
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:
diff
changeset
|
382 |
while((call_param_value = fcp_iterator.next_nf()) != 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:
diff
changeset
|
383 |
/* Iterate to the next parameter of the function being called. |
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:
diff
changeset
|
384 |
* Get the name of that parameter, and ignore if EN or ENO. |
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:
diff
changeset
|
385 |
*/ |
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:
diff
changeset
|
386 |
do { |
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:
diff
changeset
|
387 |
param_name = fp_iterator.next(); |
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:
diff
changeset
|
388 |
/* If there is no other parameter declared, then we are passing too many parameters... */ |
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
389 |
if(param_name == NULL) return false; |
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:
diff
changeset
|
390 |
} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
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:
diff
changeset
|
391 |
|
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:
diff
changeset
|
392 |
/* Get the parameter type */ |
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
393 |
param_datatype = base_type(fp_iterator.param_type()); |
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
394 |
|
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
395 |
/* check whether one of the candidate_data_types of the value being passed is the same as the param_type */ |
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
396 |
if (search_in_candidate_datatype_list(param_datatype, call_param_value->candidate_datatypes) < 0) |
442 | 397 |
return false; /* return false if param_type not in the list! */ |
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
398 |
} |
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
399 |
/* call is compatible! */ |
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
400 |
return true; |
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
401 |
} |
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
402 |
|
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
403 |
|
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
404 |
|
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
405 |
/* returns true if compatible function/FB invocation, otherwise returns false */ |
424
43d73e28eca8
Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents:
422
diff
changeset
|
406 |
/* Assumes that the candidate_datatype lists of all the parameters being passed haved already been filled in */ |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
407 |
bool fill_candidate_datatypes_c::match_formal_call(symbol_c *f_call, symbol_c *f_decl, symbol_c **first_param_datatype) { |
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
408 |
symbol_c *call_param_value, *call_param_name, *param_datatype; |
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:
diff
changeset
|
409 |
symbol_c *verify_duplicate_param; |
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:
diff
changeset
|
410 |
identifier_c *param_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:
diff
changeset
|
411 |
function_param_iterator_c fp_iterator(f_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:
diff
changeset
|
412 |
function_call_param_iterator_c fcp_iterator(f_call); |
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:
diff
changeset
|
413 |
int extensible_parameter_highest_index = -1; |
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:
diff
changeset
|
414 |
identifier_c *extensible_parameter_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:
diff
changeset
|
415 |
unsigned int i; |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
416 |
bool is_first_param = true; |
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:
diff
changeset
|
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:
diff
changeset
|
418 |
/* Iterating through the formal parameters of the function call */ |
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:
diff
changeset
|
419 |
while((call_param_name = fcp_iterator.next_f()) != 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:
diff
changeset
|
420 |
/* Obtaining the value being passed in the function call */ |
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:
diff
changeset
|
421 |
call_param_value = fcp_iterator.get_current_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:
diff
changeset
|
422 |
/* the following should never occur. If it does, then we have a bug in our code... */ |
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:
diff
changeset
|
423 |
if (NULL == call_param_value) 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:
diff
changeset
|
424 |
|
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
425 |
/* Obtaining the assignment direction: := (assign_in) or => (assign_out) */ |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
426 |
function_call_param_iterator_c::assign_direction_t call_param_dir = fcp_iterator.get_assign_direction(); |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
427 |
|
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:
diff
changeset
|
428 |
/* Checking if there are duplicated parameter values */ |
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:
diff
changeset
|
429 |
verify_duplicate_param = fcp_iterator.search_f(call_param_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:
diff
changeset
|
430 |
if(verify_duplicate_param != call_param_value) |
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
431 |
return false; |
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:
diff
changeset
|
432 |
|
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:
diff
changeset
|
433 |
/* Obtaining the type of the value being passed in the function call */ |
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:
diff
changeset
|
434 |
std::vector <symbol_c *>&call_param_types = call_param_value->candidate_datatypes; |
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:
diff
changeset
|
435 |
|
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:
diff
changeset
|
436 |
/* Find the corresponding parameter in function 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:
diff
changeset
|
437 |
param_name = fp_iterator.search(call_param_name); |
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
438 |
if(param_name == NULL) return false; |
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
439 |
/* Get the parameter data type */ |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
440 |
param_datatype = base_type(fp_iterator.param_type()); |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
441 |
/* Get the parameter direction: IN, OUT, IN_OUT */ |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
442 |
function_param_iterator_c::param_direction_t param_dir = fp_iterator.param_direction(); |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
443 |
|
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
444 |
/* check whether direction (IN, OUT, IN_OUT) and assignment types (:= , =>) are compatible !!! */ |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
445 |
if (function_call_param_iterator_c::assign_in == call_param_dir) { |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
446 |
if ((function_param_iterator_c::direction_in != param_dir) && |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
447 |
(function_param_iterator_c::direction_inout != param_dir)) |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
448 |
return false; |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
449 |
} else if (function_call_param_iterator_c::assign_out == call_param_dir) { |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
450 |
if ((function_param_iterator_c::direction_out != param_dir)) |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
451 |
return false; |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
452 |
} else ERROR; |
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
453 |
|
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
454 |
/* check whether one of the candidate_data_types of the value being passed is the same as the param_type */ |
449
3c6225521059
Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
455 |
if (search_in_candidate_datatype_list(param_datatype, call_param_types) < 0) |
442 | 456 |
return false; /* return false if param_type not in the list! */ |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
457 |
|
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
458 |
/* If this is the first parameter, then copy the datatype to *first_param_datatype */ |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
459 |
if (is_first_param) |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
460 |
if (NULL != first_param_datatype) |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
461 |
*first_param_datatype = param_datatype; |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
462 |
is_first_param = false; |
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
463 |
} |
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
464 |
/* call is compatible! */ |
420
866eb35e4e14
Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents:
419
diff
changeset
|
465 |
return true; |
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:
diff
changeset
|
466 |
} |
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:
diff
changeset
|
467 |
|
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
468 |
|
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
469 |
|
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
470 |
|
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
471 |
/* Handle a generic function call! |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
472 |
* Assumes that the parameter_list containing the values being passed in this function invocation |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
473 |
* has already had all the candidate_datatype lists filled in! |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
474 |
* |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
475 |
* All parameters being passed to the called function MUST be in the parameter list to which f_call points to! |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
476 |
* This means that, for non formal function calls in IL, de current (default value) must be artificially added to the |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
477 |
* beginning of the parameter list BEFORE calling handle_function_call(). |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
478 |
*/ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
479 |
/* |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
480 |
typedef struct { |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
481 |
symbol_c *function_name, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
482 |
symbol_c *nonformal_operand_list, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
483 |
symbol_c * formal_operand_list, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
484 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
485 |
std::vector <symbol_c *> &candidate_functions, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
486 |
symbol_c &*called_function_declaration, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
487 |
int &extensible_param_count |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
488 |
} generic_function_call_t; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
489 |
*/ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
490 |
/* |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
491 |
void narrow_candidate_datatypes_c::narrow_function_invocation(symbol_c *fcall, generic_function_call_t fcall_data) { |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
492 |
void *fill_candidate_datatypes_c::handle_function_call(symbol_c *f_call, symbol_c *function_name, invocation_type_t invocation_type, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
493 |
std::vector <symbol_c *> *candidate_datatypes, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
494 |
std::vector <symbol_c *> *candidate_functions) { |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
495 |
*/ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
496 |
void fill_candidate_datatypes_c::handle_function_call(symbol_c *fcall, generic_function_call_t fcall_data) { |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
497 |
function_declaration_c *f_decl; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
498 |
list_c *parameter_list; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
499 |
list_c *parameter_candidate_datatypes; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
500 |
symbol_c *returned_parameter_type; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
501 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
502 |
if (debug) std::cout << "function()\n"; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
503 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
504 |
function_symtable_t::iterator lower = function_symtable.lower_bound(fcall_data.function_name); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
505 |
function_symtable_t::iterator upper = function_symtable.upper_bound(fcall_data.function_name); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
506 |
/* If the name of the function being called is not found in the function symbol table, then this is an invalid call */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
507 |
/* Since the lexical parser already checks for this, then if this occurs then we have an internal compiler error. */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
508 |
if (lower == function_symtable.end()) ERROR; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
509 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
510 |
/* Look for all compatible function declarations, and add their return datatypes |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
511 |
* to the candidate_datatype list of this function invocation. |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
512 |
* |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
513 |
* If only one function exists, we add its return datatype to the candidate_datatype list, |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
514 |
* even if the parameters passed to it are invalid. |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
515 |
* This guarantees that the remainder of the expression in which the function call is inserted |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
516 |
* is treated as if the function call returns correctly, and therefore does not generate |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
517 |
* spurious error messages. |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
518 |
* Even if the parameters to the function call are invalid, doing this is still safe, as the |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
519 |
* expressions inside the function call will themselves have erros and will guarantee that |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
520 |
* compilation is aborted in stage3 (in print_datatypes_error_c). |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
521 |
*/ |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
522 |
if (function_symtable.count(fcall_data.function_name) == 1) { |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
523 |
f_decl = function_symtable.get_value(lower); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
524 |
returned_parameter_type = base_type(f_decl->type_name); |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
525 |
if (add_datatype_to_candidate_list(fcall, returned_parameter_type)) |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
526 |
/* we only add it to the function declaration list if this entry was not already present in the candidate datatype list! */ |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
527 |
fcall_data.candidate_functions.push_back(f_decl); |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
528 |
|
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
529 |
} |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
530 |
for(; lower != upper; lower++) { |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
531 |
bool compatible = false; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
532 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
533 |
f_decl = function_symtable.get_value(lower); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
534 |
/* Check if function declaration in symbol_table is compatible with parameters */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
535 |
if (NULL != fcall_data.nonformal_operand_list) compatible=match_nonformal_call(fcall, f_decl); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
536 |
if (NULL != fcall_data. formal_operand_list) compatible= match_formal_call(fcall, f_decl); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
537 |
if (compatible) { |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
538 |
/* Add the data type returned by the called functions. |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
539 |
* However, only do this if this data type is not already present in the candidate_datatypes list_c |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
540 |
*/ |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
541 |
returned_parameter_type = base_type(f_decl->type_name); |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
542 |
if (add_datatype_to_candidate_list(fcall, returned_parameter_type)) |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
543 |
/* we only add it to the function declaration list if this entry was not already present in the candidate datatype list! */ |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
544 |
fcall_data.candidate_functions.push_back(f_decl); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
545 |
} |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
546 |
} |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
547 |
if (debug) std::cout << "end_function() [" << fcall->candidate_datatypes.size() << "] result.\n"; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
548 |
return; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
549 |
} |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
550 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
551 |
|
447
aad0f3e5df33
Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents:
445
diff
changeset
|
552 |
/* handle implicit FB call in IL. |
448
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
553 |
* e.g. CLK ton_var |
447
aad0f3e5df33
Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents:
445
diff
changeset
|
554 |
* CU counter_var |
aad0f3e5df33
Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents:
445
diff
changeset
|
555 |
*/ |
489
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
556 |
void *fill_candidate_datatypes_c::handle_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) { |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
557 |
symbol_c *fb_decl = (NULL == il_operand)? NULL : search_var_instance_decl->get_basetype_decl(il_operand); |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
558 |
if (! get_datatype_info_c::is_function_block(fb_decl)) fb_decl = NULL; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
559 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
560 |
/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
561 |
/* However, when calling using the 'S' and 'R' operators, this error is not caught by stage 2, as these operators have two possible semantics */ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
562 |
// if (NULL == fb_type_id) ERROR; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
563 |
|
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
564 |
/* The narrow_candidate_datatypes_c does not rely on this called_fb_declaration pointer being == NULL to conclude that |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
565 |
* we have a datatype incompatibility error, so we set it to fb_decl to allow the print_datatype_error_c to print out |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
566 |
* more informative error messages! |
450
eb1b28acec2e
Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
449
diff
changeset
|
567 |
*/ |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
568 |
called_fb_declaration = fb_decl; |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
569 |
|
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
570 |
/* This implicit FB call does not change the value stored in the current/default IL variable */ |
456 | 571 |
/* It does, however, require that the datatype be compatible with the input parameter of the FB being called. |
572 |
* If we were to follow the filling & narrowing algorithm correctly (implemented in fill_candidate_datatypes_c |
|
573 |
* & narrow_candidate_datatypes_c respectively), we should be restricting the candidate_datatpes to the datatypes |
|
574 |
* that are compatible to the FB call. |
|
575 |
* However, doing the above will often result in some very confusing error messages for the user, especially in the case |
|
576 |
* in which the FB call is wrong, so the resulting cadidate datatypes is an empty list. In this case, the user would see |
|
577 |
* many error messages related to the IL instructions that follow the FB call, even though those IL instructions may be perfectly |
|
578 |
* correct. |
|
579 |
* For now, we will simply let the narrow_candidate_datatypes_c verify if the datatypes are compatible (something that should be done |
|
580 |
* here). |
|
581 |
*/ |
|
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
582 |
if (NULL != prev_il_instruction) |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
583 |
il_instruction->candidate_datatypes = prev_il_instruction->candidate_datatypes; |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
584 |
|
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
585 |
if (debug) std::cout << "handle_implicit_il_fb_call() [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << il_instruction->candidate_datatypes.size() << " result.\n"; |
489
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
586 |
return NULL; |
447
aad0f3e5df33
Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents:
445
diff
changeset
|
587 |
} |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
588 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
589 |
|
479 | 590 |
|
591 |
||
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
592 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
593 |
/* handle the S and R IL operators... */ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
594 |
/* operator_str should be set to either "S" or "R" */ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
595 |
void *fill_candidate_datatypes_c::handle_S_and_R_operator(symbol_c *symbol, const char *operator_str, symbol_c *&called_fb_declaration) { |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
596 |
/* NOTE: this operator has two possible semantic meanings: |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
597 |
* - Set/Reset the BOOL operand variable to true |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
598 |
* - call the FB specified by the operand. |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
599 |
* Which of the two semantics will have to be determined by the datatype of the operand! |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
600 |
*/ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
601 |
symbol_c *prev_instruction_type, *operand_type; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
602 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
603 |
if (NULL == prev_il_instruction) return NULL; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
604 |
if (NULL == il_operand) return NULL; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
605 |
|
837 | 606 |
/* Try the Set/Reset semantics */ |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
607 |
for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
608 |
for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
609 |
prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
610 |
operand_type = il_operand->candidate_datatypes[j]; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
611 |
/* IEC61131-3, Table 52, Note (e) states that the datatype of the operand must be BOOL! |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
612 |
* IEC61131-3, Table 52, line 3 states that this operator should "Set operand to 1 if current result is Boolean 1" |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
613 |
* which implies that the prev_instruction_type MUST also be BOOL compatible. |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
614 |
*/ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
615 |
if (get_datatype_info_c::is_BOOL_compatible(prev_instruction_type) && get_datatype_info_c::is_BOOL_compatible(operand_type)) |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
616 |
add_datatype_to_candidate_list(symbol, prev_instruction_type); |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
617 |
} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
618 |
} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
619 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
620 |
/* if the appropriate semantics is not a Set/Reset of a boolean variable, the we try for the FB invocation! */ |
837 | 621 |
if (symbol->candidate_datatypes.size() == 0) { |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
622 |
handle_implicit_il_fb_call(symbol, operator_str, called_fb_declaration); |
837 | 623 |
/* If it is also not a valid FB call, make sure the candidate_datatypes is empty (handle_implicit_il_fb_call may leave it non-empty!!) */ |
624 |
/* From here on out, all later code will consider the symbol->called_fb_declaration being NULL as an indication that this operator must use the |
|
625 |
* Set/Reset semantics, so we must also guarantee that the remainder of the state of this symbol is compatible with that assumption! |
|
626 |
*/ |
|
627 |
if (NULL == called_fb_declaration) |
|
628 |
symbol->candidate_datatypes.clear(); |
|
629 |
} |
|
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
630 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
631 |
if (debug) std::cout << operator_str << " [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
632 |
return NULL; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
633 |
} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
634 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
635 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
636 |
|
479 | 637 |
/* handle a binary IL operator, like ADD, SUB, etc... */ |
638 |
void *fill_candidate_datatypes_c::handle_binary_operator(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) { |
|
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
639 |
if (NULL == l_expr) return NULL; /* if no prev_il_instruction */ |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
640 |
if (NULL == r_expr) return NULL; /* if no IL operand!! */ |
479 | 641 |
|
642 |
for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++) |
|
643 |
for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) |
|
644 |
/* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ |
|
645 |
add_datatype_to_candidate_list(symbol, widening_conversion(l_expr->candidate_datatypes[i], r_expr->candidate_datatypes[j], widen_table)); |
|
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
646 |
remove_incompatible_datatypes(symbol); |
479 | 647 |
if (debug) std::cout << "[" << l_expr->candidate_datatypes.size() << "," << r_expr->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
648 |
return NULL; |
|
649 |
} |
|
650 |
||
651 |
||
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
652 |
|
479 | 653 |
/* handle a binary ST expression, like '+', '-', etc... */ |
654 |
void *fill_candidate_datatypes_c::handle_binary_expression(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) { |
|
655 |
l_expr->accept(*this); |
|
656 |
r_expr->accept(*this); |
|
657 |
return handle_binary_operator(widen_table, symbol, l_expr, r_expr); |
|
658 |
} |
|
659 |
||
660 |
||
661 |
||
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
662 |
/* handle the two equality comparison operations, i.e. = (euqal) and != (not equal) */ |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
663 |
/* This function is special, as it will also allow enumeration data types to be compared, with the result being a BOOL data type! |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
664 |
* It will also allow to REF_TO datatypes to be compared. |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
665 |
* These possibilities are not expressed in the 'widening' tables, so we need to hard code it here |
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
666 |
*/ |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
667 |
void *fill_candidate_datatypes_c::handle_equality_comparison(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) { |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
668 |
handle_binary_expression(widen_table, symbol, l_expr, r_expr); |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
669 |
for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++) |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
670 |
for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) { |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
671 |
if ( (get_datatype_info_c::is_enumerated(l_expr->candidate_datatypes[i]) && (l_expr->candidate_datatypes[i] == r_expr->candidate_datatypes[j])) |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
672 |
|| (get_datatype_info_c::is_ref_to (l_expr->candidate_datatypes[i]) && get_datatype_info_c::is_type_equal(l_expr->candidate_datatypes[i], r_expr->candidate_datatypes[j]))) |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
673 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name); |
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
674 |
} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
675 |
return NULL; |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
676 |
} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
677 |
|
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
678 |
|
479 | 679 |
|
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:
diff
changeset
|
680 |
/* a helper function... */ |
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:
diff
changeset
|
681 |
symbol_c *fill_candidate_datatypes_c::base_type(symbol_c *symbol) { |
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
717
diff
changeset
|
682 |
/* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used in the code. */ |
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:
diff
changeset
|
683 |
if (symbol == NULL) return NULL; |
718
a9f8cc778444
Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents:
717
diff
changeset
|
684 |
return search_base_type_c::get_basetype_decl(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:
diff
changeset
|
685 |
} |
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:
diff
changeset
|
686 |
|
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
687 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
688 |
/***************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
689 |
/* B 0 - Programming Model */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
690 |
/***************************/ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
691 |
/* main entry function! */ |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
692 |
void *fill_candidate_datatypes_c::visit(library_c *symbol) { |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
693 |
symbol->accept(populate_globalenumvalue_symtable); |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
694 |
/* Now let the base class iterator_visitor_c iterate through all the library elements */ |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
695 |
return iterator_visitor_c::visit(symbol); |
719
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
696 |
} |
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
697 |
|
19595fce59f0
Move the enumerated_value_symtable to fill_candidate_datatypes_c, since it is only used there!
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
698 |
|
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:
diff
changeset
|
699 |
/*********************/ |
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:
diff
changeset
|
700 |
/* B 1.2 - Constants */ |
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:
diff
changeset
|
701 |
/*********************/ |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
702 |
/*********************************/ |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
703 |
/* B 1.2.XX - Reference Literals */ |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
704 |
/*********************************/ |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
705 |
/* defined in IEC 61131-3 v3 - Basically the 'NULL' keyword! */ |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
706 |
void *fill_candidate_datatypes_c::visit(ref_value_null_literal_c *symbol) { |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
707 |
/* 'NULL' does not have any specific datatype. It is compatible with any reference, i.e. REF_TO <anything> |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
708 |
* The fill_candidate_datatypes / narrow_candidate_datatypes algorithm would require us to add |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
709 |
* as possible datatypes all the REF_TO <datatype>. To do this we would need to go through the list of all |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
710 |
* user declared datatypes, as well as all the elementary datatypes. This is easily done by using the |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
711 |
* type_symtable symbol table declared in absyntax_utils.hh. |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
712 |
* |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
713 |
* for(int i=0; i<type_symtable.n; i++) add_datatype_to_candidate_list(symbol, new ref_spec_c(type_symtable[i])); |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
714 |
* add_datatype_to_candidate_list(symbol, new ref_spec_c( ... SINT ...)); |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
715 |
* add_datatype_to_candidate_list(symbol, new ref_spec_c( ... INT ...)); |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
716 |
* add_datatype_to_candidate_list(symbol, new ref_spec_c( ... LINT ...)); |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
717 |
* ... |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
718 |
* |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
719 |
* However, doing this for all NULL constants that may show up is probably a little too crazy, just for |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
720 |
* the 'pleasure' of following the standard fill/narrow algorithm. |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
721 |
* |
921
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
722 |
* I have therefore opted to handle this as a special case: |
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
723 |
* We use the ref_spec_c, pointing to a generic_type_any_c, as a pointer to ANY (basically, a void *) |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
724 |
*/ |
921
d228aaa4d616
Introduce absyntax class for keyword ANY, and use REF_TO(ANY) as datatype of NULL literal.
mjsousa
parents:
919
diff
changeset
|
725 |
add_datatype_to_candidate_list(symbol, new ref_spec_c(new generic_type_any_c())); |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
726 |
return NULL; |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
727 |
} |
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
728 |
|
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
729 |
|
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:
diff
changeset
|
730 |
/******************************/ |
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:
diff
changeset
|
731 |
/* B 1.2.1 - Numeric Literals */ |
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:
diff
changeset
|
732 |
/******************************/ |
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
733 |
#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol) |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
734 |
|
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
735 |
void *fill_candidate_datatypes_c::handle_any_integer(symbol_c *symbol) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
736 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name, &get_datatype_info_c::safebool_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
737 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::byte_type_name, &get_datatype_info_c::safebyte_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
738 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::word_type_name, &get_datatype_info_c::safeword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
739 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::dword_type_name, &get_datatype_info_c::safedword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
740 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::lword_type_name, &get_datatype_info_c::safelword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
741 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::sint_type_name, &get_datatype_info_c::safesint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
742 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::int_type_name, &get_datatype_info_c::safeint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
743 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::dint_type_name, &get_datatype_info_c::safedint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
744 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::lint_type_name, &get_datatype_info_c::safelint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
745 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::usint_type_name, &get_datatype_info_c::safeusint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
746 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::uint_type_name, &get_datatype_info_c::safeuint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
747 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::udint_type_name, &get_datatype_info_c::safeudint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
748 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::ulint_type_name, &get_datatype_info_c::safeulint_type_name); |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
749 |
remove_incompatible_datatypes(symbol); |
479 | 750 |
if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl; |
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
751 |
return NULL; |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
752 |
} |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
753 |
|
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
754 |
|
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
755 |
|
488 | 756 |
void *fill_candidate_datatypes_c::handle_any_real(symbol_c *symbol) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
757 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::real_type_name, &get_datatype_info_c::safereal_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
758 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::lreal_type_name, &get_datatype_info_c::safelreal_type_name); |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
759 |
remove_incompatible_datatypes(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:
diff
changeset
|
760 |
if (debug) std::cout << "ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl; |
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:
diff
changeset
|
761 |
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:
diff
changeset
|
762 |
} |
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:
diff
changeset
|
763 |
|
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
764 |
|
488 | 765 |
|
766 |
void *fill_candidate_datatypes_c::handle_any_literal(symbol_c *symbol, symbol_c *symbol_value, symbol_c *symbol_type) { |
|
767 |
symbol_value->accept(*this); |
|
768 |
if (search_in_candidate_datatype_list(symbol_type, symbol_value->candidate_datatypes) >= 0) |
|
769 |
add_datatype_to_candidate_list(symbol, symbol_type); |
|
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
770 |
remove_incompatible_datatypes(symbol); |
643
1cc0e1ca2aad
Fix constant folding: now handles INT_MIN and neg_integer_c correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
612
diff
changeset
|
771 |
if (debug) std::cout << "ANY_LITERAL [" << symbol->candidate_datatypes.size() << "]\n"; |
488 | 772 |
return NULL; |
773 |
} |
|
774 |
||
775 |
||
776 |
||
777 |
void *fill_candidate_datatypes_c::visit( real_c *symbol) {return handle_any_real(symbol);} |
|
778 |
void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {return handle_any_real(symbol);} |
|
779 |
||
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:
diff
changeset
|
780 |
|
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
781 |
|
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:
diff
changeset
|
782 |
void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) { |
650 | 783 |
/* Please read the comment in neg_expression_c method, as it also applies here */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
784 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::int_type_name, &get_datatype_info_c::safeint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
785 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::sint_type_name, &get_datatype_info_c::safesint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
786 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::dint_type_name, &get_datatype_info_c::safedint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
787 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::lint_type_name, &get_datatype_info_c::safelint_type_name); |
603
a45a62dd6df9
Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents:
558
diff
changeset
|
788 |
remove_incompatible_datatypes(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:
diff
changeset
|
789 |
if (debug) std::cout << "neg ANY_INT [" << symbol->candidate_datatypes.size() << "]" << std::endl; |
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:
diff
changeset
|
790 |
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:
diff
changeset
|
791 |
} |
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:
diff
changeset
|
792 |
|
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
793 |
|
488 | 794 |
|
479 | 795 |
void *fill_candidate_datatypes_c::visit(integer_c *symbol) {return handle_any_integer(symbol);} |
796 |
void *fill_candidate_datatypes_c::visit(binary_integer_c *symbol) {return handle_any_integer(symbol);} |
|
797 |
void *fill_candidate_datatypes_c::visit(octal_integer_c *symbol) {return handle_any_integer(symbol);} |
|
798 |
void *fill_candidate_datatypes_c::visit(hex_integer_c *symbol) {return handle_any_integer(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:
diff
changeset
|
799 |
|
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
800 |
|
488 | 801 |
|
427
eb9bc99944d9
Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents:
426
diff
changeset
|
802 |
// SYM_REF2(integer_literal_c, type, value) |
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
803 |
/* |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
804 |
* integer_literal: |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
805 |
* integer_type_name '#' signed_integer |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
806 |
* | integer_type_name '#' binary_integer |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
807 |
* | integer_type_name '#' octal_integer |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
808 |
* | integer_type_name '#' hex_integer |
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
809 |
*/ |
488 | 810 |
void *fill_candidate_datatypes_c::visit( integer_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);} |
811 |
void *fill_candidate_datatypes_c::visit( real_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);} |
|
812 |
void *fill_candidate_datatypes_c::visit(bit_string_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);} |
|
813 |
||
814 |
void *fill_candidate_datatypes_c::visit( boolean_literal_c *symbol) { |
|
815 |
if (NULL != symbol->type) return handle_any_literal(symbol, symbol->value, symbol->type); |
|
816 |
||
427
eb9bc99944d9
Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents:
426
diff
changeset
|
817 |
symbol->value->accept(*this); |
488 | 818 |
symbol->candidate_datatypes = symbol->value->candidate_datatypes; |
819 |
return NULL; |
|
820 |
} |
|
821 |
||
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:
diff
changeset
|
822 |
|
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:
diff
changeset
|
823 |
void *fill_candidate_datatypes_c::visit(boolean_true_c *symbol) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
824 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name, &get_datatype_info_c::safebool_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:
diff
changeset
|
825 |
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:
diff
changeset
|
826 |
} |
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:
diff
changeset
|
827 |
|
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:
diff
changeset
|
828 |
void *fill_candidate_datatypes_c::visit(boolean_false_c *symbol) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
829 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name, &get_datatype_info_c::safebool_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:
diff
changeset
|
830 |
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:
diff
changeset
|
831 |
} |
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:
diff
changeset
|
832 |
|
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:
diff
changeset
|
833 |
/*******************************/ |
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:
diff
changeset
|
834 |
/* B.1.2.2 Character Strings */ |
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:
diff
changeset
|
835 |
/*******************************/ |
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:
diff
changeset
|
836 |
void *fill_candidate_datatypes_c::visit(double_byte_character_string_c *symbol) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
837 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::wstring_type_name, &get_datatype_info_c::safewstring_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:
diff
changeset
|
838 |
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:
diff
changeset
|
839 |
} |
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:
diff
changeset
|
840 |
|
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:
diff
changeset
|
841 |
void *fill_candidate_datatypes_c::visit(single_byte_character_string_c *symbol) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
842 |
add_2datatypes_to_candidate_list(symbol, &get_datatype_info_c::string_type_name, &get_datatype_info_c::safestring_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:
diff
changeset
|
843 |
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:
diff
changeset
|
844 |
} |
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:
diff
changeset
|
845 |
|
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:
diff
changeset
|
846 |
/***************************/ |
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:
diff
changeset
|
847 |
/* B 1.2.3 - Time Literals */ |
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:
diff
changeset
|
848 |
/***************************/ |
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:
diff
changeset
|
849 |
/************************/ |
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:
diff
changeset
|
850 |
/* B 1.2.3.1 - Duration */ |
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:
diff
changeset
|
851 |
/************************/ |
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:
diff
changeset
|
852 |
void *fill_candidate_datatypes_c::visit(duration_c *symbol) { |
472
d26759a2274a
Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents:
470
diff
changeset
|
853 |
add_datatype_to_candidate_list(symbol, symbol->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:
diff
changeset
|
854 |
if (debug) std::cout << "TIME_LITERAL [" << symbol->candidate_datatypes.size() << "]\n"; |
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:
diff
changeset
|
855 |
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:
diff
changeset
|
856 |
} |
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:
diff
changeset
|
857 |
|
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:
diff
changeset
|
858 |
/************************************/ |
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:
diff
changeset
|
859 |
/* B 1.2.3.2 - Time of day and Date */ |
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:
diff
changeset
|
860 |
/************************************/ |
479 | 861 |
void *fill_candidate_datatypes_c::visit(time_of_day_c *symbol) {add_datatype_to_candidate_list(symbol, symbol->type_name); return NULL;} |
862 |
void *fill_candidate_datatypes_c::visit(date_c *symbol) {add_datatype_to_candidate_list(symbol, symbol->type_name); return NULL;} |
|
863 |
void *fill_candidate_datatypes_c::visit(date_and_time_c *symbol) {add_datatype_to_candidate_list(symbol, symbol->type_name); return 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:
diff
changeset
|
864 |
|
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:
diff
changeset
|
865 |
/**********************/ |
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:
diff
changeset
|
866 |
/* B 1.3 - Data types */ |
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:
diff
changeset
|
867 |
/**********************/ |
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:
diff
changeset
|
868 |
/********************************/ |
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:
diff
changeset
|
869 |
/* B 1.3.3 - Derived data types */ |
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:
diff
changeset
|
870 |
/********************************/ |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
871 |
|
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
872 |
void *fill_candidate_datatypes_c::fill_type_decl(symbol_c *symbol, symbol_c *type_name, symbol_c *spec_init) { |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
873 |
/* NOTE: Unlike the rest of the 'fill' algorithm that works using a bottom->up approach, when handling |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
874 |
* data type declarations (section B.1.3.3 - Derived data types) we use a top->bottom approach. |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
875 |
* This is intentional, and not a bug! Explanation follows... |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
876 |
* Here we are essentially determining the base type of each defined data type. In many cases (especially structs, |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
877 |
* enumerations, arrays, etc...), the datatype is its own base type. However, the derived datatype is stored in |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
878 |
* multiple symbol_c classes (e.g. an enumeration uses enumerated_type_declaration_c, enumerated_spec_init_c, |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
879 |
* enumerated_value_list_c, enumerated_value_c, ...). Several of these could be chosen to work as the canonical base datatype |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
880 |
* symbol. Which symbol is used is really up to the search_base_type_c, and not this fill_candidate_datatypes_c. |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
881 |
* Here we must right the code to handle whatever the search_base_type_c chooses to use as the canonical symbol to represent |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
882 |
* the base datatype. |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
883 |
* Since the base datatype may be (and sometimes/often/always(?) actually is) the top level symbol_c (an enumerated_type_declaration_c |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
884 |
* in the case of the enumerations), it only makes sense to ask search_base_type_c for a basetype when we pass it the |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
885 |
* symbol in the highest level of the type declaration (the enumerated_type_declaration_c in the case of the enumerations). |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
886 |
* For this reason, we determine the basetype at the top level, and send that info down to the bottom level of the data type |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
887 |
* declaration. In summary, a top->down algorithm! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
888 |
*/ |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
889 |
add_datatype_to_candidate_list(symbol, base_type(symbol)); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
890 |
type_name->candidate_datatypes = symbol->candidate_datatypes; // use top->down algorithm!! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
891 |
spec_init->candidate_datatypes = symbol->candidate_datatypes; // use top->down algorithm!! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
892 |
spec_init->accept(*this); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
893 |
return NULL; |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
894 |
} |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
895 |
|
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
896 |
|
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
897 |
void *fill_candidate_datatypes_c::fill_spec_init(symbol_c *symbol, symbol_c *type_spec, symbol_c *init_value) { |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
898 |
/* NOTE: The note in the fill_type_decl() function is also partially valid here, |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
899 |
* i.e. here too we work using a top->down algorithm for the type_spec part, but a bottom->up algorithm |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
900 |
* for the init_value part!! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
901 |
*/ |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
902 |
/* NOTE: When a variable is declared inside a POU as, for example |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
903 |
* VAR |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
904 |
* a : ARRAY[9] OF REAL; |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
905 |
* e : ENUM (black, white, gray); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
906 |
* s : STRUCT x, y: REAL; END_STRUCT |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
907 |
* END_VAR |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
908 |
* the anonymous datatype will be defined directly by the ***_spec_init_c, and will not have an |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
909 |
* ****_type_declaration_c. In these cases, the anonymous data type is its own basetype, and the |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
910 |
* ***_spec_init_c class will act as the canonical symbol that represents the (anonymous) basetype. |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
911 |
* |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
912 |
* This method must handle the above case, as well as the case in which the ***_spec_init_c is called |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
913 |
* from an ****_type_declaration_c. |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
914 |
*/ |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
915 |
if (symbol->candidate_datatypes.size() == 0) // i.e., if this is an anonymous datatype! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
916 |
add_datatype_to_candidate_list(symbol, base_type(symbol)); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
917 |
|
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
918 |
// use top->down algorithm!! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
919 |
type_spec->candidate_datatypes = symbol->candidate_datatypes; |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
920 |
type_spec->accept(*this); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
921 |
|
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
922 |
// use bottom->up algorithm!! |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
923 |
if (NULL != init_value) init_value->accept(*this); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
924 |
/* NOTE: Even if the constant and the type are of incompatible data types, we let the |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
925 |
* ***_spec_init_c object inherit the data type of the type declaration (simple_specification) |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
926 |
* This will let us produce more informative error messages when checking data type compatibility |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
927 |
* with located variables (AT %QW3.4 : WORD). |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
928 |
*/ |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
929 |
// if (NULL != init_value) intersect_candidate_datatype_list(symbol /*origin, dest.*/, init_value /*with*/); |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
930 |
return NULL; |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
931 |
} |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
932 |
|
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
933 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
934 |
/* TYPE type_declaration_list END_TYPE */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
935 |
// SYM_REF1(data_type_declaration_c, type_declaration_list) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
936 |
/* NOTE: Not required. already handled by iterator_visitor_c base class */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
937 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
938 |
/* helper symbol for data_type_declaration */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
939 |
// SYM_LIST(type_declaration_list_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
940 |
/* NOTE: Not required. already handled by iterator_visitor_c base class */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
941 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
942 |
/* simple_type_name ':' simple_spec_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
943 |
// SYM_REF2(simple_type_declaration_c, simple_type_name, simple_spec_init) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
944 |
void *fill_candidate_datatypes_c::visit(simple_type_declaration_c *symbol) {return fill_type_decl(symbol, symbol->simple_type_name, symbol->simple_spec_init);} |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
945 |
|
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
946 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
947 |
/* simple_specification ASSIGN constant */ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
948 |
// SYM_REF2(simple_spec_init_c, simple_specification, constant) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
949 |
void *fill_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->simple_specification, symbol->constant);} |
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
950 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
951 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
952 |
/* subrange_type_name ':' subrange_spec_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
953 |
// SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
954 |
void *fill_candidate_datatypes_c::visit(subrange_type_declaration_c *symbol) {return fill_type_decl(symbol, symbol->subrange_type_name, symbol->subrange_spec_init);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
955 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
956 |
/* subrange_specification ASSIGN signed_integer */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
957 |
// SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
958 |
void *fill_candidate_datatypes_c::visit(subrange_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->subrange_specification, symbol->signed_integer);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
959 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
960 |
/* integer_type_name '(' subrange')' */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
961 |
// SYM_REF2(subrange_specification_c, integer_type_name, subrange) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
962 |
// NOTE: not needed! Iterator visitor already handles this! |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
963 |
|
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:
diff
changeset
|
964 |
/* signed_integer DOTDOT signed_integer */ |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
965 |
/* dimension will be filled in during stage 3 (array_range_check_c) with the number of elements in this subrange */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
966 |
// SYM_REF2(subrange_c, lower_limit, upper_limit, unsigned long long int dimension;) |
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:
diff
changeset
|
967 |
void *fill_candidate_datatypes_c::visit(subrange_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:
diff
changeset
|
968 |
symbol->lower_limit->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:
diff
changeset
|
969 |
symbol->upper_limit->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:
diff
changeset
|
970 |
|
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:
diff
changeset
|
971 |
for (unsigned int u = 0; u < symbol->upper_limit->candidate_datatypes.size(); u++) { |
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:
diff
changeset
|
972 |
for(unsigned int l = 0; l < symbol->lower_limit->candidate_datatypes.size(); l++) { |
676
ca4f17211251
Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
666
diff
changeset
|
973 |
if (get_datatype_info_c::is_type_equal(symbol->upper_limit->candidate_datatypes[u], symbol->lower_limit->candidate_datatypes[l])) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
974 |
add_datatype_to_candidate_list(symbol, symbol->lower_limit->candidate_datatypes[l]); |
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:
diff
changeset
|
975 |
} |
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:
diff
changeset
|
976 |
} |
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:
diff
changeset
|
977 |
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:
diff
changeset
|
978 |
} |
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:
diff
changeset
|
979 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
980 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
981 |
/* enumerated_type_name ':' enumerated_spec_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
982 |
// SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
983 |
void *fill_candidate_datatypes_c::visit(enumerated_type_declaration_c *symbol) {return fill_type_decl(symbol, symbol->enumerated_type_name, symbol->enumerated_spec_init);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
984 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
985 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
986 |
/* enumerated_specification ASSIGN enumerated_value */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
987 |
// SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value) |
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
|
988 |
// NOTE: enumerated_specification is either an enumerated_value_list_c or derived_datatype_identifier_c. |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
989 |
void *fill_candidate_datatypes_c::visit(enumerated_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->enumerated_specification, symbol->enumerated_value);} |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
990 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
991 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
992 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
993 |
/* enumerated_value_list ',' enumerated_value */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
994 |
// SYM_LIST(enumerated_value_list_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
995 |
void *fill_candidate_datatypes_c::visit(enumerated_value_list_c *symbol) { |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
996 |
if (symbol->candidate_datatypes.size() != 1) ERROR; |
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
997 |
symbol_c *current_enumerated_spec_type = symbol->candidate_datatypes[0]; |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
998 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
999 |
/* We already know the datatype of the enumerated_value(s) in the list, so we set them directly instead of recursively calling the enumerated_value_c visit method! */ |
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:
724
diff
changeset
|
1000 |
for(int i = 0; i < symbol->n; i++) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
1001 |
add_datatype_to_candidate_list(symbol->elements[i], current_enumerated_spec_type); // top->down algorithm!! |
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:
724
diff
changeset
|
1002 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1003 |
return NULL; |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1004 |
} |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1005 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1006 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1007 |
/* enumerated_type_name '#' identifier */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1008 |
// SYM_REF2(enumerated_value_c, type, value) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1009 |
/* WARNING: The enumerated_value_c is used when delcaring an enumerated datatype |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1010 |
* (e.g. TYPE enumT: (xxx1, xxx2); END_TYPE ---> xxx1 and xxx2 will be enumerated_value_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1011 |
* as well as in the source code of POU bodies |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1012 |
* (e.g. enumVar := xxx1 ---> xxx1 will be enumerated_value_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1013 |
* |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1014 |
* The following method will only be used to visit enumerated_value_c that show up inside the |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1015 |
* source code of POU bodies (or the initial values of an enumerated type). When used inside an |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1016 |
* enumerated type declaration to list the possible enum values (whether inside |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1017 |
* a TYPE ... END_TYPE, or inside a VAR .. END_VAR), the visitor method for enumerated_value_list_c |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1018 |
* will NOT recursively call the following enumerated_value_c visitor method! |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1019 |
*/ |
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:
diff
changeset
|
1020 |
void *fill_candidate_datatypes_c::visit(enumerated_value_c *symbol) { |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1021 |
symbol_c *global_enumerated_type; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1022 |
symbol_c *local_enumerated_type; |
735
0304ff59fd7f
Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents:
733
diff
changeset
|
1023 |
symbol_c *enumerated_type = 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:
diff
changeset
|
1024 |
|
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1025 |
if (NULL != symbol->type) { |
733
246b4ef78da6
Do datatype verification of fully qualified enumerated values (e.g. ENUMTYPE#enumconst)
Mario de Sousa <msousa@fe.up.pt>
parents:
732
diff
changeset
|
1026 |
/* NOTE: This code must take into account the following situation: |
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1027 |
* |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1028 |
* TYPE |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1029 |
* base_enum_t: (x1, x2, x3); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1030 |
* enum_t1 : base_enum_t := x1; |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1031 |
* enum_t2 : base_enum_t := x2; |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1032 |
* enum_t12: enum_t1 := x2; |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1033 |
* END_TYPE |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1034 |
* |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1035 |
* considering the above, ALL of the following are correct! |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1036 |
* base_enum_t#x1 |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1037 |
* enum_t1#x1 |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1038 |
* enum_t2#x1 |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1039 |
* enum_t12#x1 |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1040 |
*/ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1041 |
/* check whether the value really belongs to that datatype!! */ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1042 |
/* All local enum values are declared inside anonymous enumeration datatypes (i.e. inside a VAR ... END_VAR declaration, with |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1043 |
* the enum type having no type name), so thay cannot possibly be referenced using a datatype_t#enumvalue syntax. |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1044 |
* Because of this, we only look for the datatype identifier in the global enum value symbol table! |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1045 |
*/ |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1046 |
enumerated_type = NULL; // assume error... |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1047 |
enumerated_value_symtable_t::iterator lower = global_enumerated_value_symtable.lower_bound(symbol->value); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1048 |
enumerated_value_symtable_t::iterator upper = global_enumerated_value_symtable.upper_bound(symbol->value); |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1049 |
for (; lower != upper; lower++) |
733
246b4ef78da6
Do datatype verification of fully qualified enumerated values (e.g. ENUMTYPE#enumconst)
Mario de Sousa <msousa@fe.up.pt>
parents:
732
diff
changeset
|
1050 |
if (get_datatype_info_c::is_type_equal(base_type(lower->second), base_type(symbol->type))) |
724
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1051 |
enumerated_type = symbol->type; |
d19877568878
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
Mario de Sousa <msousa@fe.up.pt>
parents:
720
diff
changeset
|
1052 |
} |
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:
diff
changeset
|
1053 |
else { |
972
bc90dd4bbf4f
Change dsymbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents:
965
diff
changeset
|
1054 |
symbol_c *global_enumerated_type = global_enumerated_value_symtable.find (symbol->value)->second; |
bc90dd4bbf4f
Change dsymbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents:
965
diff
changeset
|
1055 |
symbol_c * local_enumerated_type = local_enumerated_value_symtable.find (symbol->value)->second; |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1056 |
int global_multiplicity = global_enumerated_value_symtable.count(symbol->value); |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1057 |
int local_multiplicity = local_enumerated_value_symtable.count(symbol->value); |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1058 |
|
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1059 |
if (( local_multiplicity == 0) && (global_multiplicity == 0)) |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1060 |
enumerated_type = NULL; // not found! |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1061 |
else if ( local_multiplicity > 1) |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1062 |
enumerated_type = NULL; // Local duplicate, so it is ambiguous! |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1063 |
else if ( local_multiplicity == 1) |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1064 |
enumerated_type = local_enumerated_type; |
720
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1065 |
else if ( global_multiplicity > 1) |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1066 |
enumerated_type = NULL; // Global duplicate, so it is ambiguous! |
f637ac331a68
Use duplicate symtable instead of symtable for enum constant value table (this will later allow us to detect semantic errors in IEC 61131-3 source code)
Mario de Sousa <msousa@fe.up.pt>
parents:
719
diff
changeset
|
1067 |
else if ( global_multiplicity == 1) |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1068 |
enumerated_type = global_enumerated_type; |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1069 |
else ERROR; |
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:
diff
changeset
|
1070 |
} |
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:
diff
changeset
|
1071 |
enumerated_type = base_type(enumerated_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:
diff
changeset
|
1072 |
if (NULL != enumerated_type) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1073 |
add_datatype_to_candidate_list(symbol, enumerated_type); |
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:
diff
changeset
|
1074 |
|
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:
diff
changeset
|
1075 |
if (debug) std::cout << "ENUMERATE [" << symbol->candidate_datatypes.size() << "]\n"; |
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:
diff
changeset
|
1076 |
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:
diff
changeset
|
1077 |
} |
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:
diff
changeset
|
1078 |
|
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:
diff
changeset
|
1079 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1080 |
/* identifier ':' array_spec_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1081 |
// SYM_REF2(array_type_declaration_c, identifier, array_spec_init) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
1082 |
void *fill_candidate_datatypes_c::visit(array_type_declaration_c *symbol) {return fill_type_decl(symbol, symbol->identifier, symbol->array_spec_init);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1083 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1084 |
/* array_specification [ASSIGN array_initialization} */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1085 |
/* array_initialization may be NULL ! */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1086 |
// SYM_REF2(array_spec_init_c, array_specification, array_initialization) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
1087 |
void *fill_candidate_datatypes_c::visit(array_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->array_specification, symbol->array_initialization);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1088 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1089 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1090 |
// SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1091 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1092 |
/* helper symbol for array_specification */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1093 |
/* array_subrange_list ',' subrange */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1094 |
// SYM_LIST(array_subrange_list_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1095 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1096 |
/* array_initialization: '[' array_initial_elements_list ']' */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1097 |
/* helper symbol for array_initialization */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1098 |
/* array_initial_elements_list ',' array_initial_elements */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1099 |
// SYM_LIST(array_initial_elements_list_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1100 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1101 |
/* integer '(' [array_initial_element] ')' */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1102 |
/* array_initial_element may be NULL ! */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1103 |
// SYM_REF2(array_initial_elements_c, integer, array_initial_element) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1104 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1105 |
/* structure_type_name ':' structure_specification */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1106 |
// SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
1107 |
void *fill_candidate_datatypes_c::visit(structure_type_declaration_c *symbol) {return fill_type_decl(symbol, symbol->structure_type_name, symbol->structure_specification);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1108 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1109 |
/* structure_type_name ASSIGN structure_initialization */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1110 |
/* structure_initialization may be NULL ! */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1111 |
// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
806
f218434eeaf8
Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
763
diff
changeset
|
1112 |
void *fill_candidate_datatypes_c::visit(initialized_structure_c *symbol) {return fill_spec_init(symbol, symbol->structure_type_name, symbol->structure_initialization);} |
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1113 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1114 |
/* helper symbol for structure_declaration */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1115 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1116 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1117 |
// SYM_LIST(structure_element_declaration_list_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1118 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1119 |
/* structure_element_name ':' *_spec_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1120 |
// SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1121 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1122 |
/* helper symbol for structure_initialization */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1123 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1124 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1125 |
// SYM_LIST(structure_element_initialization_list_c) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1126 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1127 |
/* structure_element_name ASSIGN value */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1128 |
// SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1129 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1130 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1131 |
// SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) |
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1132 |
|
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1133 |
|
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
|
1134 |
/* function_block_type_name ASSIGN 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
|
1135 |
/* structure_initialization -> may be NULL ! */ |
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
|
1136 |
// 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
|
1137 |
void *fill_candidate_datatypes_c::visit(fb_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->function_block_type_name, symbol->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
|
1138 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1139 |
|
909
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1140 |
/* REF_TO (non_generic_type_name | function_block_type_name) */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1141 |
// SYM_REF1(ref_spec_c, type_name) |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1142 |
void *fill_candidate_datatypes_c::visit(ref_spec_c *symbol) { |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1143 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1144 |
// when parsing datatype declarations, fill_candidate_datatypes_c follows a top->down algorithm (see the comment in fill_type_decl() for an explanation) |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1145 |
add_datatype_to_candidate_list(symbol->type_name, base_type(symbol->type_name)); |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1146 |
symbol->type_name->accept(*this); /* The referenced/pointed to datatype! */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1147 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1148 |
if (symbol->candidate_datatypes.size() == 0) // i.e., if this is an anonymous datatype! |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1149 |
add_datatype_to_candidate_list(symbol, base_type(symbol)); |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1150 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1151 |
return NULL; |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1152 |
} |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1153 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1154 |
/* 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:
873
diff
changeset
|
1155 |
/* ref_spec [ ASSIGN ref_initialization ] */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1156 |
/* NOTE: ref_initialization may be NULL!! */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1157 |
// SYM_REF2(ref_spec_init_c, ref_spec, ref_initialization) |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1158 |
void *fill_candidate_datatypes_c::visit(ref_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->ref_spec, symbol->ref_initialization);} |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1159 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1160 |
/* identifier ':' ref_spec_init */ |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1161 |
// 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:
873
diff
changeset
|
1162 |
void *fill_candidate_datatypes_c::visit(ref_type_decl_c *symbol) {return fill_type_decl(symbol, symbol->ref_type_name, symbol->ref_spec_init);} |
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1163 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1164 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1165 |
|
8b2a31dea131
Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents:
873
diff
changeset
|
1166 |
|
717
44f74fad2cc0
Start datatype checking of variable declarations (for now, only seting symbol.datatype of enumerations)
Mario de Sousa <msousa@fe.up.pt>
parents:
716
diff
changeset
|
1167 |
|
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:
diff
changeset
|
1168 |
/*********************/ |
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:
diff
changeset
|
1169 |
/* B 1.4 - Variables */ |
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:
diff
changeset
|
1170 |
/*********************/ |
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:
diff
changeset
|
1171 |
void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) { |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1172 |
symbol->scope = current_scope; // the scope in which this variable was declared! |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1173 |
/* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1174 |
* Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1175 |
* in this fill_candidate_datatypes_c itself! |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1176 |
* This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1177 |
* we will search for the field_variable of the structured_variable_c. Similarly, it is also used to determine the datatype |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1178 |
* to which a REF_TO variable points to. |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1179 |
*/ |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1180 |
symbol->datatype = search_var_instance_decl->get_basetype_decl(symbol); // Do the narrow algorithm in this fill_candidate_datatypes_c!! |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1181 |
add_datatype_to_candidate_list(symbol, symbol->datatype); /* will only add if non 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:
diff
changeset
|
1182 |
if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n"; |
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:
diff
changeset
|
1183 |
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:
diff
changeset
|
1184 |
} |
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:
diff
changeset
|
1185 |
|
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1186 |
|
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:
diff
changeset
|
1187 |
/********************************************/ |
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:
diff
changeset
|
1188 |
/* B 1.4.1 - Directly Represented Variables */ |
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:
diff
changeset
|
1189 |
/********************************************/ |
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:
diff
changeset
|
1190 |
void *fill_candidate_datatypes_c::visit(direct_variable_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:
diff
changeset
|
1191 |
/* Comment added by mario: |
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:
diff
changeset
|
1192 |
* The following code is safe, actually, as the lexical parser guarantees the correct IEC61131-3 syntax was used. |
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:
diff
changeset
|
1193 |
*/ |
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:
diff
changeset
|
1194 |
/* However, we should probably add an assertion in case we later change the lexical parser! */ |
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:
diff
changeset
|
1195 |
/* if (symbol->value == NULL) 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:
diff
changeset
|
1196 |
* if (symbol->value[0] == '\0') 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:
diff
changeset
|
1197 |
* if (symbol->value[1] == '\0') 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:
diff
changeset
|
1198 |
*/ |
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:
diff
changeset
|
1199 |
switch (symbol->value[2]) { |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1200 |
case 'x': case 'X': /* bit - 1 bit */ add_datatype_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name); break; |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1201 |
case 'b': case 'B': /* byte - 8 bits */ add_datatype_to_candidate_list(symbol, &get_datatype_info_c::byte_type_name); break; |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1202 |
case 'w': case 'W': /* word - 16 bits */ add_datatype_to_candidate_list(symbol, &get_datatype_info_c::word_type_name); break; |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1203 |
case 'd': case 'D': /* dword - 32 bits */ add_datatype_to_candidate_list(symbol, &get_datatype_info_c::dword_type_name); break; |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1204 |
case 'l': case 'L': /* lword - 64 bits */ add_datatype_to_candidate_list(symbol, &get_datatype_info_c::lword_type_name); break; |
479 | 1205 |
/* if none of the above, then the empty string was used <=> boolean */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1206 |
default: add_datatype_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name); break; |
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:
diff
changeset
|
1207 |
} |
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:
diff
changeset
|
1208 |
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:
diff
changeset
|
1209 |
} |
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:
diff
changeset
|
1210 |
|
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:
diff
changeset
|
1211 |
/*************************************/ |
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:
diff
changeset
|
1212 |
/* B 1.4.2 - Multi-element variables */ |
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:
diff
changeset
|
1213 |
/*************************************/ |
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:
diff
changeset
|
1214 |
/* subscripted_variable '[' subscript_list ']' */ |
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:
diff
changeset
|
1215 |
// SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
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:
diff
changeset
|
1216 |
void *fill_candidate_datatypes_c::visit(array_variable_c *symbol) { |
827
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1217 |
/* recursively call the subscripted_variable. We need to do this since the array variable may be stored inside a structured |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1218 |
* variable (i.e. if it is an element inside a struct), in which case we want to recursively visit every element of the struct, |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1219 |
* as it may contain more arrays whose subscripts must also be visited! |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1220 |
* e.g. structvar.a1[v1+2].b1.c1[v2+3].d1 |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1221 |
* TYPE |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1222 |
* d_s: STRUCT d1: int; d2: int; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1223 |
* d_a: ARRAY [1..3] OF d_s; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1224 |
* c_s: STRUCT c1: d_a; c2: d_a; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1225 |
* b_s: STRUCT b1: c_s; b2: c_s; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1226 |
* b_a: ARRAY [1..3] OF b_s; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1227 |
* a_s: STRUCT a1: b_a; a2: b_a; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1228 |
* END_TYPE |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1229 |
* VAR |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1230 |
* structvar: a_s; |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1231 |
* END_VAR |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1232 |
*/ |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1233 |
symbol->subscripted_variable->accept(*this); |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1234 |
// the scope in which this variable was declared! It will be the same as the subscripted variable (a symbolic_variable_ !) |
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1235 |
symbol->scope = symbol->subscripted_variable->scope; |
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1236 |
if (NULL == symbol->scope) ERROR; |
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1237 |
|
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1238 |
/* get the declaration of the data type __stored__ in the array... */ |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1239 |
add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(get_datatype_info_c::get_array_storedtype_id(symbol->subscripted_variable->datatype))); /* will only add if non NULL */ |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1240 |
|
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1241 |
/* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1242 |
* Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1243 |
* in this fill_candidate_datatypes_c itself! |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1244 |
* This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1245 |
* we will search for the field_variable of the structured_variable_c. Similarly, it is also used to determine the datatype |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1246 |
* to which a REF_TO variable points to. |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1247 |
*/ |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1248 |
if (symbol->candidate_datatypes.size() == 1) |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1249 |
// narrow the symbol->datatype for this array_variable as explained above! |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1250 |
symbol->datatype = symbol->candidate_datatypes[0]; |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1251 |
|
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1252 |
/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */ |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1253 |
symbol->subscript_list->accept(*this); |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1254 |
|
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:
diff
changeset
|
1255 |
if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n"; |
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:
diff
changeset
|
1256 |
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:
diff
changeset
|
1257 |
} |
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:
diff
changeset
|
1258 |
|
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:
diff
changeset
|
1259 |
|
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:
diff
changeset
|
1260 |
/* subscript_list ',' subscript */ |
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:
diff
changeset
|
1261 |
// SYM_LIST(subscript_list_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:
diff
changeset
|
1262 |
/* NOTE: we inherit from iterator visitor, so we do not need to implement this method... */ |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1263 |
// void *fill_candidate_datatypes_c::visit(subscript_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:
diff
changeset
|
1264 |
|
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:
diff
changeset
|
1265 |
|
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:
diff
changeset
|
1266 |
/* record_variable '.' field_selector */ |
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:
diff
changeset
|
1267 |
/* WARNING: input and/or output variables of function blocks |
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:
diff
changeset
|
1268 |
* may be accessed as fields of a structured variable! |
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:
diff
changeset
|
1269 |
* Code handling a structured_variable_c must take |
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:
diff
changeset
|
1270 |
* this into account! |
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:
diff
changeset
|
1271 |
*/ |
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:
diff
changeset
|
1272 |
// SYM_REF2(structured_variable_c, record_variable, field_selector) |
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:
diff
changeset
|
1273 |
void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) { |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1274 |
/* Remember that a structured variable may be stored inside an array (e.g. arrayvar[33].elem1) |
827
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1275 |
* The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined! |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1276 |
* The expression, may even contain a function call to an overloaded function! |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1277 |
* (e.g. arrayvar[ varx + TRUNC(realvar)].elem1) |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1278 |
*/ |
e3800aff352c
Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents:
813
diff
changeset
|
1279 |
symbol->record_variable->accept(*this); |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1280 |
symbol->scope = symbol->record_variable->datatype; // the scope in which this variable was declared! Will be used in stage4 |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1281 |
|
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1282 |
/* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1283 |
* Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1284 |
* in this fill_candidate_datatypes_c itself! |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1285 |
* This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1286 |
* we will search for the field_variable of the structured_variable_c. Similarly, it is also used to determine the datatype |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1287 |
* to which a REF_TO variable points to. |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1288 |
*/ |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1289 |
if (NULL != symbol->record_variable->datatype) |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1290 |
// We relly on the fact that we have already narrowed the symbol->datatype for the record variable, and use it as the scope in which the filed_variable is declared! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1291 |
add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(get_datatype_info_c::get_struct_field_type_id(symbol->record_variable->datatype, symbol->field_selector))); /* will only add if non NULL */ |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1292 |
if (symbol->candidate_datatypes.size() == 1) |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1293 |
// narrow the symbol->datatype for this strcutured_variable as explained above! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
1294 |
symbol->datatype = symbol->candidate_datatypes[0]; |
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:
diff
changeset
|
1295 |
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:
diff
changeset
|
1296 |
} |
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:
diff
changeset
|
1297 |
|
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1298 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1299 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1300 |
/******************************************/ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1301 |
/* B 1.4.3 - Declaration & Initialisation */ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1302 |
/******************************************/ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1303 |
|
945
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1304 |
/* When handling the declaration of variables the fill/narrow algorithm will simply visit the objects |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1305 |
* in the abstract syntax tree defining the desired datatype for the variables. Tis is to set the |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1306 |
* symbol->datatype to the basetype of that datatype. |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1307 |
* |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1308 |
* Note that we do not currently set the symbol->datatype annotation for the identifier_c objects naming the |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1309 |
* variables inside the variable declaration. However, this is liable to change in the future, so do not write |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1310 |
* any code that depends on this! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1311 |
* |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1312 |
* example: |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1313 |
* VAR var1, var2, var3 : my_type; END_VAR |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1314 |
* (* ^^^^ ^^^^ ^^^^ -> will NOT have the symbol->datatype set (for now, may change in the future!) *) |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1315 |
* (* ^^^^^^^ -> WILL have the symbol->datatype set *) |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1316 |
* |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1317 |
* (remeber too that the identifier_c objects identifying variables inside ST/IL/SFC code *will* have their |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1318 |
* symbol->datatype annotation filled by the fill/narrow algorithm) |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1319 |
*/ |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1320 |
void *fill_candidate_datatypes_c::fill_var_declaration(symbol_c *var_list, symbol_c *type) { |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1321 |
/* The type may be either a datatype object (e.g. array_spec_init_c, ...), or a derived_datatype_identifier_c |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1322 |
* naming a previously declared datatype. |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1323 |
* If it is a derived_datatype_identifier_c, we will search the list of all declared datatypes to determine |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1324 |
* the requested datatype. This is done automatically by the search_base_type_c::get_basetype_decl() method, |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1325 |
* so we do not need to do anything special here! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1326 |
*/ |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1327 |
add_datatype_to_candidate_list(type, search_base_type_c::get_basetype_decl(type)); /* will only add if non NULL */ |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1328 |
type->accept(*this); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1329 |
// handle the extensible_input_parameter_c, etc... |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1330 |
/* The extensible_input_parameter_c will be visited since this class inherits from the iterator_visitor_c. |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1331 |
* It needs to be visited in order to handle the datatype of the first_index parameter of that class. |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1332 |
*/ |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1333 |
var_list->accept(*this); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1334 |
return NULL; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1335 |
} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1336 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1337 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1338 |
void *fill_candidate_datatypes_c::visit(var1_init_decl_c *symbol) {return fill_var_declaration(symbol->var1_list, symbol->spec_init);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1339 |
void *fill_candidate_datatypes_c::visit(array_var_init_decl_c *symbol) {return fill_var_declaration(symbol->var1_list, symbol->array_spec_init);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1340 |
void *fill_candidate_datatypes_c::visit(structured_var_init_decl_c *symbol) {return fill_var_declaration(symbol->var1_list, symbol->initialized_structure);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1341 |
void *fill_candidate_datatypes_c::visit(fb_name_decl_c *symbol) {return fill_var_declaration(symbol->fb_name_list, symbol->fb_spec_init);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1342 |
void *fill_candidate_datatypes_c::visit(array_var_declaration_c *symbol) {return fill_var_declaration(symbol->var1_list, symbol->array_specification);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1343 |
void *fill_candidate_datatypes_c::visit(structured_var_declaration_c *symbol) {return fill_var_declaration(symbol->var1_list, symbol->structure_type_name);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1344 |
void *fill_candidate_datatypes_c::visit(external_declaration_c *symbol) {return fill_var_declaration(symbol->global_var_name, symbol->specification);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1345 |
void *fill_candidate_datatypes_c::visit(global_var_decl_c *symbol) {return fill_var_declaration(symbol->global_var_spec, symbol->type_specification);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1346 |
void *fill_candidate_datatypes_c::visit(incompl_located_var_decl_c *symbol) {return fill_var_declaration(symbol->variable_name, symbol->var_spec);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1347 |
//void *fill_candidate_datatypes_c::visit(single_byte_string_var_declaration_c *symbol) {return handle_var_declaration(symbol->single_byte_string_spec);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1348 |
//void *fill_candidate_datatypes_c::visit(double_byte_string_var_declaration_c *symbol) {return handle_var_declaration(symbol->double_byte_string_spec);} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1349 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1350 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1351 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1352 |
// NOTE: this method is not required since fill_candidate_datatypes_c inherits from iterator_visitor_c. TODO: delete this method! |
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1353 |
void *fill_candidate_datatypes_c::visit(var1_list_c *symbol) { |
945
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1354 |
for(int i = 0; i < symbol->n; i++) {symbol->elements[i]->accept(*this);} |
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1355 |
return NULL; |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1356 |
} |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1357 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1358 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1359 |
/* AT direct_variable */ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1360 |
// SYM_REF1(location_c, direct_variable) |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1361 |
void *fill_candidate_datatypes_c::visit(location_c *symbol) { |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1362 |
/* This is a special situation. |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1363 |
* |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1364 |
* The reason is that a located variable may be declared to be of any data type, as long as the size |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1365 |
* matches the location (lines 1 3 and 4 of table 17). For example: |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1366 |
* var1 AT %MB42.0 : BYTE; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1367 |
* var1 AT %MB42.1 : SINT; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1368 |
* var1 AT %MB42.2 : USINT; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1369 |
* var1 AT %MW64 : INT; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1370 |
* var1 AT %MD56 : DINT; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1371 |
* var1 AT %MD57 : REAL; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1372 |
* are all valid!! |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1373 |
* |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1374 |
* However, when used inside an expression, the direct variable (uses the same syntax as the location |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1375 |
* of a located variable) is limited to the following (ANY_BIT) data types: |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1376 |
* %MX --> BOOL |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1377 |
* %MB --> BYTE |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1378 |
* %MW --> WORD |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1379 |
* %MD --> DWORD |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1380 |
* %ML --> LWORD |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1381 |
* |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1382 |
* So, in order to be able to analyse expressions with direct variables |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1383 |
* e.g: var1 := 66 OR %MW34 |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1384 |
* where the direct variable may only take the ANY_BIT data types, the fill_candidate_datatypes_c |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1385 |
* considers that only the ANY_BIT data types are allowed for a direct variable. |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1386 |
* However, it appears from the examples in the standard (lines 1 3 and 4 of table 17) |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1387 |
* a location may have any data type (presumably as long as the size in bits match). |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1388 |
* For this reason, a location_c may have more allowable data types than a direct_variable_c |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1389 |
*/ |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1390 |
|
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1391 |
symbol->direct_variable->accept(*this); |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1392 |
for (unsigned int i = 0; i < symbol->direct_variable->candidate_datatypes.size(); i++) { |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1393 |
switch (get_sizeof_datatype_c::getsize(symbol->direct_variable->candidate_datatypes[i])) { |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1394 |
case 1: /* bit - 1 bit */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1395 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1396 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safebool_type_name); |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1397 |
break; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1398 |
case 8: /* byte - 8 bits */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1399 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::byte_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1400 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safebyte_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1401 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::sint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1402 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safesint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1403 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::usint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1404 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safeusint_type_name); |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1405 |
break; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1406 |
case 16: /* word - 16 bits */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1407 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::word_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1408 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safeword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1409 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::int_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1410 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safeint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1411 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::uint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1412 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safeuint_type_name); |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1413 |
break; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1414 |
case 32: /* dword - 32 bits */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1415 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::dword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1416 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safedword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1417 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::dint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1418 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safedint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1419 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::udint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1420 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safeudint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1421 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::real_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1422 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safereal_type_name); |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1423 |
break; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1424 |
case 64: /* lword - 64 bits */ |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1425 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::lword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1426 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safelword_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1427 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::lint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1428 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safelint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1429 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::ulint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1430 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safeulint_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1431 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::lreal_type_name); |
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
690
diff
changeset
|
1432 |
add_datatype_to_candidate_list(symbol, &get_datatype_info_c::safelreal_type_name); |
558
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1433 |
break; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1434 |
default: /* if none of the above, then no valid datatype allowed... */ |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1435 |
break; |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1436 |
} /* switch() */ |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1437 |
} /* for */ |
9273dfc5fa7c
Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents:
552
diff
changeset
|
1438 |
|
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1439 |
return NULL; |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1440 |
} |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1441 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1442 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1443 |
/* [variable_name] location ':' located_var_spec_init */ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1444 |
/* variable_name -> may be NULL ! */ |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1445 |
// SYM_REF3(located_var_decl_c, variable_name, location, located_var_spec_init) |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1446 |
void *fill_candidate_datatypes_c::visit(located_var_decl_c *symbol) { |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1447 |
symbol->located_var_spec_init->accept(*this); |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1448 |
symbol->location->accept(*this); |
523
773303b7f31f
Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents:
502
diff
changeset
|
1449 |
if (NULL != symbol->variable_name) { |
773303b7f31f
Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents:
502
diff
changeset
|
1450 |
symbol->variable_name->candidate_datatypes = symbol->location->candidate_datatypes; |
773303b7f31f
Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents:
502
diff
changeset
|
1451 |
intersect_candidate_datatype_list(symbol->variable_name /*origin, dest.*/, symbol->located_var_spec_init /*with*/); |
773303b7f31f
Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents:
502
diff
changeset
|
1452 |
} |
502
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1453 |
return NULL; |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1454 |
} |
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1455 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1456 |
|
a6211f73690b
Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents:
490
diff
changeset
|
1457 |
|
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:
diff
changeset
|
1458 |
/************************************/ |
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:
diff
changeset
|
1459 |
/* B 1.5 Program organization units */ |
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:
diff
changeset
|
1460 |
/************************************/ |
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:
diff
changeset
|
1461 |
/*********************/ |
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:
diff
changeset
|
1462 |
/* B 1.5.1 Functions */ |
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:
diff
changeset
|
1463 |
/*********************/ |
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:
diff
changeset
|
1464 |
void *fill_candidate_datatypes_c::visit(function_declaration_c *symbol) { |
479 | 1465 |
if (debug) printf("Filling candidate data types list of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1466 |
local_enumerated_value_symtable.reset(); |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1467 |
current_scope = symbol; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1468 |
symbol->var_declarations_list->accept(populate_enumvalue_symtable); |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1469 |
|
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1470 |
search_var_instance_decl = new search_var_instance_decl_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:
diff
changeset
|
1471 |
symbol->var_declarations_list->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:
diff
changeset
|
1472 |
symbol->function_body->accept(*this); |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1473 |
delete search_var_instance_decl; |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1474 |
search_var_instance_decl = NULL; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1475 |
|
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1476 |
current_scope = NULL; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1477 |
local_enumerated_value_symtable.reset(); |
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:
diff
changeset
|
1478 |
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:
diff
changeset
|
1479 |
} |
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:
diff
changeset
|
1480 |
|
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:
diff
changeset
|
1481 |
/***************************/ |
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:
diff
changeset
|
1482 |
/* B 1.5.2 Function blocks */ |
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:
diff
changeset
|
1483 |
/***************************/ |
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:
diff
changeset
|
1484 |
void *fill_candidate_datatypes_c::visit(function_block_declaration_c *symbol) { |
479 | 1485 |
if (debug) printf("Filling candidate data types list of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1486 |
local_enumerated_value_symtable.reset(); |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1487 |
current_scope = symbol; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1488 |
symbol->var_declarations->accept(populate_enumvalue_symtable); |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1489 |
|
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1490 |
search_var_instance_decl = new search_var_instance_decl_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:
diff
changeset
|
1491 |
symbol->var_declarations->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:
diff
changeset
|
1492 |
symbol->fblock_body->accept(*this); |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1493 |
delete search_var_instance_decl; |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1494 |
search_var_instance_decl = NULL; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1495 |
|
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1496 |
current_scope = NULL; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1497 |
local_enumerated_value_symtable.reset(); |
807
4d71292f8732
Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
806
diff
changeset
|
1498 |
|
4d71292f8732
Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
806
diff
changeset
|
1499 |
/* The FB declaration itself may be used as a dataype! We now do the fill algorithm considering |
4d71292f8732
Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
806
diff
changeset
|
1500 |
* function_block_declaration_c a data type declaration... |
4d71292f8732
Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
806
diff
changeset
|
1501 |
*/ |
4d71292f8732
Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
806
diff
changeset
|
1502 |
// The next line is essentially equivalent to doing--> symbol->candidate_datatypes.push_back(symbol); |
4d71292f8732
Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents:
806
diff
changeset
|
1503 |
add_datatype_to_candidate_list(symbol, base_type(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:
diff
changeset
|
1504 |
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:
diff
changeset
|
1505 |
} |
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:
diff
changeset
|
1506 |
|
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:
diff
changeset
|
1507 |
/**********************/ |
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:
diff
changeset
|
1508 |
/* B 1.5.3 - Programs */ |
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:
diff
changeset
|
1509 |
/**********************/ |
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:
diff
changeset
|
1510 |
void *fill_candidate_datatypes_c::visit(program_declaration_c *symbol) { |
479 | 1511 |
if (debug) printf("Filling candidate data types list in program %s\n", ((token_c *)(symbol->program_type_name))->value); |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1512 |
local_enumerated_value_symtable.reset(); |
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1513 |
current_scope = symbol; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1514 |
symbol->var_declarations->accept(populate_enumvalue_symtable); |
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1515 |
|
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1516 |
search_var_instance_decl = new search_var_instance_decl_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:
diff
changeset
|
1517 |
symbol->var_declarations->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:
diff
changeset
|
1518 |
symbol->function_block_body->accept(*this); |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1519 |
delete search_var_instance_decl; |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1520 |
search_var_instance_decl = NULL; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1521 |
|
940
61e2bdae5899
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
mjsousa
parents:
939
diff
changeset
|
1522 |
current_scope = NULL; |
716
eb9aad0c3627
Do datatype checking of enum values defined inside anonymous enumeration types (i.e. enum types defined inside a VAR ... END_VAR daclaration).
Mario de Sousa <msousa@fe.up.pt>
parents:
693
diff
changeset
|
1523 |
local_enumerated_value_symtable.reset(); |
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:
diff
changeset
|
1524 |
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:
diff
changeset
|
1525 |
} |
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:
diff
changeset
|
1526 |
|
802
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1527 |
/********************************************/ |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1528 |
/* B 1.6 Sequential function chart elements */ |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1529 |
/********************************************/ |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1530 |
|
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1531 |
void *fill_candidate_datatypes_c::visit(transition_condition_c *symbol) { |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1532 |
symbol_c *condition_type; |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1533 |
|
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1534 |
if (symbol->transition_condition_il != NULL) { |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1535 |
symbol->transition_condition_il->accept(*this); |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1536 |
for (unsigned int i = 0; i < symbol->transition_condition_il->candidate_datatypes.size(); i++) { |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1537 |
condition_type = symbol->transition_condition_il->candidate_datatypes[i]; |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1538 |
if (get_datatype_info_c::is_BOOL_compatible(condition_type)) |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1539 |
add_datatype_to_candidate_list(symbol, condition_type); |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1540 |
} |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1541 |
} |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1542 |
if (symbol->transition_condition_st != NULL) { |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1543 |
symbol->transition_condition_st->accept(*this); |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1544 |
for (unsigned int i = 0; i < symbol->transition_condition_st->candidate_datatypes.size(); i++) { |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1545 |
condition_type = symbol->transition_condition_st->candidate_datatypes[i]; |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1546 |
if (get_datatype_info_c::is_BOOL_compatible(condition_type)) |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1547 |
add_datatype_to_candidate_list(symbol, condition_type); |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1548 |
} |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1549 |
} |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1550 |
return NULL; |
cac262d1d6a5
Fixed bug with SFC transition datatype checking
Laurent Bessard
parents:
763
diff
changeset
|
1551 |
} |
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:
diff
changeset
|
1552 |
|
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:
diff
changeset
|
1553 |
/********************************/ |
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:
diff
changeset
|
1554 |
/* B 1.7 Configuration 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:
diff
changeset
|
1555 |
/********************************/ |
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:
diff
changeset
|
1556 |
void *fill_candidate_datatypes_c::visit(configuration_declaration_c *symbol) { |
945
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1557 |
if (debug) printf("Filling candidate data types list in configuration %s\n", ((token_c *)(symbol->configuration_name))->value); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1558 |
current_scope = symbol; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1559 |
// local_enumerated_value_symtable.reset(); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1560 |
// symbol->global_var_declarations->accept(populate_enumvalue_symtable); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1561 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1562 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1563 |
symbol->global_var_declarations ->accept(*this); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1564 |
symbol->resource_declarations ->accept(*this); // points to a single_resource_declaration_c or a resource_declaration_list_c |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1565 |
// symbol->access_declarations ->accept(*this); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1566 |
// symbol->instance_specific_initializations->accept(*this); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1567 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1568 |
delete search_var_instance_decl; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1569 |
search_var_instance_decl = NULL; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1570 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1571 |
current_scope = NULL; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1572 |
// local_enumerated_value_symtable.reset(); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1573 |
return NULL; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1574 |
} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1575 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1576 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1577 |
void *fill_candidate_datatypes_c::visit(resource_declaration_c *symbol) { |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1578 |
if (debug) printf("Filling candidate data types list in resource %s\n", ((token_c *)(symbol->resource_name))->value); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1579 |
// local_enumerated_value_symtable.reset(); // TODO-> this must be replaced with local_enumerated_value_symtable.push(), which is not yet implemented for the dsyntable_c! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1580 |
symbol_c *prev_scope = current_scope; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1581 |
current_scope = symbol; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1582 |
/* TODO Enumeration constants may be defined inside a VAR_GLOBAL .. END_VAR variable declaration list. |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1583 |
* We currently do not yet consider enumeration values defined in the var declarations inside a resource! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1584 |
*/ |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1585 |
// symbol->global_var_declarations->accept(populate_enumvalue_symtable); // TODO! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1586 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1587 |
search_var_instance_decl_c *prev_search_var_instance_decl = search_var_instance_decl; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1588 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1589 |
symbol->global_var_declarations->accept(*this); |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1590 |
symbol->resource_declaration ->accept(*this); // points to a single_resource_declaration_c! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1591 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1592 |
delete search_var_instance_decl; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1593 |
search_var_instance_decl = prev_search_var_instance_decl; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1594 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1595 |
current_scope = prev_scope; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1596 |
// local_enumerated_value_symtable.reset(); // TODO-> this must be replaced with local_enumerated_value_symtable.pop(), which is not yet implemented for the dsyntable_c! |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1597 |
return NULL; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1598 |
} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1599 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1600 |
|
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1601 |
void *fill_candidate_datatypes_c::visit(single_resource_declaration_c *symbol) { |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1602 |
// symbol->task_configuration_list ->accept(*this); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1603 |
// symbol->program_configuration_list ->accept(*this); // TODO |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1604 |
return NULL; |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1605 |
} |
477393b00f95
Add support for relaxed datatype model for array datatypes.
mjsousa
parents:
942
diff
changeset
|
1606 |
|
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:
diff
changeset
|
1607 |
|
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:
diff
changeset
|
1608 |
/****************************************/ |
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:
diff
changeset
|
1609 |
/* B.2 - Language IL (Instruction List) */ |
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:
diff
changeset
|
1610 |
/****************************************/ |
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:
diff
changeset
|
1611 |
/***********************************/ |
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:
diff
changeset
|
1612 |
/* B 2.1 Instructions and Operands */ |
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:
diff
changeset
|
1613 |
/***********************************/ |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1614 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1615 |
/*| instruction_list il_instruction */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1616 |
// SYM_LIST(instruction_list_c) |
464
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1617 |
void *fill_candidate_datatypes_c::visit(instruction_list_c *symbol) { |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1618 |
/* In order to fill the data type candidates correctly |
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1619 |
* in IL instruction lists containing JMPs to labels that come before the JMP instruction |
464
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1620 |
* itself, we need to run the fill candidate datatypes algorithm twice on the Instruction List. |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1621 |
* e.g.: ... |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1622 |
* ld 23 |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1623 |
* label1:st byte_var |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1624 |
* ld 34 |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1625 |
* JMP label1 |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1626 |
* |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1627 |
* Note that the second time we run the algorithm, most of the candidate datatypes are already filled |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1628 |
* in, so it will be able to produce tha correct candidate datatypes for the IL instruction referenced |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1629 |
* by the label, as in the 2nd pass we already know the candidate datatypes of the JMP instruction! |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1630 |
*/ |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1631 |
for(int j = 0; j < 2; j++) { |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1632 |
for(int i = 0; i < symbol->n; i++) { |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1633 |
symbol->elements[i]->accept(*this); |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1634 |
} |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1635 |
} |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1636 |
return NULL; |
319ee8b218f3
Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents:
462
diff
changeset
|
1637 |
} |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1638 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1639 |
|
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1640 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1641 |
/* | label ':' [il_incomplete_instruction] eol_list */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1642 |
// SYM_REF2(il_instruction_c, label, il_instruction) |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1643 |
// void *visit(instruction_list_c *symbol); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1644 |
void *fill_candidate_datatypes_c::visit(il_instruction_c *symbol) { |
448
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1645 |
if (NULL == symbol->il_instruction) { |
450
eb1b28acec2e
Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
449
diff
changeset
|
1646 |
/* This empty/null il_instruction does not change the value of the current/default IL variable. |
eb1b28acec2e
Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
449
diff
changeset
|
1647 |
* So it inherits the candidate_datatypes from it's previous IL instructions! |
eb1b28acec2e
Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
449
diff
changeset
|
1648 |
*/ |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1649 |
intersect_prev_candidate_datatype_lists(symbol); |
448
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1650 |
} else { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1651 |
il_instruction_c fake_prev_il_instruction = *symbol; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1652 |
intersect_prev_candidate_datatype_lists(&fake_prev_il_instruction); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1653 |
|
457
67d8b07bac22
Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents:
456
diff
changeset
|
1654 |
if (symbol->prev_il_instruction.size() == 0) prev_il_instruction = NULL; |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1655 |
else prev_il_instruction = &fake_prev_il_instruction; |
448
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1656 |
symbol->il_instruction->accept(*this); |
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1657 |
prev_il_instruction = NULL; |
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1658 |
|
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1659 |
/* This object has (inherits) the same candidate datatypes as the il_instruction */ |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1660 |
symbol->candidate_datatypes = symbol->il_instruction->candidate_datatypes; |
448
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
447
diff
changeset
|
1661 |
} |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1662 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1663 |
return NULL; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1664 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1665 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1666 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1667 |
|
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:
diff
changeset
|
1668 |
void *fill_candidate_datatypes_c::visit(il_simple_operation_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:
diff
changeset
|
1669 |
/* determine the data type of the operand */ |
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:
diff
changeset
|
1670 |
if (NULL != symbol->il_operand) { |
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:
diff
changeset
|
1671 |
symbol->il_operand->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:
diff
changeset
|
1672 |
} |
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:
diff
changeset
|
1673 |
/* recursive call to fill the candidate data types list */ |
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:
diff
changeset
|
1674 |
il_operand = symbol->il_operand; |
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:
diff
changeset
|
1675 |
symbol->il_simple_operator->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:
diff
changeset
|
1676 |
il_operand = NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
442
diff
changeset
|
1677 |
/* This object has (inherits) the same candidate datatypes as the il_simple_operator */ |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1678 |
symbol->candidate_datatypes = symbol->il_simple_operator->candidate_datatypes; |
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:
diff
changeset
|
1679 |
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:
diff
changeset
|
1680 |
} |
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:
diff
changeset
|
1681 |
|
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1682 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1683 |
/* | function_name [il_operand_list] */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1684 |
/* NOTE: The parameters 'called_function_declaration' and 'extensible_param_count' are used to pass data between the stage 3 and stage 4. */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1685 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;) |
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:
diff
changeset
|
1686 |
void *fill_candidate_datatypes_c::visit(il_function_call_c *symbol) { |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1687 |
/* The first parameter of a non formal function call in IL will be the 'current value' (i.e. the prev_il_instruction) |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1688 |
* In order to be able to handle this without coding special cases, we will simply prepend that symbol |
451 | 1689 |
* to the il_operand_list, and remove it after calling handle_function_call(). |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1690 |
* |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1691 |
* However, if no further paramters are given, then il_operand_list will be NULL, and we will |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1692 |
* need to create a new object to hold the pointer to prev_il_instruction. |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1693 |
*/ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1694 |
if (NULL == symbol->il_operand_list) symbol->il_operand_list = new il_operand_list_c; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1695 |
if (NULL == symbol->il_operand_list) ERROR; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1696 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1697 |
symbol->il_operand_list->accept(*this); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1698 |
|
451 | 1699 |
if (NULL != prev_il_instruction) { |
1700 |
((list_c *)symbol->il_operand_list)->insert_element(prev_il_instruction, 0); |
|
1701 |
||
1702 |
generic_function_call_t fcall_param = { |
|
1703 |
/* fcall_param.function_name = */ symbol->function_name, |
|
1704 |
/* fcall_param.nonformal_operand_list = */ symbol->il_operand_list, |
|
1705 |
/* fcall_param.formal_operand_list = */ NULL, |
|
1706 |
/* enum {POU_FB, POU_function} POU_type = */ generic_function_call_t::POU_function, |
|
1707 |
/* fcall_param.candidate_functions = */ symbol->candidate_functions, |
|
1708 |
/* fcall_param.called_function_declaration = */ symbol->called_function_declaration, |
|
1709 |
/* fcall_param.extensible_param_count = */ symbol->extensible_param_count |
|
1710 |
}; |
|
1711 |
handle_function_call(symbol, fcall_param); |
|
1712 |
||
1713 |
/* Undo the changes to the abstract syntax tree we made above... */ |
|
1714 |
((list_c *)symbol->il_operand_list)->remove_element(0); |
|
1715 |
} |
|
1716 |
||
1717 |
/* Undo the changes to the abstract syntax tree we made above... */ |
|
1718 |
if (((list_c *)symbol->il_operand_list)->n == 0) { |
|
1719 |
/* if the list becomes empty, then that means that it did not exist before we made these changes, so we delete it! */ |
|
1720 |
delete symbol->il_operand_list; |
|
1721 |
symbol->il_operand_list = NULL; |
|
1722 |
} |
|
1723 |
||
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1724 |
if (debug) std::cout << "il_function_call_c [" << symbol->candidate_datatypes.size() << "] result.\n"; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1725 |
return NULL; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1726 |
} |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1727 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1728 |
|
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:
diff
changeset
|
1729 |
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
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:
diff
changeset
|
1730 |
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list); |
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:
diff
changeset
|
1731 |
void *fill_candidate_datatypes_c::visit(il_expression_c *symbol) { |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1732 |
symbol_c *prev_il_instruction_backup = prev_il_instruction; |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1733 |
|
690
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1734 |
/* Stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list if necessary. We can therefore ignore the 'il_operand' entry! */ |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1735 |
// if (NULL != symbol->il_operand) |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1736 |
// symbol->il_operand->accept(*this); |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1737 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1738 |
if(symbol->simple_instr_list != 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:
diff
changeset
|
1739 |
symbol->simple_instr_list->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:
diff
changeset
|
1740 |
|
690
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1741 |
/* Since stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list when an 'il_operand' exists, we know |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1742 |
* that if (symbol->il_operand != NULL), then the first IL instruction in the simple_instr_list will be the equivalent and artificial |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1743 |
* 'LD <il_operand>' IL instruction. |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1744 |
* Just to be cosistent, we will copy the datatype info back into the il_operand, even though this should not be necessary! |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1745 |
*/ |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1746 |
if ((NULL != symbol->il_operand) && ((NULL == symbol->simple_instr_list) || (0 == ((list_c *)symbol->simple_instr_list)->n))) ERROR; // stage2 is not behaving as we expect it to! |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1747 |
if (NULL != symbol->il_operand) |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1748 |
symbol->il_operand->candidate_datatypes = ((list_c *)symbol->simple_instr_list)->elements[0]->candidate_datatypes; |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
676
diff
changeset
|
1749 |
|
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:
diff
changeset
|
1750 |
/* Now check the if the data type semantics of operation are correct, */ |
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1751 |
il_operand = symbol->simple_instr_list; |
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:
diff
changeset
|
1752 |
prev_il_instruction = prev_il_instruction_backup; |
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:
diff
changeset
|
1753 |
symbol->il_expr_operator->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:
diff
changeset
|
1754 |
il_operand = NULL; |
454
099aa5d655de
Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents:
453
diff
changeset
|
1755 |
|
099aa5d655de
Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents:
453
diff
changeset
|
1756 |
/* This object has the same candidate datatypes as the il_expr_operator. */ |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1757 |
symbol->candidate_datatypes = symbol->il_expr_operator->candidate_datatypes; |
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:
diff
changeset
|
1758 |
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:
diff
changeset
|
1759 |
} |
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:
diff
changeset
|
1760 |
|
462
f7dada0a8952
Fix filling candidate datatypes of JMP operations
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
1761 |
|
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:
diff
changeset
|
1762 |
void *fill_candidate_datatypes_c::visit(il_jump_operation_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:
diff
changeset
|
1763 |
/* recursive call to fill the candidate data types list */ |
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:
diff
changeset
|
1764 |
il_operand = 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:
diff
changeset
|
1765 |
symbol->il_jump_operator->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:
diff
changeset
|
1766 |
il_operand = NULL; |
462
f7dada0a8952
Fix filling candidate datatypes of JMP operations
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
1767 |
/* This object has the same candidate datatypes as the il_jump_operator. */ |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1768 |
symbol->candidate_datatypes = symbol->il_jump_operator->candidate_datatypes; |
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:
diff
changeset
|
1769 |
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:
diff
changeset
|
1770 |
} |
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:
diff
changeset
|
1771 |
|
439
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1772 |
|
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1773 |
/* il_call_operator prev_declared_fb_name |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1774 |
* | il_call_operator prev_declared_fb_name '(' ')' |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1775 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')' |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1776 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1777 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1778 |
*/ |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1779 |
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 */ |
439
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1780 |
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
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:
diff
changeset
|
1781 |
void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) { |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
1782 |
symbol_c *fb_decl = search_var_instance_decl->get_basetype_decl(symbol->fb_name); |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1783 |
if (! get_datatype_info_c::is_function_block(fb_decl)) fb_decl = NULL; |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1784 |
|
439
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1785 |
/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */ |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1786 |
if (NULL == fb_decl) ERROR; |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1787 |
|
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1788 |
if (symbol-> il_param_list != NULL) symbol->il_param_list->accept(*this); |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1789 |
if (symbol->il_operand_list != NULL) symbol->il_operand_list->accept(*this); |
439
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1790 |
|
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1791 |
/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1792 |
* we have a datat type incompatibility error, so setting it to the correct fb_decl is actually safe, |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1793 |
* as the compiler will never reach the compilation stage! |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1794 |
*/ |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1795 |
symbol->called_fb_declaration = fb_decl; |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1796 |
|
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1797 |
/* Let the il_call_operator (CAL, CALC, or CALCN) determine the candidate datatypes of the il_fb_call_c... */ |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1798 |
/* NOTE: We ignore whether the call is 'compatible' or not when filling in the candidate datatypes list. |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1799 |
* Even if it is not compatible, we fill in the candidate datatypes list correctly so that the following |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1800 |
* IL instructions may be handled correctly and debuged. |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1801 |
* Doing this is actually safe, as the parameter_list will still contain errors that will be found by |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1802 |
* print_datatypes_error_c, so the code will never reach stage 4! |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1803 |
*/ |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
1804 |
symbol->il_call_operator->accept(*this); |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1805 |
symbol->candidate_datatypes = symbol->il_call_operator->candidate_datatypes; |
450
eb1b28acec2e
Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
449
diff
changeset
|
1806 |
|
439
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1807 |
if (debug) std::cout << "FB [] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1808 |
return NULL; |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1809 |
} |
cf7d6862033d
Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents:
438
diff
changeset
|
1810 |
|
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:
diff
changeset
|
1811 |
|
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1812 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1813 |
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */ |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1814 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;) |
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:
diff
changeset
|
1815 |
void *fill_candidate_datatypes_c::visit(il_formal_funct_call_c *symbol) { |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1816 |
symbol->il_param_list->accept(*this); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1817 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1818 |
generic_function_call_t fcall_param = { |
441
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1819 |
/* fcall_param.function_name = */ symbol->function_name, |
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1820 |
/* fcall_param.nonformal_operand_list = */ NULL, |
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1821 |
/* fcall_param.formal_operand_list = */ symbol->il_param_list, |
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1822 |
/* enum {POU_FB, POU_function} POU_type = */ generic_function_call_t::POU_function, |
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1823 |
/* fcall_param.candidate_functions = */ symbol->candidate_functions, |
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1824 |
/* fcall_param.called_function_declaration = */ symbol->called_function_declaration, |
e8de43eefcc5
Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
440
diff
changeset
|
1825 |
/* fcall_param.extensible_param_count = */ symbol->extensible_param_count |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1826 |
}; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1827 |
handle_function_call(symbol, fcall_param); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1828 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1829 |
if (debug) std::cout << "il_formal_funct_call_c [" << symbol->candidate_datatypes.size() << "] result.\n"; |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
1830 |
return 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:
diff
changeset
|
1831 |
} |
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:
diff
changeset
|
1832 |
|
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1833 |
|
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1834 |
// void *visit(il_operand_list_c *symbol); |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1835 |
|
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1836 |
|
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1837 |
/* | simple_instr_list il_simple_instruction */ |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1838 |
/* This object is referenced by il_expression_c objects */ |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1839 |
void *fill_candidate_datatypes_c::visit(simple_instr_list_c *symbol) { |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1840 |
if (symbol->n <= 0) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1841 |
return NULL; /* List is empty! Nothing to do. */ |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1842 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1843 |
for(int i = 0; i < symbol->n; i++) |
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1844 |
symbol->elements[i]->accept(*this); |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1845 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1846 |
/* This object has (inherits) the same candidate datatypes as the last il_instruction */ |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1847 |
symbol->candidate_datatypes = symbol->elements[symbol->n-1]->candidate_datatypes; |
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1848 |
|
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1849 |
if (debug) std::cout << "simple_instr_list_c [" << symbol->candidate_datatypes.size() << "] result.\n"; |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1850 |
return NULL; |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1851 |
} |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
451
diff
changeset
|
1852 |
|
457
67d8b07bac22
Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents:
456
diff
changeset
|
1853 |
|
67d8b07bac22
Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents:
456
diff
changeset
|
1854 |
|
67d8b07bac22
Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents:
456
diff
changeset
|
1855 |
|
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1856 |
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1857 |
void *fill_candidate_datatypes_c::visit(il_simple_instruction_c *symbol) { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
1858 |
if (symbol->prev_il_instruction.size() > 1) ERROR; /* There should be no labeled insructions inside an IL expression! */ |
457
67d8b07bac22
Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents:
456
diff
changeset
|
1859 |
if (symbol->prev_il_instruction.size() == 0) prev_il_instruction = NULL; |
67d8b07bac22
Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents:
456
diff
changeset
|
1860 |
else prev_il_instruction = symbol->prev_il_instruction[0]; |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1861 |
symbol->il_simple_instruction->accept(*this); |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1862 |
prev_il_instruction = NULL; |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1863 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1864 |
/* This object has (inherits) the same candidate datatypes as the il_simple_instruction it points to */ |
467
4910eaa1206a
Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents:
465
diff
changeset
|
1865 |
symbol->candidate_datatypes = symbol->il_simple_instruction->candidate_datatypes; |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1866 |
return NULL; |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1867 |
} |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1868 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
1869 |
|
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:
diff
changeset
|
1870 |
/* |
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:
diff
changeset
|
1871 |
void *visit(il_param_list_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:
diff
changeset
|
1872 |
void *visit(il_param_assignment_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:
diff
changeset
|
1873 |
void *visit(il_param_out_assignment_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:
diff
changeset
|
1874 |
*/ |
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:
diff
changeset
|
1875 |
|
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:
diff
changeset
|
1876 |
/*******************/ |
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:
diff
changeset
|
1877 |
/* B 2.2 Operators */ |
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:
diff
changeset
|
1878 |
/*******************/ |
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:
diff
changeset
|
1879 |
void *fill_candidate_datatypes_c::visit(LD_operator_c *symbol) { |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1880 |
if (NULL == il_operand) return 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:
diff
changeset
|
1881 |
for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) { |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1882 |
add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]); |
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:
diff
changeset
|
1883 |
} |
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:
diff
changeset
|
1884 |
if (debug) std::cout << "LD [" << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
1885 |
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:
diff
changeset
|
1886 |
} |
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:
diff
changeset
|
1887 |
|
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:
diff
changeset
|
1888 |
void *fill_candidate_datatypes_c::visit(LDN_operator_c *symbol) { |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1889 |
if (NULL == il_operand) return 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:
diff
changeset
|
1890 |
for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) { |
666
8ba9ec4bae50
Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
1891 |
if (get_datatype_info_c::is_ANY_BIT_compatible(il_operand->candidate_datatypes[i])) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1892 |
add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]); |
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:
diff
changeset
|
1893 |
} |
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:
diff
changeset
|
1894 |
if (debug) std::cout << "LDN [" << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
1895 |
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:
diff
changeset
|
1896 |
} |
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:
diff
changeset
|
1897 |
|
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:
diff
changeset
|
1898 |
void *fill_candidate_datatypes_c::visit(ST_operator_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:
diff
changeset
|
1899 |
symbol_c *prev_instruction_type, *operand_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:
diff
changeset
|
1900 |
|
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:
diff
changeset
|
1901 |
if (NULL == prev_il_instruction) return NULL; |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1902 |
if (NULL == il_operand) return 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:
diff
changeset
|
1903 |
for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
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:
diff
changeset
|
1904 |
for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
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:
diff
changeset
|
1905 |
prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; |
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:
diff
changeset
|
1906 |
operand_type = il_operand->candidate_datatypes[j]; |
676
ca4f17211251
Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
666
diff
changeset
|
1907 |
if (get_datatype_info_c::is_type_equal(prev_instruction_type, operand_type)) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1908 |
add_datatype_to_candidate_list(symbol, prev_instruction_type); |
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:
diff
changeset
|
1909 |
} |
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:
diff
changeset
|
1910 |
} |
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:
diff
changeset
|
1911 |
if (debug) std::cout << "ST [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
1912 |
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:
diff
changeset
|
1913 |
} |
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:
diff
changeset
|
1914 |
|
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:
diff
changeset
|
1915 |
void *fill_candidate_datatypes_c::visit(STN_operator_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:
diff
changeset
|
1916 |
symbol_c *prev_instruction_type, *operand_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:
diff
changeset
|
1917 |
|
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:
diff
changeset
|
1918 |
if (NULL == prev_il_instruction) return NULL; |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1919 |
if (NULL == il_operand) return 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:
diff
changeset
|
1920 |
for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
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:
diff
changeset
|
1921 |
for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
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:
diff
changeset
|
1922 |
prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; |
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:
diff
changeset
|
1923 |
operand_type = il_operand->candidate_datatypes[j]; |
676
ca4f17211251
Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
666
diff
changeset
|
1924 |
if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_ANY_BIT_compatible(operand_type)) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1925 |
add_datatype_to_candidate_list(symbol, prev_instruction_type); |
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:
diff
changeset
|
1926 |
} |
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:
diff
changeset
|
1927 |
} |
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:
diff
changeset
|
1928 |
if (debug) std::cout << "STN [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
1929 |
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:
diff
changeset
|
1930 |
} |
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:
diff
changeset
|
1931 |
|
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:
diff
changeset
|
1932 |
void *fill_candidate_datatypes_c::visit(NOT_operator_c *symbol) { |
470
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1933 |
/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand> |
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1934 |
* NOT [<il_operand>] |
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1935 |
* However, it does not define the semantic of the NOT operation when the <il_operand> is specified. |
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1936 |
* We therefore consider it an error if an il_operand is specified! |
612 | 1937 |
* We do not need to generate an error message. This error will be caught somewhere else! |
470
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1938 |
*/ |
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1939 |
if (NULL == prev_il_instruction) return NULL; |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1940 |
if (NULL == il_operand) return NULL; |
470
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1941 |
for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
666
8ba9ec4bae50
Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
1942 |
if (get_datatype_info_c::is_ANY_BIT_compatible(prev_il_instruction->candidate_datatypes[i])) |
470
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1943 |
add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); |
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1944 |
} |
d2cd05c5e01a
Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents:
467
diff
changeset
|
1945 |
if (debug) std::cout << "NOT_operator [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
1946 |
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:
diff
changeset
|
1947 |
} |
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:
diff
changeset
|
1948 |
|
447
aad0f3e5df33
Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents:
445
diff
changeset
|
1949 |
|
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1950 |
void *fill_candidate_datatypes_c::visit( S_operator_c *symbol) {return handle_S_and_R_operator (symbol, "S", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1951 |
void *fill_candidate_datatypes_c::visit( R_operator_c *symbol) {return handle_S_and_R_operator (symbol, "R", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1952 |
|
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1953 |
void *fill_candidate_datatypes_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "S1", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1954 |
void *fill_candidate_datatypes_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "R1", symbol->called_fb_declaration);} |
489
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1955 |
void *fill_candidate_datatypes_c::visit( CLK_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);} |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1956 |
void *fill_candidate_datatypes_c::visit( CU_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "CU", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1957 |
void *fill_candidate_datatypes_c::visit( CD_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "CD", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1958 |
void *fill_candidate_datatypes_c::visit( PV_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "PV", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1959 |
void *fill_candidate_datatypes_c::visit( IN_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "IN", symbol->called_fb_declaration);} |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
1960 |
void *fill_candidate_datatypes_c::visit( PT_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "PT", symbol->called_fb_declaration);} |
447
aad0f3e5df33
Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents:
445
diff
changeset
|
1961 |
|
483
7f839fb100c1
Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents:
481
diff
changeset
|
1962 |
void *fill_candidate_datatypes_c::visit( AND_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);} |
489
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1963 |
void *fill_candidate_datatypes_c::visit( OR_operator_c *symbol) {return handle_binary_operator( widen_OR_table, symbol, prev_il_instruction, il_operand);} |
483
7f839fb100c1
Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents:
481
diff
changeset
|
1964 |
void *fill_candidate_datatypes_c::visit( XOR_operator_c *symbol) {return handle_binary_operator(widen_XOR_table, symbol, prev_il_instruction, il_operand);} |
7f839fb100c1
Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents:
481
diff
changeset
|
1965 |
void *fill_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);} |
7f839fb100c1
Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents:
481
diff
changeset
|
1966 |
void *fill_candidate_datatypes_c::visit( ORN_operator_c *symbol) {return handle_binary_operator( widen_OR_table, symbol, prev_il_instruction, il_operand);} |
7f839fb100c1
Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents:
481
diff
changeset
|
1967 |
void *fill_candidate_datatypes_c::visit(XORN_operator_c *symbol) {return handle_binary_operator(widen_XOR_table, symbol, prev_il_instruction, il_operand);} |
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:
diff
changeset
|
1968 |
|
489
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1969 |
void *fill_candidate_datatypes_c::visit( ADD_operator_c *symbol) {return handle_binary_operator(widen_ADD_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1970 |
void *fill_candidate_datatypes_c::visit( SUB_operator_c *symbol) {return handle_binary_operator(widen_SUB_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1971 |
void *fill_candidate_datatypes_c::visit( MUL_operator_c *symbol) {return handle_binary_operator(widen_MUL_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1972 |
void *fill_candidate_datatypes_c::visit( DIV_operator_c *symbol) {return handle_binary_operator(widen_DIV_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1973 |
void *fill_candidate_datatypes_c::visit( MOD_operator_c *symbol) {return handle_binary_operator(widen_MOD_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1974 |
|
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1975 |
void *fill_candidate_datatypes_c::visit( GT_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1976 |
void *fill_candidate_datatypes_c::visit( GE_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1977 |
void *fill_candidate_datatypes_c::visit( EQ_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1978 |
void *fill_candidate_datatypes_c::visit( LT_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1979 |
void *fill_candidate_datatypes_c::visit( LE_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1980 |
void *fill_candidate_datatypes_c::visit( NE_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);} |
484
f78750994a82
Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents:
483
diff
changeset
|
1981 |
|
f78750994a82
Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents:
483
diff
changeset
|
1982 |
|
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:
diff
changeset
|
1983 |
|
487 | 1984 |
void *fill_candidate_datatypes_c::handle_conditional_il_flow_control_operator(symbol_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:
diff
changeset
|
1985 |
if (NULL == prev_il_instruction) 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:
diff
changeset
|
1986 |
for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
666
8ba9ec4bae50
Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
1987 |
if (get_datatype_info_c::is_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
1988 |
add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); |
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:
diff
changeset
|
1989 |
} |
487 | 1990 |
return NULL; |
1991 |
} |
|
1992 |
||
489
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1993 |
void *fill_candidate_datatypes_c::visit( CAL_operator_c *symbol) {if (NULL != prev_il_instruction) symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1994 |
void *fill_candidate_datatypes_c::visit( RET_operator_c *symbol) {if (NULL != prev_il_instruction) symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;} |
2c874cccbb44
Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents:
488
diff
changeset
|
1995 |
void *fill_candidate_datatypes_c::visit( JMP_operator_c *symbol) {if (NULL != prev_il_instruction) symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;} |
487 | 1996 |
void *fill_candidate_datatypes_c::visit( CALC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);} |
1997 |
void *fill_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);} |
|
1998 |
void *fill_candidate_datatypes_c::visit( RETC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);} |
|
1999 |
void *fill_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);} |
|
2000 |
void *fill_candidate_datatypes_c::visit( JMPC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);} |
|
2001 |
void *fill_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);} |
|
2002 |
||
2003 |
||
2004 |
||
2005 |
||
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:
diff
changeset
|
2006 |
/* Symbol class handled together with function call checks */ |
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:
diff
changeset
|
2007 |
// void *visit(il_assign_operator_c *symbol, variable_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:
diff
changeset
|
2008 |
/* Symbol class handled together with function call checks */ |
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:
diff
changeset
|
2009 |
// void *visit(il_assign_operator_c *symbol, option, variable_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:
diff
changeset
|
2010 |
|
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:
diff
changeset
|
2011 |
/***************************************/ |
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:
diff
changeset
|
2012 |
/* B.3 - Language ST (Structured Text) */ |
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:
diff
changeset
|
2013 |
/***************************************/ |
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:
diff
changeset
|
2014 |
/***********************/ |
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:
diff
changeset
|
2015 |
/* B 3.1 - Expressions */ |
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:
diff
changeset
|
2016 |
/***********************/ |
933
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2017 |
/* SYM_REF1(deref_expression_c, exp) --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */ |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2018 |
void *fill_candidate_datatypes_c::visit(deref_expression_c *symbol) { |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2019 |
symbol->exp->accept(*this); |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2020 |
|
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2021 |
for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2022 |
/* Determine whether the datatype is a ref_spec_c, as this is the class used as the */ |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2023 |
/* canonical/base datatype of REF_TO types (see search_base_type_c ...) */ |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2024 |
ref_spec_c *ref_spec = dynamic_cast<ref_spec_c *>(symbol->exp->candidate_datatypes[i]); |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2025 |
|
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2026 |
if (NULL != ref_spec) |
935
be4373d07201
Fix bug: add support for dereferencing of REF_TO to REF_TO xxx (e.g.: bool_var := ref_to_ref_to_bool^^;)
mjsousa
parents:
933
diff
changeset
|
2027 |
add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(ref_spec->type_name)); |
933
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2028 |
} |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2029 |
|
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2030 |
return NULL; |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2031 |
} |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2032 |
|
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2033 |
|
936
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2034 |
/* SYM_REF1(deref_operator_c, exp) --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */ |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2035 |
void *fill_candidate_datatypes_c::visit(deref_operator_c *symbol) { |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2036 |
symbol->exp->accept(*this); |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2037 |
|
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2038 |
for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2039 |
/* Determine whether the datatype is a ref_spec_c, as this is the class used as the */ |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2040 |
/* canonical/base datatype of REF_TO types (see search_base_type_c ...) */ |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2041 |
ref_spec_c *ref_spec = dynamic_cast<ref_spec_c *>(symbol->exp->candidate_datatypes[i]); |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2042 |
|
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2043 |
if (NULL != ref_spec) |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2044 |
add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(ref_spec->type_name)); |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2045 |
|
936
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2046 |
} |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2047 |
|
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2048 |
/* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2049 |
* Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2050 |
* in this fill_candidate_datatypes_c itself! |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
2051 |
* This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
2052 |
* we will search for the field_variable of the structured_variable_c. Similarly, it is also used to determine the datatype |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
2053 |
* to which a REF_TO variable points to. |
938
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2054 |
* |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2055 |
* Since the deref_operator_c may be used inside structures, we must narrow it here, if possible! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2056 |
*/ |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2057 |
if (symbol->candidate_datatypes.size() == 1) |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2058 |
// narrow the symbol->datatype for this symbol as explained above! |
31e3b3f2eff1
Do the full fill_candidate/narrow_datatype algorithm for all fields of a structured variable in the fill_candidate_datatypes_c
mjsousa
parents:
936
diff
changeset
|
2059 |
symbol->datatype = symbol->candidate_datatypes[0]; |
942
8739d8259932
Fix bug: set the scope annotation in deref_operators used inside structs
mjsousa
parents:
940
diff
changeset
|
2060 |
|
8739d8259932
Fix bug: set the scope annotation in deref_operators used inside structs
mjsousa
parents:
940
diff
changeset
|
2061 |
/* Since the deref_operator_c may be used inside structures, we must handle set the 'scope' annotation here too! */ |
8739d8259932
Fix bug: set the scope annotation in deref_operators used inside structs
mjsousa
parents:
940
diff
changeset
|
2062 |
symbol->scope = symbol->exp->scope; |
936
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2063 |
|
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2064 |
return NULL; |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2065 |
} |
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2066 |
|
0f7bcc160568
Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents:
935
diff
changeset
|
2067 |
|
873
dea39ef02847
Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents:
854
diff
changeset
|
2068 |
/* SYM_REF1(ref_expression_c, exp) --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */ |
dea39ef02847
Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents:
854
diff
changeset
|
2069 |
void *fill_candidate_datatypes_c::visit( ref_expression_c *symbol) { |
933
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2070 |
/* We must first determine the datatype of the expression passed to the REF() operator, with no ambiguities! |
911
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2071 |
* To do this, we could use the complete standard fill/narrow algorithm for determining the datatype |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2072 |
* of the expression. This is actually possible, as nothing stops us from directly calling the narrow_candidate_datatypes_c |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2073 |
* from this method inside fill_candidate_datatypes_c, to complete the fill/narrow algorithm on this |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2074 |
* expression only. |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2075 |
* However, for the moment we take a shortcut, and set the expression's "datatype" directly, even though this |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2076 |
* should really only be done in narrow_candidate_datatypes_c. This is possible because the expression should be |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2077 |
* an lvalue (assuming source code has no bugs), with only one candidate datatype. |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2078 |
* |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2079 |
* (We should really check whether the expression is an lvalue. For now, leave it for the future!) |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2080 |
* |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2081 |
* Note, however, that array variables are also lvalues, and they may containg complex |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2082 |
* expressions that include function calls in their indexes. These complex expressions must therefore still be |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2083 |
* analysed using the standard fill/narrow algorithm... |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2084 |
*/ |
873
dea39ef02847
Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents:
854
diff
changeset
|
2085 |
symbol->exp->accept(*this); |
911
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2086 |
if (symbol->exp->candidate_datatypes.size() == 1) |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2087 |
symbol->exp->datatype = symbol->exp->candidate_datatypes[0]; |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2088 |
|
933
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2089 |
/* Create a new object of ref_spec_c, as this is the class used as the */ |
76324f461aed
Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents:
921
diff
changeset
|
2090 |
/* canonical/base datatype of REF_TO types (see search_base_type_c ...) */ |
911
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2091 |
ref_spec_c *ref_spec = new ref_spec_c(symbol->exp->datatype); |
ef3347dbfa0c
Change REF() operator to return the correct REF_TO datatype datatype.
mjsousa
parents:
909
diff
changeset
|
2092 |
add_datatype_to_candidate_list(symbol, ref_spec); |
873
dea39ef02847
Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents:
854
diff
changeset
|
2093 |
return NULL; |
dea39ef02847
Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents:
854
diff
changeset
|
2094 |
} |
dea39ef02847
Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents:
854
diff
changeset
|
2095 |
|
652
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2096 |
void *fill_candidate_datatypes_c::visit( or_expression_c *symbol) {return handle_binary_expression (widen_OR_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2097 |
void *fill_candidate_datatypes_c::visit( xor_expression_c *symbol) {return handle_binary_expression (widen_XOR_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2098 |
void *fill_candidate_datatypes_c::visit( and_expression_c *symbol) {return handle_binary_expression (widen_AND_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2099 |
|
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2100 |
void *fill_candidate_datatypes_c::visit( equ_expression_c *symbol) {return handle_equality_comparison(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2101 |
void *fill_candidate_datatypes_c::visit(notequ_expression_c *symbol) {return handle_equality_comparison(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2102 |
void *fill_candidate_datatypes_c::visit( lt_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2103 |
void *fill_candidate_datatypes_c::visit( gt_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2104 |
void *fill_candidate_datatypes_c::visit( le_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2105 |
void *fill_candidate_datatypes_c::visit( ge_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2106 |
|
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2107 |
void *fill_candidate_datatypes_c::visit( add_expression_c *symbol) {return handle_binary_expression (widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2108 |
void *fill_candidate_datatypes_c::visit( sub_expression_c *symbol) {return handle_binary_expression (widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2109 |
void *fill_candidate_datatypes_c::visit( mul_expression_c *symbol) {return handle_binary_expression (widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2110 |
void *fill_candidate_datatypes_c::visit( div_expression_c *symbol) {return handle_binary_expression (widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2111 |
void *fill_candidate_datatypes_c::visit( mod_expression_c *symbol) {return handle_binary_expression (widen_MOD_table, symbol, symbol->l_exp, symbol->r_exp);} |
7fe1533d2260
Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
651
diff
changeset
|
2112 |
void *fill_candidate_datatypes_c::visit( power_expression_c *symbol) {return handle_binary_expression (widen_EXPT_table, symbol, symbol->l_exp, symbol->r_exp);} |
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:
diff
changeset
|
2113 |
|
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:
diff
changeset
|
2114 |
|
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:
diff
changeset
|
2115 |
void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) { |
435
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2116 |
/* NOTE: The standard defines the syntax for this 'negation' operation, but |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2117 |
* does not define the its semantics. |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2118 |
* |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2119 |
* We could be tempted to consider that the semantics of the |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2120 |
* 'negation' operation are similar/identical to the semantics of the |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2121 |
* SUB expression/operation. This would include assuming that the |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2122 |
* possible datatypes for the 'negation' operation is also |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2123 |
* the same as those for the SUB expression/operation, namely ANY_MAGNITUDE. |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2124 |
* |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2125 |
* However, this would then mean that the following ST code would be |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2126 |
* syntactically and semantically correct: |
650 | 2127 |
* VAR uint_var : UINT END_VAR; |
435
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2128 |
* uint_var := - (uint_var); |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2129 |
* |
650 | 2130 |
* Assuming uint_var is not 0, the standard states that the above code should result in a |
2131 |
* runtime error since the operation will result in an overflow. Since the above operation |
|
2132 |
* is only valid when uint_var=0, it would probably make more sense for the programmer to |
|
2133 |
* use if (uint_var=0) ..., so we will simply assume that the above statement simply |
|
2134 |
* does not make sense in any situation (whether or not uint_var is 0), and therefore |
|
2135 |
* we will not allow it. |
|
2136 |
* (Notice that doing so does not ago against the standard, as the standard does not |
|
2137 |
* explicitly define the semantics of the NEG operator, nor the data types it may accept |
|
2138 |
* as input. We are simply assuming that the NEG operator may not be applied to unsigned |
|
2139 |
* ANY_NUM data types!). |
|
435
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2140 |
* |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2141 |
* It is much easier for the compiler to detect this at compile time, |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2142 |
* and it is probably safer to the resulting code too. |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2143 |
* |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2144 |
* To detect these tyes of errors at compile time, the easisest solution |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2145 |
* is to only allow ANY_NUM datatytpes that are signed. |
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2146 |
* So, that is what we do here! |
650 | 2147 |
* |
2148 |
* NOTE: The above argument also applies to the neg_integer_c method! |
|
435
82cb6a64a763
Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents:
431
diff
changeset
|
2149 |
*/ |
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:
diff
changeset
|
2150 |
symbol->exp->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:
diff
changeset
|
2151 |
for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
666
8ba9ec4bae50
Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
2152 |
if (get_datatype_info_c::is_ANY_signed_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i])) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
2153 |
add_datatype_to_candidate_list(symbol, symbol->exp->candidate_datatypes[i]); |
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:
diff
changeset
|
2154 |
} |
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:
diff
changeset
|
2155 |
if (debug) std::cout << "neg [" << symbol->exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
2156 |
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:
diff
changeset
|
2157 |
} |
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:
diff
changeset
|
2158 |
|
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:
diff
changeset
|
2159 |
|
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:
diff
changeset
|
2160 |
void *fill_candidate_datatypes_c::visit(not_expression_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:
diff
changeset
|
2161 |
symbol->exp->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:
diff
changeset
|
2162 |
for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
666
8ba9ec4bae50
Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
2163 |
if (get_datatype_info_c::is_ANY_BIT_compatible(symbol->exp->candidate_datatypes[i])) |
465
b52ec62773db
Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents:
464
diff
changeset
|
2164 |
add_datatype_to_candidate_list(symbol, symbol->exp->candidate_datatypes[i]); |
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:
diff
changeset
|
2165 |
} |
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:
diff
changeset
|
2166 |
if (debug) std::cout << "not [" << symbol->exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
2167 |
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:
diff
changeset
|
2168 |
} |
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:
diff
changeset
|
2169 |
|
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:
diff
changeset
|
2170 |
|
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:
diff
changeset
|
2171 |
void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) { |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2172 |
if (NULL != symbol->formal_param_list) symbol-> formal_param_list->accept(*this); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2173 |
else if (NULL != symbol->nonformal_param_list) symbol->nonformal_param_list->accept(*this); |
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:
diff
changeset
|
2174 |
else ERROR; |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2175 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2176 |
generic_function_call_t fcall_param = { |
763
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2177 |
function_name: symbol->function_name, |
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2178 |
nonformal_operand_list: symbol->nonformal_param_list, |
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2179 |
formal_operand_list: symbol->formal_param_list, |
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2180 |
POU_type: generic_function_call_t::POU_function, |
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2181 |
candidate_functions: symbol->candidate_functions, |
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2182 |
called_function_declaration: symbol->called_function_declaration, |
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2183 |
extensible_param_count: symbol->extensible_param_count |
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2184 |
}; |
763
2779f4a5f305
Fix struct generic_function_call_t initialize style.
Manuele Conti <conti.ma@alice.it>
parents:
738
diff
changeset
|
2185 |
|
438
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2186 |
handle_function_call(symbol, fcall_param); |
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2187 |
|
744b125d911e
Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents:
437
diff
changeset
|
2188 |
if (debug) std::cout << "function_invocation_c [" << symbol->candidate_datatypes.size() << "] result.\n"; |
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:
diff
changeset
|
2189 |
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:
diff
changeset
|
2190 |
} |
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:
diff
changeset
|
2191 |
|
421
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
2192 |
|
840cb1e1e177
Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
420
diff
changeset
|
2193 |
|
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:
diff
changeset
|
2194 |
/********************/ |
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:
diff
changeset
|
2195 |
/* B 3.2 Statements */ |
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:
diff
changeset
|
2196 |
/********************/ |
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:
diff
changeset
|
2197 |
// SYM_LIST(statement_list_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:
diff
changeset
|
2198 |
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list. |
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:
diff
changeset
|
2199 |
* We do not need to do anything here... |
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:
diff
changeset
|
2200 |
*/ |
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:
diff
changeset
|
2201 |
// void *fill_candidate_datatypes_c::visit(statement_list_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:
diff
changeset
|
2202 |
|
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:
diff
changeset
|
2203 |
|
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:
diff
changeset
|
2204 |
/*********************************/ |
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:
diff
changeset
|
2205 |
/* B 3.2.1 Assignment Statements */ |
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:
diff
changeset
|
2206 |
/*********************************/ |
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:
diff
changeset
|
2207 |
void *fill_candidate_datatypes_c::visit(assignment_statement_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:
diff
changeset
|
2208 |
symbol_c *left_type, *right_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:
diff
changeset
|
2209 |
symbol->l_exp->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:
diff
changeset
|
2210 |
symbol->r_exp->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:
diff
changeset
|
2211 |
for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { |
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:
diff
changeset
|
2212 |
for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { |
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:
diff
changeset
|
2213 |
left_type = symbol->l_exp->candidate_datatypes[i]; |
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:
diff
changeset
|
2214 |
right_type = symbol->r_exp->candidate_datatypes[j]; |
676
ca4f17211251
Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
666
diff
changeset
|
2215 |
if (get_datatype_info_c::is_type_equal(left_type, right_type)) |
919
8da635655f37
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents:
911
diff
changeset
|
2216 |
add_datatype_to_candidate_list(symbol, left_type); // NOTE: Must use left_type, as the right_type may be the 'NULL' reference! (see comment in visit(ref_value_null_literal_c)) */ |
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:
diff
changeset
|
2217 |
} |
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:
diff
changeset
|
2218 |
} |
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:
diff
changeset
|
2219 |
if (debug) std::cout << ":= [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
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:
diff
changeset
|
2220 |
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:
diff
changeset
|
2221 |
} |
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:
diff
changeset
|
2222 |
|
418
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2223 |
/*****************************************/ |
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2224 |
/* B 3.2.2 Subprogram Control Statements */ |
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2225 |
/*****************************************/ |
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2226 |
void *fill_candidate_datatypes_c::visit(fb_invocation_c *symbol) { |
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
938
diff
changeset
|
2227 |
symbol_c *fb_decl = search_var_instance_decl->get_basetype_decl(symbol->fb_name); |
834
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
2228 |
if (! get_datatype_info_c::is_function_block(fb_decl )) fb_decl = NULL; |
783ef40344dd
Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents:
827
diff
changeset
|
2229 |
if (NULL == fb_decl) ERROR; /* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */ |
455
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
2230 |
|
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
2231 |
if (symbol-> formal_param_list != NULL) symbol->formal_param_list->accept(*this); |
933c0dccc82f
Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents:
454
diff
changeset
|
2232 |
if (symbol->nonformal_param_list != NULL) symbol->nonformal_param_list->accept(*this); |
424
43d73e28eca8
Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents:
422
diff
changeset
|
2233 |
|
431
5792016eedd8
More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
429
diff
changeset
|
2234 |
/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that |
5792016eedd8
More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
429
diff
changeset
|
2235 |
* we have a datat type incompatibility error, so setting it to the correct fb_decl is actually safe, |
5792016eedd8
More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
429
diff
changeset
|
2236 |
* as the compiler will never reach the compilation stage! |
5792016eedd8
More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
429
diff
changeset
|
2237 |
*/ |
5792016eedd8
More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents:
429
diff
changeset
|
2238 |
symbol->called_fb_declaration = fb_decl; |
424
43d73e28eca8
Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents:
422
diff
changeset
|
2239 |
|
418
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2240 |
if (debug) std::cout << "FB [] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2241 |
return NULL; |
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2242 |
} |
2ac41d2cba91
Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents:
417
diff
changeset
|
2243 |
|
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:
diff
changeset
|
2244 |
|
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:
diff
changeset
|
2245 |
|
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:
diff
changeset
|
2246 |
/********************************/ |
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:
diff
changeset
|
2247 |
/* B 3.2.3 Selection Statements */ |
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:
diff
changeset
|
2248 |
/********************************/ |
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:
diff
changeset
|
2249 |
void *fill_candidate_datatypes_c::visit(if_statement_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:
diff
changeset
|
2250 |
symbol->expression->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:
diff
changeset
|
2251 |
if (NULL != symbol->statement_list) |
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:
diff
changeset
|
2252 |
symbol->statement_list->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:
diff
changeset
|
2253 |
if (NULL != symbol->elseif_statement_list) |
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:
diff
changeset
|
2254 |
symbol->elseif_statement_list->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:
diff
changeset
|
2255 |
if (NULL != symbol->else_statement_list) |
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:
diff
changeset
|
2256 |
symbol->else_statement_list->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:
diff
changeset
|
2257 |
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:
diff
changeset
|
2258 |
} |
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:
diff
changeset
|
2259 |
|
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:
diff
changeset
|
2260 |
|
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:
diff
changeset
|
2261 |
void *fill_candidate_datatypes_c::visit(elseif_statement_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:
diff
changeset
|
2262 |
symbol->expression->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:
diff
changeset
|
2263 |
if (NULL != symbol->statement_list) |
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:
diff
changeset
|
2264 |
symbol->statement_list->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:
diff
changeset
|
2265 |
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:
diff
changeset
|
2266 |
} |
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:
diff
changeset
|
2267 |
|
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:
diff
changeset
|
2268 |
/* CASE expression OF case_element_list ELSE statement_list END_CASE */ |
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:
diff
changeset
|
2269 |
// SYM_REF3(case_statement_c, expression, case_element_list, statement_list) |
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:
diff
changeset
|
2270 |
void *fill_candidate_datatypes_c::visit(case_statement_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:
diff
changeset
|
2271 |
symbol->expression->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:
diff
changeset
|
2272 |
if (NULL != symbol->case_element_list) |
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:
diff
changeset
|
2273 |
symbol->case_element_list->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:
diff
changeset
|
2274 |
if (NULL != symbol->statement_list) |
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:
diff
changeset
|
2275 |
symbol->statement_list->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:
diff
changeset
|
2276 |
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:
diff
changeset
|
2277 |
} |
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:
diff
changeset
|
2278 |
|
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:
diff
changeset
|
2279 |
|
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:
diff
changeset
|
2280 |
/* helper symbol for case_statement */ |
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:
diff
changeset
|
2281 |
// SYM_LIST(case_element_list_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:
diff
changeset
|
2282 |
/* NOTE: visitor method for case_element_list_c is not required since we inherit from iterator_visitor_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:
diff
changeset
|
2283 |
|
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:
diff
changeset
|
2284 |
/* case_list ':' statement_list */ |
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:
diff
changeset
|
2285 |
// SYM_REF2(case_element_c, case_list, statement_list) |
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:
diff
changeset
|
2286 |
/* NOTE: visitor method for case_element_c is not required since we inherit from iterator_visitor_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:
diff
changeset
|
2287 |
|
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:
diff
changeset
|
2288 |
// SYM_LIST(case_list_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:
diff
changeset
|
2289 |
/* NOTE: visitor method for case_list_c is not required since we inherit from iterator_visitor_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:
diff
changeset
|
2290 |
|
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:
diff
changeset
|
2291 |
/********************************/ |
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:
diff
changeset
|
2292 |
/* B 3.2.4 Iteration Statements */ |
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:
diff
changeset
|
2293 |
/********************************/ |
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:
diff
changeset
|
2294 |
|
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:
diff
changeset
|
2295 |
void *fill_candidate_datatypes_c::visit(for_statement_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:
diff
changeset
|
2296 |
symbol->control_variable->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:
diff
changeset
|
2297 |
symbol->beg_expression->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:
diff
changeset
|
2298 |
symbol->end_expression->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:
diff
changeset
|
2299 |
if (NULL != symbol->by_expression) |
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:
diff
changeset
|
2300 |
symbol->by_expression->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:
diff
changeset
|
2301 |
if (NULL != symbol->statement_list) |
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:
diff
changeset
|
2302 |
symbol->statement_list->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:
diff
changeset
|
2303 |
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:
diff
changeset
|
2304 |
} |
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:
diff
changeset
|
2305 |
|
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:
diff
changeset
|
2306 |
|
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:
diff
changeset
|
2307 |
void *fill_candidate_datatypes_c::visit(while_statement_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:
diff
changeset
|
2308 |
symbol->expression->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:
diff
changeset
|
2309 |
if (NULL != symbol->statement_list) |
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:
diff
changeset
|
2310 |
symbol->statement_list->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:
diff
changeset
|
2311 |
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:
diff
changeset
|
2312 |
} |
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:
diff
changeset
|
2313 |
|
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:
diff
changeset
|
2314 |
|
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:
diff
changeset
|
2315 |
void *fill_candidate_datatypes_c::visit(repeat_statement_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:
diff
changeset
|
2316 |
symbol->expression->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:
diff
changeset
|
2317 |
if (NULL != symbol->statement_list) |
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:
diff
changeset
|
2318 |
symbol->statement_list->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:
diff
changeset
|
2319 |
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:
diff
changeset
|
2320 |
} |
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:
diff
changeset
|
2321 |
|
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:
diff
changeset
|
2322 |
|
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:
diff
changeset
|
2323 |
|
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:
diff
changeset
|
2324 |
|
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:
diff
changeset
|
2325 |
|
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:
diff
changeset
|
2326 |