Clang Project

clang_source_code/unittests/Tooling/RecursiveASTVisitorTests/InitListExprPostOrder.cpp
1//===- unittest/Tooling/RecursiveASTVisitorTests/InitListExprPostOrder.cpp -==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "TestVisitor.h"
10
11using namespace clang;
12
13namespace {
14
15class InitListExprPostOrderVisitor
16    : public ExpectedLocationVisitor<InitListExprPostOrderVisitor> {
17public:
18  bool shouldTraversePostOrder() const { return true; }
19
20  bool VisitInitListExpr(InitListExpr *ILE) {
21    Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getBeginLoc());
22    return true;
23  }
24};
25
26TEST(RecursiveASTVisitor, InitListExprIsPostOrderVisitedTwice) {
27  InitListExprPostOrderVisitor Visitor;
28  Visitor.ExpectMatch("syntactic"221);
29  Visitor.ExpectMatch("semantic"221);
30  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
31                              "static struct S s = {.x = 0};\n",
32                              InitListExprPostOrderVisitor::Lang_C));
33}
34
35// end anonymous namespace
36