Merge 13ad58351a into 3afb7e1a21
This commit is contained in:
commit
e54b35389a
|
|
@ -284,6 +284,7 @@ Thomas Brown
|
||||||
Thomas Dybdahl Ahle
|
Thomas Dybdahl Ahle
|
||||||
Thomas Santerre
|
Thomas Santerre
|
||||||
Tim Hutt
|
Tim Hutt
|
||||||
|
Tim Paine
|
||||||
Tim Snyder
|
Tim Snyder
|
||||||
Tobias Jensen
|
Tobias Jensen
|
||||||
Tobias Rosenkranz
|
Tobias Rosenkranz
|
||||||
|
|
|
||||||
54
src/flexfix
54
src/flexfix
|
|
@ -12,10 +12,48 @@
|
||||||
######################################################################
|
######################################################################
|
||||||
# DESCRIPTION: Edits flex output to get around various broken flex issues.
|
# DESCRIPTION: Edits flex output to get around various broken flex issues.
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
|
|
||||||
|
def _flexlexer_uses_size_t() -> bool:
|
||||||
|
"""Return True if the FlexLexer.h that will be used declares LexerInput with size_t."""
|
||||||
|
candidates = []
|
||||||
|
env_paths = os.environ.get("CPATH", "") + os.pathsep + os.environ.get("CPLUS_INCLUDE_PATH", "")
|
||||||
|
for d in env_paths.split(os.pathsep):
|
||||||
|
if d:
|
||||||
|
candidates.append(os.path.join(d, "FlexLexer.h"))
|
||||||
|
if platform.system() == "Darwin":
|
||||||
|
try:
|
||||||
|
sdk = subprocess.check_output(["xcrun", "--show-sdk-path"],
|
||||||
|
stderr=subprocess.DEVNULL).decode().strip()
|
||||||
|
if sdk:
|
||||||
|
candidates.append(os.path.join(sdk, "usr", "include", "FlexLexer.h"))
|
||||||
|
except (OSError, subprocess.CalledProcessError):
|
||||||
|
pass
|
||||||
|
candidates.extend([
|
||||||
|
"/opt/homebrew/include/FlexLexer.h",
|
||||||
|
"/usr/local/include/FlexLexer.h",
|
||||||
|
])
|
||||||
|
candidates.extend(["/usr/include/FlexLexer.h"])
|
||||||
|
for path in candidates:
|
||||||
|
try:
|
||||||
|
with open(path, "r", encoding="utf-8", errors="ignore") as fh:
|
||||||
|
text = fh.read()
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
if re.search(r"\bLexerInput\s*\(\s*char\s*\*\s*\w*\s*,\s*size_t\b", text):
|
||||||
|
return True
|
||||||
|
if re.search(r"\bLexerInput\s*\(\s*char\s*\*\s*\w*\s*,\s*int\b", text):
|
||||||
|
return False
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
_LEXER_USES_SIZE_T = _flexlexer_uses_size_t()
|
||||||
|
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
# Fix flex 2.6.1 warning
|
# Fix flex 2.6.1 warning
|
||||||
line = re.sub(r'for \( i = 0; i < _yybytes_len; \+\+i \)',
|
line = re.sub(r'for \( i = 0; i < _yybytes_len; \+\+i \)',
|
||||||
|
|
@ -48,14 +86,12 @@ for line in sys.stdin:
|
||||||
line = re.sub(r'(#line \d+ ".*)_pretmp', r'\1', line)
|
line = re.sub(r'(#line \d+ ".*)_pretmp', r'\1', line)
|
||||||
# Fix 'register' storage class specifier is deprecated and incompatible with C++17
|
# Fix 'register' storage class specifier is deprecated and incompatible with C++17
|
||||||
line = re.sub(r'register ', '', line)
|
line = re.sub(r'register ', '', line)
|
||||||
# Change int to size_t on LexerInput/LexerOutput when using macOS Tahoe
|
# Change int to size_t on LexerInput/LexerOutput when the FlexLexer.h in use
|
||||||
if platform.system() == "Darwin":
|
# declares them with size_t (e.g. macOS Tahoe's system flex). Skip when the
|
||||||
try:
|
# actual FlexLexer.h still uses int (e.g. Homebrew flex 2.6.4) to avoid an
|
||||||
osv = platform.mac_ver()[0] # Example "26.2"
|
# out-of-line-definition mismatch.
|
||||||
if len(osv) > 2 and osv[2] == "." and int(osv[:2]) >= 26:
|
if _LEXER_USES_SIZE_T:
|
||||||
if "::LexerInput(" in line or "::LexerOutput(" in line:
|
if "::LexerInput(" in line or "::LexerOutput(" in line:
|
||||||
line = re.sub(r'int ', r'size_t ', line)
|
line = re.sub(r'int ', r'size_t ', line)
|
||||||
except IndexError as e:
|
|
||||||
print(f"Unexpected index error {e}")
|
|
||||||
|
|
||||||
print(line, end='')
|
print(line, end='')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue