Debian Codegraph @

src/ast/archive.rs

raw symbols SCIP
1 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::{ArchiveMemberrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMember#, ArchiveMembersrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMembers#};
2 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::*;
3 use rowanrust-analyzer cargo rowan 0.16.1 crate/::astrust-analyzer cargo rowan 0.16.1 ast/::AstNoderust-analyzer cargo rowan 0.16.1 ast/AstNode#;
4
5 impl ArchiveMembersrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMembers# {
6 /// Get the archive name (e.g., "libfoo.a" from "libfoo.a(bar.o)")
7 pub fn archive_namerust-analyzer cargo makefile-lossless 0.3.40 ast/archive/impl#[ArchiveMembers]archive_name().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
8 // Get the first identifier before the opening parenthesis
9 for element in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[ArchiveMembers][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
10 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = element.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
11 if token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# {
12 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
13 } else if token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# {
14 // Reached the opening parenthesis without finding an identifier
15 break;
16 }
17 }
18 }
19 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
20 }
21
22 /// Get all member nodes
23 pub fn membersrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/impl#[ArchiveMembers]members().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = ArchiveMemberrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMember#> + '_ {
24 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[ArchiveMembers][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(ArchiveMemberrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMember#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[ArchiveMember][AstNode]cast().)
25 }
26
27 /// Get all member names as strings
28 pub fn member_namesrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/impl#[ArchiveMembers]member_names().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
29 self.membersrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/impl#[ArchiveMembers]members().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|m| m.textrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/impl#[ArchiveMember]text().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
30 }
31 }
32
33 impl ArchiveMemberrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMember# {
34 /// Get the text of this archive member
35 pub fn textrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/impl#[ArchiveMember]text().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
36 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[ArchiveMember][AstNode]syntax().().textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
37 }
38 }
39
40 #[cfg(test)]
41 mod testsrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/tests/ {
42 use superrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/::*;
43 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().;
44 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::ARCHIVE_MEMBERSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBERS#;
45
46 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
47 fn test_archive_member_parsingrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/tests/test_archive_member_parsing().() {
48 // Test basic archive member syntax
49 let input = "libfoo.a(bar.o): bar.c\n\tgcc -c bar.c -o bar.o\n\tar r libfoo.a bar.o\n";
50 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
51 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
52 parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(),
53 "Should parse archive member without errors"
54 );
55
56 let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().();
57 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
58 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
59
60 // Check that the target is recognized as an archive member
61 let target_text = rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
62 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(target_text, "libfoo.a(bar.o)");
63 }
64
65 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
66 fn test_archive_member_multiple_membersrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/tests/test_archive_member_multiple_members().() {
67 // Test archive with multiple members
68 let input = "libfoo.a(bar.o baz.o): bar.c baz.c\n\tgcc -c bar.c baz.c\n\tar r libfoo.a bar.o baz.o\n";
69 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
70 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
71 parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(),
72 "Should parse multiple archive members"
73 );
74
75 let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().();
76 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
77 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
78 }
79
80 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
81 fn test_archive_member_in_dependenciesrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/tests/test_archive_member_in_dependencies().() {
82 // Test archive members in dependencies
83 let input =
84 "program: main.o libfoo.a(bar.o) libfoo.a(baz.o)\n\tgcc -o program main.o libfoo.a\n";
85 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
86 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
87 parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(),
88 "Should parse archive members in dependencies"
89 );
90
91 let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().();
92 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
93 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
94 }
95
96 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
97 fn test_archive_member_with_variablesrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/tests/test_archive_member_with_variables().() {
98 // Test archive members with variable references
99 let input = "$(LIB)($(OBJ)): $(SRC)\n\t$(CC) -c $(SRC)\n\t$(AR) r $(LIB) $(OBJ)\n";
100 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
101 // Variable references in archive members should parse without errors
102 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
103 parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(),
104 "Should parse archive members with variables"
105 );
106 }
107
108 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
109 fn test_archive_member_ast_accessrust-analyzer cargo makefile-lossless 0.3.40 ast/archive/tests/test_archive_member_ast_access().() {
110 // Test that we can access archive member nodes through the AST
111 let input = "libtest.a(foo.o bar.o): foo.c bar.c\n\tgcc -c foo.c bar.c\n";
112 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
113 let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().();
114
115 // Find archive member nodes in the syntax tree
116 let archive_member_count = makefile
117 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
118 .descendantsrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]descendants().()
119 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|n| n.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().ARCHIVE_MEMBERSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBERS#)
120 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().();
121
122 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
123 archive_member_count >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0,
124 "Should find ARCHIVE_MEMBERS nodes in AST"
125 );
126 }
127 }