Skip to content

Commit 0a13fec

Browse files
committed
Apply generated macros to the code
1 parent d7da556 commit 0a13fec

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/c_langs_macros/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod c_macros;
2+
pub use c_macros::*;
3+
4+
mod c_specials;
5+
pub use c_specials::*;

src/c_macro.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::collections::HashSet;
22

3+
use crate::c_langs_macros::is_predefined_macros;
4+
35
const DOLLARS: [u8; 2048] = [b'$'; 2048];
4-
include!(concat!(env!("OUT_DIR"), "/gen_c_macros.rs"));
56

67
#[inline(always)]
78
fn is_identifier_part(c: u8) -> bool {
@@ -18,7 +19,7 @@ fn is_identifier_starter(c: u8) -> bool {
1819

1920
#[inline(always)]
2021
fn is_macro<S: ::std::hash::BuildHasher>(mac: &str, macros: &HashSet<String, S>) -> bool {
21-
macros.contains(mac) || PREDEFINED_MACROS.contains(mac)
22+
macros.contains(mac) | is_predefined_macros(mac)
2223
}
2324

2425
pub fn replace<S: ::std::hash::BuildHasher>(

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extern crate serde;
5656

5757
#[macro_use]
5858
mod asttools;
59+
mod c_langs_macros;
5960
mod c_macro;
6061
#[macro_use]
6162
mod macros;

src/preproc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ use petgraph::{
44
use std::collections::{hash_map, HashMap, HashSet};
55
use std::path::{Path, PathBuf};
66

7+
use crate::c_langs_macros::is_specials;
78
use crate::node::Node;
89

910
use crate::langs::*;
1011
use crate::languages::language_preproc::*;
1112
use crate::tools::*;
1213
use crate::traits::*;
1314

14-
include!(concat!(env!("OUT_DIR"), "/gen_c_specials.rs"));
15-
1615
/// Preprocessor data of a `C/C++` file.
1716
#[derive(Debug, Default, Deserialize, Serialize)]
1817
pub struct PreprocFile {
@@ -214,7 +213,7 @@ pub fn preprocess(parser: &PreprocParser, path: &Path, results: &mut PreprocResu
214213

215214
if identifier.kind_id() == Preproc::Identifier {
216215
let r#macro = identifier.utf8_text(code).unwrap();
217-
if !SPECIALS.contains(r#macro) {
216+
if !is_specials(r#macro) {
218217
file_result.macros.insert(r#macro.to_string());
219218
}
220219
}

0 commit comments

Comments
 (0)