1 //===- ASTDiffInternal.h --------------------------------------*- C++ -*- -===//
2 //
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLING_ASTDIFF_ASTDIFFINTERNAL_H
11 #define LLVM_CLANG_TOOLING_ASTDIFF_ASTDIFFINTERNAL_H
12 
13 #include "clang/AST/ASTTypeTraits.h"
14 
15 namespace clang {
16 namespace diff {
17 
18 using DynTypedNode = ast_type_traits::DynTypedNode;
19 
20 class SyntaxTree;
21 class SyntaxTreeImpl;
22 struct ComparisonOptions;
23 
24 /// Within a tree, this identifies a node by its preorder offset.
25 struct NodeId {
26 private:
27   static constexpr int InvalidNodeId = -1;
28 
29 public:
30   int Id;
31 
32   NodeId() : Id(InvalidNodeId) {}
33   NodeId(int Id) : Id(Id) {}
34 
35   operator int() const { return Id; }
36   NodeId &operator++() { return ++Id, *this; }
37   NodeId &operator--() { return --Id, *this; }
38   // Support defining iterators on NodeId.
39   NodeId &operator*() { return *this; }
40 
41   bool isValid() const { return Id != InvalidNodeId; }
42   bool isInvalid() const { return Id == InvalidNodeId; }
43 };
44 
45 } // end namespace diff
46 } // end namespace clang
47 #endif
48