author | Edouard Tisserant |
Wed, 24 Nov 2021 08:58:58 +0100 | |
changeset 1095 | 36bbd0b64816 |
parent 1041 | 56ebe2a31b5b |
permissions | -rw-r--r-- |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
3 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
265
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
6 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
10 |
* (at your option) any later version. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
15 |
* GNU General Public License for more details. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
19 |
* |
181 | 20 |
* |
21 |
* This code is made available on the understanding that it will not be |
|
22 |
* used in safety-critical situations without a full and competent review. |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
26 |
* An IEC 61131-3 compiler. |
181 | 27 |
* |
28 |
* Based on the |
|
29 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
||
34 |
/* |
|
35 |
* Function parameter iterator. |
|
36 |
* Iterate through the in/out parameters of a function declaration. |
|
37 |
* Function blocks are also suported. |
|
38 |
* |
|
39 |
* This is part of the 4th stage that generates |
|
40 |
* a c++ source program equivalent to the IL and ST |
|
41 |
* code. |
|
42 |
*/ |
|
43 |
||
44 |
/* Given a function_declaration_c, iterate through each |
|
45 |
* function in/out/inout parameter, returning the name |
|
46 |
* of each parameter...function_param_iterator_c |
|
47 |
*/ |
|
48 |
||
49 |
||
595
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
50 |
#include "function_param_iterator.hh" /* no longer required, aready included by absyntax_utils.hh */ |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
51 |
#include "spec_init_separator.hh" /* no longer required, aready included by absyntax_utils.hh */ |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
52 |
#include <stdlib.h> /* required for strtol() */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
53 |
#include <string.h> |
181 | 54 |
#include <strings.h> |
595
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
55 |
#include <limits> // required for std::numeric_limits< XXX >::max() |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
56 |
#include <errno.h> // required for errno |
596
4efb11e44065
Add ERROR_MSG macro && move extract_XXX() functions to constant_folding.cc
Mario de Sousa <msousa@fe.up.pt>
parents:
595
diff
changeset
|
57 |
#include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
181 | 58 |
|
59 |
//#define DEBUG |
|
60 |
#ifdef DEBUG |
|
61 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
62 |
#else |
|
63 |
#define TRACE(classname) |
|
64 |
#endif |
|
65 |
||
66 |
||
67 |
||
595
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
68 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
69 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
70 |
/* NOTE: The following function is not really needed, as we could get the value that constant_folding_c determined for this |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
71 |
* integer. Remember that currently constant_folding_c runs before this class is ever used/called! |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
72 |
* However, I (Mario) do not currently feel it would be a good idea to restrict the use of this |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
73 |
* abstract syntax utility to only after the constant_folding_c has had a chance to fill in the constant value |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
74 |
* of this symbol. |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
75 |
* For this reason only, I have opted to let this abstract syntax utility have its own private copy of the |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
76 |
* extract_integer() function. |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
77 |
* Another aspect that makes this OK is that this function will only be used to extract the integer value of the |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
78 |
* index for the first extensible paramater (examples follow shortly). Since this is an extension to IEC 61131-3 |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
79 |
* that we created to allow us to handle extensible functions with very little hard coding, it is OK if we |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
80 |
* impose extra/different limits on how an integer may be legally be formated in this case. This will also |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
81 |
* only show up in code that describes the interface to the standard function of IEC 61131-3, which the user |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
82 |
* will not ever get to see. We write that IEC 61131-3 code ourselves! |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
83 |
* |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
84 |
* Example of source code we will be parsing and analysing: |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
85 |
* |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
86 |
* FUNCTION ADD : REAL VAR_INPUT IN 1 .. : REAL; END_VAR RETURN; END_FUNCTION |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
87 |
* ^^^ |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
88 |
* |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
89 |
* FUNCTION MUX : REAL VAR_INPUT K : USINT; IN 0 .. : REAL; END_VAR RETURN; END_FUNCTION |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
90 |
* ^^^ |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
91 |
* |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
92 |
* Basically, currently this will only be either a '0' or a '1' !! |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
93 |
*/ |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
94 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
95 |
/* NOTE: it must ignore underscores! */ |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
96 |
static int extract_first_index_value(symbol_c *sym) { |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
97 |
std::string str = ""; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
98 |
integer_c *integer; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
99 |
long int ret; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
100 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
101 |
if ((integer = dynamic_cast<integer_c *>(sym)) == NULL) ERROR; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
102 |
for(unsigned int i = 0; i < strlen(integer->value); i++) |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
103 |
if (integer->value[i] != '_') str += integer->value[i]; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
104 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
105 |
errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly! |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
106 |
ret = strtol(str.c_str(), NULL, 10); |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
107 |
if (errno != 0) ERROR; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
108 |
if (ret < 0) ERROR; // the following code assumes that the first index will never be negative! |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
109 |
if (ret > std::numeric_limits< int >::max()) ERROR; // output of this function is only an int!! |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
110 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
111 |
return ret; |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
112 |
} |
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
113 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
114 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
115 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
116 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
117 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
118 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
119 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
120 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
121 |
|
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
122 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
123 |
/* compare the name of two __extensible__ function parameters. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
124 |
* The usual use case is to have one of the parameters as used |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
125 |
* in the function declaration, and another as used in a formal function call. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
126 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
127 |
* Will return: |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
128 |
* < 0 : if two parameters are not compatible, or one is invalid |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
129 |
* >= 0 : if both parameters .......... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
130 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
131 |
/* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
132 |
* ("in", "i0") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
133 |
* ("in1", "in") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
134 |
* ("in", "in") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
135 |
* ("in", "inw") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
136 |
* ("in", "in10.4") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
137 |
* ("in", "in10e") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
138 |
* ("in", "") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
139 |
* ("", "in10e") -> returns error (<0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
140 |
* ("in", "in0") -> returns 0 |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
141 |
* ("in", "in9") -> returns 9 |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
142 |
* ("in", "in42") -> returns 42 |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
143 |
* ("in", "in-42") -> returns -42 (error!) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
144 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
145 |
int function_param_iterator_c::cmp_extparam_names(const char* s1, const char* s2) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
146 |
int res; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
147 |
char *endptr; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
148 |
int len; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
149 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
150 |
if ((s1 == NULL) || (s2 == NULL) || (*s1 == '\0') || (*s2 == '\0')) return -1; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
151 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
152 |
len = strlen(s1); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
153 |
if (strncasecmp(s1, s2, len)) return -2; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
154 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
155 |
s1 = &s2[len]; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
156 |
if (*s1 == '\0') return -3; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
157 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
158 |
res = strtol(s1, &endptr, 10); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
159 |
if (*endptr != '\0') return -4; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
160 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
161 |
return res; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
162 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
163 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
164 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
165 |
|
181 | 166 |
void* function_param_iterator_c::handle_param_list(list_c *list) { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
167 |
switch (current_operation) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
168 |
case iterate_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
169 |
if (next_param <= param_count + list->n) |
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
810
diff
changeset
|
170 |
return list->get_element(next_param - param_count - 1); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
171 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
172 |
/* the desired param is not on this list... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
173 |
param_count += list->n; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
174 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
175 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
176 |
case search_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
177 |
for(int i = 0; i < list->n; i++) { |
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
810
diff
changeset
|
178 |
symbol_c *sym = list->get_element(i); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
179 |
extensible_input_parameter_c *extensible_parameter = dynamic_cast<extensible_input_parameter_c *>(sym); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
180 |
if (extensible_parameter != NULL) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
181 |
sym = extensible_parameter->var_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
182 |
current_param_is_extensible = true; |
595
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
183 |
_first_extensible_param_index = extract_first_index_value(extensible_parameter->first_index); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
184 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
185 |
identifier_c *variable_name = dynamic_cast<identifier_c *>(sym); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
186 |
if (variable_name == NULL) ERROR; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
187 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
188 |
if (!current_param_is_extensible) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
189 |
if (strcasecmp(search_param_name->value, variable_name->value) == 0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
190 |
/* FOUND! This is the same parameter!! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
191 |
return (void *)variable_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
192 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
193 |
if (current_param_is_extensible) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
194 |
current_extensible_param_index = cmp_extparam_names(variable_name->value, search_param_name->value); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
195 |
if (current_extensible_param_index >= 0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
196 |
/* FOUND! This is a compatible extensible parameter!! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
197 |
return (void *)variable_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
198 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
199 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
200 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
201 |
} /* switch */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
202 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
203 |
/* Not found! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
204 |
return NULL; |
181 | 205 |
} |
206 |
||
207 |
void* function_param_iterator_c::handle_single_param(symbol_c *var_name) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
208 |
switch (current_operation) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
209 |
case iterate_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
210 |
param_count++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
211 |
if (next_param == param_count) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
212 |
return var_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
213 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
214 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
215 |
case search_op: |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
216 |
extensible_input_parameter_c *extensible_parameter = dynamic_cast<extensible_input_parameter_c *>(var_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
217 |
if (extensible_parameter != NULL) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
218 |
var_name = extensible_parameter->var_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
219 |
current_param_is_extensible = true; |
595
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
220 |
_first_extensible_param_index = extract_first_index_value(extensible_parameter->first_index); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
221 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
222 |
identifier_c *variable_name = dynamic_cast<identifier_c *>(var_name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
223 |
if (variable_name == NULL) ERROR; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
224 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
225 |
if (!current_param_is_extensible) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
226 |
if (strcasecmp(search_param_name->value, variable_name->value) == 0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
227 |
/* FOUND! This is the same parameter!! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
228 |
return (void *)variable_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
229 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
230 |
if (current_param_is_extensible) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
231 |
current_extensible_param_index = cmp_extparam_names(variable_name->value, search_param_name->value); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
232 |
if (current_extensible_param_index >= 0) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
233 |
/* FOUND! This is a compatible extensible parameter!! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
234 |
return (void *)variable_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
235 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
236 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
237 |
} /* switch */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
238 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
239 |
/* Not found! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
240 |
return NULL; |
181 | 241 |
} |
242 |
||
243 |
void* function_param_iterator_c::iterate_list(list_c *list) { |
|
244 |
void *res; |
|
245 |
for (int i = 0; i < list->n; i++) { |
|
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
810
diff
changeset
|
246 |
res = list->get_element(i)->accept(*this); |
181 | 247 |
if (res != NULL) |
248 |
return res; |
|
249 |
} |
|
250 |
return NULL; |
|
251 |
} |
|
252 |
||
253 |
/* start off at the first parameter once again... */ |
|
254 |
void function_param_iterator_c::reset(void) { |
|
255 |
next_param = param_count = 0; |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
256 |
_first_extensible_param_index = -1; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
257 |
current_param_is_extensible = false; |
181 | 258 |
current_param_name = NULL; |
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:
350
diff
changeset
|
259 |
current_param_type = NULL; |
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:
350
diff
changeset
|
260 |
current_param_default_value = NULL; |
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:
350
diff
changeset
|
261 |
last_returned_parameter = NULL; /* the last parameter returned by search() or next() */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
262 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
263 |
|
181 | 264 |
|
265 |
/* initialise the iterator object. |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
266 |
* We must be given a reference to one of the following |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
267 |
* - function_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
268 |
* - function_block_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
269 |
* - program_declaration_c |
181 | 270 |
* that will be analysed... |
271 |
*/ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
272 |
function_param_iterator_c::function_param_iterator_c(symbol_c *pou_decl) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
273 |
/* do some consistency checks... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
274 |
function_declaration_c * f_decl = dynamic_cast<function_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
275 |
function_block_declaration_c *fb_decl = dynamic_cast<function_block_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
276 |
program_declaration_c * p_decl = dynamic_cast<program_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
277 |
|
426
78f31e12fc52
Better identification of erros in function/FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
424
diff
changeset
|
278 |
if ((NULL == f_decl) && (NULL == fb_decl) && (NULL == p_decl)) |
78f31e12fc52
Better identification of erros in function/FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
424
diff
changeset
|
279 |
ERROR; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
280 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
281 |
/* OK. Now initialise this object... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
282 |
this->f_decl = pou_decl; |
181 | 283 |
reset(); |
284 |
} |
|
285 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
286 |
|
181 | 287 |
|
288 |
/* Skip to the next parameter. After object creation, |
|
289 |
* the object references on parameter _before_ the first, so |
|
290 |
* this function must be called once to get the object to |
|
291 |
* reference the first parameter... |
|
292 |
* |
|
293 |
* Returns the parameter's name! |
|
294 |
*/ |
|
295 |
identifier_c *function_param_iterator_c::next(void) { |
|
296 |
void *res; |
|
297 |
identifier_c *identifier; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
298 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
299 |
if (current_param_is_extensible) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
300 |
current_extensible_param_index++; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
301 |
return current_param_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
302 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
303 |
|
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:
350
diff
changeset
|
304 |
last_returned_parameter = NULL; |
181 | 305 |
param_count = 0; |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
306 |
en_eno_param_implicit = false; |
181 | 307 |
next_param++; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
308 |
current_operation = function_param_iterator_c::iterate_op; |
181 | 309 |
res = f_decl->accept(*this); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
310 |
if (res == NULL) |
181 | 311 |
return NULL; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
312 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
313 |
symbol_c *sym = (symbol_c *)res; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
314 |
extensible_input_parameter_c *extensible_parameter = dynamic_cast<extensible_input_parameter_c *>(sym); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
315 |
if (extensible_parameter != NULL) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
316 |
sym = extensible_parameter->var_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
317 |
current_param_is_extensible = true; |
595
c41975a290ce
Add independent extract_integer() function (preparing to remove extract_XXX() from absyntax_utils.cc)
Mario de Sousa <msousa@fe.up.pt>
parents:
587
diff
changeset
|
318 |
_first_extensible_param_index = extract_first_index_value(extensible_parameter->first_index); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
319 |
current_extensible_param_index = _first_extensible_param_index; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
320 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
321 |
identifier = dynamic_cast<identifier_c *>(sym); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
322 |
if (identifier == NULL) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
323 |
ERROR; |
181 | 324 |
current_param_name = identifier; |
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:
350
diff
changeset
|
325 |
last_returned_parameter = current_param_name; |
181 | 326 |
return current_param_name; |
327 |
} |
|
328 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
329 |
/* Search for the value passed to the parameter named <param_name>... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
330 |
identifier_c *function_param_iterator_c::search(symbol_c *param_name) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
331 |
if (NULL == param_name) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
332 |
search_param_name = dynamic_cast<identifier_c *>(param_name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
333 |
if (NULL == search_param_name) ERROR; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
334 |
en_eno_param_implicit = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
335 |
current_param_is_extensible = false; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
336 |
current_operation = function_param_iterator_c::search_op; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
337 |
void *res = f_decl->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
338 |
identifier_c *res_param_name = dynamic_cast<identifier_c *>((symbol_c *)res); |
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:
350
diff
changeset
|
339 |
last_returned_parameter = res_param_name; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
340 |
return res_param_name; |
181 | 341 |
} |
342 |
||
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:
426
diff
changeset
|
343 |
identifier_c *function_param_iterator_c::search(const char *param_name) { |
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:
426
diff
changeset
|
344 |
identifier_c param_name_id(param_name); |
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:
426
diff
changeset
|
345 |
return search(¶m_name_id); |
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:
426
diff
changeset
|
346 |
} |
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:
426
diff
changeset
|
347 |
|
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:
426
diff
changeset
|
348 |
|
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:
426
diff
changeset
|
349 |
|
181 | 350 |
/* Returns the currently referenced parameter's default value, |
351 |
* or NULL if none is specified in the function declrataion itself. |
|
352 |
*/ |
|
353 |
symbol_c *function_param_iterator_c::default_value(void) { |
|
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:
350
diff
changeset
|
354 |
if (NULL == last_returned_parameter) |
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:
350
diff
changeset
|
355 |
return NULL; |
181 | 356 |
return current_param_default_value; |
357 |
} |
|
358 |
||
359 |
/* Returns the currently referenced parameter's type name. */ |
|
360 |
symbol_c *function_param_iterator_c::param_type(void) { |
|
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:
350
diff
changeset
|
361 |
if (NULL == last_returned_parameter) |
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:
350
diff
changeset
|
362 |
return NULL; |
181 | 363 |
return current_param_type; |
364 |
} |
|
365 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
366 |
/* Returns if currently referenced parameter is an implicit defined EN/ENO parameter. */ |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
367 |
bool function_param_iterator_c::is_en_eno_param_implicit(void) { |
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:
350
diff
changeset
|
368 |
if (NULL == last_returned_parameter) |
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:
350
diff
changeset
|
369 |
ERROR; |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
370 |
return en_eno_param_implicit; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
371 |
} |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
372 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
373 |
/* Returns if currently referenced parameter is an extensible parameter. */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
374 |
/* extensible paramters only occur in some standard functions, e.g. AND(word#34, word#44, word#65); */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
375 |
bool function_param_iterator_c::is_extensible_param(void) { |
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:
350
diff
changeset
|
376 |
if (NULL == last_returned_parameter) |
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:
350
diff
changeset
|
377 |
ERROR; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
378 |
return current_param_is_extensible; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
379 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
380 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
381 |
/* Returns the index of the current extensible parameter. */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
382 |
/* If the current parameter is not an extensible paramter, returns -1 */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
383 |
int function_param_iterator_c::extensible_param_index(void) { |
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:
350
diff
changeset
|
384 |
if (NULL == last_returned_parameter) |
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:
350
diff
changeset
|
385 |
ERROR; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
386 |
return (current_param_is_extensible? current_extensible_param_index : -1); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
387 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
388 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
389 |
/* Returns the index of the first extensible parameter, or -1 if no extensible parameter found. */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
390 |
/* WARNING: Will only return the correct value _after_ an extensible parameter has been found! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
391 |
int function_param_iterator_c::first_extensible_param_index(void) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
392 |
return _first_extensible_param_index; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
393 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
394 |
|
181 | 395 |
/* Returns the currently referenced parameter's data passing direction. |
396 |
* i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT |
|
397 |
*/ |
|
398 |
function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) { |
|
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:
350
diff
changeset
|
399 |
if (NULL == last_returned_parameter) |
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:
350
diff
changeset
|
400 |
ERROR; |
181 | 401 |
return current_param_direction; |
402 |
} |
|
403 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
404 |
void *function_param_iterator_c::visit(implicit_definition_c *symbol) { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
405 |
en_eno_param_implicit = true; |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
406 |
return NULL; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
407 |
} |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
408 |
|
181 | 409 |
/****************************************/ |
410 |
/* 1.4.3 - Declaration & Initialisation */ |
|
411 |
/****************************************/ |
|
412 |
void *function_param_iterator_c::visit(input_declarations_c *symbol) { |
|
413 |
TRACE("input_declarations_c"); |
|
414 |
current_param_direction = direction_in; |
|
415 |
return symbol->input_declaration_list->accept(*this); |
|
416 |
} |
|
417 |
||
418 |
void *function_param_iterator_c::visit(input_declaration_list_c *symbol) {TRACE("input_declaration_list_c"); return iterate_list(symbol);} |
|
419 |
||
420 |
void *function_param_iterator_c::visit(edge_declaration_c *symbol) {TRACE("edge_declaration_c"); return symbol->var1_list->accept(*this);} |
|
421 |
||
422 |
void *function_param_iterator_c::visit(en_param_declaration_c *symbol) { |
|
423 |
TRACE("en_param_declaration_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
424 |
/* It is OK to store these values in the current_param_XXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
425 |
* variables, because if the desired parameter is not in the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
426 |
* variable list we will be analysing, the current_param_XXXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
427 |
* variables will get overwritten when we visit the next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
428 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
429 |
*/ |
805
b737cfc92614
Use simple_spec_init_c inside en_param_declaration_c (will reduce need to handle it as a special case in the future).
Mario de Sousa <msousa@fe.up.pt>
parents:
662
diff
changeset
|
430 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->type_decl); |
b737cfc92614
Use simple_spec_init_c inside en_param_declaration_c (will reduce need to handle it as a special case in the future).
Mario de Sousa <msousa@fe.up.pt>
parents:
662
diff
changeset
|
431 |
current_param_type = spec_init_sperator_c::get_spec(symbol->type_decl); |
b737cfc92614
Use simple_spec_init_c inside en_param_declaration_c (will reduce need to handle it as a special case in the future).
Mario de Sousa <msousa@fe.up.pt>
parents:
662
diff
changeset
|
432 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
433 |
void *res = handle_single_param(symbol->name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
434 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
435 |
/* If we have found the parameter we will be returning, we set the en_eno_param_implicit to TRUE if implicitly defined */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
436 |
if (res != NULL) symbol->method->accept(*this); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
437 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
438 |
return res; |
181 | 439 |
} |
440 |
||
441 |
/* var1_list ':' array_spec_init */ |
|
442 |
//SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
235 | 443 |
void *function_param_iterator_c::visit(array_var_init_decl_c *symbol) { |
444 |
TRACE("array_var_init_decl_c"); |
|
445 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->array_spec_init); |
|
446 |
current_param_type = spec_init_sperator_c::get_spec(symbol->array_spec_init); |
|
447 |
||
448 |
return symbol->var1_list->accept(*this); |
|
449 |
} |
|
181 | 450 |
|
451 |
/* var1_list ':' initialized_structure */ |
|
452 |
//SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
235 | 453 |
void *function_param_iterator_c::visit(structured_var_init_decl_c *symbol) { |
454 |
TRACE("structured_var_init_decl_c"); |
|
455 |
||
456 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->initialized_structure); |
|
457 |
current_param_type = spec_init_sperator_c::get_spec(symbol->initialized_structure); |
|
458 |
||
459 |
return symbol->var1_list->accept(*this); |
|
460 |
} |
|
181 | 461 |
|
662
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
462 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
463 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
464 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
465 |
/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
466 |
/* structure_initialization -> may be NULL ! */ |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
467 |
// SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization) |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
468 |
void *function_param_iterator_c::visit(fb_name_decl_c *symbol) { |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
469 |
TRACE("structured_var_init_decl_c"); |
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:
805
diff
changeset
|
470 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->fb_spec_init); |
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:
805
diff
changeset
|
471 |
current_param_type = spec_init_sperator_c::get_spec(symbol->fb_spec_init); |
662
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
472 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
473 |
return symbol->fb_name_list->accept(*this); |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
474 |
} |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
475 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
476 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
477 |
/* fb_name_list ',' fb_name */ |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
478 |
// SYM_LIST(fb_name_list_c) |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
479 |
void *function_param_iterator_c::visit(fb_name_list_c *symbol) {TRACE("fb_name_list_c"); return handle_param_list(symbol);} |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
480 |
|
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
481 |
|
181 | 482 |
void *function_param_iterator_c::visit(output_declarations_c *symbol) { |
483 |
TRACE("output_declarations_c"); |
|
484 |
current_param_direction = direction_out; |
|
485 |
return symbol->var_init_decl_list->accept(*this); |
|
486 |
} |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
487 |
|
181 | 488 |
void *function_param_iterator_c::visit(eno_param_declaration_c *symbol) { |
489 |
TRACE("eno_param_declaration_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
490 |
/* It is OK to store these values in the current_param_XXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
491 |
* variables, because if the desired parameter is not in the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
492 |
* variable list we will be analysing, the current_param_XXXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
493 |
* variables will get overwritten when we visit the next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
494 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
495 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
496 |
current_param_default_value = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
497 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
498 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
499 |
void *res = handle_single_param(symbol->name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
500 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
501 |
/* If we have found the parameter we will be returning, we set the en_eno_param_implicit to TRUE if implicitly defined */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
502 |
if (res != NULL) symbol->method->accept(*this); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
503 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
504 |
return res; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
505 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
506 |
|
181 | 507 |
void *function_param_iterator_c::visit(input_output_declarations_c *symbol) { |
508 |
TRACE("input_output_declarations_c"); |
|
509 |
current_param_direction = direction_inout; |
|
510 |
return symbol->var_declaration_list->accept(*this); |
|
511 |
} |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
512 |
|
181 | 513 |
void *function_param_iterator_c::visit(var_declaration_list_c *symbol) {TRACE("var_declaration_list_c"); return iterate_list(symbol);} |
514 |
||
515 |
/* var1_list ':' array_specification */ |
|
516 |
//SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
237 | 517 |
void *function_param_iterator_c::visit(array_var_declaration_c *symbol) { |
662
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
518 |
TRACE("array_var_declaration_c"); |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
519 |
current_param_default_value = NULL; |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
520 |
current_param_type = symbol->array_specification; |
b1b11dd09a54
Also check FB passed as parameters in FB/Function calls (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents:
596
diff
changeset
|
521 |
return symbol->var1_list->accept(*this); |
237 | 522 |
} |
181 | 523 |
|
524 |
/* var1_list ':' structure_type_name */ |
|
525 |
//SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
235 | 526 |
void *function_param_iterator_c::visit(structured_var_declaration_c *symbol) { |
527 |
TRACE("structured_var_declaration_c"); |
|
528 |
current_param_default_value = NULL; |
|
529 |
current_param_type = symbol->structure_type_name; |
|
530 |
return symbol->var1_list->accept(*this); |
|
531 |
} |
|
181 | 532 |
|
533 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
534 |
void *function_param_iterator_c::visit(var_declarations_c *symbol) {TRACE("var_declarations_c"); return NULL;} |
|
535 |
||
536 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
537 |
/* option -> may be NULL ! */ |
|
538 |
// SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
539 |
void *function_param_iterator_c::visit(external_var_declarations_c *symbol) { |
|
540 |
TRACE("external_var_declarations_c"); |
|
541 |
current_param_direction = direction_extref; |
|
542 |
return symbol->external_declaration_list->accept(*this); |
|
543 |
} |
|
544 |
||
545 |
/* helper symbol for external_var_declarations */ |
|
546 |
/*| external_declaration_list external_declaration';' */ |
|
547 |
// SYM_LIST(external_declaration_list_c) |
|
548 |
void *function_param_iterator_c::visit(external_declaration_list_c *symbol) {TRACE("external_declaration_list_c"); return iterate_list(symbol);} |
|
549 |
||
550 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
551 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
552 |
void *function_param_iterator_c::visit(external_declaration_c *symbol) { |
|
553 |
TRACE("external_declaration_c"); |
|
554 |
/* It is OK to store these values in the current_param_XXX |
|
555 |
* variables, because if the desired parameter is not in the |
|
556 |
* variable list we will be analysing, the current_param_XXXX |
|
557 |
* variables will get overwritten when we visit the next |
|
558 |
* var1_init_decl_c list! |
|
559 |
*/ |
|
560 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->specification); |
|
561 |
current_param_type = spec_init_sperator_c::get_spec(symbol->specification); |
|
562 |
||
563 |
return handle_single_param(symbol->global_var_name); |
|
564 |
} |
|
565 |
||
566 |
||
567 |
#if 0 |
|
568 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
569 |
/* option -> may be NULL ! */ |
|
570 |
SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
571 |
||
572 |
/* helper symbol for global_var_declarations */ |
|
573 |
/*| global_var_decl_list global_var_decl ';' */ |
|
574 |
SYM_LIST(global_var_decl_list_c) |
|
575 |
||
576 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
577 |
/* type_specification ->may be NULL ! */ |
|
578 |
SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
579 |
||
580 |
/*| global_var_name location */ |
|
581 |
SYM_REF2(global_var_spec_c, global_var_name, location) |
|
582 |
||
583 |
/* AT direct_variable */ |
|
584 |
SYM_REF2(location_c, direct_variable, unused) |
|
585 |
||
586 |
/*| global_var_list ',' global_var_name */ |
|
587 |
SYM_LIST(global_var_list_c) |
|
588 |
||
589 |
/* var1_list ':' single_byte_string_spec */ |
|
590 |
SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
591 |
||
592 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
593 |
/* integer ->may be NULL ! */ |
|
594 |
/* single_byte_character_string ->may be NULL ! */ |
|
595 |
SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
596 |
||
597 |
/* var1_list ':' double_byte_string_spec */ |
|
598 |
SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
599 |
||
600 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
601 |
/* integer ->may be NULL ! */ |
|
602 |
/* double_byte_character_string ->may be NULL ! */ |
|
603 |
SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
604 |
||
605 |
/*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
606 |
/* option ->may be NULL ! */ |
|
607 |
SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
608 |
||
609 |
/* helper symbol for incompl_located_var_declarations */ |
|
610 |
/*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
611 |
SYM_LIST(incompl_located_var_decl_list_c) |
|
612 |
||
613 |
/* variable_name incompl_location ':' var_spec */ |
|
614 |
SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
615 |
||
616 |
/* AT incompl_location_token */ |
|
617 |
SYM_TOKEN(incompl_location_c) |
|
618 |
#endif |
|
619 |
||
620 |
||
621 |
void *function_param_iterator_c::visit(var1_init_decl_c *symbol) { |
|
622 |
TRACE("var1_init_decl_c"); |
|
623 |
/* It is OK to store these values in the current_param_XXX |
|
624 |
* variables, because if the desired parameter is not in the |
|
625 |
* variable list we will be analysing, the current_param_XXXX |
|
626 |
* variables will get overwritten when we visit the next |
|
627 |
* var1_init_decl_c list! |
|
628 |
*/ |
|
629 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
|
630 |
current_param_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
631 |
||
632 |
return symbol->var1_list->accept(*this); |
|
633 |
} |
|
634 |
||
635 |
||
636 |
void *function_param_iterator_c::visit(var1_list_c *symbol) { |
|
637 |
TRACE("var1_list_c"); |
|
638 |
return handle_param_list(symbol); |
|
639 |
} |
|
640 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
641 |
|
181 | 642 |
void *function_param_iterator_c::visit(var_init_decl_list_c *symbol) {TRACE("var_init_decl_list_c"); return iterate_list(symbol);} |
643 |
||
644 |
||
645 |
/***********************/ |
|
646 |
/* B 1.5.1 - Functions */ |
|
647 |
/***********************/ |
|
648 |
void *function_param_iterator_c::visit(function_declaration_c *symbol) {TRACE("function_declaration_c"); return symbol->var_declarations_list->accept(*this);} |
|
649 |
/* intermediate helper symbol for function_declaration */ |
|
650 |
void *function_param_iterator_c::visit(var_declarations_list_c *symbol) {TRACE("var_declarations_list_c"); return iterate_list(symbol);} |
|
651 |
void *function_param_iterator_c::visit(function_var_decls_c *symbol) {TRACE("function_var_decls_c"); /* ignore */ return NULL;} |
|
652 |
||
653 |
||
654 |
/*****************************/ |
|
655 |
/* B 1.5.2 - Function Blocks */ |
|
656 |
/*****************************/ |
|
657 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
658 |
void *function_param_iterator_c::visit(function_block_declaration_c *symbol) {TRACE("function_block_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
659 |
||
660 |
/* intermediate helper symbol for function_declaration */ |
|
661 |
/* { io_var_declarations | other_var_declarations } */ |
|
662 |
/* |
|
663 |
* NOTE: we re-use the var_declarations_list_c |
|
664 |
*/ |
|
665 |
||
666 |
/* VAR_TEMP temp_var_decl_list END_VAR */ |
|
667 |
void *function_param_iterator_c::visit(temp_var_decls_c *symbol) {TRACE("temp_var_decls_c"); /* ignore */ return NULL;} |
|
668 |
void *function_param_iterator_c::visit(temp_var_decls_list_c *symbol) {TRACE("temp_var_decls_list_c"); /* ignore */ return NULL;} |
|
669 |
||
670 |
/* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
671 |
void *function_param_iterator_c::visit(non_retentive_var_decls_c *symbol) {TRACE("non_retentive_var_decls_c"); /* ignore */ return NULL;} |
|
672 |
||
673 |
||
674 |
/**********************/ |
|
675 |
/* B 1.5.3 - Programs */ |
|
676 |
/**********************/ |
|
677 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
|
678 |
// SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) |
|
679 |
void *function_param_iterator_c::visit(program_declaration_c *symbol) {TRACE("program_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
680 |
||
681 |
/* intermediate helper symbol for program_declaration_c */ |
|
682 |
/* { io_var_declarations | other_var_declarations } */ |
|
683 |
/* |
|
684 |
* NOTE: we re-use the var_declarations_list_c |
|
685 |
*/ |
|
686 |
||
687 |
||
688 |
||
689 |
||
690 |
||
691 |