clang_generator: Access type collector/function via accessors

PiperOrigin-RevId: 490476261
Change-Id: Icbd51d3792c33dcfb185ec0514118a095135b3f6
This commit is contained in:
Christian Blichmann 2022-11-23 05:20:47 -08:00 committed by Copybara-Service
parent 13c5b564b6
commit 37ca6d0fc6
2 changed files with 9 additions and 8 deletions

View File

@ -90,9 +90,9 @@ void GeneratorASTConsumer::HandleTranslationUnit(clang::ASTContext& context) {
return; return;
} }
emitter_.AddTypeDeclarations(visitor_.collector_.GetTypeDeclarations()); // TODO(cblichmann): Move below to emit all functions after traversing TUs.
emitter_.AddTypeDeclarations(visitor_.collector().GetTypeDeclarations());
for (clang::FunctionDecl* func : visitor_.functions_) { for (clang::FunctionDecl* func : visitor_.functions()) {
absl::Status status = emitter_.AddFunction(func); absl::Status status = emitter_.AddFunction(func);
if (!status.ok()) { if (!status.ok()) {
clang::SourceLocation loc = clang::SourceLocation loc =

View File

@ -64,13 +64,15 @@ class GeneratorASTVisitor
bool VisitTypeDecl(clang::TypeDecl* decl); bool VisitTypeDecl(clang::TypeDecl* decl);
bool VisitFunctionDecl(clang::FunctionDecl* decl); bool VisitFunctionDecl(clang::FunctionDecl* decl);
TypeCollector& collector() { return collector_; }
const std::vector<clang::FunctionDecl*>& functions() const {
return functions_;
}
private: private:
friend class GeneratorASTConsumer;
TypeCollector collector_; TypeCollector collector_;
std::vector<clang::FunctionDecl*> functions_; std::vector<clang::FunctionDecl*> functions_;
const GeneratorOptions& options_; const GeneratorOptions& options_;
}; };
@ -85,7 +87,6 @@ class GeneratorASTConsumer : public clang::ASTConsumer {
std::string in_file_; std::string in_file_;
GeneratorASTVisitor visitor_; GeneratorASTVisitor visitor_;
Emitter& emitter_; Emitter& emitter_;
}; };