Boaz Brickner
fcd38a4d7f
Add support for importing C++ namespaces ( #5103 )
...
This adds support for having different C++ `NameScope`s (and not just
the main `Cpp` scope), and we keep a pointer to `clang::DeclContext`
these scopes so we can look up C++ names in the right part of the AST.
C++ Interop Demo with a namespace:
```c++
// hello_world.h
namespace some_namespace {
void hello_world();
} // namespace some_namespace
```
```c++
// hello_world.cpp
#include <cstdio>
namespace some_namespace {
void hello_world() { printf("Hello World!\n"); }
} // namespace some_namespace
```
```carbon
// main.carbon
library "Main";
import Cpp library "hello_world.h";
fn Run() -> i32 {
Cpp.some_namespace.hello_world();
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
Hello World!
```
Closes #5102
2025-03-15 20:41:48 +00:00
..
2025-02-20 22:42:47 +00:00
2025-03-15 20:41:48 +00:00
2025-03-03 10:38:19 +00:00
2025-03-08 01:34:06 +00:00
2024-09-05 23:39:58 +00:00
2025-01-27 23:48:44 +00:00
2025-03-12 00:33:54 +00:00
2025-02-25 02:07:43 +00:00
2025-02-12 01:44:37 +00:00
2025-03-03 10:38:19 +00:00
2025-03-01 07:56:04 +00:00
2025-03-14 23:58:36 +00:00
2025-02-14 19:44:36 +00:00
2025-02-11 21:38:09 +00:00
2025-03-14 23:58:36 +00:00
2025-02-19 21:46:46 +00:00
2025-03-01 07:56:04 +00:00
2025-03-11 22:53:13 +00:00
2025-03-14 15:27:24 +00:00
2025-03-14 00:44:51 +00:00
2025-03-14 00:44:51 +00:00
2024-11-20 20:58:58 +00:00
2024-11-20 20:58:58 +00:00
2025-02-26 18:44:36 +00:00
2025-02-19 22:10:11 +00:00
2025-03-10 16:00:35 +00:00
2025-02-28 00:50:43 +00:00
2025-03-12 13:54:49 +00:00
2024-12-11 22:34:10 +00:00
2025-02-27 00:21:01 +00:00
2025-02-19 22:10:11 +00:00
2025-03-04 21:01:59 +00:00
2025-02-27 17:01:29 +00:00
2025-02-27 17:01:29 +00:00
2024-07-03 16:58:47 +00:00
2025-03-01 07:56:04 +00:00
2025-02-22 21:40:43 +00:00
2025-02-22 21:40:43 +00:00
2025-02-14 19:44:36 +00:00
2024-07-03 17:49:47 +00:00
2025-02-14 19:44:36 +00:00
2025-02-20 22:42:47 +00:00
2025-03-06 19:06:51 +00:00
2024-12-02 18:51:44 +00:00
2025-02-19 16:37:36 +00:00
2025-03-12 21:35:31 +00:00
2024-07-12 22:38:06 +00:00
2025-03-05 21:55:30 +00:00
2024-07-12 22:38:06 +00:00
2024-07-12 22:38:06 +00:00
2025-03-14 22:54:12 +00:00
2025-02-12 00:21:07 +00:00
2025-02-14 19:44:36 +00:00
2025-03-04 21:01:59 +00:00
2025-02-11 21:33:57 +00:00
2025-02-14 19:44:36 +00:00
2025-03-12 00:33:46 +00:00
2025-03-06 19:06:51 +00:00
2025-02-14 19:44:36 +00:00
2025-02-14 19:44:36 +00:00
2024-07-12 22:38:06 +00:00
2025-02-15 01:36:46 +00:00
2025-03-14 22:54:12 +00:00
2024-07-12 22:38:06 +00:00
2025-02-19 07:19:23 +00:00
2024-12-18 00:19:12 +00:00
2025-02-25 02:07:10 +00:00
2024-07-12 22:38:06 +00:00
2025-02-20 03:17:45 +00:00
2024-07-12 22:38:06 +00:00
2025-02-14 19:44:36 +00:00
2025-02-14 19:44:36 +00:00
2025-02-27 00:21:01 +00:00
2024-07-12 22:38:06 +00:00
2025-03-15 02:21:49 +00:00
2025-03-14 23:58:36 +00:00
2025-03-12 13:54:49 +00:00
2025-02-19 22:10:11 +00:00
2025-03-15 20:41:48 +00:00
2025-03-03 10:38:19 +00:00
2025-03-12 00:33:46 +00:00
2025-02-19 07:19:23 +00:00
2025-03-15 20:41:48 +00:00
2025-03-15 20:41:48 +00:00
2025-01-22 23:15:00 +00:00
2025-01-23 02:21:48 +00:00
2025-02-14 19:44:36 +00:00
2025-02-14 19:44:36 +00:00
2025-03-12 13:54:49 +00:00
2025-03-12 13:54:49 +00:00
2025-01-25 02:13:52 +00:00
2024-11-04 04:00:17 +00:00
2025-02-14 19:44:36 +00:00
2024-12-03 18:46:27 +00:00
2025-03-12 00:33:46 +00:00
2025-02-26 18:44:36 +00:00
2025-03-04 21:01:59 +00:00
2025-02-27 17:01:29 +00:00
2025-01-22 23:15:00 +00:00
2024-10-17 22:47:40 +00:00
2025-03-03 17:37:10 +00:00
2025-01-22 23:15:00 +00:00
2025-03-15 20:41:48 +00:00
2025-02-19 07:19:23 +00:00
2025-01-22 23:15:00 +00:00
2025-01-22 23:15:00 +00:00
2025-02-07 22:35:18 +00:00
2025-03-14 20:16:01 +00:00
2025-02-26 18:44:36 +00:00
2025-02-26 18:44:36 +00:00
2025-02-25 02:07:43 +00:00
2025-03-06 19:06:51 +00:00
2025-01-23 02:21:48 +00:00
2025-02-14 19:44:36 +00:00
2025-02-14 19:44:36 +00:00
2024-03-18 17:40:00 +00:00
2025-03-01 07:56:04 +00:00
2025-02-26 18:44:36 +00:00
2025-01-17 17:51:34 +00:00
2025-03-01 08:00:17 +00:00
2025-03-04 21:01:59 +00:00
2025-02-25 02:07:43 +00:00
2025-02-06 20:27:57 +00:00
2025-02-06 20:27:57 +00:00
2025-02-20 03:17:45 +00:00
2025-02-20 03:17:45 +00:00
2025-02-19 22:10:11 +00:00
2024-08-09 01:05:03 +00:00
2025-03-12 00:33:46 +00:00
2025-03-12 00:33:46 +00:00
2025-02-28 00:50:43 +00:00
2025-02-28 00:50:43 +00:00