10void ASTDumper::print_type(
const Expr &e)
const
13 out <<
" of type " << *e.
type();
14 if (
auto pt = cast<const PrimitiveType>(e.
type()))
15 out << (pt->is_scalar() ?
" scalar" :
" vectorial");
21void ASTDumper::operator()(Const<ErrorExpr> &e)
23 indent() <<
"ErrorExpr '" << e.tok.text <<
"' (" << e.tok.pos <<
')';
26void ASTDumper::operator()(Const<Designator> &e)
28 if (e.has_explicit_table_name()) {
32 indent() <<
"table name '" << e.table_name.text <<
"' (" << e.table_name.pos <<
')';
33 indent() <<
"attribute name '" << e.attr_name.text <<
"' (" << e.attr_name.pos <<
')';
36 indent() <<
"Identifier '" << e.attr_name.text <<
'\'';
37 if (e.has_table_name())
out <<
" deduced to table '" << e.get_table_name() <<
'\'';
39 out <<
" (" << e.attr_name.pos <<
')';
43void ASTDumper::operator()(Const<Constant> &e)
45 indent() <<
"Constant " << e.tok.text;
46 if (e.has_type())
out <<
" of type " << *e.type();
47 out <<
" (" << e.tok.pos <<
')';
50void ASTDumper::operator()(Const<FnApplicationExpr> &e)
52 indent() <<
"FnApplicationExpr";
56 if (not e.args.empty()) {
59 for (
auto &expr : e.args)
66void ASTDumper::operator()(Const<UnaryExpr> &e)
68 indent() <<
"UnaryExpr '" << e.op().text <<
"'";
70 out <<
" (" << e.op().pos <<
')';
76void ASTDumper::operator()(Const<BinaryExpr> &e)
78 indent() <<
"BinaryExpr '" << e.op().text <<
"'";
80 out <<
" (" << e.op().pos <<
')';
87void ASTDumper::operator()(Const<QueryExpr> &e)
99void ASTDumper::operator()(Const<ErrorClause> &c)
101 indent() <<
"ErrorClause '" << c.tok.text <<
"' (" << c.tok.pos <<
')';
104void ASTDumper::operator()(Const<SelectClause> &c)
106 indent() <<
"SelectClause (" << c.tok.pos <<
')';
109 indent() <<
"* (" << c.select_all.pos <<
')';
110 for (
auto &s : c.select) {
112 indent() <<
"AS '" << s.second.text <<
"' (" << s.second.pos <<
')';
123void ASTDumper::operator()(Const<FromClause> &c)
125 indent() <<
"FromClause (" << c.tok.pos <<
')';
127 for (
auto f : c.from) {
129 indent() <<
"AS '" << f.alias.text <<
"' (" << f.alias.pos <<
')';
131 if (
auto tok = std::get_if<Token>(&f.source)) {
132 indent() << tok->text <<
" (" << tok->pos <<
')';
133 }
else if (
auto stmt = std::get_if<Stmt*>(&f.source)) {
140 M_insist(std::holds_alternative<Token>(f.source),
"nested statements require an alias");
141 Token &tok = std::get<Token>(f.source);
148void ASTDumper::operator()(Const<WhereClause> &c)
150 indent() <<
"WhereClause (" << c.tok.pos <<
')';
157void ASTDumper::operator()(Const<GroupByClause> &c)
159 indent() <<
"GroupByClause (" << c.tok.pos <<
')';
161 for (
auto &[expr, alias] : c.group_by) {
163 indent() <<
"AS '" << alias.text <<
"' (" << alias.pos <<
')';
171void ASTDumper::operator()(Const<HavingClause> &c)
173 indent() <<
"HavingClause (" << c.tok.pos <<
')';
179void ASTDumper::operator()(Const<OrderByClause> &c)
181 indent() <<
"OrderByClause (" << c.tok.pos <<
')';
183 for (
auto &o : c.order_by) {
184 indent() << (o.second ?
"ASC" :
"DESC");
192void ASTDumper::operator()(Const<LimitClause> &c)
194 indent() <<
"LimitClause (" << c.tok.pos <<
')';
197 indent() <<
"LIMIT " << c.limit.text <<
" (" << c.limit.pos <<
')';
200 indent() <<
"OFFSET " << c.offset.text <<
" (" << c.offset.pos <<
')';
208void ASTDumper::operator()(Const<PrimaryKeyConstraint> &c)
210 indent() <<
"PrimaryKeyConstraint (" << c.tok.pos <<
')';
213void ASTDumper::operator()(Const<UniqueConstraint> &c)
215 indent() <<
"UniqueConstraint (" << c.tok.pos <<
')';
218void ASTDumper::operator()(Const<NotNullConstraint> &c)
220 indent() <<
"NotNullConstraint (" << c.tok.pos <<
')';
223void ASTDumper::operator()(Const<CheckConditionConstraint> &c)
225 indent() <<
"CheckConditionConstraint (" << c.tok.pos <<
')';
231void ASTDumper::operator()(Const<ReferenceConstraint> &c)
233 indent() <<
"ReferenceConstraint (" << c.tok.pos <<
')';
235 indent() << c.table_name.text <<
'(' << c.attr_name.text <<
')';
242void ASTDumper::operator()(Const<Instruction> &inst)
244 out <<
"Instruction(" << inst.name;
245 for (
auto &arg : inst.args)
253void ASTDumper::operator()(Const<ErrorStmt> &s)
255 indent() <<
"ErrorStmt: '" << s.tok.text <<
"' (" << s.tok.pos <<
')';
258void ASTDumper::operator()(Const<EmptyStmt> &s)
260 indent() <<
"EmptyStmt: '" << s.tok.text <<
"' (" << s.tok.pos <<
')';
263void ASTDumper::operator()(Const<CreateDatabaseStmt> &s)
265 indent() <<
"CreateDatabaseStmt: '" << s.database_name.text <<
"' (" << s.database_name.pos <<
')';
268void ASTDumper::operator()(Const<DropDatabaseStmt> &s)
270 indent() <<
"DropDatabaseStmt: '" << s.database_name.text <<
"' (" << s.database_name.pos <<
')';
273 indent() <<
"if exists: true";
277void ASTDumper::operator()(Const<UseDatabaseStmt> &s)
279 indent() <<
"UseDatabaseStmt: '" << s.database_name.text <<
"' (" << s.database_name.pos <<
')';
282void ASTDumper::operator()(Const<CreateTableStmt> &s)
284 indent() <<
"CreateTableStmt: table " << s.table_name.text <<
" (" << s.table_name.pos <<
')';
288 for (
auto &attr : s.attributes) {
289 indent() << attr->name.text <<
" : " << *attr->type <<
" (" << attr->name.pos <<
')';
291 for (
auto &c : attr->constraints) {
292 if (is<PrimaryKeyConstraint>(c)) {
293 indent() <<
"PRIMARY KEY (" << c->tok.pos <<
')';
294 }
else if (is<UniqueConstraint>(c)) {
295 indent() <<
"UNIQUE (" << c->tok.pos <<
')';
296 }
else if (is<NotNullConstraint>(c)) {
297 indent() <<
"NOT NULL (" << c->tok.pos <<
')';
298 }
else if (
auto check = cast<CheckConditionConstraint>(c.get())) {
299 indent() <<
"CHECK (" << c->tok.pos <<
')';
301 (*this)(*check->cond);
303 }
else if (
auto ref = cast<ReferenceConstraint>(c.get())) {
304 indent() <<
"REFERENCES " << ref->table_name.text <<
'(' << ref->attr_name.text <<
") (" << c->tok.pos
316void ASTDumper::operator()(Const<DropTableStmt> &s)
318 indent() <<
"DropTableStmt:";
322 for (
auto &table_name : s.table_names)
323 indent() << table_name->text <<
" (" << table_name->pos <<
')';
326 indent() <<
"if exists: true";
330void ASTDumper::operator()(Const<CreateIndexStmt> &s)
332 indent() <<
"CreateIndexStmt:";
336 indent() <<
"unique: true";
337 if (s.has_if_not_exists)
338 indent() <<
"if not exists: true";
340 indent() <<
"index name: " << s.index_name.text;
342 indent() <<
"method: " << s.method.text;
344 indent() <<
"table name: " << s.table_name.text;
347 for (
auto &expr : s.key_fields) (*this)(*expr);
352void ASTDumper::operator()(Const<DropIndexStmt> &s)
354 indent() <<
"DropIndexStmt:";
358 indent() <<
"if exists: true";
362 for (
auto &idx : s.index_names)
indent() << (*idx).text;
368void ASTDumper::operator()(Const<SelectStmt> &s)
375 if (s.from) (*this)(*s.from);
376 if (s.where) (*this)(*s.where);
377 if (s.group_by) (*this)(*s.group_by);
378 if (s.having) (*this)(*s.having);
379 if (s.order_by) (*this)(*s.order_by);
380 if (s.limit) (*this)(*s.limit);
385void ASTDumper::operator()(Const<InsertStmt> &s)
387 indent() <<
"InsertStmt: table " << s.table_name.text <<
" (" << s.table_name.pos <<
')';
391 for (std::size_t idx = 0, end = s.tuples.size(); idx != end; ++idx) {
392 indent() <<
'[' << idx <<
']';
416void ASTDumper::operator()(Const<UpdateStmt> &s)
418 indent() <<
"UpdateStmt: table " << s.table_name.text <<
" (" << s.table_name.pos <<
')';
422 for (
auto &s : s.set) {
423 indent() << s.first.text <<
" (" << s.first.pos <<
')';
430 if (s.where) (*this)(*s.where);
435void ASTDumper::operator()(Const<DeleteStmt> &s)
437 indent() <<
"DeleteStmt: table " << s.table_name.text <<
" (" << s.table_name.pos <<
')';
446void ASTDumper::operator()(Const<DSVImportStmt> &s)
448 indent() <<
"ImportStmt (DSV): table " << s.table_name.text <<
" (" << s.table_name.pos <<
')';
451 indent() << s.path.text <<
" (" << s.path.pos <<
')';
453 indent() <<
"rows " << s.rows.text <<
" (" << s.rows.pos <<
')';
455 indent() <<
"delimiter " << s.delimiter.text <<
" (" << s.delimiter.pos <<
')';
459 indent() <<
"SKIP HEADER";
#define M_unreachable(MSG)
std::ostream & indent(std::ostream &out, unsigned indentation)
Start a new line with proper indentation.
int indent_
the current level of indentation
std::ostream & out
the output stream to write to
bool has_type() const
Returns true iff this Expr has been assigned a Type, most likely by Sema.
const Type * type() const
Returns the Type of this Expr.
std::vector< element_type > tuple_t
ThreadSafePooledOptionalString text
declared as optional for dummy tokens