author | Mario de Sousa <msousa@fe.up.pt> |
Mon, 04 Apr 2011 15:59:35 +0100 | |
changeset 277 | f88718b71b6c |
parent 265 | 4d222f46f8cc |
child 279 | c0453b7f99df |
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) |
181 | 5 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
6 |
* 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
|
7 |
* 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
|
8 |
* 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
|
9 |
* (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
|
10 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
11 |
* 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
|
12 |
* 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
|
13 |
* 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
|
14 |
* 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
|
15 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
16 |
* 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
|
17 |
* 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
|
18 |
* |
181 | 19 |
* |
20 |
* This code is made available on the understanding that it will not be |
|
21 |
* used in safety-critical situations without a full and competent review. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
25 |
* An IEC 61131-3 compiler. |
181 | 26 |
* |
27 |
* Based on the |
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
29 |
* |
|
30 |
*/ |
|
31 |
||
32 |
||
33 |
/* |
|
34 |
* Function call parameter iterator. |
|
35 |
* |
|
36 |
* This is part of the 4th stage that generates |
|
37 |
* a c++ source program equivalent to the IL and ST |
|
38 |
* code. |
|
39 |
*/ |
|
40 |
||
41 |
/* 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
|
42 |
* function/FB call in that code. |
181 | 43 |
*/ |
44 |
||
45 |
||
46 |
#include "function_call_iterator.hh" |
|
47 |
||
48 |
||
49 |
//#define DEBUG |
|
50 |
#ifdef DEBUG |
|
51 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
52 |
#else |
|
53 |
#define TRACE(classname) |
|
54 |
#endif |
|
55 |
||
56 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
57 |
/* function defined in main.cc */ |
|
58 |
extern void error_exit(const char *file_name, int line_no); |
|
59 |
||
60 |
||
61 |
||
62 |
||
63 |
||
64 |
/* initialise the iterator object. |
|
65 |
* We must be given a reference to the function declaration |
|
66 |
* that will be analysed... |
|
67 |
*/ |
|
68 |
function_call_iterator_c::function_call_iterator_c(symbol_c *symbol) { |
|
69 |
this->start_symbol = symbol; |
|
70 |
next_fcall = fcall_count = 0; |
|
71 |
current_finvocation = NULL; |
|
72 |
current_fcall_name = NULL; |
|
73 |
} |
|
74 |
||
75 |
/* Skip to the next function call. After object creation, |
|
76 |
* the object references _before_ the first, so |
|
77 |
* this function must be called once to get the object to |
|
78 |
* reference the first function call... |
|
79 |
* |
|
80 |
* Returns the function_invocation_c! |
|
81 |
*/ |
|
82 |
//function_invocation_c *next(void) {TRACE("function_call_iterator_c::next(): called "); |
|
83 |
symbol_c *function_call_iterator_c::next(void) {TRACE("function_call_iterator_c::next(): called "); |
|
84 |
fcall_count = 0; |
|
85 |
next_fcall++; |
|
86 |
current_finvocation = NULL; |
|
87 |
current_fcall_name = NULL; |
|
88 |
||
89 |
start_symbol->accept(*this); |
|
90 |
return current_finvocation; |
|
91 |
} |
|
92 |
||
93 |
/* Returns the name of the currently referenced function invocation */ |
|
94 |
identifier_c *function_call_iterator_c::fname(void) { |
|
95 |
identifier_c *identifier = dynamic_cast<identifier_c *>(current_fcall_name); |
|
96 |
if (identifier == NULL) ERROR; |
|
97 |
return identifier; |
|
98 |
} |
|
99 |
||
100 |
||
101 |
/***************************************/ |
|
102 |
/* B.3 - Language ST (Structured Text) */ |
|
103 |
/***************************************/ |
|
104 |
/***********************/ |
|
105 |
/* B 3.1 - Expressions */ |
|
106 |
/***********************/ |
|
107 |
void *function_call_iterator_c::visit(function_invocation_c *symbol) { |
|
108 |
fcall_count++; |
|
109 |
if (next_fcall == fcall_count) { |
|
110 |
current_finvocation = symbol; |
|
111 |
current_fcall_name = symbol->function_name; |
|
112 |
} |
|
113 |
return NULL; |
|
114 |
} |
|
115 |
||
116 |
||
117 |
||
118 |
/****************************************/ |
|
119 |
/* B.2 - Language IL (Instruction List) */ |
|
120 |
/****************************************/ |
|
121 |
/***********************************/ |
|
122 |
/* B 2.1 Instructions and Operands */ |
|
123 |
/***********************************/ |
|
124 |
||
125 |
/* | function_name [il_operand_list] */ |
|
126 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list) |
|
127 |
void *function_call_iterator_c::visit(il_function_call_c *symbol) { |
|
128 |
fcall_count++; |
|
129 |
if (next_fcall == fcall_count) { |
|
130 |
current_finvocation = symbol; |
|
131 |
current_fcall_name = symbol->function_name; |
|
132 |
} |
|
133 |
return NULL; |
|
134 |
} |
|
135 |
||
136 |
||
137 |
||
138 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
139 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
140 |
void *function_call_iterator_c::visit(il_formal_funct_call_c *symbol) { |
|
141 |
fcall_count++; |
|
142 |
if (next_fcall == fcall_count) { |
|
143 |
current_finvocation = symbol; |
|
144 |
current_fcall_name = symbol->function_name; |
|
145 |
} |
|
146 |
return NULL; |
|
147 |
} |
|
148 |
||
149 |
||
150 |
||
151 |
||
152 |