Browse Source

Merge pull request #152 from amaanq/typedef-fixes

Typedef fixes
pull/153/head
Amaan Qureshi 3 years ago
committed by GitHub
parent
commit
475dc3bb84
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59473 additions and 59138 deletions
  1. +8
    -20
      grammar.js
  2. +33
    -65
      src/grammar.json
  3. +5
    -25
      src/node-types.json
  4. +59398
    -59022
      src/parser.c
  5. +29
    -6
      test/corpus/declarations.txt

+ 8
- 20
grammar.js View File

@ -62,8 +62,8 @@ module.exports = grammar({
[$._type_specifier, $._expression_not_binary], [$._type_specifier, $._expression_not_binary],
[$._type_specifier, $._expression_not_binary, $.macro_type_specifier], [$._type_specifier, $._expression_not_binary, $.macro_type_specifier],
[$._type_specifier, $.macro_type_specifier], [$._type_specifier, $.macro_type_specifier],
[$._typedef_type_specifier, $.macro_type_specifier],
[$.sized_type_specifier], [$.sized_type_specifier],
[$._type_specifier, $.sized_type_specifier],
[$.attributed_statement], [$.attributed_statement],
[$._declaration_modifiers, $.attributed_statement], [$._declaration_modifiers, $.attributed_statement],
[$.enum_specifier], [$.enum_specifier],
@ -242,7 +242,7 @@ module.exports = grammar({
type_definition: $ => seq( type_definition: $ => seq(
'typedef', 'typedef',
repeat($.type_qualifier), repeat($.type_qualifier),
field('type', $._typedef_type_specifier),
field('type', $._type_specifier),
repeat($.type_qualifier), repeat($.type_qualifier),
commaSep1(field('declarator', $._type_declarator)), commaSep1(field('declarator', $._type_declarator)),
';', ';',
@ -358,6 +358,8 @@ module.exports = grammar({
alias($.array_type_declarator, $.array_declarator), alias($.array_type_declarator, $.array_declarator),
alias($.parenthesized_type_declarator, $.parenthesized_declarator), alias($.parenthesized_type_declarator, $.parenthesized_declarator),
$._type_identifier, $._type_identifier,
alias(choice('signed', 'unsigned', 'long', 'short'), $.primitive_type),
$.primitive_type,
), ),
_abstract_declarator: $ => choice( _abstract_declarator: $ => choice(
@ -508,16 +510,6 @@ module.exports = grammar({
'noreturn', 'noreturn',
), ),
_typedef_type_specifier: $ => choice(
$.struct_specifier,
$.union_specifier,
$.enum_specifier,
$.macro_type_specifier,
alias($._typedef_sized_type_specifier, $.sized_type_specifier),
$.primitive_type,
$._type_identifier,
),
_type_specifier: $ => choice( _type_specifier: $ => choice(
$.struct_specifier, $.struct_specifier,
$.union_specifier, $.union_specifier,
@ -528,13 +520,6 @@ module.exports = grammar({
$._type_identifier, $._type_identifier,
), ),
_typedef_sized_type_specifier: _ => repeat1(choice(
'signed',
'unsigned',
'long',
'short',
)),
sized_type_specifier: $ => seq( sized_type_specifier: $ => seq(
repeat1(choice( repeat1(choice(
'signed', 'signed',
@ -1168,7 +1153,10 @@ module.exports = grammar({
identifier: _ => identifier: _ =>
/(\p{XID_Start}|_|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})(\p{XID_Continue}|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})*/, /(\p{XID_Start}|_|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})(\p{XID_Continue}|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})*/,
_type_identifier: $ => alias($.identifier, $.type_identifier),
_type_identifier: $ => alias(
$.identifier,
$.type_identifier,
),
_field_identifier: $ => alias($.identifier, $.field_identifier), _field_identifier: $ => alias($.identifier, $.field_identifier),
_statement_identifier: $ => alias($.identifier, $.statement_identifier), _statement_identifier: $ => alias($.identifier, $.statement_identifier),

+ 33
- 65
src/grammar.json View File

@ -1972,7 +1972,7 @@
"name": "type", "name": "type",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_typedef_type_specifier"
"name": "_type_specifier"
} }
}, },
{ {
@ -2487,6 +2487,36 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_type_identifier" "name": "_type_identifier"
},
{
"type": "ALIAS",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "signed"
},
{
"type": "STRING",
"value": "unsigned"
},
{
"type": "STRING",
"value": "long"
},
{
"type": "STRING",
"value": "short"
}
]
},
"named": true,
"value": "primitive_type"
},
{
"type": "SYMBOL",
"name": "primitive_type"
} }
] ]
}, },
@ -3319,44 +3349,6 @@
} }
] ]
}, },
"_typedef_type_specifier": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "struct_specifier"
},
{
"type": "SYMBOL",
"name": "union_specifier"
},
{
"type": "SYMBOL",
"name": "enum_specifier"
},
{
"type": "SYMBOL",
"name": "macro_type_specifier"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_typedef_sized_type_specifier"
},
"named": true,
"value": "sized_type_specifier"
},
{
"type": "SYMBOL",
"name": "primitive_type"
},
{
"type": "SYMBOL",
"name": "_type_identifier"
}
]
},
"_type_specifier": { "_type_specifier": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -3390,30 +3382,6 @@
} }
] ]
}, },
"_typedef_sized_type_specifier": {
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "signed"
},
{
"type": "STRING",
"value": "unsigned"
},
{
"type": "STRING",
"value": "long"
},
{
"type": "STRING",
"value": "short"
}
]
}
},
"sized_type_specifier": { "sized_type_specifier": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -7758,10 +7726,10 @@
"macro_type_specifier" "macro_type_specifier"
], ],
[ [
"_typedef_type_specifier",
"macro_type_specifier"
"sized_type_specifier"
], ],
[ [
"_type_specifier",
"sized_type_specifier" "sized_type_specifier"
], ],
[ [

+ 5
- 25
src/node-types.json View File

@ -269,6 +269,10 @@
"type": "pointer_declarator", "type": "pointer_declarator",
"named": true "named": true
}, },
{
"type": "primitive_type",
"named": true
},
{ {
"type": "type_identifier", "type": "type_identifier",
"named": true "named": true
@ -3424,31 +3428,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "enum_specifier",
"named": true
},
{
"type": "macro_type_specifier",
"named": true
},
{
"type": "primitive_type",
"named": true
},
{
"type": "sized_type_specifier",
"named": true
},
{
"type": "struct_specifier",
"named": true
},
{
"type": "type_identifier",
"named": true
},
{
"type": "union_specifier",
"type": "_type_specifier",
"named": true "named": true
} }
] ]

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


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

@ -306,8 +306,13 @@ typedef short short_t;
typedef unsigned unsigned_t; typedef unsigned unsigned_t;
typedef signed signed_t; typedef signed signed_t;
// FIXME: Still errors
typedef long long; typedef long long;
typedef short short;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned unsigned short;
typedef signed signed short;
typedef signed signed unsigned;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -361,13 +366,19 @@ typedef long long;
declarator: (type_identifier))) declarator: (type_identifier)))
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (type_identifier))
declarator: (primitive_type))
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (type_identifier))
declarator: (primitive_type))
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (type_identifier))
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (type_identifier)) declarator: (type_identifier))
@ -388,14 +399,26 @@ typedef long long;
declarator: (type_identifier)) declarator: (type_identifier))
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier
type: (primitive_type))
declarator: (type_identifier)) declarator: (type_identifier))
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (type_identifier)) declarator: (type_identifier))
(comment)
(type_definition (type_definition
type: (sized_type_specifier) type: (sized_type_specifier)
declarator: (MISSING type_identifier)))
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type)))
================================================================================ ================================================================================
Function declarations Function declarations

Loading…
Cancel
Save