mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Create a Clang module per Carbon file. (#7594)
This isolates the C++ imports in different Carbon files from each other in `--share-cpp-ast` mode, so that a Carbon file can only see the portions of the shared Clang `ASTContext` that it actually imported. Assisted-by: Gemini via Antigravity
This commit is contained in:
@@ -20,21 +20,33 @@ library "[[@TEST_NAME]]";
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "";
|
||||
|
||||
// --- fail_import_cpp_library_file_with_quotes.carbon
|
||||
// --- fail_import_cpp_library_nonexistent.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_file_with_quotes.carbon:[[@LINE+14]]:10: error: '\' file not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 18 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: fail_import_cpp_library_nonexistent.carbon:[[@LINE+4]]:10: error: 'does_not_exist.h' file not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 8 | #include "does_not_exist.h"
|
||||
// CHECK:STDERR: | ^~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "does_not_exist.h";
|
||||
|
||||
// --- fail_todo_import_cpp_library_file_with_quotes.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// TODO: Translate the file to a `#include` that includes the named file
|
||||
// properly. `\` escapes aren't processed in regular `#include`s.
|
||||
// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+14]]:10: error: '\' file not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 20 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: | ^~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_file_with_quotes.carbon:[[@LINE+10]]:13: error: invalid suffix on literal; C++11 requires a space between literal and identifier [CppInteropParseError]
|
||||
// CHECK:STDERR: 18 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+10]]:13: error: invalid suffix on literal; C++11 requires a space between literal and identifier [CppInteropParseError]
|
||||
// CHECK:STDERR: 20 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: | {{}}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_file_with_quotes.carbon:[[@LINE+5]]:13: warning: extra tokens at end of #include directive [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 18 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+5]]:13: warning: extra tokens at end of #include directive [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 20 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: | //
|
||||
// CHECK:STDERR:
|
||||
@@ -42,6 +54,8 @@ import Cpp library "\"foo.h\"";
|
||||
|
||||
// --- todo_fail_unterminated_import_inline.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp inline '''c++
|
||||
void f() {
|
||||
''';
|
||||
|
||||
@@ -33,12 +33,16 @@ fn CallA() -> i32 {
|
||||
return Cpp.GetA();
|
||||
}
|
||||
|
||||
// --- todo_a_leaks.carbon
|
||||
// --- fail_a_does_not_leak.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
import Cpp;
|
||||
|
||||
fn CallLeakedA() -> i32 {
|
||||
// TODO: This should not be found as we have not imported "a.h".
|
||||
// This should not be found as we have not imported "a.h".
|
||||
// CHECK:STDERR: fail_a_does_not_leak.carbon:[[@LINE+4]]:10: error: member name `GetA` not found in `Cpp`
|
||||
// CHECK:STDERR: return Cpp.GetA();
|
||||
// CHECK:STDERR: ^~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
return Cpp.GetA();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user