mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
The general strategy here is to import the constructor with a signature that directly matches the argument. The intent is that the imported function will eventually be usable directly as the `ImplicitAs.Convert` function in a generated `impl`. For initialization from a tuple, for example `(1, 2)`, we import the selected constructor with a signature that takes a tuple pattern: `fn Class.Class((a: i32, b: i32)) -> Class;` In order to support that, this PR also adds support in general for tuple patterns in function signatures. It turns out the implementation was already very close to allowing this. Assisted-by: Gemini 3 Pro via Antigravity
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/sem_ir/clang_decl.h"
|
|
|
|
#include "clang/AST/DeclBase.h"
|
|
#include "clang/AST/TextNodeDumper.h"
|
|
#include "common/ostream.h"
|
|
#include "common/raw_string_ostream.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
auto ClangDeclKey::Print(llvm::raw_ostream& out) const -> void {
|
|
RawStringOstream decl_stream;
|
|
auto policy = decl->getASTContext().getPrintingPolicy();
|
|
policy.TerseOutput = true;
|
|
if (isa<clang::TranslationUnitDecl>(decl)) {
|
|
decl_stream << "<translation unit>";
|
|
} else {
|
|
decl->print(decl_stream, policy);
|
|
}
|
|
|
|
if (signature.num_params != -1) {
|
|
out << "{decl: \"" << FormatEscaped(decl_stream.TakeStr()) << "\", kind: ";
|
|
switch (signature.kind) {
|
|
case ClangDeclKey::Signature::Normal:
|
|
out << "normal";
|
|
break;
|
|
case ClangDeclKey::Signature::TuplePattern:
|
|
out << "tuple";
|
|
break;
|
|
}
|
|
out << ", num_params: " << signature.num_params << "}";
|
|
} else {
|
|
out << "\"" << FormatEscaped(decl_stream.TakeStr()) << "\"";
|
|
}
|
|
}
|
|
|
|
auto ClangDecl::Print(llvm::raw_ostream& out) const -> void {
|
|
out << "{key: " << key << ", inst_id: " << inst_id << "}";
|
|
}
|
|
|
|
} // namespace Carbon::SemIR
|