| 1 |
/* Library interface to C++ front end. |
| 2 |
Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. As it interacts with GDB through libcc1, |
| 5 |
they all become a single program as regards the GNU GPL's requirements. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify it under |
| 8 |
the terms of the GNU General Public License as published by the Free |
| 9 |
Software Foundation; either version 3, or (at your option) any later |
| 10 |
version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#include <cc1plugin-config.h> |
| 22 |
|
| 23 |
#undef PACKAGE_NAME |
| 24 |
#undef PACKAGE_STRING |
| 25 |
#undef PACKAGE_TARNAME |
| 26 |
#undef PACKAGE_VERSION |
| 27 |
|
| 28 |
#include "../gcc/config.h" |
| 29 |
|
| 30 |
#undef PACKAGE_NAME |
| 31 |
#undef PACKAGE_STRING |
| 32 |
#undef PACKAGE_TARNAME |
| 33 |
#undef PACKAGE_VERSION |
| 34 |
|
| 35 |
#define INCLUDE_MEMORY |
| 36 |
#define INCLUDE_VECTOR |
| 37 |
#include "gcc-plugin.h" |
| 38 |
#include "system.h" |
| 39 |
#include "coretypes.h" |
| 40 |
#include "stringpool.h" |
| 41 |
|
| 42 |
#include "gcc-interface.h" |
| 43 |
#include "machmode.h" |
| 44 |
#include "vec.h" |
| 45 |
#include "double-int.h" |
| 46 |
#include "input.h" |
| 47 |
#include "alias.h" |
| 48 |
#include "symtab.h" |
| 49 |
#include "options.h" |
| 50 |
#include "wide-int.h" |
| 51 |
#include "inchash.h" |
| 52 |
#include "tree.h" |
| 53 |
#include "fold-const.h" |
| 54 |
#include "stor-layout.h" |
| 55 |
#include "cp-tree.h" |
| 56 |
#include "toplev.h" |
| 57 |
#include "timevar.h" |
| 58 |
#include "hash-table.h" |
| 59 |
#include "tm.h" |
| 60 |
#include "c-family/c-pragma.h" |
| 61 |
// #include "c-lang.h" |
| 62 |
#include "diagnostic.h" |
| 63 |
#include "langhooks.h" |
| 64 |
#include "langhooks-def.h" |
| 65 |
#include "decl.h" |
| 66 |
#include "function.h" |
| 67 |
#undef cfun // we want to assign to it, and function.h won't let us |
| 68 |
|
| 69 |
#include "callbacks.hh" |
| 70 |
#include "connection.hh" |
| 71 |
#include "marshall-cp.hh" |
| 72 |
#include "rpc.hh" |
| 73 |
#include "context.hh" |
| 74 |
|
| 75 |
using namespace cc1_plugin; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
static_assert (GCC_CP_SYMBOL_MASK >= GCC_CP_SYMBOL_END, |
| 80 |
"GCC_CP_SYMBOL_MASK >= GCC_CP_SYMBOL_END"); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
static void |
| 85 |
plugin_binding_oracle (enum cp_oracle_request kind, tree identifier) |
| 86 |
{ |
| 87 |
enum gcc_cp_oracle_request request; |
| 88 |
|
| 89 |
gcc_assert (current_context != NULL); |
| 90 |
|
| 91 |
switch (kind) |
| 92 |
{ |
| 93 |
case CP_ORACLE_IDENTIFIER: |
| 94 |
request = GCC_CP_ORACLE_IDENTIFIER; |
| 95 |
break; |
| 96 |
default: |
| 97 |
abort (); |
| 98 |
} |
| 99 |
|
| 100 |
int ignore; |
| 101 |
cc1_plugin::call (current_context, "binding_oracle", &ignore, |
| 102 |
request, IDENTIFIER_POINTER (identifier)); |
| 103 |
} |
| 104 |
|
| 105 |
static int push_count; |
| 106 |
|
| 107 |
/* at_function_scope_p () tests cfun, indicating we're actually |
| 108 |
compiling the function, but we don't even set it when pretending to |
| 109 |
enter a function scope. We use this distinction to tell these two |
| 110 |
cases apart: we don't want to define e.g. class names in the user |
| 111 |
expression function's scope, when they're local to the original |
| 112 |
function, because they'd get the wrong linkage name. */ |
| 113 |
|
| 114 |
static bool |
| 115 |
at_fake_function_scope_p () |
| 116 |
{ |
| 117 |
return (!cfun || cfun->decl != current_function_decl) |
| 118 |
&& current_scope () == current_function_decl; |
| 119 |
} |
| 120 |
|
| 121 |
static void |
| 122 |
push_fake_function (tree fndecl, scope_kind kind = sk_function_parms) |
| 123 |
{ |
| 124 |
current_function_decl = fndecl; |
| 125 |
begin_scope (kind, fndecl); |
| 126 |
++function_depth; |
| 127 |
begin_scope (sk_block, NULL); |
| 128 |
} |
| 129 |
|
| 130 |
static void |
| 131 |
pop_scope () |
| 132 |
{ |
| 133 |
if (toplevel_bindings_p () && current_namespace == global_namespace) |
| 134 |
pop_from_top_level (); |
| 135 |
else if (at_namespace_scope_p ()) |
| 136 |
pop_namespace (); |
| 137 |
else if (at_class_scope_p ()) |
| 138 |
popclass (); |
| 139 |
else |
| 140 |
{ |
| 141 |
gcc_assert (at_fake_function_scope_p ()); |
| 142 |
gcc_assert (!at_function_scope_p ()); |
| 143 |
gcc_assert (current_binding_level->kind == sk_block |
| 144 |
&& current_binding_level->this_entity == NULL); |
| 145 |
leave_scope (); |
| 146 |
--function_depth; |
| 147 |
gcc_assert (current_binding_level->this_entity |
| 148 |
== current_function_decl); |
| 149 |
leave_scope (); |
| 150 |
current_function_decl = NULL; |
| 151 |
for (cp_binding_level *scope = current_binding_level; |
| 152 |
scope; scope = scope->level_chain) |
| 153 |
if (scope->kind == sk_function_parms) |
| 154 |
{ |
| 155 |
current_function_decl = scope->this_entity; |
| 156 |
break; |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
static void |
| 162 |
supplement_binding (cxx_binding *binding, tree decl) |
| 163 |
{ |
| 164 |
/* FIXME: this is pretty much a copy of supplement_binding_1 in |
| 165 |
../gcc/cp/name-lookup.c; the few replaced/removed bits are marked |
| 166 |
with "// _1:". */ |
| 167 |
tree bval = binding->value; |
| 168 |
bool ok = true; |
| 169 |
tree target_bval = strip_using_decl (bval); |
| 170 |
tree target_decl = strip_using_decl (decl); |
| 171 |
|
| 172 |
if (TREE_CODE (target_decl) == TYPE_DECL && DECL_ARTIFICIAL (target_decl) |
| 173 |
&& target_decl != target_bval |
| 174 |
&& (TREE_CODE (target_bval) != TYPE_DECL |
| 175 |
/* We allow pushing an enum multiple times in a class |
| 176 |
template in order to handle late matching of underlying |
| 177 |
type on an opaque-enum-declaration followed by an |
| 178 |
enum-specifier. */ |
| 179 |
|| (processing_template_decl |
| 180 |
&& TREE_CODE (TREE_TYPE (target_decl)) == ENUMERAL_TYPE |
| 181 |
&& TREE_CODE (TREE_TYPE (target_bval)) == ENUMERAL_TYPE |
| 182 |
&& (dependent_type_p (ENUM_UNDERLYING_TYPE |
| 183 |
(TREE_TYPE (target_decl))) |
| 184 |
|| dependent_type_p (ENUM_UNDERLYING_TYPE |
| 185 |
(TREE_TYPE (target_bval))))))) |
| 186 |
/* The new name is the type name. */ |
| 187 |
binding->type = decl; |
| 188 |
else if (/* TARGET_BVAL is null when push_class_level_binding moves |
| 189 |
an inherited type-binding out of the way to make room |
| 190 |
for a new value binding. */ |
| 191 |
!target_bval |
| 192 |
/* TARGET_BVAL is error_mark_node when TARGET_DECL's name |
| 193 |
has been used in a non-class scope prior declaration. |
| 194 |
In that case, we should have already issued a |
| 195 |
diagnostic; for graceful error recovery purpose, pretend |
| 196 |
this was the intended declaration for that name. */ |
| 197 |
|| target_bval == error_mark_node |
| 198 |
/* If TARGET_BVAL is anticipated but has not yet been |
| 199 |
declared, pretend it is not there at all. */ |
| 200 |
|| (TREE_CODE (target_bval) == FUNCTION_DECL |
| 201 |
&& DECL_IS_UNDECLARED_BUILTIN (target_bval))) |
| 202 |
binding->value = decl; |
| 203 |
else if (TREE_CODE (target_bval) == TYPE_DECL |
| 204 |
&& DECL_ARTIFICIAL (target_bval) |
| 205 |
&& target_decl != target_bval |
| 206 |
&& (TREE_CODE (target_decl) != TYPE_DECL |
| 207 |
|| same_type_p (TREE_TYPE (target_decl), |
| 208 |
TREE_TYPE (target_bval)))) |
| 209 |
{ |
| 210 |
/* The old binding was a type name. It was placed in |
| 211 |
VALUE field because it was thought, at the point it was |
| 212 |
declared, to be the only entity with such a name. Move the |
| 213 |
type name into the type slot; it is now hidden by the new |
| 214 |
binding. */ |
| 215 |
binding->type = bval; |
| 216 |
binding->value = decl; |
| 217 |
binding->value_is_inherited = false; |
| 218 |
} |
| 219 |
else if (TREE_CODE (target_bval) == TYPE_DECL |
| 220 |
&& TREE_CODE (target_decl) == TYPE_DECL |
| 221 |
&& DECL_NAME (target_decl) == DECL_NAME (target_bval) |
| 222 |
&& binding->scope->kind != sk_class |
| 223 |
&& (same_type_p (TREE_TYPE (target_decl), TREE_TYPE (target_bval)) |
| 224 |
/* If either type involves template parameters, we must |
| 225 |
wait until instantiation. */ |
| 226 |
|| uses_template_parms (TREE_TYPE (target_decl)) |
| 227 |
|| uses_template_parms (TREE_TYPE (target_bval)))) |
| 228 |
/* We have two typedef-names, both naming the same type to have |
| 229 |
the same name. In general, this is OK because of: |
| 230 |
|
| 231 |
[dcl.typedef] |
| 232 |
|
| 233 |
In a given scope, a typedef specifier can be used to redefine |
| 234 |
the name of any type declared in that scope to refer to the |
| 235 |
type to which it already refers. |
| 236 |
|
| 237 |
However, in class scopes, this rule does not apply due to the |
| 238 |
stricter language in [class.mem] prohibiting redeclarations of |
| 239 |
members. */ |
| 240 |
ok = false; |
| 241 |
/* There can be two block-scope declarations of the same variable, |
| 242 |
so long as they are `extern' declarations. However, there cannot |
| 243 |
be two declarations of the same static data member: |
| 244 |
|
| 245 |
[class.mem] |
| 246 |
|
| 247 |
A member shall not be declared twice in the |
| 248 |
member-specification. */ |
| 249 |
else if (VAR_P (target_decl) |
| 250 |
&& VAR_P (target_bval) |
| 251 |
&& DECL_EXTERNAL (target_decl) && DECL_EXTERNAL (target_bval) |
| 252 |
&& !DECL_CLASS_SCOPE_P (target_decl)) |
| 253 |
{ |
| 254 |
duplicate_decls (decl, binding->value); |
| 255 |
ok = false; |
| 256 |
} |
| 257 |
else if (TREE_CODE (decl) == NAMESPACE_DECL |
| 258 |
&& TREE_CODE (bval) == NAMESPACE_DECL |
| 259 |
&& DECL_NAMESPACE_ALIAS (decl) |
| 260 |
&& DECL_NAMESPACE_ALIAS (bval) |
| 261 |
&& ORIGINAL_NAMESPACE (bval) == ORIGINAL_NAMESPACE (decl)) |
| 262 |
/* [namespace.alias] |
| 263 |
|
| 264 |
In a declarative region, a namespace-alias-definition can be |
| 265 |
used to redefine a namespace-alias declared in that declarative |
| 266 |
region to refer only to the namespace to which it already |
| 267 |
refers. */ |
| 268 |
ok = false; |
| 269 |
else |
| 270 |
{ |
| 271 |
// _1: diagnose_name_conflict (decl, bval); |
| 272 |
ok = false; |
| 273 |
} |
| 274 |
|
| 275 |
gcc_assert (ok); // _1: return ok; |
| 276 |
} |
| 277 |
|
| 278 |
static void |
| 279 |
reactivate_decl (tree decl, cp_binding_level *b) |
| 280 |
{ |
| 281 |
bool in_function_p = TREE_CODE (b->this_entity) == FUNCTION_DECL; |
| 282 |
gcc_assert (in_function_p |
| 283 |
|| (b == current_binding_level |
| 284 |
&& !at_class_scope_p ())); |
| 285 |
|
| 286 |
tree id = DECL_NAME (decl); |
| 287 |
tree type = NULL_TREE; |
| 288 |
if (TREE_CODE (decl) == TYPE_DECL) |
| 289 |
type = TREE_TYPE (decl); |
| 290 |
|
| 291 |
if (type && TYPE_NAME (type) == decl |
| 292 |
&& (RECORD_OR_UNION_CODE_P (TREE_CODE (type)) |
| 293 |
|| TREE_CODE (type) == ENUMERAL_TYPE)) |
| 294 |
{ |
| 295 |
gcc_assert (in_function_p && DECL_CONTEXT (decl) == b->this_entity); |
| 296 |
type = TREE_TYPE (decl); |
| 297 |
} |
| 298 |
else |
| 299 |
{ |
| 300 |
gcc_assert (DECL_CONTEXT (decl) == b->this_entity |
| 301 |
|| DECL_CONTEXT (decl) == global_namespace |
| 302 |
|| TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL); |
| 303 |
type = NULL_TREE; |
| 304 |
} |
| 305 |
|
| 306 |
/* Adjust IDENTIFIER_BINDING to what it would have been if we were |
| 307 |
at binding level B. Save the binding chain up to that point in |
| 308 |
[binding, *chainp), and take note of the outermost bindings found |
| 309 |
before B. */ |
| 310 |
cxx_binding *binding = IDENTIFIER_BINDING (id), **chainp = NULL; |
| 311 |
tree *shadowing_type_p = NULL; |
| 312 |
if (binding) |
| 313 |
{ |
| 314 |
cp_binding_level *bc = current_binding_level; |
| 315 |
for (cxx_binding *prev_binding = binding; |
| 316 |
prev_binding; prev_binding = prev_binding->previous) |
| 317 |
{ |
| 318 |
while (bc != b && bc != prev_binding->scope) |
| 319 |
bc = bc->level_chain; |
| 320 |
if (bc == b) |
| 321 |
{ |
| 322 |
if (!chainp) |
| 323 |
binding = NULL; |
| 324 |
break; |
| 325 |
} |
| 326 |
chainp = &prev_binding->previous; |
| 327 |
if (type) |
| 328 |
for (tree tshadow = prev_binding->scope->type_shadowed; |
| 329 |
tshadow; tshadow = TREE_CHAIN (tshadow)) |
| 330 |
if (TREE_PURPOSE (tshadow) == id) |
| 331 |
{ |
| 332 |
shadowing_type_p = &TREE_VALUE (tshadow); |
| 333 |
break; |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
if (chainp) |
| 338 |
{ |
| 339 |
IDENTIFIER_BINDING (id) = *chainp; |
| 340 |
*chainp = NULL; |
| 341 |
} |
| 342 |
|
| 343 |
/* Like push_local_binding, supplement or add a binding to the |
| 344 |
desired level. */ |
| 345 |
if (IDENTIFIER_BINDING (id) && IDENTIFIER_BINDING (id)->scope == b) |
| 346 |
supplement_binding (IDENTIFIER_BINDING (id), decl); |
| 347 |
else |
| 348 |
push_binding (id, decl, b); |
| 349 |
|
| 350 |
/* Now restore the binding chain we'd temporarily removed. */ |
| 351 |
if (chainp) |
| 352 |
{ |
| 353 |
*chainp = IDENTIFIER_BINDING (id); |
| 354 |
IDENTIFIER_BINDING (id) = binding; |
| 355 |
|
| 356 |
if (type) |
| 357 |
{ |
| 358 |
/* Insert the new type binding in the shadowing_type_p |
| 359 |
TREE_VALUE chain. */ |
| 360 |
tree shadowed_type = NULL_TREE; |
| 361 |
if (shadowing_type_p) |
| 362 |
{ |
| 363 |
shadowed_type = *shadowing_type_p; |
| 364 |
*shadowing_type_p = type; |
| 365 |
} |
| 366 |
|
| 367 |
b->type_shadowed = tree_cons (id, shadowed_type, b->type_shadowed); |
| 368 |
TREE_TYPE (b->type_shadowed) = type; |
| 369 |
} |
| 370 |
} |
| 371 |
else if (type) |
| 372 |
{ |
| 373 |
/* Our new binding is the active one, so shadow the earlier |
| 374 |
binding. */ |
| 375 |
b->type_shadowed = tree_cons (id, REAL_IDENTIFIER_TYPE_VALUE (id), |
| 376 |
b->type_shadowed); |
| 377 |
TREE_TYPE (b->type_shadowed) = type; |
| 378 |
SET_IDENTIFIER_TYPE_VALUE (id, type); |
| 379 |
} |
| 380 |
|
| 381 |
/* Record that we have a binding for ID, like add_decl_to_level. */ |
| 382 |
tree node = build_tree_list (NULL_TREE, decl); |
| 383 |
TREE_CHAIN (node) = b->names; |
| 384 |
b->names = node; |
| 385 |
} |
| 386 |
|
| 387 |
static void |
| 388 |
plugin_pragma_push_user_expression (cpp_reader *) |
| 389 |
{ |
| 390 |
if (push_count++) |
| 391 |
return; |
| 392 |
|
| 393 |
gcc_assert (!current_class_ptr); |
| 394 |
gcc_assert (!current_class_ref); |
| 395 |
|
| 396 |
gcc_assert (!cp_binding_oracle); |
| 397 |
cp_binding_oracle = plugin_binding_oracle; |
| 398 |
|
| 399 |
/* Make the function containing the user expression a global |
| 400 |
friend, so as to bypass access controls in it. */ |
| 401 |
if (at_function_scope_p ()) |
| 402 |
set_global_friend (current_function_decl); |
| 403 |
|
| 404 |
gcc_assert (at_function_scope_p ()); |
| 405 |
function *save_cfun = cfun; |
| 406 |
cp_binding_level *orig_binding_level = current_binding_level; |
| 407 |
{ |
| 408 |
int success; |
| 409 |
cc1_plugin::call (current_context, "enter_scope", &success); |
| 410 |
} |
| 411 |
gcc_assert (at_fake_function_scope_p () || at_function_scope_p ()); |
| 412 |
|
| 413 |
function *unchanged_cfun = cfun; |
| 414 |
tree changed_func_decl = current_function_decl; |
| 415 |
|
| 416 |
gcc_assert (current_class_type == DECL_CONTEXT (current_function_decl) |
| 417 |
|| !(RECORD_OR_UNION_CODE_P |
| 418 |
(TREE_CODE (DECL_CONTEXT (current_function_decl))))); |
| 419 |
push_fake_function (save_cfun->decl, sk_block); |
| 420 |
current_class_type = NULL_TREE; |
| 421 |
if (unchanged_cfun) |
| 422 |
{ |
| 423 |
/* If we get here, GDB did NOT change the context. */ |
| 424 |
gcc_assert (cfun == save_cfun); |
| 425 |
gcc_assert (at_function_scope_p ()); |
| 426 |
gcc_assert (orig_binding_level |
| 427 |
== current_binding_level->level_chain->level_chain); |
| 428 |
} |
| 429 |
else |
| 430 |
{ |
| 431 |
cfun = save_cfun; |
| 432 |
gcc_assert (at_function_scope_p ()); |
| 433 |
|
| 434 |
cp_binding_level *b = current_binding_level->level_chain; |
| 435 |
gcc_assert (b->this_entity == cfun->decl); |
| 436 |
|
| 437 |
/* Reactivate local names from the previous context. Use |
| 438 |
IDENTIFIER_MARKED to avoid reactivating shadowed names. */ |
| 439 |
for (cp_binding_level *level = orig_binding_level;;) |
| 440 |
{ |
| 441 |
for (tree name = level->names; |
| 442 |
name; name = TREE_CHAIN (name)) |
| 443 |
{ |
| 444 |
tree decl = name; |
| 445 |
if (TREE_CODE (decl) == TREE_LIST) |
| 446 |
decl = TREE_VALUE (decl); |
| 447 |
if (IDENTIFIER_MARKED (DECL_NAME (decl))) |
| 448 |
continue; |
| 449 |
IDENTIFIER_MARKED (DECL_NAME (decl)) = 1; |
| 450 |
reactivate_decl (decl, b); |
| 451 |
} |
| 452 |
if (level->kind == sk_function_parms |
| 453 |
&& level->this_entity == cfun->decl) |
| 454 |
break; |
| 455 |
gcc_assert (!level->this_entity); |
| 456 |
level = level->level_chain; |
| 457 |
} |
| 458 |
|
| 459 |
/* Now, clear the markers. */ |
| 460 |
for (tree name = b->names; name; name = TREE_CHAIN (name)) |
| 461 |
{ |
| 462 |
tree decl = name; |
| 463 |
if (TREE_CODE (decl) == TREE_LIST) |
| 464 |
decl = TREE_VALUE (decl); |
| 465 |
gcc_assert (IDENTIFIER_MARKED (DECL_NAME (decl))); |
| 466 |
IDENTIFIER_MARKED (DECL_NAME (decl)) = 0; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
if (unchanged_cfun || DECL_OBJECT_MEMBER_FUNCTION_P (changed_func_decl)) |
| 471 |
{ |
| 472 |
/* Check whether the oracle supplies us with a "this", and if |
| 473 |
so, arrange for data members and this itself to be |
| 474 |
usable. */ |
| 475 |
tree this_val = lookup_name (get_identifier ("this")); |
| 476 |
current_class_ref = !this_val ? NULL_TREE |
| 477 |
: cp_build_indirect_ref (input_location, this_val, RO_NULL, |
| 478 |
tf_warning_or_error); |
| 479 |
current_class_ptr = this_val; |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
static void |
| 484 |
plugin_pragma_pop_user_expression (cpp_reader *) |
| 485 |
{ |
| 486 |
if (--push_count) |
| 487 |
return; |
| 488 |
|
| 489 |
gcc_assert (cp_binding_oracle); |
| 490 |
|
| 491 |
gcc_assert (at_function_scope_p ()); |
| 492 |
function *save_cfun = cfun; |
| 493 |
current_class_ptr = NULL_TREE; |
| 494 |
current_class_ref = NULL_TREE; |
| 495 |
|
| 496 |
cfun = NULL; |
| 497 |
pop_scope (); |
| 498 |
if (RECORD_OR_UNION_CODE_P (TREE_CODE (DECL_CONTEXT (current_function_decl)))) |
| 499 |
current_class_type = DECL_CONTEXT (current_function_decl); |
| 500 |
{ |
| 501 |
int success; |
| 502 |
cc1_plugin::call (current_context, "leave_scope", &success); |
| 503 |
} |
| 504 |
if (!cfun) |
| 505 |
cfun = save_cfun; |
| 506 |
else |
| 507 |
gcc_assert (cfun == save_cfun); |
| 508 |
|
| 509 |
cp_binding_oracle = NULL; |
| 510 |
gcc_assert (at_function_scope_p ()); |
| 511 |
} |
| 512 |
|
| 513 |
static void |
| 514 |
plugin_init_extra_pragmas (void *, void *) |
| 515 |
{ |
| 516 |
c_register_pragma ("GCC", "push_user_expression", plugin_pragma_push_user_expression); |
| 517 |
c_register_pragma ("GCC", "pop_user_expression", plugin_pragma_pop_user_expression); |
| 518 |
/* FIXME: this one should go once we get GDB to use push and pop. */ |
| 519 |
c_register_pragma ("GCC", "user_expression", plugin_pragma_push_user_expression); |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
static decl_addr_value |
| 525 |
build_decl_addr_value (tree decl, gcc_address address) |
| 526 |
{ |
| 527 |
decl_addr_value value = { |
| 528 |
decl, |
| 529 |
build_int_cst_type (ptr_type_node, address) |
| 530 |
}; |
| 531 |
return value; |
| 532 |
} |
| 533 |
|
| 534 |
static decl_addr_value * |
| 535 |
record_decl_address (plugin_context *ctx, decl_addr_value value) |
| 536 |
{ |
| 537 |
decl_addr_value **slot = ctx->address_map.find_slot (&value, INSERT); |
| 538 |
gcc_assert (*slot == NULL); |
| 539 |
*slot |
| 540 |
= static_cast<decl_addr_value *> (xmalloc (sizeof (decl_addr_value))); |
| 541 |
**slot = value; |
| 542 |
/* We don't want GCC to warn about e.g. static functions |
| 543 |
without a code definition. */ |
| 544 |
suppress_warning (value.decl); |
| 545 |
return *slot; |
| 546 |
} |
| 547 |
|
| 548 |
// Maybe rewrite a decl to its address. |
| 549 |
static tree |
| 550 |
address_rewriter (tree *in, int *walk_subtrees, void *arg) |
| 551 |
{ |
| 552 |
plugin_context *ctx = (plugin_context *) arg; |
| 553 |
|
| 554 |
if (!DECL_P (*in) |
| 555 |
|| TREE_CODE (*in) == NAMESPACE_DECL |
| 556 |
|| DECL_NAME (*in) == NULL_TREE) |
| 557 |
return NULL_TREE; |
| 558 |
|
| 559 |
decl_addr_value value; |
| 560 |
value.decl = *in; |
| 561 |
decl_addr_value *found_value = ctx->address_map.find (&value); |
| 562 |
if (found_value != NULL) |
| 563 |
; |
| 564 |
else if (HAS_DECL_ASSEMBLER_NAME_P (*in)) |
| 565 |
{ |
| 566 |
gcc_address address; |
| 567 |
|
| 568 |
if (!cc1_plugin::call (ctx, "address_oracle", &address, |
| 569 |
IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (*in)))) |
| 570 |
return NULL_TREE; |
| 571 |
if (address == 0) |
| 572 |
return NULL_TREE; |
| 573 |
|
| 574 |
// Insert the decl into the address map in case it is referenced |
| 575 |
// again. |
| 576 |
value = build_decl_addr_value (value.decl, address); |
| 577 |
found_value = record_decl_address (ctx, value); |
| 578 |
} |
| 579 |
else |
| 580 |
return NULL_TREE; |
| 581 |
|
| 582 |
if (found_value->address != error_mark_node) |
| 583 |
{ |
| 584 |
// We have an address for the decl, so rewrite the tree. |
| 585 |
tree ptr_type = build_pointer_type (TREE_TYPE (*in)); |
| 586 |
*in = fold_build1 (INDIRECT_REF, TREE_TYPE (*in), |
| 587 |
fold_build1 (CONVERT_EXPR, ptr_type, |
| 588 |
found_value->address)); |
| 589 |
} |
| 590 |
|
| 591 |
*walk_subtrees = 0; |
| 592 |
|
| 593 |
return NULL_TREE; |
| 594 |
} |
| 595 |
|
| 596 |
// When generating code for gdb, we want to be able to use absolute |
| 597 |
// addresses to refer to otherwise external objects that gdb knows |
| 598 |
// about. gdb passes in these addresses when building decls, and then |
| 599 |
// before gimplification we go through the trees, rewriting uses to |
| 600 |
// the equivalent of "*(TYPE *) ADDR". |
| 601 |
static void |
| 602 |
rewrite_decls_to_addresses (void *function_in, void *) |
| 603 |
{ |
| 604 |
tree function = (tree) function_in; |
| 605 |
|
| 606 |
// Do nothing if we're not in gdb. |
| 607 |
if (current_context == NULL) |
| 608 |
return; |
| 609 |
|
| 610 |
walk_tree (&DECL_SAVED_TREE (function), address_rewriter, current_context, |
| 611 |
NULL); |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
static inline tree |
| 617 |
safe_push_template_decl (tree decl) |
| 618 |
{ |
| 619 |
void (*save_oracle) (enum cp_oracle_request, tree identifier); |
| 620 |
|
| 621 |
save_oracle = cp_binding_oracle; |
| 622 |
cp_binding_oracle = NULL; |
| 623 |
|
| 624 |
tree ret = push_template_decl (decl); |
| 625 |
|
| 626 |
cp_binding_oracle = save_oracle; |
| 627 |
|
| 628 |
return ret; |
| 629 |
} |
| 630 |
|
| 631 |
static inline tree |
| 632 |
safe_pushtag (tree name, tree type) |
| 633 |
{ |
| 634 |
void (*save_oracle) (enum cp_oracle_request, tree identifier); |
| 635 |
|
| 636 |
save_oracle = cp_binding_oracle; |
| 637 |
cp_binding_oracle = NULL; |
| 638 |
|
| 639 |
tree ret = pushtag (name, type); |
| 640 |
|
| 641 |
cp_binding_oracle = save_oracle; |
| 642 |
|
| 643 |
return ret; |
| 644 |
} |
| 645 |
|
| 646 |
static inline tree |
| 647 |
safe_pushdecl (tree decl) |
| 648 |
{ |
| 649 |
void (*save_oracle) (enum cp_oracle_request, tree identifier); |
| 650 |
|
| 651 |
save_oracle = cp_binding_oracle; |
| 652 |
cp_binding_oracle = NULL; |
| 653 |
|
| 654 |
tree ret = pushdecl (decl); |
| 655 |
|
| 656 |
cp_binding_oracle = save_oracle; |
| 657 |
|
| 658 |
return ret; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
int |
| 664 |
plugin_push_namespace (cc1_plugin::connection *, |
| 665 |
const char *name) |
| 666 |
{ |
| 667 |
if (name && !*name) |
| 668 |
push_to_top_level (); |
| 669 |
else |
| 670 |
push_namespace (name ? get_identifier (name) : NULL); |
| 671 |
|
| 672 |
return 1; |
| 673 |
} |
| 674 |
|
| 675 |
int |
| 676 |
plugin_push_class (cc1_plugin::connection *, |
| 677 |
gcc_type type_in) |
| 678 |
{ |
| 679 |
tree type = convert_in (type_in); |
| 680 |
gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type))); |
| 681 |
gcc_assert (TYPE_CONTEXT (type) == FROB_CONTEXT (current_scope ())); |
| 682 |
|
| 683 |
pushclass (type); |
| 684 |
|
| 685 |
return 1; |
| 686 |
} |
| 687 |
|
| 688 |
int |
| 689 |
plugin_push_function (cc1_plugin::connection *, |
| 690 |
gcc_decl function_decl_in) |
| 691 |
{ |
| 692 |
tree fndecl = convert_in (function_decl_in); |
| 693 |
gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL); |
| 694 |
gcc_assert (DECL_CONTEXT (fndecl) == FROB_CONTEXT (current_scope ())); |
| 695 |
|
| 696 |
push_fake_function (fndecl); |
| 697 |
|
| 698 |
return 1; |
| 699 |
} |
| 700 |
|
| 701 |
int |
| 702 |
plugin_pop_binding_level (cc1_plugin::connection *) |
| 703 |
{ |
| 704 |
pop_scope (); |
| 705 |
return 1; |
| 706 |
} |
| 707 |
|
| 708 |
int |
| 709 |
plugin_reactivate_decl (cc1_plugin::connection *, |
| 710 |
gcc_decl decl_in, |
| 711 |
gcc_decl scope_in) |
| 712 |
{ |
| 713 |
tree decl = convert_in (decl_in); |
| 714 |
tree scope = convert_in (scope_in); |
| 715 |
gcc_assert (VAR_P (decl) |
| 716 |
|| TREE_CODE (decl) == FUNCTION_DECL |
| 717 |
|| TREE_CODE (decl) == TYPE_DECL); |
| 718 |
cp_binding_level *b; |
| 719 |
if (scope) |
| 720 |
{ |
| 721 |
gcc_assert (TREE_CODE (scope) == FUNCTION_DECL); |
| 722 |
for (b = current_binding_level; |
| 723 |
b->this_entity != scope; |
| 724 |
b = b->level_chain) |
| 725 |
gcc_assert (b->this_entity != global_namespace); |
| 726 |
} |
| 727 |
else |
| 728 |
{ |
| 729 |
gcc_assert (!at_class_scope_p ()); |
| 730 |
b = current_binding_level; |
| 731 |
} |
| 732 |
|
| 733 |
reactivate_decl (decl, b); |
| 734 |
return 1; |
| 735 |
} |
| 736 |
|
| 737 |
static tree |
| 738 |
get_current_scope () |
| 739 |
{ |
| 740 |
tree decl; |
| 741 |
|
| 742 |
if (at_namespace_scope_p ()) |
| 743 |
decl = current_namespace; |
| 744 |
else if (at_class_scope_p ()) |
| 745 |
decl = TYPE_NAME (current_class_type); |
| 746 |
else if (at_fake_function_scope_p () || at_function_scope_p ()) |
| 747 |
decl = current_function_decl; |
| 748 |
else |
| 749 |
gcc_unreachable (); |
| 750 |
|
| 751 |
return decl; |
| 752 |
} |
| 753 |
|
| 754 |
gcc_decl |
| 755 |
plugin_get_current_binding_level_decl (cc1_plugin::connection *) |
| 756 |
{ |
| 757 |
tree decl = get_current_scope (); |
| 758 |
|
| 759 |
return convert_out (decl); |
| 760 |
} |
| 761 |
|
| 762 |
int |
| 763 |
plugin_make_namespace_inline (cc1_plugin::connection *) |
| 764 |
{ |
| 765 |
tree inline_ns = current_namespace; |
| 766 |
|
| 767 |
gcc_assert (toplevel_bindings_p ()); |
| 768 |
gcc_assert (inline_ns != global_namespace); |
| 769 |
|
| 770 |
tree parent_ns = CP_DECL_CONTEXT (inline_ns); |
| 771 |
|
| 772 |
if (DECL_NAMESPACE_INLINE_P (inline_ns)) |
| 773 |
return 0; |
| 774 |
|
| 775 |
DECL_NAMESPACE_INLINE_P (inline_ns) = true; |
| 776 |
vec_safe_push (DECL_NAMESPACE_INLINEES (parent_ns), inline_ns); |
| 777 |
|
| 778 |
return 1; |
| 779 |
} |
| 780 |
|
| 781 |
int |
| 782 |
plugin_add_using_namespace (cc1_plugin::connection *, |
| 783 |
gcc_decl used_ns_in) |
| 784 |
{ |
| 785 |
tree used_ns = convert_in (used_ns_in); |
| 786 |
|
| 787 |
gcc_assert (TREE_CODE (used_ns) == NAMESPACE_DECL); |
| 788 |
|
| 789 |
finish_using_directive (used_ns, NULL_TREE); |
| 790 |
|
| 791 |
return 1; |
| 792 |
} |
| 793 |
|
| 794 |
int |
| 795 |
plugin_add_namespace_alias (cc1_plugin::connection *, |
| 796 |
const char *id, |
| 797 |
gcc_decl target_in) |
| 798 |
{ |
| 799 |
tree name = get_identifier (id); |
| 800 |
tree target = convert_in (target_in); |
| 801 |
|
| 802 |
do_namespace_alias (input_location, name, target); |
| 803 |
|
| 804 |
return 1; |
| 805 |
} |
| 806 |
|
| 807 |
static inline void |
| 808 |
set_access_flags (tree decl, enum gcc_cp_symbol_kind flags) |
| 809 |
{ |
| 810 |
gcc_assert (!(flags & GCC_CP_ACCESS_MASK) == !DECL_CLASS_SCOPE_P (decl)); |
| 811 |
|
| 812 |
switch (flags & GCC_CP_ACCESS_MASK) |
| 813 |
{ |
| 814 |
case GCC_CP_ACCESS_PRIVATE: |
| 815 |
TREE_PRIVATE (decl) = true; |
| 816 |
current_access_specifier = access_private_node; |
| 817 |
break; |
| 818 |
|
| 819 |
case GCC_CP_ACCESS_PROTECTED: |
| 820 |
TREE_PROTECTED (decl) = true; |
| 821 |
current_access_specifier = access_protected_node; |
| 822 |
break; |
| 823 |
|
| 824 |
case GCC_CP_ACCESS_PUBLIC: |
| 825 |
current_access_specifier = access_public_node; |
| 826 |
break; |
| 827 |
|
| 828 |
default: |
| 829 |
break; |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
int |
| 834 |
plugin_add_using_decl (cc1_plugin::connection *, |
| 835 |
enum gcc_cp_symbol_kind flags, |
| 836 |
gcc_decl target_in) |
| 837 |
{ |
| 838 |
tree target = convert_in (target_in); |
| 839 |
gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_USING); |
| 840 |
gcc_assert (!(flags & GCC_CP_FLAG_MASK)); |
| 841 |
enum gcc_cp_symbol_kind acc_flags; |
| 842 |
acc_flags = (enum gcc_cp_symbol_kind) (flags & GCC_CP_ACCESS_MASK); |
| 843 |
|
| 844 |
gcc_assert (!template_parm_scope_p ()); |
| 845 |
|
| 846 |
bool class_member_p = at_class_scope_p (); |
| 847 |
gcc_assert (!(acc_flags & GCC_CP_ACCESS_MASK) == !class_member_p); |
| 848 |
|
| 849 |
tree identifier = DECL_NAME (target); |
| 850 |
tree tcontext = DECL_CONTEXT (target); |
| 851 |
|
| 852 |
if (UNSCOPED_ENUM_P (tcontext)) |
| 853 |
tcontext = CP_TYPE_CONTEXT (tcontext); |
| 854 |
|
| 855 |
if (class_member_p) |
| 856 |
{ |
| 857 |
tree decl = do_class_using_decl (tcontext, identifier); |
| 858 |
|
| 859 |
set_access_flags (decl, flags); |
| 860 |
|
| 861 |
finish_member_declaration (decl); |
| 862 |
} |
| 863 |
else |
| 864 |
{ |
| 865 |
/* We can't be at local scope. */ |
| 866 |
gcc_assert (at_namespace_scope_p ()); |
| 867 |
finish_nonmember_using_decl (tcontext, identifier); |
| 868 |
} |
| 869 |
|
| 870 |
return 1; |
| 871 |
} |
| 872 |
|
| 873 |
static tree |
| 874 |
build_named_class_type (enum tree_code code, |
| 875 |
tree id, |
| 876 |
location_t loc) |
| 877 |
{ |
| 878 |
/* See at_fake_function_scope_p. */ |
| 879 |
gcc_assert (!at_function_scope_p ()); |
| 880 |
tree type = make_class_type (code); |
| 881 |
tree type_decl = build_decl (loc, TYPE_DECL, id, type); |
| 882 |
TYPE_NAME (type) = type_decl; |
| 883 |
TYPE_STUB_DECL (type) = type_decl; |
| 884 |
DECL_CONTEXT (type_decl) = TYPE_CONTEXT (type); |
| 885 |
|
| 886 |
return type_decl; |
| 887 |
} |
| 888 |
|
| 889 |
/* Abuse an unused field of the dummy template parms entry to hold the |
| 890 |
parm list. */ |
| 891 |
#define TP_PARM_LIST TREE_TYPE (current_template_parms) |
| 892 |
|
| 893 |
gcc_decl |
| 894 |
plugin_build_decl (cc1_plugin::connection *self, |
| 895 |
const char *name, |
| 896 |
enum gcc_cp_symbol_kind sym_kind, |
| 897 |
gcc_type sym_type_in, |
| 898 |
const char *substitution_name, |
| 899 |
gcc_address address, |
| 900 |
const char *filename, |
| 901 |
unsigned int line_number) |
| 902 |
{ |
| 903 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 904 |
gcc_assert (!name || !strchr (name, ':')); // FIXME: this can go eventually. |
| 905 |
|
| 906 |
enum tree_code code; |
| 907 |
tree decl; |
| 908 |
tree sym_type = convert_in (sym_type_in); |
| 909 |
enum gcc_cp_symbol_kind sym_flags; |
| 910 |
sym_flags = (enum gcc_cp_symbol_kind) (sym_kind & GCC_CP_FLAG_MASK); |
| 911 |
enum gcc_cp_symbol_kind acc_flags; |
| 912 |
acc_flags = (enum gcc_cp_symbol_kind) (sym_kind & GCC_CP_ACCESS_MASK); |
| 913 |
sym_kind = (enum gcc_cp_symbol_kind) (sym_kind & GCC_CP_SYMBOL_MASK); |
| 914 |
|
| 915 |
switch (sym_kind) |
| 916 |
{ |
| 917 |
case GCC_CP_SYMBOL_FUNCTION: |
| 918 |
code = FUNCTION_DECL; |
| 919 |
gcc_assert (!(sym_flags & ~GCC_CP_FLAG_MASK_FUNCTION)); |
| 920 |
break; |
| 921 |
|
| 922 |
case GCC_CP_SYMBOL_VARIABLE: |
| 923 |
code = VAR_DECL; |
| 924 |
gcc_assert (!(sym_flags & ~GCC_CP_FLAG_MASK_VARIABLE)); |
| 925 |
break; |
| 926 |
|
| 927 |
case GCC_CP_SYMBOL_TYPEDEF: |
| 928 |
code = TYPE_DECL; |
| 929 |
gcc_assert (!sym_flags); |
| 930 |
break; |
| 931 |
|
| 932 |
case GCC_CP_SYMBOL_CLASS: |
| 933 |
code = RECORD_TYPE; |
| 934 |
gcc_assert (!(sym_flags & ~GCC_CP_FLAG_MASK_CLASS)); |
| 935 |
gcc_assert (!sym_type); |
| 936 |
break; |
| 937 |
|
| 938 |
case GCC_CP_SYMBOL_UNION: |
| 939 |
code = UNION_TYPE; |
| 940 |
gcc_assert (!sym_flags); |
| 941 |
gcc_assert (!sym_type); |
| 942 |
break; |
| 943 |
|
| 944 |
default: |
| 945 |
gcc_unreachable (); |
| 946 |
} |
| 947 |
|
| 948 |
bool template_decl_p = template_parm_scope_p (); |
| 949 |
|
| 950 |
if (template_decl_p) |
| 951 |
{ |
| 952 |
gcc_assert (code == FUNCTION_DECL || code == RECORD_TYPE |
| 953 |
|| code == TYPE_DECL); |
| 954 |
|
| 955 |
/* Finish the template parm list that started this template parm. */ |
| 956 |
end_template_parm_list (TP_PARM_LIST); |
| 957 |
|
| 958 |
gcc_assert (!address); |
| 959 |
gcc_assert (!substitution_name); |
| 960 |
} |
| 961 |
|
| 962 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 963 |
bool class_member_p = at_class_scope_p (); |
| 964 |
bool ctor = false, dtor = false, assop = false; |
| 965 |
tree_code opcode = ERROR_MARK; |
| 966 |
|
| 967 |
gcc_assert (!(acc_flags & GCC_CP_ACCESS_MASK) == !class_member_p); |
| 968 |
|
| 969 |
tree identifier; |
| 970 |
if (code != FUNCTION_DECL |
| 971 |
|| !(sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION)) |
| 972 |
{ |
| 973 |
if (name) |
| 974 |
identifier = get_identifier (name); |
| 975 |
else |
| 976 |
{ |
| 977 |
gcc_assert (RECORD_OR_UNION_CODE_P (code)); |
| 978 |
identifier = make_anon_name (); |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
if (code == FUNCTION_DECL) |
| 983 |
{ |
| 984 |
if (sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION) |
| 985 |
{ |
| 986 |
#define CHARS2(f,s) (((unsigned char)f << CHAR_BIT) | (unsigned char)s) |
| 987 |
switch (CHARS2 (name[0], name[1])) |
| 988 |
{ |
| 989 |
case CHARS2 ('C', 0x0): // ctor base declaration |
| 990 |
case CHARS2 ('C', ' '): |
| 991 |
case CHARS2 ('C', '1'): |
| 992 |
case CHARS2 ('C', '2'): |
| 993 |
case CHARS2 ('C', '4'): |
| 994 |
ctor = true; |
| 995 |
cdtor: |
| 996 |
gcc_assert (!address); |
| 997 |
gcc_assert (!substitution_name); |
| 998 |
identifier = DECL_NAME (TYPE_NAME (current_class_type)); |
| 999 |
break; |
| 1000 |
case CHARS2 ('D', 0x0): // dtor base declaration |
| 1001 |
case CHARS2 ('D', ' '): |
| 1002 |
case CHARS2 ('D', '0'): |
| 1003 |
case CHARS2 ('D', '1'): |
| 1004 |
case CHARS2 ('D', '2'): |
| 1005 |
case CHARS2 ('D', '4'): |
| 1006 |
gcc_assert (!template_decl_p); |
| 1007 |
dtor = true; |
| 1008 |
goto cdtor; |
| 1009 |
case CHARS2 ('n', 'w'): // operator new |
| 1010 |
opcode = NEW_EXPR; |
| 1011 |
break; |
| 1012 |
case CHARS2 ('n', 'a'): // operator new[] |
| 1013 |
opcode = VEC_NEW_EXPR; |
| 1014 |
break; |
| 1015 |
case CHARS2 ('d', 'l'): // operator delete |
| 1016 |
opcode = DELETE_EXPR; |
| 1017 |
break; |
| 1018 |
case CHARS2 ('d', 'a'): // operator delete[] |
| 1019 |
opcode = VEC_DELETE_EXPR; |
| 1020 |
break; |
| 1021 |
case CHARS2 ('p', 's'): // operator + (unary) |
| 1022 |
opcode = PLUS_EXPR; |
| 1023 |
break; |
| 1024 |
case CHARS2 ('n', 'g'): // operator - (unary) |
| 1025 |
opcode = MINUS_EXPR; |
| 1026 |
break; |
| 1027 |
case CHARS2 ('a', 'd'): // operator & (unary) |
| 1028 |
opcode = BIT_AND_EXPR; |
| 1029 |
break; |
| 1030 |
case CHARS2 ('d', 'e'): // operator * (unary) |
| 1031 |
opcode = MULT_EXPR; |
| 1032 |
break; |
| 1033 |
case CHARS2 ('c', 'o'): // operator ~ |
| 1034 |
opcode = BIT_NOT_EXPR; |
| 1035 |
break; |
| 1036 |
case CHARS2 ('p', 'l'): // operator + |
| 1037 |
opcode = PLUS_EXPR; |
| 1038 |
break; |
| 1039 |
case CHARS2 ('m', 'i'): // operator - |
| 1040 |
opcode = MINUS_EXPR; |
| 1041 |
break; |
| 1042 |
case CHARS2 ('m', 'l'): // operator * |
| 1043 |
opcode = MULT_EXPR; |
| 1044 |
break; |
| 1045 |
case CHARS2 ('d', 'v'): // operator / |
| 1046 |
opcode = TRUNC_DIV_EXPR; |
| 1047 |
break; |
| 1048 |
case CHARS2 ('r', 'm'): // operator % |
| 1049 |
opcode = TRUNC_MOD_EXPR; |
| 1050 |
break; |
| 1051 |
case CHARS2 ('a', 'n'): // operator & |
| 1052 |
opcode = BIT_AND_EXPR; |
| 1053 |
break; |
| 1054 |
case CHARS2 ('o', 'r'): // operator | |
| 1055 |
opcode = BIT_IOR_EXPR; |
| 1056 |
break; |
| 1057 |
case CHARS2 ('e', 'o'): // operator ^ |
| 1058 |
opcode = BIT_XOR_EXPR; |
| 1059 |
break; |
| 1060 |
case CHARS2 ('a', 'S'): // operator = |
| 1061 |
opcode = NOP_EXPR; |
| 1062 |
assop = true; |
| 1063 |
break; |
| 1064 |
case CHARS2 ('p', 'L'): // operator += |
| 1065 |
opcode = PLUS_EXPR; |
| 1066 |
assop = true; |
| 1067 |
break; |
| 1068 |
case CHARS2 ('m', 'I'): // operator -= |
| 1069 |
opcode = MINUS_EXPR; |
| 1070 |
assop = true; |
| 1071 |
break; |
| 1072 |
case CHARS2 ('m', 'L'): // operator *= |
| 1073 |
opcode = MULT_EXPR; |
| 1074 |
assop = true; |
| 1075 |
break; |
| 1076 |
case CHARS2 ('d', 'V'): // operator /= |
| 1077 |
opcode = TRUNC_DIV_EXPR; |
| 1078 |
assop = true; |
| 1079 |
break; |
| 1080 |
case CHARS2 ('r', 'M'): // operator %= |
| 1081 |
opcode = TRUNC_MOD_EXPR; |
| 1082 |
assop = true; |
| 1083 |
break; |
| 1084 |
case CHARS2 ('a', 'N'): // operator &= |
| 1085 |
opcode = BIT_AND_EXPR; |
| 1086 |
assop = true; |
| 1087 |
break; |
| 1088 |
case CHARS2 ('o', 'R'): // operator |= |
| 1089 |
opcode = BIT_IOR_EXPR; |
| 1090 |
assop = true; |
| 1091 |
break; |
| 1092 |
case CHARS2 ('e', 'O'): // operator ^= |
| 1093 |
opcode = BIT_XOR_EXPR; |
| 1094 |
assop = true; |
| 1095 |
break; |
| 1096 |
case CHARS2 ('l', 's'): // operator << |
| 1097 |
opcode = LSHIFT_EXPR; |
| 1098 |
break; |
| 1099 |
case CHARS2 ('r', 's'): // operator >> |
| 1100 |
opcode = RSHIFT_EXPR; |
| 1101 |
break; |
| 1102 |
case CHARS2 ('l', 'S'): // operator <<= |
| 1103 |
opcode = LSHIFT_EXPR; |
| 1104 |
assop = true; |
| 1105 |
break; |
| 1106 |
case CHARS2 ('r', 'S'): // operator >>= |
| 1107 |
opcode = RSHIFT_EXPR; |
| 1108 |
assop = true; |
| 1109 |
break; |
| 1110 |
case CHARS2 ('e', 'q'): // operator == |
| 1111 |
opcode = EQ_EXPR; |
| 1112 |
break; |
| 1113 |
case CHARS2 ('n', 'e'): // operator != |
| 1114 |
opcode = NE_EXPR; |
| 1115 |
break; |
| 1116 |
case CHARS2 ('l', 't'): // operator < |
| 1117 |
opcode = LT_EXPR; |
| 1118 |
break; |
| 1119 |
case CHARS2 ('g', 't'): // operator > |
| 1120 |
opcode = GT_EXPR; |
| 1121 |
break; |
| 1122 |
case CHARS2 ('l', 'e'): // operator <= |
| 1123 |
opcode = LE_EXPR; |
| 1124 |
break; |
| 1125 |
case CHARS2 ('g', 'e'): // operator >= |
| 1126 |
opcode = GE_EXPR; |
| 1127 |
break; |
| 1128 |
case CHARS2 ('n', 't'): // operator ! |
| 1129 |
opcode = TRUTH_NOT_EXPR; |
| 1130 |
break; |
| 1131 |
case CHARS2 ('a', 'a'): // operator && |
| 1132 |
opcode = TRUTH_ANDIF_EXPR; |
| 1133 |
break; |
| 1134 |
case CHARS2 ('o', 'o'): // operator || |
| 1135 |
opcode = TRUTH_ORIF_EXPR; |
| 1136 |
break; |
| 1137 |
case CHARS2 ('p', 'p'): // operator ++ |
| 1138 |
opcode = POSTINCREMENT_EXPR; |
| 1139 |
break; |
| 1140 |
case CHARS2 ('m', 'm'): // operator -- |
| 1141 |
/* This stands for either one as an operator name, and |
| 1142 |
"pp" and "mm" stand for POST??CREMENT, but for some |
| 1143 |
reason the parser uses this opcode name for |
| 1144 |
operator--; let's follow their practice. */ |
| 1145 |
opcode = PREDECREMENT_EXPR; |
| 1146 |
break; |
| 1147 |
case CHARS2 ('c', 'm'): // operator , |
| 1148 |
opcode = COMPOUND_EXPR; |
| 1149 |
break; |
| 1150 |
case CHARS2 ('p', 'm'): // operator ->* |
| 1151 |
opcode = MEMBER_REF; |
| 1152 |
break; |
| 1153 |
case CHARS2 ('p', 't'): // operator -> |
| 1154 |
opcode = COMPONENT_REF; |
| 1155 |
break; |
| 1156 |
case CHARS2 ('c', 'l'): // operator () |
| 1157 |
opcode = CALL_EXPR; |
| 1158 |
break; |
| 1159 |
case CHARS2 ('i', 'x'): // operator [] |
| 1160 |
opcode = ARRAY_REF; |
| 1161 |
break; |
| 1162 |
case CHARS2 ('c', 'v'): // operator <T> (conversion operator) |
| 1163 |
identifier = make_conv_op_name (TREE_TYPE (sym_type)); |
| 1164 |
break; |
| 1165 |
// C++11-only: |
| 1166 |
case CHARS2 ('l', 'i'): // operator "" <id> |
| 1167 |
{ |
| 1168 |
char *id = (char *)name + 2; |
| 1169 |
bool freeid = false; |
| 1170 |
if (*id >= '0' && *id <= '9') |
| 1171 |
{ |
| 1172 |
unsigned len = 0; |
| 1173 |
do |
| 1174 |
{ |
| 1175 |
len *= 10; |
| 1176 |
len += id[0] - '0'; |
| 1177 |
id++; |
| 1178 |
} |
| 1179 |
while (*id && *id >= '0' && *id <= '9'); |
| 1180 |
id = xstrndup (id, len); |
| 1181 |
freeid = true; |
| 1182 |
} |
| 1183 |
identifier = cp_literal_operator_id (id); |
| 1184 |
if (freeid) |
| 1185 |
free (id); |
| 1186 |
} |
| 1187 |
break; |
| 1188 |
case CHARS2 ('q', 'u'): // ternary operator, not overloadable. |
| 1189 |
default: |
| 1190 |
gcc_unreachable (); |
| 1191 |
} |
| 1192 |
|
| 1193 |
if (opcode != ERROR_MARK) |
| 1194 |
identifier = ovl_op_identifier (assop, opcode); |
| 1195 |
} |
| 1196 |
decl = build_lang_decl_loc (loc, code, identifier, sym_type); |
| 1197 |
/* FIXME: current_lang_name is lang_name_c while compiling an |
| 1198 |
extern "C" function, and we haven't switched to a global |
| 1199 |
context at this point, and this breaks function |
| 1200 |
overloading. */ |
| 1201 |
SET_DECL_LANGUAGE (decl, lang_cplusplus); |
| 1202 |
if (TREE_CODE (sym_type) == METHOD_TYPE) |
| 1203 |
DECL_ARGUMENTS (decl) = build_this_parm (decl, current_class_type, |
| 1204 |
cp_type_quals (sym_type)); |
| 1205 |
for (tree arg = TREE_CODE (sym_type) == METHOD_TYPE |
| 1206 |
? TREE_CHAIN (TYPE_ARG_TYPES (sym_type)) |
| 1207 |
: TYPE_ARG_TYPES (sym_type); |
| 1208 |
arg && arg != void_list_node; |
| 1209 |
arg = TREE_CHAIN (arg)) |
| 1210 |
{ |
| 1211 |
tree parm = cp_build_parm_decl (decl, NULL_TREE, TREE_VALUE (arg)); |
| 1212 |
DECL_CHAIN (parm) = DECL_ARGUMENTS (decl); |
| 1213 |
DECL_ARGUMENTS (decl) = parm; |
| 1214 |
} |
| 1215 |
DECL_ARGUMENTS (decl) = nreverse (DECL_ARGUMENTS (decl)); |
| 1216 |
if (class_member_p) |
| 1217 |
{ |
| 1218 |
if (TREE_CODE (sym_type) == FUNCTION_TYPE) |
| 1219 |
DECL_STATIC_FUNCTION_P (decl) = 1; |
| 1220 |
if (sym_flags & GCC_CP_FLAG_VIRTUAL_FUNCTION) |
| 1221 |
{ |
| 1222 |
DECL_VIRTUAL_P (decl) = 1; |
| 1223 |
if (sym_flags & GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION) |
| 1224 |
DECL_PURE_VIRTUAL_P (decl) = 1; |
| 1225 |
if (sym_flags & GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION) |
| 1226 |
DECL_FINAL_P (decl) = 1; |
| 1227 |
} |
| 1228 |
else |
| 1229 |
gcc_assert (!(sym_flags & (GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION |
| 1230 |
| GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION))); |
| 1231 |
} |
| 1232 |
else |
| 1233 |
{ |
| 1234 |
gcc_assert (!(sym_flags & (GCC_CP_FLAG_VIRTUAL_FUNCTION |
| 1235 |
| GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION |
| 1236 |
| GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION))); |
| 1237 |
gcc_assert (!ctor && !dtor && !assop); |
| 1238 |
} |
| 1239 |
if (sym_flags & GCC_CP_FLAG_EXPLICIT_FUNCTION) |
| 1240 |
DECL_NONCONVERTING_P (decl) = 1; |
| 1241 |
if (sym_flags & GCC_CP_FLAG_DEFAULTED_FUNCTION) |
| 1242 |
{ |
| 1243 |
DECL_INITIAL (decl) = ridpointers[(int)RID_DEFAULT]; |
| 1244 |
DECL_DEFAULTED_FN (decl) = 1; |
| 1245 |
} |
| 1246 |
if (sym_flags & GCC_CP_FLAG_DELETED_FUNCTION) |
| 1247 |
{ |
| 1248 |
// DECL_INITIAL (decl) = ridpointers[(int)RID_DELETE]; |
| 1249 |
DECL_DELETED_FN (decl) = 1; |
| 1250 |
DECL_DECLARED_INLINE_P (decl) = 1; |
| 1251 |
DECL_INITIAL (decl) = error_mark_node; |
| 1252 |
} |
| 1253 |
|
| 1254 |
if (ctor) |
| 1255 |
DECL_CXX_CONSTRUCTOR_P (decl) = 1; |
| 1256 |
else if (dtor) |
| 1257 |
DECL_CXX_DESTRUCTOR_P (decl) = 1; |
| 1258 |
else if ((sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION) |
| 1259 |
&& opcode != ERROR_MARK) |
| 1260 |
DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op_mapping[opcode]; |
| 1261 |
} |
| 1262 |
else if (RECORD_OR_UNION_CODE_P (code)) |
| 1263 |
{ |
| 1264 |
decl = build_named_class_type (code, identifier, loc); |
| 1265 |
tree type = TREE_TYPE (decl); |
| 1266 |
|
| 1267 |
if (code == RECORD_TYPE |
| 1268 |
&& !(sym_flags & GCC_CP_FLAG_CLASS_IS_STRUCT)) |
| 1269 |
CLASSTYPE_DECLARED_CLASS (type) = true; |
| 1270 |
} |
| 1271 |
else if (class_member_p) |
| 1272 |
{ |
| 1273 |
decl = build_lang_decl_loc (loc, code, identifier, sym_type); |
| 1274 |
|
| 1275 |
if (TREE_CODE (decl) == VAR_DECL) |
| 1276 |
{ |
| 1277 |
DECL_THIS_STATIC (decl) = 1; |
| 1278 |
// The remainder of this block does the same as: |
| 1279 |
// set_linkage_for_static_data_member (decl); |
| 1280 |
TREE_PUBLIC (decl) = 1; |
| 1281 |
TREE_STATIC (decl) = 1; |
| 1282 |
DECL_INTERFACE_KNOWN (decl) = 1; |
| 1283 |
|
| 1284 |
// FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE |
| 1285 |
gcc_assert (!(sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE)); |
| 1286 |
|
| 1287 |
if (sym_flags & GCC_CP_FLAG_CONSTEXPR_VARIABLE) |
| 1288 |
DECL_DECLARED_CONSTEXPR_P (decl) = true; |
| 1289 |
} |
| 1290 |
} |
| 1291 |
else |
| 1292 |
{ |
| 1293 |
decl = build_decl (loc, code, identifier, sym_type); |
| 1294 |
|
| 1295 |
if (TREE_CODE (decl) == VAR_DECL) |
| 1296 |
{ |
| 1297 |
// FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE |
| 1298 |
gcc_assert (!(sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE)); |
| 1299 |
|
| 1300 |
if (sym_flags & GCC_CP_FLAG_CONSTEXPR_VARIABLE) |
| 1301 |
DECL_DECLARED_CONSTEXPR_P (decl) = true; |
| 1302 |
} |
| 1303 |
} |
| 1304 |
TREE_USED (decl) = 1; |
| 1305 |
TREE_ADDRESSABLE (decl) = 1; |
| 1306 |
|
| 1307 |
if (class_member_p) |
| 1308 |
DECL_CONTEXT (decl) = FROB_CONTEXT (current_class_type); |
| 1309 |
else if (at_namespace_scope_p ()) |
| 1310 |
DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ()); |
| 1311 |
|
| 1312 |
set_access_flags (decl, acc_flags); |
| 1313 |
|
| 1314 |
/* If this is the typedef that names an otherwise anonymous type, |
| 1315 |
propagate the typedef name to the type. In normal compilation, |
| 1316 |
this is done in grokdeclarator. */ |
| 1317 |
if (sym_kind == GCC_CP_SYMBOL_TYPEDEF |
| 1318 |
&& !template_decl_p |
| 1319 |
&& DECL_CONTEXT (decl) == TYPE_CONTEXT (sym_type) |
| 1320 |
&& TYPE_UNNAMED_P (sym_type)) |
| 1321 |
name_unnamed_type (sym_type, decl); |
| 1322 |
|
| 1323 |
if (sym_kind != GCC_CP_SYMBOL_TYPEDEF |
| 1324 |
&& sym_kind != GCC_CP_SYMBOL_CLASS |
| 1325 |
&& sym_kind != GCC_CP_SYMBOL_UNION |
| 1326 |
&& !template_decl_p && !ctor && !dtor) |
| 1327 |
{ |
| 1328 |
decl_addr_value value; |
| 1329 |
|
| 1330 |
DECL_EXTERNAL (decl) = 1; |
| 1331 |
value.decl = decl; |
| 1332 |
if (substitution_name != NULL) |
| 1333 |
{ |
| 1334 |
// If the translator gave us a name without a binding, |
| 1335 |
// we can just substitute error_mark_node, since we know the |
| 1336 |
// translator will be reporting an error anyhow. |
| 1337 |
value.address |
| 1338 |
= lookup_name (get_identifier (substitution_name)); |
| 1339 |
if (value.address == NULL_TREE) |
| 1340 |
value.address = error_mark_node; |
| 1341 |
} |
| 1342 |
else if (address) |
| 1343 |
value.address = build_int_cst_type (ptr_type_node, address); |
| 1344 |
else |
| 1345 |
value.address = NULL; |
| 1346 |
if (value.address) |
| 1347 |
record_decl_address (ctx, value); |
| 1348 |
} |
| 1349 |
|
| 1350 |
if (class_member_p && code == FUNCTION_DECL) |
| 1351 |
{ |
| 1352 |
if (ctor || dtor) |
| 1353 |
maybe_retrofit_in_chrg (decl); |
| 1354 |
|
| 1355 |
grok_special_member_properties (decl); |
| 1356 |
} |
| 1357 |
|
| 1358 |
if (template_decl_p) |
| 1359 |
{ |
| 1360 |
if (RECORD_OR_UNION_CODE_P (code)) |
| 1361 |
safe_pushtag (identifier, TREE_TYPE (decl)); |
| 1362 |
else |
| 1363 |
decl = safe_push_template_decl (decl); |
| 1364 |
|
| 1365 |
tree tdecl = NULL_TREE; |
| 1366 |
if (class_member_p) |
| 1367 |
tdecl = finish_member_template_decl (decl); |
| 1368 |
|
| 1369 |
end_template_decl (); |
| 1370 |
|
| 1371 |
/* We only support one level of templates, because we only |
| 1372 |
support declaring generics; actual definitions are only of |
| 1373 |
specializations. */ |
| 1374 |
gcc_assert (!template_parm_scope_p ()); |
| 1375 |
|
| 1376 |
if (class_member_p) |
| 1377 |
finish_member_declaration (tdecl); |
| 1378 |
} |
| 1379 |
else if (RECORD_OR_UNION_CODE_P (code)) |
| 1380 |
safe_pushtag (identifier, TREE_TYPE (decl)); |
| 1381 |
else if (class_member_p) |
| 1382 |
finish_member_declaration (decl); |
| 1383 |
else |
| 1384 |
decl = safe_pushdecl (decl); |
| 1385 |
|
| 1386 |
if ((ctor || dtor) |
| 1387 |
/* Don't crash after a duplicate declaration of a cdtor. */ |
| 1388 |
&& TYPE_FIELDS (current_class_type) == decl) |
| 1389 |
{ |
| 1390 |
/* ctors and dtors clones are chained after DECL. |
| 1391 |
However, we create the clones before TYPE_METHODS is |
| 1392 |
reversed. We test for cloned methods after reversal, |
| 1393 |
however, and the test requires the clones to follow |
| 1394 |
DECL. So, we reverse the chain of clones now, so |
| 1395 |
that it will come out in the right order after |
| 1396 |
reversal. */ |
| 1397 |
tree save = DECL_CHAIN (decl); |
| 1398 |
DECL_CHAIN (decl) = NULL_TREE; |
| 1399 |
clone_cdtor (decl, /*update_methods=*/true); |
| 1400 |
gcc_assert (TYPE_FIELDS (current_class_type) == decl); |
| 1401 |
TYPE_FIELDS (current_class_type) |
| 1402 |
= nreverse (TYPE_FIELDS (current_class_type)); |
| 1403 |
DECL_CHAIN (decl) = save; |
| 1404 |
} |
| 1405 |
|
| 1406 |
rest_of_decl_compilation (decl, toplevel_bindings_p (), 0); |
| 1407 |
|
| 1408 |
return convert_out (ctx->preserve (decl)); |
| 1409 |
} |
| 1410 |
|
| 1411 |
gcc_decl |
| 1412 |
plugin_define_cdtor_clone (cc1_plugin::connection *self, |
| 1413 |
const char *name, |
| 1414 |
gcc_decl cdtor_in, |
| 1415 |
gcc_address address) |
| 1416 |
{ |
| 1417 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1418 |
tree decl = convert_in (cdtor_in); |
| 1419 |
bool ctor = false; |
| 1420 |
bool dtor = false; |
| 1421 |
tree identifier; |
| 1422 |
|
| 1423 |
switch (CHARS2 (name[0], name[1])) |
| 1424 |
{ |
| 1425 |
case CHARS2 ('C', '1'): // in-charge constructor |
| 1426 |
identifier = complete_ctor_identifier; |
| 1427 |
ctor = true; |
| 1428 |
break; |
| 1429 |
case CHARS2 ('C', '2'): // not-in-charge constructor |
| 1430 |
identifier = base_ctor_identifier; |
| 1431 |
ctor = true; |
| 1432 |
break; |
| 1433 |
case CHARS2 ('C', '4'): |
| 1434 |
identifier = ctor_identifier; // unified constructor |
| 1435 |
ctor = true; |
| 1436 |
break; |
| 1437 |
case CHARS2 ('D', '0'): // deleting destructor |
| 1438 |
identifier = deleting_dtor_identifier; |
| 1439 |
dtor = true; |
| 1440 |
break; |
| 1441 |
case CHARS2 ('D', '1'): // in-charge destructor |
| 1442 |
identifier = complete_dtor_identifier; |
| 1443 |
dtor = true; |
| 1444 |
break; |
| 1445 |
case CHARS2 ('D', '2'): // not-in-charge destructor |
| 1446 |
identifier = base_dtor_identifier; |
| 1447 |
dtor = true; |
| 1448 |
break; |
| 1449 |
case CHARS2 ('D', '4'): |
| 1450 |
identifier = dtor_identifier; // unified destructor |
| 1451 |
dtor = true; |
| 1452 |
break; |
| 1453 |
|
| 1454 |
default: |
| 1455 |
gcc_unreachable (); |
| 1456 |
} |
| 1457 |
|
| 1458 |
gcc_assert (!ctor != !dtor); |
| 1459 |
gcc_assert (ctor |
| 1460 |
? (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl) |
| 1461 |
&& DECL_NAME (decl) == ctor_identifier) |
| 1462 |
: (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl) |
| 1463 |
&& DECL_NAME (decl) == dtor_identifier)); |
| 1464 |
|
| 1465 |
while (decl && DECL_NAME (decl) != identifier) |
| 1466 |
{ |
| 1467 |
decl = DECL_CHAIN (decl); |
| 1468 |
if (decl && !DECL_CLONED_FUNCTION_P (decl)) |
| 1469 |
decl = NULL_TREE; |
| 1470 |
} |
| 1471 |
gcc_assert (decl); |
| 1472 |
|
| 1473 |
record_decl_address (ctx, build_decl_addr_value (decl, address)); |
| 1474 |
|
| 1475 |
return convert_out (decl); |
| 1476 |
} |
| 1477 |
|
| 1478 |
int |
| 1479 |
plugin_add_friend (cc1_plugin::connection * /* self */, |
| 1480 |
gcc_decl decl_in, |
| 1481 |
gcc_type type_in) |
| 1482 |
{ |
| 1483 |
tree decl = convert_in (decl_in); |
| 1484 |
tree type = convert_in (type_in); |
| 1485 |
|
| 1486 |
gcc_assert (type || at_class_scope_p ()); |
| 1487 |
|
| 1488 |
if (!type) |
| 1489 |
type = current_class_type; |
| 1490 |
else |
| 1491 |
gcc_assert (TREE_CODE (type) == RECORD_TYPE); |
| 1492 |
|
| 1493 |
if (TYPE_P (decl)) |
| 1494 |
make_friend_class (type, TREE_TYPE (decl), true); |
| 1495 |
else |
| 1496 |
{ |
| 1497 |
DECL_UNIQUE_FRIEND_P (decl) = true; |
| 1498 |
add_friend (type, decl, true); |
| 1499 |
} |
| 1500 |
|
| 1501 |
return 1; |
| 1502 |
} |
| 1503 |
|
| 1504 |
gcc_type |
| 1505 |
plugin_build_pointer_type (cc1_plugin::connection *, |
| 1506 |
gcc_type base_type) |
| 1507 |
{ |
| 1508 |
// No need to preserve a pointer type as the base type is preserved. |
| 1509 |
return convert_out (build_pointer_type (convert_in (base_type))); |
| 1510 |
} |
| 1511 |
|
| 1512 |
gcc_type |
| 1513 |
plugin_build_reference_type (cc1_plugin::connection *, |
| 1514 |
gcc_type base_type_in, |
| 1515 |
enum gcc_cp_ref_qualifiers rquals) |
| 1516 |
{ |
| 1517 |
bool rval; |
| 1518 |
|
| 1519 |
switch (rquals) |
| 1520 |
{ |
| 1521 |
case GCC_CP_REF_QUAL_LVALUE: |
| 1522 |
rval = false; |
| 1523 |
break; |
| 1524 |
case GCC_CP_REF_QUAL_RVALUE: |
| 1525 |
rval = true; |
| 1526 |
break; |
| 1527 |
case GCC_CP_REF_QUAL_NONE: |
| 1528 |
default: |
| 1529 |
gcc_unreachable (); |
| 1530 |
} |
| 1531 |
|
| 1532 |
tree rtype = cp_build_reference_type (convert_in (base_type_in), rval); |
| 1533 |
|
| 1534 |
return convert_out (rtype); |
| 1535 |
} |
| 1536 |
|
| 1537 |
static tree |
| 1538 |
start_class_def (tree type, |
| 1539 |
const gcc_vbase_array *base_classes) |
| 1540 |
{ |
| 1541 |
tree bases = NULL; |
| 1542 |
if (base_classes) |
| 1543 |
{ |
| 1544 |
for (int i = 0; i < base_classes->n_elements; i++) |
| 1545 |
{ |
| 1546 |
tree access; |
| 1547 |
|
| 1548 |
gcc_assert ((base_classes->flags[i] & GCC_CP_SYMBOL_MASK) |
| 1549 |
== GCC_CP_SYMBOL_BASECLASS); |
| 1550 |
|
| 1551 |
switch (base_classes->flags[i] & GCC_CP_ACCESS_MASK) |
| 1552 |
{ |
| 1553 |
case GCC_CP_ACCESS_PRIVATE: |
| 1554 |
access = ridpointers[(int)RID_PRIVATE]; |
| 1555 |
break; |
| 1556 |
|
| 1557 |
case GCC_CP_ACCESS_PROTECTED: |
| 1558 |
access = ridpointers[(int)RID_PROTECTED]; |
| 1559 |
break; |
| 1560 |
|
| 1561 |
case GCC_CP_ACCESS_PUBLIC: |
| 1562 |
access = ridpointers[(int)RID_PUBLIC]; |
| 1563 |
break; |
| 1564 |
|
| 1565 |
default: |
| 1566 |
gcc_unreachable (); |
| 1567 |
} |
| 1568 |
|
| 1569 |
tree base = finish_base_specifier |
| 1570 |
(convert_in (base_classes->elements[i]), access, |
| 1571 |
(base_classes->flags[i] & GCC_CP_FLAG_BASECLASS_VIRTUAL) != 0); |
| 1572 |
TREE_CHAIN (base) = bases; |
| 1573 |
bases = base; |
| 1574 |
} |
| 1575 |
bases = nreverse (bases); |
| 1576 |
} |
| 1577 |
xref_basetypes (type, bases); |
| 1578 |
begin_class_definition (type); |
| 1579 |
return type; |
| 1580 |
} |
| 1581 |
|
| 1582 |
gcc_type |
| 1583 |
plugin_start_class_type (cc1_plugin::connection *self, |
| 1584 |
gcc_decl typedecl_in, |
| 1585 |
const gcc_vbase_array *base_classes, |
| 1586 |
const char *filename, |
| 1587 |
unsigned int line_number) |
| 1588 |
{ |
| 1589 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1590 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 1591 |
tree typedecl = convert_in (typedecl_in); |
| 1592 |
tree type = TREE_TYPE (typedecl); |
| 1593 |
|
| 1594 |
gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type))); |
| 1595 |
gcc_assert (!COMPLETE_TYPE_P (type)); |
| 1596 |
|
| 1597 |
DECL_SOURCE_LOCATION (typedecl) = loc; |
| 1598 |
|
| 1599 |
tree result = start_class_def (type, base_classes); |
| 1600 |
|
| 1601 |
return convert_out (ctx->preserve (result)); |
| 1602 |
} |
| 1603 |
|
| 1604 |
gcc_type |
| 1605 |
plugin_start_closure_class_type (cc1_plugin::connection *self, |
| 1606 |
int discriminator, |
| 1607 |
gcc_decl extra_scope_in, |
| 1608 |
enum gcc_cp_symbol_kind flags, |
| 1609 |
const char *filename, |
| 1610 |
unsigned int line_number) |
| 1611 |
{ |
| 1612 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1613 |
tree extra_scope = convert_in (extra_scope_in); |
| 1614 |
|
| 1615 |
gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_LAMBDA_CLOSURE); |
| 1616 |
gcc_assert ((flags & (~(GCC_CP_SYMBOL_MASK | GCC_CP_ACCESS_MASK))) == 0); |
| 1617 |
|
| 1618 |
gcc_assert (!(flags & GCC_CP_ACCESS_MASK) == !at_class_scope_p ()); |
| 1619 |
|
| 1620 |
/* See at_fake_function_scope_p. */ |
| 1621 |
gcc_assert (!at_function_scope_p ()); |
| 1622 |
|
| 1623 |
if (extra_scope) |
| 1624 |
{ |
| 1625 |
if (TREE_CODE (extra_scope) == PARM_DECL) |
| 1626 |
{ |
| 1627 |
gcc_assert (at_fake_function_scope_p ()); |
| 1628 |
/* Check that the given extra_scope is one of the parameters of |
| 1629 |
the current function. */ |
| 1630 |
for (tree parm = DECL_ARGUMENTS (current_function_decl); |
| 1631 |
; parm = DECL_CHAIN (parm)) |
| 1632 |
{ |
| 1633 |
gcc_assert (parm); |
| 1634 |
if (parm == extra_scope) |
| 1635 |
break; |
| 1636 |
} |
| 1637 |
} |
| 1638 |
else if (TREE_CODE (extra_scope) == FIELD_DECL) |
| 1639 |
{ |
| 1640 |
gcc_assert (at_class_scope_p ()); |
| 1641 |
gcc_assert (DECL_CONTEXT (extra_scope) == current_class_type); |
| 1642 |
} |
| 1643 |
else |
| 1644 |
/* FIXME: does this ever really occur? */ |
| 1645 |
gcc_assert (TREE_CODE (extra_scope) == VAR_DECL); |
| 1646 |
} |
| 1647 |
|
| 1648 |
tree lambda_expr = build_lambda_expr (); |
| 1649 |
|
| 1650 |
LAMBDA_EXPR_LOCATION (lambda_expr) = ctx->get_location_t (filename, |
| 1651 |
line_number); |
| 1652 |
|
| 1653 |
tree type = begin_lambda_type (lambda_expr); |
| 1654 |
|
| 1655 |
/* Instead of calling record_lambda_scope, do this: */ |
| 1656 |
LAMBDA_EXPR_EXTRA_SCOPE (lambda_expr) = extra_scope; |
| 1657 |
LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda_expr) = discriminator; |
| 1658 |
LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda_expr) = discriminator; |
| 1659 |
|
| 1660 |
tree decl = TYPE_NAME (type); |
| 1661 |
determine_visibility (decl); |
| 1662 |
set_access_flags (decl, flags); |
| 1663 |
|
| 1664 |
return convert_out (ctx->preserve (type)); |
| 1665 |
} |
| 1666 |
|
| 1667 |
gcc_expr |
| 1668 |
plugin_build_lambda_expr (cc1_plugin::connection *self, |
| 1669 |
gcc_type closure_type_in) |
| 1670 |
{ |
| 1671 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1672 |
tree closure_type = convert_in (closure_type_in); |
| 1673 |
|
| 1674 |
gcc_assert (LAMBDA_TYPE_P (closure_type)); |
| 1675 |
|
| 1676 |
tree lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure_type); |
| 1677 |
|
| 1678 |
tree lambda_object = build_lambda_object (lambda_expr); |
| 1679 |
|
| 1680 |
return convert_out (ctx->preserve (lambda_object)); |
| 1681 |
} |
| 1682 |
|
| 1683 |
gcc_decl |
| 1684 |
plugin_build_field (cc1_plugin::connection *, |
| 1685 |
const char *field_name, |
| 1686 |
gcc_type field_type_in, |
| 1687 |
enum gcc_cp_symbol_kind flags, |
| 1688 |
unsigned long bitsize, |
| 1689 |
unsigned long bitpos) |
| 1690 |
{ |
| 1691 |
tree record_or_union_type = current_class_type; |
| 1692 |
tree field_type = convert_in (field_type_in); |
| 1693 |
|
| 1694 |
gcc_assert (at_class_scope_p ()); |
| 1695 |
gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type))); |
| 1696 |
gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_FIELD); |
| 1697 |
gcc_assert ((flags & (~(GCC_CP_SYMBOL_MASK | GCC_CP_ACCESS_MASK |
| 1698 |
| GCC_CP_FLAG_MASK_FIELD))) == 0); |
| 1699 |
gcc_assert ((flags & GCC_CP_ACCESS_MASK)); |
| 1700 |
|
| 1701 |
/* Note that gdb does not preserve the location of field decls, so |
| 1702 |
we can't provide a decent location here. */ |
| 1703 |
tree decl = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
| 1704 |
get_identifier (field_name), field_type); |
| 1705 |
DECL_FIELD_CONTEXT (decl) = record_or_union_type; |
| 1706 |
|
| 1707 |
set_access_flags (decl, flags); |
| 1708 |
|
| 1709 |
if ((flags & GCC_CP_FLAG_FIELD_MUTABLE) != 0) |
| 1710 |
DECL_MUTABLE_P (decl) = 1; |
| 1711 |
|
| 1712 |
if (TREE_CODE (field_type) == INTEGER_TYPE |
| 1713 |
&& TYPE_PRECISION (field_type) != bitsize) |
| 1714 |
{ |
| 1715 |
DECL_BIT_FIELD_TYPE (decl) = field_type; |
| 1716 |
TREE_TYPE (decl) |
| 1717 |
= c_build_bitfield_integer_type (bitsize, TYPE_UNSIGNED (field_type)); |
| 1718 |
} |
| 1719 |
|
| 1720 |
SET_DECL_MODE (decl, TYPE_MODE (TREE_TYPE (decl))); |
| 1721 |
|
| 1722 |
// There's no way to recover this from DWARF. |
| 1723 |
SET_DECL_OFFSET_ALIGN (decl, TYPE_PRECISION (pointer_sized_int_node)); |
| 1724 |
|
| 1725 |
tree pos = bitsize_int (bitpos); |
| 1726 |
pos_from_bit (&DECL_FIELD_OFFSET (decl), &DECL_FIELD_BIT_OFFSET (decl), |
| 1727 |
DECL_OFFSET_ALIGN (decl), pos); |
| 1728 |
|
| 1729 |
DECL_SIZE (decl) = bitsize_int (bitsize); |
| 1730 |
DECL_SIZE_UNIT (decl) = size_int ((bitsize + BITS_PER_UNIT - 1) |
| 1731 |
/ BITS_PER_UNIT); |
| 1732 |
|
| 1733 |
DECL_CHAIN (decl) = TYPE_FIELDS (record_or_union_type); |
| 1734 |
TYPE_FIELDS (record_or_union_type) = decl; |
| 1735 |
|
| 1736 |
return convert_out (decl); |
| 1737 |
} |
| 1738 |
|
| 1739 |
int |
| 1740 |
plugin_finish_class_type (cc1_plugin::connection *, |
| 1741 |
unsigned long size_in_bytes) |
| 1742 |
{ |
| 1743 |
tree record_or_union_type = current_class_type; |
| 1744 |
|
| 1745 |
gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type))); |
| 1746 |
|
| 1747 |
finish_struct (record_or_union_type, NULL); |
| 1748 |
|
| 1749 |
gcc_assert (compare_tree_int (TYPE_SIZE_UNIT (record_or_union_type), |
| 1750 |
size_in_bytes) == 0); |
| 1751 |
|
| 1752 |
return 1; |
| 1753 |
} |
| 1754 |
|
| 1755 |
gcc_type |
| 1756 |
plugin_start_enum_type (cc1_plugin::connection *self, |
| 1757 |
const char *name, |
| 1758 |
gcc_type underlying_int_type_in, |
| 1759 |
enum gcc_cp_symbol_kind flags, |
| 1760 |
const char *filename, |
| 1761 |
unsigned int line_number) |
| 1762 |
{ |
| 1763 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1764 |
tree underlying_int_type = convert_in (underlying_int_type_in); |
| 1765 |
|
| 1766 |
gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_ENUM); |
| 1767 |
gcc_assert ((flags & (~(GCC_CP_SYMBOL_MASK | GCC_CP_ACCESS_MASK |
| 1768 |
| GCC_CP_FLAG_MASK_ENUM))) == 0); |
| 1769 |
gcc_assert (!(flags & GCC_CP_ACCESS_MASK) == !at_class_scope_p ()); |
| 1770 |
|
| 1771 |
if (underlying_int_type == error_mark_node) |
| 1772 |
return convert_out (error_mark_node); |
| 1773 |
|
| 1774 |
bool is_new_type = false; |
| 1775 |
|
| 1776 |
tree id = name ? get_identifier (name) : make_anon_name (); |
| 1777 |
|
| 1778 |
tree type = start_enum (id, NULL_TREE, |
| 1779 |
underlying_int_type, |
| 1780 |
/* attributes = */ NULL_TREE, |
| 1781 |
!!(flags & GCC_CP_FLAG_ENUM_SCOPED), &is_new_type); |
| 1782 |
|
| 1783 |
gcc_assert (is_new_type); |
| 1784 |
|
| 1785 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 1786 |
tree type_decl = TYPE_NAME (type); |
| 1787 |
DECL_SOURCE_LOCATION (type_decl) = loc; |
| 1788 |
SET_OPAQUE_ENUM_P (type, false); |
| 1789 |
|
| 1790 |
set_access_flags (type_decl, flags); |
| 1791 |
|
| 1792 |
return convert_out (ctx->preserve (type)); |
| 1793 |
} |
| 1794 |
|
| 1795 |
gcc_decl |
| 1796 |
plugin_build_enum_constant (cc1_plugin::connection *, |
| 1797 |
gcc_type enum_type_in, |
| 1798 |
const char *name, |
| 1799 |
unsigned long value) |
| 1800 |
{ |
| 1801 |
tree enum_type = convert_in (enum_type_in); |
| 1802 |
|
| 1803 |
gcc_assert (TREE_CODE (enum_type) == ENUMERAL_TYPE); |
| 1804 |
|
| 1805 |
build_enumerator (get_identifier (name), build_int_cst (enum_type, value), |
| 1806 |
enum_type, NULL_TREE, BUILTINS_LOCATION); |
| 1807 |
|
| 1808 |
return convert_out (TREE_VALUE (TYPE_VALUES (enum_type))); |
| 1809 |
} |
| 1810 |
|
| 1811 |
int |
| 1812 |
plugin_finish_enum_type (cc1_plugin::connection *, |
| 1813 |
gcc_type enum_type_in) |
| 1814 |
{ |
| 1815 |
tree enum_type = convert_in (enum_type_in); |
| 1816 |
|
| 1817 |
finish_enum_value_list (enum_type); |
| 1818 |
finish_enum (enum_type); |
| 1819 |
|
| 1820 |
return 1; |
| 1821 |
} |
| 1822 |
|
| 1823 |
gcc_type |
| 1824 |
plugin_build_function_type (cc1_plugin::connection *self, |
| 1825 |
gcc_type return_type_in, |
| 1826 |
const struct gcc_type_array *argument_types_in, |
| 1827 |
int is_varargs) |
| 1828 |
{ |
| 1829 |
tree return_type = convert_in (return_type_in); |
| 1830 |
tree result; |
| 1831 |
|
| 1832 |
std::vector<tree> argument_types (argument_types_in->n_elements); |
| 1833 |
for (int i = 0; i < argument_types_in->n_elements; ++i) |
| 1834 |
argument_types[i] = convert_in (argument_types_in->elements[i]); |
| 1835 |
|
| 1836 |
if (is_varargs) |
| 1837 |
result = build_varargs_function_type_array (return_type, |
| 1838 |
argument_types_in->n_elements, |
| 1839 |
argument_types.data ()); |
| 1840 |
else |
| 1841 |
result = build_function_type_array (return_type, |
| 1842 |
argument_types_in->n_elements, |
| 1843 |
argument_types.data ()); |
| 1844 |
|
| 1845 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1846 |
return convert_out (ctx->preserve (result)); |
| 1847 |
} |
| 1848 |
|
| 1849 |
#if 0 |
| 1850 |
|
| 1851 |
gcc_type |
| 1852 |
plugin_add_function_default_args (cc1_plugin::connection *self, |
| 1853 |
gcc_type function_type_in, |
| 1854 |
const struct gcc_cp_function_args *defaults) |
| 1855 |
{ |
| 1856 |
tree function_type = convert_in (function_type_in); |
| 1857 |
|
| 1858 |
gcc_assert (TREE_CODE (function_type) == FUNCTION_TYPE); |
| 1859 |
|
| 1860 |
if (!defaults || !defaults->n_elements) |
| 1861 |
return function_type_in; |
| 1862 |
|
| 1863 |
tree pargs = TYPE_ARG_TYPES (function_type); |
| 1864 |
tree nargs = NULL_TREE; |
| 1865 |
|
| 1866 |
/* Build a reversed copy of the list of default-less arguments in |
| 1867 |
NARGS. At the end of the loop, PARGS will point to the end of |
| 1868 |
the argument list, or to the first argument that had a default |
| 1869 |
value. */ |
| 1870 |
while (pargs && TREE_VALUE (pargs) != void_list_node |
| 1871 |
&& !TREE_PURPOSE (pargs)) |
| 1872 |
{ |
| 1873 |
nargs = tree_cons (NULL_TREE, TREE_VALUE (pargs), nargs); |
| 1874 |
pargs = TREE_CHAIN (pargs); |
| 1875 |
} |
| 1876 |
|
| 1877 |
/* Set the defaults in the now-leading NARGS, taking into account |
| 1878 |
that NARGS is reversed but DEFAULTS->elements isn't. */ |
| 1879 |
tree ndargs = nargs; |
| 1880 |
int i = defaults->n_elements; |
| 1881 |
while (i--) |
| 1882 |
{ |
| 1883 |
gcc_assert (ndargs); |
| 1884 |
tree deflt = convert_in (defaults->elements[i]); |
| 1885 |
if (!deflt) |
| 1886 |
deflt = error_mark_node; |
| 1887 |
TREE_PURPOSE (ndargs) = deflt; |
| 1888 |
ndargs = TREE_CHAIN (ndargs); |
| 1889 |
} |
| 1890 |
|
| 1891 |
/* Finally, reverse NARGS, and append the remaining PARGS that |
| 1892 |
already had defaults. */ |
| 1893 |
nargs = nreverse (nargs); |
| 1894 |
nargs = chainon (nargs, pargs); |
| 1895 |
|
| 1896 |
tree result = build_function_type (TREE_TYPE (function_type), nargs); |
| 1897 |
|
| 1898 |
/* Copy exceptions, attributes and whatnot. */ |
| 1899 |
result = build_exception_variant (result, |
| 1900 |
TYPE_RAISES_EXCEPTIONS (function_type)); |
| 1901 |
result = cp_build_type_attribute_variant (result, |
| 1902 |
TYPE_ATTRIBUTES (function_type)); |
| 1903 |
|
| 1904 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1905 |
return convert_out (ctx->preserve (result)); |
| 1906 |
} |
| 1907 |
|
| 1908 |
int |
| 1909 |
plugin_set_deferred_function_default_args (cc1_plugin::connection *, |
| 1910 |
gcc_decl function_in, |
| 1911 |
const struct gcc_cp_function_args |
| 1912 |
*defaults) |
| 1913 |
{ |
| 1914 |
tree function = convert_in (function_in); |
| 1915 |
|
| 1916 |
gcc_assert (TREE_CODE (function) == FUNCTION_DECL); |
| 1917 |
|
| 1918 |
if (!defaults || !defaults->n_elements) |
| 1919 |
return 1; |
| 1920 |
|
| 1921 |
tree arg = FUNCTION_FIRST_USER_PARMTYPE (function); |
| 1922 |
|
| 1923 |
for (int i = 0; i < defaults->n_elements; i++) |
| 1924 |
{ |
| 1925 |
while (arg && TREE_PURPOSE (arg) != error_mark_node) |
| 1926 |
arg = TREE_CHAIN (arg); |
| 1927 |
|
| 1928 |
if (!arg) |
| 1929 |
return 0; |
| 1930 |
|
| 1931 |
TREE_PURPOSE (arg) = convert_in (defaults->elements[i]); |
| 1932 |
arg = TREE_CHAIN (arg); |
| 1933 |
} |
| 1934 |
|
| 1935 |
return 1; |
| 1936 |
} |
| 1937 |
|
| 1938 |
#endif |
| 1939 |
|
| 1940 |
gcc_decl |
| 1941 |
plugin_get_function_parameter_decl (cc1_plugin::connection *, |
| 1942 |
gcc_decl function_in, |
| 1943 |
int index) |
| 1944 |
{ |
| 1945 |
tree function = convert_in (function_in); |
| 1946 |
|
| 1947 |
gcc_assert (TREE_CODE (function) == FUNCTION_DECL); |
| 1948 |
|
| 1949 |
if (index == -1) |
| 1950 |
{ |
| 1951 |
gcc_assert (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE); |
| 1952 |
|
| 1953 |
return convert_out (DECL_ARGUMENTS (function)); |
| 1954 |
} |
| 1955 |
|
| 1956 |
gcc_assert (index >= 0); |
| 1957 |
|
| 1958 |
tree args = FUNCTION_FIRST_USER_PARM (function); |
| 1959 |
|
| 1960 |
for (int i = 0; args && i < index; i++) |
| 1961 |
args = DECL_CHAIN (args); |
| 1962 |
|
| 1963 |
return convert_out (args); |
| 1964 |
} |
| 1965 |
|
| 1966 |
gcc_type |
| 1967 |
plugin_build_exception_spec_variant (cc1_plugin::connection *self, |
| 1968 |
gcc_type function_type_in, |
| 1969 |
const struct gcc_type_array *except_types_in) |
| 1970 |
{ |
| 1971 |
tree function_type = convert_in (function_type_in); |
| 1972 |
tree except_types = NULL_TREE; |
| 1973 |
|
| 1974 |
if (!except_types_in) |
| 1975 |
except_types = noexcept_false_spec; |
| 1976 |
else if (!except_types_in->n_elements) |
| 1977 |
except_types = empty_except_spec; |
| 1978 |
else |
| 1979 |
for (int i = 0; i < except_types_in->n_elements; i++) |
| 1980 |
except_types = add_exception_specifier (except_types, |
| 1981 |
convert_in |
| 1982 |
(except_types_in->elements[i]), |
| 1983 |
0); |
| 1984 |
|
| 1985 |
function_type = build_exception_variant (function_type, |
| 1986 |
except_types); |
| 1987 |
|
| 1988 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 1989 |
return convert_out (ctx->preserve (function_type)); |
| 1990 |
} |
| 1991 |
|
| 1992 |
gcc_type |
| 1993 |
plugin_build_method_type (cc1_plugin::connection *self, |
| 1994 |
gcc_type class_type_in, |
| 1995 |
gcc_type func_type_in, |
| 1996 |
enum gcc_cp_qualifiers quals_in, |
| 1997 |
enum gcc_cp_ref_qualifiers rquals_in) |
| 1998 |
{ |
| 1999 |
tree class_type = convert_in (class_type_in); |
| 2000 |
tree func_type = convert_in (func_type_in); |
| 2001 |
cp_cv_quals quals = 0; |
| 2002 |
cp_ref_qualifier rquals; |
| 2003 |
|
| 2004 |
if ((quals_in & GCC_CP_QUALIFIER_CONST) != 0) |
| 2005 |
quals |= TYPE_QUAL_CONST; |
| 2006 |
if ((quals_in & GCC_CP_QUALIFIER_VOLATILE) != 0) |
| 2007 |
quals |= TYPE_QUAL_VOLATILE; |
| 2008 |
gcc_assert ((quals_in & GCC_CP_QUALIFIER_RESTRICT) == 0); |
| 2009 |
|
| 2010 |
switch (rquals_in) |
| 2011 |
{ |
| 2012 |
case GCC_CP_REF_QUAL_NONE: |
| 2013 |
rquals = REF_QUAL_NONE; |
| 2014 |
break; |
| 2015 |
case GCC_CP_REF_QUAL_LVALUE: |
| 2016 |
rquals = REF_QUAL_LVALUE; |
| 2017 |
break; |
| 2018 |
case GCC_CP_REF_QUAL_RVALUE: |
| 2019 |
rquals = REF_QUAL_RVALUE; |
| 2020 |
break; |
| 2021 |
default: |
| 2022 |
gcc_unreachable (); |
| 2023 |
} |
| 2024 |
|
| 2025 |
tree method_type = class_type |
| 2026 |
? build_memfn_type (func_type, class_type, quals, rquals) |
| 2027 |
: apply_memfn_quals (func_type, quals, rquals); |
| 2028 |
|
| 2029 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2030 |
return convert_out (ctx->preserve (method_type)); |
| 2031 |
} |
| 2032 |
|
| 2033 |
gcc_type |
| 2034 |
plugin_build_pointer_to_member_type (cc1_plugin::connection *self, |
| 2035 |
gcc_type class_type_in, |
| 2036 |
gcc_type member_type_in) |
| 2037 |
{ |
| 2038 |
tree class_type = convert_in (class_type_in); |
| 2039 |
tree member_type = convert_in (member_type_in); |
| 2040 |
|
| 2041 |
tree memptr_type = build_ptrmem_type (class_type, member_type); |
| 2042 |
|
| 2043 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2044 |
return convert_out (ctx->preserve (memptr_type)); |
| 2045 |
} |
| 2046 |
|
| 2047 |
int |
| 2048 |
plugin_start_template_decl (cc1_plugin::connection *) |
| 2049 |
{ |
| 2050 |
begin_template_parm_list (); |
| 2051 |
|
| 2052 |
TP_PARM_LIST = NULL_TREE; |
| 2053 |
|
| 2054 |
return 1; |
| 2055 |
} |
| 2056 |
|
| 2057 |
gcc_decl |
| 2058 |
plugin_get_type_decl (cc1_plugin::connection *, |
| 2059 |
gcc_type type_in) |
| 2060 |
{ |
| 2061 |
tree type = convert_in (type_in); |
| 2062 |
|
| 2063 |
tree name = TYPE_NAME (type); |
| 2064 |
gcc_assert (name); |
| 2065 |
|
| 2066 |
return convert_out (name); |
| 2067 |
} |
| 2068 |
|
| 2069 |
gcc_type |
| 2070 |
plugin_get_decl_type (cc1_plugin::connection *, |
| 2071 |
gcc_decl decl_in) |
| 2072 |
{ |
| 2073 |
tree decl = convert_in (decl_in); |
| 2074 |
|
| 2075 |
tree type = TREE_TYPE (decl); |
| 2076 |
gcc_assert (type); |
| 2077 |
|
| 2078 |
return convert_out (type); |
| 2079 |
} |
| 2080 |
|
| 2081 |
gcc_type |
| 2082 |
plugin_build_type_template_parameter (cc1_plugin::connection *self, |
| 2083 |
const char *id, |
| 2084 |
int /* bool */ pack_p, |
| 2085 |
gcc_type default_type, |
| 2086 |
const char *filename, |
| 2087 |
unsigned int line_number) |
| 2088 |
{ |
| 2089 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2090 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 2091 |
|
| 2092 |
gcc_assert (template_parm_scope_p ()); |
| 2093 |
|
| 2094 |
tree parm = finish_template_type_parm (class_type_node, get_identifier (id)); |
| 2095 |
parm = build_tree_list (convert_in (default_type), parm); |
| 2096 |
|
| 2097 |
gcc_assert (!(pack_p && default_type)); |
| 2098 |
|
| 2099 |
/* Create a type and a decl for the type parm, and add the decl to |
| 2100 |
TP_PARM_LIST. */ |
| 2101 |
TP_PARM_LIST = process_template_parm (TP_PARM_LIST, loc, parm, |
| 2102 |
/* is_non_type = */ false, pack_p); |
| 2103 |
|
| 2104 |
/* Locate the decl of the newly-added, processed template parm. */ |
| 2105 |
parm = TREE_VALUE (tree_last (TP_PARM_LIST)); |
| 2106 |
|
| 2107 |
/* Return its type. */ |
| 2108 |
return convert_out (ctx->preserve (TREE_TYPE (parm))); |
| 2109 |
} |
| 2110 |
|
| 2111 |
gcc_utempl |
| 2112 |
plugin_build_template_template_parameter (cc1_plugin::connection *self, |
| 2113 |
const char *id, |
| 2114 |
int /* bool */ pack_p, |
| 2115 |
gcc_utempl default_templ, |
| 2116 |
const char *filename, |
| 2117 |
unsigned int line_number) |
| 2118 |
{ |
| 2119 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2120 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 2121 |
|
| 2122 |
gcc_assert (template_parm_scope_p ()); |
| 2123 |
|
| 2124 |
/* Finish the template parm list that started this template parm. */ |
| 2125 |
end_template_parm_list (TP_PARM_LIST); |
| 2126 |
|
| 2127 |
gcc_assert (template_parm_scope_p ()); |
| 2128 |
|
| 2129 |
tree parm = finish_template_template_parm (class_type_node, |
| 2130 |
get_identifier (id)); |
| 2131 |
parm = build_tree_list (convert_in (default_templ), parm); |
| 2132 |
|
| 2133 |
gcc_assert (!(pack_p && default_templ)); |
| 2134 |
|
| 2135 |
/* Create a type and a decl for the template parm, and add the decl |
| 2136 |
to TP_PARM_LIST. */ |
| 2137 |
TP_PARM_LIST = process_template_parm (TP_PARM_LIST, loc, parm, |
| 2138 |
/* is_non_type = */ false, pack_p); |
| 2139 |
|
| 2140 |
/* Locate the decl of the newly-added, processed template parm. */ |
| 2141 |
parm = TREE_VALUE (tree_last (TP_PARM_LIST)); |
| 2142 |
|
| 2143 |
return convert_out (ctx->preserve (parm)); |
| 2144 |
} |
| 2145 |
|
| 2146 |
gcc_decl |
| 2147 |
plugin_build_value_template_parameter (cc1_plugin::connection *self, |
| 2148 |
gcc_type type, |
| 2149 |
const char *id, |
| 2150 |
gcc_expr default_value, |
| 2151 |
const char *filename, |
| 2152 |
unsigned int line_number) |
| 2153 |
{ |
| 2154 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2155 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 2156 |
|
| 2157 |
gcc_assert (template_parm_scope_p ()); |
| 2158 |
|
| 2159 |
cp_declarator declarator; |
| 2160 |
memset (&declarator, 0, sizeof (declarator)); |
| 2161 |
// &declarator = make_id_declarator (NULL, get_identifier (id), sfk_none): |
| 2162 |
declarator.kind = cdk_id; |
| 2163 |
declarator.u.id.qualifying_scope = NULL; |
| 2164 |
declarator.u.id.unqualified_name = get_identifier (id); |
| 2165 |
declarator.u.id.sfk = sfk_none; |
| 2166 |
|
| 2167 |
cp_decl_specifier_seq declspec; |
| 2168 |
memset (&declspec, 0, sizeof (declspec)); |
| 2169 |
// cp_parser_set_decl_spec_type (&declspec, convert_in (type), -token-, false): |
| 2170 |
declspec.any_specifiers_p = declspec.any_type_specifiers_p = true; |
| 2171 |
declspec.type = convert_in (type); |
| 2172 |
declspec.locations[ds_type_spec] = loc; |
| 2173 |
|
| 2174 |
tree parm = grokdeclarator (&declarator, &declspec, TPARM, 0, 0); |
| 2175 |
parm = build_tree_list (convert_in (default_value), parm); |
| 2176 |
|
| 2177 |
/* Create a type and a decl for the template parm, and add the decl |
| 2178 |
to TP_PARM_LIST. */ |
| 2179 |
TP_PARM_LIST = process_template_parm (TP_PARM_LIST, loc, parm, |
| 2180 |
/* is_non_type = */ true, false); |
| 2181 |
|
| 2182 |
/* Locate the decl of the newly-added, processed template parm. */ |
| 2183 |
parm = TREE_VALUE (tree_last (TP_PARM_LIST)); |
| 2184 |
|
| 2185 |
return convert_out (ctx->preserve (parm)); |
| 2186 |
} |
| 2187 |
|
| 2188 |
static tree |
| 2189 |
targlist (const gcc_cp_template_args *targs) |
| 2190 |
{ |
| 2191 |
int n = targs->n_elements; |
| 2192 |
tree vec = make_tree_vec (n); |
| 2193 |
while (n--) |
| 2194 |
{ |
| 2195 |
switch (targs->kinds[n]) |
| 2196 |
{ |
| 2197 |
case GCC_CP_TPARG_VALUE: |
| 2198 |
TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].value); |
| 2199 |
break; |
| 2200 |
case GCC_CP_TPARG_CLASS: |
| 2201 |
TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].type); |
| 2202 |
break; |
| 2203 |
case GCC_CP_TPARG_TEMPL: |
| 2204 |
TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].templ); |
| 2205 |
break; |
| 2206 |
case GCC_CP_TPARG_PACK: |
| 2207 |
TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].pack); |
| 2208 |
break; |
| 2209 |
default: |
| 2210 |
gcc_unreachable (); |
| 2211 |
} |
| 2212 |
} |
| 2213 |
return vec; |
| 2214 |
} |
| 2215 |
|
| 2216 |
gcc_type |
| 2217 |
plugin_build_dependent_typename (cc1_plugin::connection *self, |
| 2218 |
gcc_type enclosing_type, |
| 2219 |
const char *id, |
| 2220 |
const gcc_cp_template_args *targs) |
| 2221 |
{ |
| 2222 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2223 |
tree type = convert_in (enclosing_type); |
| 2224 |
tree name = get_identifier (id); |
| 2225 |
if (targs) |
| 2226 |
name = build_min_nt_loc (/*loc=*/0, TEMPLATE_ID_EXPR, |
| 2227 |
name, targlist (targs)); |
| 2228 |
tree res = make_typename_type (type, name, typename_type, |
| 2229 |
/*complain=*/tf_error); |
| 2230 |
return convert_out (ctx->preserve (res)); |
| 2231 |
} |
| 2232 |
|
| 2233 |
gcc_utempl |
| 2234 |
plugin_build_dependent_class_template (cc1_plugin::connection *self, |
| 2235 |
gcc_type enclosing_type, |
| 2236 |
const char *id) |
| 2237 |
{ |
| 2238 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2239 |
tree type = convert_in (enclosing_type); |
| 2240 |
tree name = get_identifier (id); |
| 2241 |
tree res = make_unbound_class_template (type, name, NULL_TREE, |
| 2242 |
/*complain=*/tf_error); |
| 2243 |
return convert_out (ctx->preserve (res)); |
| 2244 |
} |
| 2245 |
|
| 2246 |
gcc_type |
| 2247 |
plugin_build_dependent_type_template_id (cc1_plugin::connection *self, |
| 2248 |
gcc_utempl template_decl, |
| 2249 |
const gcc_cp_template_args *targs) |
| 2250 |
{ |
| 2251 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2252 |
tree type = convert_in (template_decl); |
| 2253 |
tree decl = finish_template_type (type, targlist (targs), |
| 2254 |
/*entering_scope=*/false); |
| 2255 |
return convert_out (ctx->preserve (TREE_TYPE (decl))); |
| 2256 |
} |
| 2257 |
|
| 2258 |
gcc_expr |
| 2259 |
plugin_build_dependent_expr (cc1_plugin::connection *self, |
| 2260 |
gcc_decl enclosing_scope, |
| 2261 |
enum gcc_cp_symbol_kind flags, |
| 2262 |
const char *name, |
| 2263 |
gcc_type conv_type_in, |
| 2264 |
const gcc_cp_template_args *targs) |
| 2265 |
{ |
| 2266 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2267 |
tree scope = convert_in (enclosing_scope); |
| 2268 |
tree conv_type = convert_in (conv_type_in); |
| 2269 |
tree identifier; |
| 2270 |
|
| 2271 |
if (TREE_CODE (scope) != NAMESPACE_DECL) |
| 2272 |
{ |
| 2273 |
tree type = TREE_TYPE (scope); |
| 2274 |
gcc_assert (TYPE_NAME (type) == scope); |
| 2275 |
scope = type; |
| 2276 |
} |
| 2277 |
|
| 2278 |
if (flags == (GCC_CP_SYMBOL_FUNCTION | GCC_CP_FLAG_SPECIAL_FUNCTION)) |
| 2279 |
{ |
| 2280 |
bool assop = false, convop = false; |
| 2281 |
tree_code opcode = ERROR_MARK; |
| 2282 |
|
| 2283 |
switch (CHARS2 (name[0], name[1])) |
| 2284 |
{ |
| 2285 |
case CHARS2 ('C', 0x0): // ctor base declaration |
| 2286 |
case CHARS2 ('C', ' '): |
| 2287 |
case CHARS2 ('C', '1'): |
| 2288 |
case CHARS2 ('C', '2'): |
| 2289 |
case CHARS2 ('C', '4'): |
| 2290 |
identifier = ctor_identifier; |
| 2291 |
break; |
| 2292 |
case CHARS2 ('D', 0x0): // dtor base declaration |
| 2293 |
case CHARS2 ('D', ' '): |
| 2294 |
case CHARS2 ('D', '0'): |
| 2295 |
case CHARS2 ('D', '1'): |
| 2296 |
case CHARS2 ('D', '2'): |
| 2297 |
case CHARS2 ('D', '4'): |
| 2298 |
gcc_assert (!targs); |
| 2299 |
identifier = dtor_identifier; |
| 2300 |
break; |
| 2301 |
case CHARS2 ('n', 'w'): // operator new |
| 2302 |
opcode = NEW_EXPR; |
| 2303 |
break; |
| 2304 |
case CHARS2 ('n', 'a'): // operator new[] |
| 2305 |
opcode = VEC_NEW_EXPR; |
| 2306 |
break; |
| 2307 |
case CHARS2 ('d', 'l'): // operator delete |
| 2308 |
opcode = DELETE_EXPR; |
| 2309 |
break; |
| 2310 |
case CHARS2 ('d', 'a'): // operator delete[] |
| 2311 |
opcode = VEC_DELETE_EXPR; |
| 2312 |
break; |
| 2313 |
case CHARS2 ('p', 's'): // operator + (unary) |
| 2314 |
opcode = PLUS_EXPR; |
| 2315 |
break; |
| 2316 |
case CHARS2 ('n', 'g'): // operator - (unary) |
| 2317 |
opcode = MINUS_EXPR; |
| 2318 |
break; |
| 2319 |
case CHARS2 ('a', 'd'): // operator & (unary) |
| 2320 |
opcode = BIT_AND_EXPR; |
| 2321 |
break; |
| 2322 |
case CHARS2 ('d', 'e'): // operator * (unary) |
| 2323 |
opcode = MULT_EXPR; |
| 2324 |
break; |
| 2325 |
case CHARS2 ('c', 'o'): // operator ~ |
| 2326 |
opcode = BIT_NOT_EXPR; |
| 2327 |
break; |
| 2328 |
case CHARS2 ('p', 'l'): // operator + |
| 2329 |
opcode = PLUS_EXPR; |
| 2330 |
break; |
| 2331 |
case CHARS2 ('m', 'i'): // operator - |
| 2332 |
opcode = MINUS_EXPR; |
| 2333 |
break; |
| 2334 |
case CHARS2 ('m', 'l'): // operator * |
| 2335 |
opcode = MULT_EXPR; |
| 2336 |
break; |
| 2337 |
case CHARS2 ('d', 'v'): // operator / |
| 2338 |
opcode = TRUNC_DIV_EXPR; |
| 2339 |
break; |
| 2340 |
case CHARS2 ('r', 'm'): // operator % |
| 2341 |
opcode = TRUNC_MOD_EXPR; |
| 2342 |
break; |
| 2343 |
case CHARS2 ('a', 'n'): // operator & |
| 2344 |
opcode = BIT_AND_EXPR; |
| 2345 |
break; |
| 2346 |
case CHARS2 ('o', 'r'): // operator | |
| 2347 |
opcode = BIT_IOR_EXPR; |
| 2348 |
break; |
| 2349 |
case CHARS2 ('e', 'o'): // operator ^ |
| 2350 |
opcode = BIT_XOR_EXPR; |
| 2351 |
break; |
| 2352 |
case CHARS2 ('a', 'S'): // operator = |
| 2353 |
opcode = NOP_EXPR; |
| 2354 |
assop = true; |
| 2355 |
break; |
| 2356 |
case CHARS2 ('p', 'L'): // operator += |
| 2357 |
opcode = PLUS_EXPR; |
| 2358 |
assop = true; |
| 2359 |
break; |
| 2360 |
case CHARS2 ('m', 'I'): // operator -= |
| 2361 |
opcode = MINUS_EXPR; |
| 2362 |
assop = true; |
| 2363 |
break; |
| 2364 |
case CHARS2 ('m', 'L'): // operator *= |
| 2365 |
opcode = MULT_EXPR; |
| 2366 |
assop = true; |
| 2367 |
break; |
| 2368 |
case CHARS2 ('d', 'V'): // operator /= |
| 2369 |
opcode = TRUNC_DIV_EXPR; |
| 2370 |
assop = true; |
| 2371 |
break; |
| 2372 |
case CHARS2 ('r', 'M'): // operator %= |
| 2373 |
opcode = TRUNC_MOD_EXPR; |
| 2374 |
assop = true; |
| 2375 |
break; |
| 2376 |
case CHARS2 ('a', 'N'): // operator &= |
| 2377 |
opcode = BIT_AND_EXPR; |
| 2378 |
assop = true; |
| 2379 |
break; |
| 2380 |
case CHARS2 ('o', 'R'): // operator |= |
| 2381 |
opcode = BIT_IOR_EXPR; |
| 2382 |
assop = true; |
| 2383 |
break; |
| 2384 |
case CHARS2 ('e', 'O'): // operator ^= |
| 2385 |
opcode = BIT_XOR_EXPR; |
| 2386 |
assop = true; |
| 2387 |
break; |
| 2388 |
case CHARS2 ('l', 's'): // operator << |
| 2389 |
opcode = LSHIFT_EXPR; |
| 2390 |
break; |
| 2391 |
case CHARS2 ('r', 's'): // operator >> |
| 2392 |
opcode = RSHIFT_EXPR; |
| 2393 |
break; |
| 2394 |
case CHARS2 ('l', 'S'): // operator <<= |
| 2395 |
opcode = LSHIFT_EXPR; |
| 2396 |
assop = true; |
| 2397 |
break; |
| 2398 |
case CHARS2 ('r', 'S'): // operator >>= |
| 2399 |
opcode = RSHIFT_EXPR; |
| 2400 |
assop = true; |
| 2401 |
break; |
| 2402 |
case CHARS2 ('e', 'q'): // operator == |
| 2403 |
opcode = EQ_EXPR; |
| 2404 |
break; |
| 2405 |
case CHARS2 ('n', 'e'): // operator != |
| 2406 |
opcode = NE_EXPR; |
| 2407 |
break; |
| 2408 |
case CHARS2 ('l', 't'): // operator < |
| 2409 |
opcode = LT_EXPR; |
| 2410 |
break; |
| 2411 |
case CHARS2 ('g', 't'): // operator > |
| 2412 |
opcode = GT_EXPR; |
| 2413 |
break; |
| 2414 |
case CHARS2 ('l', 'e'): // operator <= |
| 2415 |
opcode = LE_EXPR; |
| 2416 |
break; |
| 2417 |
case CHARS2 ('g', 'e'): // operator >= |
| 2418 |
opcode = GE_EXPR; |
| 2419 |
break; |
| 2420 |
case CHARS2 ('n', 't'): // operator ! |
| 2421 |
opcode = TRUTH_NOT_EXPR; |
| 2422 |
break; |
| 2423 |
case CHARS2 ('a', 'a'): // operator && |
| 2424 |
opcode = TRUTH_ANDIF_EXPR; |
| 2425 |
break; |
| 2426 |
case CHARS2 ('o', 'o'): // operator || |
| 2427 |
opcode = TRUTH_ORIF_EXPR; |
| 2428 |
break; |
| 2429 |
case CHARS2 ('p', 'p'): // operator ++ |
| 2430 |
opcode = POSTINCREMENT_EXPR; |
| 2431 |
break; |
| 2432 |
case CHARS2 ('m', 'm'): // operator -- |
| 2433 |
opcode = PREDECREMENT_EXPR; |
| 2434 |
break; |
| 2435 |
case CHARS2 ('c', 'm'): // operator , |
| 2436 |
opcode = COMPOUND_EXPR; |
| 2437 |
break; |
| 2438 |
case CHARS2 ('p', 'm'): // operator ->* |
| 2439 |
opcode = MEMBER_REF; |
| 2440 |
break; |
| 2441 |
case CHARS2 ('p', 't'): // operator -> |
| 2442 |
opcode = COMPONENT_REF; |
| 2443 |
break; |
| 2444 |
case CHARS2 ('c', 'l'): // operator () |
| 2445 |
opcode = CALL_EXPR; |
| 2446 |
break; |
| 2447 |
case CHARS2 ('i', 'x'): // operator [] |
| 2448 |
opcode = ARRAY_REF; |
| 2449 |
break; |
| 2450 |
case CHARS2 ('c', 'v'): // operator <T> (conversion operator) |
| 2451 |
convop = true; |
| 2452 |
identifier = make_conv_op_name (conv_type); |
| 2453 |
break; |
| 2454 |
// C++11-only: |
| 2455 |
case CHARS2 ('l', 'i'): // operator "" <id> |
| 2456 |
{ |
| 2457 |
char *id = (char *)name + 2; |
| 2458 |
bool freeid = false; |
| 2459 |
if (*id >= '0' && *id <= '9') |
| 2460 |
{ |
| 2461 |
unsigned len = 0; |
| 2462 |
do |
| 2463 |
{ |
| 2464 |
len *= 10; |
| 2465 |
len += id[0] - '0'; |
| 2466 |
id++; |
| 2467 |
} |
| 2468 |
while (*id && *id >= '0' && *id <= '9'); |
| 2469 |
id = xstrndup (id, len); |
| 2470 |
freeid = true; |
| 2471 |
} |
| 2472 |
identifier = cp_literal_operator_id (id); |
| 2473 |
if (freeid) |
| 2474 |
free (id); |
| 2475 |
} |
| 2476 |
break; |
| 2477 |
case CHARS2 ('q', 'u'): // ternary operator, not overloadable. |
| 2478 |
default: |
| 2479 |
gcc_unreachable (); |
| 2480 |
} |
| 2481 |
|
| 2482 |
gcc_assert (convop || !conv_type); |
| 2483 |
|
| 2484 |
if (opcode != ERROR_MARK) |
| 2485 |
identifier = ovl_op_identifier (assop, opcode); |
| 2486 |
|
| 2487 |
gcc_assert (identifier); |
| 2488 |
} |
| 2489 |
else |
| 2490 |
{ |
| 2491 |
gcc_assert (flags == GCC_CP_SYMBOL_MASK); |
| 2492 |
gcc_assert (!conv_type); |
| 2493 |
identifier = get_identifier (name); |
| 2494 |
} |
| 2495 |
tree res = identifier; |
| 2496 |
if (!scope) |
| 2497 |
res = lookup_name (res, LOOK_where::BLOCK_NAMESPACE); |
| 2498 |
else if (!TYPE_P (scope) || !dependent_scope_p (scope)) |
| 2499 |
{ |
| 2500 |
res = lookup_qualified_name (scope, res, LOOK_want::NORMAL, true); |
| 2501 |
/* We've already resolved the name in the scope, so skip the |
| 2502 |
build_qualified_name call below. */ |
| 2503 |
scope = NULL; |
| 2504 |
} |
| 2505 |
if (targs) |
| 2506 |
res = lookup_template_function (res, targlist (targs)); |
| 2507 |
if (scope) |
| 2508 |
res = build_qualified_name (NULL_TREE, scope, res, !!targs); |
| 2509 |
return convert_out (ctx->preserve (res)); |
| 2510 |
} |
| 2511 |
|
| 2512 |
gcc_expr |
| 2513 |
plugin_build_literal_expr (cc1_plugin::connection *self, |
| 2514 |
gcc_type type, unsigned long value) |
| 2515 |
{ |
| 2516 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2517 |
tree t = convert_in (type); |
| 2518 |
tree val = build_int_cst_type (t, (unsigned HOST_WIDE_INT) value); |
| 2519 |
return convert_out (ctx->preserve (val)); |
| 2520 |
} |
| 2521 |
|
| 2522 |
gcc_expr |
| 2523 |
plugin_build_decl_expr (cc1_plugin::connection *self, |
| 2524 |
gcc_decl decl_in, |
| 2525 |
int qualified_p) |
| 2526 |
{ |
| 2527 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2528 |
tree decl = convert_in (decl_in); |
| 2529 |
gcc_assert (DECL_P (decl)); |
| 2530 |
tree result = decl; |
| 2531 |
if (qualified_p) |
| 2532 |
{ |
| 2533 |
gcc_assert (DECL_CLASS_SCOPE_P (decl)); |
| 2534 |
result = build_offset_ref (DECL_CONTEXT (decl), decl, |
| 2535 |
/*address_p=*/true, tf_error); |
| 2536 |
} |
| 2537 |
return convert_out (ctx->preserve (result)); |
| 2538 |
} |
| 2539 |
|
| 2540 |
gcc_expr |
| 2541 |
plugin_build_unary_expr (cc1_plugin::connection *self, |
| 2542 |
const char *unary_op, |
| 2543 |
gcc_expr operand) |
| 2544 |
{ |
| 2545 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2546 |
tree op0 = convert_in (operand); |
| 2547 |
tree_code opcode = ERROR_MARK; |
| 2548 |
bool global_scope_p = false; |
| 2549 |
|
| 2550 |
once_more: |
| 2551 |
switch (CHARS2 (unary_op[0], unary_op[1])) |
| 2552 |
{ |
| 2553 |
case CHARS2 ('p', 's'): // operator + (unary) |
| 2554 |
opcode = UNARY_PLUS_EXPR; |
| 2555 |
break; |
| 2556 |
case CHARS2 ('n', 'g'): // operator - (unary) |
| 2557 |
opcode = NEGATE_EXPR; |
| 2558 |
break; |
| 2559 |
case CHARS2 ('a', 'd'): // operator & (unary) |
| 2560 |
opcode = ADDR_EXPR; |
| 2561 |
break; |
| 2562 |
case CHARS2 ('d', 'e'): // operator * (unary) |
| 2563 |
opcode = INDIRECT_REF; |
| 2564 |
break; |
| 2565 |
case CHARS2 ('c', 'o'): // operator ~ |
| 2566 |
opcode = BIT_NOT_EXPR; |
| 2567 |
break; |
| 2568 |
case CHARS2 ('n', 't'): // operator ! |
| 2569 |
opcode = TRUTH_NOT_EXPR; |
| 2570 |
break; |
| 2571 |
case CHARS2 ('p', 'p'): // operator ++ |
| 2572 |
opcode = unary_op[2] == '_' ? PREINCREMENT_EXPR : POSTINCREMENT_EXPR; |
| 2573 |
break; |
| 2574 |
case CHARS2 ('m', 'm'): // operator -- |
| 2575 |
opcode = unary_op[2] == '_' ? PREDECREMENT_EXPR : POSTDECREMENT_EXPR; |
| 2576 |
break; |
| 2577 |
case CHARS2 ('n', 'x'): // noexcept |
| 2578 |
opcode = NOEXCEPT_EXPR; |
| 2579 |
break; |
| 2580 |
case CHARS2 ('t', 'w'): // throw |
| 2581 |
gcc_assert (op0); |
| 2582 |
opcode = THROW_EXPR; |
| 2583 |
break; |
| 2584 |
case CHARS2 ('t', 'r'): // rethrow |
| 2585 |
gcc_assert (!op0); |
| 2586 |
opcode = THROW_EXPR; |
| 2587 |
break; |
| 2588 |
case CHARS2 ('t', 'e'): // typeid (value) |
| 2589 |
opcode = TYPEID_EXPR; |
| 2590 |
break; |
| 2591 |
case CHARS2 ('s', 'z'): // sizeof (value) |
| 2592 |
opcode = SIZEOF_EXPR; |
| 2593 |
break; |
| 2594 |
case CHARS2 ('a', 'z'): // alignof (value) |
| 2595 |
opcode = ALIGNOF_EXPR; |
| 2596 |
break; |
| 2597 |
case CHARS2 ('g', 's'): // global scope (for delete, delete[]) |
| 2598 |
gcc_assert (!global_scope_p); |
| 2599 |
global_scope_p = true; |
| 2600 |
unary_op += 2; |
| 2601 |
goto once_more; |
| 2602 |
case CHARS2 ('d', 'l'): // delete |
| 2603 |
opcode = DELETE_EXPR; |
| 2604 |
break; |
| 2605 |
case CHARS2 ('d', 'a'): // delete[] |
| 2606 |
opcode = VEC_DELETE_EXPR; |
| 2607 |
break; |
| 2608 |
case CHARS2 ('s', 'p'): // pack... |
| 2609 |
opcode = EXPR_PACK_EXPANSION; |
| 2610 |
break; |
| 2611 |
case CHARS2 ('s', 'Z'): // sizeof...(pack) |
| 2612 |
opcode = TYPE_PACK_EXPANSION; // Not really, but let's use its code. |
| 2613 |
break; |
| 2614 |
|
| 2615 |
/* FIXME: __real__, __imag__? */ |
| 2616 |
|
| 2617 |
default: |
| 2618 |
gcc_unreachable (); |
| 2619 |
} |
| 2620 |
|
| 2621 |
gcc_assert (!global_scope_p |
| 2622 |
|| opcode == DELETE_EXPR || opcode == VEC_DELETE_EXPR); |
| 2623 |
|
| 2624 |
processing_template_decl++; |
| 2625 |
bool template_dependent_p = op0 |
| 2626 |
&& (type_dependent_expression_p (op0) |
| 2627 |
|| value_dependent_expression_p (op0)); |
| 2628 |
if (!template_dependent_p) |
| 2629 |
processing_template_decl--; |
| 2630 |
|
| 2631 |
tree result; |
| 2632 |
|
| 2633 |
gcc_assert (op0 || opcode == THROW_EXPR); |
| 2634 |
|
| 2635 |
switch (opcode) |
| 2636 |
{ |
| 2637 |
case NOEXCEPT_EXPR: |
| 2638 |
result = finish_noexcept_expr (op0, tf_error); |
| 2639 |
break; |
| 2640 |
|
| 2641 |
case THROW_EXPR: |
| 2642 |
result = build_throw (input_location, op0, tf_error); |
| 2643 |
break; |
| 2644 |
|
| 2645 |
case TYPEID_EXPR: |
| 2646 |
result = build_typeid (op0, tf_error); |
| 2647 |
break; |
| 2648 |
|
| 2649 |
case SIZEOF_EXPR: |
| 2650 |
case ALIGNOF_EXPR: |
| 2651 |
result = cxx_sizeof_or_alignof_expr (input_location, |
| 2652 |
op0, opcode, true, true); |
| 2653 |
break; |
| 2654 |
|
| 2655 |
case DELETE_EXPR: |
| 2656 |
case VEC_DELETE_EXPR: |
| 2657 |
result = delete_sanity (input_location, op0, NULL_TREE, |
| 2658 |
opcode == VEC_DELETE_EXPR, |
| 2659 |
global_scope_p, tf_error); |
| 2660 |
break; |
| 2661 |
|
| 2662 |
case EXPR_PACK_EXPANSION: |
| 2663 |
result = make_pack_expansion (op0); |
| 2664 |
break; |
| 2665 |
|
| 2666 |
/* We're using this for sizeof...(pack). */ |
| 2667 |
case TYPE_PACK_EXPANSION: |
| 2668 |
result = make_pack_expansion (op0); |
| 2669 |
PACK_EXPANSION_SIZEOF_P (result) = true; |
| 2670 |
break; |
| 2671 |
|
| 2672 |
default: |
| 2673 |
result = build_x_unary_op (/*loc=*/0, opcode, op0, NULL_TREE, tf_error); |
| 2674 |
break; |
| 2675 |
} |
| 2676 |
|
| 2677 |
if (template_dependent_p) |
| 2678 |
processing_template_decl--; |
| 2679 |
|
| 2680 |
return convert_out (ctx->preserve (result)); |
| 2681 |
} |
| 2682 |
|
| 2683 |
gcc_expr |
| 2684 |
plugin_build_binary_expr (cc1_plugin::connection *self, |
| 2685 |
const char *binary_op, |
| 2686 |
gcc_expr operand1, |
| 2687 |
gcc_expr operand2) |
| 2688 |
{ |
| 2689 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2690 |
tree op0 = convert_in (operand1); |
| 2691 |
tree op1 = convert_in (operand2); |
| 2692 |
tree_code opcode = ERROR_MARK; |
| 2693 |
|
| 2694 |
switch (CHARS2 (binary_op[0], binary_op[1])) |
| 2695 |
{ |
| 2696 |
case CHARS2 ('p', 'l'): // operator + |
| 2697 |
opcode = PLUS_EXPR; |
| 2698 |
break; |
| 2699 |
case CHARS2 ('m', 'i'): // operator - |
| 2700 |
opcode = MINUS_EXPR; |
| 2701 |
break; |
| 2702 |
case CHARS2 ('m', 'l'): // operator * |
| 2703 |
opcode = MULT_EXPR; |
| 2704 |
break; |
| 2705 |
case CHARS2 ('d', 'v'): // operator / |
| 2706 |
opcode = TRUNC_DIV_EXPR; |
| 2707 |
break; |
| 2708 |
case CHARS2 ('r', 'm'): // operator % |
| 2709 |
opcode = TRUNC_MOD_EXPR; |
| 2710 |
break; |
| 2711 |
case CHARS2 ('a', 'n'): // operator & |
| 2712 |
opcode = BIT_AND_EXPR; |
| 2713 |
break; |
| 2714 |
case CHARS2 ('o', 'r'): // operator | |
| 2715 |
opcode = BIT_IOR_EXPR; |
| 2716 |
break; |
| 2717 |
case CHARS2 ('e', 'o'): // operator ^ |
| 2718 |
opcode = BIT_XOR_EXPR; |
| 2719 |
break; |
| 2720 |
case CHARS2 ('l', 's'): // operator << |
| 2721 |
opcode = LSHIFT_EXPR; |
| 2722 |
break; |
| 2723 |
case CHARS2 ('r', 's'): // operator >> |
| 2724 |
opcode = RSHIFT_EXPR; |
| 2725 |
break; |
| 2726 |
case CHARS2 ('e', 'q'): // operator == |
| 2727 |
opcode = EQ_EXPR; |
| 2728 |
break; |
| 2729 |
case CHARS2 ('n', 'e'): // operator != |
| 2730 |
opcode = NE_EXPR; |
| 2731 |
break; |
| 2732 |
case CHARS2 ('l', 't'): // operator < |
| 2733 |
opcode = LT_EXPR; |
| 2734 |
break; |
| 2735 |
case CHARS2 ('g', 't'): // operator > |
| 2736 |
opcode = GT_EXPR; |
| 2737 |
break; |
| 2738 |
case CHARS2 ('l', 'e'): // operator <= |
| 2739 |
opcode = LE_EXPR; |
| 2740 |
break; |
| 2741 |
case CHARS2 ('g', 'e'): // operator >= |
| 2742 |
opcode = GE_EXPR; |
| 2743 |
break; |
| 2744 |
case CHARS2 ('a', 'a'): // operator && |
| 2745 |
opcode = TRUTH_ANDIF_EXPR; |
| 2746 |
break; |
| 2747 |
case CHARS2 ('o', 'o'): // operator || |
| 2748 |
opcode = TRUTH_ORIF_EXPR; |
| 2749 |
break; |
| 2750 |
case CHARS2 ('c', 'm'): // operator , |
| 2751 |
opcode = COMPOUND_EXPR; |
| 2752 |
break; |
| 2753 |
case CHARS2 ('p', 'm'): // operator ->* |
| 2754 |
opcode = MEMBER_REF; |
| 2755 |
break; |
| 2756 |
case CHARS2 ('p', 't'): // operator -> |
| 2757 |
opcode = INDIRECT_REF; // Not really! This will stand for |
| 2758 |
// INDIRECT_REF followed by COMPONENT_REF |
| 2759 |
// later on. |
| 2760 |
break; |
| 2761 |
case CHARS2 ('i', 'x'): // operator [] |
| 2762 |
opcode = ARRAY_REF; |
| 2763 |
break; |
| 2764 |
case CHARS2 ('d', 's'): // operator .* |
| 2765 |
opcode = DOTSTAR_EXPR; |
| 2766 |
break; |
| 2767 |
case CHARS2 ('d', 't'): // operator . |
| 2768 |
opcode = COMPONENT_REF; |
| 2769 |
break; |
| 2770 |
|
| 2771 |
default: |
| 2772 |
gcc_unreachable (); |
| 2773 |
} |
| 2774 |
|
| 2775 |
processing_template_decl++; |
| 2776 |
bool template_dependent_p = type_dependent_expression_p (op0) |
| 2777 |
|| value_dependent_expression_p (op0) |
| 2778 |
|| type_dependent_expression_p (op1) |
| 2779 |
|| value_dependent_expression_p (op1); |
| 2780 |
if (!template_dependent_p) |
| 2781 |
processing_template_decl--; |
| 2782 |
|
| 2783 |
tree result; |
| 2784 |
|
| 2785 |
switch (opcode) |
| 2786 |
{ |
| 2787 |
case INDIRECT_REF: // This is actually a "->". |
| 2788 |
op0 = build_x_arrow (/*loc=*/0, op0, tf_error); |
| 2789 |
/* Fall through. */ |
| 2790 |
case COMPONENT_REF: |
| 2791 |
result = finish_class_member_access_expr (op0, op1, |
| 2792 |
/*template_p=*/false, |
| 2793 |
tf_error); |
| 2794 |
break; |
| 2795 |
|
| 2796 |
default: |
| 2797 |
result = build_x_binary_op (/*loc=*/0, opcode, op0, ERROR_MARK, |
| 2798 |
op1, ERROR_MARK, NULL_TREE, NULL, tf_error); |
| 2799 |
break; |
| 2800 |
} |
| 2801 |
|
| 2802 |
if (template_dependent_p) |
| 2803 |
processing_template_decl--; |
| 2804 |
|
| 2805 |
return convert_out (ctx->preserve (result)); |
| 2806 |
} |
| 2807 |
|
| 2808 |
gcc_expr |
| 2809 |
plugin_build_ternary_expr (cc1_plugin::connection *self, |
| 2810 |
const char *ternary_op, |
| 2811 |
gcc_expr operand1, |
| 2812 |
gcc_expr operand2, |
| 2813 |
gcc_expr operand3) |
| 2814 |
{ |
| 2815 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2816 |
tree op0 = convert_in (operand1); |
| 2817 |
tree op1 = convert_in (operand2); |
| 2818 |
tree op2 = convert_in (operand3); |
| 2819 |
gcc_assert (CHARS2 (ternary_op[0], ternary_op[1]) |
| 2820 |
== CHARS2 ('q', 'u')); // ternary operator |
| 2821 |
|
| 2822 |
processing_template_decl++; |
| 2823 |
bool template_dependent_p = type_dependent_expression_p (op0) |
| 2824 |
|| value_dependent_expression_p (op0) |
| 2825 |
|| type_dependent_expression_p (op1) |
| 2826 |
|| value_dependent_expression_p (op1) |
| 2827 |
|| type_dependent_expression_p (op2) |
| 2828 |
|| value_dependent_expression_p (op2); |
| 2829 |
if (!template_dependent_p) |
| 2830 |
processing_template_decl--; |
| 2831 |
|
| 2832 |
tree val = build_x_conditional_expr (/*loc=*/0, op0, op1, op2, tf_error); |
| 2833 |
|
| 2834 |
if (template_dependent_p) |
| 2835 |
processing_template_decl--; |
| 2836 |
|
| 2837 |
return convert_out (ctx->preserve (val)); |
| 2838 |
} |
| 2839 |
|
| 2840 |
gcc_expr |
| 2841 |
plugin_build_unary_type_expr (cc1_plugin::connection *self, |
| 2842 |
const char *unary_op, |
| 2843 |
gcc_type operand) |
| 2844 |
{ |
| 2845 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2846 |
tree type = convert_in (operand); |
| 2847 |
tree_code opcode = ERROR_MARK; |
| 2848 |
|
| 2849 |
switch (CHARS2 (unary_op[0], unary_op[1])) |
| 2850 |
{ |
| 2851 |
case CHARS2 ('t', 'i'): // typeid (type) |
| 2852 |
opcode = TYPEID_EXPR; |
| 2853 |
break; |
| 2854 |
|
| 2855 |
case CHARS2 ('s', 't'): // sizeof (type) |
| 2856 |
opcode = SIZEOF_EXPR; |
| 2857 |
break; |
| 2858 |
case CHARS2 ('a', 't'): // alignof (type) |
| 2859 |
opcode = ALIGNOF_EXPR; |
| 2860 |
break; |
| 2861 |
|
| 2862 |
case CHARS2 ('s', 'Z'): // sizeof...(pack) |
| 2863 |
opcode = TYPE_PACK_EXPANSION; // Not really, but let's use its code. |
| 2864 |
break; |
| 2865 |
|
| 2866 |
// FIXME: do we have to handle "sp", for the size of a captured |
| 2867 |
// template parameter pack from an alias template, taking |
| 2868 |
// multiple template arguments? |
| 2869 |
|
| 2870 |
default: |
| 2871 |
gcc_unreachable (); |
| 2872 |
} |
| 2873 |
|
| 2874 |
processing_template_decl++; |
| 2875 |
bool template_dependent_p = dependent_type_p (type); |
| 2876 |
if (!template_dependent_p) |
| 2877 |
processing_template_decl--; |
| 2878 |
|
| 2879 |
tree result; |
| 2880 |
|
| 2881 |
switch (opcode) |
| 2882 |
{ |
| 2883 |
case TYPEID_EXPR: |
| 2884 |
result = get_typeid (type, tf_error); |
| 2885 |
break; |
| 2886 |
|
| 2887 |
// We're using this for sizeof...(pack). */ |
| 2888 |
case TYPE_PACK_EXPANSION: |
| 2889 |
result = make_pack_expansion (type); |
| 2890 |
PACK_EXPANSION_SIZEOF_P (result) = true; |
| 2891 |
break; |
| 2892 |
|
| 2893 |
default: |
| 2894 |
/* Use the C++11 alignof semantics. */ |
| 2895 |
result = cxx_sizeof_or_alignof_type (input_location, type, |
| 2896 |
opcode, true, true); |
| 2897 |
} |
| 2898 |
|
| 2899 |
if (template_dependent_p) |
| 2900 |
processing_template_decl--; |
| 2901 |
|
| 2902 |
return convert_out (ctx->preserve (result)); |
| 2903 |
} |
| 2904 |
|
| 2905 |
gcc_expr |
| 2906 |
plugin_build_cast_expr (cc1_plugin::connection *self, |
| 2907 |
const char *binary_op, |
| 2908 |
gcc_type operand1, |
| 2909 |
gcc_expr operand2) |
| 2910 |
{ |
| 2911 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2912 |
tree (*build_cast)(location_t loc, tree type, tree expr, |
| 2913 |
tsubst_flags_t complain) = NULL; |
| 2914 |
tree type = convert_in (operand1); |
| 2915 |
tree expr = convert_in (operand2); |
| 2916 |
|
| 2917 |
switch (CHARS2 (binary_op[0], binary_op[1])) |
| 2918 |
{ |
| 2919 |
case CHARS2 ('d', 'c'): // dynamic_cast |
| 2920 |
build_cast = build_dynamic_cast; |
| 2921 |
break; |
| 2922 |
|
| 2923 |
case CHARS2 ('s', 'c'): // static_cast |
| 2924 |
build_cast = build_static_cast; |
| 2925 |
break; |
| 2926 |
|
| 2927 |
case CHARS2 ('c', 'c'): // const_cast |
| 2928 |
build_cast = build_const_cast; |
| 2929 |
break; |
| 2930 |
|
| 2931 |
case CHARS2 ('r', 'c'): // reinterpret_cast |
| 2932 |
build_cast = build_reinterpret_cast; |
| 2933 |
break; |
| 2934 |
|
| 2935 |
case CHARS2 ('c', 'v'): // C cast, conversion with one argument |
| 2936 |
build_cast = cp_build_c_cast; |
| 2937 |
break; |
| 2938 |
|
| 2939 |
default: |
| 2940 |
gcc_unreachable (); |
| 2941 |
} |
| 2942 |
|
| 2943 |
processing_template_decl++; |
| 2944 |
bool template_dependent_p = dependent_type_p (type) |
| 2945 |
|| type_dependent_expression_p (expr) |
| 2946 |
|| value_dependent_expression_p (expr); |
| 2947 |
if (!template_dependent_p) |
| 2948 |
processing_template_decl--; |
| 2949 |
|
| 2950 |
tree val = build_cast (input_location, type, expr, tf_error); |
| 2951 |
|
| 2952 |
if (template_dependent_p) |
| 2953 |
processing_template_decl--; |
| 2954 |
|
| 2955 |
return convert_out (ctx->preserve (val)); |
| 2956 |
} |
| 2957 |
|
| 2958 |
static inline vec<tree, va_gc> * |
| 2959 |
args_to_tree_vec (const struct gcc_cp_function_args *args_in) |
| 2960 |
{ |
| 2961 |
vec<tree, va_gc> *args = make_tree_vector (); |
| 2962 |
for (int i = 0; i < args_in->n_elements; i++) |
| 2963 |
vec_safe_push (args, convert_in (args_in->elements[i])); |
| 2964 |
return args; |
| 2965 |
} |
| 2966 |
|
| 2967 |
static inline tree |
| 2968 |
args_to_tree_list (const struct gcc_cp_function_args *args_in) |
| 2969 |
{ |
| 2970 |
tree args, *tail = &args; |
| 2971 |
for (int i = 0; i < args_in->n_elements; i++) |
| 2972 |
{ |
| 2973 |
*tail = build_tree_list (NULL, convert_in (args_in->elements[i])); |
| 2974 |
tail = &TREE_CHAIN (*tail); |
| 2975 |
} |
| 2976 |
return args; |
| 2977 |
} |
| 2978 |
|
| 2979 |
static inline vec<constructor_elt, va_gc> * |
| 2980 |
args_to_ctor_elts (const struct gcc_cp_function_args *args_in) |
| 2981 |
{ |
| 2982 |
vec<constructor_elt, va_gc> *args = NULL; |
| 2983 |
for (int i = 0; i < args_in->n_elements; i++) |
| 2984 |
CONSTRUCTOR_APPEND_ELT (args, NULL_TREE, convert_in (args_in->elements[i])); |
| 2985 |
return args; |
| 2986 |
} |
| 2987 |
|
| 2988 |
gcc_expr |
| 2989 |
plugin_build_expression_list_expr (cc1_plugin::connection *self, |
| 2990 |
const char *conv_op, |
| 2991 |
gcc_type type_in, |
| 2992 |
const struct gcc_cp_function_args *values_in) |
| 2993 |
{ |
| 2994 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 2995 |
tree type = convert_in (type_in); |
| 2996 |
tree args; |
| 2997 |
tree result; |
| 2998 |
|
| 2999 |
switch (CHARS2 (conv_op[0], conv_op[1])) |
| 3000 |
{ |
| 3001 |
case CHARS2 ('c', 'v'): // conversion with parenthesized expression list |
| 3002 |
gcc_assert (TYPE_P (type)); |
| 3003 |
args = args_to_tree_list (values_in); |
| 3004 |
result = build_functional_cast (input_location, type, args, tf_error); |
| 3005 |
break; |
| 3006 |
|
| 3007 |
case CHARS2 ('t', 'l'): // conversion with braced expression list |
| 3008 |
gcc_assert (type); |
| 3009 |
gcc_assert (TYPE_P (type)); |
| 3010 |
args = make_node (CONSTRUCTOR); |
| 3011 |
CONSTRUCTOR_ELTS (args) = args_to_ctor_elts (values_in); |
| 3012 |
CONSTRUCTOR_IS_DIRECT_INIT (args) = 1; |
| 3013 |
result = finish_compound_literal (type, args, tf_error); |
| 3014 |
break; |
| 3015 |
|
| 3016 |
case CHARS2 ('i', 'l'): // untyped braced expression list |
| 3017 |
gcc_assert (!type); |
| 3018 |
result = make_node (CONSTRUCTOR); |
| 3019 |
CONSTRUCTOR_ELTS (result) = args_to_ctor_elts (values_in); |
| 3020 |
break; |
| 3021 |
|
| 3022 |
default: |
| 3023 |
gcc_unreachable (); |
| 3024 |
} |
| 3025 |
|
| 3026 |
return convert_out (ctx->preserve (result)); |
| 3027 |
} |
| 3028 |
|
| 3029 |
gcc_expr |
| 3030 |
plugin_build_new_expr (cc1_plugin::connection *self, |
| 3031 |
const char *new_op, |
| 3032 |
const struct gcc_cp_function_args *placement_in, |
| 3033 |
gcc_type type_in, |
| 3034 |
const struct gcc_cp_function_args *initializer_in) |
| 3035 |
{ |
| 3036 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3037 |
tree type = convert_in (type_in); |
| 3038 |
vec<tree, va_gc> *placement = NULL, *initializer = NULL; |
| 3039 |
bool global_scope_p = false; |
| 3040 |
tree nelts = NULL; |
| 3041 |
|
| 3042 |
if (placement_in) |
| 3043 |
placement = args_to_tree_vec (placement_in); |
| 3044 |
if (initializer_in) |
| 3045 |
initializer = args_to_tree_vec (initializer_in); |
| 3046 |
|
| 3047 |
gcc_assert (TYPE_P (type)); |
| 3048 |
|
| 3049 |
once_more: |
| 3050 |
switch (CHARS2 (new_op[0], new_op[1])) |
| 3051 |
{ |
| 3052 |
case CHARS2 ('g', 's'): |
| 3053 |
gcc_assert (!global_scope_p); |
| 3054 |
global_scope_p = true; |
| 3055 |
new_op += 2; |
| 3056 |
goto once_more; |
| 3057 |
|
| 3058 |
case CHARS2 ('n', 'w'): // non-array new |
| 3059 |
gcc_assert (TREE_CODE (type) != ARRAY_TYPE); |
| 3060 |
break; |
| 3061 |
|
| 3062 |
case CHARS2 ('n', 'a'): // array new |
| 3063 |
gcc_assert (TREE_CODE (type) == ARRAY_TYPE); |
| 3064 |
gcc_assert (TYPE_DOMAIN (type)); |
| 3065 |
{ |
| 3066 |
// Compute the length of the outermost array type, then discard it. |
| 3067 |
tree maxelt = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); |
| 3068 |
tree eltype = TREE_TYPE (maxelt); |
| 3069 |
tree onecst = integer_one_node; |
| 3070 |
|
| 3071 |
processing_template_decl++; |
| 3072 |
bool template_dependent_p = value_dependent_expression_p (maxelt) |
| 3073 |
|| type_dependent_expression_p (maxelt); |
| 3074 |
if (!template_dependent_p) |
| 3075 |
{ |
| 3076 |
processing_template_decl--; |
| 3077 |
onecst = fold_convert (eltype, onecst); |
| 3078 |
} |
| 3079 |
|
| 3080 |
nelts = fold_build2 (PLUS_EXPR, eltype, nelts, onecst); |
| 3081 |
|
| 3082 |
if (template_dependent_p) |
| 3083 |
processing_template_decl--; |
| 3084 |
|
| 3085 |
type = TREE_TYPE (type); |
| 3086 |
} |
| 3087 |
break; |
| 3088 |
|
| 3089 |
default: |
| 3090 |
gcc_unreachable (); |
| 3091 |
} |
| 3092 |
|
| 3093 |
processing_template_decl++; |
| 3094 |
bool template_dependent_p = dependent_type_p (type) |
| 3095 |
|| value_dependent_expression_p (nelts) |
| 3096 |
|| (placement |
| 3097 |
&& any_type_dependent_arguments_p (placement)) |
| 3098 |
|| (initializer |
| 3099 |
&& any_type_dependent_arguments_p (initializer)); |
| 3100 |
if (!template_dependent_p) |
| 3101 |
processing_template_decl--; |
| 3102 |
|
| 3103 |
tree result = build_new (input_location, &placement, type, nelts, |
| 3104 |
&initializer, global_scope_p, tf_error); |
| 3105 |
|
| 3106 |
if (template_dependent_p) |
| 3107 |
processing_template_decl--; |
| 3108 |
|
| 3109 |
if (placement != NULL) |
| 3110 |
release_tree_vector (placement); |
| 3111 |
if (initializer != NULL) |
| 3112 |
release_tree_vector (initializer); |
| 3113 |
|
| 3114 |
return convert_out (ctx->preserve (result)); |
| 3115 |
} |
| 3116 |
|
| 3117 |
gcc_expr |
| 3118 |
plugin_build_call_expr (cc1_plugin::connection *self, |
| 3119 |
gcc_expr callable_in, int qualified_p, |
| 3120 |
const struct gcc_cp_function_args *args_in) |
| 3121 |
{ |
| 3122 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3123 |
tree callable = convert_in (callable_in); |
| 3124 |
tree call_expr; |
| 3125 |
|
| 3126 |
vec<tree, va_gc> *args = args_to_tree_vec (args_in); |
| 3127 |
|
| 3128 |
bool koenig_p = false; |
| 3129 |
if (!qualified_p && !args->is_empty ()) |
| 3130 |
{ |
| 3131 |
if (identifier_p (callable)) |
| 3132 |
koenig_p = true; |
| 3133 |
else if (is_overloaded_fn (callable)) |
| 3134 |
{ |
| 3135 |
tree fn = get_first_fn (callable); |
| 3136 |
fn = STRIP_TEMPLATE (fn); |
| 3137 |
|
| 3138 |
if (!DECL_FUNCTION_MEMBER_P (fn) |
| 3139 |
&& !DECL_LOCAL_DECL_P (fn)) |
| 3140 |
koenig_p = true; |
| 3141 |
} |
| 3142 |
} |
| 3143 |
|
| 3144 |
if (koenig_p && !any_type_dependent_arguments_p (args)) |
| 3145 |
callable = perform_koenig_lookup (callable, args, tf_none); |
| 3146 |
|
| 3147 |
if (TREE_CODE (callable) == COMPONENT_REF) |
| 3148 |
{ |
| 3149 |
tree object = TREE_OPERAND (callable, 0); |
| 3150 |
tree memfn = TREE_OPERAND (callable, 1); |
| 3151 |
|
| 3152 |
if (type_dependent_expression_p (object) |
| 3153 |
|| (!BASELINK_P (memfn) && TREE_CODE (memfn) != FIELD_DECL) |
| 3154 |
|| type_dependent_expression_p (memfn) |
| 3155 |
|| any_type_dependent_arguments_p (args)) |
| 3156 |
call_expr = build_nt_call_vec (callable, args); |
| 3157 |
else if (BASELINK_P (memfn)) |
| 3158 |
call_expr = build_new_method_call (object, memfn, &args, NULL_TREE, |
| 3159 |
qualified_p |
| 3160 |
? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL |
| 3161 |
: LOOKUP_NORMAL, |
| 3162 |
NULL, tf_none); |
| 3163 |
else |
| 3164 |
call_expr = finish_call_expr (callable, &args, false, false, tf_none); |
| 3165 |
} |
| 3166 |
else if (TREE_CODE (callable) == OFFSET_REF |
| 3167 |
|| TREE_CODE (callable) == MEMBER_REF |
| 3168 |
|| TREE_CODE (callable) == DOTSTAR_EXPR) |
| 3169 |
call_expr = build_offset_ref_call_from_tree (callable, &args, tf_none); |
| 3170 |
else |
| 3171 |
call_expr = finish_call_expr (callable, &args, |
| 3172 |
!!qualified_p, koenig_p, tf_none); |
| 3173 |
|
| 3174 |
release_tree_vector (args); |
| 3175 |
return convert_out (ctx->preserve (call_expr)); |
| 3176 |
} |
| 3177 |
|
| 3178 |
gcc_type |
| 3179 |
plugin_get_expr_type (cc1_plugin::connection *self, |
| 3180 |
gcc_expr operand) |
| 3181 |
{ |
| 3182 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3183 |
tree op0 = convert_in (operand); |
| 3184 |
tree type; |
| 3185 |
if (op0) |
| 3186 |
type = TREE_TYPE (op0); |
| 3187 |
else |
| 3188 |
type = make_decltype_auto (); |
| 3189 |
return convert_out (ctx->preserve (type)); |
| 3190 |
} |
| 3191 |
|
| 3192 |
gcc_decl |
| 3193 |
plugin_build_function_template_specialization (cc1_plugin::connection *self, |
| 3194 |
gcc_decl template_decl, |
| 3195 |
const gcc_cp_template_args *targs, |
| 3196 |
gcc_address address, |
| 3197 |
const char *filename, |
| 3198 |
unsigned int line_number) |
| 3199 |
{ |
| 3200 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3201 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 3202 |
tree name = convert_in (template_decl); |
| 3203 |
tree targsl = targlist (targs); |
| 3204 |
|
| 3205 |
tree decl = tsubst (name, targsl, tf_error, NULL_TREE); |
| 3206 |
DECL_SOURCE_LOCATION (decl) = loc; |
| 3207 |
|
| 3208 |
record_decl_address (ctx, build_decl_addr_value (decl, address)); |
| 3209 |
|
| 3210 |
return convert_out (ctx->preserve (decl)); |
| 3211 |
} |
| 3212 |
|
| 3213 |
gcc_decl |
| 3214 |
plugin_build_class_template_specialization (cc1_plugin::connection *self, |
| 3215 |
gcc_decl template_decl, |
| 3216 |
const gcc_cp_template_args *args, |
| 3217 |
const char *filename, |
| 3218 |
unsigned int line_number) |
| 3219 |
{ |
| 3220 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3221 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 3222 |
tree name = convert_in (template_decl); |
| 3223 |
|
| 3224 |
tree tdecl = finish_template_type (name, targlist (args), false);; |
| 3225 |
DECL_SOURCE_LOCATION (tdecl) = loc; |
| 3226 |
|
| 3227 |
return convert_out (ctx->preserve (tdecl)); |
| 3228 |
} |
| 3229 |
|
| 3230 |
/* Return a builtin type associated with BUILTIN_NAME. */ |
| 3231 |
|
| 3232 |
static tree |
| 3233 |
safe_lookup_builtin_type (const char *builtin_name) |
| 3234 |
{ |
| 3235 |
tree result = NULL_TREE; |
| 3236 |
|
| 3237 |
if (!builtin_name) |
| 3238 |
return result; |
| 3239 |
|
| 3240 |
result = identifier_global_value (get_identifier (builtin_name)); |
| 3241 |
|
| 3242 |
if (!result) |
| 3243 |
return result; |
| 3244 |
|
| 3245 |
gcc_assert (TREE_CODE (result) == TYPE_DECL); |
| 3246 |
result = TREE_TYPE (result); |
| 3247 |
return result; |
| 3248 |
} |
| 3249 |
|
| 3250 |
gcc_type |
| 3251 |
plugin_get_int_type (cc1_plugin::connection *self, |
| 3252 |
int is_unsigned, unsigned long size_in_bytes, |
| 3253 |
const char *builtin_name) |
| 3254 |
{ |
| 3255 |
tree result; |
| 3256 |
|
| 3257 |
if (builtin_name) |
| 3258 |
{ |
| 3259 |
result = safe_lookup_builtin_type (builtin_name); |
| 3260 |
gcc_assert (!result || TREE_CODE (result) == INTEGER_TYPE); |
| 3261 |
} |
| 3262 |
else |
| 3263 |
result = c_common_type_for_size (BITS_PER_UNIT * size_in_bytes, |
| 3264 |
is_unsigned); |
| 3265 |
|
| 3266 |
if (result == NULL_TREE) |
| 3267 |
result = error_mark_node; |
| 3268 |
else |
| 3269 |
{ |
| 3270 |
gcc_assert (!TYPE_UNSIGNED (result) == !is_unsigned); |
| 3271 |
gcc_assert (TREE_CODE (TYPE_SIZE (result)) == INTEGER_CST); |
| 3272 |
gcc_assert (TYPE_PRECISION (result) == BITS_PER_UNIT * size_in_bytes); |
| 3273 |
|
| 3274 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3275 |
ctx->preserve (result); |
| 3276 |
} |
| 3277 |
return convert_out (result); |
| 3278 |
} |
| 3279 |
|
| 3280 |
gcc_type |
| 3281 |
plugin_get_char_type (cc1_plugin::connection *) |
| 3282 |
{ |
| 3283 |
return convert_out (char_type_node); |
| 3284 |
} |
| 3285 |
|
| 3286 |
gcc_type |
| 3287 |
plugin_get_float_type (cc1_plugin::connection *, |
| 3288 |
unsigned long size_in_bytes, |
| 3289 |
const char *builtin_name) |
| 3290 |
{ |
| 3291 |
if (builtin_name) |
| 3292 |
{ |
| 3293 |
tree result = safe_lookup_builtin_type (builtin_name); |
| 3294 |
|
| 3295 |
if (!result) |
| 3296 |
return convert_out (error_mark_node); |
| 3297 |
|
| 3298 |
gcc_assert (SCALAR_FLOAT_TYPE_P (result)); |
| 3299 |
gcc_assert (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (result)); |
| 3300 |
|
| 3301 |
return convert_out (result); |
| 3302 |
} |
| 3303 |
|
| 3304 |
if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (float_type_node)) |
| 3305 |
return convert_out (float_type_node); |
| 3306 |
if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (double_type_node)) |
| 3307 |
return convert_out (double_type_node); |
| 3308 |
if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (long_double_type_node)) |
| 3309 |
return convert_out (long_double_type_node); |
| 3310 |
return convert_out (error_mark_node); |
| 3311 |
} |
| 3312 |
|
| 3313 |
gcc_type |
| 3314 |
plugin_get_void_type (cc1_plugin::connection *) |
| 3315 |
{ |
| 3316 |
return convert_out (void_type_node); |
| 3317 |
} |
| 3318 |
|
| 3319 |
gcc_type |
| 3320 |
plugin_get_bool_type (cc1_plugin::connection *) |
| 3321 |
{ |
| 3322 |
return convert_out (boolean_type_node); |
| 3323 |
} |
| 3324 |
|
| 3325 |
gcc_type |
| 3326 |
plugin_get_nullptr_type (cc1_plugin::connection *) |
| 3327 |
{ |
| 3328 |
return convert_out (nullptr_type_node); |
| 3329 |
} |
| 3330 |
|
| 3331 |
gcc_expr |
| 3332 |
plugin_get_nullptr_constant (cc1_plugin::connection *) |
| 3333 |
{ |
| 3334 |
return convert_out (nullptr_node); |
| 3335 |
} |
| 3336 |
|
| 3337 |
gcc_type |
| 3338 |
plugin_build_array_type (cc1_plugin::connection *self, |
| 3339 |
gcc_type element_type_in, int num_elements) |
| 3340 |
{ |
| 3341 |
tree element_type = convert_in (element_type_in); |
| 3342 |
tree result; |
| 3343 |
|
| 3344 |
if (num_elements == -1) |
| 3345 |
result = build_array_type (element_type, NULL_TREE); |
| 3346 |
else |
| 3347 |
result = build_array_type_nelts (element_type, num_elements); |
| 3348 |
|
| 3349 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3350 |
return convert_out (ctx->preserve (result)); |
| 3351 |
} |
| 3352 |
|
| 3353 |
gcc_type |
| 3354 |
plugin_build_dependent_array_type (cc1_plugin::connection *self, |
| 3355 |
gcc_type element_type_in, |
| 3356 |
gcc_expr num_elements_in) |
| 3357 |
{ |
| 3358 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3359 |
tree element_type = convert_in (element_type_in); |
| 3360 |
tree size = convert_in (num_elements_in); |
| 3361 |
tree name = get_identifier ("dependent array type"); |
| 3362 |
|
| 3363 |
processing_template_decl++; |
| 3364 |
bool template_dependent_p = dependent_type_p (element_type) |
| 3365 |
|| type_dependent_expression_p (size) |
| 3366 |
|| value_dependent_expression_p (size); |
| 3367 |
if (!template_dependent_p) |
| 3368 |
processing_template_decl--; |
| 3369 |
|
| 3370 |
tree itype = compute_array_index_type (name, size, tf_error); |
| 3371 |
tree type = build_cplus_array_type (element_type, itype); |
| 3372 |
|
| 3373 |
if (template_dependent_p) |
| 3374 |
processing_template_decl--; |
| 3375 |
|
| 3376 |
return convert_out (ctx->preserve (type)); |
| 3377 |
} |
| 3378 |
|
| 3379 |
gcc_type |
| 3380 |
plugin_build_vla_array_type (cc1_plugin::connection *self, |
| 3381 |
gcc_type element_type_in, |
| 3382 |
const char *upper_bound_name) |
| 3383 |
{ |
| 3384 |
tree element_type = convert_in (element_type_in); |
| 3385 |
tree upper_bound = lookup_name (get_identifier (upper_bound_name)); |
| 3386 |
tree size = fold_build2 (PLUS_EXPR, TREE_TYPE (upper_bound), upper_bound, |
| 3387 |
build_one_cst (TREE_TYPE (upper_bound))); |
| 3388 |
tree range = compute_array_index_type (NULL_TREE, size, |
| 3389 |
tf_error); |
| 3390 |
|
| 3391 |
tree result = build_cplus_array_type (element_type, range); |
| 3392 |
|
| 3393 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3394 |
return convert_out (ctx->preserve (result)); |
| 3395 |
} |
| 3396 |
|
| 3397 |
gcc_type |
| 3398 |
plugin_build_qualified_type (cc1_plugin::connection *, |
| 3399 |
gcc_type unqualified_type_in, |
| 3400 |
enum gcc_cp_qualifiers qualifiers) |
| 3401 |
{ |
| 3402 |
tree unqualified_type = convert_in (unqualified_type_in); |
| 3403 |
cp_cv_quals quals = 0; |
| 3404 |
|
| 3405 |
if ((qualifiers & GCC_CP_QUALIFIER_CONST) != 0) |
| 3406 |
quals |= TYPE_QUAL_CONST; |
| 3407 |
if ((qualifiers & GCC_CP_QUALIFIER_VOLATILE) != 0) |
| 3408 |
quals |= TYPE_QUAL_VOLATILE; |
| 3409 |
if ((qualifiers & GCC_CP_QUALIFIER_RESTRICT) != 0) |
| 3410 |
quals |= TYPE_QUAL_RESTRICT; |
| 3411 |
|
| 3412 |
gcc_assert ((TREE_CODE (unqualified_type) != METHOD_TYPE |
| 3413 |
&& TREE_CODE (unqualified_type) != REFERENCE_TYPE) |
| 3414 |
|| quals == 0); |
| 3415 |
|
| 3416 |
return convert_out (build_qualified_type (unqualified_type, quals)); |
| 3417 |
} |
| 3418 |
|
| 3419 |
gcc_type |
| 3420 |
plugin_build_complex_type (cc1_plugin::connection *self, |
| 3421 |
gcc_type base_type) |
| 3422 |
{ |
| 3423 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3424 |
return convert_out (ctx->preserve (build_complex_type (convert_in (base_type)))); |
| 3425 |
} |
| 3426 |
|
| 3427 |
gcc_type |
| 3428 |
plugin_build_vector_type (cc1_plugin::connection *self, |
| 3429 |
gcc_type base_type, int nunits) |
| 3430 |
{ |
| 3431 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3432 |
return convert_out (ctx->preserve (build_vector_type (convert_in (base_type), |
| 3433 |
nunits))); |
| 3434 |
} |
| 3435 |
|
| 3436 |
int |
| 3437 |
plugin_build_constant (cc1_plugin::connection *self, gcc_type type_in, |
| 3438 |
const char *name, unsigned long value, |
| 3439 |
const char *filename, unsigned int line_number) |
| 3440 |
{ |
| 3441 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3442 |
tree cst, decl; |
| 3443 |
tree type = convert_in (type_in); |
| 3444 |
|
| 3445 |
cst = build_int_cst (type, value); |
| 3446 |
if (!TYPE_READONLY (type)) |
| 3447 |
type = build_qualified_type (type, TYPE_QUAL_CONST); |
| 3448 |
decl = build_decl (ctx->get_location_t (filename, line_number), |
| 3449 |
VAR_DECL, get_identifier (name), type); |
| 3450 |
TREE_STATIC (decl) = 1; |
| 3451 |
TREE_READONLY (decl) = 1; |
| 3452 |
cp_finish_decl (decl, cst, true, NULL, LOOKUP_ONLYCONVERTING); |
| 3453 |
safe_pushdecl (decl); |
| 3454 |
|
| 3455 |
return 1; |
| 3456 |
} |
| 3457 |
|
| 3458 |
gcc_type |
| 3459 |
plugin_error (cc1_plugin::connection *, |
| 3460 |
const char *message) |
| 3461 |
{ |
| 3462 |
error ("%s", message); |
| 3463 |
return convert_out (error_mark_node); |
| 3464 |
} |
| 3465 |
|
| 3466 |
int |
| 3467 |
plugin_add_static_assert (cc1_plugin::connection *self, |
| 3468 |
gcc_expr condition_in, |
| 3469 |
const char *errormsg, |
| 3470 |
const char *filename, |
| 3471 |
unsigned int line_number) |
| 3472 |
{ |
| 3473 |
plugin_context *ctx = static_cast<plugin_context *> (self); |
| 3474 |
tree condition = convert_in (condition_in); |
| 3475 |
|
| 3476 |
if (!errormsg) |
| 3477 |
errormsg = ""; |
| 3478 |
|
| 3479 |
tree message = build_string (strlen (errormsg) + 1, errormsg); |
| 3480 |
|
| 3481 |
TREE_TYPE (message) = char_array_type_node; |
| 3482 |
fix_string_type (message); |
| 3483 |
|
| 3484 |
location_t loc = ctx->get_location_t (filename, line_number); |
| 3485 |
|
| 3486 |
bool member_p = at_class_scope_p (); |
| 3487 |
|
| 3488 |
finish_static_assert (condition, message, loc, member_p, false); |
| 3489 |
|
| 3490 |
return 1; |
| 3491 |
} |
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
#ifdef __GNUC__ |
| 3496 |
#pragma GCC visibility push(default) |
| 3497 |
#endif |
| 3498 |
|
| 3499 |
int |
| 3500 |
plugin_init (struct plugin_name_args *plugin_info, |
| 3501 |
struct plugin_gcc_version *) |
| 3502 |
{ |
| 3503 |
generic_plugin_init (plugin_info, GCC_CP_FE_VERSION_0); |
| 3504 |
|
| 3505 |
register_callback (plugin_info->base_name, PLUGIN_PRAGMAS, |
| 3506 |
plugin_init_extra_pragmas, NULL); |
| 3507 |
register_callback (plugin_info->base_name, PLUGIN_PRE_GENERICIZE, |
| 3508 |
rewrite_decls_to_addresses, NULL); |
| 3509 |
|
| 3510 |
#define GCC_METHOD0(R, N) \ |
| 3511 |
{ \ |
| 3512 |
cc1_plugin::callback_ftype *fun \ |
| 3513 |
= cc1_plugin::invoker<R>::invoke<plugin_ ## N>; \ |
| 3514 |
current_context->add_callback (# N, fun); \ |
| 3515 |
} |
| 3516 |
#define GCC_METHOD1(R, N, A) \ |
| 3517 |
{ \ |
| 3518 |
cc1_plugin::callback_ftype *fun \ |
| 3519 |
= cc1_plugin::invoker<R, A>::invoke<plugin_ ## N>; \ |
| 3520 |
current_context->add_callback (# N, fun); \ |
| 3521 |
} |
| 3522 |
#define GCC_METHOD2(R, N, A, B) \ |
| 3523 |
{ \ |
| 3524 |
cc1_plugin::callback_ftype *fun \ |
| 3525 |
= cc1_plugin::invoker<R, A, B>::invoke<plugin_ ## N>; \ |
| 3526 |
current_context->add_callback (# N, fun); \ |
| 3527 |
} |
| 3528 |
#define GCC_METHOD3(R, N, A, B, C) \ |
| 3529 |
{ \ |
| 3530 |
cc1_plugin::callback_ftype *fun \ |
| 3531 |
= cc1_plugin::invoker<R, A, B, C>::invoke<plugin_ ## N>; \ |
| 3532 |
current_context->add_callback (# N, fun); \ |
| 3533 |
} |
| 3534 |
#define GCC_METHOD4(R, N, A, B, C, D) \ |
| 3535 |
{ \ |
| 3536 |
cc1_plugin::callback_ftype *fun \ |
| 3537 |
= cc1_plugin::invoker<R, A, B, C, \ |
| 3538 |
D>::invoke<plugin_ ## N>; \ |
| 3539 |
current_context->add_callback (# N, fun); \ |
| 3540 |
} |
| 3541 |
#define GCC_METHOD5(R, N, A, B, C, D, E) \ |
| 3542 |
{ \ |
| 3543 |
cc1_plugin::callback_ftype *fun \ |
| 3544 |
= cc1_plugin::invoker<R, A, B, C, \ |
| 3545 |
D, E>::invoke<plugin_ ## N>; \ |
| 3546 |
current_context->add_callback (# N, fun); \ |
| 3547 |
} |
| 3548 |
#define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \ |
| 3549 |
{ \ |
| 3550 |
cc1_plugin::callback_ftype *fun \ |
| 3551 |
= cc1_plugin::invoker<R, A, B, C, \ |
| 3552 |
D, E, F, G>::invoke<plugin_ ## N>; \ |
| 3553 |
current_context->add_callback (# N, fun); \ |
| 3554 |
} |
| 3555 |
|
| 3556 |
#include "gcc-cp-fe.def" |
| 3557 |
|
| 3558 |
#undef GCC_METHOD0 |
| 3559 |
#undef GCC_METHOD1 |
| 3560 |
#undef GCC_METHOD2 |
| 3561 |
#undef GCC_METHOD3 |
| 3562 |
#undef GCC_METHOD4 |
| 3563 |
#undef GCC_METHOD5 |
| 3564 |
#undef GCC_METHOD7 |
| 3565 |
|
| 3566 |
return 0; |
| 3567 |
} |