Skip to content

Commit

Permalink
Fixed issue with strings from header files not being resolved to C-st…
Browse files Browse the repository at this point in the history
…yle strings
  • Loading branch information
IsaacShelton committed Oct 18, 2024
1 parent 050bd82 commit 79f7f79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/c/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impl<'a> Parser<'a> {
if let CTokenKind::StringLiteral(encoding, string) = &self.input.peek().kind {
let string = string.clone();
let encoding = encoding.clone();

self.input.advance();
return Ok(ExprKind::StringLiteral(encoding, string).at(source));
}
Expand Down
5 changes: 4 additions & 1 deletion src/c/translation/expr/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ use crate::{
c::{encoding::Encoding, parser::ParseError},
source_files::Source,
};
use std::ffi::CString;

pub fn translate_expr_string(
encoding: &Encoding,
content: &str,
source: Source,
) -> Result<ast::Expr, ParseError> {
if let Encoding::Default = encoding {
return Ok(ast::ExprKind::String(content.into()).at(source));
// TODO: Add proper error message?
let content = CString::new(content).expect("valid null-terminated string");
return Ok(ast::ExprKind::NullTerminatedString(content).at(source));
}

todo!("translate non-default encoding C string")
Expand Down

0 comments on commit 79f7f79

Please sign in to comment.