Skip to content

Commit 4eaacab

Browse files
committed
Addresses review comments.
1 parent 49c0d92 commit 4eaacab

File tree

5 files changed

+38
-53
lines changed

5 files changed

+38
-53
lines changed

libcxx/test/libcxx/feature_test_macro/get_dialect_versions.sh.py renamed to libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
21
# ===----------------------------------------------------------------------===##
32
#
43
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,19 +6,21 @@
76
#
87
# ===----------------------------------------------------------------------===##
98

9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
10+
1011
import sys
1112

1213
sys.path.append(sys.argv[1])
13-
from generate_feature_test_macro_components import feature_test_macros
14+
from generate_feature_test_macro_components import FeatureTestMacros
1415

1516

1617
def test(output, expected):
1718
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
1819

1920

20-
fmt = feature_test_macros(sys.argv[2])
21+
ftm = FeatureTestMacros(sys.argv[2])
2122
test(
22-
fmt.get_dialect_versions(),
23+
ftm.implemented_ftms,
2324
{
2425
"__cpp_lib_any": {
2526
"c++17": "201606L",

libcxx/test/libcxx/feature_test_macro/invalid.sh.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# RUN: %{python} %s %{libcxx-dir}/utils %t
21
# ===----------------------------------------------------------------------===##
32
#
43
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,11 +6,13 @@
76
#
87
# ===----------------------------------------------------------------------===##
98

9+
# RUN: %{python} %s %{libcxx-dir}/utils %t
10+
1011
import sys
1112
import json
1213

1314
sys.path.append(sys.argv[1])
14-
from generate_feature_test_macro_components import feature_test_macros
15+
from generate_feature_test_macro_components import FeatureTestMacros
1516

1617

1718
def test(output, expected):
@@ -22,9 +23,9 @@ def test_error(data, type, message):
2223
tmp = sys.argv[2]
2324
with open(tmp, "w") as file:
2425
file.write(json.dumps(data))
25-
fmt = feature_test_macros(tmp)
26+
ftm = FeatureTestMacros(tmp)
2627
try:
27-
fmt.get_dialect_versions()
28+
ftm.implemented_ftms
2829
except type as error:
2930
test(str(error), message)
3031
else:

libcxx/test/libcxx/feature_test_macro/get_std_dialect_versions.sh.py renamed to libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
21
# ===----------------------------------------------------------------------===##
32
#
43
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,19 +6,21 @@
76
#
87
# ===----------------------------------------------------------------------===##
98

9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
10+
1011
import sys
1112

1213
sys.path.append(sys.argv[1])
13-
from generate_feature_test_macro_components import feature_test_macros
14+
from generate_feature_test_macro_components import FeatureTestMacros
1415

1516

1617
def test(output, expected):
1718
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
1819

1920

20-
fmt = feature_test_macros(sys.argv[2])
21+
ftm = FeatureTestMacros(sys.argv[2])
2122
test(
22-
fmt.get_std_dialect_versions(),
23+
ftm.standard_ftms,
2324
{
2425
"__cpp_lib_any": {
2526
"c++17": "201606L",

libcxx/test/libcxx/feature_test_macro/get_std_dialects.sh.py renamed to libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
21
# ===----------------------------------------------------------------------===##
32
#
43
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,19 +6,21 @@
76
#
87
# ===----------------------------------------------------------------------===##
98

9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
10+
1011
import sys
1112

1213
sys.path.append(sys.argv[1])
13-
from generate_feature_test_macro_components import feature_test_macros
14+
from generate_feature_test_macro_components import FeatureTestMacros
1415

1516

1617
def test(output, expected):
1718
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
1819

1920

20-
fmt = feature_test_macros(sys.argv[2])
21+
ftm = FeatureTestMacros(sys.argv[2])
2122
test(
22-
fmt.get_std_dialects(),
23+
ftm.std_dialects,
2324
[
2425
"c++17",
2526
"c++20",

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from builtins import range
55
from functools import reduce
6+
import functools
67
import json
78

89

@@ -1868,17 +1869,6 @@ def produce_docs():
18681869
f.write(doc_str)
18691870

18701871

1871-
def get_std_dialects(data):
1872-
"""Impementation for feature_test_macros.get_std_dialects()."""
1873-
dialects = set()
1874-
for feature in data:
1875-
keys = feature["values"].keys()
1876-
assert len(keys) > 0, "'values' is empty"
1877-
dialects |= keys
1878-
1879-
return sorted(dialects)
1880-
1881-
18821872
def get_dialect_versions(data, std_dialects, use_implemented_status):
18831873
"""Impementation for feature_test_macros.get_(std_|)dialect_versions()."""
18841874
result = dict()
@@ -1916,8 +1906,8 @@ def get_dialect_versions(data, std_dialects, use_implemented_status):
19161906
return result
19171907

19181908

1919-
class feature_test_macros:
1920-
"""Provides all feature-test macro (FMT) output components.
1909+
class FeatureTestMacros:
1910+
"""Provides all feature-test macro (FTM) output components.
19211911
19221912
The class has several generators to use the feature-test macros in libc++:
19231913
- FTM status page
@@ -2007,20 +1997,15 @@ class feature_test_macros:
20071997
]
20081998
"""
20091999

2010-
# The JSON data structor.
2000+
# The JSON data structure.
20112001
__data = None
20122002

2013-
# These values are used internally multiple times. They are lazily loaded
2014-
# and cached. Values that are expected to be used once are not cached.
2015-
__std_dialects = None
2016-
__std_dialect_versions = None
2017-
__dialect_versions = None
2018-
20192003
def __init__(self, filename):
20202004
"""Initializes the class with the JSON data in the file 'filename'."""
20212005
self.__data = json.load(open(filename))
20222006

2023-
def get_std_dialects(self):
2007+
@functools.cached_property
2008+
def std_dialects(self):
20242009
"""Returns the C++ dialects avaiable.
20252010
20262011
The available dialects are based on the 'c++xy' keys found the 'values'
@@ -2030,12 +2015,16 @@ def get_std_dialects(self):
20302015
The return value is a sorted list with the C++ dialects used. Since FTM
20312016
were added in C++14 the list will not contain C++98 or C++11.
20322017
"""
2033-
if not self.__std_dialects:
2034-
self.__std_dialects = get_std_dialects(self.__data)
2018+
dialects = set()
2019+
for feature in self.__data:
2020+
keys = feature["values"].keys()
2021+
assert len(keys) > 0, "'values' is empty"
2022+
dialects |= keys
20352023

2036-
return self.__std_dialects
2024+
return sorted(list(dialects))
20372025

2038-
def get_std_dialect_versions(self):
2026+
@functools.cached_property
2027+
def standard_ftms(self):
20392028
"""Returns the FTM versions per dialect in the Standard.
20402029
20412030
This function does not use the 'implemented' flag. The output contains
@@ -2049,14 +2038,10 @@ def get_std_dialect_versions(self):
20492038
* key: The version of the C++ dialect.
20502039
* value: The value of the feature-test macro.
20512040
"""
2052-
if not self.__std_dialect_versions:
2053-
self.__std_dialect_versions = get_dialect_versions(
2054-
self.__data, self.get_std_dialects(), False
2055-
)
2041+
return get_dialect_versions(self.__data, self.std_dialects, False)
20562042

2057-
return self.__std_dialect_versions
2058-
2059-
def get_dialect_versions(self):
2043+
@functools.cached_property
2044+
def implemented_ftms(self):
20602045
"""Returns the FTM versions per dialect implemented in libc++.
20612046
20622047
Unlike `get_std_dialect_versions` this function uses the 'implemented'
@@ -2069,12 +2054,8 @@ def get_dialect_versions(self):
20692054
* value: The value of the feature-test macro. When a feature-test
20702055
macro is not implemented its value is None.
20712056
"""
2072-
if not self.__dialect_versions:
2073-
self.__dialect_versions = get_dialect_versions(
2074-
self.__data, self.get_std_dialects(), True
2075-
)
20762057

2077-
return self.__dialect_versions
2058+
return get_dialect_versions(self.__data, self.std_dialects, True)
20782059

20792060

20802061
def main():

0 commit comments

Comments
 (0)