Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rust/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rust/ql/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/StructFieldImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ module Impl {

/** Holds if this record field is named `name` and belongs to the struct `s`. */
predicate isStructField(Struct s, string name) { this = s.getStructField(name) }

override string toStringImpl() { result = concat(int i | | this.toStringPart(i) order by i) }

private string toStringPart(int index) {
index = 0 and result = this.getVisibility().toAbbreviatedString() + " "
or
index = 1 and result = this.getName().getText()
or
index = 2 and result = ": "
or
index = 3 and result = this.getTypeRepr().toAbbreviatedString()
}
}
}
12 changes: 10 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/VisibilityImpl.qll
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `Visibility`.
*
Expand All @@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.Visibility
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* A visibility modifier.
*
Expand All @@ -21,5 +21,13 @@ module Impl {
* //^^^
* ```
*/
class Visibility extends Generated::Visibility { }
class Visibility extends Generated::Visibility {
override string toStringImpl() { result = this.toAbbreviatedString() }

override string toAbbreviatedString() {
result = "pub(" + this.getPath().toAbbreviatedString() + ")"
or
not this.hasPath() and result = "pub"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ getBody
getName
| gen_macro_def.rs:4:5:9:5 | MacroDef | gen_macro_def.rs:7:15:7:24 | vec_of_two |
getVisibility
| gen_macro_def.rs:4:5:9:5 | MacroDef | gen_macro_def.rs:7:5:7:7 | Visibility |
| gen_macro_def.rs:4:5:9:5 | MacroDef | gen_macro_def.rs:7:5:7:7 | pub |
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ getName
| gen_module.rs:5:1:7:1 | mod bar | gen_module.rs:5:5:5:7 | bar |
| lib.rs:1:1:1:19 | mod gen_module | lib.rs:1:9:1:18 | gen_module |
getVisibility
| lib.rs:1:1:1:19 | mod gen_module | lib.rs:1:1:1:3 | Visibility |
| lib.rs:1:1:1:19 | mod gen_module | lib.rs:1:1:1:3 | pub |
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
instances
| gen_struct_field.rs:7:16:7:21 | StructField | isUnsafe: | no |
| gen_struct_field.rs:7:16:7:21 | x: i32 | isUnsafe: | no |
getAttr
getDefault
getName
| gen_struct_field.rs:7:16:7:21 | StructField | gen_struct_field.rs:7:16:7:16 | x |
| gen_struct_field.rs:7:16:7:21 | x: i32 | gen_struct_field.rs:7:16:7:16 | x |
getTypeRepr
| gen_struct_field.rs:7:16:7:21 | StructField | gen_struct_field.rs:7:19:7:21 | i32 |
| gen_struct_field.rs:7:16:7:21 | x: i32 | gen_struct_field.rs:7:19:7:21 | i32 |
getVisibility
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
instances
| gen_struct_field_list.rs:7:14:7:31 | StructFieldList |
getField
| gen_struct_field_list.rs:7:14:7:31 | StructFieldList | 0 | gen_struct_field_list.rs:7:16:7:21 | StructField |
| gen_struct_field_list.rs:7:14:7:31 | StructFieldList | 1 | gen_struct_field_list.rs:7:24:7:29 | StructField |
| gen_struct_field_list.rs:7:14:7:31 | StructFieldList | 0 | gen_struct_field_list.rs:7:16:7:21 | x: i32 |
| gen_struct_field_list.rs:7:14:7:31 | StructFieldList | 1 | gen_struct_field_list.rs:7:24:7:29 | y: i32 |
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ getName
| gen_trait.rs:10:1:10:57 | trait Foo | gen_trait.rs:10:11:10:13 | Foo |
getTypeBoundList
getVisibility
| gen_trait.rs:10:1:10:57 | trait Foo | gen_trait.rs:10:1:10:3 | Visibility |
| gen_trait.rs:10:1:10:57 | trait Foo | gen_trait.rs:10:1:10:3 | pub |
getWhereClause
| gen_trait.rs:10:1:10:57 | trait Foo | gen_trait.rs:10:32:10:54 | WhereClause |
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
instances
| gen_visibility.rs:7:7:7:9 | Visibility |
| lib.rs:1:1:1:3 | Visibility |
| gen_visibility.rs:7:7:7:9 | pub |
| lib.rs:1:1:1:3 | pub |
getPath
42 changes: 21 additions & 21 deletions rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ lib.rs:
# 1| [SourceFile] SourceFile
# 1| getItem(0): [Module] mod call
# 1| getName(): [Name] call
# 1| getVisibility(): [Visibility] Visibility
# 1| getVisibility(): [Visibility] pub
# 2| getItem(1): [Module] mod macro_expansion
# 2| getName(): [Name] macro_expansion
# 2| getVisibility(): [Visibility] Visibility
# 2| getVisibility(): [Visibility] pub
macro_expansion.rs:
# 1| [SourceFile] SourceFile
# 1| getItem(0): [Use] use proc_macro::{...}
Expand Down Expand Up @@ -223,7 +223,7 @@ macro_expansion.rs:
# 11| getSegment(): [PathSegment] inner_1
# 11| getIdentifier(): [NameRef] inner_1
# 4| getName(): [Name] foo
# 4| getVisibility(): [Visibility] Visibility
# 4| getVisibility(): [Visibility] pub
# 4| getItem(1): [Function] fn foo_new
# 4| getParamList(): [ParamList] ParamList
# 4| getFunctionBody(): [BlockExpr] { ... }
Expand Down Expand Up @@ -271,7 +271,7 @@ macro_expansion.rs:
# 11| getSegment(): [PathSegment] inner_1
# 11| getIdentifier(): [NameRef] inner_1
# 4| getName(): [Name] foo_new
# 4| getVisibility(): [Visibility] Visibility
# 4| getVisibility(): [Visibility] pub
# 3| getAttr(0): [Attr] Attr
# 3| getMeta(): [Meta] Meta
# 3| getPath(): [Path] add_one
Expand All @@ -286,13 +286,13 @@ macro_expansion.rs:
# 16| getFunctionBody(): [BlockExpr] { ... }
# 16| getStmtList(): [StmtList] StmtList
# 16| getName(): [Name] bar_0
# 16| getVisibility(): [Visibility] Visibility
# 16| getVisibility(): [Visibility] pub
# 16| getItem(1): [Function] fn bar_0_new
# 16| getParamList(): [ParamList] ParamList
# 16| getFunctionBody(): [BlockExpr] { ... }
# 16| getStmtList(): [StmtList] StmtList
# 16| getName(): [Name] bar_0_new
# 16| getVisibility(): [Visibility] Visibility
# 16| getVisibility(): [Visibility] pub
# 15| getAttr(0): [Attr] Attr
# 15| getMeta(): [Meta] Meta
# 15| getPath(): [Path] add_one
Expand All @@ -305,13 +305,13 @@ macro_expansion.rs:
# 16| getFunctionBody(): [BlockExpr] { ... }
# 16| getStmtList(): [StmtList] StmtList
# 16| getName(): [Name] bar_1
# 16| getVisibility(): [Visibility] Visibility
# 16| getVisibility(): [Visibility] pub
# 16| getItem(1): [Function] fn bar_1_new
# 16| getParamList(): [ParamList] ParamList
# 16| getFunctionBody(): [BlockExpr] { ... }
# 16| getStmtList(): [StmtList] StmtList
# 16| getName(): [Name] bar_1_new
# 16| getVisibility(): [Visibility] Visibility
# 16| getVisibility(): [Visibility] pub
# 15| getAttr(0): [Attr] Attr
# 15| getMeta(): [Meta] Meta
# 15| getPath(): [Path] add_one
Expand Down Expand Up @@ -340,7 +340,7 @@ macro_expansion.rs:
# 22| getTokenTree(): [TokenTree] TokenTree
# 28| getItem(5): [Struct] struct S
# 28| getName(): [Name] S
# 28| getVisibility(): [Visibility] Visibility
# 28| getVisibility(): [Visibility] pub
# 30| getItem(6): [Impl] impl S { ... }
# 30| getAssocItemList(): [AssocItemList] AssocItemList
# 31| getAssocItem(0): [Function] (item with attribute macro expansion)
Expand Down Expand Up @@ -392,7 +392,7 @@ macro_expansion.rs:
# 31| getSegment(): [PathSegment] _print
# 31| getIdentifier(): [NameRef] _print
# 32| getName(): [Name] bzz_0
# 32| getVisibility(): [Visibility] Visibility
# 32| getVisibility(): [Visibility] pub
# 32| getItem(1): [Function] fn bzz_1
# 32| getParamList(): [ParamList] ParamList
# 32| getFunctionBody(): [BlockExpr] { ... }
Expand Down Expand Up @@ -440,7 +440,7 @@ macro_expansion.rs:
# 31| getSegment(): [PathSegment] _print
# 31| getIdentifier(): [NameRef] _print
# 32| getName(): [Name] bzz_1
# 32| getVisibility(): [Visibility] Visibility
# 32| getVisibility(): [Visibility] pub
# 32| getItem(2): [Function] fn bzz_2
# 32| getParamList(): [ParamList] ParamList
# 32| getFunctionBody(): [BlockExpr] { ... }
Expand Down Expand Up @@ -488,7 +488,7 @@ macro_expansion.rs:
# 31| getSegment(): [PathSegment] _print
# 31| getIdentifier(): [NameRef] _print
# 32| getName(): [Name] bzz_2
# 32| getVisibility(): [Visibility] Visibility
# 32| getVisibility(): [Visibility] pub
# 31| getAttr(0): [Attr] Attr
# 31| getMeta(): [Meta] Meta
# 31| getPath(): [Path] repeat
Expand All @@ -515,7 +515,7 @@ macro_expansion.rs:
# 44| getFunctionBody(): [BlockExpr] { ... }
# 44| getStmtList(): [StmtList] StmtList
# 44| getName(): [Name] x
# 44| getVisibility(): [Visibility] Visibility
# 44| getVisibility(): [Visibility] pub
# 43| getSelfTy(): [PathTypeRepr] S
# 43| getPath(): [Path] S
# 43| getSegment(): [PathSegment] S
Expand Down Expand Up @@ -700,7 +700,7 @@ macro_expansion.rs:
# 76| getIdentifier(): [NameRef] i32
# 78| getItem(16): [Struct] struct MyStruct
# 78| getFieldList(): [StructFieldList] StructFieldList
# 79| getField(0): [StructField] StructField
# 79| getField(0): [StructField] field: ...
# 79| getName(): [Name] field
# 79| getTypeRepr(): [MacroTypeRepr] MacroTypeRepr
# 79| getMacroCall(): [MacroCall] my_int!...
Expand Down Expand Up @@ -809,7 +809,7 @@ macro_expansion.rs:
# 83| getIdentifier(): [NameRef] derive
# 83| getTokenTree(): [TokenTree] TokenTree
# 84| getFieldList(): [StructFieldList] StructFieldList
# 85| getField(0): [StructField] StructField
# 85| getField(0): [StructField] field: usize
# 85| getName(): [Name] field
# 85| getTypeRepr(): [PathTypeRepr] usize
# 85| getPath(): [Path] usize
Expand Down Expand Up @@ -990,13 +990,13 @@ macro_expansion.rs:
# 98| getTokenTree(): [TokenTree] TokenTree
# 99| getName(): [Name] MyDeriveUnion
# 99| getStructFieldList(): [StructFieldList] StructFieldList
# 100| getField(0): [StructField] StructField
# 100| getField(0): [StructField] field1: usize
# 100| getName(): [Name] field1
# 100| getTypeRepr(): [PathTypeRepr] usize
# 100| getPath(): [Path] usize
# 100| getSegment(): [PathSegment] usize
# 100| getIdentifier(): [NameRef] usize
# 101| getField(1): [StructField] StructField
# 101| getField(1): [StructField] field2: f64
# 101| getName(): [Name] field2
# 101| getTypeRepr(): [PathTypeRepr] f64
# 101| getPath(): [Path] f64
Expand Down Expand Up @@ -2003,7 +2003,7 @@ proc_macro.rs:
# 5| getPath(): [Path] TokenStream
# 5| getSegment(): [PathSegment] TokenStream
# 5| getIdentifier(): [NameRef] TokenStream
# 5| getVisibility(): [Visibility] Visibility
# 5| getVisibility(): [Visibility] pub
# 20| getItem(3): [Function] fn add_one
# 21| getParamList(): [ParamList] ParamList
# 21| getParam(0): [Param] ...: TokenStream
Expand Down Expand Up @@ -2434,7 +2434,7 @@ proc_macro.rs:
# 21| getPath(): [Path] TokenStream
# 21| getSegment(): [PathSegment] TokenStream
# 21| getIdentifier(): [NameRef] TokenStream
# 21| getVisibility(): [Visibility] Visibility
# 21| getVisibility(): [Visibility] pub
# 31| getItem(4): [Function] fn erase
# 32| getParamList(): [ParamList] ParamList
# 32| getParam(0): [Param] ...: TokenStream
Expand Down Expand Up @@ -2473,7 +2473,7 @@ proc_macro.rs:
# 32| getPath(): [Path] TokenStream
# 32| getSegment(): [PathSegment] TokenStream
# 32| getIdentifier(): [NameRef] TokenStream
# 32| getVisibility(): [Visibility] Visibility
# 32| getVisibility(): [Visibility] pub
# 36| getItem(5): [Function] fn my_trait_derive
# 37| getParamList(): [ParamList] ParamList
# 37| getParam(0): [Param] ...: TokenStream
Expand Down Expand Up @@ -3808,4 +3808,4 @@ proc_macro.rs:
# 37| getPath(): [Path] TokenStream
# 37| getSegment(): [PathSegment] TokenStream
# 37| getIdentifier(): [NameRef] TokenStream
# 37| getVisibility(): [Visibility] Visibility
# 37| getVisibility(): [Visibility] pub
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ lib.rs:
# 1| [SourceFile] SourceFile
# 1| getItem(0): [Module] mod macro_in_library
# 1| getName(): [Name] macro_in_library
# 1| getVisibility(): [Visibility] Visibility
# 1| getVisibility(): [Visibility] pub
macro_in_library.rs:
# 1| [SourceFile] SourceFile
# 1| getItem(0): [MacroCall] (item with attribute macro expansion)
# 2| getAttributeMacroExpansion(): [MacroItems] MacroItems
# 2| getItem(0): [Function] fn foo
# 2| getParamList(): [ParamList] ParamList
# 2| getName(): [Name] foo
# 2| getVisibility(): [Visibility] Visibility
# 2| getVisibility(): [Visibility] pub
# 2| getItem(1): [Function] fn foo_new
# 2| getParamList(): [ParamList] ParamList
# 2| getName(): [Name] foo_new
# 2| getVisibility(): [Visibility] Visibility
# 2| getVisibility(): [Visibility] pub
# 4| getItem(1): [Function] fn bar
# 4| getParamList(): [ParamList] ParamList
# 4| getName(): [Name] bar
# 4| getVisibility(): [Visibility] Visibility
# 4| getVisibility(): [Visibility] pub
proc_macro.rs:
# 1| [SourceFile] SourceFile
# 1| getItem(0): [Use] use ...::TokenStream
Expand Down Expand Up @@ -60,4 +60,4 @@ proc_macro.rs:
# 5| getPath(): [Path] TokenStream
# 5| getSegment(): [PathSegment] TokenStream
# 5| getIdentifier(): [NameRef] TokenStream
# 5| getVisibility(): [Visibility] Visibility
# 5| getVisibility(): [Visibility] pub
6 changes: 3 additions & 3 deletions rust/ql/test/extractor-tests/utf8/ast.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| lib.rs:1:1:1:3 | Visibility |
| lib.rs:1:1:1:3 | pub |
| lib.rs:1:1:1:25 | SourceFile |
| lib.rs:1:1:1:25 | mod utf8_identifiers |
| lib.rs:1:9:1:24 | utf8_identifiers |
Expand All @@ -17,12 +17,12 @@
| utf8_identifiers.rs:6:8:6:8 | X |
| utf8_identifiers.rs:6:10:8:1 | StructFieldList |
| utf8_identifiers.rs:7:5:7:5 | \u03b4 |
| utf8_identifiers.rs:7:5:7:13 | StructField |
| utf8_identifiers.rs:7:5:7:13 | \u03b4: usize |
| utf8_identifiers.rs:7:9:7:13 | usize |
| utf8_identifiers.rs:7:9:7:13 | usize |
| utf8_identifiers.rs:7:9:7:13 | usize |
| utf8_identifiers.rs:7:9:7:13 | usize |
| utf8_identifiers.rs:10:1:10:3 | Visibility |
| utf8_identifiers.rs:10:1:10:3 | pub |
| utf8_identifiers.rs:10:1:12:1 | fn main |
| utf8_identifiers.rs:10:8:10:11 | main |
| utf8_identifiers.rs:10:12:10:13 | ParamList |
Expand Down
Loading