clang_decl.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/sem_ir/clang_decl.h"
  5. #include "clang/AST/DeclBase.h"
  6. #include "clang/AST/TextNodeDumper.h"
  7. #include "common/ostream.h"
  8. #include "common/raw_string_ostream.h"
  9. namespace Carbon::SemIR {
  10. auto ClangDeclKey::Print(llvm::raw_ostream& out) const -> void {
  11. RawStringOstream decl_stream;
  12. auto policy = decl->getASTContext().getPrintingPolicy();
  13. policy.TerseOutput = true;
  14. if (isa<clang::TranslationUnitDecl>(decl)) {
  15. decl_stream << "<translation unit>";
  16. } else {
  17. decl->print(decl_stream, policy);
  18. }
  19. if (num_params != -1) {
  20. out << "{decl: \"" << FormatEscaped(decl_stream.TakeStr())
  21. << "\", num_params: " << num_params << "}";
  22. } else {
  23. out << "\"" << FormatEscaped(decl_stream.TakeStr()) << "\"";
  24. }
  25. }
  26. auto ClangDecl::Print(llvm::raw_ostream& out) const -> void {
  27. out << "{key: " << key << ", inst_id: " << inst_id << "}";
  28. }
  29. } // namespace Carbon::SemIR