static void pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case VAR_DECL: case PARM_DECL: case CONST_DECL: case FIELD_DECL: if (DECL_NAME (t)) { pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t)); pp_cxx_id_expression (pp, DECL_NAME (t)); } pp_cxx_abstract_declarator (pp, TREE_TYPE (t)); break; case FUNCTION_DECL: pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t))); pp_cxx_id_expression (pp, t); pp_cxx_parameter_declaration_clause (pp, t); if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t)) { pp_base (pp)->padding = pp_before; pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t)); } pp_cxx_exception_specification (pp, TREE_TYPE (t)); break; case TYPENAME_TYPE: case TEMPLATE_DECL: case TEMPLATE_TYPE_PARM: case TEMPLATE_PARM_INDEX: case TEMPLATE_TEMPLATE_PARM: break; default: pp_c_direct_declarator (pp_c_base (pp), t); break; } }
static void pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case VAR_DECL: case PARM_DECL: case CONST_DECL: case FIELD_DECL: pp_cxx_storage_class_specifier (pp, t); pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t)); break; case TYPE_DECL: pp_cxx_identifier (pp, "typedef"); pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t)); break; case RECORD_TYPE: if (TYPE_PTRMEMFUNC_P (t)) { tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t); pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm))); pp_cxx_whitespace (pp); pp_cxx_ptr_operator (pp, t); } break; case FUNCTION_DECL: /* Constructors don't have return types. And conversion functions do not have a type-specifier in their return types. */ if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t)) pp_cxx_function_specifier (pp, t); else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t)) pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t))); else default: pp_c_declaration_specifiers (pp_c_base (pp), t); break; } }
tree nonlambda_method_basetype (void) { tree fn, type; if (!current_class_ref) return NULL_TREE; type = current_class_type; if (!LAMBDA_TYPE_P (type)) return type; /* Find the nearest enclosing non-lambda function. */ fn = TYPE_NAME (type); do fn = decl_function_context (fn); while (fn && LAMBDA_FUNCTION_P (fn)); if (!fn || !DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) return NULL_TREE; return TYPE_METHOD_BASETYPE (TREE_TYPE (fn)); }
tree lambda_expr_this_capture (tree lambda, bool add_capture_p) { tree result; tree this_capture = LAMBDA_EXPR_THIS_CAPTURE (lambda); /* In unevaluated context this isn't an odr-use, so don't capture. */ if (cp_unevaluated_operand) add_capture_p = false; /* Try to default capture 'this' if we can. */ if (!this_capture && (!add_capture_p || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) != CPLD_NONE)) { tree lambda_stack = NULL_TREE; tree init = NULL_TREE; /* If we are in a lambda function, we can move out until we hit: 1. a non-lambda function or NSDMI, 2. a lambda function capturing 'this', or 3. a non-default capturing lambda function. */ for (tree tlambda = lambda; ;) { lambda_stack = tree_cons (NULL_TREE, tlambda, lambda_stack); if (LAMBDA_EXPR_EXTRA_SCOPE (tlambda) && TREE_CODE (LAMBDA_EXPR_EXTRA_SCOPE (tlambda)) == FIELD_DECL) { /* In an NSDMI, we don't have a function to look up the decl in, but the fake 'this' pointer that we're using for parsing is in scope_chain. */ init = scope_chain->x_current_class_ptr; gcc_checking_assert (init && (TREE_TYPE (TREE_TYPE (init)) == current_nonlambda_class_type ())); break; } tree closure_decl = TYPE_NAME (LAMBDA_EXPR_CLOSURE (tlambda)); tree containing_function = decl_function_context (closure_decl); if (containing_function == NULL_TREE) /* We ran out of scopes; there's no 'this' to capture. */ break; if (!LAMBDA_FUNCTION_P (containing_function)) { /* We found a non-lambda function. */ if (DECL_NONSTATIC_MEMBER_FUNCTION_P (containing_function)) /* First parameter is 'this'. */ init = DECL_ARGUMENTS (containing_function); break; } tlambda = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (containing_function)); if (LAMBDA_EXPR_THIS_CAPTURE (tlambda)) { /* An outer lambda has already captured 'this'. */ init = LAMBDA_EXPR_THIS_CAPTURE (tlambda); break; } if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (tlambda) == CPLD_NONE) /* An outer lambda won't let us capture 'this'. */ break; } if (init) { if (add_capture_p) this_capture = add_default_capture (lambda_stack, /*id=*/this_identifier, init); else this_capture = init; } } if (cp_unevaluated_operand) result = this_capture; else if (!this_capture) { if (add_capture_p) { error ("%<this%> was not captured for this lambda function"); result = error_mark_node; } else result = NULL_TREE; } else { /* To make sure that current_class_ref is for the lambda. */ gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)) == LAMBDA_EXPR_CLOSURE (lambda)); result = this_capture; /* If 'this' is captured, each use of 'this' is transformed into an access to the corresponding unnamed data member of the closure type cast (_expr.cast_ 5.4) to the type of 'this'. [ The cast ensures that the transformed expression is an rvalue. ] */ result = rvalue (result); } return result; }
/* Return -1 if dwarf ATTR shouldn't be added for DECL, or the attribute value otherwise. */ int cp_decl_dwarf_attribute (const_tree decl, int attr) { if (decl == NULL_TREE) return -1; switch (attr) { case DW_AT_explicit: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) && DECL_NONCONVERTING_P (decl)) return 1; break; case DW_AT_deleted: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) && DECL_DELETED_FN (decl)) return 1; break; case DW_AT_defaulted: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) && DECL_DEFAULTED_FN (decl)) { if (DECL_DEFAULTED_IN_CLASS_P (decl)) return DW_DEFAULTED_in_class; if (DECL_DEFAULTED_OUTSIDE_CLASS_P (decl)) return DW_DEFAULTED_out_of_class; } break; case DW_AT_const_expr: if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_DECLARED_CONSTEXPR_P (decl)) return 1; break; case DW_AT_reference: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl) && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)) && !FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl))) return 1; break; case DW_AT_rvalue_reference: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl) && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)) && FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl))) return 1; break; case DW_AT_inline: if (VAR_P (decl) && DECL_INLINE_VAR_P (decl)) { if (DECL_VAR_DECLARED_INLINE_P (decl)) return DW_INL_declared_inlined; else return DW_INL_inlined; } break; case DW_AT_export_symbols: if (TREE_CODE (decl) == NAMESPACE_DECL && (DECL_NAMESPACE_INLINE_P (decl) || (DECL_NAME (decl) == NULL_TREE && dwarf_version >= 5))) return 1; break; default: break; } return -1; }
static void pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t) { enum tree_code code = TREE_CODE (t); switch (code) { case AGGR_INIT_EXPR: case CALL_EXPR: { tree fun = TREE_OPERAND (t, 0); tree args = TREE_OPERAND (t, 1); tree saved_scope = pp->enclosing_scope; if (TREE_CODE (fun) == ADDR_EXPR) fun = TREE_OPERAND (fun, 0); /* In templates, where there is no way to tell whether a given call uses an actual member function. So the parser builds FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until instantiation time. */ if (TREE_CODE (fun) != FUNCTION_DECL) ; else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun)) { tree object = code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t) ? TREE_OPERAND (t, 2) : TREE_VALUE (args); while (TREE_CODE (object) == NOP_EXPR) object = TREE_OPERAND (object, 0); if (TREE_CODE (object) == ADDR_EXPR) object = TREE_OPERAND (object, 0); if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE) { pp_cxx_postfix_expression (pp, object); pp_cxx_dot (pp); } else { pp_cxx_postfix_expression (pp, object); pp_cxx_arrow (pp); } args = TREE_CHAIN (args); pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object)); } pp_cxx_postfix_expression (pp, fun); pp->enclosing_scope = saved_scope; pp_cxx_call_argument_list (pp, args); } if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t)) { pp_cxx_separate_with (pp, ','); pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 2)); } break; case BASELINK: case VAR_DECL: case PARM_DECL: case FIELD_DECL: case FUNCTION_DECL: case OVERLOAD: case CONST_DECL: case TEMPLATE_DECL: case RESULT_DECL: pp_cxx_primary_expression (pp, t); break; case DYNAMIC_CAST_EXPR: case STATIC_CAST_EXPR: case REINTERPRET_CAST_EXPR: case CONST_CAST_EXPR: if (code == DYNAMIC_CAST_EXPR) pp_cxx_identifier (pp, "dynamic_cast"); else if (code == STATIC_CAST_EXPR) pp_cxx_identifier (pp, "static_cast"); else if (code == REINTERPRET_CAST_EXPR) pp_cxx_identifier (pp, "reinterpret_cast"); else pp_cxx_identifier (pp, "const_cast"); pp_cxx_begin_template_argument_list (pp); pp_cxx_type_id (pp, TREE_TYPE (t)); pp_cxx_end_template_argument_list (pp); pp_left_paren (pp); pp_cxx_expression (pp, TREE_OPERAND (t, 0)); pp_right_paren (pp); break; case EMPTY_CLASS_EXPR: pp_cxx_type_id (pp, TREE_TYPE (t)); pp_left_paren (pp); pp_right_paren (pp); break; case TYPEID_EXPR: t = TREE_OPERAND (t, 0); pp_cxx_identifier (pp, "typeid"); pp_left_paren (pp); if (TYPE_P (t)) pp_cxx_type_id (pp, t); else pp_cxx_expression (pp, t); pp_right_paren (pp); break; case PSEUDO_DTOR_EXPR: pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0)); pp_cxx_dot (pp); pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1)); pp_cxx_colon_colon (pp); pp_complement (pp); pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2)); break; case ARROW_EXPR: pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0)); pp_cxx_arrow (pp); break; default: pp_c_postfix_expression (pp_c_base (pp), t); break; } }