xref: /aosp_15_r20/external/tensorflow/tensorflow/c/experimental/ops/gen/common/source_code.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
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 #ifndef TENSORFLOW_C_EXPERIMENTAL_OPS_GEN_COMMON_SOURCE_CODE_H_
16 #define TENSORFLOW_C_EXPERIMENTAL_OPS_GEN_COMMON_SOURCE_CODE_H_
17 
18 #include "tensorflow/core/platform/types.h"
19 
20 namespace tensorflow {
21 namespace generator {
22 
23 class SourceCode {
24  public:
25   string Render() const;
SetSpacesPerIndent(int spaces_per_indent)26   void SetSpacesPerIndent(int spaces_per_indent) {
27     spaces_per_indent_ = spaces_per_indent;
28   }
29 
30   void AddLineWithIndent(const string &line);
31   void AddLineWithoutIndent(const string &line);
32   void AddBlankLine();
33   void IncreaseIndent();
34   void DecreaseIndent();
35 
36  private:
37   struct Line {
38     int indent;
39     string text;
40   };
41 
42   void ValidateAndAddLine(int indent_level, const string &raw_line);
43 
44   int spaces_per_indent_ = 2;
45   int current_indent_ = 0;
46   std::vector<Line> lines_;
47 };
48 
49 }  // namespace generator
50 }  // namespace tensorflow
51 
52 #endif  // TENSORFLOW_C_EXPERIMENTAL_OPS_GEN_COMMON_SOURCE_CODE_H_
53