clang-tools 22.0.0git
DesignatedInitializers.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/// \file
10/// This file provides utilities for designated initializers.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H
15#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H
16
17#include "clang/AST/Expr.h"
18#include "clang/Basic/SourceLocation.h"
19#include "llvm/ADT/DenseMap.h"
20
21namespace clang::tidy::utils {
22
23/// Get designators describing the elements of a (syntactic) init list.
24///
25/// Given for example the type
26/// \code
27/// struct S { int i, j; };
28/// \endcode
29/// and the definition
30/// \code
31/// S s{1, 2};
32/// \endcode
33/// calling `getUnwrittenDesignators` for the initializer list expression
34/// `{1, 2}` would produce the map `{loc(1): ".i", loc(2): ".j"}`.
35///
36/// It does not produce designators for any explicitly-written nested lists,
37/// e.g. `{1, .j=2}` would only return `{loc(1): ".i"}`.
38///
39/// It also considers structs with fields of record types like
40/// `struct T { S s; };`. In this case, there would be designators of the
41/// form `.s.i` and `.s.j` in the returned map.
42llvm::DenseMap<clang::SourceLocation, std::string>
43getUnwrittenDesignators(const clang::InitListExpr *Syn);
44
45} // namespace clang::tidy::utils
46
47#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H
llvm::DenseMap< SourceLocation, std::string > getUnwrittenDesignators(const InitListExpr *Syn)