1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5#ifndef _formatType_h
6#define _formatType_h
7
8#include "corpriv.h" // for IMDInternalImport
9
10// ILDASM code doesn't memcpy on gc pointers, so it prefers the real
11// memcpy rather than GCSafeMemCpy.
12#if defined(_DEBUG) && !defined(DACCESS_COMPILE)
13#ifdef memcpy
14#undef memcpy
15#endif
16#endif
17
18#define MAX_PREFIX_SIZE 32
19
20struct ParamDescriptor
21{
22 char* name;
23 mdToken tok;
24 DWORD attr;
25};
26
27char* DumpMarshaling(IMDInternalImport* pImport,
28 __inout_ecount(cchszString) char* szString,
29 DWORD cchszString,
30 mdToken tok);
31char* DumpParamAttr(__inout_ecount(cchszString) char* szString,
32 DWORD cchszString,
33 DWORD dwAttr);
34
35void appendStr(CQuickBytes *out, const char* str, unsigned len=(unsigned)-1);
36void insertStr(CQuickBytes *out, const char* str);
37char* asString(CQuickBytes *out);
38
39const char* PrettyPrintSig(
40 PCCOR_SIGNATURE typePtr, // type to convert,
41 unsigned typeLen, // the lenght of 'typePtr'
42 const char* name, // can be "", the name of the method for this sig 0 means local var sig
43 CQuickBytes *out, // where to put the pretty printed string
44 IMDInternalImport *pIMDI, // ptr to IMDInternalImport class with ComSig
45 __in_opt const char* inlabel, // prefix for names (NULL if no names required)
46 BOOL printTyArity=FALSE); // flag to print Type Param number (MemberRefs only)
47
48PCCOR_SIGNATURE PrettyPrintType(
49 PCCOR_SIGNATURE typePtr, // type to convert,
50 CQuickBytes *out, // where to put the pretty printed string
51 IMDInternalImport *pIMDI); // ptr to IMDInternal class with ComSig
52
53PCCOR_SIGNATURE PrettyPrintTypeOrDef( // outside ILDASM - simple wrapper of PrettyPrintType
54 PCCOR_SIGNATURE typePtr, // type to convert,
55 CQuickBytes *out, // where to put the pretty printed string
56 IMDInternalImport *pIMDI); // ptr to IMDInternal class with ComSig
57
58
59const char* PrettyPrintClass(
60 CQuickBytes *out, // where to put the pretty printed string
61 mdToken tk, // The class token to look up
62 IMDInternalImport *pIMDI); // ptr to IMDInternalImport class with ComSig
63
64//================= ILDASM-specific ==================================================================
65
66#ifdef __ILDASM__
67
68#include "../ildasm/dynamicarray.h"
69
70bool IsNameToQuote(const char *name);
71bool IsLocalToQuote(const char *name);
72const char* UnquotedProperName(__in __nullterminated const char* name, unsigned len=(unsigned)-1);
73const char* ProperName(__in __nullterminated const char* name, bool isLocalName = false);
74#define ProperLocalName(x) ProperName(x, true)
75const char* KEYWORD(__in_opt __nullterminated const char* szOrig);
76const char* COMMENT(__in_opt __nullterminated const char* szOrig);
77const char* ERRORMSG(__in_opt __nullterminated const char* szOrig);
78const char* ANCHORPT(__in __nullterminated const char* szOrig, mdToken tk);
79const char* JUMPPT(__in __nullterminated const char* szOrig, mdToken tk);
80const char* SCOPE(void);
81const char* UNSCOPE(void);
82const char* LTN(void);
83const char* GTN(void);
84const char* AMP(void);
85
86extern BOOL g_fDumpRTF,g_fDumpHTML; // declared in FormatType.cpp
87//-------------------------------------------------------------------------------
88// Protection against null names
89extern const char* const szStdNamePrefix[]; //declared in formatType.cpp
90
91extern DynamicArray<mdToken> *g_dups;
92extern DWORD g_NumDups;
93inline BOOL IsDup(mdToken tk)
94{
95 if(g_NumDups)
96 {
97 mdToken tktype = TypeFromToken(tk);
98 if((tktype==mdtTypeDef)||(tktype==mdtMethodDef)||(tktype==mdtFieldDef))
99 {
100 for (unsigned i=0; i<g_NumDups; i++)
101 {
102 if((*g_dups)[i] == tk) return TRUE;
103 }
104 }
105 }
106 return FALSE;
107}
108#define MAKE_NAME_IF_NONE(psz, tk) { if((!(psz && *psz))||IsDup(tk)) { char* sz = (char*)_alloca(16); \
109sprintf_s(sz,16,"$%s$%X",szStdNamePrefix[tk>>24],tk&0x00FFFFFF); psz = sz; } }
110
111
112struct TypeDefDescr
113{
114 char* szName;
115 mdToken tkTypeSpec;
116 mdToken tkSelf;
117 PCCOR_SIGNATURE psig;
118 ULONG cb;
119};
120extern DynamicArray<TypeDefDescr> *g_typedefs;
121extern DWORD g_NumTypedefs;
122
123
124//-------------------------------------------------------------------------------
125// Reference analysis (ILDASM)
126struct TokPair
127{
128 mdToken tkUser;
129 mdToken tkRef;
130 TokPair() { tkUser = tkRef = 0; };
131};
132extern DynamicArray<TokPair> *g_refs;
133extern DWORD g_NumRefs;
134extern mdToken g_tkRefUser; // for PrettyPrintSig
135#define REGISTER_REF(x,y) if(g_refs && (x)){ (*g_refs)[g_NumRefs].tkUser = x; (*g_refs)[g_NumRefs++].tkRef = y;}
136
137//--------------------------------------------------------------------------------
138// No-throw deallocators
139
140#define SDELETE(x) {PAL_CPP_TRY{ delete (x); } PAL_CPP_CATCH_ALL { _ASSERTE(!"AV in scalar deallocator");} PAL_CPP_ENDTRY; (x)=NULL; }
141#define VDELETE(x) {PAL_CPP_TRY{ delete [] (x); } PAL_CPP_CATCH_ALL { _ASSERTE(!"AV in vector deallocator");}; PAL_CPP_ENDTRY; (x)=NULL; }
142
143//--------------------------------------------------------------------------------
144// Generic param names
145extern mdToken g_tkVarOwner;
146extern mdToken g_tkMVarOwner;
147//void SetVarOwner(mdToken tk) { g_tkVarOwner = tk; }
148//void SetMVarOwner(mdToken tk) { g_tkMVarOwner = tk; }
149BOOL PrettyPrintGP( // defined in dasm.cpp
150 mdToken tkOwner, // Class, method or 0
151 CQuickBytes *out, // where to put the pretty printed generic param
152 int n); // Index of generic param
153
154//============== End of ILDASM-specific ================================================================
155
156#else
157
158#define IsNameToQuote(x) false
159#define IsLocalToQuote(x) false
160#define UnquotedProperName(x) x
161#define ProperName(x) x
162#define ProperLocalName(x) x
163#define KEYWORD(x) x
164#define COMMENT(x) x
165#define ERRORMSG(x) x
166#define ANCHORPT(x,y) x
167#define JUMPPT(x,y) x
168#define SCOPE() "{"
169#define UNSCOPE() "}"
170#define LTN() "<"
171#define GTN() ">"
172#define AMP() "&"
173#define REGISTER_REF(x,y) {}
174#define MAKE_NAME_IF_NONE(x,y) { }
175#define g_fDumpTokens false
176#define SDELETE(x) delete (x)
177#define VDELETE(x) delete [] (x)
178
179#endif
180
181#endif
182