|
92 | 92 | _string_re = re.compile(r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'" |
93 | 93 | r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S) |
94 | 94 |
|
| 95 | +_simple_type_sepcifiers_re = re.compile(r"""(?x) |
| 96 | + \b( |
| 97 | + void|_Bool|bool |
| 98 | + # Integer |
| 99 | + # ------- |
| 100 | + |((signed|unsigned)\s+)?(char|( |
| 101 | + ((long\s+long|long)\s+)?int |
| 102 | + )) |
| 103 | + |__uint128|__int128 |
| 104 | + # extensions |
| 105 | + |((signed|unsigned)\s+)?__int(8|16|32|64|128) |
| 106 | + # Floating-point |
| 107 | + # -------------- |
| 108 | + |(float|double|long\s+double)(\s+(_Complex|complex|_Imaginary|imaginary))? |
| 109 | + |_Decimal(32|64|128) |
| 110 | + # extensions |
| 111 | + |__float80|_Float64x|__float128|_Float128|__ibm128 |
| 112 | + |__fp16 |
| 113 | + # Fixed-point, extension |
| 114 | + |(_Sat\s+)?((signed|unsigned)\s+)?((short|long|long\s+long)\s+)?(_Fract|_Accum) |
| 115 | + # Integer types that could be prefixes of the previous ones |
| 116 | + # --------------------------------------------------------- |
| 117 | + |((signed|unsigned)\s+)?(short|long\s+long|long) |
| 118 | + |signed|unsigned |
| 119 | + )\b |
| 120 | +""") |
| 121 | + |
95 | 122 |
|
96 | 123 | class _DuplicateSymbolError(Exception): |
97 | 124 | def __init__(self, symbol: "Symbol", declaration: "ASTDeclaration") -> None: |
@@ -2123,15 +2150,6 @@ def dump(self, indent: int) -> str: |
2123 | 2150 |
|
2124 | 2151 |
|
2125 | 2152 | class DefinitionParser(BaseParser): |
2126 | | - # those without signedness and size modifiers |
2127 | | - # see https://en.cppreference.com/w/cpp/language/types |
2128 | | - _simple_fundamental_types = ( |
2129 | | - 'void', '_Bool', 'bool', 'char', 'int', 'float', 'double', |
2130 | | - '__int64', |
2131 | | - ) |
2132 | | - |
2133 | | - _prefix_keys = ('struct', 'enum', 'union') |
2134 | | - |
2135 | 2153 | @property |
2136 | 2154 | def language(self) -> str: |
2137 | 2155 | return 'C' |
@@ -2556,40 +2574,16 @@ def _parse_nested_name(self) -> ASTNestedName: |
2556 | 2574 | return ASTNestedName(names, rooted) |
2557 | 2575 |
|
2558 | 2576 | def _parse_trailing_type_spec(self) -> ASTTrailingTypeSpec: |
2559 | | - # fundamental types |
| 2577 | + # fundamental types, https://en.cppreference.com/w/c/language/type |
| 2578 | + # and extensions |
2560 | 2579 | self.skip_ws() |
2561 | | - for t in self._simple_fundamental_types: |
2562 | | - if self.skip_word(t): |
2563 | | - return ASTTrailingTypeSpecFundamental(t) |
2564 | | - |
2565 | | - # TODO: this could/should be more strict |
2566 | | - elements = [] |
2567 | | - if self.skip_word_and_ws('signed'): |
2568 | | - elements.append('signed') |
2569 | | - elif self.skip_word_and_ws('unsigned'): |
2570 | | - elements.append('unsigned') |
2571 | | - while 1: |
2572 | | - if self.skip_word_and_ws('short'): |
2573 | | - elements.append('short') |
2574 | | - elif self.skip_word_and_ws('long'): |
2575 | | - elements.append('long') |
2576 | | - else: |
2577 | | - break |
2578 | | - if self.skip_word_and_ws('char'): |
2579 | | - elements.append('char') |
2580 | | - elif self.skip_word_and_ws('int'): |
2581 | | - elements.append('int') |
2582 | | - elif self.skip_word_and_ws('double'): |
2583 | | - elements.append('double') |
2584 | | - elif self.skip_word_and_ws('__int64'): |
2585 | | - elements.append('__int64') |
2586 | | - if len(elements) > 0: |
2587 | | - return ASTTrailingTypeSpecFundamental(' '.join(elements)) |
| 2580 | + if self.match(_simple_type_sepcifiers_re): |
| 2581 | + return ASTTrailingTypeSpecFundamental(self.matched_text) |
2588 | 2582 |
|
2589 | 2583 | # prefixed |
2590 | 2584 | prefix = None |
2591 | 2585 | self.skip_ws() |
2592 | | - for k in self._prefix_keys: |
| 2586 | + for k in ('struct', 'enum', 'union'): |
2593 | 2587 | if self.skip_word_and_ws(k): |
2594 | 2588 | prefix = k |
2595 | 2589 | break |
|
0 commit comments