extract enum constants as their integer values
[pet.git] / scan.h
blob8d5cfa91415221528aa599ed91861ad8fffb5246
1 #include <map>
3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
8 #include <isl/ctx.h>
9 #include <isl/map.h>
10 #include <isl/val.h>
12 #include "context.h"
13 #include "loc.h"
14 #include "scop.h"
15 #include "tree.h"
17 /* The location of the scop, as delimited by scop and endscop
18 * pragmas by the user.
20 struct ScopLoc {
21 ScopLoc() : end(0) {}
23 unsigned start;
24 unsigned end;
27 /* Compare two RecordDecl pointers based on their names.
29 struct less_name {
30 bool operator()(const clang::RecordDecl *x,
31 const clang::RecordDecl *y) {
32 return x->getNameAsString().compare(y->getNameAsString()) < 0;
36 /* A sorted set of RecordDecl pointers. The actual order is not important,
37 * only that it is consistent across platforms.
39 typedef std::set<clang::RecordDecl *, less_name> lex_recorddecl_set;
41 struct PetScan {
42 clang::Preprocessor &PP;
43 clang::ASTContext &ast_context;
44 /* If autodetect is false, then loc contains the location
45 * of the scop to be extracted.
47 ScopLoc &loc;
48 isl_ctx *ctx;
49 pet_options *options;
50 /* Set if the pet_scop returned by an extract method only
51 * represents part of the input tree.
53 bool partial;
55 /* A cache of size expressions for array types as computed
56 * by PetScan::get_array_size.
58 std::map<const clang::Type *, pet_expr *> type_size;
60 /* A union of mappings of the form
61 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
63 isl_union_map *value_bounds;
65 PetScan(clang::Preprocessor &PP,
66 clang::ASTContext &ast_context, ScopLoc &loc,
67 pet_options *options, __isl_take isl_union_map *value_bounds) :
68 ctx(isl_union_map_get_ctx(value_bounds)), PP(PP),
69 ast_context(ast_context), loc(loc),
70 options(options), value_bounds(value_bounds),
71 partial(false) { }
73 ~PetScan();
75 struct pet_scop *scan(clang::FunctionDecl *fd);
77 static __isl_give isl_val *extract_int(isl_ctx *ctx,
78 clang::IntegerLiteral *expr);
79 __isl_give pet_expr *get_array_size(const clang::Type *type);
80 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl,
81 lex_recorddecl_set *types, __isl_keep pet_context *pc);
82 private:
83 struct pet_scop *scan(clang::Stmt *stmt);
85 struct pet_scop *scan_arrays(struct pet_scop *scop,
86 __isl_keep pet_context *pc);
87 struct pet_array *extract_array(isl_ctx *ctx,
88 std::vector<clang::ValueDecl *> decls,
89 lex_recorddecl_set *types, __isl_keep pet_context *pc);
90 __isl_give pet_expr *set_upper_bounds(__isl_take pet_expr *expr,
91 const clang::Type *type, int pos);
92 struct pet_array *set_upper_bounds(struct pet_array *array,
93 const clang::Type *type, __isl_keep pet_context *pc);
95 __isl_give pet_tree *extract(clang::Stmt *stmt,
96 bool skip_declarations = false);
97 __isl_give pet_tree *extract(clang::StmtRange stmt_range, bool block,
98 bool skip_declarations);
99 __isl_give pet_tree *extract(clang::IfStmt *stmt);
100 __isl_give pet_tree *extract(clang::WhileStmt *stmt);
101 __isl_give pet_tree *extract(clang::CompoundStmt *stmt,
102 bool skip_declarations = false);
103 __isl_give pet_tree *extract(clang::LabelStmt *stmt);
104 __isl_give pet_tree *extract(clang::DeclStmt *expr);
106 __isl_give pet_loc *construct_pet_loc(clang::SourceRange range,
107 bool skip_semi);
108 __isl_give pet_tree *extract(__isl_take pet_expr *expr,
109 clang::SourceRange range, bool skip_semi);
110 __isl_give pet_tree *update_loc(__isl_take pet_tree *tree,
111 clang::Stmt *stmt);
113 struct pet_scop *extract_scop(__isl_take pet_tree *tree);
115 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
116 clang::Decl *initialization_declaration(clang::Stmt *init);
117 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
118 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
119 clang::Decl *stmt);
120 __isl_give pet_expr *extract_unary_increment(clang::UnaryOperator *op,
121 clang::ValueDecl *iv);
122 __isl_give pet_expr *extract_binary_increment(
123 clang::BinaryOperator *op,
124 clang::ValueDecl *iv);
125 __isl_give pet_expr *extract_compound_increment(
126 clang::CompoundAssignOperator *op,
127 clang::ValueDecl *iv);
128 __isl_give pet_expr *extract_increment(clang::ForStmt *stmt,
129 clang::ValueDecl *iv);
130 __isl_give pet_tree *extract_for(clang::ForStmt *stmt);
132 __isl_give pet_expr *extract_assume(clang::Expr *expr);
133 __isl_give pet_expr *extract_argument(clang::FunctionDecl *fd, int pos,
134 clang::Expr *expr);
135 __isl_give pet_expr *extract_expr(const llvm::APInt &val);
136 __isl_give pet_expr *extract_expr(clang::Expr *expr);
137 __isl_give pet_expr *extract_expr(clang::UnaryOperator *expr);
138 __isl_give pet_expr *extract_expr(clang::BinaryOperator *expr);
139 __isl_give pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
140 __isl_give pet_expr *extract_expr(clang::IntegerLiteral *expr);
141 __isl_give pet_expr *extract_expr(clang::EnumConstantDecl *expr);
142 __isl_give pet_expr *extract_expr(clang::FloatingLiteral *expr);
143 __isl_give pet_expr *extract_expr(clang::ParenExpr *expr);
144 __isl_give pet_expr *extract_expr(clang::ConditionalOperator *expr);
145 __isl_give pet_expr *extract_expr(clang::CallExpr *expr);
146 __isl_give pet_expr *extract_expr(clang::CStyleCastExpr *expr);
148 __isl_give pet_expr *extract_access_expr(clang::QualType qt,
149 __isl_take pet_expr *index);
150 __isl_give pet_expr *extract_access_expr(clang::Expr *expr);
151 __isl_give pet_expr *extract_access_expr(clang::ValueDecl *decl);
153 __isl_give pet_expr *extract_index_expr(
154 clang::ArraySubscriptExpr *expr);
155 __isl_give pet_expr *extract_index_expr(clang::Expr *expr);
156 __isl_give pet_expr *extract_index_expr(clang::ImplicitCastExpr *expr);
157 __isl_give pet_expr *extract_index_expr(clang::DeclRefExpr *expr);
158 __isl_give pet_expr *extract_index_expr(clang::ValueDecl *decl);
159 __isl_give pet_expr *extract_index_expr(clang::MemberExpr *expr);
161 __isl_give isl_val *extract_int(clang::Expr *expr);
162 __isl_give isl_val *extract_int(clang::ParenExpr *expr);
164 void report(clang::Stmt *stmt, unsigned id);
165 void unsupported(clang::Stmt *stmt);
166 void report_prototype_required(clang::Stmt *stmt);
167 void report_missing_increment(clang::Stmt *stmt);