From 0ec375ea3953dd85b576b71b70b4d46cd4bb4637 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 25 Jan 2015 20:58:12 +0100 Subject: [PATCH] PetScan::scan_arrays: store record types into new PetTypes object This will allow us to keep track of record types and typedefs in the same object in a subsequent commit. Signed-off-by: Sven Verdoolaege --- scan.cc | 23 ++++++++++++----------- scan.h | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/scan.cc b/scan.cc index 1f02087..e79ce35 100644 --- a/scan.cc +++ b/scan.cc @@ -2299,7 +2299,7 @@ static bool has_printable_definition(RecordDecl *decl) * then we replace it by "". */ struct pet_array *PetScan::extract_array(isl_ctx *ctx, ValueDecl *decl, - lex_recorddecl_set *types, __isl_keep pet_context *pc) + PetTypes *types, __isl_keep pet_context *pc) { struct pet_array *array; QualType qt = get_array_type(decl); @@ -2358,8 +2358,7 @@ struct pet_array *PetScan::extract_array(isl_ctx *ctx, ValueDecl *decl, * Additionally, keep track of all required types in "types". */ struct pet_array *PetScan::extract_array(isl_ctx *ctx, - vector decls, lex_recorddecl_set *types, - __isl_keep pet_context *pc) + vector decls, PetTypes *types, __isl_keep pet_context *pc) { struct pet_array *array; vector::iterator it; @@ -2402,7 +2401,7 @@ struct pet_array *PetScan::extract_array(isl_ctx *ctx, } /* Add a pet_type corresponding to "decl" to "scop", provided - * it is a member of "types" and it has not been added before + * it is a member of types.records and it has not been added before * (i.e., it is not a member of "types_done"). * * Since we want the user to be able to print the types @@ -2412,14 +2411,14 @@ struct pet_array *PetScan::extract_array(isl_ctx *ctx, * on the types of all record subfields. */ static struct pet_scop *add_type(isl_ctx *ctx, struct pet_scop *scop, - RecordDecl *decl, Preprocessor &PP, lex_recorddecl_set &types, + RecordDecl *decl, Preprocessor &PP, PetTypes &types, lex_recorddecl_set &types_done) { string s; llvm::raw_string_ostream S(s); RecordDecl::field_iterator it; - if (types.find(decl) == types.end()) + if (types.records.find(decl) == types.records.end()) return scop; if (types_done.find(decl) != types_done.end()) return scop; @@ -2467,10 +2466,10 @@ static struct pet_scop *add_type(isl_ctx *ctx, struct pet_scop *scop, struct pet_scop *PetScan::scan_arrays(struct pet_scop *scop, __isl_keep pet_context *pc) { - int i; + int i, n; array_desc_set arrays; array_desc_set::iterator it; - lex_recorddecl_set types; + PetTypes types; lex_recorddecl_set types_done; lex_recorddecl_set::iterator types_it; int n_array; @@ -2504,14 +2503,16 @@ struct pet_scop *PetScan::scan_arrays(struct pet_scop *scop, goto error; } - if (types.size() == 0) + n = types.records.size(); + if (n == 0) return scop; - scop->types = isl_alloc_array(ctx, struct pet_type *, types.size()); + scop->types = isl_alloc_array(ctx, struct pet_type *, n); if (!scop->types) goto error; - for (types_it = types.begin(); types_it != types.end(); ++types_it) + for (types_it = types.records.begin(); + types_it != types.records.end(); ++types_it) scop = add_type(ctx, scop, *types_it, PP, types, types_done); return scop; diff --git a/scan.h b/scan.h index 489cf4e..61f61df 100644 --- a/scan.h +++ b/scan.h @@ -51,6 +51,18 @@ struct less_name { */ typedef std::set lex_recorddecl_set; +/* The PetTypes structure collects a set of RecordDecl pointers. + * The pointers are sorted using a fixed order. The actual order + * is not important, only that it is consistent across platforms. + */ +struct PetTypes { + std::set records; + + void insert(clang::RecordDecl *decl) { + records.insert(decl); + } +}; + struct PetScan { clang::Preprocessor &PP; clang::ASTContext &ast_context; @@ -105,7 +117,7 @@ struct PetScan { clang::IntegerLiteral *expr); __isl_give pet_expr *get_array_size(const clang::Type *type); struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl, - lex_recorddecl_set *types, __isl_keep pet_context *pc); + PetTypes *types, __isl_keep pet_context *pc); private: void set_current_stmt(clang::Stmt *stmt); bool is_current_stmt_marked_independent(); @@ -116,7 +128,7 @@ private: __isl_keep pet_context *pc); struct pet_array *extract_array(isl_ctx *ctx, std::vector decls, - lex_recorddecl_set *types, __isl_keep pet_context *pc); + PetTypes *types, __isl_keep pet_context *pc); __isl_give pet_expr *set_upper_bounds(__isl_take pet_expr *expr, const clang::Type *type, int pos); struct pet_array *set_upper_bounds(struct pet_array *array, -- 2.11.4.GIT