123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439 |
- /* Implementation of subroutines for the GNU C++ pretty-printer.
- Copyright (C) 2003-2015 Free Software Foundation, Inc.
- Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
- This file is part of GCC.
- GCC is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 3, or (at your option) any later
- version.
- GCC is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
- You should have received a copy of the GNU General Public License
- along with GCC; see the file COPYING3. If not see
- <http://www.gnu.org/licenses/>. */
- #include "config.h"
- #include "system.h"
- #include "coretypes.h"
- #include "tm.h"
- #include "intl.h"
- #include "cp-tree.h"
- #include "cxx-pretty-print.h"
- #include "tree-pretty-print.h"
- static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
- static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
- static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
- static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
- static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
- static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
- static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
- static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
- static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
- static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
- static inline void
- pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
- {
- const char *p = pp_last_position_in_text (pp);
- if (p != NULL && *p == c)
- pp_cxx_whitespace (pp);
- pp_character (pp, c);
- pp->padding = pp_none;
- }
- #define pp_cxx_expression_list(PP, T) \
- pp_c_expression_list (PP, T)
- #define pp_cxx_space_for_pointer_operator(PP, T) \
- pp_c_space_for_pointer_operator (PP, T)
- #define pp_cxx_init_declarator(PP, T) \
- pp_c_init_declarator (PP, T)
- #define pp_cxx_call_argument_list(PP, T) \
- pp_c_call_argument_list (PP, T)
- void
- pp_cxx_colon_colon (cxx_pretty_printer *pp)
- {
- pp_colon_colon (pp);
- pp->padding = pp_none;
- }
- void
- pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
- {
- pp_cxx_nonconsecutive_character (pp, '<');
- }
- void
- pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
- {
- pp_cxx_nonconsecutive_character (pp, '>');
- }
- void
- pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
- {
- pp_separate_with (pp, c);
- pp->padding = pp_none;
- }
- /* Expressions. */
- static inline bool
- is_destructor_name (tree name)
- {
- return name == complete_dtor_identifier
- || name == base_dtor_identifier
- || name == deleting_dtor_identifier;
- }
- /* conversion-function-id:
- operator conversion-type-id
- conversion-type-id:
- type-specifier-seq conversion-declarator(opt)
- conversion-declarator:
- ptr-operator conversion-declarator(opt) */
- static inline void
- pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
- {
- pp_cxx_ws_string (pp, "operator");
- pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
- }
- static inline void
- pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
- {
- pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
- pp_cxx_begin_template_argument_list (pp);
- pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
- pp_cxx_end_template_argument_list (pp);
- }
- /* Prints the unqualified part of the id-expression T.
- unqualified-id:
- identifier
- operator-function-id
- conversion-function-id
- ~ class-name
- template-id */
- static void
- pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
- {
- enum tree_code code = TREE_CODE (t);
- switch (code)
- {
- case RESULT_DECL:
- pp->translate_string ("<return-value>");
- break;
- case OVERLOAD:
- t = OVL_CURRENT (t);
- case VAR_DECL:
- case PARM_DECL:
- case CONST_DECL:
- case TYPE_DECL:
- case FUNCTION_DECL:
- case NAMESPACE_DECL:
- case FIELD_DECL:
- case LABEL_DECL:
- case USING_DECL:
- case TEMPLATE_DECL:
- t = DECL_NAME (t);
- case IDENTIFIER_NODE:
- if (t == NULL)
- pp->translate_string ("<unnamed>");
- else if (IDENTIFIER_TYPENAME_P (t))
- pp_cxx_conversion_function_id (pp, t);
- else
- {
- if (is_destructor_name (t))
- {
- pp_complement (pp);
- /* FIXME: Why is this necessary? */
- if (TREE_TYPE (t))
- t = constructor_name (TREE_TYPE (t));
- }
- pp_cxx_tree_identifier (pp, t);
- }
- break;
- case TEMPLATE_ID_EXPR:
- pp_cxx_template_id (pp, t);
- break;
- case BASELINK:
- pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
- break;
- case RECORD_TYPE:
- case UNION_TYPE:
- case ENUMERAL_TYPE:
- case TYPENAME_TYPE:
- case UNBOUND_CLASS_TEMPLATE:
- pp_cxx_unqualified_id (pp, TYPE_NAME (t));
- if (CLASS_TYPE_P (t) && CLASSTYPE_USE_TEMPLATE (t))
- {
- pp_cxx_begin_template_argument_list (pp);
- pp_cxx_template_argument_list (pp, INNERMOST_TEMPLATE_ARGS
- (CLASSTYPE_TI_ARGS (t)));
- pp_cxx_end_template_argument_list (pp);
- }
- break;
- case BIT_NOT_EXPR:
- pp_cxx_complement (pp);
- pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
- break;
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_TEMPLATE_PARM:
- if (TYPE_IDENTIFIER (t))
- pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
- else
- pp_cxx_canonical_template_parameter (pp, t);
- break;
- case TEMPLATE_PARM_INDEX:
- pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
- break;
- case BOUND_TEMPLATE_TEMPLATE_PARM:
- pp_cxx_cv_qualifier_seq (pp, t);
- pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
- pp_cxx_begin_template_argument_list (pp);
- pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
- pp_cxx_end_template_argument_list (pp);
- break;
- default:
- pp_unsupported_tree (pp, t);
- break;
- }
- }
- /* Pretty-print out the token sequence ":: template" in template codes
- where it is needed to "inline declare" the (following) member as
- a template. This situation arises when SCOPE of T is dependent
- on template parameters. */
- static inline void
- pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
- {
- if (TREE_CODE (t) == TEMPLATE_ID_EXPR
- && TYPE_P (scope) && dependent_type_p (scope))
- pp_cxx_ws_string (pp, "template");
- }
- /* nested-name-specifier:
- class-or-namespace-name :: nested-name-specifier(opt)
- class-or-namespace-name :: template nested-name-specifier */
- static void
- pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
- {
- if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
- {
- tree scope = get_containing_scope (t);
- pp_cxx_nested_name_specifier (pp, scope);
- pp_cxx_template_keyword_if_needed (pp, scope, t);
- pp_cxx_unqualified_id (pp, t);
- pp_cxx_colon_colon (pp);
- }
- }
- /* qualified-id:
- nested-name-specifier template(opt) unqualified-id */
- static void
- pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
- {
- switch (TREE_CODE (t))
- {
- /* A pointer-to-member is always qualified. */
- case PTRMEM_CST:
- pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
- pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
- break;
- /* In Standard C++, functions cannot possibly be used as
- nested-name-specifiers. However, there are situations where
- is "makes sense" to output the surrounding function name for the
- purpose of emphasizing on the scope kind. Just printing the
- function name might not be sufficient as it may be overloaded; so,
- we decorate the function with its signature too.
- FIXME: This is probably the wrong pretty-printing for conversion
- functions and some function templates. */
- case OVERLOAD:
- t = OVL_CURRENT (t);
- case FUNCTION_DECL:
- if (DECL_FUNCTION_MEMBER_P (t))
- pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
- pp_cxx_unqualified_id
- (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
- pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
- break;
- case OFFSET_REF:
- case SCOPE_REF:
- pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
- pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
- break;
- default:
- {
- tree scope = get_containing_scope (t);
- if (scope != pp->enclosing_scope)
- {
- pp_cxx_nested_name_specifier (pp, scope);
- pp_cxx_template_keyword_if_needed (pp, scope, t);
- }
- pp_cxx_unqualified_id (pp, t);
- }
- break;
- }
- }
- void
- cxx_pretty_printer::constant (tree t)
- {
- switch (TREE_CODE (t))
- {
- case STRING_CST:
- {
- const bool in_parens = PAREN_STRING_LITERAL_P (t);
- if (in_parens)
- pp_cxx_left_paren (this);
- c_pretty_printer::constant (t);
- if (in_parens)
- pp_cxx_right_paren (this);
- }
- break;
- case INTEGER_CST:
- if (NULLPTR_TYPE_P (TREE_TYPE (t)))
- {
- pp_string (this, "nullptr");
- break;
- }
- /* else fall through. */
- default:
- c_pretty_printer::constant (t);
- break;
- }
- }
- /* id-expression:
- unqualified-id
- qualified-id */
- void
- cxx_pretty_printer::id_expression (tree t)
- {
- if (TREE_CODE (t) == OVERLOAD)
- t = OVL_CURRENT (t);
- if (DECL_P (t) && DECL_CONTEXT (t))
- pp_cxx_qualified_id (this, t);
- else
- pp_cxx_unqualified_id (this, t);
- }
- /* user-defined literal:
- literal ud-suffix */
- void
- pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
- {
- pp->constant (USERDEF_LITERAL_VALUE (t));
- pp->id_expression (USERDEF_LITERAL_SUFFIX_ID (t));
- }
- /* primary-expression:
- literal
- this
- :: identifier
- :: operator-function-id
- :: qualifier-id
- ( expression )
- id-expression
- GNU Extensions:
- __builtin_va_arg ( assignment-expression , type-id )
- __builtin_offsetof ( type-id, offsetof-expression )
- __has_nothrow_assign ( type-id )
- __has_nothrow_constructor ( type-id )
- __has_nothrow_copy ( type-id )
- __has_trivial_assign ( type-id )
- __has_trivial_constructor ( type-id )
- __has_trivial_copy ( type-id )
- __has_trivial_destructor ( type-id )
- __has_virtual_destructor ( type-id )
- __is_abstract ( type-id )
- __is_base_of ( type-id , type-id )
- __is_class ( type-id )
- __is_empty ( type-id )
- __is_enum ( type-id )
- __is_literal_type ( type-id )
- __is_pod ( type-id )
- __is_polymorphic ( type-id )
- __is_std_layout ( type-id )
- __is_trivial ( type-id )
- __is_union ( type-id ) */
- void
- cxx_pretty_printer::primary_expression (tree t)
- {
- switch (TREE_CODE (t))
- {
- case VOID_CST:
- case INTEGER_CST:
- case REAL_CST:
- case COMPLEX_CST:
- case STRING_CST:
- constant (t);
- break;
- case USERDEF_LITERAL:
- pp_cxx_userdef_literal (this, t);
- break;
- case BASELINK:
- t = BASELINK_FUNCTIONS (t);
- case VAR_DECL:
- case PARM_DECL:
- case FIELD_DECL:
- case FUNCTION_DECL:
- case OVERLOAD:
- case CONST_DECL:
- case TEMPLATE_DECL:
- id_expression (t);
- break;
- case RESULT_DECL:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_TEMPLATE_PARM:
- case TEMPLATE_PARM_INDEX:
- pp_cxx_unqualified_id (this, t);
- break;
- case STMT_EXPR:
- pp_cxx_left_paren (this);
- statement (STMT_EXPR_STMT (t));
- pp_cxx_right_paren (this);
- break;
- case TRAIT_EXPR:
- pp_cxx_trait_expression (this, t);
- break;
- case VA_ARG_EXPR:
- pp_cxx_va_arg_expression (this, t);
- break;
- case OFFSETOF_EXPR:
- pp_cxx_offsetof_expression (this, t);
- break;
- default:
- c_pretty_printer::primary_expression (t);
- break;
- }
- }
- /* postfix-expression:
- primary-expression
- postfix-expression [ expression ]
- postfix-expression ( expression-list(opt) )
- simple-type-specifier ( expression-list(opt) )
- typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
- typename ::(opt) nested-name-specifier template(opt)
- template-id ( expression-list(opt) )
- postfix-expression . template(opt) ::(opt) id-expression
- postfix-expression -> template(opt) ::(opt) id-expression
- postfix-expression . pseudo-destructor-name
- postfix-expression -> pseudo-destructor-name
- postfix-expression ++
- postfix-expression --
- dynamic_cast < type-id > ( expression )
- static_cast < type-id > ( expression )
- reinterpret_cast < type-id > ( expression )
- const_cast < type-id > ( expression )
- typeid ( expression )
- typeid ( type-id ) */
- void
- cxx_pretty_printer::postfix_expression (tree t)
- {
- enum tree_code code = TREE_CODE (t);
- switch (code)
- {
- case AGGR_INIT_EXPR:
- case CALL_EXPR:
- {
- tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
- : CALL_EXPR_FN (t));
- tree saved_scope = enclosing_scope;
- bool skipfirst = false;
- tree arg;
- 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)
- ? AGGR_INIT_EXPR_SLOT (t)
- : AGGR_INIT_EXPR_ARG (t, 0))
- : CALL_EXPR_ARG (t, 0));
- while (TREE_CODE (object) == NOP_EXPR)
- object = TREE_OPERAND (object, 0);
- if (TREE_CODE (object) == ADDR_EXPR)
- object = TREE_OPERAND (object, 0);
- if (!TYPE_PTR_P (TREE_TYPE (object)))
- {
- postfix_expression (object);
- pp_cxx_dot (this);
- }
- else
- {
- postfix_expression (object);
- pp_cxx_arrow (this);
- }
- skipfirst = true;
- enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
- }
- postfix_expression (fun);
- enclosing_scope = saved_scope;
- pp_cxx_left_paren (this);
- if (code == AGGR_INIT_EXPR)
- {
- aggr_init_expr_arg_iterator iter;
- FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
- {
- if (skipfirst)
- skipfirst = false;
- else
- {
- expression (arg);
- if (more_aggr_init_expr_args_p (&iter))
- pp_cxx_separate_with (this, ',');
- }
- }
- }
- else
- {
- call_expr_arg_iterator iter;
- FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
- {
- if (skipfirst)
- skipfirst = false;
- else
- {
- expression (arg);
- if (more_call_expr_args_p (&iter))
- pp_cxx_separate_with (this, ',');
- }
- }
- }
- pp_cxx_right_paren (this);
- }
- if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
- {
- pp_cxx_separate_with (this, ',');
- postfix_expression (AGGR_INIT_EXPR_SLOT (t));
- }
- 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:
- primary_expression (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_ws_string (this, "dynamic_cast");
- else if (code == STATIC_CAST_EXPR)
- pp_cxx_ws_string (this, "static_cast");
- else if (code == REINTERPRET_CAST_EXPR)
- pp_cxx_ws_string (this, "reinterpret_cast");
- else
- pp_cxx_ws_string (this, "const_cast");
- pp_cxx_begin_template_argument_list (this);
- type_id (TREE_TYPE (t));
- pp_cxx_end_template_argument_list (this);
- pp_left_paren (this);
- expression (TREE_OPERAND (t, 0));
- pp_right_paren (this);
- break;
- case EMPTY_CLASS_EXPR:
- type_id (TREE_TYPE (t));
- pp_left_paren (this);
- pp_right_paren (this);
- break;
- case TYPEID_EXPR:
- pp_cxx_typeid_expression (this, t);
- break;
- case PSEUDO_DTOR_EXPR:
- postfix_expression (TREE_OPERAND (t, 0));
- pp_cxx_dot (this);
- if (TREE_OPERAND (t, 1))
- {
- pp_cxx_qualified_id (this, TREE_OPERAND (t, 1));
- pp_cxx_colon_colon (this);
- }
- pp_complement (this);
- pp_cxx_unqualified_id (this, TREE_OPERAND (t, 2));
- break;
- case ARROW_EXPR:
- postfix_expression (TREE_OPERAND (t, 0));
- pp_cxx_arrow (this);
- break;
- default:
- c_pretty_printer::postfix_expression (t);
- break;
- }
- }
- /* new-expression:
- ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
- ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
- new-placement:
- ( expression-list )
- new-type-id:
- type-specifier-seq new-declarator(opt)
- new-declarator:
- ptr-operator new-declarator(opt)
- direct-new-declarator
- direct-new-declarator
- [ expression ]
- direct-new-declarator [ constant-expression ]
- new-initializer:
- ( expression-list(opt) ) */
- static void
- pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
- {
- enum tree_code code = TREE_CODE (t);
- tree type = TREE_OPERAND (t, 1);
- tree init = TREE_OPERAND (t, 2);
- switch (code)
- {
- case NEW_EXPR:
- case VEC_NEW_EXPR:
- if (NEW_EXPR_USE_GLOBAL (t))
- pp_cxx_colon_colon (pp);
- pp_cxx_ws_string (pp, "new");
- if (TREE_OPERAND (t, 0))
- {
- pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
- pp_space (pp);
- }
- if (TREE_CODE (type) == ARRAY_REF)
- type = build_cplus_array_type
- (TREE_OPERAND (type, 0),
- build_index_type (fold_build2_loc (input_location,
- MINUS_EXPR, integer_type_node,
- TREE_OPERAND (type, 1),
- integer_one_node)));
- pp->type_id (type);
- if (init)
- {
- pp_left_paren (pp);
- if (TREE_CODE (init) == TREE_LIST)
- pp_c_expression_list (pp, init);
- else if (init == void_node)
- ; /* OK, empty initializer list. */
- else
- pp->expression (init);
- pp_right_paren (pp);
- }
- break;
- default:
- pp_unsupported_tree (pp, t);
- }
- }
- /* delete-expression:
- ::(opt) delete cast-expression
- ::(opt) delete [ ] cast-expression */
- static void
- pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
- {
- enum tree_code code = TREE_CODE (t);
- switch (code)
- {
- case DELETE_EXPR:
- case VEC_DELETE_EXPR:
- if (DELETE_EXPR_USE_GLOBAL (t))
- pp_cxx_colon_colon (pp);
- pp_cxx_ws_string (pp, "delete");
- pp_space (pp);
- if (code == VEC_DELETE_EXPR
- || DELETE_EXPR_USE_VEC (t))
- {
- pp_left_bracket (pp);
- pp_right_bracket (pp);
- pp_space (pp);
- }
- pp_c_cast_expression (pp, TREE_OPERAND (t, 0));
- break;
- default:
- pp_unsupported_tree (pp, t);
- }
- }
- /* unary-expression:
- postfix-expression
- ++ cast-expression
- -- cast-expression
- unary-operator cast-expression
- sizeof unary-expression
- sizeof ( type-id )
- sizeof ... ( identifier )
- new-expression
- delete-expression
- unary-operator: one of
- * & + - !
- GNU extensions:
- __alignof__ unary-expression
- __alignof__ ( type-id ) */
- void
- cxx_pretty_printer::unary_expression (tree t)
- {
- enum tree_code code = TREE_CODE (t);
- switch (code)
- {
- case NEW_EXPR:
- case VEC_NEW_EXPR:
- pp_cxx_new_expression (this, t);
- break;
- case DELETE_EXPR:
- case VEC_DELETE_EXPR:
- pp_cxx_delete_expression (this, t);
- break;
- case SIZEOF_EXPR:
- if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
- {
- pp_cxx_ws_string (this, "sizeof");
- pp_cxx_ws_string (this, "...");
- pp_cxx_whitespace (this);
- pp_cxx_left_paren (this);
- if (TYPE_P (TREE_OPERAND (t, 0)))
- type_id (TREE_OPERAND (t, 0));
- else
- unary_expression (TREE_OPERAND (t, 0));
- pp_cxx_right_paren (this);
- break;
- }
- /* Fall through */
- case ALIGNOF_EXPR:
- pp_cxx_ws_string (this, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
- pp_cxx_whitespace (this);
- if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
- {
- pp_cxx_left_paren (this);
- type_id (TREE_TYPE (TREE_OPERAND (t, 0)));
- pp_cxx_right_paren (this);
- }
- else if (TYPE_P (TREE_OPERAND (t, 0)))
- {
- pp_cxx_left_paren (this);
- type_id (TREE_OPERAND (t, 0));
- pp_cxx_right_paren (this);
- }
- else
- unary_expression (TREE_OPERAND (t, 0));
- break;
- case AT_ENCODE_EXPR:
- pp_cxx_ws_string (this, "@encode");
- pp_cxx_whitespace (this);
- pp_cxx_left_paren (this);
- type_id (TREE_OPERAND (t, 0));
- pp_cxx_right_paren (this);
- break;
- case NOEXCEPT_EXPR:
- pp_cxx_ws_string (this, "noexcept");
- pp_cxx_whitespace (this);
- pp_cxx_left_paren (this);
- expression (TREE_OPERAND (t, 0));
- pp_cxx_right_paren (this);
- break;
- case UNARY_PLUS_EXPR:
- pp_plus (this);
- pp_cxx_cast_expression (this, TREE_OPERAND (t, 0));
- break;
- default:
- c_pretty_printer::unary_expression (t);
- break;
- }
- }
- /* cast-expression:
- unary-expression
- ( type-id ) cast-expression */
- static void
- pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
- {
- switch (TREE_CODE (t))
- {
- case CAST_EXPR:
- case IMPLICIT_CONV_EXPR:
- pp->type_id (TREE_TYPE (t));
- pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
- break;
- default:
- pp_c_cast_expression (pp, t);
- break;
- }
- }
- /* pm-expression:
- cast-expression
- pm-expression .* cast-expression
- pm-expression ->* cast-expression */
- static void
- pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
- {
- switch (TREE_CODE (t))
- {
- /* Handle unfortunate OFFSET_REF overloading here. */
- case OFFSET_REF:
- if (TYPE_P (TREE_OPERAND (t, 0)))
- {
- pp_cxx_qualified_id (pp, t);
- break;
- }
- /* Else fall through. */
- case MEMBER_REF:
- case DOTSTAR_EXPR:
- pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
- if (TREE_CODE (t) == MEMBER_REF)
- pp_cxx_arrow (pp);
- else
- pp_cxx_dot (pp);
- pp_star(pp);
- pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
- break;
- default:
- pp_cxx_cast_expression (pp, t);
- break;
- }
- }
- /* multiplicative-expression:
- pm-expression
- multiplicative-expression * pm-expression
- multiplicative-expression / pm-expression
- multiplicative-expression % pm-expression */
- void
- cxx_pretty_printer::multiplicative_expression (tree e)
- {
- enum tree_code code = TREE_CODE (e);
- switch (code)
- {
- case MULT_EXPR:
- case TRUNC_DIV_EXPR:
- case TRUNC_MOD_EXPR:
- multiplicative_expression (TREE_OPERAND (e, 0));
- pp_space (this);
- if (code == MULT_EXPR)
- pp_star (this);
- else if (code == TRUNC_DIV_EXPR)
- pp_slash (this);
- else
- pp_modulo (this);
- pp_space (this);
- pp_cxx_pm_expression (this, TREE_OPERAND (e, 1));
- break;
- default:
- pp_cxx_pm_expression (this, e);
- break;
- }
- }
- /* conditional-expression:
- logical-or-expression
- logical-or-expression ? expression : assignment-expression */
- void
- cxx_pretty_printer::conditional_expression (tree e)
- {
- if (TREE_CODE (e) == COND_EXPR)
- {
- pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
- pp_space (this);
- pp_question (this);
- pp_space (this);
- expression (TREE_OPERAND (e, 1));
- pp_space (this);
- assignment_expression (TREE_OPERAND (e, 2));
- }
- else
- pp_c_logical_or_expression (this, e);
- }
- /* Pretty-print a compound assignment operator token as indicated by T. */
- static void
- pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
- {
- const char *op;
- switch (TREE_CODE (t))
- {
- case NOP_EXPR:
- op = "=";
- break;
- case PLUS_EXPR:
- op = "+=";
- break;
- case MINUS_EXPR:
- op = "-=";
- break;
- case TRUNC_DIV_EXPR:
- op = "/=";
- break;
- case TRUNC_MOD_EXPR:
- op = "%=";
- break;
- default:
- op = get_tree_code_name (TREE_CODE (t));
- break;
- }
- pp_cxx_ws_string (pp, op);
- }
- /* assignment-expression:
- conditional-expression
- logical-or-expression assignment-operator assignment-expression
- throw-expression
- throw-expression:
- throw assignment-expression(opt)
- assignment-operator: one of
- = *= /= %= += -= >>= <<= &= ^= |= */
- void
- cxx_pretty_printer::assignment_expression (tree e)
- {
- switch (TREE_CODE (e))
- {
- case MODIFY_EXPR:
- case INIT_EXPR:
- pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
- pp_space (this);
- pp_equal (this);
- pp_space (this);
- assignment_expression (TREE_OPERAND (e, 1));
- break;
- case THROW_EXPR:
- pp_cxx_ws_string (this, "throw");
- if (TREE_OPERAND (e, 0))
- assignment_expression (TREE_OPERAND (e, 0));
- break;
- case MODOP_EXPR:
- pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
- pp_cxx_assignment_operator (this, TREE_OPERAND (e, 1));
- assignment_expression (TREE_OPERAND (e, 2));
- break;
- default:
- conditional_expression (e);
- break;
- }
- }
- void
- cxx_pretty_printer::expression (tree t)
- {
- switch (TREE_CODE (t))
- {
- case STRING_CST:
- case VOID_CST:
- case INTEGER_CST:
- case REAL_CST:
- case COMPLEX_CST:
- constant (t);
- break;
- case USERDEF_LITERAL:
- pp_cxx_userdef_literal (this, t);
- break;
- case RESULT_DECL:
- pp_cxx_unqualified_id (this, t);
- break;
- #if 0
- case OFFSET_REF:
- #endif
- case SCOPE_REF:
- case PTRMEM_CST:
- pp_cxx_qualified_id (this, t);
- break;
- case OVERLOAD:
- t = OVL_CURRENT (t);
- case VAR_DECL:
- case PARM_DECL:
- case FIELD_DECL:
- case CONST_DECL:
- case FUNCTION_DECL:
- case BASELINK:
- case TEMPLATE_DECL:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_PARM_INDEX:
- case TEMPLATE_TEMPLATE_PARM:
- case STMT_EXPR:
- primary_expression (t);
- break;
- case CALL_EXPR:
- case DYNAMIC_CAST_EXPR:
- case STATIC_CAST_EXPR:
- case REINTERPRET_CAST_EXPR:
- case CONST_CAST_EXPR:
- #if 0
- case MEMBER_REF:
- #endif
- case EMPTY_CLASS_EXPR:
- case TYPEID_EXPR:
- case PSEUDO_DTOR_EXPR:
- case AGGR_INIT_EXPR:
- case ARROW_EXPR:
- postfix_expression (t);
- break;
- case NEW_EXPR:
- case VEC_NEW_EXPR:
- pp_cxx_new_expression (this, t);
- break;
- case DELETE_EXPR:
- case VEC_DELETE_EXPR:
- pp_cxx_delete_expression (this, t);
- break;
- case SIZEOF_EXPR:
- case ALIGNOF_EXPR:
- case NOEXCEPT_EXPR:
- unary_expression (t);
- break;
- case CAST_EXPR:
- case IMPLICIT_CONV_EXPR:
- pp_cxx_cast_expression (this, t);
- break;
- case OFFSET_REF:
- case MEMBER_REF:
- case DOTSTAR_EXPR:
- pp_cxx_pm_expression (this, t);
- break;
- case MULT_EXPR:
- case TRUNC_DIV_EXPR:
- case TRUNC_MOD_EXPR:
- multiplicative_expression (t);
- break;
- case COND_EXPR:
- conditional_expression (t);
- break;
- case MODIFY_EXPR:
- case INIT_EXPR:
- case THROW_EXPR:
- case MODOP_EXPR:
- assignment_expression (t);
- break;
- case NON_DEPENDENT_EXPR:
- case MUST_NOT_THROW_EXPR:
- expression (TREE_OPERAND (t, 0));
- break;
- case EXPR_PACK_EXPANSION:
- expression (PACK_EXPANSION_PATTERN (t));
- pp_cxx_ws_string (this, "...");
- break;
- case TEMPLATE_ID_EXPR:
- pp_cxx_template_id (this, t);
- break;
- case NONTYPE_ARGUMENT_PACK:
- {
- tree args = ARGUMENT_PACK_ARGS (t);
- int i, len = TREE_VEC_LENGTH (args);
- for (i = 0; i < len; ++i)
- {
- if (i > 0)
- pp_cxx_separate_with (this, ',');
- expression (TREE_VEC_ELT (args, i));
- }
- }
- break;
-
- case LAMBDA_EXPR:
- pp_cxx_ws_string (this, "<lambda>");
- break;
- case PAREN_EXPR:
- pp_cxx_left_paren (this);
- expression (TREE_OPERAND (t, 0));
- pp_cxx_right_paren (this);
- break;
- default:
- c_pretty_printer::expression (t);
- break;
- }
- }
- /* Declarations. */
- /* function-specifier:
- inline
- virtual
- explicit */
- void
- cxx_pretty_printer::function_specifier (tree t)
- {
- switch (TREE_CODE (t))
- {
- case FUNCTION_DECL:
- if (DECL_VIRTUAL_P (t))
- pp_cxx_ws_string (this, "virtual");
- else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
- pp_cxx_ws_string (this, "explicit");
- else
- c_pretty_printer::function_specifier (t);
- default:
- break;
- }
- }
- /* decl-specifier-seq:
- decl-specifier-seq(opt) decl-specifier
- decl-specifier:
- storage-class-specifier
- type-specifier
- function-specifier
- friend
- typedef */
- void
- cxx_pretty_printer::declaration_specifiers (tree t)
- {
- switch (TREE_CODE (t))
- {
- case VAR_DECL:
- case PARM_DECL:
- case CONST_DECL:
- case FIELD_DECL:
- storage_class_specifier (t);
- declaration_specifiers (TREE_TYPE (t));
- break;
- case TYPE_DECL:
- pp_cxx_ws_string (this, "typedef");
- declaration_specifiers (TREE_TYPE (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))
- function_specifier (t);
- else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
- declaration_specifiers (TREE_TYPE (TREE_TYPE (t)));
- else
- default:
- c_pretty_printer::declaration_specifiers (t);
- break;
- }
- }
- /* simple-type-specifier:
- ::(opt) nested-name-specifier(opt) type-name
- ::(opt) nested-name-specifier(opt) template(opt) template-id
- char
- wchar_t
- bool
- short
- int
- long
- signed
- unsigned
- float
- double
- void */
- void
- cxx_pretty_printer::simple_type_specifier (tree t)
- {
- switch (TREE_CODE (t))
- {
- case RECORD_TYPE:
- case UNION_TYPE:
- case ENUMERAL_TYPE:
- pp_cxx_qualified_id (this, t);
- break;
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_TEMPLATE_PARM:
- case TEMPLATE_PARM_INDEX:
- case BOUND_TEMPLATE_TEMPLATE_PARM:
- pp_cxx_unqualified_id (this, t);
- break;
- case TYPENAME_TYPE:
- pp_cxx_ws_string (this, "typename");
- pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t));
- pp_cxx_unqualified_id (this, TYPE_NAME (t));
- break;
- default:
- c_pretty_printer::simple_type_specifier (t);
- break;
- }
- }
- /* type-specifier-seq:
- type-specifier type-specifier-seq(opt)
- type-specifier:
- simple-type-specifier
- class-specifier
- enum-specifier
- elaborated-type-specifier
- cv-qualifier */
- static void
- pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
- {
- switch (TREE_CODE (t))
- {
- case TEMPLATE_DECL:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_TEMPLATE_PARM:
- case TYPE_DECL:
- case BOUND_TEMPLATE_TEMPLATE_PARM:
- pp_cxx_cv_qualifier_seq (pp, t);
- pp->simple_type_specifier (t);
- break;
- case METHOD_TYPE:
- pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
- pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
- pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
- break;
- case DECLTYPE_TYPE:
- pp_cxx_ws_string (pp, "decltype");
- pp_cxx_left_paren (pp);
- pp->expression (DECLTYPE_TYPE_EXPR (t));
- pp_cxx_right_paren (pp);
- break;
- case RECORD_TYPE:
- if (TYPE_PTRMEMFUNC_P (t))
- {
- tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
- pp->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm)));
- pp_cxx_whitespace (pp);
- pp_cxx_ptr_operator (pp, t);
- break;
- }
- /* else fall through */
- default:
- if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
- pp_c_specifier_qualifier_list (pp, t);
- }
- }
- /* ptr-operator:
- * cv-qualifier-seq(opt)
- &
- ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
- static void
- pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
- {
- if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
- t = TREE_TYPE (t);
- switch (TREE_CODE (t))
- {
- case REFERENCE_TYPE:
- case POINTER_TYPE:
- if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t)))
- pp_cxx_ptr_operator (pp, TREE_TYPE (t));
- pp_c_attributes_display (pp, TYPE_ATTRIBUTES (TREE_TYPE (t)));
- if (TYPE_PTR_P (t))
- {
- pp_star (pp);
- pp_cxx_cv_qualifier_seq (pp, t);
- }
- else
- pp_ampersand (pp);
- break;
- case RECORD_TYPE:
- if (TYPE_PTRMEMFUNC_P (t))
- {
- pp_cxx_left_paren (pp);
- pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
- pp_star (pp);
- break;
- }
- case OFFSET_TYPE:
- if (TYPE_PTRMEM_P (t))
- {
- if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
- pp_cxx_left_paren (pp);
- pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
- pp_star (pp);
- pp_cxx_cv_qualifier_seq (pp, t);
- break;
- }
- /* else fall through. */
- default:
- pp_unsupported_tree (pp, t);
- break;
- }
- }
- static inline tree
- pp_cxx_implicit_parameter_type (tree mf)
- {
- return class_of_this_parm (TREE_TYPE (mf));
- }
- /*
- parameter-declaration:
- decl-specifier-seq declarator
- decl-specifier-seq declarator = assignment-expression
- decl-specifier-seq abstract-declarator(opt)
- decl-specifier-seq abstract-declarator(opt) assignment-expression */
- static inline void
- pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
- {
- pp->declaration_specifiers (t);
- if (TYPE_P (t))
- pp->abstract_declarator (t);
- else
- pp->declarator (t);
- }
- /* parameter-declaration-clause:
- parameter-declaration-list(opt) ...(opt)
- parameter-declaration-list , ...
- parameter-declaration-list:
- parameter-declaration
- parameter-declaration-list , parameter-declaration */
- static void
- pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
- {
- tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
- tree types =
- TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
- const bool abstract = args == NULL || pp->flags & pp_c_flag_abstract;
- bool first = true;
- /* Skip artificial parameter for nonstatic member functions. */
- if (TREE_CODE (t) == METHOD_TYPE)
- types = TREE_CHAIN (types);
- pp_cxx_left_paren (pp);
- for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
- {
- if (!first)
- pp_cxx_separate_with (pp, ',');
- first = false;
- pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
- if (!abstract && pp->flags & pp_cxx_flag_default_argument)
- {
- pp_cxx_whitespace (pp);
- pp_equal (pp);
- pp_cxx_whitespace (pp);
- pp->assignment_expression (TREE_PURPOSE (types));
- }
- }
- pp_cxx_right_paren (pp);
- }
- /* exception-specification:
- throw ( type-id-list(opt) )
- type-id-list
- type-id
- type-id-list , type-id */
- static void
- pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
- {
- tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
- bool need_comma = false;
- if (ex_spec == NULL)
- return;
- if (TREE_PURPOSE (ex_spec))
- {
- pp_cxx_ws_string (pp, "noexcept");
- pp_cxx_whitespace (pp);
- pp_cxx_left_paren (pp);
- if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec))
- pp_cxx_ws_string (pp, "<uninstantiated>");
- else
- pp->expression (TREE_PURPOSE (ex_spec));
- pp_cxx_right_paren (pp);
- return;
- }
- pp_cxx_ws_string (pp, "throw");
- pp_cxx_left_paren (pp);
- for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
- {
- tree type = TREE_VALUE (ex_spec);
- tree argpack = NULL_TREE;
- int i, len = 1;
- if (ARGUMENT_PACK_P (type))
- {
- argpack = ARGUMENT_PACK_ARGS (type);
- len = TREE_VEC_LENGTH (argpack);
- }
- for (i = 0; i < len; ++i)
- {
- if (argpack)
- type = TREE_VEC_ELT (argpack, i);
- if (need_comma)
- pp_cxx_separate_with (pp, ',');
- else
- need_comma = true;
- pp->type_id (type);
- }
- }
- pp_cxx_right_paren (pp);
- }
- /* direct-declarator:
- declarator-id
- direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
- exception-specification(opt)
- direct-declaration [ constant-expression(opt) ]
- ( declarator ) */
- void
- cxx_pretty_printer::direct_declarator (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 (this, TREE_TYPE (t));
- if ((TREE_CODE (t) == PARM_DECL && DECL_PACK_P (t))
- || template_parameter_pack_p (t))
- /* A function parameter pack or non-type template
- parameter pack. */
- pp_cxx_ws_string (this, "...");
-
- id_expression (DECL_NAME (t));
- }
- abstract_declarator (TREE_TYPE (t));
- break;
- case FUNCTION_DECL:
- pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t)));
- expression (t);
- pp_cxx_parameter_declaration_clause (this, t);
- if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
- {
- padding = pp_before;
- pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t));
- }
- pp_cxx_exception_specification (this, TREE_TYPE (t));
- break;
- case TYPENAME_TYPE:
- case TEMPLATE_DECL:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_PARM_INDEX:
- case TEMPLATE_TEMPLATE_PARM:
- break;
- default:
- c_pretty_printer::direct_declarator (t);
- break;
- }
- }
- /* declarator:
- direct-declarator
- ptr-operator declarator */
- void
- cxx_pretty_printer::declarator (tree t)
- {
- direct_declarator (t);
- }
- /* ctor-initializer:
- : mem-initializer-list
- mem-initializer-list:
- mem-initializer
- mem-initializer , mem-initializer-list
- mem-initializer:
- mem-initializer-id ( expression-list(opt) )
- mem-initializer-id:
- ::(opt) nested-name-specifier(opt) class-name
- identifier */
- static void
- pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
- {
- t = TREE_OPERAND (t, 0);
- pp_cxx_whitespace (pp);
- pp_colon (pp);
- pp_cxx_whitespace (pp);
- for (; t; t = TREE_CHAIN (t))
- {
- tree purpose = TREE_PURPOSE (t);
- bool is_pack = PACK_EXPANSION_P (purpose);
- if (is_pack)
- pp->primary_expression (PACK_EXPANSION_PATTERN (purpose));
- else
- pp->primary_expression (purpose);
- pp_cxx_call_argument_list (pp, TREE_VALUE (t));
- if (is_pack)
- pp_cxx_ws_string (pp, "...");
- if (TREE_CHAIN (t))
- pp_cxx_separate_with (pp, ',');
- }
- }
- /* function-definition:
- decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
- decl-specifier-seq(opt) declarator function-try-block */
- static void
- pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
- {
- tree saved_scope = pp->enclosing_scope;
- pp->declaration_specifiers (t);
- pp->declarator (t);
- pp_needs_newline (pp) = true;
- pp->enclosing_scope = DECL_CONTEXT (t);
- if (DECL_SAVED_TREE (t))
- pp->statement (DECL_SAVED_TREE (t));
- else
- pp_cxx_semicolon (pp);
- pp_newline_and_flush (pp);
- pp->enclosing_scope = saved_scope;
- }
- /* abstract-declarator:
- ptr-operator abstract-declarator(opt)
- direct-abstract-declarator */
- void
- cxx_pretty_printer::abstract_declarator (tree t)
- {
- if (TYPE_PTRMEM_P (t))
- pp_cxx_right_paren (this);
- else if (POINTER_TYPE_P (t))
- {
- if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
- pp_cxx_right_paren (this);
- t = TREE_TYPE (t);
- }
- direct_abstract_declarator (t);
- }
- /* direct-abstract-declarator:
- direct-abstract-declarator(opt) ( parameter-declaration-clause )
- cv-qualifier-seq(opt) exception-specification(opt)
- direct-abstract-declarator(opt) [ constant-expression(opt) ]
- ( abstract-declarator ) */
- void
- cxx_pretty_printer::direct_abstract_declarator (tree t)
- {
- switch (TREE_CODE (t))
- {
- case REFERENCE_TYPE:
- abstract_declarator (t);
- break;
- case RECORD_TYPE:
- if (TYPE_PTRMEMFUNC_P (t))
- direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t));
- break;
- case METHOD_TYPE:
- case FUNCTION_TYPE:
- pp_cxx_parameter_declaration_clause (this, t);
- direct_abstract_declarator (TREE_TYPE (t));
- if (TREE_CODE (t) == METHOD_TYPE)
- {
- padding = pp_before;
- pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t));
- }
- pp_cxx_exception_specification (this, t);
- break;
- case TYPENAME_TYPE:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_TEMPLATE_PARM:
- case BOUND_TEMPLATE_TEMPLATE_PARM:
- case UNBOUND_CLASS_TEMPLATE:
- break;
- default:
- c_pretty_printer::direct_abstract_declarator (t);
- break;
- }
- }
- /* type-id:
- type-specifier-seq abstract-declarator(opt) */
- void
- cxx_pretty_printer::type_id (tree t)
- {
- pp_flags saved_flags = flags;
- flags |= pp_c_flag_abstract;
- switch (TREE_CODE (t))
- {
- case TYPE_DECL:
- case UNION_TYPE:
- case RECORD_TYPE:
- case ENUMERAL_TYPE:
- case TYPENAME_TYPE:
- case BOUND_TEMPLATE_TEMPLATE_PARM:
- case UNBOUND_CLASS_TEMPLATE:
- case TEMPLATE_TEMPLATE_PARM:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_PARM_INDEX:
- case TEMPLATE_DECL:
- case TYPEOF_TYPE:
- case UNDERLYING_TYPE:
- case DECLTYPE_TYPE:
- case TEMPLATE_ID_EXPR:
- pp_cxx_type_specifier_seq (this, t);
- break;
- case TYPE_PACK_EXPANSION:
- type_id (PACK_EXPANSION_PATTERN (t));
- pp_cxx_ws_string (this, "...");
- break;
- default:
- c_pretty_printer::type_id (t);
- break;
- }
- flags = saved_flags;
- }
- /* template-argument-list:
- template-argument ...(opt)
- template-argument-list, template-argument ...(opt)
- template-argument:
- assignment-expression
- type-id
- template-name */
- static void
- pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
- {
- int i;
- bool need_comma = false;
- if (t == NULL)
- return;
- for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
- {
- tree arg = TREE_VEC_ELT (t, i);
- tree argpack = NULL_TREE;
- int idx, len = 1;
- if (ARGUMENT_PACK_P (arg))
- {
- argpack = ARGUMENT_PACK_ARGS (arg);
- len = TREE_VEC_LENGTH (argpack);
- }
- for (idx = 0; idx < len; idx++)
- {
- if (argpack)
- arg = TREE_VEC_ELT (argpack, idx);
-
- if (need_comma)
- pp_cxx_separate_with (pp, ',');
- else
- need_comma = true;
- if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
- && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
- pp->type_id (arg);
- else
- pp->expression (arg);
- }
- }
- }
- static void
- pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
- {
- t = DECL_EXPR_DECL (t);
- pp_cxx_type_specifier_seq (pp, t);
- if (TYPE_P (t))
- pp->abstract_declarator (t);
- else
- pp->declarator (t);
- }
- /* Statements. */
- void
- cxx_pretty_printer::statement (tree t)
- {
- switch (TREE_CODE (t))
- {
- case CTOR_INITIALIZER:
- pp_cxx_ctor_initializer (this, t);
- break;
- case USING_STMT:
- pp_cxx_ws_string (this, "using");
- pp_cxx_ws_string (this, "namespace");
- if (DECL_CONTEXT (t))
- pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t));
- pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t));
- break;
- case USING_DECL:
- pp_cxx_ws_string (this, "using");
- pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t));
- pp_cxx_unqualified_id (this, DECL_NAME (t));
- break;
- case EH_SPEC_BLOCK:
- break;
- /* try-block:
- try compound-statement handler-seq */
- case TRY_BLOCK:
- pp_maybe_newline_and_indent (this, 0);
- pp_cxx_ws_string (this, "try");
- pp_newline_and_indent (this, 3);
- statement (TRY_STMTS (t));
- pp_newline_and_indent (this, -3);
- if (CLEANUP_P (t))
- ;
- else
- statement (TRY_HANDLERS (t));
- break;
- /*
- handler-seq:
- handler handler-seq(opt)
- handler:
- catch ( exception-declaration ) compound-statement
- exception-declaration:
- type-specifier-seq declarator
- type-specifier-seq abstract-declarator
- ... */
- case HANDLER:
- pp_cxx_ws_string (this, "catch");
- pp_cxx_left_paren (this);
- pp_cxx_exception_declaration (this, HANDLER_PARMS (t));
- pp_cxx_right_paren (this);
- pp_indentation (this) += 3;
- pp_needs_newline (this) = true;
- statement (HANDLER_BODY (t));
- pp_indentation (this) -= 3;
- pp_needs_newline (this) = true;
- break;
- /* selection-statement:
- if ( expression ) statement
- if ( expression ) statement else statement */
- case IF_STMT:
- pp_cxx_ws_string (this, "if");
- pp_cxx_whitespace (this);
- pp_cxx_left_paren (this);
- expression (IF_COND (t));
- pp_cxx_right_paren (this);
- pp_newline_and_indent (this, 2);
- statement (THEN_CLAUSE (t));
- pp_newline_and_indent (this, -2);
- if (ELSE_CLAUSE (t))
- {
- tree else_clause = ELSE_CLAUSE (t);
- pp_cxx_ws_string (this, "else");
- if (TREE_CODE (else_clause) == IF_STMT)
- pp_cxx_whitespace (this);
- else
- pp_newline_and_indent (this, 2);
- statement (else_clause);
- if (TREE_CODE (else_clause) != IF_STMT)
- pp_newline_and_indent (this, -2);
- }
- break;
- case SWITCH_STMT:
- pp_cxx_ws_string (this, "switch");
- pp_space (this);
- pp_cxx_left_paren (this);
- expression (SWITCH_STMT_COND (t));
- pp_cxx_right_paren (this);
- pp_indentation (this) += 3;
- pp_needs_newline (this) = true;
- statement (SWITCH_STMT_BODY (t));
- pp_newline_and_indent (this, -3);
- break;
- /* iteration-statement:
- while ( expression ) statement
- do statement while ( expression ) ;
- for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
- for ( declaration expression(opt) ; expression(opt) ) statement */
- case WHILE_STMT:
- pp_cxx_ws_string (this, "while");
- pp_space (this);
- pp_cxx_left_paren (this);
- expression (WHILE_COND (t));
- pp_cxx_right_paren (this);
- pp_newline_and_indent (this, 3);
- statement (WHILE_BODY (t));
- pp_indentation (this) -= 3;
- pp_needs_newline (this) = true;
- break;
- case DO_STMT:
- pp_cxx_ws_string (this, "do");
- pp_newline_and_indent (this, 3);
- statement (DO_BODY (t));
- pp_newline_and_indent (this, -3);
- pp_cxx_ws_string (this, "while");
- pp_space (this);
- pp_cxx_left_paren (this);
- expression (DO_COND (t));
- pp_cxx_right_paren (this);
- pp_cxx_semicolon (this);
- pp_needs_newline (this) = true;
- break;
- case FOR_STMT:
- pp_cxx_ws_string (this, "for");
- pp_space (this);
- pp_cxx_left_paren (this);
- if (FOR_INIT_STMT (t))
- statement (FOR_INIT_STMT (t));
- else
- pp_cxx_semicolon (this);
- pp_needs_newline (this) = false;
- pp_cxx_whitespace (this);
- if (FOR_COND (t))
- expression (FOR_COND (t));
- pp_cxx_semicolon (this);
- pp_needs_newline (this) = false;
- pp_cxx_whitespace (this);
- if (FOR_EXPR (t))
- expression (FOR_EXPR (t));
- pp_cxx_right_paren (this);
- pp_newline_and_indent (this, 3);
- statement (FOR_BODY (t));
- pp_indentation (this) -= 3;
- pp_needs_newline (this) = true;
- break;
- case RANGE_FOR_STMT:
- pp_cxx_ws_string (this, "for");
- pp_space (this);
- pp_cxx_left_paren (this);
- statement (RANGE_FOR_DECL (t));
- pp_space (this);
- pp_needs_newline (this) = false;
- pp_colon (this);
- pp_space (this);
- statement (RANGE_FOR_EXPR (t));
- pp_cxx_right_paren (this);
- pp_newline_and_indent (this, 3);
- statement (FOR_BODY (t));
- pp_indentation (this) -= 3;
- pp_needs_newline (this) = true;
- break;
- /* jump-statement:
- goto identifier;
- continue ;
- return expression(opt) ; */
- case BREAK_STMT:
- case CONTINUE_STMT:
- pp_string (this, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
- pp_cxx_semicolon (this);
- pp_needs_newline (this) = true;
- break;
- /* expression-statement:
- expression(opt) ; */
- case EXPR_STMT:
- expression (EXPR_STMT_EXPR (t));
- pp_cxx_semicolon (this);
- pp_needs_newline (this) = true;
- break;
- case CLEANUP_STMT:
- pp_cxx_ws_string (this, "try");
- pp_newline_and_indent (this, 2);
- statement (CLEANUP_BODY (t));
- pp_newline_and_indent (this, -2);
- pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
- pp_newline_and_indent (this, 2);
- statement (CLEANUP_EXPR (t));
- pp_newline_and_indent (this, -2);
- break;
- case STATIC_ASSERT:
- declaration (t);
- break;
- default:
- c_pretty_printer::statement (t);
- break;
- }
- }
- /* original-namespace-definition:
- namespace identifier { namespace-body }
- As an edge case, we also handle unnamed namespace definition here. */
- static void
- pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
- {
- pp_cxx_ws_string (pp, "namespace");
- if (DECL_CONTEXT (t))
- pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
- if (DECL_NAME (t))
- pp_cxx_unqualified_id (pp, t);
- pp_cxx_whitespace (pp);
- pp_cxx_left_brace (pp);
- /* We do not print the namespace-body. */
- pp_cxx_whitespace (pp);
- pp_cxx_right_brace (pp);
- }
- /* namespace-alias:
- identifier
- namespace-alias-definition:
- namespace identifier = qualified-namespace-specifier ;
- qualified-namespace-specifier:
- ::(opt) nested-name-specifier(opt) namespace-name */
- static void
- pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
- {
- pp_cxx_ws_string (pp, "namespace");
- if (DECL_CONTEXT (t))
- pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
- pp_cxx_unqualified_id (pp, t);
- pp_cxx_whitespace (pp);
- pp_equal (pp);
- pp_cxx_whitespace (pp);
- if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
- pp_cxx_nested_name_specifier (pp,
- DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
- pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
- pp_cxx_semicolon (pp);
- }
- /* simple-declaration:
- decl-specifier-seq(opt) init-declarator-list(opt) */
- static void
- pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
- {
- pp->declaration_specifiers (t);
- pp_cxx_init_declarator (pp, t);
- pp_cxx_semicolon (pp);
- pp_needs_newline (pp) = true;
- }
- /*
- template-parameter-list:
- template-parameter
- template-parameter-list , template-parameter */
- static inline void
- pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
- {
- const int n = TREE_VEC_LENGTH (t);
- int i;
- for (i = 0; i < n; ++i)
- {
- if (i)
- pp_cxx_separate_with (pp, ',');
- pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
- }
- }
- /* template-parameter:
- type-parameter
- parameter-declaration
- type-parameter:
- class ...(opt) identifier(opt)
- class identifier(opt) = type-id
- typename identifier(opt)
- typename ...(opt) identifier(opt) = type-id
- template < template-parameter-list > class ...(opt) identifier(opt)
- template < template-parameter-list > class identifier(opt) = template-name */
- static void
- pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
- {
- tree parameter = TREE_VALUE (t);
- switch (TREE_CODE (parameter))
- {
- case TYPE_DECL:
- pp_cxx_ws_string (pp, "class");
- if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
- pp_cxx_ws_string (pp, "...");
- if (DECL_NAME (parameter))
- pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
- /* FIXME: Check if we should print also default argument. */
- break;
- case PARM_DECL:
- pp_cxx_parameter_declaration (pp, parameter);
- break;
- case TEMPLATE_DECL:
- break;
- default:
- pp_unsupported_tree (pp, t);
- break;
- }
- }
- /* Pretty-print a template parameter in the canonical form
- "template-parameter-<level>-<position in parameter list>". */
- void
- pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
- {
- const enum tree_code code = TREE_CODE (parm);
- /* Brings type template parameters to the canonical forms. */
- if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
- || code == BOUND_TEMPLATE_TEMPLATE_PARM)
- parm = TEMPLATE_TYPE_PARM_INDEX (parm);
- pp_cxx_begin_template_argument_list (pp);
- pp->translate_string ("template-parameter-");
- pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
- pp_minus (pp);
- pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
- pp_cxx_end_template_argument_list (pp);
- }
- /*
- template-declaration:
- export(opt) template < template-parameter-list > declaration */
- static void
- pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
- {
- tree tmpl = most_general_template (t);
- tree level;
- pp_maybe_newline_and_indent (pp, 0);
- for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
- {
- pp_cxx_ws_string (pp, "template");
- pp_cxx_begin_template_argument_list (pp);
- pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
- pp_cxx_end_template_argument_list (pp);
- pp_newline_and_indent (pp, 3);
- }
- if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
- pp_cxx_function_definition (pp, t);
- else
- pp_cxx_simple_declaration (pp, t);
- }
- static void
- pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
- {
- pp_unsupported_tree (pp, t);
- }
- static void
- pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
- {
- pp_unsupported_tree (pp, t);
- }
- /*
- declaration:
- block-declaration
- function-definition
- template-declaration
- explicit-instantiation
- explicit-specialization
- linkage-specification
- namespace-definition
- block-declaration:
- simple-declaration
- asm-definition
- namespace-alias-definition
- using-declaration
- using-directive
- static_assert-declaration */
- void
- cxx_pretty_printer::declaration (tree t)
- {
- if (TREE_CODE (t) == STATIC_ASSERT)
- {
- pp_cxx_ws_string (this, "static_assert");
- pp_cxx_left_paren (this);
- expression (STATIC_ASSERT_CONDITION (t));
- pp_cxx_separate_with (this, ',');
- expression (STATIC_ASSERT_MESSAGE (t));
- pp_cxx_right_paren (this);
- }
- else if (!DECL_LANG_SPECIFIC (t))
- pp_cxx_simple_declaration (this, t);
- else if (DECL_USE_TEMPLATE (t))
- switch (DECL_USE_TEMPLATE (t))
- {
- case 1:
- pp_cxx_template_declaration (this, t);
- break;
- case 2:
- pp_cxx_explicit_specialization (this, t);
- break;
- case 3:
- pp_cxx_explicit_instantiation (this, t);
- break;
- default:
- break;
- }
- else switch (TREE_CODE (t))
- {
- case VAR_DECL:
- case TYPE_DECL:
- pp_cxx_simple_declaration (this, t);
- break;
- case FUNCTION_DECL:
- if (DECL_SAVED_TREE (t))
- pp_cxx_function_definition (this, t);
- else
- pp_cxx_simple_declaration (this, t);
- break;
- case NAMESPACE_DECL:
- if (DECL_NAMESPACE_ALIAS (t))
- pp_cxx_namespace_alias_definition (this, t);
- else
- pp_cxx_original_namespace_definition (this, t);
- break;
- default:
- pp_unsupported_tree (this, t);
- break;
- }
- }
- static void
- pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
- {
- t = TREE_OPERAND (t, 0);
- pp_cxx_ws_string (pp, "typeid");
- pp_cxx_left_paren (pp);
- if (TYPE_P (t))
- pp->type_id (t);
- else
- pp->expression (t);
- pp_cxx_right_paren (pp);
- }
- void
- pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
- {
- pp_cxx_ws_string (pp, "va_arg");
- pp_cxx_left_paren (pp);
- pp->assignment_expression (TREE_OPERAND (t, 0));
- pp_cxx_separate_with (pp, ',');
- pp->type_id (TREE_TYPE (t));
- pp_cxx_right_paren (pp);
- }
- static bool
- pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
- {
- switch (TREE_CODE (t))
- {
- case ARROW_EXPR:
- if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
- && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
- {
- pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
- pp_cxx_separate_with (pp, ',');
- return true;
- }
- return false;
- case COMPONENT_REF:
- if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
- return false;
- if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
- pp_cxx_dot (pp);
- pp->expression (TREE_OPERAND (t, 1));
- return true;
- case ARRAY_REF:
- if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
- return false;
- pp_left_bracket (pp);
- pp->expression (TREE_OPERAND (t, 1));
- pp_right_bracket (pp);
- return true;
- default:
- return false;
- }
- }
- void
- pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
- {
- pp_cxx_ws_string (pp, "offsetof");
- pp_cxx_left_paren (pp);
- if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
- pp->expression (TREE_OPERAND (t, 0));
- pp_cxx_right_paren (pp);
- }
- void
- pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
- {
- cp_trait_kind kind = TRAIT_EXPR_KIND (t);
- switch (kind)
- {
- case CPTK_HAS_NOTHROW_ASSIGN:
- pp_cxx_ws_string (pp, "__has_nothrow_assign");
- break;
- case CPTK_HAS_TRIVIAL_ASSIGN:
- pp_cxx_ws_string (pp, "__has_trivial_assign");
- break;
- case CPTK_HAS_NOTHROW_CONSTRUCTOR:
- pp_cxx_ws_string (pp, "__has_nothrow_constructor");
- break;
- case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
- pp_cxx_ws_string (pp, "__has_trivial_constructor");
- break;
- case CPTK_HAS_NOTHROW_COPY:
- pp_cxx_ws_string (pp, "__has_nothrow_copy");
- break;
- case CPTK_HAS_TRIVIAL_COPY:
- pp_cxx_ws_string (pp, "__has_trivial_copy");
- break;
- case CPTK_HAS_TRIVIAL_DESTRUCTOR:
- pp_cxx_ws_string (pp, "__has_trivial_destructor");
- break;
- case CPTK_HAS_VIRTUAL_DESTRUCTOR:
- pp_cxx_ws_string (pp, "__has_virtual_destructor");
- break;
- case CPTK_IS_ABSTRACT:
- pp_cxx_ws_string (pp, "__is_abstract");
- break;
- case CPTK_IS_BASE_OF:
- pp_cxx_ws_string (pp, "__is_base_of");
- break;
- case CPTK_IS_CLASS:
- pp_cxx_ws_string (pp, "__is_class");
- break;
- case CPTK_IS_EMPTY:
- pp_cxx_ws_string (pp, "__is_empty");
- break;
- case CPTK_IS_ENUM:
- pp_cxx_ws_string (pp, "__is_enum");
- break;
- case CPTK_IS_FINAL:
- pp_cxx_ws_string (pp, "__is_final");
- break;
- case CPTK_IS_POD:
- pp_cxx_ws_string (pp, "__is_pod");
- break;
- case CPTK_IS_POLYMORPHIC:
- pp_cxx_ws_string (pp, "__is_polymorphic");
- break;
- case CPTK_IS_STD_LAYOUT:
- pp_cxx_ws_string (pp, "__is_std_layout");
- break;
- case CPTK_IS_TRIVIAL:
- pp_cxx_ws_string (pp, "__is_trivial");
- break;
- case CPTK_IS_TRIVIALLY_ASSIGNABLE:
- pp_cxx_ws_string (pp, "__is_trivially_assignable");
- break;
- case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
- pp_cxx_ws_string (pp, "__is_trivially_constructible");
- break;
- case CPTK_IS_TRIVIALLY_COPYABLE:
- pp_cxx_ws_string (pp, "__is_trivially_copyable");
- break;
- case CPTK_IS_UNION:
- pp_cxx_ws_string (pp, "__is_union");
- break;
- case CPTK_IS_LITERAL_TYPE:
- pp_cxx_ws_string (pp, "__is_literal_type");
- break;
- default:
- gcc_unreachable ();
- }
- pp_cxx_left_paren (pp);
- pp->type_id (TRAIT_EXPR_TYPE1 (t));
- if (kind == CPTK_IS_BASE_OF)
- {
- pp_cxx_separate_with (pp, ',');
- pp->type_id (TRAIT_EXPR_TYPE2 (t));
- }
- pp_cxx_right_paren (pp);
- }
- typedef c_pretty_print_fn pp_fun;
- /* Initialization of a C++ pretty-printer object. */
- cxx_pretty_printer::cxx_pretty_printer ()
- : c_pretty_printer (),
- enclosing_scope (global_namespace)
- {
- type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
- parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
- }
|