Skip to content

Commit 5cf8006

Browse files
committed
[ast-match] Add isAggregate and isFullyDesignated AST matchers (#12)
1 parent 0663520 commit 5cf8006

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

.redpoint/build.ps1

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
param([switch] $Generate, [switch] $Install, [switch] $InstallOnly, [switch] $Debug)
1+
param([switch] $Generate, [switch] $Install, [switch] $InstallOnly, [switch] $Debug, [string] $UbaEngine)
22

33
$global:ErrorActionPreference = 'Stop'
44

@@ -15,19 +15,31 @@ function Invoke-CmdScript {
1515
}
1616
}
1717

18-
$UbaViaUet = (Test-Path "C:\ProgramData\UET\Current\uet.exe")
19-
2018
Push-Location "$PSScriptRoot\.."
2119
try {
2220
# Set the build path.
2321
$BuildPathDebug = "build\win64\debug"
2422
$BuildPathRelease = "build\win64\release"
25-
$LauncherFlags = @()
26-
$UbaCores = @()
27-
if ($UbaViaUet) {
28-
$LauncherFlags += "-DCMAKE_C_COMPILER_LAUNCHER=$PSScriptRoot\uet-cmake.bat"
29-
$LauncherFlags += "-DCMAKE_CXX_COMPILER_LAUNCHER=$PSScriptRoot\uet-cmake.bat"
30-
$UbaCores += "-j256"
23+
$CMakeCommand = "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
24+
$CMakeCommandArguments = @(
25+
)
26+
$CMakeCommandGenerateArguments = @(
27+
"-G",
28+
"Ninja"
29+
)
30+
if ($null -ne $UbaEngine) {
31+
$CMakeCommand = "uet";
32+
if (Test-Path "C:\Work\uet\UET\uet\bin\Debug\net9.0\win-x64\uet.exe") {
33+
$CMakeCommand = "C:\Work\uet\UET\uet\bin\Debug\net9.0\win-x64\uet.exe"
34+
}
35+
$CMakeCommandArguments = @(
36+
"cmake",
37+
"-e",
38+
$UbaEngine,
39+
"--"
40+
)
41+
$CMakeCommandGenerateArguments = @(
42+
)
3143
}
3244

3345
# Create the session ID for this build.
@@ -46,9 +58,8 @@ try {
4658
if (!(Test-Path $BuildPathRelease)) {
4759
New-Item -ItemType Directory $BuildPathRelease | Out-Null
4860
}
49-
#-T host=x64 -A x64 `
50-
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe' `
51-
-G "Ninja" `
61+
62+
& $CMakeCommand $CMakeCommandArguments $CMakeCommandGenerateArguments `
5263
"-DCMAKE_MAKE_PROGRAM=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe" `
5364
"-DLLVM_ENABLE_PROJECTS:STRING=clang;lld" `
5465
"-DCMAKE_C_COMPILER=C:\Program Files\LLVM\bin\clang-cl.exe" `
@@ -73,8 +84,7 @@ try {
7384
if ($LastExitCode -ne 0) {
7485
exit $LastExitCode
7586
}
76-
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe' `
77-
-G "Ninja" `
87+
& $CMakeCommand $CMakeCommandArguments $CMakeCommandGenerateArguments `
7888
"-DCMAKE_MAKE_PROGRAM=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe" `
7989
"-DLLVM_ENABLE_PROJECTS:STRING=clang;lld" `
8090
"-DCMAKE_C_COMPILER=C:\Program Files\LLVM\bin\clang-cl.exe" `
@@ -111,15 +121,9 @@ try {
111121

112122
# Build if not only installing.
113123
if (!$InstallOnly) {
114-
# Start UBA worker if needed.
115-
if ($UbaViaUet) {
116-
Start-Process -NoNewWindow -FilePath "C:\Work\uet\UET\uet\bin\Debug\net8.0\win-x64\uet.exe" -ArgumentList @("internal", "cmake-uba-server")
117-
}
118-
119-
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe' `
124+
& $CMakeCommand $CMakeCommandArguments `
120125
--build $BuildPath `
121-
--config $BuildConfiguration `
122-
$UbaCores
126+
--config $BuildConfiguration
123127
if ($LastExitCode -ne 0) {
124128
exit $LastExitCode
125129
}

clang/include/clang/ASTMatchers/ASTMatchers.Unreal.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,24 @@ AST_MATCHER(NestedNameSpecifier, isNamespaceSpecifierRootedToGlobal) {
532532
return false;
533533
}
534534

535+
/// Matches if a CXX record decl is an aggregate type, which is a class with no user-declared
536+
/// constructors, no private or protected non-static data members, no base classes, and no virtual
537+
/// functions (C++ [dcl.init.aggr]p1).
538+
AST_MATCHER(CXXRecordDecl, isAggregate) {
539+
return Node.hasDefinition() && Node.isAggregate();
540+
}
541+
542+
/// Matches if a init list expr is full designated (contains no initialization elements that aren't
543+
/// designated.
544+
AST_MATCHER(InitListExpr, isFullyDesignated) {
545+
if (const InitListExpr *SyntacticForm =
546+
Node.isSyntacticForm() ? &Node : Node.getSyntacticForm()) {
547+
unsigned NumberOfDesignated = llvm::count_if(*SyntacticForm, [](auto *InitExpr) {
548+
return isa<DesignatedInitExpr>(InitExpr);
549+
});
550+
return NumberOfDesignated == SyntacticForm->getNumInits();
551+
}
552+
return true;
553+
}
554+
535555
// @unreal: END

clang/lib/ASTMatchers/Dynamic/Registry.Unreal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ REGISTER_MATCHER(hasRedundantNamespacing);
2020
REGISTER_MATCHER(isExpensiveToCopy);
2121
REGISTER_MATCHER(isUnrealExported);
2222
REGISTER_MATCHER(isNamespaceSpecifierRootedToGlobal);
23+
REGISTER_MATCHER(isAggregate);
24+
REGISTER_MATCHER(isFullyDesignated);
2325
// @unreal: END

0 commit comments

Comments
 (0)