MCPcopy Create free account
hub / github.com/Samsung/UTopia / isCStyleStruct

Function isCStyleStruct

lib/utils/ASTUtil.cpp:206–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206bool isCStyleStruct(const clang::RecordDecl &D) {
207
208 // 1. Can be called without any arguments.
209 // 2. Has no private members.
210 if (!llvm::isa<clang::CXXRecordDecl>(&D))
211 return true;
212 auto &CRD = *llvm::dyn_cast<clang::CXXRecordDecl>(&D);
213
214 for (auto *Field : CRD.fields()) {
215 assert(Field && "Unexpected Program State");
216
217 if (Field->getAccess() != clang::AS_public)
218 return false;
219 }
220
221 bool HasNoParamConstructor = false;
222 if (CRD.getDefinition())
223 HasNoParamConstructor = CRD.hasDefaultConstructor();
224
225 for (auto *Method : CRD.methods()) {
226 assert(Method && "Unexpected Program State");
227
228 if (Method->getAccess() != clang::AS_public)
229 return false;
230
231 if (!llvm::isa<clang::CXXConstructorDecl>(Method))
232 continue;
233 auto &CRD = *llvm::dyn_cast<clang::CXXConstructorDecl>(Method);
234
235 if (CRD.getNumParams() == 0)
236 HasNoParamConstructor = true;
237 }
238
239 return HasNoParamConstructor;
240}
241
242bool isCStyleStruct(const clang::TagDecl &D) {
243

Callers

nothing calls this directly

Calls 1

getDefinitionMethod · 0.80

Tested by

no test coverage detected