• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Google LLC
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 //     https://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 SANDBOXED_API_TOOLS_CLANG_GENERATOR_EMITTER_H_
16 #define SANDBOXED_API_TOOLS_CLANG_GENERATOR_EMITTER_H_
17 
18 #include <string>
19 #include <vector>
20 
21 #include "absl/status/status.h"
22 #include "absl/status/statusor.h"
23 #include "clang/AST/Decl.h"
24 #include "clang/AST/Type.h"
25 #include "sandboxed_api/tools/clang_generator/emitter_base.h"
26 
27 namespace sapi {
28 
29 // Forward declaration to avoid circular dependencies.
30 struct GeneratorOptions;
31 
32 // Responsible for emitting the actual textual representation of the generated
33 // Sandboxed API header.
34 class Emitter : public EmitterBase {
35  public:
36   // Adds a function to the list of functions to be rendered. In addition, it
37   // stores the original and SAPI function information for safe drop-in
38   // generation.
39   absl::Status AddFunction(clang::FunctionDecl* decl) override;
40 
41   // Outputs a formatted header for a list of functions and their related types.
42   absl::StatusOr<std::string> EmitHeader(const GeneratorOptions& options);
43 
44  protected:
45   // Rendered function bodies, as a vector to preserve source order. This is
46   // not strictly necessary, but makes the output look less surprising.
47   std::vector<std::string> rendered_functions_ordered_;
48 };
49 
50 }  // namespace sapi
51 
52 #endif  // SANDBOXED_API_TOOLS_CLANG_GENERATOR_EMITTER_H_
53