1 /*
2  * Copyright (c) Huawei Device Co., Ltd. 2021-2024. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "srcDump.h"
17 
18 #include <ir/astNode.h>
19 
20 #include <cmath>
21 #include <iostream>
22 
23 namespace ark::es2panda::ir {
24 
SrcDumper(const ir::AstNode *node)25 SrcDumper::SrcDumper(const ir::AstNode *node)
26 {
27     node->Dump(this);
28 }
29 
IncrIndent()30 void SrcDumper::IncrIndent()
31 {
32     indent_.push_back(' ');
33     indent_.push_back(' ');
34 }
35 
DecrIndent()36 void SrcDumper::DecrIndent()
37 {
38     if (indent_.size() >= 2U) {
39         indent_.pop_back();
40         indent_.pop_back();
41     }
42 }
43 
Endl(size_t num)44 void SrcDumper::Endl(size_t num)
45 {
46     while (num != 0U) {
47         ss_ << std::endl;
48         --num;
49     }
50     ss_ << indent_;
51 }
52 
Add(const std::string &str)53 void SrcDumper::Add(const std::string &str)
54 {
55     ss_ << str;
56 }
57 
Add(int32_t i)58 void SrcDumper::Add(int32_t i)
59 {
60     ss_ << i;
61 }
62 
Add(int64_t l)63 void SrcDumper::Add(int64_t l)
64 {
65     ss_ << l;
66 }
67 
Add(float f)68 void SrcDumper::Add(float f)
69 {
70     ss_ << f;
71 }
72 
Add(double d)73 void SrcDumper::Add(double d)
74 {
75     ss_ << d;
76 }
77 }  // namespace ark::es2panda::ir
78