Browse Source

Merge pull request #142 from amaanq/enum-bitfield

add multi-bitfield structs and enums with underlying types
pull/133/head
Yoann Padioleau 3 years ago
committed by GitHub
parent
commit
84bdf40906
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42498 additions and 42270 deletions
  1. +6
    -2
      grammar.js
  2. +74
    -24
      src/grammar.json
  3. +10
    -0
      src/node-types.json
  4. +42379
    -42242
      src/parser.c
  5. +29
    -2
      test/corpus/declarations.txt

+ 6
- 2
grammar.js View File

@ -61,6 +61,7 @@ module.exports = grammar({
[$.sized_type_specifier],
[$.attributed_statement],
[$._declaration_modifiers, $.attributed_statement],
[$.enum_specifier],
],
word: $ => $.identifier,
@ -526,6 +527,7 @@ module.exports = grammar({
choice(
seq(
field('name', $._type_identifier),
optional(seq(':', field('underlying_type', $.primitive_type))),
field('body', optional($.enumerator_list)),
),
field('body', $.enumerator_list),
@ -580,8 +582,10 @@ module.exports = grammar({
field_declaration: $ => seq(
$._declaration_specifiers,
commaSep(field('declarator', $._field_declarator)),
optional($.bitfield_clause),
commaSep(seq(
field('declarator', $._field_declarator),
optional($.bitfield_clause),
)),
';',
),

+ 74
- 24
src/grammar.json View File

@ -3290,6 +3290,31 @@
"name": "_type_identifier"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "underlying_type",
"content": {
"type": "SYMBOL",
"name": "primitive_type"
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "body",
@ -3577,12 +3602,29 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "declarator",
"content": {
"type": "SYMBOL",
"name": "_field_declarator"
}
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "declarator",
"content": {
"type": "SYMBOL",
"name": "_field_declarator"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "bitfield_clause"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "REPEAT",
@ -3594,12 +3636,29 @@
"value": ","
},
{
"type": "FIELD",
"name": "declarator",
"content": {
"type": "SYMBOL",
"name": "_field_declarator"
}
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "declarator",
"content": {
"type": "SYMBOL",
"name": "_field_declarator"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "bitfield_clause"
},
{
"type": "BLANK"
}
]
}
]
}
]
}
@ -3611,18 +3670,6 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "bitfield_clause"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ";"
@ -6731,6 +6778,9 @@
[
"_declaration_modifiers",
"attributed_statement"
],
[
"enum_specifier"
]
],
"precedences": [],

+ 10
- 0
src/node-types.json View File

@ -1303,6 +1303,16 @@
"named": true
}
]
},
"underlying_type": {
"multiple": false,
"required": false,
"types": [
{
"type": "primitive_type",
"named": true
}
]
}
}
},

+ 42379
- 42242
src/parser.c
File diff suppressed because it is too large
View File


+ 29
- 2
test/corpus/declarations.txt View File

@ -9,6 +9,10 @@ struct s2 {
float y : 5;
};
struct s3 {
int x : 1, y : 2;
};
---
(translation_unit
@ -23,7 +27,19 @@ struct s2 {
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause (number_literal))))))
(bitfield_clause
(number_literal)))))
(struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause
(number_literal))
declarator: (field_identifier)
(bitfield_clause
(number_literal))))))
============================================
Union declarations
@ -67,6 +83,10 @@ enum e3 {
val1,
};
enum e4: int {
val1,
};
---
(translation_unit
@ -81,7 +101,14 @@ enum e3 {
(enum_specifier
name: (type_identifier)
body: (enumerator_list
(enumerator name: (identifier)))))
(enumerator
name: (identifier))))
(enum_specifier
name: (type_identifier)
underlying_type: (primitive_type)
body: (enumerator_list
(enumerator
name: (identifier)))))
======================================================
Struct declarations containing preprocessor directives

Loading…
Cancel
Save