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

View File

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

View File

@ -634,7 +634,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": false,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "argument_list", "type": "argument_list",
@ -3932,11 +3932,6 @@
} }
} }
}, },
{
"type": "method_attribute_specifier",
"named": true,
"fields": {}
},
{ {
"type": "method_declaration", "type": "method_declaration",
"named": true, "named": true,
@ -6413,7 +6408,7 @@
}, },
{ {
"type": "string_literal", "type": "string_literal",
"named": false, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
@ -7717,22 +7712,6 @@
"type": "CF_FORMAT_FUNCTION", "type": "CF_FORMAT_FUNCTION",
"named": false "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", "type": "Class",
"named": true "named": true
@ -7749,18 +7728,6 @@
"type": "DISPATCH_QUEUE_REFERENCE_TYPE", "type": "DISPATCH_QUEUE_REFERENCE_TYPE",
"named": true "named": true
}, },
{
"type": "FOUNDATION_EXPORT",
"named": false
},
{
"type": "FOUNDATION_EXTERN",
"named": false
},
{
"type": "FOUNDATION_STATIC_INLINE",
"named": false
},
{ {
"type": "IBInspectable", "type": "IBInspectable",
"named": false "named": false
@ -7805,14 +7772,6 @@
"type": "NS_DEPRECATED_IOS", "type": "NS_DEPRECATED_IOS",
"named": false "named": false
}, },
{
"type": "NS_DESIGNATED_INITIALIZER",
"named": false
},
{
"type": "NS_DIRECT",
"named": false
},
{ {
"type": "NS_ENUM", "type": "NS_ENUM",
"named": false "named": false
@ -7837,10 +7796,6 @@
"type": "NS_FORMAT_FUNCTION", "type": "NS_FORMAT_FUNCTION",
"named": false "named": false
}, },
{
"type": "NS_INLINE",
"named": false
},
{ {
"type": "NS_NOESCAPE", "type": "NS_NOESCAPE",
"named": false "named": false
@ -7857,14 +7812,6 @@
"type": "NS_REFINED_FOR_SWIFT", "type": "NS_REFINED_FOR_SWIFT",
"named": false "named": false
}, },
{
"type": "NS_REQUIRES_NIL_TERMINATION",
"named": false
},
{
"type": "NS_REQUIRES_SUPER",
"named": false
},
{ {
"type": "NS_SWIFT_NAME", "type": "NS_SWIFT_NAME",
"named": false "named": false
@ -7893,10 +7840,6 @@
"type": "U'", "type": "U'",
"named": false "named": false
}, },
{
"type": "UIKIT_EXTERN",
"named": false
},
{ {
"type": "UI_APPEARANCE_SELECTOR", "type": "UI_APPEARANCE_SELECTOR",
"named": false "named": false
@ -7965,10 +7908,6 @@
"type": "__attribute__", "type": "__attribute__",
"named": false "named": false
}, },
{
"type": "__attribute__((unused))",
"named": false
},
{ {
"type": "__autoreleasing", "type": "__autoreleasing",
"named": false "named": false
@ -8111,11 +8050,11 @@
}, },
{ {
"type": "auto", "type": "auto",
"named": false "named": true
}, },
{ {
"type": "auto", "type": "auto",
"named": true "named": false
}, },
{ {
"type": "break", "type": "break",
@ -8253,6 +8192,10 @@
"type": "macosx", "type": "macosx",
"named": false "named": false
}, },
{
"type": "method_attribute_specifier",
"named": true
},
{ {
"type": "module_string", "type": "module_string",
"named": true "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) keyword: (identifier)
type: (type_identifier) type: (type_identifier)
declarator: (abstract_pointer_declarator) declarator: (abstract_pointer_declarator)
type: (attribute_specifier) type: (attribute_specifier
(argument_list
(identifier)))
name: (identifier))) name: (identifier)))
body: (compound_statement)) body: (compound_statement))
(method_definition (method_definition
@ -903,6 +905,8 @@ LLVM Attributes: __unused
(keyword_declarator (keyword_declarator
keyword: (identifier) keyword: (identifier)
type: (primitive_type) type: (primitive_type)
type: (attribute_specifier) type: (attribute_specifier
(argument_list
(identifier)))
name: (identifier))) name: (identifier)))
body: (compound_statement)))) body: (compound_statement))))

View File

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