Procházet zdrojové kódy

Merge pull request #142 from amaanq/enum-bitfield

add multi-bitfield structs and enums with underlying types
pull/133/head
Yoann Padioleau před 3 roky
odevzdal GitHub
rodič
revize
84bdf40906
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 4AEE18F83AFDEB23
5 změnil soubory, kde provedl 42498 přidání a 42270 odebrání
  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 Zobrazit soubor

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

+ 74
- 24
src/grammar.json Zobrazit soubor

@ -3290,6 +3290,31 @@
"name": "_type_identifier" "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", "type": "FIELD",
"name": "body", "name": "body",
@ -3577,12 +3602,29 @@
"type": "SEQ", "type": "SEQ",
"members": [ "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", "type": "REPEAT",
@ -3594,12 +3636,29 @@
"value": "," "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", "type": "STRING",
"value": ";" "value": ";"
@ -6731,6 +6778,9 @@
[ [
"_declaration_modifiers", "_declaration_modifiers",
"attributed_statement" "attributed_statement"
],
[
"enum_specifier"
] ]
], ],
"precedences": [], "precedences": [],

+ 10
- 0
src/node-types.json Zobrazit soubor

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

+ 42379
- 42242
src/parser.c
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 29
- 2
test/corpus/declarations.txt Zobrazit soubor

@ -9,6 +9,10 @@ struct s2 {
float y : 5; float y : 5;
}; };
struct s3 {
int x : 1, y : 2;
};
--- ---
(translation_unit (translation_unit
@ -23,7 +27,19 @@ struct s2 {
(field_declaration (field_declaration
type: (primitive_type) type: (primitive_type)
declarator: (field_identifier) 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 Union declarations
@ -67,6 +83,10 @@ enum e3 {
val1, val1,
}; };
enum e4: int {
val1,
};
--- ---
(translation_unit (translation_unit
@ -81,7 +101,14 @@ enum e3 {
(enum_specifier (enum_specifier
name: (type_identifier) name: (type_identifier)
body: (enumerator_list 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 Struct declarations containing preprocessor directives

Načítá se…
Zrušit
Uložit