@@ -276,7 +276,7 @@ class Parser // NOLINT(readability/identifiers)
276
276
bool optStorageSpec (cpp_storage_spect &);
277
277
bool optCvQualify (typet &);
278
278
bool optAlignas (typet &);
279
- bool rAttribute ();
279
+ bool rAttribute (typet & );
280
280
bool optAttribute (cpp_declarationt &);
281
281
bool optIntegralTypeOrClassSpec (typet &);
282
282
bool rConstructorDecl (
@@ -473,8 +473,10 @@ void Parser::merge_types(const typet &src, typet &dest)
473
473
{
474
474
if (dest.id ()!=ID_merged_type)
475
475
{
476
+ source_locationt location=dest.source_location ();
476
477
typet tmp (ID_merged_type);
477
478
tmp.move_to_subtypes (dest);
479
+ tmp.add_source_location ()=location;
478
480
dest=tmp;
479
481
}
480
482
@@ -2044,7 +2046,7 @@ bool Parser::optCvQualify(typet &cv)
2044
2046
break ;
2045
2047
2046
2048
case TOK_GCC_ATTRIBUTE:
2047
- if (!rAttribute ())
2049
+ if (!rAttribute (cv ))
2048
2050
return false ;
2049
2051
break ;
2050
2052
@@ -2103,28 +2105,204 @@ bool Parser::optAlignas(typet &cv)
2103
2105
return true ;
2104
2106
}
2105
2107
2106
- bool Parser::rAttribute ()
2108
+ bool Parser::rAttribute (typet &t )
2107
2109
{
2110
+ #ifdef DEBUG
2111
+ indenter _i;
2112
+ std::cout << std::string (__indent, ' ' ) << " Parser::rAttribute "
2113
+ << lex.LookAhead (0 );
2114
+ #endif
2108
2115
cpp_tokent tk;
2109
2116
lex.get_token (tk);
2110
2117
2111
2118
switch (tk.kind )
2112
2119
{
2113
2120
case ' (' :
2114
- rAttribute ();
2121
+ if (lex.LookAhead (0 )!=' )' )
2122
+ rAttribute (t);
2123
+
2115
2124
if (lex.LookAhead (0 )!=' )' )
2116
2125
return false ;
2117
2126
lex.get_token (tk);
2118
- break ;
2127
+ return true ;
2119
2128
2120
- case TOK_IDENTIFIER:
2129
+ case TOK_GCC_ATTRIBUTE_PACKED:
2130
+ {
2131
+ typet attr (ID_packed);
2132
+ set_location (attr, tk);
2133
+ merge_types (attr, t);
2134
+ break ;
2135
+ }
2136
+
2137
+ case TOK_GCC_ATTRIBUTE_TRANSPARENT_UNION:
2138
+ {
2139
+ typet attr (ID_transparent_union);
2140
+ set_location (attr, tk);
2141
+ merge_types (attr, t);
2142
+ break ;
2143
+ }
2144
+
2145
+ case TOK_GCC_ATTRIBUTE_VECTOR_SIZE:
2146
+ {
2147
+ cpp_tokent tk2, tk3;
2148
+
2149
+ if (lex.get_token (tk2)!=' (' )
2150
+ return false ;
2151
+
2152
+ exprt exp ;
2153
+ if (!rCommaExpression (exp ))
2154
+ return false ;
2155
+
2156
+ if (lex.get_token (tk3)!=' )' )
2157
+ return false ;
2158
+
2159
+ vector_typet attr (nil_typet (), exp );
2160
+ attr.add_source_location ()=exp .source_location ();
2161
+ merge_types (attr, t);
2162
+ break ;
2163
+ }
2164
+
2165
+ case TOK_GCC_ATTRIBUTE_ALIGNED:
2166
+ {
2167
+ typet attr (ID_aligned);
2168
+ set_location (attr, tk);
2169
+
2170
+ if (lex.LookAhead (0 )==' (' )
2171
+ {
2172
+ cpp_tokent tk2, tk3;
2173
+
2174
+ if (lex.get_token (tk2)!=' (' )
2175
+ return false ;
2176
+
2177
+ exprt exp ;
2178
+ if (!rCommaExpression (exp ))
2179
+ return false ;
2180
+
2181
+ if (lex.get_token (tk3)!=' )' )
2182
+ return false ;
2183
+
2184
+ attr.add (ID_size, exp );
2185
+ }
2186
+
2187
+ merge_types (attr, t);
2188
+ break ;
2189
+ }
2190
+
2191
+ case TOK_GCC_ATTRIBUTE_MODE:
2192
+ {
2193
+ cpp_tokent tk2, tk3;
2194
+
2195
+ if (lex.get_token (tk2)!=' (' )
2196
+ return false ;
2197
+
2198
+ irept name;
2199
+ if (!rName (name))
2200
+ return false ;
2201
+
2202
+ if (lex.get_token (tk3)!=' )' )
2203
+ return false ;
2204
+
2205
+ typet attr (ID_gcc_attribute_mode);
2206
+ set_location (attr, tk);
2207
+ attr.set (ID_size, name.get (ID_identifier));
2208
+ merge_types (attr, t);
2209
+ break ;
2210
+ }
2211
+
2212
+ case TOK_GCC_ATTRIBUTE_GNU_INLINE:
2213
+ {
2214
+ typet attr (ID_static);
2215
+ set_location (attr, tk);
2216
+ merge_types (attr, t);
2217
+ break ;
2218
+ }
2219
+
2220
+ case TOK_GCC_ATTRIBUTE_WEAK:
2221
+ {
2222
+ typet attr (ID_weak);
2223
+ set_location (attr, tk);
2224
+ merge_types (attr, t);
2225
+ break ;
2226
+ }
2227
+
2228
+ case TOK_GCC_ATTRIBUTE_ALIAS:
2229
+ {
2230
+ cpp_tokent tk2, tk3, tk4;
2231
+
2232
+ if (lex.get_token (tk2)!=' (' )
2233
+ return false ;
2234
+
2235
+ if (!rString (tk3))
2236
+ return false ;
2237
+
2238
+ if (lex.get_token (tk4)!=' )' )
2239
+ return false ;
2240
+
2241
+ typet attr (ID_alias);
2242
+ set_location (attr, tk);
2243
+ attr.move_to_sub (tk3.data );
2244
+ merge_types (attr, t);
2245
+ break ;
2246
+ }
2247
+
2248
+ case TOK_GCC_ATTRIBUTE_SECTION:
2249
+ {
2250
+ cpp_tokent tk2, tk3, tk4;
2251
+
2252
+ if (lex.get_token (tk2)!=' (' )
2253
+ return false ;
2254
+
2255
+ if (!rString (tk3))
2256
+ return false ;
2257
+
2258
+ if (lex.get_token (tk4)!=' )' )
2259
+ return false ;
2260
+
2261
+ typet attr (ID_section);
2262
+ set_location (attr, tk);
2263
+ attr.move_to_sub (tk3.data );
2264
+ merge_types (attr, t);
2265
+ break ;
2266
+ }
2267
+
2268
+ case TOK_GCC_ATTRIBUTE_NORETURN:
2269
+ {
2270
+ typet attr (ID_noreturn);
2271
+ set_location (attr, tk);
2272
+ merge_types (attr, t);
2273
+ break ;
2274
+ }
2275
+
2276
+ case TOK_GCC_ATTRIBUTE_CONSTRUCTOR:
2277
+ {
2278
+ typet attr (ID_constructor);
2279
+ set_location (attr, tk);
2280
+ merge_types (attr, t);
2281
+ break ;
2282
+ }
2283
+
2284
+ case TOK_GCC_ATTRIBUTE_DESTRUCTOR:
2285
+ {
2286
+ typet attr (ID_destructor);
2287
+ set_location (attr, tk);
2288
+ merge_types (attr, t);
2289
+ break ;
2290
+ }
2291
+
2292
+ case ' ,' :
2293
+ if (lex.LookAhead (0 )==' )' )
2294
+ // the scanner ignored an attribute
2295
+ return true ;
2121
2296
break ;
2122
2297
2123
2298
default :
2124
2299
return false ;
2125
2300
}
2126
2301
2127
- return true ;
2302
+ if (lex.LookAhead (0 )==' )' )
2303
+ return true ;
2304
+
2305
+ return rAttribute (t);
2128
2306
}
2129
2307
2130
2308
bool Parser::optAttribute (cpp_declarationt &declaration)
@@ -2971,6 +3149,8 @@ bool Parser::rDeclarator(
2971
3149
break ;
2972
3150
}
2973
3151
3152
+ optCvQualify (d_outer);
3153
+
2974
3154
#ifdef DEBUG
2975
3155
std::cout << std::string (__indent, ' ' ) << " Parser::rDeclarator2 13\n " ;
2976
3156
#endif
0 commit comments