Skip to content

Commit a672ff8

Browse files
Ukilelevinniefalco
authored andcommitted
Generate some simple non member functions
1 parent f1c28fd commit a672ff8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tools/generate.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def NamespaceDefinitionsFolder():
2020
def ClassSpecifiersFolder():
2121
return os.path.join(ToplevelFolder(), "class.pre")
2222

23+
def NonMemberFunctionDeclarationsFolder():
24+
return os.path.join(ToplevelFolder(), "functions", "non-member")
25+
2326

2427
def GenerateEnumDeclarations():
2528
#https://eel.is/c++draft/enum
@@ -69,6 +72,41 @@ def GenerateClassSpecifiers():
6972
return generator
7073

7174

75+
def GenerateNonMemberFunctions():
76+
special_cases = """
77+
int const f\(\);|
78+
int volatile f\(\);|
79+
int const volatile f\(\);|
80+
int\* f\(\);|
81+
int& f\(\);|
82+
int&& f\(\);|
83+
void f\(bool const b\);|
84+
void f\(bool volatile b\);|
85+
void f\(bool const volatile b\);|
86+
void f\(bool& b\);|
87+
void f\(bool&& b\);|
88+
int f\(bool b\.\.\.\);|
89+
void f\(\) noexcept;|
90+
void f\(\) noexcept\(false\);|
91+
extern "C" int f\(bool b\);|
92+
namespace CppScope \{ extern "C" int f\(bool b\); \}|
93+
extern "C" \{ extern "C\+\+" int f\(bool b\); \}|
94+
int f\(bool b\) = delete;|
95+
int f\(bool b\) try \{ return b \? 1 : 2; \} catch\(\.\.\.\) \{ throw; \}|
96+
int f\(bool b\) noexcept\(false\) try \{ return b \? 1 : 2; \} catch\(\.\.\.\) \{ throw; \}|
97+
auto f\(bool b\) -> int;|
98+
auto f\(bool b\) -> auto \{ return b; \}|
99+
class C;\nint C::\* f\(int C::\* p\);|
100+
class C;\nusing MemFnPtr = char\(C::\*\)\(int\) const&;\nconst MemFnPtr& f\(MemFnPtr a, MemFnPtr& b, MemFnPtr&& c, const MemFnPtr& d\);
101+
"""
102+
all_fundamental_types_except_void = "decltype\(nullptr\)|bool|char|signed char|unsigned char|char8_t|char16_t|char32_t|wchar_t|short|int|long|long long|unsigned short|unsigned int|unsigned long|unsigned long long|float|double|long double"
103+
all_fundamental_types = f"{all_fundamental_types_except_void}|void"
104+
function_returning_fundamental_types = f"({all_fundamental_types}) f\(\);"
105+
function_taking_one_fundamental_type = f"void f\(({all_fundamental_types_except_void}) arg\);"
106+
regex = f"({function_returning_fundamental_types}|{function_taking_one_fundamental_type}|{special_cases})"
107+
generator = exrex.generate(regex)
108+
return generator
109+
72110
def GenerateIndexedCppFiles(parentDirectory, fileContents):
73111
os.makedirs(parentDirectory, exist_ok=True)
74112
for index, aDeclaration in enumerate(fileContents):
@@ -84,3 +122,4 @@ def GenerateIndexedCppFiles(parentDirectory, fileContents):
84122
GenerateIndexedCppFiles(EmptyDeclarationFolder(), [";"])
85123
GenerateIndexedCppFiles(NamespaceDefinitionsFolder(), GenerateNamespaceDefinitions())
86124
GenerateIndexedCppFiles(ClassSpecifiersFolder(), GenerateClassSpecifiers())
125+
GenerateIndexedCppFiles(NonMemberFunctionDeclarationsFolder(), GenerateNonMemberFunctions())

0 commit comments

Comments
 (0)