1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2016-2020 Red Hat, Inc.
5 //
6 // Author: Dodji Seketeli
7 
8 /// @file
9 ///
10 /// This contains the private implementation of the suppression engine
11 /// of libabigail.
12 
13 #ifndef __ABG_IR_PRIV_H__
14 #define __ABG_IR_PRIV_H__
15 
16 #include <string>
17 
18 #include "abg-ir.h"
19 
20 namespace abigail
21 {
22 
23 namespace ir
24 {
25 
26 using std::string;
27 
28 /// The internal representation of an integral type.
29 ///
30 /// This is a "utility type" used internally to canonicalize the name
31 /// of fundamental integral types, so that "unsignd long" and "long
32 /// unsined int" end-up having the same name.
33 class integral_type
34 {
35 public:
36   /// The possible base types of integral types.  We might have
37   /// forgotten many of these, so do not hesitate to add new ones.
38   ///
39   /// If you do add new ones, please also consider updating functions
40   /// parse_base_integral_type and integral_type::to_string.
41   enum base_type
42   {
43     /// The "int" base type.
44     INT_BASE_TYPE,
45     /// The "char" base type.
46     CHAR_BASE_TYPE,
47     /// The "bool" base type in C++ or "_Bool" in C11.
48     BOOL_BASE_TYPE,
49     /// The "double" base type.
50     DOUBLE_BASE_TYPE,
51     /// The "float" base type.
52     FLOAT_BASE_TYPE,
53     /// The "char16_t base type.
54     CHAR16_T_BASE_TYPE,
55     /// The "char32_t" base type.
56     CHAR32_T_BASE_TYPE,
57     /// The "wchar_t" base type.
58     WCHAR_T_BASE_TYPE
59   };
60 
61   /// The modifiers of the base types above.  Several modifiers can be
62   /// combined for a given base type.  The presence of modifiers is
63   /// usually modelled by a bitmap of modifiers.
64   ///
65   /// If you add a new modifier, please consider updating functions
66   /// parse_integral_type_modifier and integral_type::to_string.
67   enum modifiers_type
68   {
69     NO_MODIFIER = 0,
70     /// The "signed" modifier.
71     SIGNED_MODIFIER = 1,
72     /// The "unsigned" modier.
73     UNSIGNED_MODIFIER = 1 << 1,
74     /// The "short" modifier.
75     SHORT_MODIFIER = 1 << 2,
76     /// The "long" modifier.
77     LONG_MODIFIER = 1 << 3,
78     /// The "long long" modifier.
79     LONG_LONG_MODIFIER = 1 << 4
80   };
81 
82 private:
83   base_type	base_;
84   modifiers_type modifiers_;
85 
86 public:
87 
88   integral_type();
89   integral_type(const string& name);
90   integral_type(base_type, modifiers_type);
91 
92   base_type
93   get_base_type() const;
94 
95   modifiers_type
96   get_modifiers() const;
97 
98   bool
99   operator==(const integral_type&) const;
100 
101   string
102   to_string() const;
103 
104   operator string() const;
105 }; // end class integral_type
106 
107 integral_type::modifiers_type
108 operator|(integral_type::modifiers_type l, integral_type::modifiers_type r);
109 
110 integral_type::modifiers_type
111 operator&(integral_type::modifiers_type l, integral_type::modifiers_type r);
112 
113 integral_type::modifiers_type&
114 operator|=(integral_type::modifiers_type& l, integral_type::modifiers_type r);
115 
116 bool
117 parse_integral_type(const string& type_name,
118 		    integral_type& type);
119 
120 /// Private type to hold private members of @ref translation_unit
121 struct translation_unit::priv
122 {
123   const environment*				env_;
124   corpus*					corp;
125   bool						is_constructed_;
126   char						address_size_;
127   language					language_;
128   std::string					path_;
129   std::string					comp_dir_path_;
130   std::string					abs_path_;
131   location_manager				loc_mgr_;
132   mutable global_scope_sptr			global_scope_;
133   mutable vector<type_base_sptr>		synthesized_types_;
134   vector<function_type_sptr>			live_fn_types_;
135   type_maps					types_;
136 
137 
privpriv138   priv(const environment* env)
139     : env_(env),
140       corp(),
141       is_constructed_(),
142       address_size_(),
143       language_(LANG_UNKNOWN)
144   {}
145 
~privpriv146   ~priv()
147   {}
148 
149   type_maps&
get_typespriv150   get_types()
151   {return types_;}
152 }; // end translation_unit::priv
153 
154 } // end namespace ir
155 
156 } // end namespace abigail
157 
158 #endif // __ABG_IR_PRIV_H__
159 
160