Skip to content

Commit

Permalink
Add generate.py to generate enum declarations into tests/py/dcl.enum/
Browse files Browse the repository at this point in the history
close #95
  • Loading branch information
Ukilele authored and vinniefalco committed Apr 25, 2023
1 parent 8893e61 commit 5efe3ef
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 77 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ if (MRDOX_BUILD_TESTS)
target_link_libraries(mrdox-test PRIVATE mrdox-api ${llvm_libs})
target_include_directories(mrdox-test PRIVATE ${PROJECT_SOURCE_DIR}/source/tests)
add_test(NAME mrdox-test COMMAND mrdox-test
"${PROJECT_SOURCE_DIR}/tests/n4944"
"${PROJECT_SOURCE_DIR}/tests/old-tests"
)
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
Expand Down
43 changes: 43 additions & 0 deletions tests/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! python3

import exrex
import os

def ToplevelFolder():
scriptPath = os.path.realpath(__file__)
parentDirectory = os.path.dirname(scriptPath)
return os.path.join(parentDirectory, "py")

def EnumDeclarationsFolder():
return os.path.join(ToplevelFolder(), "dcl.enum")


def GenerateEnumDeclarations():
#https://eel.is/c++draft/enum
enum_base = "(|: short|: unsigned int|: const long|: const volatile long long|: decltype\(0\))"
enumerator_initializer = "(| = 0| = true \? 1,2 : 3| = \!\+\[\]\(\)\{\})"
enumerators = " (|(A" + enumerator_initializer + "|A" + enumerator_initializer + ", B " + enumerator_initializer + "),?) "
regex = "enum (|EnumName|class EnumName|struct EnumName) " + enum_base + " (\{" + enumerators + "\})? ;"
generator = exrex.generate(regex)
declarations = list(generator)
# Unfortunately, the regex produces some invalid declarations. We remove them by hand as of now.
for invalidDeclaration in ["enum ;", "enum : short ;", "enum : unsigned int ;",
"enum : const long ;", "enum : const volatile long long ;",
"enum : decltype(0) ;", "enum EnumName ;"]:
try:
declarations.remove(invalidDeclaration)
except ValueError:
print("The invalid declaration \"" + invalidDeclaration + "\" gets no longer generated, so it can be removed from the list of invalid declarations.")
return declarations


def GenerateIndexedCppFiles(parentDirectory, fileContents):
os.makedirs(parentDirectory, exist_ok=True)
for index, aDeclaration in enumerate(fileContents):
fileName = str(index) + ".cpp"
filePath = os.path.join(parentDirectory, fileName)
with open(filePath, "w") as f:
f.write(aDeclaration)


GenerateIndexedCppFiles(EnumDeclarationsFolder(), GenerateEnumDeclarations())
2 changes: 0 additions & 2 deletions tests/n4944/dcl.enum/1.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions tests/n4944/dcl.enum/1.xml

This file was deleted.

1 change: 0 additions & 1 deletion tests/n4944/dcl.enum/2.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions tests/n4944/dcl.enum/2.xml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/n4944/dcl.enum/3.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions tests/n4944/dcl.enum/3.xml

This file was deleted.

1 change: 0 additions & 1 deletion tests/n4944/dcl.enum/4.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions tests/n4944/dcl.enum/4.xml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/n4944/dcl.enum/5.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions tests/n4944/dcl.enum/5.xml

This file was deleted.

16 changes: 0 additions & 16 deletions tests/old-tests/mem-fn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
<file path="mem-fn.cpp" line="17" class="def"/>
<function name="f" access="public" id="wSFf8IAx5Twq6aD5T8XdnXGuhw8=">
<file path="mem-fn.cpp" line="17"/>
<volatile/>
</function>
</struct>
<struct name="U" id="FLgkhM3m0U3Lo2o3XLPUizWPH00=">
<file path="mem-fn.cpp" line="22" class="def"/>
<function name="f1" access="public" id="DBXd564vaQo7GHkh6XCC6HV78/I=">
<file path="mem-fn.cpp" line="24" class="def"/>
<const/><constexpr/><inline/><noexcept/><trailing/><variadic/><volatile/>
</function>
<function name="f2" access="public" id="II436kVwM/ZBYOf9q474VxRXK6c=">
<file path="mem-fn.cpp" line="25" class="def"/>
<constexpr/><inline/><noexcept/><trailing/>
<return name="char"/>
</function>
<function name="f3" access="public" id="YOkqb7VjZXBs2Rg5gWCOYGX3Tnw=">
<file path="mem-fn.cpp" line="26"/>
<const/><noexcept/><pure/><virtual/><volatile/>
<return name="int"/>
</function>
</struct>
Expand All @@ -31,7 +27,6 @@
<base name="T14" access="public" id="SLJhBKx+2u4KxSJ78Fg6wqlObPc="/>
<function name="f" access="public" id="5+yfyWtDpz80IwKT3xugro18Ev0=">
<file path="mem-fn.cpp" line="20"/>
<override/>
</function>
</struct>
<struct name="T02" id="H+pnPDuG6B+W6+srjVP2qhqXCrQ=">
Expand All @@ -44,22 +39,19 @@
<file path="mem-fn.cpp" line="6" class="def"/>
<function name="f" access="public" id="G71rDzcAZPSKGoGGoDswQjD1JuA=">
<file path="mem-fn.cpp" line="6"/>
<volatile/>
</function>
</struct>
<struct name="T11" id="MXMa4TZZfdRkREzWSLpIF6ruUyw=">
<file path="mem-fn.cpp" line="13" class="def"/>
<function name="f" access="public" id="+NevzZlqigIe1KSKS7eqq7pCd40=">
<file path="mem-fn.cpp" line="13"/>
<trailing/>
<return name="int"/>
</function>
</struct>
<struct name="T13" id="NyLraUP0R3lYeyTpHQYZpyZMstc=">
<file path="mem-fn.cpp" line="15" class="def"/>
<function name="f" access="public" id="5d5eSOvkYwBOnpbLcrkRuFvJGP4=">
<file path="mem-fn.cpp" line="15"/>
<virtual/>
</function>
</struct>
<struct name="T01" id="O2UBDeG42PMrk1up8f8PGVFhIGk=">
Expand All @@ -72,35 +64,30 @@
<file path="mem-fn.cpp" line="16" class="def"/>
<function name="f" access="public" id="1Lz3aFupR+OsCqiPOaIFWqGuyCc=">
<file path="mem-fn.cpp" line="16"/>
<pure/><virtual/>
</function>
</struct>
<struct name="T09" id="SX7tpa77UInh7a4AsMFjfiCtoLY=">
<file path="mem-fn.cpp" line="11" class="def"/>
<function name="f" access="public" id="u+MePKsNF/sYSk6UpgNS65+USGU=">
<file path="mem-fn.cpp" line="11"/>
<noexcept/>
</function>
</struct>
<struct name="T06" id="SzwXGFnhX4HlHjHolU7XF/KEqDs=">
<file path="mem-fn.cpp" line="8" class="def"/>
<function name="f" access="public" id="A3MUO5+pwkURxw+SBeh1y0BKv7c=">
<file path="mem-fn.cpp" line="8" class="def"/>
<constexpr/>
</function>
</struct>
<struct name="T10" id="TJnjDRnoO8E/5XEw8BaODsKxlwQ=">
<file path="mem-fn.cpp" line="12" class="def"/>
<function name="f" access="public" id="0hjrVGeDlQhdYkOu4shvWWPqNKU=">
<file path="mem-fn.cpp" line="12"/>
<trailing/>
</function>
</struct>
<struct name="T08" id="WU9ZeQm0IOT8cYJkWXom3NXeWsM=">
<file path="mem-fn.cpp" line="10" class="def"/>
<function name="f" access="public" id="jlrEtbnYd1B6OAjYlF0gQ/oYu5w=">
<file path="mem-fn.cpp" line="10"/>
<inline/>
</function>
</struct>
<struct name="T03" id="rM+ml6ikwiS9Twa1IwpCHbSHTbg=">
Expand All @@ -113,14 +100,12 @@
<file path="mem-fn.cpp" line="7" class="def"/>
<function name="f" access="public" id="rWLMsKBEv1FtDyk7Y7XNzcgmt68=">
<file path="mem-fn.cpp" line="7"/>
<const/>
</function>
</struct>
<struct name="T12" id="7rg34TfmIwu+7zOd7DN+Dq8mLCc=">
<file path="mem-fn.cpp" line="14" class="def"/>
<function name="f" access="public" id="I0S8eMgTnTkagm+IrM34MBiU4XI=">
<file path="mem-fn.cpp" line="14"/>
<variadic/>
</function>
</struct>
<struct name="T16" id="75395VGvKeZbe1EhfJwktZuWLs0=">
Expand All @@ -134,7 +119,6 @@
<base name="U" access="public" id="FLgkhM3m0U3Lo2o3XLPUizWPH00="/>
<function name="f3" access="public" id="/C2pxLlwRMKnr6YRbVnykUArzEI=">
<file path="mem-fn.cpp" line="31"/>
<const/><noexcept/><override/><volatile/>
<return name="int"/>
</function>
</struct>
Expand Down
3 changes: 0 additions & 3 deletions tests/old-tests/noreturn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
<friend id="CnO51rIKTzfiVKHkR3TdPa0eo+8="/>
<function name="f2" access="public" id="QjsWLydQujVa097RP8f2Lq3nLQ4=">
<file path="noreturn.cpp" line="5"/>
<noreturn/>
</function>
<function name="f3" access="public" id="TkBjWwqMDycyUbq+TJZ9qfUhSn0=">
<file path="noreturn.cpp" line="7"/>
<noreturn/>
</function>
</struct>
<function name="f1" id="CnO51rIKTzfiVKHkR3TdPa0eo+8=">
<file path="noreturn.cpp" line="1"/>
<file path="noreturn.cpp" line="9"/>
<noreturn/>
</function>
</namespace>
</mrdox>

0 comments on commit 5efe3ef

Please sign in to comment.