|
10 | 10 |
|
11 | 11 | #include <ostream>
|
12 | 12 |
|
| 13 | +#include <iostream> |
| 14 | + |
13 | 15 | #include "source_location.h"
|
14 | 16 | #include "std_expr.h"
|
| 17 | +#include "string_utils.h" |
15 | 18 | #include "suffix.h"
|
16 | 19 |
|
17 | 20 | /// Dump the state of a symbol object to a given output stream.
|
@@ -139,7 +142,51 @@ bool symbolt::is_well_formed() const
|
139 | 142 | // general name.
|
140 | 143 | if(!has_suffix(id2string(name), id2string(base_name)))
|
141 | 144 | {
|
142 |
| - return false; |
| 145 | + bool criterion_must_hold = true; |
| 146 | + |
| 147 | + // There are some special cases where this criterion doesn't hold, check |
| 148 | + // to see if we have one of those cases |
| 149 | + |
| 150 | + if (is_type) |
| 151 | + { |
| 152 | + // Typedefs |
| 153 | + if (type.find(ID_C_typedef).is_not_nil()) |
| 154 | + { |
| 155 | + // FIXME: Is there an additional check that can be made here, like for tag types below? |
| 156 | + criterion_must_hold = false; |
| 157 | + } |
| 158 | + |
| 159 | + // Tag types |
| 160 | + if (type.find(ID_tag).is_not_nil() && type.find(ID_tag).id() == base_name) |
| 161 | + { |
| 162 | + criterion_must_hold = false; |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + // Linker renaming may have added $linkN suffixes to the name, and other |
| 167 | + // suffixes such as #return_value may have then be subsequently added. |
| 168 | + // Strip out the first $linkN substring and then see if the criterion holds |
| 169 | + |
| 170 | + const auto split_name = split_string(id2string(name), '$'); |
| 171 | + if( |
| 172 | + split_name.size() > 1 && has_prefix(split_name[1], "link")) // FIXME: Should loop for all delimited? |
| 173 | + { |
| 174 | + |
| 175 | + size_t post_link_start = 4; |
| 176 | + while (post_link_start < split_name[1].size() && std::isdigit(split_name[1][post_link_start])) |
| 177 | + ++post_link_start; |
| 178 | + |
| 179 | + const auto stripped_name = split_name[0] + split_name[1].substr(post_link_start,split_name[1].size()); |
| 180 | + |
| 181 | + if (has_suffix(stripped_name, id2string(base_name))) |
| 182 | + criterion_must_hold = false; |
| 183 | + } |
| 184 | + |
| 185 | + if (criterion_must_hold) |
| 186 | + { |
| 187 | + // For all other cases this criterion should hold |
| 188 | + return false; |
| 189 | + } |
143 | 190 | }
|
144 | 191 |
|
145 | 192 | return true;
|
|
0 commit comments