clang  6.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 
23 namespace clang {
24 
25 class ASTContext;
26 class Decl;
27 class DiagnosticBuilder;
28 class QualType;
29 class RecordDecl;
30 class SourceLocation;
31 
33  /// AST contexts for which we are checking structural equivalence.
35 
36  /// The set of "tentative" equivalences between two canonical
37  /// declarations, mapping from a declaration in the first context to the
38  /// declaration in the second context that we believe to be equivalent.
39  llvm::DenseMap<Decl *, Decl *> TentativeEquivalences;
40 
41  /// Queue of declarations in the first context whose equivalence
42  /// with a declaration in the second context still needs to be verified.
43  std::deque<Decl *> DeclsToCheck;
44 
45  /// Declaration (from, to) pairs that are known not to be equivalent
46  /// (which we have already complained about).
48 
49  /// Whether we're being strict about the spelling of types when
50  /// unifying two types.
52 
53  /// Whether warn or error on tag type mismatches.
55 
56  /// Whether to complain about failures.
57  bool Complain;
58 
59  /// \c true if the last diagnostic came from ToCtx.
61 
63  ASTContext &FromCtx, ASTContext &ToCtx,
64  llvm::DenseSet<std::pair<Decl *, Decl *>> &NonEquivalentDecls,
65  bool StrictTypeSpelling = false, bool Complain = true,
66  bool ErrorOnTagTypeMismatch = false)
67  : FromCtx(FromCtx), ToCtx(ToCtx), NonEquivalentDecls(NonEquivalentDecls),
68  StrictTypeSpelling(StrictTypeSpelling),
69  ErrorOnTagTypeMismatch(ErrorOnTagTypeMismatch), Complain(Complain),
70  LastDiagFromC2(false) {}
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 } // namespace clang
102 
103 #endif // LLVM_CLANG_AST_ASTSTRUCTURALEQUIVALENCE_H
A (possibly-)qualified type.
Definition: Type.h:653
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.
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3482
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
bool ErrorOnTagTypeMismatch
Whether warn or error on tag type mismatches.
bool StrictTypeSpelling
Whether we&#39;re being strict about the spelling of types when unifying two types.
bool IsStructurallyEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:955
DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID)
bool LastDiagFromC2
true if the last diagnostic came from ToCtx.
DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID)
#define false
Definition: stdbool.h:33
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...
static llvm::Optional< unsigned > findUntaggedStructOrUnionIndex(RecordDecl *Anon)
Find the index of the given anonymous struct/union within its context.
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.