clang  7.0.0svn
ASTStructuralEquivalence.h
Go to the documentation of this file.
1 //===- ASTStructuralEquivalence.h -------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the StructuralEquivalenceContext class which checks for
11 // structural equivalence between types.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_ASTSTRUCTURALEQUIVALENCE_H
16 #define LLVM_CLANG_AST_ASTSTRUCTURALEQUIVALENCE_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/ADT/Optional.h"
21 #include <deque>
22 #include <utility>
23 
24 namespace clang {
25 
26 class ASTContext;
27 class Decl;
28 class DiagnosticBuilder;
29 class QualType;
30 class RecordDecl;
31 class SourceLocation;
32 
34  /// AST contexts for which we are checking structural equivalence.
36 
37  /// The set of "tentative" equivalences between two canonical
38  /// declarations, mapping from a declaration in the first context to the
39  /// declaration in the second context that we believe to be equivalent.
40  llvm::DenseMap<Decl *, Decl *> TentativeEquivalences;
41 
42  /// Queue of declarations in the first context whose equivalence
43  /// with a declaration in the second context still needs to be verified.
44  std::deque<Decl *> DeclsToCheck;
45 
46  /// Declaration (from, to) pairs that are known not to be equivalent
47  /// (which we have already complained about).
49 
50  /// Whether we're being strict about the spelling of types when
51  /// unifying two types.
53 
54  /// Whether warn or error on tag type mismatches.
56 
57  /// Whether to complain about failures.
58  bool Complain;
59 
60  /// \c true if the last diagnostic came from ToCtx.
61  bool LastDiagFromC2 = false;
62 
64  ASTContext &FromCtx, ASTContext &ToCtx,
65  llvm::DenseSet<std::pair<Decl *, Decl *>> &NonEquivalentDecls,
66  bool StrictTypeSpelling = false, bool Complain = true,
67  bool ErrorOnTagTypeMismatch = false)
68  : FromCtx(FromCtx), ToCtx(ToCtx), NonEquivalentDecls(NonEquivalentDecls),
69  StrictTypeSpelling(StrictTypeSpelling),
70  ErrorOnTagTypeMismatch(ErrorOnTagTypeMismatch), Complain(Complain) {}
71 
72  DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID);
73  DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID);
74 
75  /// Determine whether the two declarations are structurally
76  /// equivalent.
77  bool IsStructurallyEquivalent(Decl *D1, Decl *D2);
78 
79  /// Determine whether the two types are structurally equivalent.
81 
82  /// Find the index of the given anonymous struct/union within its
83  /// context.
84  ///
85  /// \returns Returns the index of this anonymous struct/union in its context,
86  /// including the next assigned index (if none of them match). Returns an
87  /// empty option if the context is not a record, i.e.. if the anonymous
88  /// struct/union is at namespace or block scope.
89  ///
90  /// FIXME: This is needed by ASTImporter and ASTStructureEquivalence. It
91  /// probably makes more sense in some other common place then here.
94 
95 private:
96  /// Finish checking all of the structural equivalences.
97  ///
98  /// \returns true if an error occurred, false otherwise.
99  bool Finish();
100 };
101 
102 } // namespace clang
103 
104 #endif // LLVM_CLANG_AST_ASTSTRUCTURALEQUIVALENCE_H
A (possibly-)qualified type.
Definition: Type.h:654
static llvm::Optional< unsigned > findUntaggedStructOrUnionIndex(RecordDecl *Anon)
Find the index of the given anonymous struct/union within its context.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
StructuralEquivalenceContext(ASTContext &FromCtx, ASTContext &ToCtx, llvm::DenseSet< std::pair< Decl *, Decl *>> &NonEquivalentDecls, bool StrictTypeSpelling=false, bool Complain=true, bool ErrorOnTagTypeMismatch=false)
ASTContext & FromCtx
AST contexts for which we are checking structural equivalence.
bool IsStructurallyEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID)
Represents a struct/union/class.
Definition: Decl.h:3548
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:150
bool ErrorOnTagTypeMismatch
Whether warn or error on tag type mismatches.
DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID)
bool StrictTypeSpelling
Whether we&#39;re being strict about the spelling of types when unifying two types.
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1042
bool LastDiagFromC2
true if the last diagnostic came from ToCtx.
Encodes a location in the source.
Dataflow Directional Tag Classes.
llvm::DenseSet< std::pair< Decl *, Decl * > > & NonEquivalentDecls
Declaration (from, to) pairs that are known not to be equivalent (which we have already complained ab...
llvm::DenseMap< Decl *, Decl * > TentativeEquivalences
The set of "tentative" equivalences between two canonical declarations, mapping from a declaration in...
std::deque< Decl * > DeclsToCheck
Queue of declarations in the first context whose equivalence with a declaration in the second context...
bool Complain
Whether to complain about failures.