From a0f511bfbc55d1e7dbf4e295b8e63a5f42fc8749 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 31 Jan 2015 17:04:59 +0100 Subject: [PATCH] scan.cc: add_type: extract out add_field_types We will be able to reuse this function when we start keeping track of typedefs. Signed-off-by: Sven Verdoolaege --- scan.cc | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/scan.cc b/scan.cc index 35280e5..afc42cd 100644 --- a/scan.cc +++ b/scan.cc @@ -2400,6 +2400,32 @@ struct pet_array *PetScan::extract_array(isl_ctx *ctx, return array; } +static struct pet_scop *add_type(isl_ctx *ctx, struct pet_scop *scop, + RecordDecl *decl, Preprocessor &PP, PetTypes &types, + std::set &types_done); + +/* For each of the fields of "decl" that is itself a record type, + * add a corresponding pet_type to "scop". + */ +static struct pet_scop *add_field_types(isl_ctx *ctx, struct pet_scop *scop, + RecordDecl *decl, Preprocessor &PP, PetTypes &types, + std::set &types_done) +{ + RecordDecl::field_iterator it; + + for (it = decl->field_begin(); it != decl->field_end(); ++it) { + RecordDecl *record; + QualType type = it->getType(); + + if (!type->isRecordType()) + continue; + record = pet_clang_record_decl(type); + scop = add_type(ctx, scop, record, PP, types, types_done); + } + + return scop; +} + /* Add a pet_type corresponding to "decl" to "scop", provided * it is a member of types.records and it has not been added before * (i.e., it is not a member of "types_done"). @@ -2408,7 +2434,7 @@ struct pet_array *PetScan::extract_array(isl_ctx *ctx, * in the order in which they appear in the scop, we need to * make sure that types of fields in a structure appear before * that structure. We therefore call ourselves recursively - * on the types of all record subfields. + * through add_field_types on the types of all record subfields. */ static struct pet_scop *add_type(isl_ctx *ctx, struct pet_scop *scop, RecordDecl *decl, Preprocessor &PP, PetTypes &types, @@ -2416,22 +2442,13 @@ static struct pet_scop *add_type(isl_ctx *ctx, struct pet_scop *scop, { string s; llvm::raw_string_ostream S(s); - RecordDecl::field_iterator it; if (types.records.find(decl) == types.records.end()) return scop; if (types_done.find(decl) != types_done.end()) return scop; - for (it = decl->field_begin(); it != decl->field_end(); ++it) { - RecordDecl *record; - QualType type = it->getType(); - - if (!type->isRecordType()) - continue; - record = pet_clang_record_decl(type); - scop = add_type(ctx, scop, record, PP, types, types_done); - } + add_field_types(ctx, scop, decl, PP, types, types_done); if (strlen(decl->getName().str().c_str()) == 0) return scop; -- 2.11.4.GIT