Skip to content

Commit a9086d8

Browse files
committed
Use published version of rcc; rcc -> saltwater
1 parent 46443fe commit a9086d8

File tree

5 files changed

+50
-53
lines changed

5 files changed

+50
-53
lines changed

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ regex = { version = "1.0", default-features = false , features = [ "std", "unico
5858
which = { version = "3.0", optional = true, default-features = false }
5959
shlex = "0.1"
6060
rustc-hash = "1.0.1"
61+
saltwater = { version = "0.10", default-features = false }
62+
6163
# New validation in 0.3.6 breaks bindgen-integration:
6264
# https://github.com/alexcrichton/proc-macro2/commit/489c642.
6365
proc-macro2 = { version = "1", default-features = false }
@@ -70,11 +72,6 @@ version = "0.7"
7072
optional = true
7173
version = "0.4"
7274

73-
[dependencies.rcc]
74-
git = "https://github.com/jyn514/rcc/"
75-
branch = "bindgen"
76-
default-features = false
77-
7875
[features]
7976
default = ["logging", "clap", "runtime", "which-rustfmt"]
8077
logging = ["env_logger", "log"]

src/clang.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,11 @@ impl Cursor {
705705
RawTokens::new(self)
706706
}
707707

708-
/// Gets the tokens that correspond to that cursor as `rcc` tokens.
709-
pub fn rcc_tokens(self) -> Vec<rcc::Locatable<rcc::Token>> {
708+
/// Gets the tokens that correspond to that cursor as `saltwater` tokens.
709+
pub fn swcc_tokens(self) -> Vec<saltwater::Locatable<saltwater::Token>> {
710710
self.tokens()
711711
.iter()
712-
.filter_map(|token| token.as_rcc_token())
712+
.filter_map(|token| token.as_swcc_token())
713713
.collect()
714714
}
715715

@@ -804,12 +804,12 @@ impl ClangToken {
804804
c_str.to_bytes()
805805
}
806806

807-
/// Converts a ClangToken to an `rcc` token if possible.
808-
pub fn as_rcc_token(&self) -> Option<rcc::Locatable<rcc::Token>> {
809-
use rcc::{Files, Lexer, Literal, Token};
807+
/// Converts a ClangToken to an `saltwater` token if possible.
808+
pub fn as_swcc_token(&self) -> Option<saltwater::Locatable<saltwater::Token>> {
809+
use saltwater::{Files, Lexer, Literal, Token};
810810

811811
match self.kind {
812-
// `rcc` does not have a comment token
812+
// `saltwater` does not have a comment token
813813
CXToken_Comment => return None,
814814
CXToken_Punctuation |
815815
CXToken_Literal |
@@ -819,8 +819,8 @@ impl ClangToken {
819819
let mut files = Files::new();
820820
let id = files.add("", "".into());
821821
let mut lexer = Lexer::new(id, spelling, false);
822-
let mut token = lexer.next().unwrap().expect("rcc failed to parse clang token");
823-
// rcc generates null-terminated string immediately,
822+
let mut token = lexer.next().unwrap().expect("saltwater failed to parse clang token");
823+
// saltwater generates null-terminated string immediately,
824824
// but bindgen only adds the null-terminator during codegen.
825825
if let Token::Literal(Literal::Str(ref mut string)) = &mut token.data {
826826
assert_eq!(string.pop(), Some(b'\0'));

src/ir/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::BindgenOptions;
2626
use crate::{Entry, HashMap, HashSet};
2727
use clang_sys;
2828
use proc_macro2::{Ident, Span};
29-
use rcc::InternedStr;
29+
use saltwater::InternedStr;
3030
use std::borrow::Cow;
3131
use std::cell::Cell;
3232
use std::collections::HashMap as StdHashMap;
@@ -351,8 +351,8 @@ pub struct BindgenContext {
351351
/// hard errors while parsing duplicated macros, as well to allow macro
352352
/// expression parsing.
353353
///
354-
/// This needs to be an std::HashMap because the rcc API requires it.
355-
parsed_macros: StdHashMap<InternedStr, rcc::Definition>,
354+
/// This needs to be an std::HashMap because the saltwater API requires it.
355+
parsed_macros: StdHashMap<InternedStr, saltwater::Definition>,
356356

357357
/// The active replacements collected from replaces="xxx" annotations.
358358
replacements: HashMap<Vec<String>, ItemId>,
@@ -2043,7 +2043,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20432043
/// Get the currently parsed macros.
20442044
pub fn parsed_macros(
20452045
&self,
2046-
) -> &StdHashMap<InternedStr, rcc::Definition> {
2046+
) -> &StdHashMap<InternedStr, saltwater::Definition> {
20472047
debug_assert!(!self.in_codegen_phase());
20482048
&self.parsed_macros
20492049
}
@@ -2052,9 +2052,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20522052
pub fn note_parsed_macro(
20532053
&mut self,
20542054
id: InternedStr,
2055-
value: rcc::Literal,
2055+
value: saltwater::Literal,
20562056
) {
2057-
self.parsed_macros.insert(id, rcc::Definition::Object(vec![rcc::Token::Literal(value)]));
2057+
self.parsed_macros.insert(id, saltwater::Definition::Object(vec![saltwater::Token::Literal(value)]));
20582058
}
20592059

20602060
/// Are we in the codegen phase?

src/ir/var.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::parse::{
1414
};
1515
use std::io;
1616
use std::collections::HashMap;
17-
use rcc::{InternedStr, Literal};
17+
use saltwater::{InternedStr, Literal};
1818

1919
/// The type for a constant variable.
2020
#[derive(Debug)]
@@ -245,7 +245,7 @@ impl ClangSubItemParser for Var {
245245
let parse_int = |value| {
246246
let kind = ctx
247247
.parse_callbacks()
248-
.and_then(|c| c.int_macro(rcc::get_str!(id), value))
248+
.and_then(|c| c.int_macro(saltwater::get_str!(id), value))
249249
.unwrap_or_else(|| {
250250
default_macro_constant_type(value)
251251
});
@@ -267,7 +267,7 @@ impl ClangSubItemParser for Var {
267267
ctx,
268268
);
269269
if let Some(callbacks) = ctx.parse_callbacks() {
270-
callbacks.str_macro(rcc::get_str!(id), &val);
270+
callbacks.str_macro(saltwater::get_str!(id), &val);
271271
}
272272
(TypeKind::Pointer(char_ty), VarType::String(val))
273273
}
@@ -377,10 +377,10 @@ fn parse_macro(
377377
ctx: &BindgenContext,
378378
tokens: &[ClangToken],
379379
) -> Option<(InternedStr, Literal)> {
380-
use rcc::Token;
380+
use saltwater::Token;
381381

382-
let mut rcc_tokens = tokens.iter().filter_map(ClangToken::as_rcc_token);
383-
let ident_str = match rcc_tokens.next()?.data {
382+
let mut swcc_tokens = tokens.iter().filter_map(ClangToken::as_swcc_token);
383+
let ident_str = match swcc_tokens.next()?.data {
384384
Token::Id(id) => id,
385385
_ => return None,
386386
};
@@ -389,8 +389,8 @@ fn parse_macro(
389389
}
390390
let parsed_macros = ctx.parsed_macros();
391391

392-
// TODO: remove this clone (will need changes in rcc)
393-
if let Some(literal) = rcc_expr(rcc_tokens.clone(), &parsed_macros) {
392+
// TODO: remove this clone (will need changes in saltwater)
393+
if let Some(literal) = swcc_expr(swcc_tokens.clone(), &parsed_macros) {
394394
return Some((ident_str, literal));
395395
}
396396

@@ -400,27 +400,27 @@ fn parse_macro(
400400
// See:
401401
// https://bugs.llvm.org//show_bug.cgi?id=9069
402402
// https://reviews.llvm.org/D26446
403-
let tokens = tokens[1..tokens.len() - 1].iter().filter_map(ClangToken::as_rcc_token);
404-
if let Some(literal) = rcc_expr(tokens, &parsed_macros) {
403+
let tokens = tokens[1..tokens.len() - 1].iter().filter_map(ClangToken::as_swcc_token);
404+
if let Some(literal) = swcc_expr(tokens, &parsed_macros) {
405405
Some((ident_str, literal))
406406
} else {
407407
None
408408
}
409409
}
410410

411-
fn rcc_expr(rcc_tokens: impl Iterator<Item = rcc::Locatable<rcc::Token>>, definitions: &HashMap<InternedStr, rcc::Definition>) -> Option<Literal> {
412-
use rcc::PreProcessor;
411+
fn swcc_expr(swcc_tokens: impl Iterator<Item = saltwater::Locatable<saltwater::Token>>, definitions: &HashMap<InternedStr, saltwater::Definition>) -> Option<Literal> {
412+
use saltwater::PreProcessor;
413413

414-
let mut rcc_tokens = rcc_tokens.peekable();
415-
let location = rcc_tokens.peek()?.location;
416-
PreProcessor::cpp_expr(definitions, rcc_tokens, location).ok()?.const_fold().ok()?.into_literal().ok()
414+
let mut swcc_tokens = swcc_tokens.peekable();
415+
let location = swcc_tokens.peek()?.location;
416+
PreProcessor::cpp_expr(definitions, swcc_tokens, location).ok()?.const_fold().ok()?.into_literal().ok()
417417
}
418418

419419
fn parse_int_literal_tokens(cursor: &clang::Cursor) -> Option<i64> {
420-
let rcc_tokens = cursor.rcc_tokens().into_iter();
420+
let swcc_tokens = cursor.swcc_tokens().into_iter();
421421

422422
// TODO(emilio): We can try to parse other kinds of literals.
423-
match rcc_expr(rcc_tokens, &HashMap::new()) {
423+
match swcc_expr(swcc_tokens, &HashMap::new()) {
424424
Some(Literal::Int(i)) => Some(i),
425425
Some(Literal::UnsignedInt(u)) => Some(u as i64),
426426
_ => None,

0 commit comments

Comments
 (0)