author | laurent |
Sat, 12 Mar 2011 18:38:41 +0100 | |
changeset 248 | 9cb18ec14fa2 |
parent 202 | da1a8186f86f |
child 265 | 4d222f46f8cc |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
/* |
|
27 |
* Function call parameter iterator. |
|
28 |
* |
|
29 |
* This is part of the 4th stage that generates |
|
30 |
* a c++ source program equivalent to the IL and ST |
|
31 |
* code. |
|
32 |
*/ |
|
33 |
||
34 |
/* 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
|
35 |
* function/FB call in that code. |
181 | 36 |
*/ |
37 |
||
38 |
||
39 |
#include "function_call_iterator.hh" |
|
40 |
||
41 |
||
42 |
//#define DEBUG |
|
43 |
#ifdef DEBUG |
|
44 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
45 |
#else |
|
46 |
#define TRACE(classname) |
|
47 |
#endif |
|
48 |
||
49 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
50 |
/* function defined in main.cc */ |
|
51 |
extern void error_exit(const char *file_name, int line_no); |
|
52 |
||
53 |
||
54 |
||
55 |
||
56 |
||
57 |
/* initialise the iterator object. |
|
58 |
* We must be given a reference to the function declaration |
|
59 |
* that will be analysed... |
|
60 |
*/ |
|
61 |
function_call_iterator_c::function_call_iterator_c(symbol_c *symbol) { |
|
62 |
this->start_symbol = symbol; |
|
63 |
next_fcall = fcall_count = 0; |
|
64 |
current_finvocation = NULL; |
|
65 |
current_fcall_name = NULL; |
|
66 |
} |
|
67 |
||
68 |
/* Skip to the next function call. After object creation, |
|
69 |
* the object references _before_ the first, so |
|
70 |
* this function must be called once to get the object to |
|
71 |
* reference the first function call... |
|
72 |
* |
|
73 |
* Returns the function_invocation_c! |
|
74 |
*/ |
|
75 |
//function_invocation_c *next(void) {TRACE("function_call_iterator_c::next(): called "); |
|
76 |
symbol_c *function_call_iterator_c::next(void) {TRACE("function_call_iterator_c::next(): called "); |
|
77 |
fcall_count = 0; |
|
78 |
next_fcall++; |
|
79 |
current_finvocation = NULL; |
|
80 |
current_fcall_name = NULL; |
|
81 |
||
82 |
start_symbol->accept(*this); |
|
83 |
return current_finvocation; |
|
84 |
} |
|
85 |
||
86 |
/* Returns the name of the currently referenced function invocation */ |
|
87 |
identifier_c *function_call_iterator_c::fname(void) { |
|
88 |
identifier_c *identifier = dynamic_cast<identifier_c *>(current_fcall_name); |
|
89 |
if (identifier == NULL) ERROR; |
|
90 |
return identifier; |
|
91 |
} |
|
92 |
||
93 |
||
94 |
/***************************************/ |
|
95 |
/* B.3 - Language ST (Structured Text) */ |
|
96 |
/***************************************/ |
|
97 |
/***********************/ |
|
98 |
/* B 3.1 - Expressions */ |
|
99 |
/***********************/ |
|
100 |
void *function_call_iterator_c::visit(function_invocation_c *symbol) { |
|
101 |
fcall_count++; |
|
102 |
if (next_fcall == fcall_count) { |
|
103 |
current_finvocation = symbol; |
|
104 |
current_fcall_name = symbol->function_name; |
|
105 |
} |
|
106 |
return NULL; |
|
107 |
} |
|
108 |
||
109 |
||
110 |
||
111 |
/****************************************/ |
|
112 |
/* B.2 - Language IL (Instruction List) */ |
|
113 |
/****************************************/ |
|
114 |
/***********************************/ |
|
115 |
/* B 2.1 Instructions and Operands */ |
|
116 |
/***********************************/ |
|
117 |
||
118 |
/* | function_name [il_operand_list] */ |
|
119 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list) |
|
120 |
void *function_call_iterator_c::visit(il_function_call_c *symbol) { |
|
121 |
fcall_count++; |
|
122 |
if (next_fcall == fcall_count) { |
|
123 |
current_finvocation = symbol; |
|
124 |
current_fcall_name = symbol->function_name; |
|
125 |
} |
|
126 |
return NULL; |
|
127 |
} |
|
128 |
||
129 |
||
130 |
||
131 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
132 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
133 |
void *function_call_iterator_c::visit(il_formal_funct_call_c *symbol) { |
|
134 |
fcall_count++; |
|
135 |
if (next_fcall == fcall_count) { |
|
136 |
current_finvocation = symbol; |
|
137 |
current_fcall_name = symbol->function_name; |
|
138 |
} |
|
139 |
return NULL; |
|
140 |
} |
|
141 |
||
142 |
||
143 |
||
144 |
||
145 |