@@ -22,14 +22,14 @@ pub struct CIntrinsic<'a> {
22
22
}
23
23
24
24
impl < ' a > CIntrinsic < ' a > {
25
- pub fn new ( node : Node , source : & ' a String ) -> Self {
25
+ pub fn new ( node : Node , source : & ' a str ) -> Self {
26
26
// Take an intrinsic definition for example:
27
- //
27
+ //
28
28
// static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u32x4_make(uint32_t __c0, uint32_t __c1, uint32_t __c2, uint32_t __c3) {...}
29
- //
29
+ //
30
30
// For a C intrinsic, the immediate children
31
31
// would have their grammar names as:
32
- //
32
+ //
33
33
// "storage_class_specifier" (which is `static`)
34
34
// "storage_class_specifier" (which is `__inline__`)
35
35
// "identifier" (which is `v128_t`. The parser doesn't recognize that it is a type, instead thinks that it is an identifier)
@@ -54,7 +54,7 @@ impl<'a> CIntrinsic<'a> {
54
54
55
55
// The immediate children of the `function_declarator` node would have
56
56
// their grammar as follows:
57
- //
57
+ //
58
58
// "identifier" (which is the intrinsic name)
59
59
// "parameter_list" (which is the arguments to the intrinsic)
60
60
let declarator_node = node
@@ -64,27 +64,27 @@ impl<'a> CIntrinsic<'a> {
64
64
65
65
// The immediate children of a `parameter_list` node would have
66
66
// their grammar as follows (assuming 2 arguments):
67
- //
67
+ //
68
68
// "(" -> The opening bracket that denotes the start of the arguments definition
69
69
// "parameter_declaration" -> The definition for the first argument
70
70
// "," -> The comma that separates the first and the second arguments
71
71
// "parameter_declaration" -> The definition for the first argument
72
72
// ")" -> The closing bracket that denotes the start of the arguments definition
73
- //
73
+ //
74
74
// Each node with grammar name as `parameter_declaration` could have their children as
75
75
// (incase of `int x`):
76
76
// 1. "primitive_type" -> Points to `int`
77
77
// 2. "indentifier" -> Points to `x`
78
- //
78
+ //
79
79
// or have (incase of `v128_t x`):
80
80
// 1. "identifier" -> Points to `v128_t` which is actually a type (but the parser is unaware of it)
81
81
// 2. "identifier" -> Points to `x`
82
- //
82
+ //
83
83
// or have (incase of `const void *__mem`):
84
84
// 1. "type_qualifier" -> Points to `const`
85
85
// 2. "primitive_type" -> Points to `void`
86
86
// 3. "pointer_declarator" -> breaks down into "*" and "identifier" (which is `__mem`)
87
- //
87
+ //
88
88
let intrinsic_name = source
89
89
. get (
90
90
declarator_node
@@ -108,9 +108,9 @@ impl<'a> CIntrinsic<'a> {
108
108
// Since the type could be identified as either `primitive_type, `indentifier`,
109
109
// or a combination of `type_qualifier`, `primitive_type` and `*` (in the case of "const void *")
110
110
// this approach first calculates the end index (which is right before the start of an argument variable)
111
- //
111
+ //
112
112
// And then searches backwards until it finds a break (either a comma
113
- // or the opening bracket). The entire portion contained within this range
113
+ // or the opening bracket). The entire portion contained within this range
114
114
// is then considered as the type of the argument.
115
115
let end_index = arg_name_node. byte_range ( ) . start ;
116
116
let start_index = source
@@ -149,10 +149,10 @@ impl<'a> CIntrinsic<'a> {
149
149
}
150
150
151
151
impl < ' a > RustIntrinsic < ' a > {
152
- pub fn new ( node : Node , source : & ' a String ) -> Self {
152
+ pub fn new ( node : Node , source : & ' a str ) -> Self {
153
153
// For a Rust intrinsic, the immediate children
154
154
// would have their grammar names as:
155
- //
155
+ //
156
156
// 1. "visibility_modifier" (for `pub`)
157
157
// 2. "function_modifiers" (for `unsafe`. May not always be present)
158
158
// 3. "fn" (the actual keyword `fn`)
@@ -162,7 +162,7 @@ impl<'a> RustIntrinsic<'a> {
162
162
// 7. "->" (the arrow used to specify return type)
163
163
// 8. "identifier" (the return type of the function)
164
164
// 9. "block" (the body of the function)
165
- //
165
+ //
166
166
let mut cursor = node. walk ( ) ;
167
167
let intrinsic_name = source
168
168
. get (
@@ -196,14 +196,13 @@ impl<'a> RustIntrinsic<'a> {
196
196
if let Some ( generic_args) = generic_args {
197
197
// The children of this node have their grammar_names as the following
198
198
// (assuming 2 generic arguments):
199
- //
199
+ //
200
200
// "<" (The opening angle bracket that starts the generic arguments definition)
201
201
// "const_parameter" (The first const generic argument)
202
202
// "," (The comma that denotes the end of definition of the first const generic argument)
203
203
// "const_parameter" (The second const generic argument)
204
204
// ">" (The closing angle bracket that concludes the generic arguments definition)
205
- //
206
-
205
+ //
207
206
( generic_arg_names, generic_arg_types) = generic_args
208
207
. children ( & mut cursor)
209
208
. filter ( |arg| arg. grammar_name ( ) == "const_parameter" )
@@ -225,13 +224,12 @@ impl<'a> RustIntrinsic<'a> {
225
224
if let Some ( args) = args {
226
225
// The children of this node have their grammar_names as the following
227
226
// (assuming 2 generic arguments):
228
- //
227
+ //
229
228
// "(" (The opening circular bracket that starts the arguments definition)
230
229
// "parameter" (The first argument)
231
230
// "," (The comma that denotes the end of definition of the first argument)
232
231
// "parameter" (The second argument)
233
232
// ")" (The closing circular bracket that concludes the arguments definition)
234
- //
235
233
( arg_names, arg_types) = args
236
234
. children ( & mut cursor)
237
235
. filter ( |arg| arg. grammar_name ( ) == "parameter" )
0 commit comments