author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 26 Apr 2024 09:27:21 +0200 | |
changeset 1105 | 8128cad6a6e3 |
parent 1041 | 56ebe2a31b5b |
permissions | -rw-r--r-- |
959
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
1 |
/* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
3 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
4 |
* Copyright (C) 2014 Mario de Sousa (msousa@fe.up.pt) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
5 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
6 |
* This program is free software: you can redistribute it and/or modify |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License as published by |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
8 |
* the Free Software Foundation, either version 3 of the License, or |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
9 |
* (at your option) any later version. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
10 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
14 |
* GNU General Public License for more details. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
15 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
18 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
19 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
20 |
* This code is made available on the understanding that it will not be |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
21 |
* used in safety-critical situations without a full and competent review. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
22 |
*/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
23 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
24 |
/* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
25 |
* An IEC 61131-3 compiler. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
26 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
27 |
* Based on the |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
29 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
30 |
*/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
31 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
32 |
/* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
33 |
* Re-oder the POUs in te library so that no forward references occur. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
34 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
35 |
* Since stage1_2 now suppport POUs that contain references to POUS that are only declared later, |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
36 |
* (e.g. a variable of FB1_t is declared, before the FB1_T function block is itself declared!) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
37 |
* we may need to re-order all the POUs in the library so that these forward references do not occur. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
38 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
39 |
* This utility function will do just that. However, it does not destroy the original abstract syntax |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
40 |
* tree (AST). It instead creates a new re-ordered AST, by instantiating a new library_c object. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
41 |
* This new library_c object will however point to the *same* objects of the original AST, just in |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
42 |
* a new order. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
43 |
* This means that the new and original AST share all the object instances, and only use a distinct |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
44 |
* library_c object! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
45 |
*/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
46 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
47 |
#include "remove_forward_dependencies.hh" |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
48 |
#include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
49 |
#include "../absyntax_utils/absyntax_utils.hh" |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
50 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
51 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
52 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
53 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
54 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
55 |
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
56 |
#define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
57 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
58 |
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
59 |
#define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
60 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
61 |
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) { \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
62 |
if (current_display_error_level >= error_level) { \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
63 |
fprintf(stderr, "%s:%d-%d..%d-%d: error: ", \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
64 |
FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
65 |
LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
66 |
fprintf(stderr, __VA_ARGS__); \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
67 |
fprintf(stderr, "\n"); \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
68 |
error_count++; \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
69 |
} \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
70 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
71 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
72 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
73 |
#define STAGE3_WARNING(symbol1, symbol2, ...) { \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
74 |
fprintf(stderr, "%s:%d-%d..%d-%d: warning: ", \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
75 |
FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
76 |
LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
77 |
fprintf(stderr, __VA_ARGS__); \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
78 |
fprintf(stderr, "\n"); \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
79 |
warning_found = true; \ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
80 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
81 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
82 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
83 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
84 |
/* NOTE: We create an independent visitor for this task instead of having this done by the remove_forward_dependencies_c |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
85 |
* because we do not want to handle the ***_pragma_c classes while doing this search. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
86 |
* (remove_forward_dependencies_c needs to visit those classes when handling all the possible entries in |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
87 |
* library_c, and must have those visitors) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
88 |
* |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
89 |
* NOTE: |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
90 |
* This class could have been written by visiting all the AST objects that could _reference_ a |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
91 |
* - FB type |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
92 |
* - Program type |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
93 |
* - Function type |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
94 |
* and by checking whether those references are in the declared_identifiers list. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
95 |
* However, one of those objects, the ref_spec_c, may reference an FB type, or any other datatype, so we must have a way |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
96 |
* of knowing what is being referenced in this case. I have opted to introduce a new object type in the AST, the |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
97 |
* poutype_identifier_c, that will be used anywhere in the AST that references either a PROGRAM name or a FB type name |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
98 |
* or a FUNCTION name (previously a simple identifier_c was used!). |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
99 |
* This means that we merely need to visit the new poutype_identifier_c object in this visitor. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
100 |
*/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
101 |
class find_forward_dependencies_c: public search_visitor_c { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
102 |
private: |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
103 |
identifiers_symbtable_t *declared_identifiers; // list of identifiers already declared by the symbols in the new tree |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
104 |
public: |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
105 |
find_forward_dependencies_c(identifiers_symbtable_t *declared_identifiers_) {declared_identifiers = declared_identifiers_;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
106 |
/*******************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
107 |
/* B 1.1 - Letters, digits and identifiers */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
108 |
/*******************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
109 |
// return NULL if the symbol is already in the declared_identifiers symbol table, otherwise return the missing symbol! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
110 |
void *visit( poutype_identifier_c *symbol) |
971
8aee27d46208
Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents:
959
diff
changeset
|
111 |
{if (declared_identifiers->find(symbol) != declared_identifiers->end()) return NULL; else return symbol;} |
959
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
112 |
}; /* class find_forward_dependencies_c */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
113 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
114 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
115 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
116 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
117 |
/* A class to count the number of POUs (Function, FBs Programs and Configurations) in a library. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
118 |
* This will be used to make sure whether we have copied all the POUs from the original AST (abstract |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
119 |
* syntax tree) to the new AST. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
120 |
* Note that we can't simply use the number of 'elements' in the AST, as it may contain unknown/unsupported pragmas. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
121 |
*/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
122 |
class pou_count_c: public search_visitor_c { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
123 |
private: |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
124 |
static pou_count_c *singleton; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
125 |
long long int count; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
126 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
127 |
public: |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
128 |
static long long int get_count(library_c *library) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
129 |
if (NULL == singleton) singleton = new pou_count_c; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
130 |
if (NULL == singleton) ERROR; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
131 |
singleton->count = 0; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
132 |
library->accept(*singleton); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
133 |
return singleton->count; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
134 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
135 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
136 |
/**************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
137 |
/* B.1.5 - Program organization units */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
138 |
/**************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
139 |
void *visit( function_declaration_c *symbol) {count++; return NULL;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
140 |
void *visit(function_block_declaration_c *symbol) {count++; return NULL;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
141 |
void *visit( program_declaration_c *symbol) {count++; return NULL;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
142 |
void *visit( configuration_declaration_c *symbol) {count++; return NULL;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
143 |
}; /* class pou_count_c */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
144 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
145 |
pou_count_c *pou_count_c::singleton = NULL; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
146 |
symbol_c remove_forward_dependencies_c_null_symbol; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
147 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
148 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
149 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
150 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
151 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
152 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
153 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
154 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
155 |
/************************************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
156 |
/************************************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
157 |
/****** The main class: Remove Forward Depencies *******/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
158 |
/************************************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
159 |
/************************************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
160 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
161 |
// constructor & destructor |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
162 |
remove_forward_dependencies_c:: remove_forward_dependencies_c(void) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
163 |
find_forward_dependencies = new find_forward_dependencies_c(&declared_identifiers); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
164 |
current_display_error_level = error_level_default; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
165 |
error_count = 0; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
166 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
167 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
168 |
remove_forward_dependencies_c::~remove_forward_dependencies_c(void) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
169 |
delete find_forward_dependencies; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
170 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
171 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
172 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
173 |
int remove_forward_dependencies_c::get_error_count(void) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
174 |
return error_count; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
175 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
176 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
177 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
178 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
179 |
library_c *remove_forward_dependencies_c::create_new_tree(symbol_c *tree) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
180 |
library_c *old_tree = dynamic_cast<library_c *>(tree); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
181 |
if (NULL == old_tree) ERROR; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
182 |
new_tree = new library_c; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
183 |
*((symbol_c *)new_tree) = *((symbol_c *)tree); // copy any annotations from tree to new_tree; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
184 |
new_tree->clear(); // remove all elements from list. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
185 |
tree->accept(*this); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
186 |
return new_tree; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
187 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
188 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
189 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
190 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
191 |
void *remove_forward_dependencies_c::handle_library_symbol(symbol_c *symbol, symbol_c *name, symbol_c *search1, symbol_c *search2, symbol_c *search3) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
192 |
if (inserted_symbols.find(symbol) != inserted_symbols.end()) return NULL; // already previously inserted into new_tree and declared_identifiers. Do not handle again! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
193 |
if ((search1 != NULL) && (search1->accept(*find_forward_dependencies) != NULL)) return NULL; // A forward depency has not yet been satisfied. Wait for a later iteration to try again! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
194 |
if ((search2 != NULL) && (search2->accept(*find_forward_dependencies) != NULL)) return NULL; // A forward depency has not yet been satisfied. Wait for a later iteration to try again! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
195 |
if ((search3 != NULL) && (search3->accept(*find_forward_dependencies) != NULL)) return NULL; // A forward depency has not yet been satisfied. Wait for a later iteration to try again! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
196 |
/* no forward dependencies found => insert into new AST, and add to the 'defined identifiers' and 'inserted symbol' lists */ |
971
8aee27d46208
Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents:
959
diff
changeset
|
197 |
if (declared_identifiers.find(name) == declared_identifiers.end()) |
959
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
198 |
declared_identifiers.insert(name, NULL); // only add if not yet in the symbol table (an overloaded version of this same POU could have been inderted previously!) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
199 |
inserted_symbols.insert(symbol); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
200 |
new_tree->add_element(current_code_generation_pragma); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
201 |
new_tree->add_element(symbol); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
202 |
return NULL; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
203 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
204 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
205 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
206 |
/* Tell the user that the source code contains a circular dependency */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
207 |
void remove_forward_dependencies_c::print_circ_error(library_c *symbol) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
208 |
/* Note that we only print Functions and FBs, as Programs and Configurations cannot contain circular references due to syntax rules */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
209 |
/* Note too that circular references in derived datatypes is also not possible due to sytax! */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
210 |
int initial_error_count = error_count; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
211 |
for (int i = 0; i < symbol->n; i++) |
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
212 |
if ( (inserted_symbols.find(symbol->get_element(i)) == inserted_symbols.end()) // if not copied to new AST |
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
213 |
&&( (NULL != dynamic_cast <function_block_declaration_c *>(symbol->get_element(i))) // and (is a FB |
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
214 |
||(NULL != dynamic_cast < function_declaration_c *>(symbol->get_element(i))))) // or a Function) |
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
215 |
STAGE3_ERROR(0, symbol->get_element(i), symbol->get_element(i), "POU (%s) contains a self-reference and/or belongs in a circular referencing loop", get_datatype_info_c::get_id_str(symbol->get_element(i))); |
959
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
216 |
if (error_count == initial_error_count) ERROR; // We were unable to determine which POUs contain the circular references!! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
217 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
218 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
219 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
220 |
/***************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
221 |
/* B 0 - Programming Model */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
222 |
/***************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
223 |
/* enumvalue_symtable is filled in by enum_declaration_check_c, during stage3 semantic verification, with a list of all enumerated constants declared inside this POU */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
224 |
// SYM_LIST(library_c, enumvalue_symtable_t enumvalue_symtable;) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
225 |
void *remove_forward_dependencies_c::visit(library_c *symbol) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
226 |
/* this method is the expected entry point for this visitor, and implements the main algorithm of the visitor */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
227 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
228 |
/* first insert all the derived datatype declarations, in the same order by which they are delcared in the original AST */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
229 |
/* Since IEC 61131-3 does not allow FBs in arrays or structures, it is actually safe to place all the datatypes before all the POUs! */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
230 |
for (int i = 0; i < symbol->n; i++) |
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
231 |
if (NULL != dynamic_cast <data_type_declaration_c *>(symbol->get_element(i))) |
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
232 |
new_tree->add_element(symbol->get_element(i)); |
959
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
233 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
234 |
/* now do the POUs, in whatever order is necessary to guarantee no forward references. */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
235 |
long long int old_tree_pou_count = pou_count_c::get_count(symbol); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
236 |
// if no code generation pragma exists before the first entry in the library, the default is to enable code generation. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
237 |
enable_code_generation_pragma_c *default_code_generation_pragma = new enable_code_generation_pragma_c; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
238 |
int prev_n; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
239 |
cycle_count = 0; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
240 |
do { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
241 |
cycle_count++; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
242 |
prev_n = new_tree->n; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
243 |
current_code_generation_pragma = default_code_generation_pragma; |
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
971
diff
changeset
|
244 |
for (int i = 0; i < symbol->n; i++) symbol->get_element(i)->accept(*this); |
959
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
245 |
} while (prev_n != new_tree->n); // repeat while new elementns are still being added to the new AST |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
246 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
247 |
if (old_tree_pou_count != pou_count_c::get_count(new_tree)) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
248 |
print_circ_error(symbol); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
249 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
250 |
return NULL; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
251 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
252 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
253 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
254 |
/**************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
255 |
/* B.1.5 - Program organization units */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
256 |
/**************************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
257 |
/***********************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
258 |
/* B 1.5.1 - Functions */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
259 |
/***********************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
260 |
// SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body, enumvalue_symtable_t enumvalue_symtable;) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
261 |
void *remove_forward_dependencies_c::visit(function_declaration_c *symbol) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
262 |
{return handle_library_symbol(symbol, symbol->derived_function_name, symbol->type_name, symbol->var_declarations_list, symbol->function_body);} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
263 |
/*****************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
264 |
/* B 1.5.2 - Function Blocks */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
265 |
/*****************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
266 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
267 |
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body, enumvalue_symtable_t enumvalue_symtable;) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
268 |
void *remove_forward_dependencies_c::visit(function_block_declaration_c *symbol) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
269 |
{return handle_library_symbol(symbol, symbol->fblock_name, symbol->var_declarations, symbol->fblock_body);} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
270 |
/**********************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
271 |
/* B 1.5.3 - Programs */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
272 |
/**********************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
273 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
274 |
// SYM_REF3(program_declaration_c, program_type_name, var_declarations, function_block_body, enumvalue_symtable_t enumvalue_symtable;) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
275 |
void *remove_forward_dependencies_c::visit(program_declaration_c *symbol) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
276 |
{return handle_library_symbol(symbol, symbol->program_type_name, symbol->var_declarations, symbol->function_block_body);} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
277 |
/********************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
278 |
/* B 1.7 Configuration elements */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
279 |
/********************************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
280 |
/* CONFIGURATION configuration_name (...) END_CONFIGURATION */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
281 |
// SYM_REF5(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, enumvalue_symtable_t enumvalue_symtable;) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
282 |
void *remove_forward_dependencies_c::visit(configuration_declaration_c *symbol) |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
283 |
{return handle_library_symbol(symbol, symbol->configuration_name, symbol->global_var_declarations, symbol->resource_declarations, symbol->access_declarations);} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
284 |
/********************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
285 |
/* 2.1.6 - Pragmas */ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
286 |
/********************/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
287 |
void *remove_forward_dependencies_c::visit(disable_code_generation_pragma_c *symbol) {current_code_generation_pragma = symbol; return NULL;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
288 |
void *remove_forward_dependencies_c::visit( enable_code_generation_pragma_c *symbol) {current_code_generation_pragma = symbol; return NULL;} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
289 |
/* I have no ideia what this pragma is. Where should we place it in the re-ordered tree? |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
290 |
* Without knowing the semantics of the pragma, it is not possible to hande it correctly. |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
291 |
* We therefore print out an error message, and abort! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
292 |
*/ |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
293 |
// TODO: print error message! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
294 |
void *remove_forward_dependencies_c::visit(pragma_c *symbol) { |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
295 |
if (1 != cycle_count) return NULL; // only handle unknown pragmas in the first cycle! |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
296 |
STAGE3_WARNING(symbol, symbol, "Unrecognized pragma. Including the pragma when using the '-p' command line option for 'allow use of forward references' may result in unwanted behaviour."); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
297 |
new_tree->add_element(symbol); |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
298 |
return NULL; |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
299 |
} |
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
300 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
301 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
302 |
|
8bfcc8e62bd6
Fix C code generation when forward references (-p command line option) is on.
mjsousa
parents:
diff
changeset
|
303 |