cxx_gen/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 = quote_spanned!(include.begin_span=> .);
21                let end = quote_spanned!(include.end_span=> .);
22                let span = quote!(#begin #end);
23                cx.error(span, error::DOT_INCLUDE.msg);
24            }
25        }
26    }
27}