MOD: optimize attribute specifiers, reduce the size of parser.c

This commit is contained in:
shengxuanwei 2022-04-24 11:37:32 +08:00
parent 7533039f42
commit 0df922fb6f
6 changed files with 573330 additions and 643540 deletions

View File

@ -264,13 +264,7 @@ module.exports = grammar(C, {
storage_class_specifier: ($, superclass) => choice(
superclass,
'FOUNDATION_EXPORT',
'FOUNDATION_EXTERN',
'FOUNDATION_STATIC_INLINE',
'NS_INLINE',
'UIKIT_EXTERN',
'CG_EXTERN',
'CG_INLINE',
/FOUNDATION_EXPORT|FOUNDATION_EXTERN|FOUNDATION_STATIC_INLINE|NS_INLINE|UIKIT_EXTERN|CG_EXTERN|CG_INLINE/
),
property_declaration: $ => seq(
@ -319,7 +313,6 @@ module.exports = grammar(C, {
class_interface_attribute_sepcifier: $ => token.immediate(/IB_DESIGNABLE|NS_ROOT_CLASS/),
attribute_specifier: ($, superclass) => prec.dynamic(1, prec.left(choice(
'__attribute__((unused))',
seq(
choice('__attribute', '__attribute__'),
'(',
@ -331,14 +324,7 @@ module.exports = grammar(C, {
$.availability_attribute_specifier,
))),
method_attribute_specifier: $ => choice(
'NS_DESIGNATED_INITIALIZER',
'NS_REQUIRES_SUPER',
'CF_RETURNS_RETAINED',
'CF_RETURNS_NOT_RETAINED',
'NS_REQUIRES_NIL_TERMINATION',
'NS_DIRECT'
),
method_attribute_specifier: $ => token.immediate(/NS_DESIGNATED_INITIALIZER|NS_REQUIRES_SUPER|CF_RETURNS_RETAINED|CF_RETURNS_NOT_RETAINED|NS_REQUIRES_NIL_TERMINATION|NS_DIRECT/),
method_variadic_arguments_attribute_specifier: $=> seq(
choice('NS_FORMAT_FUNCTION', 'CF_FORMAT_FUNCTION'),

View File

@ -2048,10 +2048,6 @@
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "__attribute__((unused))"
},
{
"type": "SEQ",
"members": [
@ -3110,32 +3106,8 @@
]
},
{
"type": "STRING",
"value": "FOUNDATION_EXPORT"
},
{
"type": "STRING",
"value": "FOUNDATION_EXTERN"
},
{
"type": "STRING",
"value": "FOUNDATION_STATIC_INLINE"
},
{
"type": "STRING",
"value": "NS_INLINE"
},
{
"type": "STRING",
"value": "UIKIT_EXTERN"
},
{
"type": "STRING",
"value": "CG_EXTERN"
},
{
"type": "STRING",
"value": "CG_INLINE"
"type": "PATTERN",
"value": "FOUNDATION_EXPORT|FOUNDATION_EXTERN|FOUNDATION_STATIC_INLINE|NS_INLINE|UIKIT_EXTERN|CG_EXTERN|CG_INLINE"
}
]
},
@ -8478,33 +8450,11 @@
}
},
"method_attribute_specifier": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "NS_DESIGNATED_INITIALIZER"
},
{
"type": "STRING",
"value": "NS_REQUIRES_SUPER"
},
{
"type": "STRING",
"value": "CF_RETURNS_RETAINED"
},
{
"type": "STRING",
"value": "CF_RETURNS_NOT_RETAINED"
},
{
"type": "STRING",
"value": "NS_REQUIRES_NIL_TERMINATION"
},
{
"type": "STRING",
"value": "NS_DIRECT"
}
]
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "NS_DESIGNATED_INITIALIZER|NS_REQUIRES_SUPER|CF_RETURNS_RETAINED|CF_RETURNS_NOT_RETAINED|NS_REQUIRES_NIL_TERMINATION|NS_DIRECT"
}
},
"method_variadic_arguments_attribute_specifier": {
"type": "SEQ",

View File

@ -634,7 +634,7 @@
"fields": {},
"children": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "argument_list",
@ -3932,11 +3932,6 @@
}
}
},
{
"type": "method_attribute_specifier",
"named": true,
"fields": {}
},
{
"type": "method_declaration",
"named": true,
@ -6413,7 +6408,7 @@
},
{
"type": "string_literal",
"named": false,
"named": true,
"fields": {},
"children": {
"multiple": true,
@ -7717,22 +7712,6 @@
"type": "CF_FORMAT_FUNCTION",
"named": false
},
{
"type": "CF_RETURNS_NOT_RETAINED",
"named": false
},
{
"type": "CF_RETURNS_RETAINED",
"named": false
},
{
"type": "CG_EXTERN",
"named": false
},
{
"type": "CG_INLINE",
"named": false
},
{
"type": "Class",
"named": true
@ -7749,18 +7728,6 @@
"type": "DISPATCH_QUEUE_REFERENCE_TYPE",
"named": true
},
{
"type": "FOUNDATION_EXPORT",
"named": false
},
{
"type": "FOUNDATION_EXTERN",
"named": false
},
{
"type": "FOUNDATION_STATIC_INLINE",
"named": false
},
{
"type": "IBInspectable",
"named": false
@ -7805,14 +7772,6 @@
"type": "NS_DEPRECATED_IOS",
"named": false
},
{
"type": "NS_DESIGNATED_INITIALIZER",
"named": false
},
{
"type": "NS_DIRECT",
"named": false
},
{
"type": "NS_ENUM",
"named": false
@ -7837,10 +7796,6 @@
"type": "NS_FORMAT_FUNCTION",
"named": false
},
{
"type": "NS_INLINE",
"named": false
},
{
"type": "NS_NOESCAPE",
"named": false
@ -7857,14 +7812,6 @@
"type": "NS_REFINED_FOR_SWIFT",
"named": false
},
{
"type": "NS_REQUIRES_NIL_TERMINATION",
"named": false
},
{
"type": "NS_REQUIRES_SUPER",
"named": false
},
{
"type": "NS_SWIFT_NAME",
"named": false
@ -7893,10 +7840,6 @@
"type": "U'",
"named": false
},
{
"type": "UIKIT_EXTERN",
"named": false
},
{
"type": "UI_APPEARANCE_SELECTOR",
"named": false
@ -7965,10 +7908,6 @@
"type": "__attribute__",
"named": false
},
{
"type": "__attribute__((unused))",
"named": false
},
{
"type": "__autoreleasing",
"named": false
@ -8111,11 +8050,11 @@
},
{
"type": "auto",
"named": false
"named": true
},
{
"type": "auto",
"named": true
"named": false
},
{
"type": "break",
@ -8253,6 +8192,10 @@
"type": "macosx",
"named": false
},
{
"type": "method_attribute_specifier",
"named": true
},
{
"type": "module_string",
"named": true

1216703
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -893,7 +893,9 @@ LLVM Attributes: __unused
keyword: (identifier)
type: (type_identifier)
declarator: (abstract_pointer_declarator)
type: (attribute_specifier)
type: (attribute_specifier
(argument_list
(identifier)))
name: (identifier)))
body: (compound_statement))
(method_definition
@ -903,6 +905,8 @@ LLVM Attributes: __unused
(keyword_declarator
keyword: (identifier)
type: (primitive_type)
type: (attribute_specifier)
type: (attribute_specifier
(argument_list
(identifier)))
name: (identifier)))
body: (compound_statement))))

View File

@ -1008,7 +1008,9 @@ __auto_type copy = (typeof(self.message))[self.message copy];
keyword: (identifier)
type: (type_identifier)
declarator: (abstract_pointer_declarator)
type: (attribute_specifier)
type: (attribute_specifier
(argument_list
(identifier)))
name: (identifier)))
body: (compound_statement)))
(type_definition