Skip to content

Commit 6b33679

Browse files
committed
Fixed issue with C unary operators not parsing as intended
1 parent a7eec5f commit 6b33679

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Diff for: src/c/parser/expr.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use crate::{
88
parser::speculate::speculate,
99
punctuator::Punctuator,
1010
token::CTokenKind,
11+
translate::get_decorators,
1112
},
1213
source_files::Source,
1314
};
15+
use ignore::types::TypesBuilder;
1416

1517
// Implements expression parsing for the C parser
1618
impl<'a> Parser<'a> {
@@ -237,30 +239,38 @@ impl<'a> Parser<'a> {
237239

238240
match &self.input.peek().kind {
239241
CTokenKind::Punctuator(Punctuator::Ampersand) => {
242+
self.input.advance();
240243
let inner = self.parse_expr_primary()?;
241244
return Ok(ExprKind::AddressOf(Box::new(inner)).at(source));
242245
}
243246
CTokenKind::Punctuator(Punctuator::Multiply) => {
247+
self.input.advance();
244248
let inner = self.parse_expr_primary()?;
245249
return Ok(ExprKind::Dereference(Box::new(inner)).at(source));
246250
}
247251
CTokenKind::Punctuator(Punctuator::Add) => todo!(),
248252
CTokenKind::Punctuator(Punctuator::Subtract) => {
253+
self.input.advance();
249254
let inner = self.parse_expr_primary()?;
250255
return Ok(ExprKind::Negate(Box::new(inner)).at(source));
251256
}
252257
CTokenKind::Punctuator(Punctuator::BitComplement) => {
258+
self.input.advance();
253259
let inner = self.parse_expr_primary()?;
254260
return Ok(ExprKind::BitComplement(Box::new(inner)).at(source));
255261
}
256262
CTokenKind::Punctuator(Punctuator::Not) => {
263+
self.input.advance();
257264
let inner = self.parse_expr_primary()?;
258265
return Ok(ExprKind::Not(Box::new(inner)).at(source));
259266
}
260267
CTokenKind::Punctuator(Punctuator::Increment) => todo!("parse increment expression"),
261268
CTokenKind::Punctuator(Punctuator::Decrement) => todo!("parse decrement expression"),
262269
CTokenKind::SizeofKeyword => {
263-
if let Ok(_ty) = speculate!(self.input, self.parse_type_in_parens()) {
270+
self.input.advance();
271+
272+
if let Ok(type_name) = speculate!(self.input, self.parse_type_in_parens()) {
273+
let mut type_builder = TypesBuilder::new();
264274
return todo!("handle parsed sizeof(type)");
265275
}
266276

@@ -303,7 +313,7 @@ impl<'a> Parser<'a> {
303313

304314
let type_name = self.parse_type_name()?;
305315

306-
if !self.eat_open_paren() {
316+
if !self.eat_punctuator(Punctuator::CloseParen) {
307317
return Err(self.error("Expected ')' after type in parentheses"));
308318
}
309319

Diff for: src/c/translate/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
workspace::compile::c_code::CFileType,
1616
};
1717
use std::collections::HashMap;
18+
pub use types::get_decorators;
1819

1920
pub struct TranslateCtx<'ast, 'typedefs, 'diagnostics, 'source_files> {
2021
pub ast_file: &'ast mut AstFile,

Diff for: src/c/translate/types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn get_name_and_decorators(
286286
}
287287
}
288288

289-
fn get_decorators(
289+
pub fn get_decorators(
290290
ctx: &mut TranslateCtx,
291291
abstract_declarator: &AbstractDeclarator,
292292
) -> Result<Decorators, ParseError> {

0 commit comments

Comments
 (0)