7
7
// ===----------------------------------------------------------------------===//
8
8
#include " clang/Frontend/LayoutOverrideSource.h"
9
9
#include " clang/AST/Decl.h"
10
- #include " clang/AST/DeclCXX.h"
11
10
#include " clang/Basic/CharInfo.h"
12
11
#include " llvm/Support/raw_ostream.h"
13
12
#include < fstream>
@@ -27,18 +26,6 @@ static std::string parseName(StringRef S) {
27
26
return S.substr (0 , Offset).str ();
28
27
}
29
28
30
- // / Parse an unsigned integer and move S to the next non-digit character.
31
- static bool parseUnsigned (StringRef &S, unsigned long long &ULL) {
32
- if (S.empty () || !isDigit (S[0 ]))
33
- return false ;
34
- unsigned Idx = 1 ;
35
- while (Idx < S.size () && isDigit (S[Idx]))
36
- ++Idx;
37
- (void )S.substr (0 , Idx).getAsInteger (10 , ULL);
38
- S = S.substr (Idx);
39
- return true ;
40
- }
41
-
42
29
LayoutOverrideSource::LayoutOverrideSource (StringRef Filename) {
43
30
std::ifstream Input (Filename.str ().c_str ());
44
31
if (!Input.is_open ())
@@ -93,8 +80,8 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
93
80
LineStr = LineStr.substr (Pos + strlen (" Size:" ));
94
81
95
82
unsigned long long Size = 0 ;
96
- if ( parseUnsigned ( LineStr, Size))
97
- CurrentLayout.Size = Size;
83
+ ( void ) LineStr. getAsInteger ( 10 , Size);
84
+ CurrentLayout.Size = Size;
98
85
continue ;
99
86
}
100
87
@@ -105,22 +92,21 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
105
92
LineStr = LineStr.substr (Pos + strlen (" Alignment:" ));
106
93
107
94
unsigned long long Alignment = 0 ;
108
- if ( parseUnsigned ( LineStr, Alignment))
109
- CurrentLayout.Align = Alignment;
95
+ ( void ) LineStr. getAsInteger ( 10 , Alignment);
96
+ CurrentLayout.Align = Alignment;
110
97
continue ;
111
98
}
112
99
113
- // Check for the size/alignment of the type. The number follows "size=" or
114
- // "align=" indicates number of bytes.
100
+ // Check for the size/alignment of the type.
115
101
Pos = LineStr.find (" sizeof=" );
116
102
if (Pos != StringRef::npos) {
117
103
/* Skip past the sizeof= prefix. */
118
104
LineStr = LineStr.substr (Pos + strlen (" sizeof=" ));
119
105
120
106
// Parse size.
121
107
unsigned long long Size = 0 ;
122
- if ( parseUnsigned ( LineStr, Size))
123
- CurrentLayout.Size = Size * 8 ;
108
+ ( void ) LineStr. getAsInteger ( 10 , Size);
109
+ CurrentLayout.Size = Size;
124
110
125
111
Pos = LineStr.find (" align=" );
126
112
if (Pos != StringRef::npos) {
@@ -129,59 +115,34 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
129
115
130
116
// Parse alignment.
131
117
unsigned long long Alignment = 0 ;
132
- if ( parseUnsigned ( LineStr, Alignment))
133
- CurrentLayout.Align = Alignment * 8 ;
118
+ ( void ) LineStr. getAsInteger ( 10 , Alignment);
119
+ CurrentLayout.Align = Alignment;
134
120
}
135
121
136
122
continue ;
137
123
}
138
124
139
125
// Check for the field offsets of the type.
140
126
Pos = LineStr.find (" FieldOffsets: [" );
141
- if (Pos != StringRef::npos) {
142
- LineStr = LineStr.substr (Pos + strlen (" FieldOffsets: [" ));
143
- while (!LineStr.empty () && isDigit (LineStr[0 ])) {
144
- unsigned long long Offset = 0 ;
145
- if (parseUnsigned (LineStr, Offset))
146
- CurrentLayout.FieldOffsets .push_back (Offset);
147
-
148
- // Skip over this offset, the following comma, and any spaces.
149
- LineStr = LineStr.substr (1 );
150
- while (!LineStr.empty () && isWhitespace (LineStr[0 ]))
151
- LineStr = LineStr.substr (1 );
152
- }
153
- }
127
+ if (Pos == StringRef::npos)
128
+ continue ;
154
129
155
- // Check for the base offsets.
156
- Pos = LineStr.find (" BaseOffsets: [" );
157
- if (Pos != StringRef::npos) {
158
- LineStr = LineStr.substr (Pos + strlen (" BaseOffsets: [" ));
159
- while (!LineStr.empty () && isDigit (LineStr[0 ])) {
160
- unsigned long long Offset = 0 ;
161
- if (parseUnsigned (LineStr, Offset))
162
- CurrentLayout.BaseOffsets .push_back (CharUnits::fromQuantity (Offset));
130
+ LineStr = LineStr.substr (Pos + strlen (" FieldOffsets: [" ));
131
+ while (!LineStr.empty () && isDigit (LineStr[0 ])) {
132
+ // Parse this offset.
133
+ unsigned Idx = 1 ;
134
+ while (Idx < LineStr.size () && isDigit (LineStr[Idx]))
135
+ ++Idx;
163
136
164
- // Skip over this offset, the following comma, and any spaces.
165
- LineStr = LineStr.substr (1 );
166
- while (!LineStr.empty () && isWhitespace (LineStr[0 ]))
167
- LineStr = LineStr.substr (1 );
168
- }
169
- }
137
+ unsigned long long Offset = 0 ;
138
+ (void )LineStr.substr (0 , Idx).getAsInteger (10 , Offset);
170
139
171
- // Check for the virtual base offsets.
172
- Pos = LineStr.find (" VBaseOffsets: [" );
173
- if (Pos != StringRef::npos) {
174
- LineStr = LineStr.substr (Pos + strlen (" VBaseOffsets: [" ));
175
- while (!LineStr.empty () && isDigit (LineStr[0 ])) {
176
- unsigned long long Offset = 0 ;
177
- if (parseUnsigned (LineStr, Offset))
178
- CurrentLayout.VBaseOffsets .push_back (CharUnits::fromQuantity (Offset));
140
+ CurrentLayout.FieldOffsets .push_back (Offset);
179
141
180
- // Skip over this offset, the following comma, and any spaces.
142
+ // Skip over this offset, the following comma, and any spaces.
143
+ LineStr = LineStr.substr (Idx + 1 );
144
+ while (!LineStr.empty () && isWhitespace (LineStr[0 ]))
181
145
LineStr = LineStr.substr (1 );
182
- while (!LineStr.empty () && isWhitespace (LineStr[0 ]))
183
- LineStr = LineStr.substr (1 );
184
- }
185
146
}
186
147
}
187
148
@@ -221,24 +182,6 @@ LayoutOverrideSource::layoutRecordType(const RecordDecl *Record,
221
182
if (NumFields != Known->second .FieldOffsets .size ())
222
183
return false ;
223
184
224
- // Provide base offsets.
225
- if (const auto *RD = dyn_cast<CXXRecordDecl>(Record)) {
226
- unsigned NumNB = 0 ;
227
- unsigned NumVB = 0 ;
228
- for (const auto &I : RD->vbases ()) {
229
- if (NumVB >= Known->second .VBaseOffsets .size ())
230
- continue ;
231
- const CXXRecordDecl *VBase = I.getType ()->getAsCXXRecordDecl ();
232
- VirtualBaseOffsets[VBase] = Known->second .VBaseOffsets [NumVB++];
233
- }
234
- for (const auto &I : RD->bases ()) {
235
- if (I.isVirtual () || NumNB >= Known->second .BaseOffsets .size ())
236
- continue ;
237
- const CXXRecordDecl *Base = I.getType ()->getAsCXXRecordDecl ();
238
- BaseOffsets[Base] = Known->second .BaseOffsets [NumNB++];
239
- }
240
- }
241
-
242
185
Size = Known->second .Size ;
243
186
Alignment = Known->second .Align ;
244
187
return true ;
0 commit comments