summaryrefslogtreecommitdiff
path: root/src/md/compiler/mdsighelper.h
blob: 0d089729bbdf1e1c18e311daa73fe7864a056444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//*****************************************************************************

// 
// MDSigHelp.h
//
// contains utility code for signature parsing and comparisons.
//
// This is needed for validator support, especially because it may need to compare signatures
// across multiple metadata scopes.
//*****************************************************************************

#ifndef __mdsighelper_h_
#define __mdsighelper_h_

#include "regmeta.h"


//****************************************************************************
//****************************************************************************
class MDSigParser : public SigParser
{
    friend class MDSigComparer;

  public:
    //------------------------------------------------------------------------
    // Constructor.
    //------------------------------------------------------------------------
    FORCEINLINE MDSigParser(PCCOR_SIGNATURE ptr, DWORD len)
        : SigParser(ptr, len)
    { }

    FORCEINLINE MDSigParser(const MDSigParser &sig)
        : SigParser(sig.m_ptr, sig.m_dwLen)
    { }
};

//****************************************************************************
//****************************************************************************
class MDSigComparer
{
  public:
    //------------------------------------------------------------------------
    // This is the base type used to provide callback comparison functionality.
    //------------------------------------------------------------------------
    class MDSigComparerBaseType
    {
      public:
        //------------------------------------------------------------------------
        // Returns S_OK if the tokens are equivalent, E_FAIL if they are not, or
        // error.
        //------------------------------------------------------------------------
        virtual HRESULT CompareToken(const mdToken &tok1, const mdToken &tok2) = 0;
    };

    //------------------------------------------------------------------------
    // Ctor
    //------------------------------------------------------------------------
    MDSigComparer(const MDSigParser &sig1,
                  const MDSigParser &sig2,
                  MDSigComparerBaseType &comparer)
        : m_sig1(sig1), m_sig2(sig2), m_comparer(comparer)
    { }

    //------------------------------------------------------------------------
    // Returns S_OK if the signatures are equivalent, E_FAIL if they are not,
    // or error.
    //------------------------------------------------------------------------
    HRESULT CompareMethodSignature();

  protected:
    MDSigParser            m_sig1;
    MDSigParser            m_sig2;
    MDSigComparerBaseType &m_comparer;

    // This will compare exactly one type in each signature to determine
    // if they are equal
    HRESULT _CompareMethodSignature();
    HRESULT _CompareExactlyOne();
    HRESULT _CompareData(ULONG *pulData);
    HRESULT _CompareMethodSignatureHeader(ULONG &cArgs);
};

//****************************************************************************
//****************************************************************************
class UnifiedAssemblySigComparer : public MDSigComparer::MDSigComparerBaseType
{
  public:
    //------------------------------------------------------------------------
    // Ctor
    //------------------------------------------------------------------------
    UnifiedAssemblySigComparer(const RegMeta &regMeta)
        : m_pRegMeta(const_cast<RegMeta*>(&regMeta))
    { }

    //------------------------------------------------------------------------
    // Returns S_OK if the tokens are equivalent, E_FAIL if they are not, or
    // error.
    //------------------------------------------------------------------------
    virtual HRESULT CompareToken(const mdToken &tok1, const mdToken &tok2);

  protected:
    RegMeta *m_pRegMeta;

#ifdef FEATURE_FUSION
    HRESULT _CreateIAssemblyNameFromAssemblyRef(
        mdToken tkAsmRef,
        IAssemblyName **ppAsmName);
#else
    HRESULT _CompareAssemblies(mdToken tkAsmRef1,mdToken tkAsmRef2, BOOL* pfEquivalent);
#endif

    HRESULT _CreateTypeNameFromTypeRef(
        mdToken tkTypeRef,
        SString &ssName,
        mdToken &tkParent);

    HRESULT _CreateFullyQualifiedTypeNameFromTypeRef(
        mdToken tkTypeRef,
        SString &ssFullName,
        mdToken &tkParent);
};


#endif // __mdsighelper_h_