3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
17 /* The location of the scop, as delimited by scop and endscop
18 * pragmas by the user.
19 * "start_line" is the line number of the start position.
29 /* Compare two RecordDecl pointers based on their names.
32 bool operator()(const clang::RecordDecl
*x
,
33 const clang::RecordDecl
*y
) {
34 return x
->getNameAsString().compare(y
->getNameAsString()) < 0;
38 /* A sorted set of RecordDecl pointers. The actual order is not important,
39 * only that it is consistent across platforms.
41 typedef std::set
<clang::RecordDecl
*, less_name
> lex_recorddecl_set
;
44 clang::Preprocessor
&PP
;
45 clang::ASTContext
&ast_context
;
46 /* If autodetect is false, then loc contains the location
47 * of the scop to be extracted.
52 /* Set if the pet_scop returned by an extract method only
53 * represents part of the input tree.
57 /* A cache of size expressions for array types as computed
58 * by PetScan::get_array_size.
60 std::map
<const clang::Type
*, pet_expr
*> type_size
;
62 /* A union of mappings of the form
63 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
65 isl_union_map
*value_bounds
;
67 /* The line number of the previously considered Stmt. */
69 /* The line number of the Stmt currently being considered. */
70 unsigned current_line
;
72 PetScan(clang::Preprocessor
&PP
,
73 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
74 pet_options
*options
, __isl_take isl_union_map
*value_bounds
) :
75 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
76 ast_context(ast_context
), loc(loc
),
77 options(options
), value_bounds(value_bounds
),
78 partial(false), last_line(0), current_line(0) { }
82 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
84 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
85 clang::IntegerLiteral
*expr
);
86 __isl_give pet_expr
*get_array_size(const clang::Type
*type
);
87 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
88 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
90 void set_current_stmt(clang::Stmt
*stmt
);
92 struct pet_scop
*scan(clang::Stmt
*stmt
);
94 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
95 __isl_keep pet_context
*pc
);
96 struct pet_array
*extract_array(isl_ctx
*ctx
,
97 std::vector
<clang::ValueDecl
*> decls
,
98 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
99 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
100 const clang::Type
*type
, int pos
);
101 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
102 const clang::Type
*type
, __isl_keep pet_context
*pc
);
104 __isl_give pet_tree
*extract(clang::Stmt
*stmt
,
105 bool skip_declarations
= false);
106 __isl_give pet_tree
*extract(clang::StmtRange stmt_range
, bool block
,
107 bool skip_declarations
);
108 __isl_give pet_tree
*extract(clang::IfStmt
*stmt
);
109 __isl_give pet_tree
*extract(clang::WhileStmt
*stmt
);
110 __isl_give pet_tree
*extract(clang::CompoundStmt
*stmt
,
111 bool skip_declarations
= false);
112 __isl_give pet_tree
*extract(clang::LabelStmt
*stmt
);
113 __isl_give pet_tree
*extract(clang::DeclStmt
*expr
);
115 __isl_give pet_loc
*construct_pet_loc(clang::SourceRange range
,
117 __isl_give pet_tree
*extract(__isl_take pet_expr
*expr
,
118 clang::SourceRange range
, bool skip_semi
);
119 __isl_give pet_tree
*update_loc(__isl_take pet_tree
*tree
,
122 struct pet_scop
*extract_scop(__isl_take pet_tree
*tree
);
124 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
125 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
126 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
127 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
129 __isl_give pet_expr
*extract_unary_increment(clang::UnaryOperator
*op
,
130 clang::ValueDecl
*iv
);
131 __isl_give pet_expr
*extract_binary_increment(
132 clang::BinaryOperator
*op
,
133 clang::ValueDecl
*iv
);
134 __isl_give pet_expr
*extract_compound_increment(
135 clang::CompoundAssignOperator
*op
,
136 clang::ValueDecl
*iv
);
137 __isl_give pet_expr
*extract_increment(clang::ForStmt
*stmt
,
138 clang::ValueDecl
*iv
);
139 __isl_give pet_tree
*extract_for(clang::ForStmt
*stmt
);
141 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
142 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
144 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
145 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
146 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
147 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
148 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
149 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
150 __isl_give pet_expr
*extract_expr(clang::EnumConstantDecl
*expr
);
151 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
152 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
153 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
154 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
155 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
157 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
158 __isl_take pet_expr
*index
);
159 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
160 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
162 __isl_give pet_expr
*extract_index_expr(
163 clang::ArraySubscriptExpr
*expr
);
164 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
165 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
166 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
167 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
168 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
170 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
171 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
173 void report(clang::Stmt
*stmt
, unsigned id
);
174 void unsupported(clang::Stmt
*stmt
);
175 void report_prototype_required(clang::Stmt
*stmt
);
176 void report_missing_increment(clang::Stmt
*stmt
);