Skip to content

Commit

Permalink
js, cpp2, c2
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Nov 22, 2023
1 parent deac309 commit 1e1c357
Show file tree
Hide file tree
Showing 22 changed files with 120 additions and 102 deletions.
2 changes: 1 addition & 1 deletion example/js/lib/api/ICU4XLocale.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions example/js/lib/api/diplomat-runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions example/js/lib/api/diplomat-wasm.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/c2/include/BorrowedFields.d.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp2/include/BorrowedFields.d.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp2/include/BorrowedFields.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp2/include/BorrowedFields.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions feature_tests/js/api/BorrowedFields.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js/api/BorrowedFieldsReturning.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions feature_tests/js/api/Foo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions feature_tests/js/api/MyString.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions feature_tests/js/api/diplomat-runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions feature_tests/js/api/diplomat-wasm.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions tool/src/c2/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,11 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> {
("size_t".into(), format!("{param_name}_len").into()),
]
}
// TODO(#240): Implement UTF-16
Type::Slice(hir::Slice::Str(_, hir::StringEncoding::UnvalidatedUtf16))
if !is_struct =>
{
vec![
(
"const uint16_t*".into(),
format!("{param_name}_data").into(),
),
("const wchar_t*".into(), format!("{param_name}_data").into()),
("size_t".into(), format!("{param_name}_len").into()),
]
}
Expand Down Expand Up @@ -327,8 +323,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> {
Type::Slice(ref s) => {
let ptr_ty = match s {
hir::Slice::Str(_, hir::StringEncoding::UnvalidatedUtf8) => "char".into(),
// TODO(#240): Implement UTF-16
hir::Slice::Str(_, hir::StringEncoding::UnvalidatedUtf16) => "uint16_t".into(),
hir::Slice::Str(_, hir::StringEncoding::UnvalidatedUtf16) => "wchar_t".into(),
hir::Slice::Primitive(_, prim) => self.cx.formatter.fmt_primitive_as_c(*prim),
&_ => unreachable!("unknown AST/HIR variant"),
};
Expand Down
9 changes: 8 additions & 1 deletion tool/src/cpp2/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl<'tcx> Cpp2Formatter<'tcx> {
ident: &'a str,
mutability: hir::Mutability,
) -> Cow<'a, str> {
// TODO: This needs to change if an abstraction other than std::span is used
// TODO: Where is the right place to put `const` here?
if mutability.is_mutable() {
format!("diplomat::span<{ident}>").into()
Expand All @@ -131,10 +132,16 @@ impl<'tcx> Cpp2Formatter<'tcx> {
}
}

pub fn fmt_borrowed_str(&self) -> Cow<'static, str> {
pub fn fmt_borrowed_utf8_str(&self) -> Cow<'static, str> {
// TODO: This needs to change if an abstraction other than std::u8string_view is used
"std::string_view".into()
}

pub fn fmt_borrowed_utf16_str(&self) -> Cow<'static, str> {
// TODO: This needs to change if an abstraction other than std::u16string_view is used
"std::wstring_view".into()
}

pub fn fmt_owned_str(&self) -> Cow<'static, str> {
"std::string".into()
}
Expand Down
Loading

0 comments on commit 1e1c357

Please sign in to comment.