clang_decl.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 (signature.num_params != -1) {
  20. out << "{decl: \"" << FormatEscaped(decl_stream.TakeStr()) << "\", kind: ";
  21. switch (signature.kind) {
  22. case ClangDeclKey::Signature::Normal:
  23. out << "normal";
  24. break;
  25. case ClangDeclKey::Signature::TuplePattern:
  26. out << "tuple";
  27. break;
  28. }
  29. out << ", num_params: " << signature.num_params << "}";
  30. } else {
  31. out << "\"" << FormatEscaped(decl_stream.TakeStr()) << "\"";
  32. }
  33. }
  34. auto ClangDecl::Print(llvm::raw_ostream& out) const -> void {
  35. out << "{key: " << key << ", inst_id: " << inst_id << "}";
  36. }
  37. } // namespace Carbon::SemIR