cxx_build/gen/
check.rs

1use crate::gen::Opt;
2use crate::syntax::report::Errors;
3use crate::syntax::{error, Api};
4use quote::{quote, quote_spanned};
5use std::path::{Component, Path};
6
7pub(super) use crate::syntax::check::{typecheck, Generator};
8
9pub(super) fn precheck(cx: &mut Errors, apis: &[Api], opt: &Opt) {
10    if !opt.allow_dot_includes {
11        check_dot_includes(cx, apis);
12    }
13}
14
15fn check_dot_includes(cx: &mut Errors, apis: &[Api]) {
16    for api in apis {
17        if let Api::Include(include) = api {
18            let first_component = Path::new(&include.path).components().next();
19            if let Some(Component::CurDir | Component::ParentDir) = first_component {
20                let begin = {
    let mut _s = ::quote::__private::TokenStream::new();
    let _span: ::quote::__private::Span =
        ::quote::__private::get_span(include.begin_span).__into_span();
    ::quote::__private::push_dot_spanned(&mut _s, _span);
    _s
}quote_spanned!(include.begin_span=> .);
21                let end = {
    let mut _s = ::quote::__private::TokenStream::new();
    let _span: ::quote::__private::Span =
        ::quote::__private::get_span(include.end_span).__into_span();
    ::quote::__private::push_dot_spanned(&mut _s, _span);
    _s
}quote_spanned!(include.end_span=> .);
22                let span = {
    let mut _s = ::quote::__private::TokenStream::new();
    ::quote::ToTokens::to_tokens(&begin, &mut _s);
    ::quote::ToTokens::to_tokens(&end, &mut _s);
    _s
}quote!(#begin #end);
23                cx.error(span, error::DOT_INCLUDE.msg);
24            }
25        }
26    }
27}