Skip to content

Commit 5efe3ef

Browse files
Ukilelevinniefalco
authored andcommitted
Add generate.py to generate enum declarations into tests/py/dcl.enum/
close #95
1 parent 8893e61 commit 5efe3ef

File tree

14 files changed

+43
-77
lines changed

14 files changed

+43
-77
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ if (MRDOX_BUILD_TESTS)
189189
target_link_libraries(mrdox-test PRIVATE mrdox-api ${llvm_libs})
190190
target_include_directories(mrdox-test PRIVATE ${PROJECT_SOURCE_DIR}/source/tests)
191191
add_test(NAME mrdox-test COMMAND mrdox-test
192-
"${PROJECT_SOURCE_DIR}/tests/n4944"
193192
"${PROJECT_SOURCE_DIR}/tests/old-tests"
194193
)
195194
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)

tests/generate.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#! python3
2+
3+
import exrex
4+
import os
5+
6+
def ToplevelFolder():
7+
scriptPath = os.path.realpath(__file__)
8+
parentDirectory = os.path.dirname(scriptPath)
9+
return os.path.join(parentDirectory, "py")
10+
11+
def EnumDeclarationsFolder():
12+
return os.path.join(ToplevelFolder(), "dcl.enum")
13+
14+
15+
def GenerateEnumDeclarations():
16+
#https://eel.is/c++draft/enum
17+
enum_base = "(|: short|: unsigned int|: const long|: const volatile long long|: decltype\(0\))"
18+
enumerator_initializer = "(| = 0| = true \? 1,2 : 3| = \!\+\[\]\(\)\{\})"
19+
enumerators = " (|(A" + enumerator_initializer + "|A" + enumerator_initializer + ", B " + enumerator_initializer + "),?) "
20+
regex = "enum (|EnumName|class EnumName|struct EnumName) " + enum_base + " (\{" + enumerators + "\})? ;"
21+
generator = exrex.generate(regex)
22+
declarations = list(generator)
23+
# Unfortunately, the regex produces some invalid declarations. We remove them by hand as of now.
24+
for invalidDeclaration in ["enum ;", "enum : short ;", "enum : unsigned int ;",
25+
"enum : const long ;", "enum : const volatile long long ;",
26+
"enum : decltype(0) ;", "enum EnumName ;"]:
27+
try:
28+
declarations.remove(invalidDeclaration)
29+
except ValueError:
30+
print("The invalid declaration \"" + invalidDeclaration + "\" gets no longer generated, so it can be removed from the list of invalid declarations.")
31+
return declarations
32+
33+
34+
def GenerateIndexedCppFiles(parentDirectory, fileContents):
35+
os.makedirs(parentDirectory, exist_ok=True)
36+
for index, aDeclaration in enumerate(fileContents):
37+
fileName = str(index) + ".cpp"
38+
filePath = os.path.join(parentDirectory, fileName)
39+
with open(filePath, "w") as f:
40+
f.write(aDeclaration)
41+
42+
43+
GenerateIndexedCppFiles(EnumDeclarationsFolder(), GenerateEnumDeclarations())

tests/n4944/dcl.enum/1.cpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/n4944/dcl.enum/1.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/n4944/dcl.enum/2.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/n4944/dcl.enum/2.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/n4944/dcl.enum/3.cpp

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/n4944/dcl.enum/3.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/n4944/dcl.enum/4.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/n4944/dcl.enum/4.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)