kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/indexer/textproto/analyzer.h (about)

     1  /*
     2   * Copyright 2019 The Kythe Authors. All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *   http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  #ifndef KYTHE_CXX_INDEXER_TEXTPROTO_ANALYZER_H_
    18  #define KYTHE_CXX_INDEXER_TEXTPROTO_ANALYZER_H_
    19  
    20  #include <cstdio>
    21  #include <string>
    22  
    23  #include "absl/functional/function_ref.h"
    24  #include "absl/status/status.h"
    25  #include "kythe/cxx/common/indexing/KytheGraphRecorder.h"
    26  #include "kythe/proto/analysis.pb.h"
    27  #include "plugin.h"
    28  
    29  namespace kythe {
    30  namespace lang_textproto {
    31  
    32  // The canonical name for the textproto language in Kythe.
    33  extern const absl::string_view kLanguageName;
    34  
    35  /// Analyzes the textproto file(s) described by @unit and emits graph facts to
    36  /// @recorder.
    37  ///
    38  /// The basic indexing flow is as follows:
    39  /// * Build a DescriptorPool from all protos in the compilation unit.
    40  /// * Find the descriptor for the textproto's main message by name.
    41  /// * Construct an empty message instance from the descriptor.
    42  /// * Parse the textproto into our empty message using TextFormat::Parser with
    43  ///   locations recorded to a ParseInfoTree. The parser uses the DescriptorPool
    44  ///   to lookup field descriptors and extensions.
    45  /// * For each field in the descriptor, see if the ParseInfoTree saw one in the
    46  ///   input. If so, add an anchor node and associate it with the proto
    47  ///   descriptor with a “ref” edge.
    48  /// * Repeat the above step recursively for any fields that are messages.
    49  ///
    50  /// \param unit The compilation unit specifying the textproto and the
    51  /// protos that define its schema.
    52  /// \param file_data The file contents of the textproto and relevant protos.
    53  /// \param The name of the message type that defines the schema for the
    54  /// textproto file (including namespace).
    55  absl::Status AnalyzeCompilationUnit(const proto::CompilationUnit& unit,
    56                                      const std::vector<proto::FileData>& files,
    57                                      KytheGraphRecorder* recorder);
    58  
    59  // Callback function to instantiate plugins for a given proto message.
    60  using PluginLoadCallback =
    61      absl::FunctionRef<std::vector<std::unique_ptr<Plugin>>(
    62          const google::protobuf::Message& proto)>;
    63  
    64  // Override for AnalyzeCompilationUnit() that accepts a PluginLoadCallback for
    65  // loading plugins.
    66  absl::Status AnalyzeCompilationUnit(PluginLoadCallback plugin_loader,
    67                                      const proto::CompilationUnit& unit,
    68                                      const std::vector<proto::FileData>& files,
    69                                      KytheGraphRecorder* recorder);
    70  
    71  }  // namespace lang_textproto
    72  }  // namespace kythe
    73  
    74  #endif  // KYTHE_CXX_INDEXER_TEXTPROTO_ANALYZER_H_