@@ -60,8 +60,16 @@ __typeof__ (lang_check_failed) lang_check_failed __attribute__ ((weak));
6060
6161__typeof__ (decl_as_string ) decl_as_string __attribute__ ((weak ));
6262
63- /* Similar for namespace_binding: */
63+ /* Similar for namespace_binding, though gcc 8's r247654 (aka
64+ f906dcc33dd818b71e16c88cef38f33c161070db) replaced it with
65+ get_namespace_value and reversed the order of the params
66+ and r247745 (aka 9d79db401edbb9665cde47ddea2702671c89e548)
67+ renamed it from get_namespace_value to get_namespace_binding. */
68+ #if (GCC_VERSION >= 8000 )
69+ __typeof__ (get_namespace_binding ) get_namespace_binding __attribute__ ((weak ));
70+ #else
6471__typeof__ (namespace_binding ) namespace_binding __attribute__ ((weak ));
72+ #endif
6573
6674/* And for cp_namespace_decls: */
6775__typeof__ (cp_namespace_decls ) cp_namespace_decls __attribute__ ((weak ));
@@ -678,13 +686,32 @@ PyGccConstructor_get_elements(PyObject *self, void *closure)
678686 return NULL ;
679687}
680688
689+ #if (GCC_VERSION >= 5000 )
690+
691+ static void
692+ print_integer_cst_to_buf (tree int_cst , char * buf , tree type )
693+ {
694+ /*
695+ GCC 8 commit r253595 (aka e3d0f65c14ffd7a63455dc1aa9d0405d25b327e4,
696+ 2017-10-10) introduces and requires the use of wi::to_wide on
697+ INTEGER_CST.
698+ */
699+ #if (GCC_VERSION >= 8000 )
700+ print_dec (wi ::to_wide (int_cst ), buf , TYPE_SIGN (type ));
701+ #else
702+ print_dec (int_cst , buf , TYPE_SIGN (type ));
703+ #endif
704+ }
705+
706+ #endif /* #if (GCC_VERSION >= 5000) */
707+
681708PyObject *
682709PyGcc_int_from_int_cst (tree int_cst )
683710{
684711 tree type = TREE_TYPE (int_cst );
685712#if (GCC_VERSION >= 5000 )
686713 char buf [WIDE_INT_PRINT_BUFFER_SIZE ];
687- print_dec (int_cst , buf , TYPE_SIGN ( type ) );
714+ print_integer_cst_to_buf (int_cst , buf , type );
688715 return PyGcc_int_from_decimal_string_buffer (buf );
689716#else
690717 return PyGcc_int_from_double_int (TREE_INT_CST (int_cst ),
@@ -704,7 +731,7 @@ PyGccIntegerConstant_repr(struct PyGccTree * self)
704731 tree type = TREE_TYPE (self -> t .inner );
705732#if (GCC_VERSION >= 5000 )
706733 char buf [WIDE_INT_PRINT_BUFFER_SIZE ];
707- print_dec (self -> t .inner , buf , TYPE_SIGN ( type ) );
734+ print_integer_cst_to_buf (self -> t .inner , buf , type );
708735#else
709736 char buf [512 ];
710737 PyGcc_DoubleIntAsText (TREE_INT_CST (self -> t .inner ),
@@ -931,13 +958,22 @@ PyGccNamespaceDecl_lookup(struct PyGccTree * self, PyObject *args, PyObject *kwa
931958 return NULL ;
932959 }
933960
961+ #if (GCC_VERSION >= 8000 )
962+ if (NULL == get_namespace_binding ) {
963+ #else
934964 if (NULL == namespace_binding ) {
965+ #endif
935966 return raise_cplusplus_only ("gcc.NamespaceDecl.lookup" );
936967 }
937968
938969 t_name = get_identifier (name );
939970
971+ #if (GCC_VERSION >= 8000 )
972+ t_result = get_namespace_binding (self -> t .inner , t_name );
973+ #else
940974 t_result = namespace_binding (t_name , self -> t .inner );
975+ #endif
976+
941977 return PyGccTree_New (gcc_private_make_tree (t_result ));
942978}
943979
@@ -980,6 +1016,16 @@ PyGccNamespaceDecl_declarations(tree t)
9801016 return PyGcc_TreeListFromChain (cp_namespace_decls (t ));
9811017}
9821018
1019+ #if (GCC_VERSION >= 8000 )
1020+
1021+ static int is_namespace (tree decl , void * )
1022+ {
1023+ return (TREE_CODE (decl ) == NAMESPACE_DECL
1024+ && !DECL_NAMESPACE_ALIAS (decl ));
1025+ }
1026+
1027+ #endif /* #if (GCC_VERSION >= 8000) */
1028+
9831029PyObject *
9841030PyGccNamespaceDecl_namespaces (tree t )
9851031{
@@ -993,7 +1039,57 @@ PyGccNamespaceDecl_namespaces(tree t)
9931039 if (DECL_NAMESPACE_ALIAS (t ))
9941040 return raise_namespace_alias ("gcc.NamespaceDecl.namespaces" );
9951041
1042+ /* GCC 8's r248821 (aka f7564df45462679c3b0b82f2942f5fb50b640113)
1043+ eliminated the "namespaces" field from cp_binding_level. */
1044+
1045+ #if (GCC_VERSION >= 8000 )
1046+ return PyGcc_TreeListFromChainWithFilter (NAMESPACE_LEVEL (t )-> names ,
1047+ is_namespace , NULL );
1048+ #else
9961049 return PyGcc_TreeListFromChain (NAMESPACE_LEVEL (t )-> namespaces );
1050+ #endif
1051+ }
1052+
1053+ /* Accessing the fields and methods of compound types.
1054+ GCC 8's r250413 (aka ab87ee8f509c0b600102195704105d4d98ec59d9)
1055+ eliminated TYPE_METHODS, instead putting both fields and methods
1056+ on the TYPE_FIELDS chain, using DECL_DECLARES_FUNCTION_P to
1057+ distinguish them. */
1058+
1059+ #if (GCC_VERSION >= 8000 )
1060+
1061+ static int is_field (tree t , void * )
1062+ {
1063+ return !DECL_DECLARES_FUNCTION_P (t );
1064+ }
1065+
1066+ static int is_method (tree t , void * )
1067+ {
1068+ return DECL_DECLARES_FUNCTION_P (t );
1069+ }
1070+
1071+ #endif /* #if (GCC_VERSION >= 8000) */
1072+
1073+ PyObject *
1074+ PyGcc_GetFields (struct PyGccTree * self )
1075+ {
1076+ #if (GCC_VERSION >= 8000 )
1077+ return PyGcc_TreeListFromChainWithFilter (TYPE_FIELDS (self -> t .inner ),
1078+ is_field , NULL );
1079+ #else
1080+ return PyGcc_TreeListFromChain (TYPE_FIELDS (self -> t .inner ));
1081+ #endif
1082+ }
1083+
1084+ PyObject *
1085+ PyGcc_GetMethods (struct PyGccTree * self )
1086+ {
1087+ #if (GCC_VERSION >= 8000 )
1088+ return PyGcc_TreeListFromChainWithFilter (TYPE_FIELDS (self -> t .inner ),
1089+ is_method , NULL );
1090+ #else
1091+ return PyGcc_TreeListFromChain (TYPE_METHODS (self -> t .inner ));
1092+ #endif
9971093}
9981094
9991095/*
@@ -1104,6 +1200,44 @@ PyGcc_TreeListFromChain(tree t)
11041200 return NULL ;
11051201}
11061202
1203+ /* As above, but only add nodes for which "filter" returns true. */
1204+ PyObject *
1205+ PyGcc_TreeListFromChainWithFilter (tree t ,
1206+ int (* filter ) (tree , void * ),
1207+ void * user_data )
1208+ {
1209+ PyObject * result = NULL ;
1210+
1211+ result = PyList_New (0 );
1212+ if (!result ) {
1213+ goto error ;
1214+ }
1215+
1216+ while (t ) {
1217+ if (filter (t , user_data )) {
1218+ PyObject * item ;
1219+
1220+ item = PyGccTree_New (gcc_private_make_tree (t ));
1221+ if (!item ) {
1222+ goto error ;
1223+ }
1224+ if (-1 == PyList_Append (result , item )) {
1225+ Py_DECREF (item );
1226+ goto error ;
1227+ }
1228+ Py_DECREF (item );
1229+ }
1230+
1231+ t = TREE_CHAIN (t );
1232+ }
1233+
1234+ return result ;
1235+
1236+ error :
1237+ Py_XDECREF (result );
1238+ return NULL ;
1239+ }
1240+
11071241/*
11081242 As above, but expect nodes of the form:
11091243 tree_list ---> value
0 commit comments