blob: 8ce40c66ba1d72ab00ef7764b737225c9341eb06 [file] [log] [blame]
// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_SUBSTITUTIONS_H_
#define CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_SUBSTITUTIONS_H_
#include "lifetime_annotations/lifetime.h"
#include "llvm/ADT/DenseMap.h"
namespace clang {
namespace tidy {
namespace lifetimes {
// A set of substitutions of a lifetime variable with another lifetime (variable
// or constant).
class LifetimeSubstitutions {
public:
// Constructs an empty set of substitutions.
LifetimeSubstitutions() = default;
// Adds a substitution of `variable` by `substitution`.
// Precondition: `variable.IsVariable()`
void Add(Lifetime variable, Lifetime substitution);
// Returns the result of (transitively) applying all applicable substitutions
// to `l`.
// For convenience, `l` may be a constant lifetime; in this case, `l` is
// always returned unchanged.
Lifetime Substitute(Lifetime l) const;
// Dumps the substitutions to llvm::errs().
void Dump() const;
private:
llvm::DenseMap<Lifetime, Lifetime> substitutions_;
};
} // namespace lifetimes
} // namespace tidy
} // namespace clang
#endif // CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_SUBSTITUTIONS_H_