1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 #include "rust-hir-dump.h"
24 Dump::Dump (std::ostream
&stream
) : stream (stream
), indent (0) {}
27 Dump::go (HIR::Crate
&crate
)
35 stream
<< std::string (indent
, indent_char
);
36 stream
<< "inner_attrs"
40 for (auto &attr
: crate
.inner_attrs
)
41 stream
<< attr
.as_string ();
47 stream
<< std::string (indent
, indent_char
);
55 stream
<< std::string (indent
, indent_char
);
56 for (const auto &item
: crate
.items
)
59 item
->accept_vis (*this);
61 stream
<< std::string (indent
, indent_char
);
68 stream
<< std::string (indent
, indent_char
);
69 stream
<< "node_mappings"
73 // TODO: print crate mapping attrs
74 stream
<< "]" << std::endl
;
77 stream
<< "}" << std::endl
;
81 Dump::visit (Lifetime
&)
84 Dump::visit (LifetimeParam
&)
87 Dump::visit (PathInExpression
&)
90 Dump::visit (TypePathSegment
&)
93 Dump::visit (TypePathSegmentGeneric
&)
96 Dump::visit (TypePathSegmentFunction
&)
99 Dump::visit (TypePath
&)
102 Dump::visit (QualifiedPathInExpression
&)
105 Dump::visit (QualifiedPathInType
&)
109 Dump::visit (LiteralExpr
&literal_expr
)
112 stream
<< std::string (indent
, indent_char
);
113 stream
<< "( " + literal_expr
.get_literal ().as_string () + " ("
114 + literal_expr
.get_mappings ().as_string () + "))";
118 Dump::visit (BorrowExpr
&)
121 Dump::visit (DereferenceExpr
&)
124 Dump::visit (ErrorPropagationExpr
&)
127 Dump::visit (NegationExpr
&)
130 Dump::visit (ArithmeticOrLogicalExpr
&)
133 Dump::visit (ComparisonExpr
&)
136 Dump::visit (LazyBooleanExpr
&)
139 Dump::visit (TypeCastExpr
&)
142 Dump::visit (AssignmentExpr
&)
145 Dump::visit (CompoundAssignmentExpr
&)
148 Dump::visit (GroupedExpr
&)
152 Dump::visit (ArrayElemsValues
&)
155 Dump::visit (ArrayElemsCopied
&)
158 Dump::visit (ArrayExpr
&)
161 Dump::visit (ArrayIndexExpr
&)
164 Dump::visit (TupleExpr
&)
167 Dump::visit (TupleIndexExpr
&)
170 Dump::visit (StructExprStruct
&)
174 Dump::visit (StructExprFieldIdentifier
&)
177 Dump::visit (StructExprFieldIdentifierValue
&)
181 Dump::visit (StructExprFieldIndexValue
&)
184 Dump::visit (StructExprStructFields
&)
187 Dump::visit (StructExprStructBase
&)
191 Dump::visit (CallExpr
&)
194 Dump::visit (MethodCallExpr
&)
197 Dump::visit (FieldAccessExpr
&)
200 Dump::visit (ClosureExpr
&)
203 Dump::visit (BlockExpr
&)
205 stream
<< "BlockExpr"
210 // TODO: print statements
211 // TODO: print tail expression if exists
217 Dump::visit (ContinueExpr
&)
220 Dump::visit (BreakExpr
&)
223 Dump::visit (RangeFromToExpr
&)
226 Dump::visit (RangeFromExpr
&)
229 Dump::visit (RangeToExpr
&)
232 Dump::visit (RangeFullExpr
&)
235 Dump::visit (RangeFromToInclExpr
&)
238 Dump::visit (RangeToInclExpr
&)
241 Dump::visit (ReturnExpr
&)
244 Dump::visit (UnsafeBlockExpr
&)
247 Dump::visit (LoopExpr
&)
250 Dump::visit (WhileLoopExpr
&)
253 Dump::visit (WhileLetLoopExpr
&)
256 Dump::visit (ForLoopExpr
&)
259 Dump::visit (IfExpr
&)
262 Dump::visit (IfExprConseqElse
&)
265 Dump::visit (IfExprConseqIf
&)
268 Dump::visit (IfExprConseqIfLet
&)
271 Dump::visit (IfLetExpr
&)
274 Dump::visit (IfLetExprConseqElse
&)
277 Dump::visit (IfLetExprConseqIf
&)
280 Dump::visit (IfLetExprConseqIfLet
&)
284 Dump::visit (MatchExpr
&)
287 Dump::visit (AwaitExpr
&)
290 Dump::visit (AsyncBlockExpr
&)
294 Dump::visit (TypeParam
&)
298 Dump::visit (ConstGenericParam
&)
302 Dump::visit (LifetimeWhereClauseItem
&)
305 Dump::visit (TypeBoundWhereClauseItem
&)
308 Dump::visit (Module
&)
311 Dump::visit (ExternCrate
&)
315 Dump::visit (UseTreeGlob
&)
318 Dump::visit (UseTreeList
&)
321 Dump::visit (UseTreeRebind
&)
324 Dump::visit (UseDeclaration
&)
327 Dump::visit (Function
&)
330 stream
<< std::string (indent
, indent_char
);
333 stream
<< "{" << std::endl
;
334 // TODO: print function params
335 stream
<< std::string (indent
, indent_char
);
336 stream
<< "}" << std::endl
;
337 // TODO: get function definition and visit block
343 Dump::visit (TypeAlias
&)
346 Dump::visit (StructStruct
&)
349 Dump::visit (TupleStruct
&)
352 Dump::visit (EnumItem
&)
355 Dump::visit (EnumItemTuple
&)
358 Dump::visit (EnumItemStruct
&)
361 Dump::visit (EnumItemDiscriminant
&)
367 Dump::visit (Union
&)
370 Dump::visit (ConstantItem
&)
373 Dump::visit (StaticItem
&)
376 Dump::visit (TraitItemFunc
&)
379 Dump::visit (TraitItemConst
&)
382 Dump::visit (TraitItemType
&)
385 Dump::visit (Trait
&)
388 Dump::visit (ImplBlock
&)
392 Dump::visit (ExternalStaticItem
&)
395 Dump::visit (ExternalFunctionItem
&)
398 Dump::visit (ExternBlock
&)
402 Dump::visit (LiteralPattern
&)
405 Dump::visit (IdentifierPattern
&)
408 Dump::visit (WildcardPattern
&)
412 Dump::visit (RangePatternBoundLiteral
&)
415 Dump::visit (RangePatternBoundPath
&)
418 Dump::visit (RangePatternBoundQualPath
&)
421 Dump::visit (RangePattern
&)
424 Dump::visit (ReferencePattern
&)
428 Dump::visit (StructPatternFieldTuplePat
&)
431 Dump::visit (StructPatternFieldIdentPat
&)
434 Dump::visit (StructPatternFieldIdent
&)
437 Dump::visit (StructPattern
&)
441 Dump::visit (TupleStructItemsNoRange
&)
444 Dump::visit (TupleStructItemsRange
&)
447 Dump::visit (TupleStructPattern
&)
451 Dump::visit (TuplePatternItemsMultiple
&)
454 Dump::visit (TuplePatternItemsRanged
&)
457 Dump::visit (TuplePattern
&)
460 Dump::visit (SlicePattern
&)
464 Dump::visit (EmptyStmt
&)
467 Dump::visit (LetStmt
&)
470 Dump::visit (ExprStmtWithoutBlock
&)
473 Dump::visit (ExprStmtWithBlock
&)
477 Dump::visit (TraitBound
&)
480 Dump::visit (ImplTraitType
&)
483 Dump::visit (TraitObjectType
&)
486 Dump::visit (ParenthesisedType
&)
489 Dump::visit (ImplTraitTypeOneBound
&)
492 Dump::visit (TupleType
&)
495 Dump::visit (NeverType
&)
498 Dump::visit (RawPointerType
&)
501 Dump::visit (ReferenceType
&)
504 Dump::visit (ArrayType
&)
507 Dump::visit (SliceType
&)
510 Dump::visit (InferredType
&)
513 Dump::visit (BareFunctionType
&)