author | Mario de Sousa <msousa@fe.up.pt> |
Tue, 23 Aug 2011 11:51:14 +0100 | |
changeset 360 | f4ce1b1c2112 |
parent 279 | c0453b7f99df |
child 596 | 4efb11e44065 |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
181 | 3 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
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 |
181 | 6 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
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:
202
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:
202
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:
202
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:
202
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
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:
202
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:
202
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:
202
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:
202
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
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:
202
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:
202
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:
202
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 call parameter iterator. |
|
36 |
* |
|
37 |
* This is part of the 4th stage that generates |
|
38 |
* a c++ source program equivalent to the IL and ST |
|
39 |
* code. |
|
40 |
*/ |
|
41 |
||
42 |
/* given a function_body_c, iterate through each |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
43 |
* function/FB call in that code. |
181 | 44 |
*/ |
45 |
||
46 |
||
47 |
#include "function_call_iterator.hh" |
|
48 |
||
49 |
||
50 |
//#define DEBUG |
|
51 |
#ifdef DEBUG |
|
52 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
53 |
#else |
|
54 |
#define TRACE(classname) |
|
55 |
#endif |
|
56 |
||
57 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
58 |
/* function defined in main.cc */ |
|
59 |
extern void error_exit(const char *file_name, int line_no); |
|
60 |
||
61 |
||
62 |
||
63 |
||
64 |
||
65 |
/* initialise the iterator object. |
|
66 |
* We must be given a reference to the function declaration |
|
67 |
* that will be analysed... |
|
68 |
*/ |
|
69 |
function_call_iterator_c::function_call_iterator_c(symbol_c *symbol) { |
|
70 |
this->start_symbol = symbol; |
|
71 |
next_fcall = fcall_count = 0; |
|
72 |
current_finvocation = NULL; |
|
73 |
current_fcall_name = NULL; |
|
74 |
} |
|
75 |
||
76 |
/* Skip to the next function call. After object creation, |
|
77 |
* the object references _before_ the first, so |
|
78 |
* this function must be called once to get the object to |
|
79 |
* reference the first function call... |
|
80 |
* |
|
81 |
* Returns the function_invocation_c! |
|
82 |
*/ |
|
83 |
//function_invocation_c *next(void) {TRACE("function_call_iterator_c::next(): called "); |
|
84 |
symbol_c *function_call_iterator_c::next(void) {TRACE("function_call_iterator_c::next(): called "); |
|
85 |
fcall_count = 0; |
|
86 |
next_fcall++; |
|
87 |
current_finvocation = NULL; |
|
88 |
current_fcall_name = NULL; |
|
89 |
||
90 |
start_symbol->accept(*this); |
|
91 |
return current_finvocation; |
|
92 |
} |
|
93 |
||
94 |
/* Returns the name of the currently referenced function invocation */ |
|
95 |
identifier_c *function_call_iterator_c::fname(void) { |
|
96 |
identifier_c *identifier = dynamic_cast<identifier_c *>(current_fcall_name); |
|
97 |
if (identifier == NULL) ERROR; |
|
98 |
return identifier; |
|
99 |
} |
|
100 |
||
101 |
||
102 |
/***************************************/ |
|
103 |
/* B.3 - Language ST (Structured Text) */ |
|
104 |
/***************************************/ |
|
105 |
/***********************/ |
|
106 |
/* B 3.1 - Expressions */ |
|
107 |
/***********************/ |
|
108 |
void *function_call_iterator_c::visit(function_invocation_c *symbol) { |
|
109 |
fcall_count++; |
|
110 |
if (next_fcall == fcall_count) { |
|
111 |
current_finvocation = symbol; |
|
112 |
current_fcall_name = symbol->function_name; |
|
113 |
} |
|
114 |
return NULL; |
|
115 |
} |
|
116 |
||
117 |
||
118 |
||
119 |
/****************************************/ |
|
120 |
/* B.2 - Language IL (Instruction List) */ |
|
121 |
/****************************************/ |
|
122 |
/***********************************/ |
|
123 |
/* B 2.1 Instructions and Operands */ |
|
124 |
/***********************************/ |
|
125 |
||
126 |
/* | function_name [il_operand_list] */ |
|
127 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list) |
|
128 |
void *function_call_iterator_c::visit(il_function_call_c *symbol) { |
|
129 |
fcall_count++; |
|
130 |
if (next_fcall == fcall_count) { |
|
131 |
current_finvocation = symbol; |
|
132 |
current_fcall_name = symbol->function_name; |
|
133 |
} |
|
134 |
return NULL; |
|
135 |
} |
|
136 |
||
137 |
||
138 |
||
139 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
140 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
141 |
void *function_call_iterator_c::visit(il_formal_funct_call_c *symbol) { |
|
142 |
fcall_count++; |
|
143 |
if (next_fcall == fcall_count) { |
|
144 |
current_finvocation = symbol; |
|
145 |
current_fcall_name = symbol->function_name; |
|
146 |
} |
|
147 |
return NULL; |
|
148 |
} |
|
149 |
||
150 |
||
151 |
||
152 |
||
153 |