48 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file provides utilities for designated initializers.11///12//===----------------------------------------------------------------------===//13 14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H15#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H16 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 type26/// \code27/// struct S { int i, j; };28/// \endcode29/// and the definition30/// \code31/// S s{1, 2};32/// \endcode33/// calling `getUnwrittenDesignators` for the initializer list expression34/// `{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 like40/// `struct T { S s; };`. In this case, there would be designators of the41/// 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::utils46 47#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H48