Clang Project

clang_source_code/unittests/Tooling/RecursiveASTVisitorTests/InitListExprPreOrder.cpp
1//===- unittest/Tooling/RecursiveASTVisitorTests/InitListExprPreOrder.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
15// Check to ensure that InitListExpr is visited twice, once each for the
16// syntactic and semantic form.
17class InitListExprPreOrderVisitor
18    : public ExpectedLocationVisitor<InitListExprPreOrderVisitor> {
19public:
20  bool VisitInitListExpr(InitListExpr *ILE) {
21    Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getBeginLoc());
22    return true;
23  }
24};
25
26TEST(RecursiveASTVisitor, InitListExprIsPreOrderVisitedTwice) {
27  InitListExprPreOrderVisitor 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                              InitListExprPreOrderVisitor::Lang_C));
33}
34
35// end anonymous namespace
36