Debian Codegraph @

src/pp.rs

raw symbols SCIP
1 use craterust-analyzer cargo pp-rs 0.2.1 crate/::lexerrust-analyzer cargo pp-rs 0.2.1 lexer/::{selfrust-analyzer cargo pp-rs 0.2.1 lexer/, Tokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token# as LexerTokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#, TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue# as LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#};
2 use craterust-analyzer cargo pp-rs 0.2.1 crate/::tokenrust-analyzer cargo pp-rs 0.2.1 token/::*;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
4 cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#,
5 collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#},
6 convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#,
7 rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#,
8 };
9
10 mod if_parserrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/;
11
12 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
13 struct Definerust-analyzer cargo pp-rs 0.2.1 pp/Define# {
14 namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
15 function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like.: bool,
16 paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, usize>,
17 tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>,
18 }
19
20 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
21 struct DefineInvocationrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation# {
22 definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define.: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#>,
23 define_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define_position.: usize,
24
25 parametersrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameters.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>>,
26 parameter_expandingrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_expanding.: usize,
27 parameter_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_position.: usize,
28 }
29
30 pub type Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<T> = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#>;
31
32 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
33 pub enum StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit# {
34 Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)),
35 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#,
36 Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#,
37 }
38
39 use selfrust-analyzer cargo pp-rs 0.2.1 pp/::StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#;
40 use selfrust-analyzer cargo pp-rs 0.2.1 pp/::StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#;
41
42 impl<T> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#> for Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<T> {
43 fn fromrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Result<T, StepExit>`][`From<StepExit>`]from().(exit: StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<T> {
44 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(exit)
45 }
46 }
47
48 trait MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer# {
49 fn steprust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#step().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>;
50 fn get_definerust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#get_define().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#>>;
51 fn apply_line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#apply_line_offset().(&self, line: u32, location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<u32>;
52 }
53
54 fn make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token: LexerTokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#) -> StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit# {
55 let error = match token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
56 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Integerrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Integer#(i) => PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedTokenrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedToken#(TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Integerrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Integer#(i)),
57 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Floatrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Float#(f) => PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedTokenrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedToken#(TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Floatrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Float#(f)),
58 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(s) => PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedTokenrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedToken#(TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Ident#(s)),
59 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(p) => PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedTokenrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedToken#(TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Punct#(p)),
60 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# => PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedNewLinerust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedNewLine#,
61 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Hashrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Hash# => PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedHashrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedHash#,
62 };
63 StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((error, token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.))
64 }
65
66 fn make_line_overflow_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_line_overflow_error().(location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit# {
67 StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::LineOverflowrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#LineOverflow#, location))
68 }
69
70 struct DirectiveBlockrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock# {
71 start_locationrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#start_location.: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#,
72 had_valid_segmentrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_valid_segment.: bool,
73 had_elserust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_else.: bool,
74 outer_skippedrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#outer_skipped.: bool,
75 }
76
77 struct DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#<'a> {
78 lexerrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#lexer.: lexerrust-analyzer cargo pp-rs 0.2.1 lexer/::Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#<'a>,
79 definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#>>,
80 skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping.: bool,
81 blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DirectiveBlockrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#>,
82 line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#line_offset.: i64,
83 had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive.: bool,
84 had_non_directive_tokenrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_non_directive_token.: bool,
85 }
86
87 pub fn convert_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token().(token: LexerTokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#, (PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)> {
88 let location = token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.;
89 match token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
90 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Integerrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Integer#(i) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
91 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Integerrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Integer#(i),
92 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
93 }),
94 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Floatrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Float#(f) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
95 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Floatrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Float#(f),
96 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
97 }),
98 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(s) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
99 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Ident#(s),
100 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
101 }),
102 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(p) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
103 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Punct#(p),
104 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
105 }),
106
107 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Hashrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Hash# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#((PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedHashrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedHash#, location)),
108 // In all the places that call convert_lexer_token, newlines are handled specially as they
109 // are either noops, or act as a separator.
110 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
111 }
112 }
113
114 pub fn convert_lexer_token_to_steprust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token_to_step().(token: LexerTokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
115 convert_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token().(token).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#)
116 }
117
118 fn legal_redefinitionrust-analyzer cargo pp-rs 0.2.1 pp/legal_redefinition().(a: &Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#, b: &Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#) -> bool {
119 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a.namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name. == b.namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name.);
120 a.function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().b.function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like.
121 && a.paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params. rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`PartialEq<Self>`]eq().b.paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params.
122 && a.tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().b.tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
123 && a.tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens.
124 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
125 .ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(&b.tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens.)
126 .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|(ta, tb)| ta.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value. rust-analyzer cargo pp-rs 0.2.1 token/impl#[TokenValue][`PartialEq<Self>`]eq().==rust-analyzer cargo pp-rs 0.2.1 token/impl#[TokenValue][`PartialEq<Self>`]eq(). rust-analyzer cargo pp-rs 0.2.1 token/impl#[TokenValue][`PartialEq<Self>`]eq().tb.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.)
127 }
128
129 impl<'a> DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#<'a> {
130 pub fn newrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]new().(input: &'a str) -> DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor# {
131 DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor# {
132 lexerrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#lexer.: lexerrust-analyzer cargo pp-rs 0.2.1 lexer/::Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#::newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]new().(input),
133 definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().(),
134 skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping.: false,
135 blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(),
136 line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#line_offset.: 0,
137 had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive.: false,
138 had_non_directive_tokenrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_non_directive_token.: false,
139 }
140 }
141
142 fn get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<LexerTokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#> {
143 match self.lexerrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#lexer..nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`][Iterator]next().() {
144 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
145 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tok)) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tok),
146 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err)) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#(err)),
147 }
148 }
149
150 fn expect_a_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_a_lexer_token().(&mut self, current_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<LexerTokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#> {
151 match self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().() {
152 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token),
153 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
154 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedEndOfInputrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedEndOfInput#,
155 current_location,
156 ))),
157 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e),
158 }
159 }
160
161 fn expect_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_token().(
162 &mut self,
163 expected: LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#,
164 current_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#,
165 ) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#> {
166 let token = self.expect_a_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_a_lexer_token().(current_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
167 if token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().==rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq(). rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().expected {
168 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)
169 } else {
170 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token))
171 }
172 }
173
174 fn expect_lexer_identrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_ident().(&mut self, current_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)> {
175 let token = self.expect_a_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_a_lexer_token().(current_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
176 if let LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(name) = token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
177 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((name, token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.))
178 } else {
179 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token))
180 }
181 }
182
183 fn consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
184 loop {
185 // TODO allow unexpected character errors because we are skipping.
186 if let LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
187 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
188 }
189 }
190 }
191
192 fn gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>> {
193 let mut tokens = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
194 loop {
195 let token = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
196 if token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().==rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq(). rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# {
197 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tokens);
198 }
199 tokens.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(convert_lexer_token_to_steprust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token_to_step().(token)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
200 }
201 }
202
203 fn parse_define_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_define_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
204 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
205 return self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().();
206 }
207
208 let (name, name_location) = self.expect_lexer_identrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_ident().(directive_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
209
210 // TODO validate the name?
211 let mut define = Definerust-analyzer cargo pp-rs 0.2.1 pp/Define# {
212 namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name.,
213 function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like.: false,
214 paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().(),
215 tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(),
216 };
217
218 // TODO what if token is none? EOF but still need to check it is not a redefinition?
219 let mut token = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
220
221 // The is a function-like define, parse the argument list, leaving token as the next
222 // token.
223 if token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().==rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq(). rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftParen#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().token.leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Token#leading_whitespace. {
224 define.function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like. = true;
225 let mut first_param = true;
226 loop {
227 token = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
228 match &token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
229 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#RightParen#) => {
230 token = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
231 break;
232 }
233
234 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(param_name) => {
235 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().first_param {
236 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token));
237 }
238 first_param = false;
239 define
240 .paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params.
241 .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(param_name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), define.paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().());
242 }
243
244 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Commarust-analyzer cargo pp-rs 0.2.1 token/Punct#Comma#) => {
245 if first_param {
246 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token));
247 }
248
249 let (param_name, param_location) =
250 self.expect_lexer_identrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_ident().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
251 if define.paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&param_name) {
252 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
253 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::DuplicateParameterrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#DuplicateParameter#,
254 param_location,
255 )));
256 }
257 define.paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(param_name, define.paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().());
258 }
259 _ => {
260 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token));
261 }
262 }
263 }
264 }
265
266 // Tokens until the newline are that define's tokens (including the current one)
267 loop {
268 if token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().==rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq(). rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# {
269 break;
270 }
271 define.tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(convert_lexer_token_to_steprust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token_to_step().(token)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
272 token = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
273 }
274
275 // Defines are allowed to be redefined if they are exactly the same up to token locations.
276 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(previous_define) = self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&define.namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name.) {
277 if legal_redefinitionrust-analyzer cargo pp-rs 0.2.1 pp/legal_redefinition().(&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().previous_define, &define) {
278 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
279 } else {
280 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
281 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::DefineRedefinedrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#DefineRedefined#,
282 name_location,
283 )))
284 }
285 } else {
286 self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(define.namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(define));
287 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
288 }
289 }
290
291 fn add_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]add_define().(
292 &mut self,
293 name: &str,
294 content: &str,
295 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), (PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)> {
296 let mut define = Definerust-analyzer cargo pp-rs 0.2.1 pp/Define# {
297 namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name.: name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
298 function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like.: false,
299 paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().(),
300 tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(),
301 };
302
303 // Convert the content to tokens and add it to the define.
304 let mut lexer = lexerrust-analyzer cargo pp-rs 0.2.1 lexer/::Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#::newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]new().(content);
305 loop {
306 match lexer.nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`][Iterator]next().() {
307 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(lexer_token)) => {
308 // Skip over newlines (the lexer always adds a newline, which would cause an
309 // error in convert_lexer_token).
310 if lexer_token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().==rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq(). rust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`PartialEq<Self>`]eq().LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# {
311 continue;
312 }
313
314 define.tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(convert_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token().(lexer_token)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
315 }
316
317 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err)) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err),
318 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break,
319 }
320 }
321
322 // Note this overwrites existing defines, we might want to add an option to make this
323 // an error in the future.
324 self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(define.namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(define));
325
326 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
327 }
328
329 fn parse_undef_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_undef_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
330 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
331 return self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().();
332 }
333
334 let (name, name_location) = self.expect_lexer_identrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_ident().(directive_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
335 // TODO check predefine
336 // It is valid to undef a name that is not defined.
337 self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(&name);
338
339 self.expect_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_token().(LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#, name_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
340 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
341 }
342
343 fn parse_error_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_error_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
344 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
345 self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().()
346 } else {
347 // TODO consume the rest of the line and make a nice error message
348 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
349 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::ErrorDirectiverust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#ErrorDirective#,
350 directive_location,
351 )))
352 }
353 }
354
355 fn parse_line_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_line_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
356 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
357 return self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().();
358 }
359
360 let line = self.gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
361
362 let mut parser = if_parserrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/::IfParserrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/IfParser#::newrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]new().(line, &self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines., directive_location, false);
363 let line = parser.evaluate_expressionrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]evaluate_expression().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
364
365 // Validates that the line is between 0 and 2^31 as per the C standard.
366 if line as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().32) {
367 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_line_overflow_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_line_overflow_error().(directive_location));
368 }
369 self.line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#line_offset. = line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().directive_location.linerust-analyzer cargo pp-rs 0.2.1 token/Location#line. as i64;
370
371 if parser.peekrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
372 // TODO figure out what to do with the file, either number or string?
373 let _source_id = parser.evaluate_expressionrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]evaluate_expression().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
374 }
375
376 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = parser.peekrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
377 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
378 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedTokenrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedToken#(token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.),
379 token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
380 )));
381 }
382
383 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
384 }
385
386 fn evaluate_if_expressionrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]evaluate_if_expression().(&mut self, location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#, line: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<bool> {
387 let mut parser = if_parserrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/::IfParserrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/IfParser#::newrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]new().(line, &self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines., location, true);
388 let res = parser.evaluate_expressionrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]evaluate_expression().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
389
390 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = parser.peekrust-analyzer cargo pp-rs 0.2.1 pp/if_parser/impl#[`IfParser<'macros>`]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
391 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
392 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedTokenrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedToken#(token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.),
393 token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
394 )))
395 } else {
396 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().0)
397 }
398 }
399
400 fn parse_if_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_if_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
401 self.parse_if_like_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_if_like_directive().(directive_location, |this, location| {
402 let line = this.gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
403 this.evaluate_if_expressionrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]evaluate_if_expression().(location, line)
404 })
405 }
406
407 fn parse_ifdef_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_ifdef_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
408 self.parse_if_like_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_if_like_directive().(directive_location, |this, location| {
409 let (name, name_location) = this.expect_lexer_identrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_ident().(location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
410 this.expect_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_token().(LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#, name_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
411 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(this.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&name))
412 })
413 }
414
415 fn parse_ifndef_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_ifndef_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
416 self.parse_if_like_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_if_like_directive().(directive_location, |this, location| {
417 let (name, name_location) = this.expect_lexer_identrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_ident().(location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
418 this.expect_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_token().(LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#, name_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
419 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().this.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&name))
420 })
421 }
422
423 fn parse_elif_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_elif_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
424 self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. = true;
425
426 // Do checks that the #elif block is well structured even if skipping.
427 let block = self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
428 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::ElifOutsideOfBlockrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#ElifOutsideOfBlock#,
429 directive_location,
430 )))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
431
432 if block.had_elserust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_else. {
433 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
434 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::ElifAfterElserust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#ElifAfterElse#,
435 directive_location,
436 )));
437 }
438
439 // The condition isn't parsed if it doesn't need to (and doesn't produce errors).
440 if block.outer_skippedrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#outer_skipped. || block.had_valid_segmentrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_valid_segment. {
441 return self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().();
442 }
443
444 let line = self.gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
445 if self.evaluate_if_expressionrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]evaluate_if_expression().(directive_location, line)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
446 self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. = false;
447 self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().had_valid_segmentrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_valid_segment. = true;
448 }
449
450 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
451 }
452
453 fn parse_else_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_else_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
454 self.expect_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_token().(LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#, directive_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
455
456 let block = self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
457 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::ElseOutsideOfBlockrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#ElseOutsideOfBlock#,
458 directive_location,
459 )))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
460
461 // #else can only appear once in a block.
462 if block.had_elserust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_else. {
463 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
464 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::MoreThanOneElserust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#MoreThanOneElse#,
465 directive_location,
466 )))
467 } else {
468 self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. = block.outer_skippedrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#outer_skipped. || block.had_valid_segmentrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_valid_segment.;
469 block.had_elserust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_else. = true;
470 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
471 }
472 }
473
474 fn parse_endif_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_endif_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
475 let block = self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
476 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::EndifOutsideOfBlockrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#EndifOutsideOfBlock#,
477 directive_location,
478 )))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
479
480 // After #endif we start processing tokens iff the block was not skipped.
481 self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. = block.outer_skippedrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#outer_skipped.;
482
483 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
484 self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().()
485 } else {
486 self.expect_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_lexer_token().(LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#, directive_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
487 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
488 }
489 }
490
491 fn parse_if_like_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_if_like_directive().(
492 &mut self,
493 directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#,
494 parse: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<bool>,
495 ) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<()> {
496 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
497 self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DirectiveBlockrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock# {
498 start_locationrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#start_location.: directive_location,
499 had_valid_segmentrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_valid_segment.: false,
500 had_elserust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_else.: false,
501 outer_skippedrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#outer_skipped.: true,
502 });
503 self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().()
504 } else {
505 let result = parse(self, directive_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
506 self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().result;
507
508 self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DirectiveBlockrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock# {
509 start_locationrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#start_location.: directive_location,
510 had_valid_segmentrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_valid_segment.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping.,
511 had_elserust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#had_else.: false,
512 outer_skippedrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#outer_skipped.: false,
513 });
514 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
515 }
516 }
517
518 fn parse_version_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_version_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
519 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
520 self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
521 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
522 } else {
523 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
524 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.: directive_location,
525 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Versionrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Version#(Versionrust-analyzer cargo pp-rs 0.2.1 token/Version# {
526 tokensrust-analyzer cargo pp-rs 0.2.1 token/Version#tokens.: self.gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
527 is_first_directiverust-analyzer cargo pp-rs 0.2.1 token/Version#is_first_directive.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(self.had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive. || self.had_non_directive_tokenrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_non_directive_token.),
528 has_comments_beforerust-analyzer cargo pp-rs 0.2.1 token/Version#has_comments_before.: self.lexerrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#lexer..had_commentsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]had_comments().(),
529 }),
530 })
531 }
532 }
533
534 fn parse_extension_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_extension_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
535 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
536 self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
537 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
538 } else {
539 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
540 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.: directive_location,
541 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Extensionrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Extension#(Extensionrust-analyzer cargo pp-rs 0.2.1 token/Extension# {
542 tokensrust-analyzer cargo pp-rs 0.2.1 token/Extension#tokens.: self.gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
543 has_non_directive_beforerust-analyzer cargo pp-rs 0.2.1 token/Extension#has_non_directive_before.: self.had_non_directive_tokenrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_non_directive_token.,
544 }),
545 })
546 }
547 }
548
549 fn parse_pragma_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_pragma_directive().(&mut self, directive_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
550 if self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
551 self.consume_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]consume_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
552 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
553 } else {
554 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
555 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.: directive_location,
556 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Pragmarust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Pragma#(Pragmarust-analyzer cargo pp-rs 0.2.1 token/Pragma# {
557 tokensrust-analyzer cargo pp-rs 0.2.1 token/Pragma#tokens.: self.gather_until_newlinerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]gather_until_newline().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
558 }),
559 })
560 }
561 }
562
563 fn parse_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_directive().(&mut self, hash_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
564 let token = self.expect_a_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]expect_a_lexer_token().(hash_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
565
566 if let LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(ref directive) = token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
567 match directive.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
568 // TODO elif line
569 "error" => self.parse_error_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_error_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
570 "line" => self.parse_line_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_line_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
571
572 "define" => self.parse_define_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_define_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
573 "undef" => self.parse_undef_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_undef_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
574
575 "if" => self.parse_if_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_if_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
576 "ifdef" => self.parse_ifdef_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_ifdef_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
577 "ifndef" => self.parse_ifndef_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_ifndef_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
578 "elif" => self.parse_elif_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_elif_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
579 "else" => self.parse_else_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_else_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
580 "endif" => self.parse_endif_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_endif_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
581
582 "version" => {
583 let result = self.parse_version_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_version_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.);
584 self.had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive. = true;
585 return result;
586 }
587 "extension" => {
588 let result = self.parse_extension_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_extension_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.);
589 self.had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive. = true;
590 return result;
591 }
592 "pragma" => {
593 let result = self.parse_pragma_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_pragma_directive().(token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.);
594 self.had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive. = true;
595 return result;
596 }
597 _ => {
598 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
599 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
600 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnknownDirectiverust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnknownDirective#,
601 token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.,
602 )));
603 }
604 }
605 }
606 self.had_directiverust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_directive. = true;
607 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
608 } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
609 make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(token).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
610 } else {
611 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
612 }
613 }
614 }
615
616 impl<'a> MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer# for DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#<'a> {
617 fn steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`][MeLexer]step().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
618 let step = (|| {
619 // TODO: if we are skipping invalid characters should be allowed.
620 let lexer_token = self.get_lexer_tokenrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]get_lexer_token().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
621 match lexer_token.valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value. {
622 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine# => Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
623 LexerTokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Hashrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Hash# => {
624 if lexer_token.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Token#start_of_line. {
625 self.parse_directiverust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]parse_directive().(lexer_token.locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.)
626 } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
627 make_unexpected_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_unexpected_error().(lexer_token).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
628 } else {
629 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
630 }
631 }
632
633 _ => {
634 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.skippingrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#skipping. {
635 self.had_non_directive_tokenrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#had_non_directive_token. = true;
636 convert_lexer_token_to_steprust-analyzer cargo pp-rs 0.2.1 pp/convert_lexer_token_to_step().(lexer_token)
637 } else {
638 Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
639 }
640 }
641 }
642 })();
643
644 if step rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#) {
645 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block) = self.blocksrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#blocks..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() {
646 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
647 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnfinishedBlockrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnfinishedBlock#,
648 block.start_locationrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveBlock#start_location.,
649 )));
650 }
651 }
652
653 step
654 }
655
656 fn get_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`][MeLexer]get_define().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#>> {
657 self.definesrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#defines..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name)
658 }
659
660 fn apply_line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`][MeLexer]apply_line_offset().(&self, line: u32, location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<u32> {
661 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset_line) = u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<i64>`]try_from().(line as i64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().self.line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#line_offset.) {
662 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset_line)
663 } else {
664 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(make_line_overflow_errorrust-analyzer cargo pp-rs 0.2.1 pp/make_line_overflow_error().(location))
665 }
666 }
667 }
668
669 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
670 struct MacroProcessorrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor# {
671 define_invocationsrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_invocations.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DefineInvocationrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#>,
672 defines_being_expandedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#defines_being_expanded.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
673
674 peekedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#peeked.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>>,
675 define_linerust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_line.: u32,
676 }
677
678 impl MacroProcessorrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor# {
679 fn start_define_invocationrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]start_define_invocation().(
680 &mut self,
681 name: &str,
682 location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#,
683 lexer: &mut dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#,
684 ) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<bool> {
685 // Defines can be expanding only once, it is not possible to do recursive defines
686 if self.defines_being_expandedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#defines_being_expanded..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(name) {
687 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
688 }
689
690 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(define) = lexer.get_definerust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#get_define().(name) {
691 let mut invocation = DefineInvocationrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation# {
692 definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define.: define.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().(),
693 define_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define_position.: 0,
694
695 parametersrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameters.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(),
696 parameter_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_position.: 0,
697 parameter_expandingrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_expanding.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::usizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX.,
698 };
699
700 // If this is a not a function-like define, __LINE__ inside the define is the line of the first
701 // character of the invocation. Only the line of the top-level invocation counts.
702 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_expanding_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]is_expanding_define().() {
703 self.define_linerust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_line. = location.linerust-analyzer cargo pp-rs 0.2.1 token/Location#line.;
704 }
705
706 if invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..function_likerust-analyzer cargo pp-rs 0.2.1 pp/Define#function_like. {
707 let lparen_location = match self.step_no_continuerust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step_no_continue().(lexer) {
708 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
709 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftParen#),
710 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
711 }) => location,
712
713 // Function-like macros are not processed if there is no ( right after the identifier
714 token => {
715 self.peekedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#peeked. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token);
716 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
717 }
718 };
719
720 // TODO still bail out if define was undefined until now? This would match
721 // clang and GCC
722 let (parameters, closing_location) =
723 self.parse_define_call_argumentsrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]parse_define_call_arguments().(lexer, lparen_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
724
725 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_expanding_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]is_expanding_define().() {
726 self.define_linerust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_line. = closing_location.linerust-analyzer cargo pp-rs 0.2.1 token/Location#line.;
727 }
728
729 // Check for the number of arguments.
730 match parameters.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][Ord]cmp().(&invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().()) {
731 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => {
732 let params_empty = parameters.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 && parameters[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().();
733 let expects_zero_args = invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().();
734
735 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(params_empty && expects_zero_args) {
736 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
737 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::TooManyDefineArgumentsrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#TooManyDefineArguments#,
738 lparen_location,
739 )));
740 }
741 }
742 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => {
743 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
744 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::TooFewDefineArgumentsrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#TooFewDefineArguments#,
745 lparen_location,
746 )));
747 }
748 _ => {}
749 }
750
751 // Fully expand the parameters
752 for parameter in parameters {
753 invocation
754 .parametersrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameters.
755 .pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(self.expand_parameterrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]expand_parameter().(lexer, parameter)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
756 }
757 }
758
759 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self
760 .defines_being_expandedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#defines_being_expanded.
761 .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()));
762 self.define_invocationsrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_invocations..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(invocation);
763
764 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true);
765 }
766
767 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false)
768 }
769
770 // Parse the arguments of the function-like define starting after the first (. Also returns
771 // the location of the closing ).
772 fn parse_define_call_argumentsrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]parse_define_call_arguments().(
773 &mut self,
774 lexer: &mut dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#,
775 mut current_location: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#,
776 ) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>>, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)> {
777 let mut paren_nesting = 0u32;
778 let mut arguments = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]];
779
780 loop {
781 // Get the next token (without additional expansion)
782 let token = match self.steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step().(lexer) {
783 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#) => continue,
784 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#) => {
785 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
786 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedEndOfInputrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedEndOfInput#,
787 current_location,
788 )));
789 }
790 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err @ StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#(_)) => {
791 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err);
792 }
793 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token) => token,
794 };
795
796 current_location = token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.;
797
798 // Handle special tokens
799 match token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value. {
800 // Avoid overflow on parenthesis nesting counting.
801 TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftParen#) => match paren_nesting.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]checked_add().(1) {
802 // TODO figure out a way to cover this code path? Maybe make it a max nesting
803 // so that it can be set to a small value?
804 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
805 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#((
806 PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::IntegerOverflowrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#IntegerOverflow#,
807 current_location,
808 )));
809 }
810 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => paren_nesting = v,
811 },
812
813 TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#RightParen#) => {
814 // Return the arguments when we find our )
815 if paren_nesting rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 {
816 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((arguments, token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.));
817 }
818 paren_nesting rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign().1;
819 }
820
821 TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Commarust-analyzer cargo pp-rs 0.2.1 token/Punct#Comma#) => {
822 // Commas outside of () split arguments and must not be added to them.
823 if paren_nesting rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 {
824 arguments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().());
825 continue;
826 }
827 }
828
829 _ => {}
830 }
831
832 arguments.last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(token);
833 }
834 }
835
836 fn expand_parameterrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]expand_parameter().(&self, lexer: &mut dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#, parameter: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>> {
837 struct ExpandParameterLexerrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#<'a> {
838 parent_lexerrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#parent_lexer.: &'a dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#,
839 expanderrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#expander.: &'a MacroProcessorrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#,
840 tokensrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#tokens.: &'a Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#>,
841 positionrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#position.: usize,
842 }
843
844 impl<'a> MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer# for ExpandParameterLexerrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#<'a> {
845 fn steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[`ExpandParameterLexer<'a>`][MeLexer]step().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
846 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = self.tokensrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#tokens..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.positionrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#position.) {
847 self.positionrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#position. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
848 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token.clonerust-analyzer cargo pp-rs 0.2.1 token/impl#[Token][Clone]clone().())
849 } else {
850 Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
851 }
852 }
853
854 fn get_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`ExpandParameterLexer<'a>`][MeLexer]get_define().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<Definerust-analyzer cargo pp-rs 0.2.1 pp/Define#>> {
855 if self.expanderrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#expander..defines_being_expandedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#defines_being_expanded..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(name) {
856 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
857 } else {
858 self.parent_lexerrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#parent_lexer..get_definerust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#get_define().(name)
859 }
860 }
861
862 fn apply_line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`ExpandParameterLexer<'a>`][MeLexer]apply_line_offset().(&self, line: u32, _: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<u32> {
863 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(line)
864 }
865 }
866
867 let mut parameter_lexer = ExpandParameterLexerrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer# {
868 parent_lexerrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#parent_lexer.: lexer,
869 expanderrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#expander.: self,
870 tokensrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#tokens.: &parameter,
871 positionrust-analyzer cargo pp-rs 0.2.1 pp/ExpandParameterLexer#position.: 0,
872 };
873
874 let mut processor: MacroProcessorrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor# = Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor][Default]default().();
875 let mut expanded_parameters = Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().();
876 loop {
877 match processor.steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step().(&mut parameter_lexer) {
878 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err @ StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#(_)) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err),
879 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expanded_parameters),
880 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#) => continue,
881 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token) => {
882 if let TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Ident#(name) = &token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value. {
883 if processor.start_define_invocationrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]start_define_invocation().(
884 name,
885 token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
886 &mut parameter_lexer,
887 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
888 continue;
889 }
890 }
891
892 expanded_parameters.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(token);
893 }
894 }
895 }
896 }
897
898 fn is_expanding_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]is_expanding_define().(&self) -> bool {
899 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.define_invocationsrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_invocations..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()
900 }
901
902 fn step_internalrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step_internal().(&mut self, lexer: &mut dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
903 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(step) = self.peekedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#peeked..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
904 return step;
905 }
906
907 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(invocation) = self.define_invocationsrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_invocations..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() {
908 // Keep expanding the parameters
909 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(argument) = invocation.parametersrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameters..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(invocation.parameter_expandingrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_expanding.) {
910 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = argument.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(invocation.parameter_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_position.) {
911 invocation.parameter_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_position. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
912 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token.clonerust-analyzer cargo pp-rs 0.2.1 token/impl#[Token][Clone]clone().());
913 } else {
914 invocation.parameter_expandingrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_expanding. = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::usizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX.;
915 return Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
916 }
917 }
918
919 // Take tokens from the define definition.
920 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..tokensrust-analyzer cargo pp-rs 0.2.1 pp/Define#tokens..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(invocation.define_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define_position.) {
921 invocation.define_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define_position. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
922
923 // We found a parameter! Start expanding it.
924 if let TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Ident#(name) = &token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value. {
925 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parameter_index) = invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..paramsrust-analyzer cargo pp-rs 0.2.1 pp/Define#params..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name) {
926 invocation.parameter_expandingrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_expanding. = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().parameter_index;
927 invocation.parameter_positionrust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#parameter_position. = 0;
928 return Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
929 }
930 }
931
932 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token.clonerust-analyzer cargo pp-rs 0.2.1 token/impl#[Token][Clone]clone().());
933 } else {
934 self.defines_being_expandedrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#defines_being_expanded..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]remove().(&invocation.definerust-analyzer cargo pp-rs 0.2.1 pp/DefineInvocation#define..namerust-analyzer cargo pp-rs 0.2.1 pp/Define#name.);
935 self.define_invocationsrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_invocations..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().();
936 return Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
937 }
938 }
939
940 lexer.steprust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#step().()
941 }
942
943 fn steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step().(&mut self, lexer: &mut dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
944 let token = self.step_internalrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step_internal().(lexer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
945
946 if let TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Ident#(name) = &token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value. {
947 if name rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."__LINE__" {
948 // When inside a define, __LINE__ is that define's line.
949 let line = if self.is_expanding_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]is_expanding_define().() {
950 self.define_linerust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#define_line.
951 } else {
952 token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location..linerust-analyzer cargo pp-rs 0.2.1 token/Location#line.
953 };
954
955 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token# {
956 valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Integerrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Integer#(Integerrust-analyzer cargo pp-rs 0.2.1 token/Integer# {
957 valuerust-analyzer cargo pp-rs 0.2.1 token/Integer#value.: lexer.apply_line_offsetrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#apply_line_offset().(line, token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as u64,
958 signedrust-analyzer cargo pp-rs 0.2.1 token/Integer#signed.: false,
959 widthrust-analyzer cargo pp-rs 0.2.1 token/Integer#width.: 32,
960 }),
961 locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.: token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
962 });
963 }
964 }
965
966 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token)
967 }
968
969 fn step_no_continuerust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step_no_continue().(&mut self, lexer: &mut dyn MeLexerrust-analyzer cargo pp-rs 0.2.1 pp/MeLexer#) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
970 loop {
971 let step = self.steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step().(lexer);
972 if step rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() {
973 return step;
974 }
975 }
976 }
977 }
978
979 pub struct Preprocessorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#<'a> {
980 directive_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#directive_processor.: DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#<'a>,
981 macro_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#macro_processor.: MacroProcessorrust-analyzer cargo pp-rs 0.2.1 pp/MacroProcessor#,
982 }
983
984 impl<'a> Preprocessorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#<'a> {
985 pub fn newrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`]new().(input: &'a str) -> Preprocessorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor# {
986 Preprocessorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor# {
987 directive_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#directive_processor.: DirectiveProcessorrust-analyzer cargo pp-rs 0.2.1 pp/DirectiveProcessor#::newrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]new().(input),
988 macro_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#macro_processor.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor][Default]default().(),
989 }
990 }
991
992 pub fn add_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`]add_define().(
993 &mut self,
994 name: &str,
995 content: &str,
996 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), (PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)> {
997 self.directive_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#directive_processor..add_definerust-analyzer cargo pp-rs 0.2.1 pp/impl#[`DirectiveProcessor<'a>`]add_define().(name, content)
998 }
999
1000 fn steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`]step().(&mut self) -> Steprust-analyzer cargo pp-rs 0.2.1 pp/Step#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#> {
1001 let token = self.macro_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#macro_processor..steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]step().(&mut self.directive_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#directive_processor.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1002
1003 // Is this token the start of a new macro?
1004 if let TokenValuerust-analyzer cargo pp-rs 0.2.1 token/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 token/TokenValue#Ident#(name) = &token.valuerust-analyzer cargo pp-rs 0.2.1 token/Token#value. {
1005 // Returns Continue if it started the define, token otherwise.
1006 if self.macro_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#macro_processor..start_define_invocationrust-analyzer cargo pp-rs 0.2.1 pp/impl#[MacroProcessor]start_define_invocation().(
1007 name,
1008 token.locationrust-analyzer cargo pp-rs 0.2.1 token/Token#location.,
1009 &mut self.directive_processorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#directive_processor.,
1010 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
1011 return Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
1012 }
1013 }
1014
1015 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token)
1016 }
1017 }
1018
1019 pub type PreprocessorItemrust-analyzer cargo pp-rs 0.2.1 pp/PreprocessorItem# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Tokenrust-analyzer cargo pp-rs 0.2.1 token/Token#, (PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)>;
1020
1021 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Preprocessorrust-analyzer cargo pp-rs 0.2.1 pp/Preprocessor#<'a> {
1022 type Itemrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`][Iterator]Item# = PreprocessorItemrust-analyzer cargo pp-rs 0.2.1 pp/PreprocessorItem#;
1023
1024 fn nextrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1025 loop {
1026 match self.steprust-analyzer cargo pp-rs 0.2.1 pp/impl#[`Preprocessor<'a>`]step().() {
1027 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token)),
1028 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Errorrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Error#(err)) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err)),
1029 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Finishedrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Finished#) => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1030 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(StepExitrust-analyzer cargo pp-rs 0.2.1 pp/StepExit#::Continuerust-analyzer cargo pp-rs 0.2.1 pp/StepExit#Continue#) => continue,
1031 };
1032 }
1033 }
1034 }