mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Only supports classes with a single (non copy non move) constructor (without default values), until overloading is supported. Based on #5878. C++ Interop Demo: ```c++ // hello_world.h #include <cstdio> class C { public: C(int x, int y) : x_(x), y_(y) {} int x() const { return x_;} int y() const { return y_;} private: int x_; int y_; }; void hello_world(C* _Nonnull c); ``` ```c++ // hello_world.cpp #include "hello_world.h" #include <cstdio> void hello_world(C* _Nonnull c) { printf("C.x = %d. C.y = %d\n", c->x(), c->y()); } ``` ```carbon // main.carbon library "Main"; import Cpp library "hello_world.h"; fn Run() -> i32 { var c : Cpp.C = Cpp.C.C(1, 2); Cpp.hello_world(&c); return 0; } ``` ```shell $ clang -c hello_world.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link hello_world.o main.o --output=demo $ ./demo C.x = 1. C.y = 2 ``` Part of #5880.
20 lines
649 B
C++
20 lines
649 B
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
|
|
|
|
#ifndef CARBON_TOOLCHAIN_LOWER_CLANG_GLOBAL_DECL_H_
|
|
#define CARBON_TOOLCHAIN_LOWER_CLANG_GLOBAL_DECL_H_
|
|
|
|
#include "clang/AST/Decl.h"
|
|
#include "clang/AST/GlobalDecl.h"
|
|
|
|
namespace Carbon::Lower {
|
|
|
|
// Returns `clang::GlobalDecl` with special handling of constructors, assuming
|
|
// they're complete.
|
|
auto CreateGlobalDecl(const clang::NamedDecl* decl) -> clang::GlobalDecl;
|
|
|
|
} // namespace Carbon::Lower
|
|
|
|
#endif // CARBON_TOOLCHAIN_LOWER_CLANG_GLOBAL_DECL_H_
|